ProcessFeedbackService.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package platform.modules.company.service;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import org.apache.commons.lang3.StringUtils;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Service;
  7. import org.springframework.transaction.annotation.Transactional;
  8. import com.github.pagehelper.PageHelper;
  9. import com.github.pagehelper.PageInfo;
  10. import platform.common.Constant;
  11. import platform.common.base.model.DictionaryItem;
  12. import platform.common.base.service.BaseService;
  13. import platform.common.base.service.DictionaryItemService;
  14. import platform.common.util.WebUtil;
  15. import platform.modules.company.dao.ProcessFeedbackDao;
  16. import platform.modules.company.entity.ProcessFeedback;
  17. import platform.modules.company.entity.StockLand;
  18. import platform.modules.government.dao.AttachmentDao;
  19. import platform.modules.government.entity.Attachment;
  20. import platform.modules.government.entity.FileDown;
  21. import platform.modules.government.service.AttachmentService;
  22. import tk.mybatis.mapper.entity.Example;
  23. @Transactional
  24. @Service
  25. public class ProcessFeedbackService extends BaseService<ProcessFeedback> {
  26. @Autowired
  27. private AttachmentDao attachmentDao;
  28. @Autowired
  29. private DictionaryItemService dictionaryItemService;
  30. @Autowired
  31. private AttachmentService attachmentService;
  32. @Autowired
  33. private StockLandService stockLandService;
  34. @Autowired
  35. private ProcessFeedbackDao processFeedbackDao;
  36. public Boolean saveFeedback(ProcessFeedback feedback) {
  37. if (this.insertAndGetId(feedback) > 0) {
  38. //插入进程反馈材料
  39. if(null != feedback.getFileDowns() && feedback.getFileDowns().size()>0) {
  40. for(FileDown file : feedback.getFileDowns()) {
  41. if(null != file && null !=file.getFile_id()) {
  42. attachmentDao.updateAttachment(Constant.Attachment.PROCESS_FEEDBACK, feedback.getId(), file.getFile_id());
  43. }
  44. }
  45. }
  46. return true;
  47. }
  48. return false;
  49. }
  50. public Boolean updateFeedback(ProcessFeedback feedback) {
  51. if (this.updateSelective(feedback) > 0) {
  52. //插入进程反馈材料,删掉页面删除的旧材料
  53. if(null != feedback.getFileDowns() && feedback.getFileDowns().size()>0) {
  54. List<Attachment> preAttachments = attachmentDao.selectByIdAndBusinessId(Constant.Attachment.PROCESS_FEEDBACK, feedback.getId(), null);
  55. for(FileDown file : feedback.getFileDowns()) {
  56. Attachment preFile = isPreAttachment(preAttachments,file);
  57. if(null != preFile) {
  58. //旧文件
  59. //把没有删除的旧文件去除,剩下的就是页面已经删除的文件
  60. preAttachments.remove(preFile);
  61. }else {
  62. //新上传的文件
  63. List<Attachment> attachments = attachmentDao.selectByIdAndBusinessId(Constant.Attachment.PROCESS_FEEDBACK, feedback.getId(), file.getFile_id());
  64. if (attachments.size() == 0) {
  65. //size为0,则是重新上传的文件,更新附件
  66. attachmentDao.updateAttachment(Constant.Attachment.PROCESS_FEEDBACK, feedback.getId(), file.getFile_id());
  67. }
  68. }
  69. }
  70. //删除页面上已经删除的文件
  71. for(Attachment deletedFile : preAttachments) {
  72. attachmentDao.deleteByIdAndBusinessId(Constant.Attachment.PROCESS_FEEDBACK, feedback.getId(), deletedFile.getId());
  73. }
  74. }
  75. return true;
  76. }
  77. return false;
  78. }
  79. //是不是上次上传的数据
  80. public Attachment isPreAttachment(List<Attachment> preAttachments,FileDown file) {
  81. for(Attachment preFile : preAttachments) {
  82. if(file.getFile_id().equals(preFile.getId())) {
  83. return preFile;
  84. }
  85. }
  86. return null;
  87. }
  88. //进程反馈列表,带分页
  89. public PageInfo<ProcessFeedback> findFeedbackListPage(Integer pageNum, Integer pageSize,String keyword , String type , Integer apply_id) {
  90. Example example = new Example(ProcessFeedback.class);
  91. Example.Criteria criteria = example.createCriteria();
  92. criteria.andEqualTo("del_flag", 0);
  93. criteria.andEqualTo("apply_id", apply_id);
  94. criteria.andEqualTo("type", type);
  95. //倒序
  96. example.setOrderByClause("create_time desc");
  97. PageHelper.startPage(pageNum, pageSize);
  98. List<ProcessFeedback> feedbacks = this.selectByExample(example);
  99. for(ProcessFeedback feedback : feedbacks) {
  100. getFullInfo(feedback);
  101. }
  102. return new PageInfo<ProcessFeedback>(feedbacks);
  103. }
  104. //进程反馈列表,不带分页,用于申请详情页面显示
  105. public List<ProcessFeedback> findFeedbacksByTypeAndApplyId(String type,Integer apply_id){
  106. Example example = new Example(ProcessFeedback.class);
  107. Example.Criteria criteria = example.createCriteria();
  108. criteria.andEqualTo("del_flag", 0);
  109. criteria.andEqualTo("apply_id", apply_id);
  110. criteria.andEqualTo("type", type);
  111. //顺序
  112. example.setOrderByClause("create_time");
  113. List<ProcessFeedback> feedbacks = this.selectByExample(example);
  114. for(ProcessFeedback feedback : feedbacks) {
  115. getFullInfo(feedback);
  116. }
  117. return feedbacks;
  118. }
  119. public ProcessFeedback findFeedBackById(Integer id) {
  120. ProcessFeedback feedback = this.findById(id);
  121. getFullInfo(feedback);
  122. return feedback;
  123. }
  124. public ProcessFeedback getFullInfo(ProcessFeedback feedback) {
  125. //判断是否可以编辑办理状态,只有最近一个进程反馈才可以编辑办理状态
  126. if(isLastFeedback(feedback.getId())) {
  127. feedback.setIsLastFeedback(1);
  128. }
  129. if(StringUtils.isNotBlank(feedback.getProcess_status())) {
  130. feedback.setProcess_status_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROCESS_STATUS, feedback.getProcess_status()));
  131. }
  132. //绑定材料
  133. List<Attachment> feedbackFiles = attachmentService.selectByIdAndBusinessId(Constant.Attachment.PROCESS_FEEDBACK,feedback.getId(),null);
  134. if(null != feedbackFiles && feedbackFiles.size()>0) {
  135. List<FileDown> fileDowns = new ArrayList<FileDown>();
  136. for(int i = 0;i<feedbackFiles.size();i++) {
  137. FileDown fileDown = new FileDown(feedbackFiles.get(i).getId(), feedbackFiles.get(i).getFile_name(), feedbackFiles.get(i).getFile_url(),feedbackFiles.get(0).getDownload_uri());
  138. fileDowns.add(fileDown);
  139. }
  140. feedback.setFileDowns(fileDowns);
  141. }
  142. return feedback;
  143. }
  144. public Boolean deleteFeedback(Integer id) {
  145. ProcessFeedback feedback = this.findById(id);
  146. feedback.setDel_flag(true);
  147. if(this.updateSelective(feedback)>0) {
  148. if(!feedback.getProcess_status().equals(Constant.ProcessStatus.IN_PROGRESS)) {
  149. //如果删除的反馈状态的通过、不通过,则需要更新申请办理状态为进行中
  150. StockLand apply = stockLandService.findById(feedback.getApply_id());
  151. apply.setProcess_status(Constant.ProcessStatus.IN_PROGRESS);
  152. stockLandService.updateSelective(apply);
  153. }
  154. return true;
  155. }
  156. return false;
  157. }
  158. public Boolean isLastFeedback(Integer id) {
  159. //如果0,就是最后一条
  160. return processFeedbackDao.getLaterFeedbackCount(id) == 0;
  161. }
  162. }