package platform.modules.sys.service; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.github.pagehelper.PageHelper; import org.springframework.transaction.annotation.Transactional; import platform.common.Constant; import platform.common.base.model.BaseEntity; import platform.common.base.model.DictionaryItem; import platform.common.base.service.BaseService; import platform.common.base.service.DictionaryItemService; import platform.common.util.ShiroUtils; import platform.common.util.WebUtil; import platform.modules.company.service.StockLandService; import platform.modules.government.dao.AttachmentDao; import platform.modules.government.dto.*; import platform.modules.government.entity.Attachment; import platform.modules.government.entity.FileDown; import platform.modules.government.entity.User; import platform.modules.government.service.AttachmentService; import platform.modules.government.service.UserService; import platform.modules.sys.dao.ApprovalDao; import platform.modules.sys.entity.Approval; import platform.modules.sys.entity.Department; import tk.mybatis.mapper.entity.Example; @Service public class ApprovalService extends BaseService { @Autowired private ApprovalDao approvalDao; @Autowired private DictionaryItemService dictionaryItemService; @Autowired private AttachmentService attachmentService; @Autowired private StockLandService stockLandService; @Autowired private UserService userService; @Autowired private DepartmentService departmentService; public Approval getLatestApproval(Integer apply_id, String type) { return approvalDao.getLatestApproval(apply_id, type); } //查找最近一条审核记录,含撤回的记录 不判断del_flag public Approval getLatestApprovalAll(Integer apply_id, String type) { return approvalDao.getLatestApprovalAll(apply_id, type); } //获取存量用地审核流程数据 public List getApprovalList(Integer apply_id) { //合规性审查只能看到自己部门的审核信息 //1.查出合规性审查小组的userId,根据审核流程来查找 String userIds = stockLandService.findComplianceAuditUserIds(apply_id); String[] userIdArr = userIds.split(","); Example example = new Example(Approval.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("type", Constant.DictionaryType.STOCKLAND); criteria.andEqualTo("del_flag", false); criteria.andEqualTo("apply_id", apply_id); List approvals = this.selectByExample(example); //如果当前用户是合规性审查小组成员,查出当前用户所属的部门id List list = Arrays.asList(userIdArr); int currentUserId = ShiroUtils.getUserId(); if (ShiroUtils.getUserType().equals(Constant.UserType.GOVERNMENT)) { if (list.contains(String.valueOf(currentUserId))) { Integer departmentId = userService.findDepartmentIdByUserId(currentUserId); if (null != departmentId) { approvals = approvals.stream().filter(approval -> !(null != approval.getChecker() && !departmentId.equals(userService.findDepartmentIdByUserId(approval.getChecker())) && null != approval.getBefore_approvalstatus() && approval.getBefore_approvalstatus().equals(Constant.LandApproveStatus.COMPLIANCE_AUDIT))).collect(Collectors.toList()); } } //排序 合规性审核 按照部门排序 approvals = approvals.stream().sorted((x, y) -> { if (x.getBefore_approvalstatus().equals(Constant.LandApproveStatus.COMPLIANCE_AUDIT) && y.getBefore_approvalstatus().equals(Constant.LandApproveStatus.COMPLIANCE_AUDIT)) { return x.getDepartment().compareTo(y.getDepartment()); } else { return x.getCreate_time().compareTo(y.getCreate_time()); } }).collect(Collectors.toList()); if (Arrays.asList(stockLandService.findUserIdByGroupName(Constant.XTGZXZ).split(",")).contains(String.valueOf(ShiroUtils.getUserId()))) { //协调工作小组成员,可以看到那个局审批了,哪个局未审批-2018-06-07 //一共需要哪些局进行合规性审核,还剩哪些没审核 List pendingAuditDepts = getPendingAuditDepts(apply_id, list, approvals); for (Department dept : pendingAuditDepts) { Approval approval = new Approval(Constant.LandApproveStatus.COMPLIANCE_AUDIT, Constant.OperType.PENDING, dept.getName()); approvals.add(approval); } // } } else if (ShiroUtils.getUserType().equals(Constant.UserType.COMPANY)) { approvals = approvals.stream().filter(approval -> (approval.getOper_type().equals(Constant.OperType.CONFIRM_AND_NOTIFY))).collect(Collectors.toList()); } for (Approval approval : approvals) { if (StringUtils.isNotBlank(approval.getBefore_approvalstatus())) { approval.setBefore_approvalstatus_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.STOCKLAND_APPROVE_STATUS, approval.getBefore_approvalstatus())); } //绑定审核材料 getApproveFiles(approval); } return approvals; } //存量用地合规性审核 ,还没审核的部门 private List getPendingAuditDepts(Integer apply_id, List userIdArr, List approvals) { //总共需要审核的部门 List allDepts = departmentService.getAllUserDepts(userIdArr); if (approvals.size() == 0){ try { throw new Exception("没有审批流程"); } catch (Exception e) { e.printStackTrace(); } } Approval latestApproval = approvals.get(approvals.size() - 1); int approvalRound = latestApproval.getApproval_round(); List list = approvals.stream().filter(a -> approvalRound == a.getApproval_round()) .collect(Collectors.toList()); for (Approval approval : list) { //过滤掉已经审核过的部门 allDepts = allDepts.stream().filter(d -> !d.getName().equals(approval.getDepartment())).collect(Collectors.toList()); } return allDepts; } //获取存量用地审核流程数据,申请查询页面,只显示街道确认并通知的信息 public List getApplyApprovalList(Integer apply_id) { Example example = new Example(Approval.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("apply_id", apply_id); criteria.andEqualTo("type", Constant.DictionaryType.STOCKLAND); criteria.andEqualTo("del_flag", false); List approvals = this.selectByExample(example); approvals = approvals.stream().filter(approval -> (approval.getOper_type().equals(Constant.OperType.CONFIRM_AND_NOTIFY))).collect(Collectors.toList()); for (Approval approval : approvals) { if (StringUtils.isNotBlank(approval.getBefore_approvalstatus())) { approval.setBefore_approvalstatus_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.STOCKLAND_APPROVE_STATUS, approval.getBefore_approvalstatus())); } //绑定审核材料 getApproveFiles(approval); } return approvals; } //获取注册审核流程数据 public List getRegisterApprovalList(Integer apply_id) { Example example = new Example(Approval.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("apply_id", apply_id); List approvals = this.selectByExample(example); for (Approval approval : approvals) { if (StringUtils.isNotBlank(approval.getBefore_approvalstatus())) { approval.setBefore_approvalstatus_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.STOCKLAND_APPROVE_STATUS, approval.getBefore_approvalstatus())); } //绑定审核材料 getApproveFiles(approval); } return approvals; } //绑定审核的审核材料 public Approval getApproveFiles(Approval approval) { //绑定审核材料 List approveFiles = attachmentService.selectByIdAndBusinessId(Constant.Attachment.STOCKLAND_APPROVE, approval.getId(), null); if (null != approveFiles && approveFiles.size() > 0) { List fileDowns = new ArrayList(); for (int i = 0; i < approveFiles.size(); i++) { FileDown fileDown = new FileDown(approveFiles.get(i).getId(), approveFiles.get(i).getFile_name(), approveFiles.get(i).getFile_url(), approveFiles.get(i).getDownload_uri()); fileDowns.add(fileDown); } approval.setFileDowns(fileDowns); } return approval; } //该用户审核的最近一条 public Approval getLatestApprovalByUser(Integer apply_id, String type, Integer user_id) { return approvalDao.getLatestApprovalByUser(apply_id, type, user_id); } public Approval findLastByCheckerAndBeforeStatu(Integer id, String type, Integer userId, String complianceAudit) { Approval approval = approvalDao.findLastByCheckerAndBeforeStatu(id, type, userId, complianceAudit); return approval; } public List findDepartmentNameByApplyId(int id) { List list = approvalDao.findDepartmentNameByApplyId(id); return list; } //找出审核节点的item public List findProcessNodes(Integer apply_id, String statusType) { return approvalDao.findProcessNodes(apply_id, statusType); } //查询企业通过审核的时间 public Approval findLatelyTime(Integer id, String type) { Approval approval = approvalDao.getLatestApproval(id, type); return approval; } //查询项目申报流程信息 public List getProjectApprovalList(Integer apply_id) { Example example = new Example(Approval.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("apply_id", apply_id); criteria.andEqualTo("type", Constant.DictionaryType.PROJECT_APPLICATION); List approvals = this.selectByExample(example); for (Approval approval : approvals) { if (StringUtils.isNotBlank(approval.getBefore_approvalstatus())) { approval.setBefore_approvalstatus_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_APPROVE_STATUS, approval.getBefore_approvalstatus())); } //绑定审核材料 //getApproveFiles(approval); } return approvals; } //查询用户最近一条已审核记录 public Approval getLatestApprovalAllByUser(Integer id, String type, Integer userId) { return approvalDao.getLatestApprovalAllByUser(id, type, userId); } //查询项目申报流程信息 public List getProjectProvincesApprovalList(Integer apply_id) { Example example = new Example(Approval.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("apply_id", apply_id); criteria.andEqualTo("type", Constant.DictionaryType.PROJECT_PROVINCES); List approvals = this.selectByExample(example); for (Approval approval : approvals) { if (StringUtils.isNotBlank(approval.getBefore_approvalstatus())) { approval.setBefore_approvalstatus_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_PROVINCES_APPROVE_STATUS, approval.getBefore_approvalstatus())); } } return approvals; } //查询项目申报流程信息 public List getProjectMattersApprovalList(Integer apply_id) { Example example = new Example(Approval.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("apply_id", apply_id); criteria.andEqualTo("type", Constant.DictionaryType.PROJECT_MATTERS); List approvals = this.selectByExample(example); for (Approval approval : approvals) { if (StringUtils.isNotBlank(approval.getBefore_approvalstatus())) { approval.setBefore_approvalstatus_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_MATTERS_APPROVE_STATUS, approval.getBefore_approvalstatus())); } } return approvals; } //查询项目申报流程信息 public List getProjectIntelligentApprovalList(Integer apply_id) { Example example = new Example(Approval.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("apply_id", apply_id); criteria.andEqualTo("type", Constant.DictionaryType.PROJECT_INTELLIGENT); List approvals = this.selectByExample(example); for (Approval approval : approvals) { if (StringUtils.isNotBlank(approval.getBefore_approvalstatus())) { approval.setBefore_approvalstatus_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_INTELLIGENT_APPROVE_STATUS, approval.getBefore_approvalstatus())); } } return approvals; } //查询项目申报流程信息 public List getProjectFillingApprovalList(Integer apply_id) { Example example = new Example(Approval.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("apply_id", apply_id); criteria.andEqualTo("type", Constant.DictionaryType.PROJECT_FILLING); List approvals = this.selectByExample(example); for (Approval approval : approvals) { if (StringUtils.isNotBlank(approval.getBefore_approvalstatus())) { approval.setBefore_approvalstatus_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_FILLING_APPROVE_STATUS, approval.getBefore_approvalstatus())); } } return approvals; } public List getCenterBusiness(BusinessSearchDto businessSearchDto) { return approvalDao.getCenterBusiness(businessSearchDto); } @Transactional(readOnly = true) public int getBusinessVolume(BusinessSearchDto businessSearchDto) { return approvalDao.getBusinessVolume(businessSearchDto); } public CenterWindow getWindowBusiness(BusinessSearchDto businessSearchDto) { return approvalDao.getWindowBusiness(businessSearchDto); } public CenterWindow getMonthStatistical(BusinessSearchDto businessSearchDto, Integer xnum) { businessSearchDto.setXnum(xnum); return approvalDao.getMonthStatistical(businessSearchDto); } public List getOverallAnalysis(SearchCondition searchCondition) { return approvalDao.getOverallAnalysis(searchCondition); } public AffairsTrackingDto getDepartmentTrack(List userList) { return approvalDao.getDepartmentTrack(userList); } public CheckTrackingNum getTrackByUser(Integer userId) { return approvalDao.getTrackByUser(userId); } public List getDocumentByUser(SearchCondition searchCondition) { return approvalDao.getDocumentByUser(searchCondition); } public List getSearchDocumentByUser(SearchCondition searchCondition) { return approvalDao.getSearchDocumentByUser(searchCondition); } public List getNear3MonthStatistical(int i) { return approvalDao.getNear3MonthStatistical(i); } public int getBusinessAcceptNum(BusinessSearchDto businessSearchDto) { return approvalDao.getBusinessAcceptNum(businessSearchDto); } /** * 获取流程信息 * * @param apply_id * @param type * @return */ public List getListByApplyIdAndType(Integer apply_id, String type) { Example example = new Example(Approval.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("type", type); criteria.andEqualTo("del_flag", false); criteria.andEqualTo("apply_id", apply_id); example.orderBy("create_time").asc(); List approvals = this.selectByExample(example); return approvals; } }