首页>代码>基于maven多模块构建的spring+spring mvc+hibernate开发cms内容管理系统,包括后台管理系统,对外接口模块,前端项目>/tianti-cms/src/main/java/com/jeff/tianti/cms/dao/ArticleDaoImpl.java
package com.jeff.tianti.cms.dao;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import com.jeff.tianti.cms.dto.ArticleQueryDTO;
import com.jeff.tianti.cms.dto.CurrentArticleInfoDTO;
import com.jeff.tianti.cms.entity.Article;
import com.jeff.tianti.common.dao.CustomBaseSqlDaoImpl;
import com.jeff.tianti.common.entity.PageModel;
/**
* @author xujianfang
* @desc ArticleDaoImpl类
* @date 2017-03-16
*/
public class ArticleDaoImpl extends CustomBaseSqlDaoImpl implements ArticleDaoCustom {
public PageModel<Article> queryArticlePage(ArticleQueryDTO articleQueryDTO){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Map<String,Object> map = new HashMap<String,Object>();
StringBuilder hql = new StringBuilder();
hql.append("select t from Article t where 1=1 ");
if(articleQueryDTO != null){
if(StringUtils.isNotBlank(articleQueryDTO.getRootColumnId())){
hql.append(" and t.rootColumnInfo.id = :rootColumnId ");
map.put("rootColumnId", articleQueryDTO.getRootColumnId());
}
if(StringUtils.isNotBlank(articleQueryDTO.getColumnId())){
hql.append(" and t.columnInfo.id = :columnId ");
map.put("columnId", articleQueryDTO.getColumnId());
}
if(StringUtils.isNotBlank(articleQueryDTO.getTitle())){
hql.append(" and t.title like :title ");
map.put("title", "%"+articleQueryDTO.getTitle()+"%");
}
if(StringUtils.isNotBlank(articleQueryDTO.getPublisher())){
hql.append(" and t.publisher like :publisher ");
map.put("publisher", "%"+articleQueryDTO.getPublisher()+"%");
}
if(StringUtils.isNotBlank(articleQueryDTO.getDeleteFlag())){
hql.append(" and t.deleteFlag = :deleteFlag ");
map.put("deleteFlag", articleQueryDTO.getDeleteFlag());
}
if(StringUtils.isNotBlank(articleQueryDTO.getStartDate())){
hql.append(" and t.createDate >= :startDate ");
try {
map.put("startDate",sdf.parse(articleQueryDTO.getStartDate()));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(StringUtils.isNotBlank(articleQueryDTO.getEndDate())){
hql.append(" and t.createDate <= :endDate ");
try {
map.put("endDate",sdf.parse(articleQueryDTO.getEndDate()));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(articleQueryDTO.getIsFront() != null && articleQueryDTO.getIsFront()){
//前端默认查询审核通过的且未删除的记录,且按照置顶和时间降序排序
hql.append(" and t.isAudit =1 order by t.isTop desc,t.createDate desc ");
}else{
if(StringUtils.isNotBlank(articleQueryDTO.getType())){
if(articleQueryDTO.getType().equals("laji")){
hql.append(" and t.deleteFlag =1 ");
}else if(articleQueryDTO.getType().equals("zhiding")){
hql.append(" and t.isTop =1 ");
}
hql.append(" order by t.createDate desc ");
}
}
}
return this.queryForPageWithParams(hql.toString(),map,articleQueryDTO.getCurrentPage(),articleQueryDTO.getPageSize());
}
public List<Article> queryArticleList(ArticleQueryDTO articleQueryDTO){
List<Article> articleList = null;
Map<String,Object> map = new HashMap<String,Object>();
StringBuilder hql = new StringBuilder();
hql.append("select t from Article t where 1=1 ");
if(articleQueryDTO != null){
if(StringUtils.isNotBlank(articleQueryDTO.getColumnId())){
hql.append(" and t.columnInfo.id = :columnId ");
map.put("columnId", articleQueryDTO.getColumnId());
}
if(StringUtils.isNotBlank(articleQueryDTO.getTitle())){
hql.append(" and t.title like = :title ");
map.put("title", "%"+articleQueryDTO.getTitle()+"%");
}
if(StringUtils.isNotBlank(articleQueryDTO.getPublisher())){
hql.append(" and t.publisher like = :publisher ");
map.put("publisher", "%"+articleQueryDTO.getPublisher()+"%");
}
if(StringUtils.isNotBlank(articleQueryDTO.getDeleteFlag())){
hql.append(" and t.deleteFlag = :deleteFlag ");
map.put("deleteFlag", articleQueryDTO.getDeleteFlag());
}
if(StringUtils.isNotBlank(articleQueryDTO.getStartDate())){
hql.append(" and t.createDate >= :startDate ");
map.put("startDate",articleQueryDTO.getStartDate());
}
if(StringUtils.isNotBlank(articleQueryDTO.getEndDate())){
hql.append(" and t.createDate <= :endDate ");
map.put("endDate",articleQueryDTO.getEndDate());
}
if(articleQueryDTO.getIsFront() != null && articleQueryDTO.getIsFront()){
//前端默认查询审核通过的且未删除的记录,且按照置顶和时间降序排序
hql.append(" and t.isAudit =1 order by t.isTop desc,t.createDate desc ");
}else{
if(StringUtils.isNotBlank(articleQueryDTO.getType())){
if(articleQueryDTO.getType().equals("laji")){
hql.append(" and t.deleteFlag =1 ");
}else if(articleQueryDTO.getType().equals("zhiding")){
hql.append(" and t.isTop =1 ");
}
hql.append(" order by t.createDate desc ");
}
}
}
if(articleQueryDTO.getTop() != null){
PageModel pageModel = this.queryForPageWithParams(hql.toString(),map,0, articleQueryDTO.getTop());
if(pageModel != null){
articleList = pageModel.getList();
}
}else{
articleList = this.queryByMapParams(hql.toString(),map);
}
return articleList;
}
public List<Map<String, Object>> queryStatisMapList(ArticleQueryDTO articleQueryDTO){
String sql = " select count(1) as totalCount,(select count(1) from cms_article where is_top=1 and delete_flag = '0') as zhidingCount,(select count(1) from cms_article where is_audit=1 and delete_flag = '0') as shenheCount,(select count(1) from cms_article where delete_flag='1') as deleteCount from cms_article a ";
return this.querySqlObjects(sql);
}
public List<Article> queryNextArticleList(CurrentArticleInfoDTO currentArticleInfoDTO){
Map<String,Object> map = new HashMap<String,Object>();
StringBuilder hql = new StringBuilder();
hql.append(" select a from Article a where 1=1 ");
if(StringUtils.isNotBlank(currentArticleInfoDTO.getArticleId())){
hql.append(" and a.id <> :articleId ");
map.put("articleId", currentArticleInfoDTO.getArticleId());
}
if(StringUtils.isNotBlank(currentArticleInfoDTO.getColumnId())){
hql.append(" and a.columnInfo.id = :columnInfoId ");
map.put("columnInfoId", currentArticleInfoDTO.getColumnId());
}
if(currentArticleInfoDTO.getArticleDate() != null){
hql.append(" and a.createDate < :date ");
map.put("date", currentArticleInfoDTO.getArticleDate());
hql.append(" order by a.createDate desc ");
}else if(currentArticleInfoDTO.getOrderNo() != null){
hql.append(" and a.orderNo < :orderNo ");
map.put("orderNo", currentArticleInfoDTO.getOrderNo());
hql.append(" order by a.orderNo desc ");
}
return this.queryByMapParams(hql.toString(), map);
}
public List<Article> queryPreArticleList(CurrentArticleInfoDTO currentArticleInfoDTO){
Map<String,Object> map = new HashMap<String,Object>();
StringBuilder hql = new StringBuilder();
hql.append(" select a from Article a where 1=1 ");
if(StringUtils.isNotBlank(currentArticleInfoDTO.getArticleId())){
hql.append(" and a.id <> :articleId ");
map.put("articleId", currentArticleInfoDTO.getArticleId());
}
if(StringUtils.isNotBlank(currentArticleInfoDTO.getColumnId())){
hql.append(" and a.columnInfo.id = :columnInfoId ");
map.put("columnInfoId", currentArticleInfoDTO.getColumnId());
}
if(currentArticleInfoDTO.getArticleDate() != null){
hql.append(" and a.createDate > :date ");
map.put("date", currentArticleInfoDTO.getArticleDate());
hql.append(" order by a.createDate asc ");
}else if(currentArticleInfoDTO.getOrderNo() != null){
hql.append(" and a.orderNo > :orderNo ");
map.put("orderNo", currentArticleInfoDTO.getOrderNo());
hql.append(" order by a.orderNo asc ");
}
return this.queryByMapParams(hql.toString(), map);
}
}
最近下载更多
微信网友_6658091507814400 LV3
2023年10月10日
微信网友_6602457430806528 LV6
2023年9月21日
哇塞塞哈哈哈 LV8
2023年5月4日
我也不知道谁的 LV3
2023年3月28日
GeminiLong LV6
2022年12月22日
352601466 LV2
2022年9月20日
ma752060990 LV11
2022年9月17日
testuser1234567 LV24
2022年6月15日
wanglinddad LV55
2022年3月15日
tiansitong LV14
2022年3月9日

最近浏览