package com.qxueyou.scc.portal.homepage.dao; //import com.qxueyou.entity.article.ArticleDO; //import com.qxueyou.service.MongoService; //import com.qxueyou.util.CollectionUtils; import com.qxueyou.scc.base.dao.BaseDAO; import com.qxueyou.scc.base.model.Pager; import com.qxueyou.scc.base.util.ClientUtils; import com.qxueyou.scc.base.util.CollectionUtils; import com.qxueyou.scc.portal.information.model.Information; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; //import org.springframework.data.mongodb.core.query.Criteria; //import org.springframework.data.mongodb.core.query.Query; //import org.springframework.data.mongodb.core.query.Update; import org.springframework.stereotype.Repository; import javax.annotation.PostConstruct; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * @author ZERO 2021-03-03 16:36 */ @Repository public class ArticleDao extends BaseDAO { public Map moreOccupation(String type, String subColumn, String numbers,int page, int size, String keyword) { StringBuffer hql = new StringBuffer(500); hql.append( "from Information where deleteFlag=0 and type = ? and status= ?"); List params = CollectionUtils.newList(type, Information.UP_STATUS); // Map condition = CollectionUtils.newObjectMap("type", type, "status", Information.UP_STATUS); if(StringUtils.isNotEmpty(keyword)){ hql.append( " and title = ? "); params.add(keyword); } if (type.equals("examBriefing")) { hql.append( "and subColumn = ? "); params.add( subColumn); } // if(subColumn!=null) { // if (subColumn.equals("previousContest")) { // condition.put("numbers", numbers); // } // } long totalCount = findCount(hql.toString(),params); hql.append( "order by dateTime desc"); List articleList = findList(hql.toString(),new Pager(page,size),params,Information.class); List> data = articleList .stream() .map(article -> CollectionUtils.newObjectMap( "id", article.getId(), "content", article.getContent(), "title", article.getTitle(), "attachment", article.getAttachment(), "browseCount", article.getBrowseCount(), "status", article.getStatus(), "thumbnailUrl", article.getThumbnailUrl(), "type", article.getType(), "dateTime", article.getDateTime(), "competition",article.getCompetition())) .collect(Collectors.toList()); return CollectionUtils.newObjectMap("totalCount", totalCount, "data", data); } public Map getVideoList(String type, String subColumn,int page, int size){ StringBuffer hql = new StringBuffer(500); hql.append( "from Information where deleteFlag=0 and type = ? and status= ? "); List params = CollectionUtils.newList(type, Information.UP_STATUS); // Map condition = CollectionUtils.newObjectMap("type", type, "status", Information.UP_STATUS); if (type.equals("examBriefing")) { hql.append( "and subColumn = ? "); params.add( subColumn); } long totalCount = findCount(hql.toString(),params); hql.append( "order by dateTime desc"); List articleList =findList(hql.toString(),new Pager(page,size),params,Information.class); List> data = articleList .stream() .map(article -> CollectionUtils.newObjectMap( "title", article.getTitle(), "type", article.getType(), "dateTime", article.getDateTime(), "videoUrl",article.getVideoUrl(), "name",article.getNumbers())) .collect(Collectors.toList()); return CollectionUtils.newObjectMap("totalCount", totalCount, "data", data); } // public boolean exist(String type) { String hql= "from Information where deleteFlag=0 and type = ? and status= ? "; long totalCount = findCount(hql,CollectionUtils.newList(type, Information.UP_STATUS)); return totalCount>0?true:false; } // public boolean existsubColumn(String type, String subColumn) { String hql= "from Information where deleteFlag=0 and type = ? and status= ? and subColumn=?"; long totalCount = findCount(hql,CollectionUtils.newList(type, Information.UP_STATUS,subColumn)); return totalCount>0?true:false; } public Map getPreAndBehindArticle(String currentArticleId, String type) { StringBuffer hql = new StringBuffer(500); hql.append("from Information where deleteFlag=0 and type = ? and status= ? order by updateTime desc"); List params = CollectionUtils.newList(type, Information.UP_STATUS); // Query query = Query.query(Criteria.where("type").is(type) // .and("status").is(ArticleDO.UP_STATUS) // .and("deleteFlag").is(false)) // .with(Sort.by(Sort.Direction.DESC, "updateTime")); // query.fields().include("id"); // List articleList =find(hql.toString(),params,Information.class); List articleIdList = find(hql.toString(),params,Information.class) .stream() .map(Information::getId) .collect(Collectors.toList()); int currentIndex = articleIdList.indexOf(currentArticleId); Map data = CollectionUtils.newObjectMap("previous", null, "behind", null); if (currentIndex != 0) { Information preArticle = read(Information.class,articleIdList.get(currentIndex - 1)); data.put("previous", CollectionUtils.newObjectMap( "id", preArticle.getId(), "title", preArticle.getTitle(), "type", preArticle.getType())); } if (currentIndex != articleIdList.size() - 1) { Information behindArticle = read(Information.class,articleIdList.get(currentIndex + 1)); data.put("previous", CollectionUtils.newObjectMap( "id", behindArticle.getId(), "title", behindArticle.getTitle(), "type", behindArticle.getType())); } return data; } // public void incBrowseCount(String id) { // Query query = Query.query(Criteria.where("id").is(id)); // Update update = new Update(); // update.inc("browseCount", 1); // template.updateFirst(query, update, clz); Information behindArticle = read(Information.class,id); behindArticle.setBrowseCount(behindArticle.getBrowseCount()+1); saveOrUpdate(behindArticle); } public Information getArticle(String type,String subColumn) { StringBuffer hql = new StringBuffer(500); hql.append( "from Information where deleteFlag=0 and type = ? and status= ? order by updateTime desc"); List params = CollectionUtils.newList(type, Information.UP_STATUS); if (type.equals("examBriefing")) { hql.append( "and subColumn = ? "); params.add( subColumn); } // Query query = Query.query(Criteria.where("type").is(type) // .and("status").is(ArticleDO.UP_STATUS) // .and("deleteFlag").is(false)) // .with(Sort.by(Sort.Direction.DESC, "updateTime")); // System.out.println(type); // if (type.equals("examBriefing")) { // query.addCriteria(Criteria.where("subColumn").is(subColumn)); // } Information articleDO = findUnique(hql.toString(), params, Information.class); // ArticleDO articleDO =findOne(query,ArticleDO.class); return articleDO; } }