SlidesService.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package platform.modules.government.service;
  2. import com.github.pagehelper.PageHelper;
  3. import com.github.pagehelper.PageInfo;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Service;
  6. import org.springframework.transaction.annotation.Transactional;
  7. import platform.common.Constant;
  8. import platform.common.base.service.BaseService;
  9. import platform.modules.build.DTO.HomeSlideDto;
  10. import platform.modules.government.dao.AttachmentDao;
  11. import platform.modules.government.entity.Attachment;
  12. import platform.modules.government.entity.FileDown;
  13. import platform.modules.government.entity.Slides;
  14. import tk.mybatis.mapper.entity.Example;
  15. import java.util.ArrayList;
  16. import java.util.List;
  17. /**
  18. * 幻灯片管理Service
  19. *
  20. * @author lhf
  21. * @version 2017-10-26
  22. */
  23. @Service
  24. @Transactional
  25. public class SlidesService extends BaseService<Slides> {
  26. @Autowired
  27. private AttachmentService attachmentService;
  28. @Autowired
  29. private AttachmentDao attachmentDao;
  30. @Transactional(readOnly = true)
  31. public PageInfo<Slides> findPage(Integer pageNum, Integer pageSize) throws Exception {
  32. Example example = new Example(Slides.class);
  33. Example.Criteria criteria = example.createCriteria();
  34. criteria.andEqualTo("del_flag", "0");
  35. /*
  36. * if(StringUtils.isNotBlank(param)) { criteria.andLike("title", "%" +
  37. * param + "%"); }
  38. */
  39. // 倒序
  40. example.orderBy("create_time").desc();
  41. PageHelper.startPage(pageNum, pageSize);
  42. List<Slides> Slides = this.selectByExample(example);
  43. for (Slides slide : Slides) {
  44. Attachment attachment = attachmentService.findByBizIdAndBizType(slide.getId(), Constant.Attachment.SLIDES);
  45. slide.setFileDown(new FileDown(attachment.getId(), attachment.getFile_name(), attachment.getFile_url(), attachment.getDownload_uri()));
  46. }
  47. return new PageInfo<>(Slides);
  48. }
  49. @Transactional(readOnly = true)
  50. public PageInfo<Slides> findFrontPage(Integer pageNum, Integer pageSize) throws Exception {
  51. Example example = new Example(Slides.class);
  52. Example.Criteria criteria = example.createCriteria();
  53. criteria.andEqualTo("del_flag", "0");
  54. criteria.andEqualTo("is_start", "1");
  55. // 倒序
  56. example.orderBy("create_time").desc();
  57. PageHelper.startPage(pageNum, pageSize);
  58. List<Slides> Slides = this.selectByExample(example);
  59. for (Slides slide : Slides) {
  60. Attachment attachment = attachmentService.findByBizIdAndBizType(slide.getId(), Constant.Attachment.SLIDES);
  61. if(attachment!=null){
  62. slide.setFileDown(new FileDown(attachment.getId(), attachment.getFile_name(), attachment.getFile_url(), attachment.getDownload_uri()));
  63. }
  64. }
  65. return new PageInfo<>(Slides);
  66. }
  67. public Boolean saveSlides(Slides slides) throws Exception {
  68. if (this.saveSelective(slides) == 1) {
  69. attachmentDao.updateAttachment(Constant.Attachment.SLIDES, slides.getId(),
  70. slides.getFileDown().getFile_id());
  71. return true;
  72. }
  73. return false;
  74. }
  75. public Boolean updateSlides(Slides slides) throws Exception {
  76. if (this.updateSelective(slides) == 1) {
  77. if(null!=slides.getFileDown().getFile_id()) {
  78. attachmentDao.deleteByBusiness(Constant.Attachment.SLIDES, slides.getId());
  79. attachmentDao.updateAttachment(Constant.Attachment.SLIDES, slides.getId(),
  80. slides.getFileDown().getFile_id());
  81. }
  82. return true;
  83. }
  84. return false;
  85. }
  86. public Boolean deleteSlidesByIds(String ids) throws Exception {
  87. if (this.deleteByIds(ids) == 1) {
  88. return true;
  89. }
  90. return false;
  91. }
  92. public List<HomeSlideDto> showHomeSlides() {
  93. Example example = new Example(Slides.class);
  94. Example.Criteria criteria = example.createCriteria();
  95. criteria.andEqualTo("del_flag", "0");
  96. criteria.andEqualTo("is_start", "1");
  97. // 倒序
  98. example.orderBy("sort").asc();
  99. List<HomeSlideDto> slideDtoList = new ArrayList<>();
  100. List<Slides> Slides = this.selectByExample(example);
  101. if (Slides.size() > 0) {
  102. for (Slides slides : Slides) {
  103. HomeSlideDto homeSlideDto = new HomeSlideDto();
  104. List<Attachment> attashMemtList = attachmentDao.selectByIdAndBusinessId(Constant.Attachment.SLIDES,
  105. slides.getId(), null);
  106. if (attashMemtList.size() > 0) {
  107. homeSlideDto.setImagUrl(attashMemtList.get(0).getFile_url());
  108. }
  109. homeSlideDto.setIsLink(slides.getIs_link());
  110. if(slides.getIs_link()){
  111. homeSlideDto.setLinkLocation(slides.getHref());
  112. }else{
  113. homeSlideDto.setLinkLocation("javascript:return false;");
  114. }
  115. slideDtoList.add(homeSlideDto);
  116. }
  117. }
  118. return slideDtoList;
  119. }
  120. }