| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- 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<ProcessFeedback> {
- @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<Attachment> 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<Attachment> 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<Attachment> preAttachments,FileDown file) {
- for(Attachment preFile : preAttachments) {
- if(file.getFile_id().equals(preFile.getId())) {
- return preFile;
- }
- }
- return null;
- }
-
- //进程反馈列表,带分页
- public PageInfo<ProcessFeedback> 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<ProcessFeedback> feedbacks = this.selectByExample(example);
- for(ProcessFeedback feedback : feedbacks) {
- getFullInfo(feedback);
- }
- return new PageInfo<ProcessFeedback>(feedbacks);
- }
-
- //进程反馈列表,不带分页,用于申请详情页面显示
- public List<ProcessFeedback> 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<ProcessFeedback> 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<Attachment> feedbackFiles = attachmentService.selectByIdAndBusinessId(Constant.Attachment.PROCESS_FEEDBACK,feedback.getId(),null);
- if(null != feedbackFiles && feedbackFiles.size()>0) {
- List<FileDown> fileDowns = new ArrayList<FileDown>();
- for(int i = 0;i<feedbackFiles.size();i++) {
- FileDown fileDown = new FileDown(feedbackFiles.get(i).getId(), feedbackFiles.get(i).getFile_name(), feedbackFiles.get(i).getFile_url(),feedbackFiles.get(0).getDownload_uri());
- fileDowns.add(fileDown);
- }
- feedback.setFileDowns(fileDowns);
- }
- return feedback;
- }
- public Boolean deleteFeedback(Integer id) {
- ProcessFeedback feedback = this.findById(id);
- feedback.setDel_flag(true);
- if(this.updateSelective(feedback)>0) {
- 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;
- }
- }
|