ApprovalService.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. package platform.modules.sys.service;
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.stream.Collectors;
  6. import org.apache.commons.lang3.StringUtils;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Service;
  9. import com.github.pagehelper.PageHelper;
  10. import org.springframework.transaction.annotation.Transactional;
  11. import platform.common.Constant;
  12. import platform.common.base.model.BaseEntity;
  13. import platform.common.base.model.DictionaryItem;
  14. import platform.common.base.service.BaseService;
  15. import platform.common.base.service.DictionaryItemService;
  16. import platform.common.util.ShiroUtils;
  17. import platform.common.util.WebUtil;
  18. import platform.modules.company.service.StockLandService;
  19. import platform.modules.government.dao.AttachmentDao;
  20. import platform.modules.government.dto.*;
  21. import platform.modules.government.entity.Attachment;
  22. import platform.modules.government.entity.FileDown;
  23. import platform.modules.government.entity.User;
  24. import platform.modules.government.service.AttachmentService;
  25. import platform.modules.government.service.UserService;
  26. import platform.modules.sys.dao.ApprovalDao;
  27. import platform.modules.sys.entity.Approval;
  28. import platform.modules.sys.entity.Department;
  29. import tk.mybatis.mapper.entity.Example;
  30. @Service
  31. public class ApprovalService extends BaseService<Approval> {
  32. @Autowired
  33. private ApprovalDao approvalDao;
  34. @Autowired
  35. private DictionaryItemService dictionaryItemService;
  36. @Autowired
  37. private AttachmentService attachmentService;
  38. @Autowired
  39. private StockLandService stockLandService;
  40. @Autowired
  41. private UserService userService;
  42. @Autowired
  43. private DepartmentService departmentService;
  44. public Approval getLatestApproval(Integer apply_id, String type) {
  45. return approvalDao.getLatestApproval(apply_id, type);
  46. }
  47. //查找最近一条审核记录,含撤回的记录 不判断del_flag
  48. public Approval getLatestApprovalAll(Integer apply_id, String type) {
  49. return approvalDao.getLatestApprovalAll(apply_id, type);
  50. }
  51. //获取存量用地审核流程数据
  52. public List<Approval> getApprovalList(Integer apply_id) {
  53. //合规性审查只能看到自己部门的审核信息
  54. //1.查出合规性审查小组的userId,根据审核流程来查找
  55. String userIds = stockLandService.findComplianceAuditUserIds(apply_id);
  56. String[] userIdArr = userIds.split(",");
  57. Example example = new Example(Approval.class);
  58. Example.Criteria criteria = example.createCriteria();
  59. criteria.andEqualTo("type", Constant.DictionaryType.STOCKLAND);
  60. criteria.andEqualTo("del_flag", false);
  61. criteria.andEqualTo("apply_id", apply_id);
  62. List<Approval> approvals = this.selectByExample(example);
  63. //如果当前用户是合规性审查小组成员,查出当前用户所属的部门id
  64. List<String> list = Arrays.asList(userIdArr);
  65. int currentUserId = ShiroUtils.getUserId();
  66. if (ShiroUtils.getUserType().equals(Constant.UserType.GOVERNMENT)) {
  67. if (list.contains(String.valueOf(currentUserId))) {
  68. Integer departmentId = userService.findDepartmentIdByUserId(currentUserId);
  69. if (null != departmentId) {
  70. approvals = approvals.stream().filter(approval -> !(null != approval.getChecker() && !departmentId.equals(userService.findDepartmentIdByUserId(approval.getChecker()))
  71. && null != approval.getBefore_approvalstatus() && approval.getBefore_approvalstatus().equals(Constant.LandApproveStatus.COMPLIANCE_AUDIT))).collect(Collectors.toList());
  72. }
  73. }
  74. //排序 合规性审核 按照部门排序
  75. approvals = approvals.stream().sorted((x, y) -> {
  76. if (x.getBefore_approvalstatus().equals(Constant.LandApproveStatus.COMPLIANCE_AUDIT)
  77. && y.getBefore_approvalstatus().equals(Constant.LandApproveStatus.COMPLIANCE_AUDIT)) {
  78. return x.getDepartment().compareTo(y.getDepartment());
  79. } else {
  80. return x.getCreate_time().compareTo(y.getCreate_time());
  81. }
  82. }).collect(Collectors.toList());
  83. if (Arrays.asList(stockLandService.findUserIdByGroupName(Constant.XTGZXZ).split(",")).contains(String.valueOf(ShiroUtils.getUserId()))) {
  84. //协调工作小组成员,可以看到那个局审批了,哪个局未审批-2018-06-07
  85. //一共需要哪些局进行合规性审核,还剩哪些没审核
  86. List<Department> pendingAuditDepts = getPendingAuditDepts(apply_id, list, approvals);
  87. for (Department dept : pendingAuditDepts) {
  88. Approval approval = new Approval(Constant.LandApproveStatus.COMPLIANCE_AUDIT, Constant.OperType.PENDING, dept.getName());
  89. approvals.add(approval);
  90. }
  91. //
  92. }
  93. } else if (ShiroUtils.getUserType().equals(Constant.UserType.COMPANY)) {
  94. approvals = approvals.stream().filter(approval -> (approval.getOper_type().equals(Constant.OperType.CONFIRM_AND_NOTIFY))).collect(Collectors.toList());
  95. }
  96. for (Approval approval : approvals) {
  97. if (StringUtils.isNotBlank(approval.getBefore_approvalstatus())) {
  98. approval.setBefore_approvalstatus_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.STOCKLAND_APPROVE_STATUS, approval.getBefore_approvalstatus()));
  99. }
  100. //绑定审核材料
  101. getApproveFiles(approval);
  102. }
  103. return approvals;
  104. }
  105. //存量用地合规性审核 ,还没审核的部门
  106. private List<Department> getPendingAuditDepts(Integer apply_id, List<String> userIdArr, List<Approval> approvals) {
  107. //总共需要审核的部门
  108. List<Department> allDepts = departmentService.getAllUserDepts(userIdArr);
  109. if (approvals.size() == 0){
  110. try {
  111. throw new Exception("没有审批流程");
  112. } catch (Exception e) {
  113. e.printStackTrace();
  114. }
  115. }
  116. Approval latestApproval = approvals.get(approvals.size() - 1);
  117. int approvalRound = latestApproval.getApproval_round();
  118. List<Approval> list = approvals.stream().filter(a -> approvalRound == a.getApproval_round())
  119. .collect(Collectors.toList());
  120. for (Approval approval : list) {
  121. //过滤掉已经审核过的部门
  122. allDepts = allDepts.stream().filter(d -> !d.getName().equals(approval.getDepartment())).collect(Collectors.toList());
  123. }
  124. return allDepts;
  125. }
  126. //获取存量用地审核流程数据,申请查询页面,只显示街道确认并通知的信息
  127. public List<Approval> getApplyApprovalList(Integer apply_id) {
  128. Example example = new Example(Approval.class);
  129. Example.Criteria criteria = example.createCriteria();
  130. criteria.andEqualTo("apply_id", apply_id);
  131. criteria.andEqualTo("type", Constant.DictionaryType.STOCKLAND);
  132. criteria.andEqualTo("del_flag", false);
  133. List<Approval> approvals = this.selectByExample(example);
  134. approvals = approvals.stream().filter(approval -> (approval.getOper_type().equals(Constant.OperType.CONFIRM_AND_NOTIFY))).collect(Collectors.toList());
  135. for (Approval approval : approvals) {
  136. if (StringUtils.isNotBlank(approval.getBefore_approvalstatus())) {
  137. approval.setBefore_approvalstatus_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.STOCKLAND_APPROVE_STATUS, approval.getBefore_approvalstatus()));
  138. }
  139. //绑定审核材料
  140. getApproveFiles(approval);
  141. }
  142. return approvals;
  143. }
  144. //获取注册审核流程数据
  145. public List<Approval> getRegisterApprovalList(Integer apply_id) {
  146. Example example = new Example(Approval.class);
  147. Example.Criteria criteria = example.createCriteria();
  148. criteria.andEqualTo("apply_id", apply_id);
  149. List<Approval> approvals = this.selectByExample(example);
  150. for (Approval approval : approvals) {
  151. if (StringUtils.isNotBlank(approval.getBefore_approvalstatus())) {
  152. approval.setBefore_approvalstatus_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.STOCKLAND_APPROVE_STATUS, approval.getBefore_approvalstatus()));
  153. }
  154. //绑定审核材料
  155. getApproveFiles(approval);
  156. }
  157. return approvals;
  158. }
  159. //绑定审核的审核材料
  160. public Approval getApproveFiles(Approval approval) {
  161. //绑定审核材料
  162. List<Attachment> approveFiles = attachmentService.selectByIdAndBusinessId(Constant.Attachment.STOCKLAND_APPROVE, approval.getId(), null);
  163. if (null != approveFiles && approveFiles.size() > 0) {
  164. List<FileDown> fileDowns = new ArrayList<FileDown>();
  165. for (int i = 0; i < approveFiles.size(); i++) {
  166. FileDown fileDown = new FileDown(approveFiles.get(i).getId(), approveFiles.get(i).getFile_name(), approveFiles.get(i).getFile_url(), approveFiles.get(i).getDownload_uri());
  167. fileDowns.add(fileDown);
  168. }
  169. approval.setFileDowns(fileDowns);
  170. }
  171. return approval;
  172. }
  173. //该用户审核的最近一条
  174. public Approval getLatestApprovalByUser(Integer apply_id, String type, Integer user_id) {
  175. return approvalDao.getLatestApprovalByUser(apply_id, type, user_id);
  176. }
  177. public Approval findLastByCheckerAndBeforeStatu(Integer id, String type, Integer userId, String complianceAudit) {
  178. Approval approval = approvalDao.findLastByCheckerAndBeforeStatu(id, type, userId, complianceAudit);
  179. return approval;
  180. }
  181. public List<String> findDepartmentNameByApplyId(int id) {
  182. List<String> list = approvalDao.findDepartmentNameByApplyId(id);
  183. return list;
  184. }
  185. //找出审核节点的item
  186. public List<DictionaryItem> findProcessNodes(Integer apply_id, String statusType) {
  187. return approvalDao.findProcessNodes(apply_id, statusType);
  188. }
  189. //查询企业通过审核的时间
  190. public Approval findLatelyTime(Integer id, String type) {
  191. Approval approval = approvalDao.getLatestApproval(id, type);
  192. return approval;
  193. }
  194. //查询项目申报流程信息
  195. public List<Approval> getProjectApprovalList(Integer apply_id) {
  196. Example example = new Example(Approval.class);
  197. Example.Criteria criteria = example.createCriteria();
  198. criteria.andEqualTo("apply_id", apply_id);
  199. criteria.andEqualTo("type", Constant.DictionaryType.PROJECT_APPLICATION);
  200. List<Approval> approvals = this.selectByExample(example);
  201. for (Approval approval : approvals) {
  202. if (StringUtils.isNotBlank(approval.getBefore_approvalstatus())) {
  203. approval.setBefore_approvalstatus_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_APPROVE_STATUS, approval.getBefore_approvalstatus()));
  204. }
  205. //绑定审核材料
  206. //getApproveFiles(approval);
  207. }
  208. return approvals;
  209. }
  210. //查询用户最近一条已审核记录
  211. public Approval getLatestApprovalAllByUser(Integer id, String type, Integer userId) {
  212. return approvalDao.getLatestApprovalAllByUser(id, type, userId);
  213. }
  214. //查询项目申报流程信息
  215. public List<Approval> getProjectProvincesApprovalList(Integer apply_id) {
  216. Example example = new Example(Approval.class);
  217. Example.Criteria criteria = example.createCriteria();
  218. criteria.andEqualTo("apply_id", apply_id);
  219. criteria.andEqualTo("type", Constant.DictionaryType.PROJECT_PROVINCES);
  220. List<Approval> approvals = this.selectByExample(example);
  221. for (Approval approval : approvals) {
  222. if (StringUtils.isNotBlank(approval.getBefore_approvalstatus())) {
  223. approval.setBefore_approvalstatus_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_PROVINCES_APPROVE_STATUS, approval.getBefore_approvalstatus()));
  224. }
  225. }
  226. return approvals;
  227. }
  228. //查询项目申报流程信息
  229. public List<Approval> getProjectMattersApprovalList(Integer apply_id) {
  230. Example example = new Example(Approval.class);
  231. Example.Criteria criteria = example.createCriteria();
  232. criteria.andEqualTo("apply_id", apply_id);
  233. criteria.andEqualTo("type", Constant.DictionaryType.PROJECT_MATTERS);
  234. List<Approval> approvals = this.selectByExample(example);
  235. for (Approval approval : approvals) {
  236. if (StringUtils.isNotBlank(approval.getBefore_approvalstatus())) {
  237. approval.setBefore_approvalstatus_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_MATTERS_APPROVE_STATUS, approval.getBefore_approvalstatus()));
  238. }
  239. }
  240. return approvals;
  241. }
  242. //查询项目申报流程信息
  243. public List<Approval> getProjectIntelligentApprovalList(Integer apply_id) {
  244. Example example = new Example(Approval.class);
  245. Example.Criteria criteria = example.createCriteria();
  246. criteria.andEqualTo("apply_id", apply_id);
  247. criteria.andEqualTo("type", Constant.DictionaryType.PROJECT_INTELLIGENT);
  248. List<Approval> approvals = this.selectByExample(example);
  249. for (Approval approval : approvals) {
  250. if (StringUtils.isNotBlank(approval.getBefore_approvalstatus())) {
  251. approval.setBefore_approvalstatus_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_INTELLIGENT_APPROVE_STATUS, approval.getBefore_approvalstatus()));
  252. }
  253. }
  254. return approvals;
  255. }
  256. //查询项目申报流程信息
  257. public List<Approval> getProjectFillingApprovalList(Integer apply_id) {
  258. Example example = new Example(Approval.class);
  259. Example.Criteria criteria = example.createCriteria();
  260. criteria.andEqualTo("apply_id", apply_id);
  261. criteria.andEqualTo("type", Constant.DictionaryType.PROJECT_FILLING);
  262. List<Approval> approvals = this.selectByExample(example);
  263. for (Approval approval : approvals) {
  264. if (StringUtils.isNotBlank(approval.getBefore_approvalstatus())) {
  265. approval.setBefore_approvalstatus_str(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_FILLING_APPROVE_STATUS, approval.getBefore_approvalstatus()));
  266. }
  267. }
  268. return approvals;
  269. }
  270. public List<CenterBusiness> getCenterBusiness(BusinessSearchDto businessSearchDto) {
  271. return approvalDao.getCenterBusiness(businessSearchDto);
  272. }
  273. @Transactional(readOnly = true)
  274. public int getBusinessVolume(BusinessSearchDto businessSearchDto) {
  275. return approvalDao.getBusinessVolume(businessSearchDto);
  276. }
  277. public CenterWindow getWindowBusiness(BusinessSearchDto businessSearchDto) {
  278. return approvalDao.getWindowBusiness(businessSearchDto);
  279. }
  280. public CenterWindow getMonthStatistical(BusinessSearchDto businessSearchDto, Integer xnum) {
  281. businessSearchDto.setXnum(xnum);
  282. return approvalDao.getMonthStatistical(businessSearchDto);
  283. }
  284. public List<GovStatisticsDto> getOverallAnalysis(SearchCondition searchCondition) {
  285. return approvalDao.getOverallAnalysis(searchCondition);
  286. }
  287. public AffairsTrackingDto getDepartmentTrack(List<User> userList) {
  288. return approvalDao.getDepartmentTrack(userList);
  289. }
  290. public CheckTrackingNum getTrackByUser(Integer userId) {
  291. return approvalDao.getTrackByUser(userId);
  292. }
  293. public List<Approval> getDocumentByUser(SearchCondition searchCondition) {
  294. return approvalDao.getDocumentByUser(searchCondition);
  295. }
  296. public List<CheckTrackingNum> getSearchDocumentByUser(SearchCondition searchCondition) {
  297. return approvalDao.getSearchDocumentByUser(searchCondition);
  298. }
  299. public List<Approval> getNear3MonthStatistical(int i) {
  300. return approvalDao.getNear3MonthStatistical(i);
  301. }
  302. public int getBusinessAcceptNum(BusinessSearchDto businessSearchDto) {
  303. return approvalDao.getBusinessAcceptNum(businessSearchDto);
  304. }
  305. /**
  306. * 获取流程信息
  307. *
  308. * @param apply_id
  309. * @param type
  310. * @return
  311. */
  312. public List<Approval> getListByApplyIdAndType(Integer apply_id, String type) {
  313. Example example = new Example(Approval.class);
  314. Example.Criteria criteria = example.createCriteria();
  315. criteria.andEqualTo("type", type);
  316. criteria.andEqualTo("del_flag", false);
  317. criteria.andEqualTo("apply_id", apply_id);
  318. example.orderBy("create_time").asc();
  319. List<Approval> approvals = this.selectByExample(example);
  320. return approvals;
  321. }
  322. }