ProvisionalPlanServiceImpl.java 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  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()).setRefType("1").setProjectType(byId.getProjectType()).setEvaluation(byId.getEvaluation());
  276. PlanQuarterServiceImpl.refIsExist(ref, pmAuditDeptRefMapper);
  277. PlanQuarterServiceImpl.insertAuditDeptRef(userService, pmAuditDeptRefService, ref);
  278. return provisionalPlanMapper.commitProvisionalPlan(provisionalPlanVo.getPlanPracticalId());
  279. }
  280. @Override
  281. public AjaxResult seletById(Long planPracticalId) {
  282. ProvisionalPlan provisionalPlan = provisionalPlanMapper.seletById(planPracticalId);
  283. if (StringUtils.isNull(provisionalPlan)) {
  284. return AjaxResult.error("数据查询失败");
  285. }
  286. // 转换字段中文
  287. ProvisionalPlan provisionalPlanC = changeToProvisionalPlan(provisionalPlan);
  288. LambdaQueryWrapper<SysFileRef> lw = new LambdaQueryWrapper<>();
  289. lw.eq(SysFileRef::getRedId, provisionalPlanC.getPlanPracticalId());
  290. lw.in(SysFileRef::getType, Arrays.asList(SysFileRefEnum.PLAN_TEMPORARY.getType(), SysFileRefEnum.PLAN_TEMPORARY_EXAMINE.getType()));
  291. List<SysFileRef> fileRefs = sysFileRefMapper.selectList(lw);
  292. List<SysFileInfo> fileInfos = new ArrayList<>();
  293. ProvisionalPlanVo provisionalPlanVo = new ProvisionalPlanVo();
  294. BeanUtils.copyProperties(provisionalPlanC, provisionalPlanVo);
  295. if (!ObjectUtils.isEmpty(fileRefs)) {
  296. for (SysFileRef ref : fileRefs) {
  297. SysFileInfo fileInfo = fileService.getById(ref.getFileId());
  298. fileInfos.add(fileInfo);
  299. }
  300. provisionalPlanVo.setFileInfos(fileInfos);
  301. }
  302. return AjaxResult.success(provisionalPlanVo);
  303. }
  304. @Override
  305. public AjaxResult selectProvisionalPlan(ProvisionalPlanVo vo, HttpServletRequest request, LoginUser loginUser) {
  306. List<ProvisionalPlanResVo> provisionalPlanList = new ArrayList<>();
  307. try {
  308. LambdaQueryWrapper<ProvisionalPlan> lw = new LambdaQueryWrapper<>();
  309. lw.eq(ProvisionalPlan::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  310. lw.eq(ProvisionalPlan::getPlanType, "1");
  311. if (!loginUser.getUserId().equals(Long.valueOf("1"))) {
  312. lw.eq(ProvisionalPlan::getCreated, loginUser.getUserId());
  313. //lw.eq(ProvisionalPlan::getPurchaseDeptId, loginUser.getDeptId());
  314. }
  315. if (!ObjectUtils.isEmpty(vo.getProjectName())) {
  316. lw.like(ProvisionalPlan::getProjectName, vo.getProjectName());
  317. }
  318. if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) {
  319. lw.eq(ProvisionalPlan::getPurchaseServices, vo.getPurchaseServices());
  320. }
  321. if (!ObjectUtils.isEmpty(vo.getIsExcess())) {
  322. lw.eq(ProvisionalPlan::getIsExcess, vo.getIsExcess());
  323. }
  324. if (!ObjectUtils.isEmpty(vo.getProjectStatus())) {
  325. lw.eq(ProvisionalPlan::getProjectStatus, vo.getProjectStatus());
  326. }
  327. if (!ObjectUtils.isEmpty(vo.getParams())) {
  328. if (!ObjectUtils.isEmpty(vo.getParams().get("beginTime"))) {
  329. lw.ge(ProvisionalPlan::getPlanDemandSubTime, vo.getParams().get("beginTime"));
  330. }
  331. if (!ObjectUtils.isEmpty(vo.getParams().get("endTime"))) {
  332. SimpleDateFormat dateFormatT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
  333. Date parse = dateFormatT.parse(vo.getParams().get("endTime").toString() + " 23:59:59:999");
  334. lw.le(ProvisionalPlan::getPlanDemandSubTime, parse);
  335. }
  336. }
  337. lw.orderBy(true, false, ProvisionalPlan::getCreateTime);
  338. List<ProvisionalPlan> list = provisionalPlanMapper.selectList(lw);
  339. provisionalPlanList = changeTo(list);
  340. } catch (Exception e) {
  341. e.printStackTrace();
  342. }
  343. Page pages = PageUtils.getPages(vo.getPageNum().intValue(), vo.getPageSize().intValue(), provisionalPlanList);
  344. PageInfo<ProvisionalPlan> provisionalPlanPageInfo = new PageInfo<>();
  345. if (!ObjectUtils.isEmpty(pages) && pages.getRecords().size() > 0) {
  346. provisionalPlanPageInfo.setList(pages.getRecords());
  347. provisionalPlanPageInfo.setSize(Math.toIntExact(pages.getSize()));
  348. provisionalPlanPageInfo.setPageNum(Math.toIntExact(pages.getCurrent()));
  349. provisionalPlanPageInfo.setTotal(pages.getTotal());
  350. provisionalPlanPageInfo.setPages(Integer.parseInt(pages.getPages() + ""));
  351. }
  352. return AjaxResult.success(provisionalPlanPageInfo);
  353. }
  354. @Override
  355. public AjaxResult selectProvisionalPlanAudit(ProvisionalPlanVo vo, HttpServletRequest request, LoginUser loginUser) {
  356. List<ProvisionalPlanResVo> provisionalPlanList = new ArrayList<>();
  357. try {
  358. LambdaQueryWrapper<ProvisionalPlan> lw = new LambdaQueryWrapper<>();
  359. lw.eq(ProvisionalPlan::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  360. lw.eq(ProvisionalPlan::getPlanType, "1");
  361. if (!loginUser.getUserId().equals(Long.valueOf("1"))) {
  362. lw.eq(ProvisionalPlan::getPurchaseDeptId, loginUser.getDeptId());
  363. }
  364. if (!ObjectUtils.isEmpty(vo.getProjectName())) {
  365. lw.like(ProvisionalPlan::getProjectName, vo.getProjectName());
  366. }
  367. if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) {
  368. lw.eq(ProvisionalPlan::getPurchaseServices, vo.getPurchaseServices());
  369. }
  370. if (!ObjectUtils.isEmpty(vo.getIsExcess())) {
  371. lw.eq(ProvisionalPlan::getIsExcess, vo.getIsExcess());
  372. }
  373. if (!ObjectUtils.isEmpty(vo.getProjectStatus())) {
  374. lw.eq(ProvisionalPlan::getProjectStatus, vo.getProjectStatus());
  375. } else {
  376. lw.apply(" project_status IN (1,2,3)", "");
  377. }
  378. if (!ObjectUtils.isEmpty(vo.getParams())) {
  379. if (!ObjectUtils.isEmpty(vo.getParams().get("beginTime"))) {
  380. lw.ge(ProvisionalPlan::getPlanDemandSubTime, vo.getParams().get("beginTime"));
  381. }
  382. if (!ObjectUtils.isEmpty(vo.getParams().get("endTime"))) {
  383. SimpleDateFormat dateFormatT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
  384. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  385. Date ofMonth = DateUtils.getLastDayOfMonth(dateFormat.parse(vo.getParams().get("endTime").toString()));
  386. Date parse = dateFormatT.parse(dateFormat.format(ofMonth) + " 23:59:59:999");
  387. lw.le(ProvisionalPlan::getPlanDemandSubTime, parse);
  388. }
  389. }
  390. lw.orderBy(true, false, ProvisionalPlan::getCreateTime);
  391. List<ProvisionalPlan> list = provisionalPlanMapper.selectList(lw);
  392. provisionalPlanList = changeTo(list);
  393. } catch (Exception e) {
  394. e.printStackTrace();
  395. }
  396. Page pages = PageUtils.getPages(vo.getPageNum().intValue(), vo.getPageSize().intValue(), provisionalPlanList);
  397. PageInfo<ProvisionalPlan> provisionalPlanPageInfo = new PageInfo<>();
  398. if (!ObjectUtils.isEmpty(pages) && pages.getRecords().size() > 0) {
  399. provisionalPlanPageInfo.setList(pages.getRecords());
  400. provisionalPlanPageInfo.setSize(Math.toIntExact(pages.getSize()));
  401. provisionalPlanPageInfo.setPageNum(Math.toIntExact(pages.getCurrent()));
  402. provisionalPlanPageInfo.setTotal(pages.getTotal());
  403. provisionalPlanPageInfo.setPages(Integer.parseInt(pages.getPages() + ""));
  404. }
  405. return AjaxResult.success(provisionalPlanPageInfo);
  406. }
  407. @Override
  408. @Transactional
  409. public AjaxResult auditPass(ProvisionalPlanVo provisionalPlanVo) {
  410. SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
  411. Long deptId = sysUser.getDeptId();
  412. SysDept sysDept = deptMapper.selectDeptById(deptId);
  413. String[] ancestors = sysDept.getAncestors().split(",");
  414. String deptLevel = null;
  415. if (ancestors.length == 2) { //C级
  416. deptLevel = "C";
  417. } else if (ancestors.length == 3) { //B级
  418. deptLevel = "B";
  419. } else if (ancestors.length == 4) { //A级
  420. deptLevel = "A";
  421. }
  422. LambdaQueryWrapper<PmAuditDeptRef> lw = new LambdaQueryWrapper();
  423. lw.eq(PmAuditDeptRef::getRefId, provisionalPlanVo.getPlanPracticalId());
  424. lw.eq(PmAuditDeptRef::getRefType, "1");
  425. List<PmAuditDeptRef> list = pmAuditDeptRefService.list(lw);
  426. boolean flay = true;
  427. if (!ObjectUtils.isEmpty(list)) {
  428. for (PmAuditDeptRef pmAuditDeptRef : list) {
  429. // 判断 deptLevel 是否还有更高的 且是 待审核的数据
  430. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) > 0
  431. && pmAuditDeptRef.getStatus().equals(Integer.parseInt("0"))) {
  432. flay = false;
  433. }
  434. // 更新当前 deptLevel 级别的审核状态
  435. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) == 0) {
  436. pmAuditDeptRef.setStatus(1);
  437. pmAuditDeptRefService.updateById(pmAuditDeptRef);
  438. }
  439. }
  440. }
  441. realReviewTo(provisionalPlanVo, flay);
  442. return AjaxResult.success();
  443. }
  444. public AjaxResult realReviewTo(ProvisionalPlanVo provisionalPlanVo, boolean flay) {
  445. Date now = new Date();
  446. ProvisionalPlan byId = provisionalPlanMapper.seletById(provisionalPlanVo.getPlanPracticalId());
  447. if (ObjectUtils.isEmpty(byId.getPlanYearId())) {
  448. PlanYears ofYears = new PlanYears();
  449. BeanUtils.copyProperties(byId, ofYears);
  450. ofYears.setProjectStatus(ProjectStatus.PLANTOEXAMINE.getCode());
  451. planYearsMapper.insertPlanYears(ofYears);
  452. byId.setPlanYearId(ofYears.getPlanYearId());
  453. }
  454. //上传审核文件
  455. PlanQuarterStandardVo standardVo = new PlanQuarterStandardVo();
  456. BeanUtils.copyProperties(provisionalPlanVo, standardVo);
  457. quarterService.upExamineFile(standardVo);
  458. if (flay) {
  459. PmDemand demand = new PmDemand();
  460. BeanUtils.copyProperties(byId, demand);
  461. demand.setPlanId(Long.valueOf(byId.getPlanPracticalId()));
  462. demand.setEvaluation(byId.getEvaluation().doubleValue());
  463. demand.setIsExcess(Integer.parseInt(byId.getIsExcess()));
  464. //同步到项目管理状态为需求待填制
  465. demand.setProjectStatus(PmProjectStatus.DEMAND_WAIT_FILL.getCode());
  466. demand.setPurchaseDeptId(Long.parseLong(byId.getPurchaseDeptId()));
  467. demand.setCreateTime(now);
  468. demand.setCreateBy(byId.getCreated());
  469. demand.setUpdateTime(now);
  470. demand.setUpdateBy(demand.getCreateBy());
  471. //demand.setIsExcess(Integer.parseInt(byId.getIsExcess()));
  472. pmDemandMapper.insert(demand);
  473. demandService.updateDemandWarnStatus(demand.getDemandId());
  474. //计划附件也进行同步---查询临时计划附件后复制一份改为项目需求附件
  475. LambdaQueryWrapper<SysFileRef> sysFileRefLp = new LambdaQueryWrapper<>();
  476. sysFileRefLp.eq(SysFileRef::getRedId, byId.getPlanPracticalId());
  477. sysFileRefLp.in(SysFileRef::getType, Arrays.asList(SysFileRefEnum.PLAN_TEMPORARY.getType(), SysFileRefEnum.PLAN_TEMPORARY_EXAMINE.getType()));
  478. List<SysFileRef> sysFileRefs = sysFileRefMapper.selectList(sysFileRefLp);
  479. if (!ObjectUtils.isEmpty(sysFileRefs)) {
  480. for (SysFileRef ref : sysFileRefs) {
  481. ref.setRedId(demand.getDemandId());
  482. ref.setType(SysFileRefEnum.PM_DEMAND.getType());
  483. ref.setId(null);
  484. sysFileRefMapper.insert(ref);
  485. }
  486. for (SysFileRef ref : sysFileRefs) {
  487. ref.setRedId(byId.getPlanYearId());
  488. ref.setType(SysFileRefEnum.PLAN_YEAR.getType());
  489. ref.setId(null);
  490. ref.setCreated(provisionalPlanVo.getUpdated());
  491. ref.setCreateTime(now);
  492. ref.setUpdated(provisionalPlanVo.getUpdated());
  493. ref.setUpdateTime(now);
  494. sysFileRefMapper.insert(ref);
  495. }
  496. }
  497. provisionalPlanMapper.updateById(byId);
  498. //赋予项目状态已审核
  499. provisionalPlanVo.setProjectStatus(ProjectStatus.PLANTOEXAMINE.getCode());
  500. return review(provisionalPlanVo);
  501. }
  502. return AjaxResult.success("成功");
  503. }
  504. @Override
  505. public AjaxResult auditNoPass(ProvisionalPlanVo provisionalPlanVo) {
  506. PlanQuarterStandardVo standardVo = new PlanQuarterStandardVo();
  507. BeanUtils.copyProperties(provisionalPlanVo, standardVo);
  508. //上传审核文件并赋予计划审核退回
  509. quarterService.upExamineFile(standardVo);
  510. provisionalPlanVo.setProjectStatus(ProjectStatus.PLANTOBACK.getCode());
  511. return review(provisionalPlanVo);
  512. }
  513. @Override
  514. public List<ProvisionalPlan> queryPage(ProvisionalPlanVo vo) throws ParseException {
  515. LoginUser loginUser = SecurityUtils.getLoginUser();
  516. if (!loginUser.getUserId().equals(Long.valueOf("1"))) {
  517. vo.setPurchaseDeptId(loginUser.getDeptId());
  518. }
  519. List<ProvisionalPlan> provisionalPlanList = provisionalPlanMapper.query(vo);
  520. if (!ObjectUtils.isEmpty(provisionalPlanList)) {
  521. provisionalPlanList.stream().map(o -> {
  522. LambdaQueryWrapper<PmAuditDeptRef> lw = new LambdaQueryWrapper();
  523. lw.eq(PmAuditDeptRef::getRefId, o.getPlanPracticalId());
  524. lw.eq(PmAuditDeptRef::getRefType, "1");
  525. List<PmAuditDeptRef> list = pmAuditDeptRefService.list(lw);
  526. boolean fl = true;
  527. if (!ObjectUtils.isEmpty(list) && list.size() > 0) {
  528. List<PmAuditDeptRef> collect = list.stream()
  529. .filter(f -> f.getDeptId().equals(Long.valueOf(vo.getPurchaseDeptId())))
  530. .collect(Collectors.toList());
  531. if (ObjectUtils.isEmpty(collect)) {
  532. fl = false;
  533. } else {
  534. String deptLevel = collect.get(0).getDeptLevel();
  535. fl = collect.get(0).getStatus().equals(Integer.parseInt("1")) ? false : true;
  536. for (PmAuditDeptRef pmAuditDeptRef : list) {
  537. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) == -1
  538. && pmAuditDeptRef.getStatus().equals(Integer.parseInt("0"))) {
  539. fl = false;
  540. }
  541. }
  542. }
  543. /*
  544. * String s1="A";
  545. String s2="B";
  546. System.out.println(s1.compareTo(s2));
  547. * over: -1
  548. * */
  549. }
  550. if (vo.getCreated().equals("1")) {
  551. fl = false;
  552. }
  553. o.setFlag(fl);
  554. return o;
  555. }).collect(Collectors.toList());
  556. }
  557. return provisionalPlanList;
  558. }
  559. @Override
  560. public Integer countYearProjectName(String projectName) {
  561. return provisionalPlanMapper.countYearProjectName(projectName);
  562. }
  563. @Override
  564. public Integer countProjectName(String projectName) {
  565. return provisionalPlanMapper.countProjectName(projectName);
  566. }
  567. @Override
  568. @Transactional
  569. public AjaxResult adPurchaseServices(ProvisionalPlanVo provisionalPlan) {
  570. ProvisionalPlan years = new ProvisionalPlan();
  571. BeanUtils.copyProperties(provisionalPlan, years);
  572. if (provisionalPlanMapper.updateById(years) == 1) {
  573. return AjaxResult.success("成功");
  574. }
  575. return AjaxResult.success("成功");
  576. }
  577. @Override
  578. public Integer countProjectNameOth(ProvisionalPlanVo provisionalPlan) {
  579. return provisionalPlanMapper.countProjectNameOth(provisionalPlan);
  580. }
  581. private AjaxResult review(ProvisionalPlanVo vo) {
  582. int review = provisionalPlanMapper.review(vo);
  583. if (review != 1) {
  584. return AjaxResult.error("项目状态数据异常");
  585. }
  586. return AjaxResult.success();
  587. }
  588. // 字典项负值
  589. public ProvisionalPlan changeToProvisionalPlan(ProvisionalPlan provisionalPlan) {
  590. HashMap<String, HashMap<String, String>> planEnums = dictTypeService.getAboutEnums();
  591. HashMap<String, String> projectTypesMap = planEnums.get("projectTypes");
  592. HashMap<String, String> projectAttributes = planEnums.get("projectAttributes");
  593. if (provisionalPlan.getPurchaseDeptId() != null) {
  594. SysDeptResponseVo sysDeptResponseVo = (SysDeptResponseVo) deptService.selectDeptById(Long.valueOf(provisionalPlan.getPurchaseDeptId())).get("sysDept");
  595. provisionalPlan.setPurchaseDeptName(sysDeptResponseVo.getDeptName());
  596. }
  597. for (Map.Entry<String, String> entry : projectTypesMap.entrySet()) {
  598. if (provisionalPlan.getProjectType() != null && provisionalPlan.getProjectType().equals(entry.getValue())) {
  599. provisionalPlan.setProjectTypeStr(entry.getKey());
  600. break;
  601. }
  602. }
  603. //项目属性是拼接的
  604. if (provisionalPlan.getProjectAttr().length() > 1) {
  605. StringBuilder builder = new StringBuilder();
  606. String[] split = provisionalPlan.getProjectAttr().split(",");
  607. for (String s : split) {
  608. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  609. if (s.equals(entry.getValue())) {
  610. builder.append(entry.getKey() + ",");
  611. break;
  612. }
  613. }
  614. }
  615. provisionalPlan.setProjectAttrName(builder.toString());
  616. } else {
  617. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  618. if (provisionalPlan.getProjectAttr() != null && provisionalPlan.getProjectAttr().equals(entry.getValue())) {
  619. provisionalPlan.setProjectAttrName(entry.getKey());
  620. break;
  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. return provisionalPlan;
  631. }
  632. //字段赋值对应的名称
  633. public List<ProvisionalPlanResVo> changeTo(List<ProvisionalPlan> provisionalPlans) {
  634. //获取字典数据
  635. HashMap<String, HashMap<String, String>> planEnums = dictTypeService.getAboutEnums();
  636. //项目属性
  637. HashMap<String, String> projectAttributes = planEnums.get("projectAttributes");
  638. //项目审核状态
  639. HashMap<String, String> projectStatusMap = planEnums.get("projectStatus");
  640. //项目类型
  641. HashMap<String, String> projectTypesMap = planEnums.get("projectTypes");
  642. //预算科目
  643. HashMap<String, String> budgetAccountMap = planEnums.get("budgetAccount");
  644. //采购服务站
  645. HashMap<String, String> purchaseServicesMap = planEnums.get("purchaseServices");
  646. List<ProvisionalPlanResVo> list = new ArrayList<ProvisionalPlanResVo>();
  647. for (ProvisionalPlan provisionalPlan : provisionalPlans) {
  648. ProvisionalPlanResVo provisionalPlanResVo = new ProvisionalPlanResVo();
  649. if (provisionalPlan.getPurchaseDeptId() != null) {
  650. SysDeptResponseVo sysDeptResponseVo = (SysDeptResponseVo) deptService.selectDeptById(Long.valueOf(provisionalPlan.getPurchaseDeptId())).get("sysDept");
  651. provisionalPlan.setPurchaseDeptName(sysDeptResponseVo.getDeptName());
  652. }
  653. //预算科目
  654. for (Map.Entry<String, String> entry : budgetAccountMap.entrySet()) {
  655. if (!ObjectUtils.isEmpty(provisionalPlan.getBudgetAccount()) && provisionalPlan.getBudgetAccount().equals(entry.getValue())) {
  656. provisionalPlan.setBudgetAccountStr(entry.getKey());
  657. break;
  658. }
  659. }
  660. //采购服务站
  661. for (Map.Entry<String, String> entry : purchaseServicesMap.entrySet()) {
  662. if (!ObjectUtils.isEmpty(provisionalPlan.getPurchaseServices()) && provisionalPlan.getPurchaseServices().equals(entry.getValue())) {
  663. provisionalPlan.setPurchaseServicesStr(entry.getKey());
  664. break;
  665. }
  666. }
  667. //项目审核状态
  668. for (Map.Entry<String, String> entry : projectStatusMap.entrySet()) {
  669. if (!ObjectUtils.isEmpty(provisionalPlan.getProjectStatus()) && provisionalPlan.getProjectStatus().equals(entry.getValue())) {
  670. provisionalPlan.setProjectStatusStr(entry.getKey());
  671. break;
  672. }
  673. }
  674. //项目类型
  675. for (Map.Entry<String, String> entry : projectTypesMap.entrySet()) {
  676. if (provisionalPlan.getProjectType() != null && provisionalPlan.getProjectType().equals(entry.getValue())) {
  677. provisionalPlan.setProjectTypeStr(entry.getKey());
  678. break;
  679. }
  680. }
  681. //项目属性是拼接的
  682. if (provisionalPlan.getProjectAttr().length() > 1) {
  683. StringBuilder builder = new StringBuilder();
  684. String[] split = provisionalPlan.getProjectAttr().split(",");
  685. for (String s : split) {
  686. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  687. if (s.equals(entry.getValue())) {
  688. if (!provisionalPlan.getProjectAttr().endsWith(s)) {
  689. builder.append(entry.getKey() + ",");
  690. } else {
  691. builder.append(entry.getKey());
  692. }
  693. break;
  694. }
  695. }
  696. }
  697. provisionalPlan.setProjectAttrName(builder.toString());
  698. } else {
  699. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  700. if (provisionalPlan.getProjectAttr() != null && provisionalPlan.getProjectAttr().equals(entry.getValue())) {
  701. provisionalPlan.setProjectAttrName(entry.getKey());
  702. break;
  703. }
  704. }
  705. }
  706. //机关业务指导处(科)为id拼接
  707. String organDivision = provisionalPlan.getOrganDivision();
  708. if (!ObjectUtils.isEmpty(organDivision)) {
  709. int length = organDivision.split(",").length;
  710. SysDept sysDept = new SysDept();
  711. if (length > 1) {
  712. StringBuilder builder = new StringBuilder();
  713. String[] split = organDivision.split(",");
  714. for (String s : split) {
  715. sysDept = deptService.selectById(Long.valueOf(s));
  716. if (!ObjectUtils.isEmpty(sysDept)) {
  717. if (!organDivision.endsWith(s)) {
  718. builder.append(sysDept.getDeptName() + ",");
  719. } else {
  720. builder.append(sysDept.getDeptName());
  721. }
  722. }
  723. }
  724. provisionalPlan.setOrganDivisionStr(builder.toString());
  725. } else if (length == 1) {
  726. sysDept = deptService.selectById(Long.valueOf(organDivision));
  727. if (!ObjectUtils.isEmpty(sysDept)) {
  728. provisionalPlan.setOrganDivisionStr(sysDept.getDeptName());
  729. }
  730. }
  731. }
  732. //是否可以申请撤销和申请修改
  733. //需求待填制可以申请,需求建档就不能申请
  734. PmDemand demand = demandService.selectByPlanId(provisionalPlan.getPlanPracticalId());
  735. if (!ObjectUtils.isEmpty(demand) && !demand.getProjectStatus().equals(PmProjectStatus.DEMAND_WAIT_FILL.getCode())) {
  736. provisionalPlan.setAppDeleteDo("false");
  737. provisionalPlan.setAppUpdateDo("false");
  738. } else {
  739. //能否申请撤销
  740. if (!ObjectUtils.isEmpty(provisionalPlan.getAppDelete()) && provisionalPlan.getAppDelete().equals("true")) {
  741. //申请过的不能再申请
  742. provisionalPlan.setAppDeleteDo("false");
  743. } else if (provisionalPlan.getProjectStatus().equals("0")) {
  744. provisionalPlan.setAppDeleteDo("false");
  745. } else {
  746. //提交后可以申请撤销
  747. provisionalPlan.setAppDeleteDo("true");
  748. }
  749. //能否申请修改
  750. if (!ObjectUtils.isEmpty(provisionalPlan.getAppUpdate()) && provisionalPlan.getAppUpdate().equals("true")) {
  751. //申请过的不能再申请
  752. provisionalPlan.setAppUpdateDo("false");
  753. } else if (provisionalPlan.getProjectStatus().equals("0")) {
  754. provisionalPlan.setAppUpdateDo("false");
  755. } else {
  756. //提交后可以申请撤销
  757. provisionalPlan.setAppUpdateDo("true");
  758. }
  759. }
  760. BeanUtils.copyProperties(provisionalPlan, provisionalPlanResVo);
  761. //状态在采购需求对接和流废标退回之间的项目可以进行催告---已发函不可再次发函
  762. provisionalPlanResVo.setSendLetterDo("false");
  763. if (!ObjectUtils.isEmpty(demand)) {
  764. if (quarterService.sendLetterDo(demand.getProjectStatus()) && provisionalPlan.getSendLetter().equals("0")) {
  765. provisionalPlanResVo.setSendLetterDo("true");
  766. }
  767. }
  768. list.add(provisionalPlanResVo);
  769. }
  770. return list;
  771. }
  772. }