LogoService.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.government.dao.AttachmentDao;
  10. import platform.modules.government.dao.LogoDao;
  11. import platform.modules.government.entity.Attachment;
  12. import platform.modules.government.entity.FileDown;
  13. import platform.modules.government.entity.Logo;
  14. import tk.mybatis.mapper.entity.Example;
  15. import java.util.List;
  16. /**
  17. * 首页logService
  18. *
  19. * @author lhf
  20. * @version 2017-10-26
  21. */
  22. @Service
  23. @Transactional
  24. public class LogoService extends BaseService<Logo> {
  25. @Autowired
  26. LogoDao logoDao;
  27. @Autowired
  28. private AttachmentDao attachmentDao;
  29. @Autowired
  30. private AttachmentService attachmentService;
  31. @Transactional(readOnly = true)
  32. public PageInfo<Logo> findPage(Integer pageNum, Integer pageSize) throws Exception {
  33. Example example = new Example(Logo.class);
  34. Example.Criteria criteria = example.createCriteria();
  35. criteria.andEqualTo("del_flag", 0);
  36. // 倒序
  37. example.orderBy("is_start").desc();
  38. example.orderBy("create_time").desc();
  39. PageHelper.startPage(pageNum, pageSize);
  40. List<Logo> Logo = this.selectByExample(example);
  41. for (Logo logo : Logo) {
  42. List<Attachment> attachments = attachmentService.selectByIdAndBusinessId(Constant.Attachment.LOGO, logo.getId(), null);
  43. if (null != attachments && attachments.size() > 0) {
  44. FileDown fileDown = new FileDown(attachments.get(0).getId(), attachments.get(0).getFile_name(), attachments.get(0).getFile_url(),attachments.get(0).getDownload_uri());
  45. logo.setFileDown(fileDown);
  46. }
  47. }
  48. return new PageInfo<Logo>(Logo);
  49. }
  50. public Logo findLogo() {
  51. Example example = new Example(Logo.class);
  52. Example.Criteria criteria = example.createCriteria();
  53. criteria.andEqualTo("del_flag", 0);
  54. criteria.andEqualTo("is_start", 1);
  55. example.orderBy("create_time").desc();
  56. List<Logo> logo = this.selectByExample(example);
  57. if (null != logo) {
  58. Logo lo = logo.get(0);
  59. List<Attachment> attachments = attachmentService.selectByIdAndBusinessId(Constant.Attachment.LOGO, lo.getId(), null);
  60. if (null != attachments && attachments.size() > 0) {
  61. FileDown fileDown = new FileDown(attachments.get(0).getId(), attachments.get(0).getFile_name(), attachments.get(0).getFile_url(),attachments.get(0).getDownload_uri());
  62. lo.setFileDown(fileDown);
  63. }
  64. return lo;
  65. }
  66. return null;
  67. }
  68. public Boolean saveLogo(Logo logo) throws Exception {
  69. if (this.insertAndGetId(logo) > 0) {
  70. //更新其他logo
  71. if(null!=logo.getIs_start()&&logo.getIs_start()){
  72. logoDao.updateOtherLogo(logo.getId());
  73. }
  74. attachmentDao.deleteByBusiness(Constant.Attachment.LOGO, logo.getId());
  75. attachmentDao.updateAttachment(Constant.Attachment.LOGO, logo.getId(), logo.getFileDown().getFile_id());
  76. return true;
  77. }
  78. return false;
  79. }
  80. public Boolean updateLogo(Logo logo) throws Exception {
  81. if (this.updateSelective(logo) == 1) {
  82. //更新其他logo
  83. if(null!=logo.getIs_start()&&logo.getIs_start()){
  84. logoDao.updateOtherLogo(logo.getId());
  85. }
  86. if(null!=logo.getFileDown().getFile_id()) {
  87. attachmentDao.deleteByBusiness(Constant.Attachment.LOGO, logo.getId());
  88. attachmentDao.updateAttachment(Constant.Attachment.LOGO, logo.getId(), logo.getFileDown().getFile_id());
  89. }
  90. return true;
  91. }
  92. return false;
  93. }
  94. public Boolean deleteLogoByIds(String ids) throws Exception {
  95. if (this.deleteByIds(ids) == 1) {
  96. return true;
  97. }
  98. return false;
  99. }
  100. public int findStartLogo() {
  101. Example example = new Example(Logo.class);
  102. Example.Criteria criteria = example.createCriteria();
  103. criteria.andEqualTo("del_flag", 0);
  104. criteria.andEqualTo("is_start", 1);
  105. List<Logo> Logo = this.selectByExample(example);
  106. return Logo == null ? 0 : Logo.size();
  107. }
  108. public void updateOtherLogo(Integer id) throws Exception {
  109. logoDao.updateOtherLogo(id);
  110. }
  111. public Integer countLogo(Integer id) throws Exception {
  112. return logoDao.countLogo(id);
  113. }
  114. }