ProvisionalPlanServiceImpl.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. package com.ozs.plan.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import com.github.pagehelper.PageInfo;
  8. import com.ozs.base.domain.BasePolicy;
  9. import com.ozs.common.constant.Constants;
  10. import com.ozs.common.core.domain.AjaxResult;
  11. import com.ozs.common.core.domain.entity.SysDept;
  12. import com.ozs.common.core.domain.entity.SysDictData;
  13. import com.ozs.common.core.domain.entity.SysRole;
  14. import com.ozs.common.core.domain.entity.SysUser;
  15. import com.ozs.common.core.domain.model.LoginUser;
  16. import com.ozs.common.enums.DataIsDelete;
  17. import com.ozs.common.enums.PmProjectStatus;
  18. import com.ozs.common.enums.ProjectStatus;
  19. import com.ozs.common.enums.ProjectTypes;
  20. import com.ozs.common.enums.SysFileRefEnum;
  21. import com.ozs.common.exception.ServiceException;
  22. import com.ozs.common.utils.PageUtils;
  23. import com.ozs.common.utils.SecurityUtils;
  24. import com.ozs.common.utils.StringUtils;
  25. import com.ozs.common.utils.bean.BeanUtils;
  26. import com.ozs.plan.doman.PlanYears;
  27. import com.ozs.plan.doman.ProvisionalPlan;
  28. import com.ozs.plan.doman.vo.requestVo.ProvisionalPlanVo;
  29. import com.ozs.plan.mapper.PlanYearsMapper;
  30. import com.ozs.plan.mapper.ProvisionalPlanMapper;
  31. import com.ozs.plan.service.ProvisionalPlanService;
  32. import com.ozs.pm.doman.PmAuditDeptRef;
  33. import com.ozs.pm.doman.PmDemand;
  34. import com.ozs.pm.mapper.PmDemandMapper;
  35. import com.ozs.pm.service.IPmDemandService;
  36. import com.ozs.pm.service.PmAuditDeptRefService;
  37. import com.ozs.system.domain.SysFileInfo;
  38. import com.ozs.system.domain.SysFileRef;
  39. import com.ozs.system.domain.vo.responseVo.SysDeptResponseVo;
  40. import com.ozs.system.mapper.SysDeptMapper;
  41. import com.ozs.system.mapper.SysFileRefMapper;
  42. import com.ozs.system.service.ISysDeptService;
  43. import com.ozs.system.service.ISysDictTypeService;
  44. import com.ozs.system.service.ISysUserService;
  45. import com.ozs.system.service.SysFileService;
  46. import org.springframework.beans.factory.annotation.Autowired;
  47. import org.springframework.stereotype.Service;
  48. import org.springframework.transaction.annotation.Transactional;
  49. import org.springframework.util.ObjectUtils;
  50. import javax.servlet.http.HttpServletRequest;
  51. import java.math.BigDecimal;
  52. import java.text.SimpleDateFormat;
  53. import java.util.*;
  54. import java.util.stream.Collectors;
  55. @Service
  56. public class ProvisionalPlanServiceImpl extends ServiceImpl<ProvisionalPlanMapper, ProvisionalPlan> implements ProvisionalPlanService {
  57. @Autowired
  58. private ProvisionalPlanMapper provisionalPlanMapper;
  59. @Autowired
  60. private ISysDictTypeService dictTypeService;
  61. @Autowired
  62. private SysDeptMapper deptMapper;
  63. @Autowired
  64. private ISysDeptService deptService;
  65. @Autowired
  66. private PlanYearsMapper planYearsMapper;
  67. @Autowired
  68. private SysFileRefMapper sysFileRefMapper;
  69. @Autowired
  70. private SysFileService fileService;
  71. @Autowired
  72. private PmDemandMapper pmDemandMapper;
  73. @Autowired
  74. private IPmDemandService demandService;
  75. @Autowired
  76. private ISysUserService userService;
  77. @Autowired
  78. private PmAuditDeptRefService pmAuditDeptRefService;
  79. @Override
  80. public int deleteProvisionalPlanById(Long planPracticalId) {
  81. return provisionalPlanMapper.deleteProvisionalPlanById(planPracticalId);
  82. }
  83. @Override
  84. @Transactional
  85. public int updateProvisionalPlanById(ProvisionalPlanVo provisionalPlan) {
  86. //默认未超额
  87. if (ObjectUtils.isEmpty(provisionalPlan.getIsExcess())) {
  88. provisionalPlan.setIsExcess("0");
  89. }
  90. List<SysFileRef> sysFileRefs = provisionalPlan.getSysFileRefs();
  91. if (!ObjectUtils.isEmpty(sysFileRefs)) {
  92. // 删关联
  93. LambdaQueryWrapper<SysFileRef> lw = new LambdaQueryWrapper<>();
  94. lw.eq(SysFileRef::getRedId, provisionalPlan.getPlanPracticalId());
  95. lw.eq(SysFileRef::getType, SysFileRefEnum.PLAN_TEMPORARY.getType());
  96. sysFileRefMapper.delete(lw);
  97. for (SysFileRef ref : sysFileRefs) {
  98. ref.setRedId(provisionalPlan.getPlanPracticalId());
  99. ref.setType(SysFileRefEnum.PLAN_TEMPORARY.getType());
  100. ref.setCreated(provisionalPlan.getCreated());
  101. ref.setCreateTime(new Date());
  102. ref.setUpdated(provisionalPlan.getCreated());
  103. ref.setUpdateTime(new Date());
  104. sysFileRefMapper.insert(ref);
  105. }
  106. }
  107. return provisionalPlanMapper.updateProvisionalPlanById(provisionalPlan);
  108. }
  109. @Override
  110. public String importProvisionalPlan(List<ProvisionalPlan> provisionalPlans, boolean updateSupport, LoginUser loginUser) {
  111. // 字典项
  112. HashMap<String, HashMap<String, String>> planEnums = dictTypeService.getAboutEnums();
  113. HashMap<String, String> projectTypesMap = planEnums.get("projectTypes");
  114. HashMap<String, String> planPurchaseModesMap = planEnums.get("planPurchaseModes");
  115. HashMap<String, String> projectAttributes = planEnums.get("projectAttributes");
  116. // HashMap<String, String> purchaseServices = planEnums.get("purchaseServices");
  117. int successNum = 0;
  118. int failureNum = 0;
  119. StringBuilder successMsg = new StringBuilder();
  120. StringBuilder failureMsg = new StringBuilder();
  121. for (ProvisionalPlan ofProvisionalPlan : provisionalPlans) {
  122. try {
  123. //验证项目名称是否重复导入
  124. List<ProvisionalPlan> plan = provisionalPlanMapper.selectProjectName(ofProvisionalPlan.getProjectName());
  125. //将录入信息中的值更改为要保存的数据
  126. if (plan.size() == 0) {
  127. //采购单位
  128. SysDept info = deptMapper.checkDeptNameOnlyOne(ofProvisionalPlan.getPurchaseDeptName());
  129. if (StringUtils.isNotNull(info)) {
  130. ofProvisionalPlan.setPurchaseDeptId(String.valueOf(info.getDeptId()));
  131. }
  132. ofProvisionalPlan.setProjectType(projectTypesMap.get(ofProvisionalPlan.getProjectType()));
  133. ofProvisionalPlan.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode());
  134. ofProvisionalPlan.setPurchaseMode(planPurchaseModesMap.get(ofProvisionalPlan.getPurchaseMode()));
  135. //项目属性是多选字段
  136. StringBuilder builder = new StringBuilder();
  137. if (ofProvisionalPlan.getProjectAttr().contains(",")) {
  138. String[] split = ofProvisionalPlan.getProjectAttr().split(",");
  139. for (String s : split) {
  140. if (!ofProvisionalPlan.getProjectAttr().endsWith(s)) {
  141. builder.append(projectAttributes.get(s) + ",");
  142. } else {
  143. builder.append(projectAttributes.get(s));
  144. }
  145. }
  146. } else {
  147. builder.append(projectAttributes.get(ofProvisionalPlan.getProjectAttr()));
  148. }
  149. ofProvisionalPlan.setProjectAttr(builder.toString());
  150. // ofProvisionalPlan.setPurchaseServices(purchaseServices.get(ofProvisionalPlan.getPurchaseServicesStr()));
  151. ofProvisionalPlan.setIsExcess(deptService.isExcessOrNo(ofProvisionalPlan.getProjectType(), ofProvisionalPlan.getEvaluation(), info.getDeptId()));
  152. ofProvisionalPlan.setCreated(String.valueOf(loginUser.getUserId()));
  153. ofProvisionalPlan.setCreateTime(new Date());
  154. ofProvisionalPlan.setPlanType("1");
  155. provisionalPlanMapper.insert(ofProvisionalPlan);
  156. successNum++;
  157. successMsg.append("*" + successNum + "、项目 " + ofProvisionalPlan.getProjectName() + " 导入成功!");
  158. } else {
  159. failureNum++;
  160. failureMsg.append("*" + successNum + "、项目 " + ofProvisionalPlan.getProjectName() + " 已存在");
  161. }
  162. } catch (Exception exc) {
  163. failureNum++;
  164. String msg = "*" + successNum + "、项目 " + ofProvisionalPlan.getProjectName() + " 导入失败";
  165. failureMsg.append(msg + exc.getMessage());
  166. log.error(msg, exc);
  167. }
  168. }
  169. if (failureNum > 0) {
  170. failureMsg.insert(0, "导入失败!共 " + failureNum + " 条数据格式不正确:");
  171. throw new ServiceException(failureMsg.toString());
  172. } else {
  173. successMsg.insert(0, "导入成功!共 " + successNum + " 条。");
  174. }
  175. return successMsg.toString();
  176. }
  177. @Override
  178. public List<ProvisionalPlan> selectProvisionalPlanExport(ProvisionalPlanVo vo, LoginUser loginUser) {
  179. List<ProvisionalPlan> list = new ArrayList<>();
  180. List<ProvisionalPlan> provisionalPlanList = new ArrayList<>();
  181. try {
  182. int num = 1;
  183. int size = 200;
  184. while (size == 200) {
  185. LambdaQueryWrapper<ProvisionalPlan> lw = new LambdaQueryWrapper<ProvisionalPlan>();
  186. lw.eq(ProvisionalPlan::getPlanType, "1");
  187. lw.eq(ProvisionalPlan::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  188. if (!loginUser.getUserId().equals(Long.valueOf("1"))) {
  189. lw.eq(ProvisionalPlan::getPurchaseDeptId, loginUser.getDeptId());
  190. }
  191. lw.eq(ProvisionalPlan::getPlanType, "1");
  192. if (!ObjectUtils.isEmpty(vo.getProjectName())) {
  193. lw.like(ProvisionalPlan::getProjectName, vo.getProjectName());
  194. }
  195. if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) {
  196. lw.eq(ProvisionalPlan::getPurchaseServices, vo.getPurchaseServices());
  197. }
  198. if (!ObjectUtils.isEmpty(vo.getIsExcess())) {
  199. lw.eq(ProvisionalPlan::getIsExcess, vo.getIsExcess());
  200. }
  201. if (!ObjectUtils.isEmpty(vo.getProjectStatus())) {
  202. lw.eq(ProvisionalPlan::getProjectStatus, vo.getProjectStatus());
  203. }
  204. if (!ObjectUtils.isEmpty(vo.getBeginTime())) {
  205. lw.ge(ProvisionalPlan::getPlanDemandSubTime, vo.getBeginTime());
  206. }
  207. if (!ObjectUtils.isEmpty(vo.getEndTime())) {
  208. lw.le(ProvisionalPlan::getPlanDemandSubTime, vo.getEndTime());
  209. }
  210. Page<ProvisionalPlan> page = provisionalPlanMapper.selectPage(new Page<ProvisionalPlan>(num, size, false), lw);
  211. list.addAll(page.getRecords());
  212. size = page.getRecords().size();
  213. num++;
  214. }
  215. provisionalPlanList = changeTo(list);
  216. } catch (Exception e) {
  217. e.printStackTrace();
  218. }
  219. return provisionalPlanList;
  220. }
  221. @Override
  222. @Transactional
  223. public int commitProvisionalPlan(ProvisionalPlanVo provisionalPlanVo) {
  224. ProvisionalPlan byId = provisionalPlanMapper.seletById(provisionalPlanVo.getPlanPracticalId());
  225. BigDecimal evaluation = byId.getEvaluation();
  226. SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
  227. Long deptId = sysUser.getDeptId();
  228. if (!pmAuditDeptRefService.insertPmAuditDeptRefs(byId.getPlanPracticalId(),
  229. "1",
  230. deptId,
  231. evaluation,
  232. sysUser.getUserId(),
  233. byId.getProjectType())) {
  234. throw new ServiceException("审核关联数据插入失败");
  235. }
  236. return provisionalPlanMapper.commitProvisionalPlan(provisionalPlanVo.getPlanPracticalId());
  237. }
  238. @Override
  239. public AjaxResult seletById(Long planPracticalId) {
  240. ProvisionalPlan provisionalPlan = provisionalPlanMapper.seletById(planPracticalId);
  241. if (StringUtils.isNull(provisionalPlan)) {
  242. return AjaxResult.error("数据查询失败");
  243. }
  244. // 转换字段中文
  245. ProvisionalPlan provisionalPlanC = changeToProvisionalPlan(provisionalPlan);
  246. LambdaQueryWrapper<SysFileRef> lw = new LambdaQueryWrapper<>();
  247. lw.eq(SysFileRef::getRedId, provisionalPlanC.getPlanPracticalId());
  248. lw.in(SysFileRef::getType, Arrays.asList(SysFileRefEnum.PLAN_TEMPORARY.getType(), SysFileRefEnum.PLAN_TEMPORARY_EXAMINE.getType()));
  249. List<SysFileRef> fileRefs = sysFileRefMapper.selectList(lw);
  250. List<SysFileInfo> fileInfos = new ArrayList<>();
  251. ProvisionalPlanVo provisionalPlanVo = new ProvisionalPlanVo();
  252. BeanUtils.copyProperties(provisionalPlanC, provisionalPlanVo);
  253. if (!ObjectUtils.isEmpty(fileRefs)) {
  254. for (SysFileRef ref : fileRefs) {
  255. SysFileInfo fileInfo = fileService.getById(ref.getFileId());
  256. fileInfos.add(fileInfo);
  257. }
  258. provisionalPlanVo.setFileInfos(fileInfos);
  259. }
  260. return AjaxResult.success(provisionalPlanVo);
  261. }
  262. @Override
  263. public AjaxResult selectProvisionalPlan(ProvisionalPlanVo vo, HttpServletRequest request, LoginUser loginUser) {
  264. List<ProvisionalPlan> provisionalPlanList = new ArrayList<>();
  265. try {
  266. LambdaQueryWrapper<ProvisionalPlan> lw = new LambdaQueryWrapper<>();
  267. lw.eq(ProvisionalPlan::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  268. lw.eq(ProvisionalPlan::getPlanType, "1");
  269. if (!loginUser.getUserId().equals(Long.valueOf("1"))) {
  270. lw.eq(ProvisionalPlan::getPurchaseDeptId, loginUser.getDeptId());
  271. }
  272. if (!ObjectUtils.isEmpty(vo.getProjectName())) {
  273. lw.like(ProvisionalPlan::getProjectName, vo.getProjectName());
  274. }
  275. if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) {
  276. lw.eq(ProvisionalPlan::getPurchaseServices, vo.getPurchaseServices());
  277. }
  278. if (!ObjectUtils.isEmpty(vo.getIsExcess())) {
  279. lw.eq(ProvisionalPlan::getIsExcess, vo.getIsExcess());
  280. }
  281. if (!ObjectUtils.isEmpty(vo.getProjectStatus())) {
  282. lw.eq(ProvisionalPlan::getProjectStatus, vo.getProjectStatus());
  283. }
  284. if (!ObjectUtils.isEmpty(vo.getBeginTime())) {
  285. lw.ge(ProvisionalPlan::getPlanDemandSubTime, vo.getBeginTime());
  286. }
  287. if (!ObjectUtils.isEmpty(vo.getEndTime())) {
  288. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  289. SimpleDateFormat dateFormatT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
  290. Date parse = dateFormatT.parse(dateFormat.format(vo.getEndTime()) + " 23:59:59:999");
  291. lw.le(ProvisionalPlan::getPlanDemandSubTime, parse);
  292. }
  293. lw.orderBy(true, false, ProvisionalPlan::getCreateTime);
  294. List<ProvisionalPlan> list = provisionalPlanMapper.selectList(lw);
  295. provisionalPlanList = changeTo(list);
  296. } catch (Exception e) {
  297. e.printStackTrace();
  298. }
  299. Page pages = PageUtils.getPages(vo.getPageNum().intValue(), vo.getPageSize().intValue(), provisionalPlanList);
  300. PageInfo<ProvisionalPlan> provisionalPlanPageInfo = new PageInfo<>();
  301. if (!ObjectUtils.isEmpty(pages) && pages.getRecords().size() > 0) {
  302. provisionalPlanPageInfo.setList(pages.getRecords());
  303. provisionalPlanPageInfo.setSize(Math.toIntExact(pages.getSize()));
  304. provisionalPlanPageInfo.setPageNum(Math.toIntExact(pages.getCurrent()));
  305. provisionalPlanPageInfo.setTotal(pages.getTotal());
  306. provisionalPlanPageInfo.setPages(Integer.parseInt(pages.getPages() + ""));
  307. }
  308. return AjaxResult.success(provisionalPlanPageInfo);
  309. }
  310. @Override
  311. public AjaxResult selectProvisionalPlanAudit(ProvisionalPlanVo vo, HttpServletRequest request, LoginUser loginUser) {
  312. List<ProvisionalPlan> provisionalPlanList = new ArrayList<>();
  313. try {
  314. LambdaQueryWrapper<ProvisionalPlan> lw = new LambdaQueryWrapper<>();
  315. lw.eq(ProvisionalPlan::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  316. lw.eq(ProvisionalPlan::getPlanType, "1");
  317. if (!loginUser.getUserId().equals(Long.valueOf("1"))) {
  318. lw.eq(ProvisionalPlan::getPurchaseDeptId, loginUser.getDeptId());
  319. }
  320. if (!ObjectUtils.isEmpty(vo.getProjectName())) {
  321. lw.like(ProvisionalPlan::getProjectName, vo.getProjectName());
  322. }
  323. if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) {
  324. lw.eq(ProvisionalPlan::getPurchaseServices, vo.getPurchaseServices());
  325. }
  326. if (!ObjectUtils.isEmpty(vo.getIsExcess())) {
  327. lw.eq(ProvisionalPlan::getIsExcess, vo.getIsExcess());
  328. }
  329. if (!ObjectUtils.isEmpty(vo.getProjectStatus())) {
  330. lw.eq(ProvisionalPlan::getProjectStatus, vo.getProjectStatus());
  331. } else {
  332. lw.apply(" project_status IN (1,3)", "");
  333. }
  334. if (!ObjectUtils.isEmpty(vo.getBeginTime())) {
  335. lw.ge(ProvisionalPlan::getPlanDemandSubTime, vo.getBeginTime());
  336. }
  337. if (!ObjectUtils.isEmpty(vo.getEndTime())) {
  338. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  339. SimpleDateFormat dateFormatT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
  340. Date parse = dateFormatT.parse(dateFormat.format(vo.getEndTime()) + " 23:59:59:999");
  341. lw.le(ProvisionalPlan::getPlanDemandSubTime, parse);
  342. }
  343. lw.orderBy(true, false, ProvisionalPlan::getCreateTime);
  344. List<ProvisionalPlan> list = provisionalPlanMapper.selectList(lw);
  345. provisionalPlanList = changeTo(list);
  346. } catch (Exception e) {
  347. e.printStackTrace();
  348. }
  349. Page pages = PageUtils.getPages(vo.getPageNum().intValue(), vo.getPageSize().intValue(), provisionalPlanList);
  350. PageInfo<ProvisionalPlan> provisionalPlanPageInfo = new PageInfo<>();
  351. if (!ObjectUtils.isEmpty(pages) && pages.getRecords().size() > 0) {
  352. provisionalPlanPageInfo.setList(pages.getRecords());
  353. provisionalPlanPageInfo.setSize(Math.toIntExact(pages.getSize()));
  354. provisionalPlanPageInfo.setPageNum(Math.toIntExact(pages.getCurrent()));
  355. provisionalPlanPageInfo.setTotal(pages.getTotal());
  356. provisionalPlanPageInfo.setPages(Integer.parseInt(pages.getPages() + ""));
  357. }
  358. return AjaxResult.success(provisionalPlanPageInfo);
  359. }
  360. @Override
  361. @Transactional
  362. public AjaxResult auditPass(ProvisionalPlanVo provisionalPlanVo) {
  363. SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
  364. Long deptId = sysUser.getDeptId();
  365. SysDept sysDept = deptMapper.selectDeptById(deptId);
  366. String[] ancestors = sysDept.getAncestors().split(",");
  367. String deptLevel = null;
  368. if (ancestors.length == 2) { //C级
  369. deptLevel = "C";
  370. } else if (ancestors.length == 3) { //B级
  371. deptLevel = "B";
  372. } else if (ancestors.length == 4) { //A级
  373. deptLevel = "A";
  374. }
  375. LambdaQueryWrapper<PmAuditDeptRef> lw = new LambdaQueryWrapper();
  376. lw.eq(PmAuditDeptRef::getRefId, provisionalPlanVo.getPlanPracticalId());
  377. lw.eq(PmAuditDeptRef::getRefType, "1");
  378. List<PmAuditDeptRef> list = pmAuditDeptRefService.list(lw);
  379. boolean flay = true;
  380. if (!ObjectUtils.isEmpty(list)) {
  381. for (PmAuditDeptRef pmAuditDeptRef : list) {
  382. // 判断 deptLevel 是否还有更高的 且是 待审核的数据
  383. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) > 0
  384. && pmAuditDeptRef.getStatus().equals(Integer.parseInt("0"))) {
  385. flay = false;
  386. }
  387. // 更新当前 deptLevel 级别的审核状态
  388. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) == 0) {
  389. pmAuditDeptRef.setStatus(1);
  390. pmAuditDeptRefService.updateById(pmAuditDeptRef);
  391. }
  392. }
  393. }
  394. realReviewTo(provisionalPlanVo, flay);
  395. return AjaxResult.success();
  396. }
  397. public AjaxResult realReviewTo(ProvisionalPlanVo provisionalPlanVo, boolean flay) {
  398. Date now = new Date();
  399. ProvisionalPlan byId = provisionalPlanMapper.seletById(provisionalPlanVo.getPlanPracticalId());
  400. if (ObjectUtils.isEmpty(byId.getPlanYearId())) {
  401. PlanYears ofYears = new PlanYears();
  402. BeanUtils.copyProperties(byId, ofYears);
  403. ofYears.setProjectStatus(ProjectStatus.PLANTOEXAMINE.getCode());
  404. planYearsMapper.insertPlanYears(ofYears);
  405. byId.setPlanYearId(ofYears.getPlanYearId());
  406. }
  407. //上传审核文件并赋予计划审核通过
  408. List<SysFileRef> sysFileRefss = provisionalPlanVo.getSysFileRefs();
  409. if (!ObjectUtils.isEmpty(sysFileRefss)) {
  410. for (SysFileRef ref : sysFileRefss) {
  411. ref.setRedId(provisionalPlanVo.getPlanPracticalId().longValue());
  412. ref.setType(SysFileRefEnum.PLAN_TEMPORARY_EXAMINE.getType());
  413. ref.setCreated(provisionalPlanVo.getUpdated());
  414. ref.setCreateTime(now);
  415. ref.setUpdated(provisionalPlanVo.getUpdated());
  416. ref.setUpdateTime(now);
  417. sysFileRefMapper.insert(ref);
  418. }
  419. }
  420. if (flay) {
  421. PmDemand demand = new PmDemand();
  422. BeanUtils.copyProperties(byId, demand);
  423. demand.setPlanId(Long.valueOf(byId.getPlanPracticalId()));
  424. demand.setEvaluation(byId.getEvaluation().doubleValue());
  425. demand.setIsExcess(Integer.parseInt(byId.getIsExcess()));
  426. //同步到项目管理状态为需求待填制
  427. demand.setProjectStatus(PmProjectStatus.DEMAND_WAIT_FILL.getCode());
  428. demand.setPurchaseDeptId(Long.parseLong(byId.getPurchaseDeptId()));
  429. demand.setCreateTime(now);
  430. demand.setCreateBy(provisionalPlanVo.getUpdated());
  431. demand.setUpdateTime(demand.getCreateTime());
  432. demand.setUpdateBy(demand.getCreateBy());
  433. demand.setIsExcess(Integer.parseInt(byId.getIsExcess()));
  434. provisionalPlanVo.setProjectStatus(ProjectStatus.PLANTOEXAMINE.getCode());
  435. provisionalPlanMapper.updateById(byId);
  436. pmDemandMapper.insert(demand);
  437. demandService.updateDemandWarnStatus(demand.getDemandId());
  438. //计划附件也进行同步---查询临时计划附件后复制一份改为项目需求附件
  439. LambdaQueryWrapper<SysFileRef> sysFileRefLp = new LambdaQueryWrapper<>();
  440. sysFileRefLp.eq(SysFileRef::getRedId, byId.getPlanPracticalId());
  441. sysFileRefLp.in(SysFileRef::getType, Arrays.asList(SysFileRefEnum.PLAN_TEMPORARY.getType(), SysFileRefEnum.PLAN_TEMPORARY_EXAMINE.getType()));
  442. List<SysFileRef> sysFileRefs = sysFileRefMapper.selectList(sysFileRefLp);
  443. if (!ObjectUtils.isEmpty(sysFileRefs)) {
  444. for (SysFileRef ref : sysFileRefs) {
  445. ref.setRedId(demand.getDemandId());
  446. ref.setType(SysFileRefEnum.PM_DEMAND.getType());
  447. ref.setId(null);
  448. sysFileRefMapper.insert(ref);
  449. }
  450. for (SysFileRef ref : sysFileRefs) {
  451. ref.setRedId(byId.getPlanYearId());
  452. ref.setType(SysFileRefEnum.PLAN_YEAR.getType());
  453. ref.setId(null);
  454. ref.setCreated(provisionalPlanVo.getUpdated());
  455. ref.setCreateTime(now);
  456. ref.setUpdated(provisionalPlanVo.getUpdated());
  457. ref.setUpdateTime(now);
  458. sysFileRefMapper.insert(ref);
  459. }
  460. }
  461. }
  462. return review(provisionalPlanVo);
  463. }
  464. @Override
  465. public AjaxResult auditNoPass(ProvisionalPlanVo provisionalPlanVo) {
  466. Date now = new Date();
  467. provisionalPlanVo.setProjectStatus(ProjectStatus.PLANTOBACK.getCode());
  468. //上传审核文件并赋予计划审核退回
  469. List<SysFileRef> sysFileRefuses = provisionalPlanVo.getSysFileRefs();
  470. if (!ObjectUtils.isEmpty(sysFileRefuses)) {
  471. for (SysFileRef ref : sysFileRefuses) {
  472. ref.setRedId(provisionalPlanVo.getPlanPracticalId());
  473. ref.setType(SysFileRefEnum.PLAN_TEMPORARY_EXAMINE.getType());
  474. ref.setCreated(provisionalPlanVo.getUpdated());
  475. ref.setCreateTime(now);
  476. ref.setUpdated(provisionalPlanVo.getUpdated());
  477. ref.setUpdateTime(now);
  478. sysFileRefMapper.insert(ref);
  479. }
  480. }
  481. return review(provisionalPlanVo);
  482. }
  483. @Override
  484. public List<ProvisionalPlan> queryPage(ProvisionalPlanVo vo) {
  485. List<ProvisionalPlan> provisionalPlanList = provisionalPlanMapper.query(vo);
  486. if (!ObjectUtils.isEmpty(provisionalPlanList)) {
  487. provisionalPlanList.stream().map(o -> {
  488. LambdaQueryWrapper<PmAuditDeptRef> lw = new LambdaQueryWrapper();
  489. lw.eq(PmAuditDeptRef::getRefId, o.getPlanPracticalId());
  490. lw.eq(PmAuditDeptRef::getRefType, "1");
  491. List<PmAuditDeptRef> list = pmAuditDeptRefService.list(lw);
  492. if (!ObjectUtils.isEmpty(list)) {
  493. List<PmAuditDeptRef> collect = list.stream()
  494. .filter(f -> f.getDeptId().equals(Long.valueOf(vo.getPurchaseDeptId())))
  495. .collect(Collectors.toList());
  496. String deptLevel = collect.get(0).getDeptLevel();
  497. boolean f = true;
  498. f = collect.get(0).getStatus().equals(Integer.parseInt("1")) ? false : true;
  499. for (PmAuditDeptRef pmAuditDeptRef : list) {
  500. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) == -1
  501. && pmAuditDeptRef.getStatus().equals(Integer.parseInt("0"))) {
  502. f = false;
  503. }
  504. }
  505. /*
  506. * String s1="A";
  507. String s2="B";
  508. System.out.println(s1.compareTo(s2));
  509. * over: -1
  510. * */
  511. o.setFlag(f);
  512. }
  513. return o;
  514. }).collect(Collectors.toList());
  515. }
  516. return provisionalPlanList;
  517. }
  518. private AjaxResult review(ProvisionalPlanVo vo) {
  519. int review = provisionalPlanMapper.review(vo);
  520. if (review != 1) {
  521. return AjaxResult.error("项目状态数据异常");
  522. }
  523. return AjaxResult.success();
  524. }
  525. // 字典项负值
  526. public ProvisionalPlan changeToProvisionalPlan(ProvisionalPlan provisionalPlan) {
  527. HashMap<String, HashMap<String, String>> planEnums = dictTypeService.getAboutEnums();
  528. HashMap<String, String> projectTypesMap = planEnums.get("projectTypes");
  529. HashMap<String, String> planPurchaseModesMap = planEnums.get("planPurchaseModes");
  530. HashMap<String, String> projectAttributes = planEnums.get("projectAttributes");
  531. HashMap<String, String> purchaseServices = planEnums.get("purchaseServices");
  532. if (provisionalPlan.getPurchaseDeptId() != null) {
  533. SysDeptResponseVo sysDeptResponseVo = (SysDeptResponseVo) deptService.selectDeptById(Long.valueOf(provisionalPlan.getPurchaseDeptId())).get("sysDept");
  534. provisionalPlan.setPurchaseDeptName(sysDeptResponseVo.getDeptName());
  535. }
  536. for (Map.Entry<String, String> entry : projectTypesMap.entrySet()) {
  537. if (provisionalPlan.getProjectType() != null && provisionalPlan.getProjectType().equals(entry.getValue())) {
  538. provisionalPlan.setProjectTypeStr(entry.getKey());
  539. break;
  540. }
  541. }
  542. for (Map.Entry<String, String> entry : planPurchaseModesMap.entrySet()) {
  543. if (provisionalPlan.getPurchaseMode() != null && provisionalPlan.getPurchaseMode().equals(entry.getValue())) {
  544. provisionalPlan.setPurchaseModeStr(entry.getKey());
  545. break;
  546. }
  547. }
  548. //项目属性是拼接的
  549. if (provisionalPlan.getProjectAttr().length() > 1) {
  550. StringBuilder builder = new StringBuilder();
  551. String[] split = provisionalPlan.getProjectAttr().split(",");
  552. for (String s : split) {
  553. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  554. if (s.equals(entry.getValue())) {
  555. builder.append(entry.getKey() + ",");
  556. break;
  557. }
  558. }
  559. }
  560. provisionalPlan.setProjectAttrStr(builder.toString());
  561. } else {
  562. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  563. if (provisionalPlan.getProjectAttr() != null && provisionalPlan.getProjectAttr().equals(entry.getValue())) {
  564. provisionalPlan.setProjectAttrStr(entry.getKey());
  565. break;
  566. }
  567. }
  568. }
  569. /*for (Map.Entry<String, String> entry : purchaseServices.entrySet()) {
  570. if (provisionalPlan.getPurchaseServices() != null && provisionalPlan.getPurchaseServices().equals(entry.getValue())) {
  571. provisionalPlan.setPurchaseServicesStr(entry.getKey());
  572. break;
  573. }
  574. }*/
  575. return provisionalPlan;
  576. }
  577. //字段赋值对应的名称
  578. public List<ProvisionalPlan> changeTo(List<ProvisionalPlan> provisionalPlans) {
  579. HashMap<String, HashMap<String, String>> planEnums = dictTypeService.getAboutEnums();
  580. HashMap<String, String> projectTypesMap = planEnums.get("projectTypes");
  581. HashMap<String, String> planPurchaseModesMap = planEnums.get("planPurchaseModes");
  582. HashMap<String, String> projectAttributes = planEnums.get("projectAttributes");
  583. HashMap<String, String> purchaseServices = planEnums.get("purchaseServices");
  584. List<ProvisionalPlan> list = new ArrayList<ProvisionalPlan>();
  585. for (ProvisionalPlan provisionalPlan : provisionalPlans) {
  586. if (provisionalPlan.getPurchaseDeptId() != null) {
  587. SysDeptResponseVo sysDeptResponseVo = (SysDeptResponseVo) deptService.selectDeptById(Long.valueOf(provisionalPlan.getPurchaseDeptId())).get("sysDept");
  588. provisionalPlan.setPurchaseDeptName(sysDeptResponseVo.getDeptName());
  589. }
  590. for (Map.Entry<String, String> entry : projectTypesMap.entrySet()) {
  591. if (provisionalPlan.getProjectType() != null && provisionalPlan.getProjectType().equals(entry.getValue())) {
  592. provisionalPlan.setProjectTypeStr(entry.getKey());
  593. break;
  594. }
  595. }
  596. for (Map.Entry<String, String> entry : planPurchaseModesMap.entrySet()) {
  597. if (provisionalPlan.getPurchaseMode() != null && provisionalPlan.getPurchaseMode().equals(entry.getValue())) {
  598. provisionalPlan.setPurchaseModeStr(entry.getKey());
  599. break;
  600. }
  601. }
  602. //项目属性是拼接的
  603. if (provisionalPlan.getProjectAttr().length() > 1) {
  604. StringBuilder builder = new StringBuilder();
  605. String[] split = provisionalPlan.getProjectAttr().split(",");
  606. for (String s : split) {
  607. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  608. if (s.equals(entry.getValue())) {
  609. builder.append(entry.getKey() + ",");
  610. break;
  611. }
  612. }
  613. }
  614. provisionalPlan.setProjectAttrStr(builder.toString());
  615. } else {
  616. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  617. if (provisionalPlan.getProjectAttr() != null && provisionalPlan.getProjectAttr().equals(entry.getValue())) {
  618. provisionalPlan.setProjectAttrStr(entry.getKey());
  619. break;
  620. }
  621. }
  622. }
  623. // 采购服务站
  624. // for (Map.Entry<String, String> entry : purchaseServices.entrySet()) {
  625. // if (provisionalPlan.getPurchaseServices() != null && provisionalPlan.getPurchaseServices().equals(entry.getValue())) {
  626. // provisionalPlan.setPurchaseServicesStr(entry.getKey());
  627. // break;
  628. // }
  629. // }
  630. list.add(provisionalPlan);
  631. }
  632. return list;
  633. }
  634. }