package platform.modules.government.service; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; 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.modules.build.DTO.HomeSlideDto; import platform.modules.government.dao.AttachmentDao; import platform.modules.government.entity.Attachment; import platform.modules.government.entity.FileDown; import platform.modules.government.entity.Slides; 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 SlidesService extends BaseService { @Autowired private AttachmentService attachmentService; @Autowired private AttachmentDao attachmentDao; @Transactional(readOnly = true) public PageInfo findPage(Integer pageNum, Integer pageSize) throws Exception { Example example = new Example(Slides.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("del_flag", "0"); /* * if(StringUtils.isNotBlank(param)) { criteria.andLike("title", "%" + * param + "%"); } */ // 倒序 example.orderBy("create_time").desc(); PageHelper.startPage(pageNum, pageSize); List Slides = this.selectByExample(example); for (Slides slide : Slides) { Attachment attachment = attachmentService.findByBizIdAndBizType(slide.getId(), Constant.Attachment.SLIDES); slide.setFileDown(new FileDown(attachment.getId(), attachment.getFile_name(), attachment.getFile_url(), attachment.getDownload_uri())); } return new PageInfo<>(Slides); } @Transactional(readOnly = true) public PageInfo findFrontPage(Integer pageNum, Integer pageSize) throws Exception { Example example = new Example(Slides.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("del_flag", "0"); criteria.andEqualTo("is_start", "1"); // 倒序 example.orderBy("create_time").desc(); PageHelper.startPage(pageNum, pageSize); List Slides = this.selectByExample(example); for (Slides slide : Slides) { Attachment attachment = attachmentService.findByBizIdAndBizType(slide.getId(), Constant.Attachment.SLIDES); if(attachment!=null){ slide.setFileDown(new FileDown(attachment.getId(), attachment.getFile_name(), attachment.getFile_url(), attachment.getDownload_uri())); } } return new PageInfo<>(Slides); } public Boolean saveSlides(Slides slides) throws Exception { if (this.saveSelective(slides) == 1) { attachmentDao.updateAttachment(Constant.Attachment.SLIDES, slides.getId(), slides.getFileDown().getFile_id()); return true; } return false; } public Boolean updateSlides(Slides slides) throws Exception { if (this.updateSelective(slides) == 1) { if(null!=slides.getFileDown().getFile_id()) { attachmentDao.deleteByBusiness(Constant.Attachment.SLIDES, slides.getId()); attachmentDao.updateAttachment(Constant.Attachment.SLIDES, slides.getId(), slides.getFileDown().getFile_id()); } return true; } return false; } public Boolean deleteSlidesByIds(String ids) throws Exception { if (this.deleteByIds(ids) == 1) { return true; } return false; } public List showHomeSlides() { Example example = new Example(Slides.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("del_flag", "0"); criteria.andEqualTo("is_start", "1"); // 倒序 example.orderBy("sort").asc(); List slideDtoList = new ArrayList<>(); List Slides = this.selectByExample(example); if (Slides.size() > 0) { for (Slides slides : Slides) { HomeSlideDto homeSlideDto = new HomeSlideDto(); List attashMemtList = attachmentDao.selectByIdAndBusinessId(Constant.Attachment.SLIDES, slides.getId(), null); if (attashMemtList.size() > 0) { homeSlideDto.setImagUrl(attashMemtList.get(0).getFile_url()); } homeSlideDto.setIsLink(slides.getIs_link()); if(slides.getIs_link()){ homeSlideDto.setLinkLocation(slides.getHref()); }else{ homeSlideDto.setLinkLocation("javascript:return false;"); } slideDtoList.add(homeSlideDto); } } return slideDtoList; } }