package platform.modules.company.service; import java.util.ArrayList; import java.util.List; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import platform.common.Constant; import platform.common.base.model.DictionaryItem; import platform.common.base.service.BaseService; import platform.common.base.service.DictionaryItemService; import platform.common.util.WebUtil; import platform.modules.company.dao.ProcessFeedbackDao; import platform.modules.company.entity.ProcessFeedback; import platform.modules.company.entity.StockLand; import platform.modules.government.dao.AttachmentDao; import platform.modules.government.entity.Attachment; import platform.modules.government.entity.FileDown; import platform.modules.government.service.AttachmentService; import tk.mybatis.mapper.entity.Example; @Transactional @Service public class ProcessFeedbackService extends BaseService { @Autowired private AttachmentDao attachmentDao; @Autowired private DictionaryItemService dictionaryItemService; @Autowired private AttachmentService attachmentService; @Autowired private StockLandService stockLandService; @Autowired private ProcessFeedbackDao processFeedbackDao; public Boolean saveFeedback(ProcessFeedback feedback) { if (this.insertAndGetId(feedback) > 0) { //插入进程反馈材料 if(null != feedback.getFileDowns() && feedback.getFileDowns().size()>0) { for(FileDown file : feedback.getFileDowns()) { if(null != file && null !=file.getFile_id()) { attachmentDao.updateAttachment(Constant.Attachment.PROCESS_FEEDBACK, feedback.getId(), file.getFile_id()); } } } return true; } return false; } public Boolean updateFeedback(ProcessFeedback feedback) { if (this.updateSelective(feedback) > 0) { //插入进程反馈材料,删掉页面删除的旧材料 if(null != feedback.getFileDowns() && feedback.getFileDowns().size()>0) { List preAttachments = attachmentDao.selectByIdAndBusinessId(Constant.Attachment.PROCESS_FEEDBACK, feedback.getId(), null); for(FileDown file : feedback.getFileDowns()) { Attachment preFile = isPreAttachment(preAttachments,file); if(null != preFile) { //旧文件 //把没有删除的旧文件去除,剩下的就是页面已经删除的文件 preAttachments.remove(preFile); }else { //新上传的文件 List attachments = attachmentDao.selectByIdAndBusinessId(Constant.Attachment.PROCESS_FEEDBACK, feedback.getId(), file.getFile_id()); if (attachments.size() == 0) { //size为0,则是重新上传的文件,更新附件 attachmentDao.updateAttachment(Constant.Attachment.PROCESS_FEEDBACK, feedback.getId(), file.getFile_id()); } } } //删除页面上已经删除的文件 for(Attachment deletedFile : preAttachments) { attachmentDao.deleteByIdAndBusinessId(Constant.Attachment.PROCESS_FEEDBACK, feedback.getId(), deletedFile.getId()); } } return true; } return false; } //是不是上次上传的数据 public Attachment isPreAttachment(List preAttachments,FileDown file) { for(Attachment preFile : preAttachments) { if(file.getFile_id().equals(preFile.getId())) { return preFile; } } return null; } //进程反馈列表,带分页 public PageInfo findFeedbackListPage(Integer pageNum, Integer pageSize,String keyword , String type , Integer apply_id) { Example example = new Example(ProcessFeedback.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("del_flag", 0); criteria.andEqualTo("apply_id", apply_id); criteria.andEqualTo("type", type); //倒序 example.setOrderByClause("create_time desc"); PageHelper.startPage(pageNum, pageSize); List feedbacks = this.selectByExample(example); for(ProcessFeedback feedback : feedbacks) { getFullInfo(feedback); } return new PageInfo(feedbacks); } //进程反馈列表,不带分页,用于申请详情页面显示 public List findFeedbacksByTypeAndApplyId(String type,Integer apply_id){ Example example = new Example(ProcessFeedback.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("del_flag", 0); criteria.andEqualTo("apply_id", apply_id); criteria.andEqualTo("type", type); //顺序 example.setOrderByClause("create_time"); List feedbacks = this.selectByExample(example); for(ProcessFeedback feedback : feedbacks) { getFullInfo(feedback); } return feedbacks; } public ProcessFeedback findFeedBackById(Integer id) { ProcessFeedback feedback = this.findById(id); getFullInfo(feedback); return feedback; } public ProcessFeedback getFullInfo(ProcessFeedback feedback) { //判断是否可以编辑办理状态,只有最近一个进程反馈才可以编辑办理状态 if(isLastFeedback(feedback.getId())) { feedback.setIsLastFeedback(1); } if(StringUtils.isNotBlank(feedback.getProcess_status())) { feedback.setProcess_status_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROCESS_STATUS, feedback.getProcess_status())); } //绑定材料 List feedbackFiles = attachmentService.selectByIdAndBusinessId(Constant.Attachment.PROCESS_FEEDBACK,feedback.getId(),null); if(null != feedbackFiles && feedbackFiles.size()>0) { List fileDowns = new ArrayList(); for(int i = 0;i0) { if(!feedback.getProcess_status().equals(Constant.ProcessStatus.IN_PROGRESS)) { //如果删除的反馈状态的通过、不通过,则需要更新申请办理状态为进行中 StockLand apply = stockLandService.findById(feedback.getApply_id()); apply.setProcess_status(Constant.ProcessStatus.IN_PROGRESS); stockLandService.updateSelective(apply); } return true; } return false; } public Boolean isLastFeedback(Integer id) { //如果0,就是最后一条 return processFeedbackDao.getLaterFeedbackCount(id) == 0; } }