ProvisionalPlanServiceImpl.java 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. package com.ozs.plan.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.github.pagehelper.PageInfo;
  6. import com.ozs.common.core.domain.AjaxResult;
  7. import com.ozs.common.core.domain.entity.SysDept;
  8. import com.ozs.common.core.domain.entity.SysUser;
  9. import com.ozs.common.core.domain.model.LoginUser;
  10. import com.ozs.common.enums.DataIsDelete;
  11. import com.ozs.common.enums.PmProjectStatus;
  12. import com.ozs.common.enums.ProjectStatus;
  13. import com.ozs.common.enums.SysFileRefEnum;
  14. import com.ozs.common.exception.ServiceException;
  15. import com.ozs.common.utils.DateUtils;
  16. import com.ozs.common.utils.PageUtils;
  17. import com.ozs.common.utils.SecurityUtils;
  18. import com.ozs.common.utils.StringUtils;
  19. import com.ozs.common.utils.bean.BeanUtils;
  20. import com.ozs.plan.doman.PlanQuarter;
  21. import com.ozs.plan.doman.PlanYears;
  22. import com.ozs.plan.doman.ProvisionalPlan;
  23. import com.ozs.plan.doman.vo.requestVo.PlanQuarterStandardVo;
  24. import com.ozs.plan.doman.vo.requestVo.PlanYearsStandardVo;
  25. import com.ozs.plan.doman.vo.requestVo.ProvisionalPlanVo;
  26. import com.ozs.plan.doman.vo.responseVo.ProvisionalPlanResVo;
  27. import com.ozs.plan.mapper.PlanYearsMapper;
  28. import com.ozs.plan.mapper.ProvisionalPlanMapper;
  29. import com.ozs.plan.service.PlanQuarterService;
  30. import com.ozs.plan.service.ProvisionalPlanService;
  31. import com.ozs.pm.doman.PmAuditDeptRef;
  32. import com.ozs.pm.doman.PmDemand;
  33. import com.ozs.pm.mapper.PmAuditDeptRefMapper;
  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.SysDeptOrgan;
  38. import com.ozs.system.domain.SysFileInfo;
  39. import com.ozs.system.domain.SysFileRef;
  40. import com.ozs.system.domain.vo.responseVo.SysDeptResponseVo;
  41. import com.ozs.system.mapper.SysDeptMapper;
  42. import com.ozs.system.mapper.SysDeptOrganMapper;
  43. import com.ozs.system.mapper.SysFileRefMapper;
  44. import com.ozs.system.service.ISysDeptService;
  45. import com.ozs.system.service.ISysDictTypeService;
  46. import com.ozs.system.service.ISysUserService;
  47. import com.ozs.system.service.SysDeptOrganService;
  48. import com.ozs.system.service.SysFileService;
  49. import org.springframework.beans.factory.annotation.Autowired;
  50. import org.springframework.stereotype.Service;
  51. import org.springframework.transaction.annotation.Transactional;
  52. import org.springframework.util.ObjectUtils;
  53. import javax.servlet.http.HttpServletRequest;
  54. import java.math.BigDecimal;
  55. import java.text.ParseException;
  56. import java.text.SimpleDateFormat;
  57. import java.util.*;
  58. import java.util.stream.Collectors;
  59. @Service
  60. public class ProvisionalPlanServiceImpl extends ServiceImpl<ProvisionalPlanMapper, ProvisionalPlan> implements ProvisionalPlanService {
  61. @Autowired
  62. private SysDeptMapper deptMapper;
  63. @Autowired
  64. private SysFileService fileService;
  65. @Autowired
  66. private ISysUserService userService;
  67. @Autowired
  68. private ISysDeptService deptService;
  69. @Autowired
  70. private PmDemandMapper pmDemandMapper;
  71. @Autowired
  72. private IPmDemandService demandService;
  73. @Autowired
  74. private PlanYearsMapper planYearsMapper;
  75. @Autowired
  76. private PlanQuarterService quarterService;
  77. @Autowired
  78. private SysFileRefMapper sysFileRefMapper;
  79. @Autowired
  80. private ISysDictTypeService dictTypeService;
  81. @Autowired
  82. private SysDeptOrganMapper sysDeptOrganMapper;
  83. @Autowired
  84. private PmAuditDeptRefMapper pmAuditDeptRefMapper;
  85. @Autowired
  86. private PmAuditDeptRefService pmAuditDeptRefService;
  87. @Autowired
  88. private ProvisionalPlanMapper provisionalPlanMapper;
  89. @Override
  90. public int deleteProvisionalPlanById(Long planPracticalId) {
  91. return provisionalPlanMapper.deleteProvisionalPlanById(planPracticalId);
  92. }
  93. @Override
  94. @Transactional
  95. public int updateProvisionalPlanById(ProvisionalPlanVo provisionalPlan) {
  96. //默认未超额
  97. if (ObjectUtils.isEmpty(provisionalPlan.getIsExcess())) {
  98. provisionalPlan.setIsExcess("0");
  99. }
  100. List<SysFileRef> sysFileRefs = provisionalPlan.getSysFileRefs();
  101. if (!ObjectUtils.isEmpty(sysFileRefs)) {
  102. // 删关联
  103. LambdaQueryWrapper<SysFileRef> lw = new LambdaQueryWrapper<>();
  104. lw.eq(SysFileRef::getRedId, provisionalPlan.getPlanPracticalId());
  105. lw.eq(SysFileRef::getType, SysFileRefEnum.PLAN_TEMPORARY.getType());
  106. sysFileRefMapper.delete(lw);
  107. for (SysFileRef ref : sysFileRefs) {
  108. ref.setRedId(provisionalPlan.getPlanPracticalId());
  109. ref.setType(SysFileRefEnum.PLAN_TEMPORARY.getType());
  110. ref.setCreated(provisionalPlan.getCreated());
  111. ref.setCreateTime(new Date());
  112. ref.setUpdated(provisionalPlan.getCreated());
  113. ref.setUpdateTime(new Date());
  114. sysFileRefMapper.insert(ref);
  115. }
  116. }
  117. return provisionalPlanMapper.updateProvisionalPlanById(provisionalPlan);
  118. }
  119. @Override
  120. public String importProvisionalPlan(List<ProvisionalPlan> provisionalPlans, boolean updateSupport, LoginUser loginUser) {
  121. // 字典项
  122. HashMap<String, HashMap<String, String>> planEnums = dictTypeService.getAboutEnums();
  123. HashMap<String, String> projectTypesMap = planEnums.get("projectTypesAds");
  124. HashMap<String, String> projectAttributes = planEnums.get("projectAttributes");
  125. //预算科目
  126. HashMap<String, String> budgetAccountMap = planEnums.get("budgetAccount");
  127. int successNum = 0;
  128. int failureNum = 0;
  129. StringBuilder successMsg = new StringBuilder();
  130. StringBuilder failureMsg = new StringBuilder();
  131. for (ProvisionalPlan ofProvisionalPlan : provisionalPlans) {
  132. try {
  133. //将录入信息中的值更改为要保存的数据
  134. //采购单位
  135. SysDept info = deptMapper.checkDeptNameOnlyOne(ofProvisionalPlan.getPurchaseDeptName());
  136. if (StringUtils.isNotNull(info)) {
  137. ofProvisionalPlan.setPurchaseDeptId(String.valueOf(info.getDeptId()));
  138. }
  139. ofProvisionalPlan.setProjectType(projectTypesMap.get(ofProvisionalPlan.getProjectType()));
  140. ofProvisionalPlan.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode());
  141. //机关业务指导处是多选字段
  142. StringBuilder zBuilder = new StringBuilder();
  143. if (ofProvisionalPlan.getOrganDivision().contains(",")) {
  144. String[] split = ofProvisionalPlan.getOrganDivision().split(",");
  145. for (String s : split) {
  146. SysDeptOrgan infoTow = sysDeptOrganMapper.checkDeptOrganNameOnlyOne(s);
  147. //不是最后一位就加‘,’,是就直接结尾
  148. if (!ofProvisionalPlan.getOrganDivision().endsWith(s)) {
  149. if (!ObjectUtils.isEmpty(infoTow)) {
  150. zBuilder.append(infoTow.getId() + ",");
  151. } else {
  152. ++failureNum;
  153. failureMsg.append(failureNum + "、机关业务指导处(科)“" + ofProvisionalPlan.getOrganDivision() + "”不存在");
  154. }
  155. } else {
  156. if (!ObjectUtils.isEmpty(infoTow)) {
  157. zBuilder.append(infoTow.getId());
  158. } else {
  159. ++failureNum;
  160. failureMsg.append(failureNum + "、机关业务指导处(科)“" + ofProvisionalPlan.getOrganDivision() + "”不存在");
  161. }
  162. }
  163. }
  164. String zs = zBuilder.toString();
  165. if (zs.endsWith(",")) {
  166. zBuilder = null;
  167. zBuilder.append(zs.substring(0, zs.length() - 1));
  168. }
  169. } else {
  170. //没有多选
  171. SysDeptOrgan infoTow = sysDeptOrganMapper.checkDeptOrganNameOnlyOne(ofProvisionalPlan.getOrganDivision());
  172. if (!ObjectUtils.isEmpty(infoTow)) {
  173. zBuilder.append(infoTow.getId());
  174. } else {
  175. ++failureNum;
  176. failureMsg.append(failureNum + "、机关业务指导处(科)“" + ofProvisionalPlan.getOrganDivision() + "”不存在");
  177. }
  178. }
  179. ofProvisionalPlan.setOrganDivision(zBuilder.toString());
  180. ofProvisionalPlan.setBudgetAccount(budgetAccountMap.get(ofProvisionalPlan.getBudgetAccount()));
  181. //项目属性是多选字段
  182. StringBuilder builder = new StringBuilder();
  183. if (ofProvisionalPlan.getProjectAttr().contains(",")) {
  184. String[] split = ofProvisionalPlan.getProjectAttr().split(",");
  185. for (String s : split) {
  186. if (!ofProvisionalPlan.getProjectAttr().endsWith(s)) {
  187. builder.append(projectAttributes.get(s) + ",");
  188. } else {
  189. builder.append(projectAttributes.get(s));
  190. }
  191. }
  192. } else {
  193. builder.append(projectAttributes.get(ofProvisionalPlan.getProjectAttr()));
  194. }
  195. ofProvisionalPlan.setProjectAttr(builder.toString());
  196. //ofProvisionalPlan.setIsExcess(deptService.isExcessOrNo(ofProvisionalPlan.getProjectType(), ofProvisionalPlan.getEvaluation(), info.getDeptId()));
  197. ofProvisionalPlan.setCreated(String.valueOf(loginUser.getUserId()));
  198. ofProvisionalPlan.setCreateTime(new Date());
  199. ofProvisionalPlan.setPlanType("1");
  200. if (!ObjectUtils.isEmpty(ofProvisionalPlan.getPurchaseDeptId()) && !ObjectUtils.isEmpty(ofProvisionalPlan.getOrganDivision())) {
  201. provisionalPlanMapper.insert(ofProvisionalPlan);
  202. successNum++;
  203. successMsg.append(successNum + "、项目 " + ofProvisionalPlan.getProjectName() + " 导入成功!");
  204. }
  205. } catch (Exception exc) {
  206. failureNum++;
  207. String msg = successNum + "、项目 " + ofProvisionalPlan.getProjectName() + " 导入失败;";
  208. failureMsg.append(msg + exc.getMessage());
  209. log.error(msg, exc);
  210. }
  211. }
  212. if (failureNum > 0) {
  213. failureMsg.insert(0, "导入失败!共 " + failureNum + " 条数据格式不正确:");
  214. throw new ServiceException(failureMsg.toString());
  215. } else {
  216. successMsg.insert(0, "导入成功!共 " + successNum + " 条。");
  217. }
  218. return successMsg.toString();
  219. }
  220. @Override
  221. public List<ProvisionalPlanResVo> selectProvisionalPlanExport(ProvisionalPlanVo vo, LoginUser loginUser) {
  222. List<ProvisionalPlan> list = new ArrayList<>();
  223. List<ProvisionalPlanResVo> provisionalPlanList = new ArrayList<>();
  224. try {
  225. int num = 1;
  226. int size = 200;
  227. while (size == 200) {
  228. LambdaQueryWrapper<ProvisionalPlan> lw = new LambdaQueryWrapper<ProvisionalPlan>();
  229. lw.eq(ProvisionalPlan::getPlanType, "1");
  230. lw.eq(ProvisionalPlan::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  231. if (!loginUser.getUserId().equals(Long.valueOf("1"))) {
  232. lw.eq(ProvisionalPlan::getCreated, loginUser.getUserId());
  233. //lw.eq(ProvisionalPlan::getPurchaseDeptId, loginUser.getDeptId());
  234. }
  235. lw.eq(ProvisionalPlan::getPlanType, "1");
  236. if (!ObjectUtils.isEmpty(vo.getProjectName())) {
  237. lw.like(ProvisionalPlan::getProjectName, vo.getProjectName());
  238. }
  239. if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) {
  240. lw.eq(ProvisionalPlan::getPurchaseServices, vo.getPurchaseServices());
  241. }
  242. if (!ObjectUtils.isEmpty(vo.getIsExcess())) {
  243. lw.eq(ProvisionalPlan::getIsExcess, vo.getIsExcess());
  244. }
  245. if (!ObjectUtils.isEmpty(vo.getProjectStatus())) {
  246. lw.eq(ProvisionalPlan::getProjectStatus, vo.getProjectStatus());
  247. }
  248. if (!ObjectUtils.isEmpty(vo.getParams())) {
  249. if (!ObjectUtils.isEmpty(vo.getParams().get("beginTime"))) {
  250. lw.ge(ProvisionalPlan::getPlanDemandSubTime, vo.getParams().get("beginTime"));
  251. }
  252. if (!ObjectUtils.isEmpty(vo.getParams().get("endTime"))) {
  253. SimpleDateFormat dateFormatT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
  254. Date parse = dateFormatT.parse(vo.getParams().get("endTime").toString() + " 23:59:59:999");
  255. lw.le(ProvisionalPlan::getPlanDemandSubTime, parse);
  256. }
  257. }
  258. Page<ProvisionalPlan> page = provisionalPlanMapper.selectPage(new Page<ProvisionalPlan>(num, size, false), lw);
  259. list.addAll(page.getRecords());
  260. size = page.getRecords().size();
  261. num++;
  262. }
  263. provisionalPlanList = changeTo(list);
  264. } catch (Exception e) {
  265. e.printStackTrace();
  266. }
  267. return provisionalPlanList;
  268. }
  269. @Override
  270. @Transactional
  271. public int commitProvisionalPlan(ProvisionalPlanVo provisionalPlanVo) {
  272. ProvisionalPlan byId = provisionalPlanMapper.seletById(provisionalPlanVo.getPlanPracticalId());
  273. //申请修改之后再次提交,先清除上一次提交后的审核记录
  274. PmAuditDeptRef ref = new PmAuditDeptRef();
  275. ref.setRefId(byId.getPlanPracticalId());
  276. ref.setRefType("1");
  277. ref.setProjectType(byId.getProjectType());
  278. ref.setEvaluation(byId.getEvaluation());
  279. PlanQuarterServiceImpl.refIsExist(ref, pmAuditDeptRefMapper);
  280. PlanQuarterServiceImpl.insertAuditDeptRef(userService, pmAuditDeptRefService, ref);
  281. return provisionalPlanMapper.commitProvisionalPlan(provisionalPlanVo.getPlanPracticalId());
  282. }
  283. @Override
  284. public AjaxResult seletById(Long planPracticalId) {
  285. ProvisionalPlan provisionalPlan = provisionalPlanMapper.seletById(planPracticalId);
  286. if (StringUtils.isNull(provisionalPlan)) {
  287. return AjaxResult.error("数据查询失败");
  288. }
  289. // 转换字段中文
  290. ProvisionalPlan provisionalPlanC = changeToProvisionalPlan(provisionalPlan);
  291. LambdaQueryWrapper<SysFileRef> lw = new LambdaQueryWrapper<>();
  292. lw.eq(SysFileRef::getRedId, provisionalPlanC.getPlanPracticalId());
  293. lw.in(SysFileRef::getType, Arrays.asList(SysFileRefEnum.PLAN_TEMPORARY.getType(), SysFileRefEnum.PLAN_TEMPORARY_EXAMINE.getType()));
  294. List<SysFileRef> fileRefs = sysFileRefMapper.selectList(lw);
  295. List<SysFileInfo> fileInfos = new ArrayList<>();
  296. ProvisionalPlanVo provisionalPlanVo = new ProvisionalPlanVo();
  297. BeanUtils.copyProperties(provisionalPlanC, provisionalPlanVo);
  298. if (!ObjectUtils.isEmpty(fileRefs)) {
  299. for (SysFileRef ref : fileRefs) {
  300. SysFileInfo fileInfo = fileService.getById(ref.getFileId());
  301. fileInfos.add(fileInfo);
  302. }
  303. provisionalPlanVo.setFileInfos(fileInfos);
  304. }
  305. return AjaxResult.success(provisionalPlanVo);
  306. }
  307. @Override
  308. public AjaxResult selectProvisionalPlan(ProvisionalPlanVo vo, HttpServletRequest request, LoginUser loginUser) {
  309. List<ProvisionalPlanResVo> provisionalPlanList = new ArrayList<>();
  310. try {
  311. LambdaQueryWrapper<ProvisionalPlan> lw = new LambdaQueryWrapper<>();
  312. lw.eq(ProvisionalPlan::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  313. lw.eq(ProvisionalPlan::getPlanType, "1");
  314. if (!loginUser.getUserId().equals(Long.valueOf("1"))) {
  315. lw.eq(ProvisionalPlan::getCreated, loginUser.getUserId());
  316. //lw.eq(ProvisionalPlan::getPurchaseDeptId, loginUser.getDeptId());
  317. }
  318. if (!ObjectUtils.isEmpty(vo.getProjectName())) {
  319. lw.like(ProvisionalPlan::getProjectName, vo.getProjectName());
  320. }
  321. if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) {
  322. lw.eq(ProvisionalPlan::getPurchaseServices, vo.getPurchaseServices());
  323. }
  324. if (!ObjectUtils.isEmpty(vo.getIsExcess())) {
  325. lw.eq(ProvisionalPlan::getIsExcess, vo.getIsExcess());
  326. }
  327. if (!ObjectUtils.isEmpty(vo.getProjectStatus())) {
  328. lw.eq(ProvisionalPlan::getProjectStatus, vo.getProjectStatus());
  329. }
  330. if (!ObjectUtils.isEmpty(vo.getParams())) {
  331. if (!ObjectUtils.isEmpty(vo.getParams().get("beginTime"))) {
  332. lw.ge(ProvisionalPlan::getPlanDemandSubTime, vo.getParams().get("beginTime"));
  333. }
  334. if (!ObjectUtils.isEmpty(vo.getParams().get("endTime"))) {
  335. SimpleDateFormat dateFormatT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
  336. Date parse = dateFormatT.parse(vo.getParams().get("endTime").toString() + " 23:59:59:999");
  337. lw.le(ProvisionalPlan::getPlanDemandSubTime, parse);
  338. }
  339. }
  340. lw.orderBy(true, false, ProvisionalPlan::getCreateTime);
  341. List<ProvisionalPlan> list = provisionalPlanMapper.selectList(lw);
  342. provisionalPlanList = changeTo(list);
  343. } catch (Exception e) {
  344. e.printStackTrace();
  345. }
  346. Page pages = PageUtils.getPages(vo.getPageNum().intValue(), vo.getPageSize().intValue(), provisionalPlanList);
  347. PageInfo<ProvisionalPlan> provisionalPlanPageInfo = new PageInfo<>();
  348. if (!ObjectUtils.isEmpty(pages) && pages.getRecords().size() > 0) {
  349. provisionalPlanPageInfo.setList(pages.getRecords());
  350. provisionalPlanPageInfo.setSize(Math.toIntExact(pages.getSize()));
  351. provisionalPlanPageInfo.setPageNum(Math.toIntExact(pages.getCurrent()));
  352. provisionalPlanPageInfo.setTotal(pages.getTotal());
  353. provisionalPlanPageInfo.setPages(Integer.parseInt(pages.getPages() + ""));
  354. }
  355. return AjaxResult.success(provisionalPlanPageInfo);
  356. }
  357. @Override
  358. public AjaxResult selectProvisionalPlanAudit(ProvisionalPlanVo vo, HttpServletRequest request, LoginUser loginUser) {
  359. List<ProvisionalPlanResVo> provisionalPlanList = new ArrayList<>();
  360. try {
  361. LambdaQueryWrapper<ProvisionalPlan> lw = new LambdaQueryWrapper<>();
  362. lw.eq(ProvisionalPlan::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  363. lw.eq(ProvisionalPlan::getPlanType, "1");
  364. if (!loginUser.getUserId().equals(Long.valueOf("1"))) {
  365. lw.eq(ProvisionalPlan::getPurchaseDeptId, loginUser.getDeptId());
  366. }
  367. if (!ObjectUtils.isEmpty(vo.getProjectName())) {
  368. lw.like(ProvisionalPlan::getProjectName, vo.getProjectName());
  369. }
  370. if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) {
  371. lw.eq(ProvisionalPlan::getPurchaseServices, vo.getPurchaseServices());
  372. }
  373. if (!ObjectUtils.isEmpty(vo.getIsExcess())) {
  374. lw.eq(ProvisionalPlan::getIsExcess, vo.getIsExcess());
  375. }
  376. if (!ObjectUtils.isEmpty(vo.getProjectStatus())) {
  377. lw.eq(ProvisionalPlan::getProjectStatus, vo.getProjectStatus());
  378. } else {
  379. lw.apply(" project_status IN (1,2,3)", "");
  380. }
  381. if (!ObjectUtils.isEmpty(vo.getParams())) {
  382. if (!ObjectUtils.isEmpty(vo.getParams().get("beginTime"))) {
  383. lw.ge(ProvisionalPlan::getPlanDemandSubTime, vo.getParams().get("beginTime"));
  384. }
  385. if (!ObjectUtils.isEmpty(vo.getParams().get("endTime"))) {
  386. SimpleDateFormat dateFormatT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
  387. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  388. Date ofMonth = DateUtils.getLastDayOfMonth(dateFormat.parse(vo.getParams().get("endTime").toString()));
  389. Date parse = dateFormatT.parse(dateFormat.format(ofMonth) + " 23:59:59:999");
  390. lw.le(ProvisionalPlan::getPlanDemandSubTime, parse);
  391. }
  392. }
  393. lw.orderBy(true, false, ProvisionalPlan::getCreateTime);
  394. List<ProvisionalPlan> list = provisionalPlanMapper.selectList(lw);
  395. provisionalPlanList = changeTo(list);
  396. } catch (Exception e) {
  397. e.printStackTrace();
  398. }
  399. Page pages = PageUtils.getPages(vo.getPageNum().intValue(), vo.getPageSize().intValue(), provisionalPlanList);
  400. PageInfo<ProvisionalPlan> provisionalPlanPageInfo = new PageInfo<>();
  401. if (!ObjectUtils.isEmpty(pages) && pages.getRecords().size() > 0) {
  402. provisionalPlanPageInfo.setList(pages.getRecords());
  403. provisionalPlanPageInfo.setSize(Math.toIntExact(pages.getSize()));
  404. provisionalPlanPageInfo.setPageNum(Math.toIntExact(pages.getCurrent()));
  405. provisionalPlanPageInfo.setTotal(pages.getTotal());
  406. provisionalPlanPageInfo.setPages(Integer.parseInt(pages.getPages() + ""));
  407. }
  408. return AjaxResult.success(provisionalPlanPageInfo);
  409. }
  410. @Override
  411. @Transactional
  412. public AjaxResult auditPass(ProvisionalPlanVo provisionalPlanVo) {
  413. SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
  414. Long deptId = sysUser.getDeptId();
  415. SysDept sysDept = deptMapper.selectDeptById(deptId);
  416. String[] ancestors = sysDept.getAncestors().split(",");
  417. String deptLevel = null;
  418. if (ancestors.length == 2) { //C级
  419. deptLevel = "C";
  420. } else if (ancestors.length == 3) { //B级
  421. deptLevel = "B";
  422. } else if (ancestors.length == 4) { //A级
  423. deptLevel = "A";
  424. }
  425. LambdaQueryWrapper<PmAuditDeptRef> lw = new LambdaQueryWrapper();
  426. lw.eq(PmAuditDeptRef::getRefId, provisionalPlanVo.getPlanPracticalId());
  427. lw.eq(PmAuditDeptRef::getRefType, "1");
  428. List<PmAuditDeptRef> list = pmAuditDeptRefService.list(lw);
  429. boolean flay = true;
  430. if (!ObjectUtils.isEmpty(list)) {
  431. for (PmAuditDeptRef pmAuditDeptRef : list) {
  432. // 判断 deptLevel 是否还有更高的 且是 待审核的数据
  433. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) > 0
  434. && pmAuditDeptRef.getStatus().equals(Integer.parseInt("0"))) {
  435. flay = false;
  436. }
  437. // 更新当前 deptLevel 级别的审核状态
  438. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) == 0) {
  439. pmAuditDeptRef.setStatus(1);
  440. pmAuditDeptRefService.updateById(pmAuditDeptRef);
  441. }
  442. }
  443. }
  444. realReviewTo(provisionalPlanVo, flay);
  445. return AjaxResult.success();
  446. }
  447. public AjaxResult realReviewTo(ProvisionalPlanVo provisionalPlanVo, boolean flay) {
  448. Date now = new Date();
  449. ProvisionalPlan byId = provisionalPlanMapper.seletById(provisionalPlanVo.getPlanPracticalId());
  450. if (ObjectUtils.isEmpty(byId.getPlanYearId())) {
  451. PlanYears ofYears = new PlanYears();
  452. BeanUtils.copyProperties(byId, ofYears);
  453. ofYears.setProjectStatus(ProjectStatus.PLANTOEXAMINE.getCode());
  454. planYearsMapper.insertPlanYears(ofYears);
  455. byId.setPlanYearId(ofYears.getPlanYearId());
  456. }
  457. //上传审核文件
  458. PlanQuarterStandardVo standardVo = new PlanQuarterStandardVo();
  459. BeanUtils.copyProperties(provisionalPlanVo, standardVo);
  460. quarterService.upExamineFile(standardVo);
  461. if (flay) {
  462. PmDemand demand = new PmDemand();
  463. BeanUtils.copyProperties(byId, demand);
  464. demand.setPlanId(Long.valueOf(byId.getPlanPracticalId()));
  465. demand.setEvaluation(byId.getEvaluation().doubleValue());
  466. demand.setIsExcess(Integer.parseInt(byId.getIsExcess()));
  467. //同步到项目管理状态为需求待填制
  468. demand.setProjectStatus(PmProjectStatus.DEMAND_WAIT_FILL.getCode());
  469. demand.setPurchaseDeptId(Long.parseLong(byId.getPurchaseDeptId()));
  470. demand.setCreateTime(now);
  471. demand.setCreateBy(byId.getCreated());
  472. demand.setUpdateTime(now);
  473. demand.setUpdateBy(demand.getCreateBy());
  474. //demand.setIsExcess(Integer.parseInt(byId.getIsExcess()));
  475. pmDemandMapper.insert(demand);
  476. demandService.updateDemandWarnStatus(demand.getDemandId());
  477. //计划附件也进行同步---查询临时计划附件后复制一份改为项目需求附件
  478. LambdaQueryWrapper<SysFileRef> sysFileRefLp = new LambdaQueryWrapper<>();
  479. sysFileRefLp.eq(SysFileRef::getRedId, byId.getPlanPracticalId());
  480. sysFileRefLp.in(SysFileRef::getType, Arrays.asList(SysFileRefEnum.PLAN_TEMPORARY.getType(), SysFileRefEnum.PLAN_TEMPORARY_EXAMINE.getType()));
  481. List<SysFileRef> sysFileRefs = sysFileRefMapper.selectList(sysFileRefLp);
  482. if (!ObjectUtils.isEmpty(sysFileRefs)) {
  483. for (SysFileRef ref : sysFileRefs) {
  484. ref.setRedId(demand.getDemandId());
  485. ref.setType(SysFileRefEnum.PM_DEMAND.getType());
  486. ref.setId(null);
  487. sysFileRefMapper.insert(ref);
  488. }
  489. for (SysFileRef ref : sysFileRefs) {
  490. ref.setRedId(byId.getPlanYearId());
  491. ref.setType(SysFileRefEnum.PLAN_YEAR.getType());
  492. ref.setId(null);
  493. ref.setCreated(provisionalPlanVo.getUpdated());
  494. ref.setCreateTime(now);
  495. ref.setUpdated(provisionalPlanVo.getUpdated());
  496. ref.setUpdateTime(now);
  497. sysFileRefMapper.insert(ref);
  498. }
  499. }
  500. provisionalPlanMapper.updateById(byId);
  501. //赋予项目状态已审核
  502. provisionalPlanVo.setProjectStatus(ProjectStatus.PLANTOEXAMINE.getCode());
  503. return review(provisionalPlanVo);
  504. }
  505. return AjaxResult.success("成功");
  506. }
  507. @Override
  508. public AjaxResult auditNoPass(ProvisionalPlanVo provisionalPlanVo) {
  509. PlanQuarterStandardVo standardVo = new PlanQuarterStandardVo();
  510. BeanUtils.copyProperties(provisionalPlanVo, standardVo);
  511. //上传审核文件并赋予计划审核退回
  512. quarterService.upExamineFile(standardVo);
  513. provisionalPlanVo.setProjectStatus(ProjectStatus.PLANTOBACK.getCode());
  514. return review(provisionalPlanVo);
  515. }
  516. @Override
  517. public List<ProvisionalPlan> queryPage(ProvisionalPlanVo vo) throws ParseException {
  518. LoginUser loginUser = SecurityUtils.getLoginUser();
  519. if (!loginUser.getUserId().equals(Long.valueOf("1"))) {
  520. vo.setPurchaseDeptId(loginUser.getDeptId());
  521. }
  522. List<ProvisionalPlan> provisionalPlanList = provisionalPlanMapper.query(vo);
  523. if (!ObjectUtils.isEmpty(provisionalPlanList)) {
  524. provisionalPlanList.stream().map(o -> {
  525. LambdaQueryWrapper<PmAuditDeptRef> lw = new LambdaQueryWrapper();
  526. lw.eq(PmAuditDeptRef::getRefId, o.getPlanPracticalId());
  527. lw.eq(PmAuditDeptRef::getRefType, "1");
  528. List<PmAuditDeptRef> list = pmAuditDeptRefService.list(lw);
  529. boolean fl = true;
  530. if (!ObjectUtils.isEmpty(list) && list.size() > 0) {
  531. List<PmAuditDeptRef> collect = list.stream()
  532. .filter(f -> f.getDeptId().equals(Long.valueOf(vo.getPurchaseDeptId())))
  533. .collect(Collectors.toList());
  534. if (ObjectUtils.isEmpty(collect)) {
  535. fl = false;
  536. } else {
  537. String deptLevel = collect.get(0).getDeptLevel();
  538. fl = collect.get(0).getStatus().equals(Integer.parseInt("1")) ? false : true;
  539. for (PmAuditDeptRef pmAuditDeptRef : list) {
  540. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) == -1
  541. && pmAuditDeptRef.getStatus().equals(Integer.parseInt("0"))) {
  542. fl = false;
  543. }
  544. }
  545. }
  546. /*
  547. * String s1="A";
  548. String s2="B";
  549. System.out.println(s1.compareTo(s2));
  550. * over: -1
  551. * */
  552. }
  553. if (vo.getCreated().equals("1")) {
  554. fl = false;
  555. }
  556. o.setFlag(fl);
  557. return o;
  558. }).collect(Collectors.toList());
  559. }
  560. return provisionalPlanList;
  561. }
  562. @Override
  563. public Integer countYearProjectName(String projectName) {
  564. return provisionalPlanMapper.countYearProjectName(projectName);
  565. }
  566. @Override
  567. public Integer countProjectName(String projectName) {
  568. return provisionalPlanMapper.countProjectName(projectName);
  569. }
  570. @Override
  571. @Transactional
  572. public AjaxResult adPurchaseServices(ProvisionalPlanVo provisionalPlan) {
  573. ProvisionalPlan years = new ProvisionalPlan();
  574. BeanUtils.copyProperties(provisionalPlan, years);
  575. if (provisionalPlanMapper.updateById(years) == 1) {
  576. return AjaxResult.success("成功");
  577. }
  578. return AjaxResult.success("成功");
  579. }
  580. @Override
  581. public Integer countProjectNameOth(ProvisionalPlanVo provisionalPlan) {
  582. return provisionalPlanMapper.countProjectNameOth(provisionalPlan);
  583. }
  584. private AjaxResult review(ProvisionalPlanVo vo) {
  585. int review = provisionalPlanMapper.review(vo);
  586. if (review != 1) {
  587. return AjaxResult.error("项目状态数据异常");
  588. }
  589. return AjaxResult.success();
  590. }
  591. // 字典项负值
  592. public ProvisionalPlan changeToProvisionalPlan(ProvisionalPlan provisionalPlan) {
  593. HashMap<String, HashMap<String, String>> planEnums = dictTypeService.getAboutEnums();
  594. HashMap<String, String> projectTypesMap = planEnums.get("projectTypes");
  595. HashMap<String, String> projectAttributes = planEnums.get("projectAttributes");
  596. if (provisionalPlan.getPurchaseDeptId() != null) {
  597. SysDeptResponseVo sysDeptResponseVo = (SysDeptResponseVo) deptService.selectDeptById(Long.valueOf(provisionalPlan.getPurchaseDeptId())).get("sysDept");
  598. provisionalPlan.setPurchaseDeptName(sysDeptResponseVo.getDeptName());
  599. }
  600. for (Map.Entry<String, String> entry : projectTypesMap.entrySet()) {
  601. if (provisionalPlan.getProjectType() != null && provisionalPlan.getProjectType().equals(entry.getValue())) {
  602. provisionalPlan.setProjectTypeStr(entry.getKey());
  603. break;
  604. }
  605. }
  606. //项目属性是拼接的
  607. if (provisionalPlan.getProjectAttr().length() > 1) {
  608. StringBuilder builder = new StringBuilder();
  609. String[] split = provisionalPlan.getProjectAttr().split(",");
  610. for (String s : split) {
  611. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  612. if (s.equals(entry.getValue())) {
  613. builder.append(entry.getKey() + ",");
  614. break;
  615. }
  616. }
  617. }
  618. provisionalPlan.setProjectAttrName(builder.toString());
  619. } else {
  620. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  621. if (provisionalPlan.getProjectAttr() != null && provisionalPlan.getProjectAttr().equals(entry.getValue())) {
  622. provisionalPlan.setProjectAttrName(entry.getKey());
  623. break;
  624. }
  625. }
  626. }
  627. /*for (Map.Entry<String, String> entry : purchaseServices.entrySet()) {
  628. if (provisionalPlan.getPurchaseServices() != null && provisionalPlan.getPurchaseServices().equals(entry.getValue())) {
  629. provisionalPlan.setPurchaseServicesStr(entry.getKey());
  630. break;
  631. }
  632. }*/
  633. return provisionalPlan;
  634. }
  635. //字段赋值对应的名称
  636. public List<ProvisionalPlanResVo> changeTo(List<ProvisionalPlan> provisionalPlans) {
  637. //获取字典数据
  638. HashMap<String, HashMap<String, String>> planEnums = dictTypeService.getAboutEnums();
  639. //项目属性
  640. HashMap<String, String> projectAttributes = planEnums.get("projectAttributes");
  641. //项目审核状态
  642. HashMap<String, String> projectStatusMap = planEnums.get("projectStatus");
  643. //项目类型
  644. HashMap<String, String> projectTypesMap = planEnums.get("projectTypes");
  645. //预算科目
  646. HashMap<String, String> budgetAccountMap = planEnums.get("budgetAccount");
  647. //采购服务站
  648. HashMap<String, String> purchaseServicesMap = planEnums.get("purchaseServices");
  649. List<ProvisionalPlanResVo> list = new ArrayList<ProvisionalPlanResVo>();
  650. for (ProvisionalPlan provisionalPlan : provisionalPlans) {
  651. ProvisionalPlanResVo provisionalPlanResVo = new ProvisionalPlanResVo();
  652. if (provisionalPlan.getPurchaseDeptId() != null) {
  653. SysDeptResponseVo sysDeptResponseVo = (SysDeptResponseVo) deptService.selectDeptById(Long.valueOf(provisionalPlan.getPurchaseDeptId())).get("sysDept");
  654. provisionalPlan.setPurchaseDeptName(sysDeptResponseVo.getDeptName());
  655. }
  656. //预算科目
  657. for (Map.Entry<String, String> entry : budgetAccountMap.entrySet()) {
  658. if (!ObjectUtils.isEmpty(provisionalPlan.getBudgetAccount()) && provisionalPlan.getBudgetAccount().equals(entry.getValue())) {
  659. provisionalPlan.setBudgetAccountStr(entry.getKey());
  660. break;
  661. }
  662. }
  663. //采购服务站
  664. for (Map.Entry<String, String> entry : purchaseServicesMap.entrySet()) {
  665. if (!ObjectUtils.isEmpty(provisionalPlan.getPurchaseServices()) && provisionalPlan.getPurchaseServices().equals(entry.getValue())) {
  666. provisionalPlan.setPurchaseServicesStr(entry.getKey());
  667. break;
  668. }
  669. }
  670. //项目审核状态
  671. for (Map.Entry<String, String> entry : projectStatusMap.entrySet()) {
  672. if (!ObjectUtils.isEmpty(provisionalPlan.getProjectStatus()) && provisionalPlan.getProjectStatus().equals(entry.getValue())) {
  673. provisionalPlan.setProjectStatusStr(entry.getKey());
  674. break;
  675. }
  676. }
  677. //项目类型
  678. for (Map.Entry<String, String> entry : projectTypesMap.entrySet()) {
  679. if (provisionalPlan.getProjectType() != null && provisionalPlan.getProjectType().equals(entry.getValue())) {
  680. provisionalPlan.setProjectTypeStr(entry.getKey());
  681. break;
  682. }
  683. }
  684. //项目属性是拼接的
  685. if (provisionalPlan.getProjectAttr().length() > 1) {
  686. StringBuilder builder = new StringBuilder();
  687. String[] split = provisionalPlan.getProjectAttr().split(",");
  688. for (String s : split) {
  689. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  690. if (s.equals(entry.getValue())) {
  691. if (!provisionalPlan.getProjectAttr().endsWith(s)) {
  692. builder.append(entry.getKey() + ",");
  693. } else {
  694. builder.append(entry.getKey());
  695. }
  696. break;
  697. }
  698. }
  699. }
  700. provisionalPlan.setProjectAttrName(builder.toString());
  701. } else {
  702. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  703. if (provisionalPlan.getProjectAttr() != null && provisionalPlan.getProjectAttr().equals(entry.getValue())) {
  704. provisionalPlan.setProjectAttrName(entry.getKey());
  705. break;
  706. }
  707. }
  708. }
  709. //机关业务指导处(科)为id拼接
  710. String organDivision = provisionalPlan.getOrganDivision();
  711. if (!ObjectUtils.isEmpty(organDivision)) {
  712. int length = organDivision.split(",").length;
  713. SysDept sysDept = new SysDept();
  714. if (length > 1) {
  715. StringBuilder builder = new StringBuilder();
  716. String[] split = organDivision.split(",");
  717. for (String s : split) {
  718. sysDept = deptService.selectById(Long.valueOf(s));
  719. if (!ObjectUtils.isEmpty(sysDept)) {
  720. if (!organDivision.endsWith(s)) {
  721. builder.append(sysDept.getDeptName() + ",");
  722. } else {
  723. builder.append(sysDept.getDeptName());
  724. }
  725. }
  726. }
  727. provisionalPlan.setOrganDivisionStr(builder.toString());
  728. } else if (length == 1) {
  729. sysDept = deptService.selectById(Long.valueOf(organDivision));
  730. if (!ObjectUtils.isEmpty(sysDept)) {
  731. provisionalPlan.setOrganDivisionStr(sysDept.getDeptName());
  732. }
  733. }
  734. }
  735. //是否可以申请撤销和申请修改
  736. //需求待填制可以申请,需求建档就不能申请
  737. PmDemand demand = demandService.selectByPlanId(provisionalPlan.getPlanPracticalId());
  738. if (!ObjectUtils.isEmpty(demand) && !demand.getProjectStatus().equals(PmProjectStatus.DEMAND_WAIT_FILL.getCode())) {
  739. provisionalPlan.setAppDeleteDo("false");
  740. provisionalPlan.setAppUpdateDo("false");
  741. } else {
  742. //能否申请撤销
  743. if (!ObjectUtils.isEmpty(provisionalPlan.getAppDelete()) && provisionalPlan.getAppDelete().equals("true")) {
  744. //申请过的不能再申请
  745. provisionalPlan.setAppDeleteDo("false");
  746. } else if (provisionalPlan.getProjectStatus().equals("0")) {
  747. provisionalPlan.setAppDeleteDo("false");
  748. } else {
  749. //提交后可以申请撤销
  750. provisionalPlan.setAppDeleteDo("true");
  751. }
  752. //能否申请修改
  753. if (!ObjectUtils.isEmpty(provisionalPlan.getAppUpdate()) && provisionalPlan.getAppUpdate().equals("true")) {
  754. //申请过的不能再申请
  755. provisionalPlan.setAppUpdateDo("false");
  756. } else if (provisionalPlan.getProjectStatus().equals("0")) {
  757. provisionalPlan.setAppUpdateDo("false");
  758. } else {
  759. //提交后可以申请撤销
  760. provisionalPlan.setAppUpdateDo("true");
  761. }
  762. }
  763. BeanUtils.copyProperties(provisionalPlan, provisionalPlanResVo);
  764. //状态在采购需求对接和流废标退回之间的项目可以进行催告---已发函不可再次发函
  765. provisionalPlanResVo.setSendLetterDo("false");
  766. if (!ObjectUtils.isEmpty(demand)) {
  767. if (quarterService.sendLetterDo(demand.getProjectStatus()) && provisionalPlan.getSendLetter().equals("0")) {
  768. provisionalPlanResVo.setSendLetterDo("true");
  769. }
  770. }
  771. list.add(provisionalPlanResVo);
  772. }
  773. return list;
  774. }
  775. }