12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package com.yihu.editor.service;
- import com.yihu.editor.dao.ArticleDao;
- import com.yihu.editor.entity.SystemDictItem;
- import com.yihu.editor.entity.YdfHealthEduArticle;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.domain.Page;
- import org.springframework.data.domain.PageRequest;
- import org.springframework.data.domain.Sort;
- import org.springframework.data.jpa.domain.Specification;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springside.modules.persistence.DynamicSpecifications;
- import org.springside.modules.persistence.SearchFilter;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * Created by Administrator on 2017/6/11 0011.
- */
- @Service
- @Transactional
- public class FeedbackService {
- @Autowired
- private ArticleDao articleDao;
- public Page<YdfHealthEduArticle> findFeedback(int page, int rows, int type, int identity, int status) {
- if (page <= 0) {
- page = 1;
- }
- if (rows <= 0) {
- rows = 15;
- }
- // 排序
- Sort sort = new Sort(Sort.Direction.DESC, "id");
- // 分页信息
- PageRequest pageRequest = new PageRequest(page - 1, rows, sort);
- // 设置查询条件
- Map<String, SearchFilter> filters = new HashMap<>();
- if (type!=-1) {
- filters.put("type", new SearchFilter("type", SearchFilter.Operator.EQ, type));
- }
- if (identity!=-1) {
- filters.put("identity", new SearchFilter("identity", SearchFilter.Operator.EQ, identity));
- }
- if (status!=-1) {
- filters.put("status", new SearchFilter("status", SearchFilter.Operator.EQ, status));
- }
- Specification<YdfHealthEduArticle> spec = DynamicSpecifications.bySearchFilter(filters.values(), YdfHealthEduArticle.class);
- return articleDao.findAll(spec, pageRequest);
- }
- public void save(YdfHealthEduArticle article){
- articleDao.save(article);
- }
- public List<SystemDictItem> findHealthEduArticleTypeList() {
- return articleDao.findByDict("4");
- }
- }
|