FeedbackService.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.yihu.editor.service;
  2. import com.yihu.editor.dao.ArticleDao;
  3. import com.yihu.editor.entity.SystemDictItem;
  4. import com.yihu.editor.entity.YdfHealthEduArticle;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.data.domain.Page;
  7. import org.springframework.data.domain.PageRequest;
  8. import org.springframework.data.domain.Sort;
  9. import org.springframework.data.jpa.domain.Specification;
  10. import org.springframework.stereotype.Service;
  11. import org.springframework.transaction.annotation.Transactional;
  12. import org.springside.modules.persistence.DynamicSpecifications;
  13. import org.springside.modules.persistence.SearchFilter;
  14. import java.util.HashMap;
  15. import java.util.List;
  16. import java.util.Map;
  17. /**
  18. * Created by Administrator on 2017/6/11 0011.
  19. */
  20. @Service
  21. @Transactional
  22. public class FeedbackService {
  23. @Autowired
  24. private ArticleDao articleDao;
  25. public Page<YdfHealthEduArticle> findFeedback(int page, int rows, int type, int identity, int status) {
  26. if (page <= 0) {
  27. page = 1;
  28. }
  29. if (rows <= 0) {
  30. rows = 15;
  31. }
  32. // 排序
  33. Sort sort = new Sort(Sort.Direction.DESC, "id");
  34. // 分页信息
  35. PageRequest pageRequest = new PageRequest(page - 1, rows, sort);
  36. // 设置查询条件
  37. Map<String, SearchFilter> filters = new HashMap<>();
  38. if (type!=-1) {
  39. filters.put("type", new SearchFilter("type", SearchFilter.Operator.EQ, type));
  40. }
  41. if (identity!=-1) {
  42. filters.put("identity", new SearchFilter("identity", SearchFilter.Operator.EQ, identity));
  43. }
  44. if (status!=-1) {
  45. filters.put("status", new SearchFilter("status", SearchFilter.Operator.EQ, status));
  46. }
  47. Specification<YdfHealthEduArticle> spec = DynamicSpecifications.bySearchFilter(filters.values(), YdfHealthEduArticle.class);
  48. return articleDao.findAll(spec, pageRequest);
  49. }
  50. public void save(YdfHealthEduArticle article){
  51. articleDao.save(article);
  52. }
  53. public List<SystemDictItem> findHealthEduArticleTypeList() {
  54. return articleDao.findByDict("4");
  55. }
  56. }