| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- package platform.modules.government.service;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import platform.common.Constant;
- import platform.common.base.service.BaseService;
- import platform.common.util.WebUtil;
- import platform.modules.government.dao.AttachmentDao;
- import platform.modules.government.dao.ContentDao;
- import platform.modules.government.entity.Attachment;
- import platform.modules.government.entity.Content;
- import platform.modules.government.entity.FileDown;
- import platform.modules.government.entity.Navigation;
- import platform.modules.home.request.FindRequest;
- import platform.modules.home.response.FindResponse;
- import tk.mybatis.mapper.entity.Example;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * 内容管理Service
- *
- * @author lhf
- * @version 2017-10-26
- */
- @Service
- @Transactional
- public class ContentService extends BaseService<Content> {
- @Autowired
- private NavigationService navigationService;
- @Autowired
- private AttachmentService attachmentService;
- @Autowired
- private ContentDao contentDao;
- @Autowired
- private AttachmentDao attachmentDao;
- @Transactional(readOnly = true)
- public PageInfo<Content> findPage(Integer pageNum, Integer pageSize, String param, Content searchCondition) throws Exception {
- Example example = new Example(Content.class);
- Example.Criteria criteria = example.createCriteria();
- if (StringUtils.isNotBlank(param)) {
- criteria.andLike("title", "%" + WebUtil.covertData(param) + "%");
- }
- if (null != searchCondition.getNavigation_id()) {
- criteria.andEqualTo("navigation_id", searchCondition.getNavigation_id());
- }
- //倒序
- example.orderBy("create_time").desc();
- PageHelper.startPage(pageNum, pageSize);
- List<Content> contents = this.selectByExample(example);
- for (Content content : contents) {
- Navigation navigation = navigationService.findById(content.getNavigation_id());
- if (null != navigation) {
- content.setNavigation_name(navigation.getName());
- }
- }
- return new PageInfo<Content>(contents);
- }
- public Boolean saveContent(Content Content) throws Exception {
- if (this.saveSelective(Content) == 1) {
- if (null != Content.getFileDown().getFile_id()) {
- attachmentDao.updateAttachment(Constant.Attachment.CONTENT, Content.getId(), Content.getFileDown().getFile_id());
- }
- if (null != Content.getAddFileDown().getFile_id()) {
- attachmentDao.updateAttachment(Constant.Attachment.CONTENT_FILE, Content.getId(), Content.getAddFileDown().getFile_id());
- }
- return true;
- }
- return false;
- }
- public Boolean updateContent(Content Content) throws Exception {
- if (this.updateSelective(Content) == 1) {
- attachmentDao.deleteByBusiness(Constant.Attachment.CONTENT, Content.getId());
- if (null != Content.getFileDown().getFile_id()) {
- attachmentDao.updateAttachment(Constant.Attachment.CONTENT, Content.getId(), Content.getFileDown().getFile_id());
- }
- attachmentDao.deleteByBusiness(Constant.Attachment.CONTENT_FILE, Content.getId());
- if (null != Content.getAddFileDown().getFile_id()) {
- attachmentDao.updateAttachment(Constant.Attachment.CONTENT_FILE, Content.getId(), Content.getAddFileDown().getFile_id());
- }
- return true;
- }
- return false;
- }
- //首页通知公告
- @Transactional(readOnly = true)
- public PageInfo<Content> findPageByNavigationId(Integer pageNum, Integer pageSize, String param, Integer navigation_id) throws Exception {
- Example example = new Example(Content.class);
- Example.Criteria criteria = example.createCriteria();
- if (StringUtils.isNotBlank(param)) {
- criteria.andLike("title", "%" + WebUtil.covertData(param) + "%");
- }
- criteria.andEqualTo("navigation_id", navigation_id);
- //倒序
- example.orderBy("sort").asc();
- example.orderBy("create_time").desc();
- PageHelper.startPage(pageNum, pageSize);
- List<Content> contents = this.selectByExample(example);
- for (Content content : contents) {
- Navigation navigation = navigationService.findById(content.getNavigation_id());
- if (null != navigation) {
- content.setNavigation_name(navigation.getName());
- }
- }
- return new PageInfo<Content>(contents);
- }
- public List<Content> findContentsByNavigationId(Integer navigation_id) {
- Example example = new Example(Content.class);
- Example.Criteria criteria = example.createCriteria();
- criteria.andEqualTo("navigation_id", navigation_id);//通知公告
- criteria.andEqualTo("is_start", 1);
- criteria.andEqualTo("del_flag", 0);
- example.orderBy("is_top").desc();
- example.orderBy("sort").asc();
- example.orderBy("create_time").desc();
- PageHelper.startPage(1, 5);
- List<Content> contents = this.selectByExample(example);
- return contents;
- }
- public List<Content> findContentsByNavigationId() {
- List<Content> contents = contentDao.findContentsByNavigationId();
- for (Content content : contents) {
- List<Attachment> attachments = attachmentService.selectByIdAndBusinessId(Constant.Attachment.CONTENT, content.getId(), null);
- if (null != attachments && attachments.size() > 0) {
- FileDown fileDown = new FileDown(attachments.get(0).getId(), attachments.get(0).getFile_name(), attachments.get(0).getFile_url(), attachments.get(0).getDownload_uri());
- content.setFileDown(fileDown);
- }
- }
- return contents;
- }
- public FindResponse findContents(FindRequest request) {
- FindResponse response = new FindResponse();
- List<Content> contents = new ArrayList<>();
- int lastPageNumber = 1;
- int count = contentDao.findContentsCount(request);
- if (count > 0) {
- // 处理分页参数
- if (request.getPage_size() > 0) {
- //如果输入的页码大于实际的分页数,将页码设置为最后一页的页码
- lastPageNumber = (int) ((count - 1) / request.getPage_size() + 1);
- if (request.getPage_number() > lastPageNumber) {
- request.setPage_no(lastPageNumber);
- }
- }
- contents = contentDao.findContents(request);
- }
- response.setContents(contents);
- response.setCounts(count);
- response.setPage_no(request.getPage_no());
- return response;
- }
- public Integer countContent() {
- return contentDao.countContent();
- }
- public List<Content> findContentsByNavigationIdForIndex(Integer id) {
- return contentDao.findContentsByNavigationIdForIndex(id);
- }
-
- public Integer findContentsCount(FindRequest request) {
- return contentDao.findContentsCount(request);
- }
- /**
- * 获取门户消息
- * 、
- * @param request
- * @return
- */
- public List<Content> findContentList(FindRequest request) {
- return contentDao.findContentList(request);
- }
- }
|