SlidesService.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. slide.setFileDown(new FileDown(attachment.getId(), attachment.getFile_name(), attachment.getFile_url(), attachment.getDownload_uri()));
  62. }
  63. return new PageInfo<>(Slides);
  64. }
  65. public Boolean saveSlides(Slides slides) throws Exception {
  66. if (this.saveSelective(slides) == 1) {
  67. attachmentDao.updateAttachment(Constant.Attachment.SLIDES, slides.getId(),
  68. slides.getFileDown().getFile_id());
  69. return true;
  70. }
  71. return false;
  72. }
  73. public Boolean updateSlides(Slides slides) throws Exception {
  74. if (this.updateSelective(slides) == 1) {
  75. if(null!=slides.getFileDown().getFile_id()) {
  76. attachmentDao.deleteByBusiness(Constant.Attachment.SLIDES, slides.getId());
  77. attachmentDao.updateAttachment(Constant.Attachment.SLIDES, slides.getId(),
  78. slides.getFileDown().getFile_id());
  79. }
  80. return true;
  81. }
  82. return false;
  83. }
  84. public Boolean deleteSlidesByIds(String ids) throws Exception {
  85. if (this.deleteByIds(ids) == 1) {
  86. return true;
  87. }
  88. return false;
  89. }
  90. public List<HomeSlideDto> showHomeSlides() {
  91. Example example = new Example(Slides.class);
  92. Example.Criteria criteria = example.createCriteria();
  93. criteria.andEqualTo("del_flag", "0");
  94. criteria.andEqualTo("is_start", "1");
  95. // 倒序
  96. example.orderBy("sort").asc();
  97. List<HomeSlideDto> slideDtoList = new ArrayList<>();
  98. List<Slides> Slides = this.selectByExample(example);
  99. if (Slides.size() > 0) {
  100. for (Slides slides : Slides) {
  101. HomeSlideDto homeSlideDto = new HomeSlideDto();
  102. List<Attachment> attashMemtList = attachmentDao.selectByIdAndBusinessId(Constant.Attachment.SLIDES,
  103. slides.getId(), null);
  104. if (attashMemtList.size() > 0) {
  105. homeSlideDto.setImagUrl(attashMemtList.get(0).getFile_url());
  106. }
  107. homeSlideDto.setIsLink(slides.getIs_link());
  108. if(slides.getIs_link()){
  109. homeSlideDto.setLinkLocation(slides.getHref());
  110. }else{
  111. homeSlideDto.setLinkLocation("javascript:return false;");
  112. }
  113. slideDtoList.add(homeSlideDto);
  114. }
  115. }
  116. return slideDtoList;
  117. }
  118. }