package net.y2t70.blog.dao.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.jsp.jstl.sql.Result;
import net.y2t70.blog.dao.ArticlesDao;
import net.y2t70.blog.entity.Articles;
import net.y2t70.blog.tools.StringUtil;
public class ArticlesDaoImpl extends BaseDao implements ArticlesDao {
/**
* 1.发表博文
*/
public int addArticle(Articles art) {
try {
String sql = "insert into Articles values(articles_seq.nextval,'"
+ art.getTitle() + "'," + art.getUserID() + ",'"
+ art.getContent() + "',current_date," + art.getArtTypeID()
+ "," + art.getState() + "," + art.getIsComment() + ","
+ art.getIsreship() + "," + art.getIsOpen()
+ ",default,default,default,default)";
return this.executeUpdate(sql, null);
} catch (Exception e) {
System.out.println("1.发表博文出错:" + e.getMessage());
return 0;
}
}
/**
* 2.修改博文
*/
public int updateArticle(Articles art) {
try {
String sql = "update Articles set title='" + art.getTitle()
+ "',content='" + art.getContent() + "',arttypeid="
+ art.getArtTypeID() + ",state=" + art.getState()
+ ",iscomment=" + art.getIsComment() + ",isreship="
+ art.getIsreship() + ",isopen=" + art.getIsOpen()
+ " where artid=" + art.getArtID() + " and userid="
+ art.getUserID() + "";
return this.executeUpdate(sql, null);
} catch (Exception e) {
System.out.println("2.修改博文出错:" + e.getMessage());
return 0;
}
}
/**
* 3.删除博文(不是真正意义上的删除,是将其状态改为2进入回收站)
*/
public int deleteArticle(int state, int artID, int userID) {
try {
String sql = "update Articles set state=" + state
+ " where artid=" + artID + " and userid=" + userID + "";
return this.executeUpdate(sql, null);
} catch (Exception e) {
System.out.println("3.删除博文出错:" + e.getMessage());
return 0;
}
}
/**
* 4.根据博文分类名称和用户ID查询博文
*/
public List<Articles> showArtByArtType(String typename, int userID) {
try {
String sql = "select artid,title,content,sendtime,zhuanzaiCount,shoucangCount,pingCount,dianjiCount from Articles inner join ArticleType on Articles.arttypeid=ArticleType.arttypeid where typename='"
+ typename
+ "' and Articles.userid="
+ userID
+ " and state=0 and isopen=0";
Result result = this.executeQuery(sql, null);
List<Articles> list = new ArrayList<Articles>();
int size = result.getRowCount();
for (int i = 0; i < size; i++) {
Map map = result.getRows()[i];
Articles art = new Articles();
art.setArtID(StringUtil.toInt(StringUtil.parseString(map
.get("artid"))));
art.setTitle(StringUtil.parseString(map.get("title")));
art.setContent(StringUtil.parseString(map.get("content")));
art.setSendTime(StringUtil.parseString(map.get("sendtime")));
art.setZhuanzaiCount(StringUtil.toInt(StringUtil
.parseString(map.get("zhuanzaicount"))));
art.setShoucangCount(StringUtil.toInt(StringUtil
.parseString(map.get("shoucangcount"))));
art.setPingCount(StringUtil.toInt(StringUtil.parseString(map
.get("pingcount"))));
art.setDianjiCount(StringUtil.toInt(StringUtil.parseString(map
.get("dianjicount"))));
list.add(art);
}
return list;
} catch (Exception e) {
System.out.println("4.根据博文分类名称和用户ID查询博文出错:" + e.getMessage());
return null;
}
}
/**
* 5.根据博文的id显示其详细信息
*/
public Articles LookOneArt(int artID) {
try {
String sql = "select artid,title,Articles.userid,content,sendtime,Articles.arttypeid,state,iscomment,isreship,isopen,typename,zhuanzaiCount,shoucangCount,pingCount,dianjiCount from Articles inner join ArticleType on Articles.arttypeid=ArticleType.arttypeid where artid="
+ artID + " and state=0";
Result result = this.executeQuery(sql, null);
int size = result.getRowCount();
if (result.getRowCount() > 0) {
Map map = result.getRows()[0];
Articles art = new Articles();
art.setArtID(StringUtil.toInt(StringUtil.parseString(map
.get("artid"))));
art.setTitle(StringUtil.parseString(map.get("title")));
art.setUserID(StringUtil.toInt(StringUtil.parseString(map
.get("userid"))));
art.setContent(StringUtil.parseString(map.get("content")));
art.setSendTime(StringUtil.parseString(map.get("sendtime")));
art.setArtTypeID(StringUtil.toInt(StringUtil.parseString(map
.get("arttypeid"))));
art.setState(StringUtil.toInt(StringUtil.parseString(map
.get("state"))));
art.setIsComment(StringUtil.toInt(StringUtil.parseString(map
.get("iscomment"))));
art.setIsreship(StringUtil.toInt(StringUtil.parseString(map
.get("isreship"))));
art.setIsOpen(StringUtil.toInt(StringUtil.parseString(map
.get("isopen"))));
art.setTypename(StringUtil.parseString(map.get("typename")));
art.setZhuanzaiCount(StringUtil.toInt(StringUtil
.parseString(map.get("zhuanzaicount"))));
art.setShoucangCount(StringUtil.toInt(StringUtil
.parseString(map.get("shoucangcount"))));
art.setPingCount(StringUtil.toInt(StringUtil.parseString(map
.get("pingcount"))));
art.setDianjiCount(StringUtil.toInt(StringUtil.parseString(map
.get("dianjicount"))));
return art;
}
return null;
} catch (Exception e) {
System.out.println("5.根据博文的id显示其详细信息出错:" + e.getMessage());
return null;
}
}
/**
* 6.显示草稿箱信息
*/
public List<Articles> showCaoGao() {
try {
String sql = "select artid,title,content,sendtime,typename from Articles inner join ArticleType on Articles.arttypeid=ArticleType.arttypeid where state=1";
Result result = this.executeQuery(sql, null);
List<Articles> list = new ArrayList<Articles>();
int size = result.getRowCount();
for (int i = 0; i < size; i++) {
Map map = result.getRows()[i];
Articles art = new Articles();
art.setArtID(StringUtil.toInt(StringUtil.parseString(map
.get("artid"))));
art.setTitle(StringUtil.parseString(map.get("title")));
art.setContent(StringUtil.parseString(map.get("content")));
art.setSendTime(StringUtil.parseString(map.get("sendtime")));
art.setTypename(StringUtil.parseString(map.get("typename")));
list.add(art);
}
return list;
} catch (Exception e) {
System.out.println(" 6.显示草稿箱信息出错:" + e.getMessage());
return null;
}
}
/**
* 7.显示回收站的博文列表
*/
public List<Articles> showHuiShou() {
try {
String sql = "select artid,title,content,sendtime,typename from Articles inner join ArticleType on Articles.arttypeid=ArticleType.arttypeid where state=2";
Result result = this.executeQuery(sql, null);
List<Articles> list = new ArrayList<Articles>();
int size = result.getRowCount();
for (int i = 0; i < size; i++) {
Map map = result.getRows()[i];
Articles art = new Articles();
art.setArtID(StringUtil.toInt(StringUtil.parseString(map
.get("artid"))));
art.setTitle(StringUtil.parseString(map.get("title")));
art.setContent(StringUtil.parseString(map.get("content")));
art.setSendTime(StringUtil.parseString(map.get("sendtime")));
art.setTypename(StringUtil.parseString(map.get("typename")));
list.add(art);
}
return list;
} catch (Exception e) {
System.out.println("7.显示回收站的博文列表出错:" + e.getMessage());
return null;
}
}
/**
* 8.将回收站的博文恢复
*/
public int HuiFuArt(int artID) {
try {
String sql = "update Articles set state=0 where artid=" + artID
+ " and state=2";
return this.executeUpdate(sql, null);
} catch (Exception e) {
System.out.println("8.将回收站的博文恢复出错:" + e.getMessage());
return 0;
}
}
/**
* 9.将在回收站中的博文删除,改变其s
评论4
最新资源