PlanQuarterServiceImpl.java 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  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.ozs.common.core.domain.AjaxResult;
  6. import com.ozs.common.core.domain.entity.SysDept;
  7. import com.ozs.common.core.domain.entity.SysDictData;
  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.QuarterEnum;
  14. import com.ozs.common.enums.SysFileRefEnum;
  15. import com.ozs.common.exception.ServiceException;
  16. import com.ozs.common.utils.DateUtils;
  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.vo.requestVo.PlanQuarterStandardVo;
  23. import com.ozs.plan.doman.vo.responseVo.PlanQuarterResponseVo;
  24. import com.ozs.plan.mapper.PlanQuarterMapper;
  25. import com.ozs.plan.mapper.PlanYearsMapper;
  26. import com.ozs.plan.service.PlanQuarterService;
  27. import com.ozs.pm.doman.PmAuditDeptRef;
  28. import com.ozs.pm.doman.PmDemand;
  29. import com.ozs.pm.mapper.PmAuditDeptRefMapper;
  30. import com.ozs.pm.mapper.PmDemandMapper;
  31. import com.ozs.pm.service.IPmDemandService;
  32. import com.ozs.pm.service.PmAuditDeptRefService;
  33. import com.ozs.system.domain.SysDeptOrgan;
  34. import com.ozs.system.domain.SysFileInfo;
  35. import com.ozs.system.domain.SysFileRef;
  36. import com.ozs.system.domain.vo.responseVo.SysDeptResponseVo;
  37. import com.ozs.system.mapper.SysDeptMapper;
  38. import com.ozs.system.mapper.SysDeptOrganMapper;
  39. import com.ozs.system.mapper.SysFileRefMapper;
  40. import com.ozs.system.service.ISysDeptService;
  41. import com.ozs.system.service.ISysDictDataService;
  42. import com.ozs.system.service.ISysDictTypeService;
  43. import com.ozs.system.service.ISysUserService;
  44. import com.ozs.system.service.SysFileService;
  45. import lombok.extern.slf4j.Slf4j;
  46. import org.springframework.beans.factory.annotation.Autowired;
  47. import org.springframework.security.core.token.TokenService;
  48. import org.springframework.stereotype.Service;
  49. import org.springframework.transaction.annotation.Transactional;
  50. import org.springframework.util.ObjectUtils;
  51. import javax.validation.Validator;
  52. import java.math.BigDecimal;
  53. import java.text.ParseException;
  54. import java.text.SimpleDateFormat;
  55. import java.util.ArrayList;
  56. import java.util.Arrays;
  57. import java.util.Calendar;
  58. import java.util.Date;
  59. import java.util.HashMap;
  60. import java.util.LinkedHashMap;
  61. import java.util.LinkedList;
  62. import java.util.List;
  63. import java.util.Map;
  64. import java.util.stream.Collectors;
  65. /**
  66. * @author buzhanyi
  67. */
  68. @Service
  69. @Slf4j
  70. public class PlanQuarterServiceImpl extends ServiceImpl<PlanQuarterMapper, PlanQuarter> implements PlanQuarterService {
  71. @Autowired
  72. PlanQuarterMapper planQuarterMapper;
  73. @Autowired
  74. PlanYearsMapper planYearsMapper;
  75. @Autowired
  76. protected Validator validator;
  77. @Autowired
  78. private ISysDictTypeService dictTypeService;
  79. @Autowired
  80. private ISysDeptService deptService;
  81. @Autowired
  82. SysFileRefMapper sysFileRefMapper;
  83. @Autowired
  84. private SysDeptMapper deptMapper;
  85. @Autowired
  86. private SysFileService fileService;
  87. @Autowired
  88. private PmDemandMapper pmDemandMapper;
  89. @Autowired
  90. private IPmDemandService demandService;
  91. @Autowired
  92. private ISysUserService userService;
  93. @Autowired
  94. private PmAuditDeptRefService pmAuditDeptRefService;
  95. @Autowired
  96. private PmAuditDeptRefMapper pmAuditDeptRefMapper;
  97. @Autowired
  98. private SysDeptOrganMapper sysDeptOrganMapper;
  99. @Override
  100. public List<PlanQuarterResponseVo> selectPlanQuarterListEXP(PlanQuarterStandardVo vo, LoginUser loginUser) {
  101. List<PlanQuarter> list = new ArrayList<>();
  102. List<PlanQuarterResponseVo> planQuarterList = new ArrayList<>();
  103. try {
  104. int num = 1;
  105. int size = 200;
  106. while (size == 200) {
  107. LambdaQueryWrapper<PlanQuarter> lw = new LambdaQueryWrapper<>();
  108. if (!loginUser.getUserId().equals(Long.valueOf("1"))) {
  109. lw.eq(PlanQuarter::getCreated, loginUser.getUserId());
  110. //lw.eq(PlanQuarter::getPurchaseDeptId, loginUser.getDeptId());
  111. }
  112. lw.eq(PlanQuarter::getPlanType, "0");
  113. if (!ObjectUtils.isEmpty(vo.getProjectName())) {
  114. lw.like(PlanQuarter::getProjectName, vo.getProjectName());
  115. }
  116. if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) {
  117. lw.eq(PlanQuarter::getPurchaseServices, vo.getPurchaseServices());
  118. }
  119. if (!ObjectUtils.isEmpty(vo.getProjectStatus())) {
  120. lw.eq(PlanQuarter::getProjectStatus, vo.getProjectStatus());
  121. }
  122. if (!ObjectUtils.isEmpty(vo.getParams())) {
  123. if (!ObjectUtils.isEmpty(vo.getParams().get("beginTime"))) {
  124. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
  125. Date ofMonth = dateFormat.parse(vo.getParams().get("beginTime").toString() + "-01");
  126. lw.ge(PlanQuarter::getPlanDemandSubTime, ofMonth);
  127. }
  128. if (!ObjectUtils.isEmpty(vo.getParams().get("endTime"))) {
  129. SimpleDateFormat dateFormaH = new SimpleDateFormat("yyyy-MM");
  130. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  131. SimpleDateFormat dateFormatT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
  132. Date ofMonth = DateUtils.getLastDayOfMonth(dateFormaH.parse(vo.getParams().get("endTime").toString()));
  133. Date parse = dateFormatT.parse(dateFormat.format(ofMonth) + " 23:59:59:999");
  134. lw.le(PlanQuarter::getPlanDemandSubTime, parse);
  135. }
  136. }
  137. lw.eq(PlanQuarter::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  138. Page<PlanQuarter> page = planQuarterMapper.selectPage(new Page<>(num, size, false), lw);
  139. list.addAll(page.getRecords());
  140. size = page.getRecords().size();
  141. num++;
  142. }
  143. planQuarterList = changeTo(list);
  144. } catch (Exception e) {
  145. e.printStackTrace();
  146. }
  147. return planQuarterList;
  148. }
  149. @Override
  150. public List<PlanQuarterResponseVo> selectPlanQuarterExamineListEXP(PlanQuarterStandardVo vo, LoginUser loginUser) {
  151. List<PlanQuarter> list = new ArrayList<>();
  152. List<PlanQuarterResponseVo> planQuarterList = new ArrayList<>();
  153. try {
  154. int num = 1;
  155. int size = 200;
  156. while (size == 200) {
  157. LambdaQueryWrapper<PlanQuarter> lw = new LambdaQueryWrapper<PlanQuarter>();
  158. if (!loginUser.getUserId().equals(Long.valueOf("1"))) {
  159. lw.eq(PlanQuarter::getPurchaseDeptId, loginUser.getDeptId());
  160. }
  161. lw.eq(PlanQuarter::getPlanType, "0");
  162. if (!ObjectUtils.isEmpty(vo.getProjectName())) {
  163. lw.like(PlanQuarter::getProjectName, vo.getProjectName());
  164. }
  165. if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) {
  166. lw.eq(PlanQuarter::getPurchaseServices, vo.getPurchaseServices());
  167. }
  168. if (!ObjectUtils.isEmpty(vo.getProjectStatus())) {
  169. lw.eq(PlanQuarter::getProjectStatus, vo.getProjectStatus());
  170. } else {
  171. lw.in(PlanQuarter::getProjectStatus, "1,3,4");
  172. }
  173. if (!ObjectUtils.isEmpty(vo.getParams())) {
  174. if (!ObjectUtils.isEmpty(vo.getParams().get("beginTime"))) {
  175. lw.ge(PlanQuarter::getPlanDemandSubTime, vo.getParams().get("beginTime"));
  176. }
  177. if (!ObjectUtils.isEmpty(vo.getParams().get("endTime"))) {
  178. SimpleDateFormat dateFormatT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
  179. Date parse = dateFormatT.parse(vo.getParams().get("endTime").toString() + " 23:59:59:999");
  180. lw.le(PlanQuarter::getPlanDemandSubTime, parse);
  181. }
  182. }
  183. lw.eq(PlanQuarter::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  184. Page<PlanQuarter> page = planQuarterMapper.selectPage(new Page<PlanQuarter>(num, size, false), lw);
  185. list.addAll(page.getRecords());
  186. size = page.getRecords().size();
  187. num++;
  188. }
  189. planQuarterList = changeTo(list);
  190. } catch (Exception e) {
  191. e.printStackTrace();
  192. }
  193. return planQuarterList;
  194. }
  195. @Transactional
  196. @Override
  197. public AjaxResult insertPlanQuarter(PlanQuarterStandardVo quarterStandardVo) {
  198. if (planQuarterMapper.countProjectName(quarterStandardVo.getProjectName()) > 0) {
  199. return AjaxResult.error("该项目名称已经存在");
  200. }
  201. //默认未超额
  202. PlanQuarter quarters = new PlanQuarter();
  203. try {
  204. BeanUtils.copyProperties(quarterStandardVo, quarters);
  205. } catch (Exception e) {
  206. e.printStackTrace();
  207. }
  208. quarters.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode());
  209. quarters.setCreateTime(new Date());
  210. planQuarterMapper.insertPlanQuarter(quarters);
  211. log.info("id:{}", quarters.getPlanPracticalId());
  212. List<SysFileRef> sysFileRefs = quarterStandardVo.getSysFileRefs();
  213. if (!ObjectUtils.isEmpty(sysFileRefs)) {
  214. for (SysFileRef ref : sysFileRefs) {
  215. ref.setRedId(quarters.getPlanPracticalId());
  216. ref.setType(SysFileRefEnum.PLAN_TEMPORARY.getType());
  217. ref.setCreated(quarters.getCreated());
  218. ref.setCreateTime(new Date());
  219. ref.setUpdated(quarters.getCreated());
  220. ref.setUpdateTime(new Date());
  221. sysFileRefMapper.insert(ref);
  222. }
  223. }
  224. return AjaxResult.success();
  225. }
  226. @Override
  227. public AjaxResult deletePlanQuarterByIds(Long[] planIds) {
  228. planQuarterMapper.deletePlanQuarterByIds(planIds);
  229. return AjaxResult.success();
  230. }
  231. @Override
  232. public AjaxResult deletePlanQuarterById(Long planId) {
  233. planQuarterMapper.deletePlanQuarterById(planId);
  234. return AjaxResult.success();
  235. }
  236. @Override
  237. public AjaxResult view(PlanQuarterStandardVo quarterStandardVo) {
  238. PlanQuarterResponseVo responseVo = new PlanQuarterResponseVo();
  239. PlanQuarter byId = planQuarterMapper.getById(quarterStandardVo.getPlanPracticalId());
  240. if (byId == null) {
  241. return AjaxResult.error("数据查询失败");
  242. }
  243. SysDeptResponseVo sysDeptResponseVo = (SysDeptResponseVo) deptService.selectDeptById(Long.valueOf(byId.getPurchaseDeptId())).get("sysDept");
  244. byId.setPurchaseDeptName(sysDeptResponseVo.getDeptName());
  245. LambdaQueryWrapper<SysFileRef> lw = new LambdaQueryWrapper<>();
  246. lw.eq(SysFileRef::getRedId, quarterStandardVo.getPlanPracticalId());
  247. lw.in(SysFileRef::getType, Arrays.asList(SysFileRefEnum.PLAN_TEMPORARY.getType(), SysFileRefEnum.PLAN_TEMPORARY_EXAMINE.getType()));
  248. List<SysFileRef> fileRefs = sysFileRefMapper.selectList(lw);
  249. List<SysFileInfo> fileInfos = new ArrayList<>();
  250. BeanUtils.copyProperties(byId, responseVo);
  251. if (!ObjectUtils.isEmpty(fileRefs)) {
  252. for (SysFileRef ref : fileRefs) {
  253. SysFileInfo fileInfo = fileService.getById(ref.getFileId());
  254. fileInfos.add(fileInfo);
  255. }
  256. responseVo.setFileInfos(fileInfos);
  257. }
  258. String organDivision = byId.getOrganDivision();
  259. if (!ObjectUtils.isEmpty(organDivision)) {
  260. int length = organDivision.split(",").length;
  261. SysDeptOrgan organ = new SysDeptOrgan();
  262. if (length > 1) {
  263. StringBuilder builder = new StringBuilder();
  264. String[] split = organDivision.split(",");
  265. for (String s : split) {
  266. organ = sysDeptOrganMapper.selectById(s);
  267. if (!ObjectUtils.isEmpty(organ)) {
  268. if (!organDivision.endsWith(s)) {
  269. builder.append(organ.getOrganName() + ",");
  270. } else {
  271. builder.append(organ.getOrganName());
  272. }
  273. }
  274. }
  275. responseVo.setOrganDivisionStr(builder.toString());
  276. } else if (length == 1) {
  277. organ = sysDeptOrganMapper.selectById(organDivision);
  278. if (!ObjectUtils.isEmpty(organ)) {
  279. responseVo.setOrganDivisionStr(organ.getOrganName());
  280. }
  281. }
  282. }
  283. return AjaxResult.success(responseVo);
  284. }
  285. @Transactional
  286. @Override
  287. public AjaxResult update(PlanQuarterStandardVo quarterStandardVo) {
  288. Date now = new Date();
  289. if (planQuarterMapper.countProjectNameOther(quarterStandardVo.getProjectName(), String.valueOf(quarterStandardVo.getPlanPracticalId())) > 0) {
  290. return AjaxResult.error("该项目名称已经存在");
  291. }
  292. PlanQuarter quarters = new PlanQuarter();
  293. try {
  294. BeanUtils.copyProperties(quarterStandardVo, quarters);
  295. } catch (Exception e) {
  296. e.printStackTrace();
  297. }
  298. quarters.setUpdateTime(now);
  299. PlanQuarter byId = planQuarterMapper.selectById(quarters.getPlanPracticalId());
  300. //临时计划修改后要更新年度计划
  301. if (byId.getPlanType().equals(Integer.parseInt("1"))) {
  302. if (!ObjectUtils.isEmpty(planYearsMapper.selectById(byId.getPlanYearId()))) {
  303. PlanYears years = new PlanYears();
  304. BeanUtils.copyProperties(quarterStandardVo, years);
  305. years.setProjectAttr(null);
  306. years.setPlanYearId(null);
  307. planYearsMapper.updateById(years);
  308. }
  309. }
  310. planQuarterMapper.updateById(quarters);
  311. List<SysFileRef> sysFileRefs = quarterStandardVo.getSysFileRefs();
  312. if (!ObjectUtils.isEmpty(sysFileRefs)) {
  313. // 删关联
  314. LambdaQueryWrapper<SysFileRef> lw = new LambdaQueryWrapper<>();
  315. lw.eq(SysFileRef::getRedId, quarters.getPlanPracticalId());
  316. lw.eq(SysFileRef::getType, SysFileRefEnum.PLAN_TEMPORARY.getType());
  317. sysFileRefMapper.delete(lw);
  318. for (SysFileRef ref : sysFileRefs) {
  319. ref.setRedId(quarters.getPlanPracticalId());
  320. ref.setType(SysFileRefEnum.PLAN_TEMPORARY.getType());
  321. ref.setCreated(quarterStandardVo.getUpdated());
  322. ref.setCreateTime(now);
  323. ref.setUpdated(quarterStandardVo.getUpdated());
  324. ref.setUpdateTime(now);
  325. sysFileRefMapper.insert(ref);
  326. }
  327. }
  328. return AjaxResult.success();
  329. }
  330. @Override
  331. public String importPlanQuarter(List<PlanQuarterStandardVo> planQuarters, boolean isUpdateSupport, LoginUser loginUser) {
  332. if (StringUtils.isNull(planQuarters) || planQuarters.size() == 0) {
  333. throw new ServiceException("导入季度计划数据不能为空!");
  334. }
  335. List<PlanQuarter> list = new ArrayList<>();
  336. for (PlanQuarterStandardVo standardVo : planQuarters) {
  337. PlanQuarter quarter = new PlanQuarter();
  338. BeanUtils.copyProperties(standardVo, quarter);
  339. quarter.setPurchaseDeptName(standardVo.getPurchaseDeptId());
  340. list.add(quarter);
  341. }
  342. HashMap<String, HashMap<String, String>> planEnums = dictTypeService.getAboutEnums();
  343. HashMap<String, String> projectTypesMap = planEnums.get("projectTypes");
  344. HashMap<String, String> projectAttributes = planEnums.get("projectAttributes");
  345. int successNum = 0;
  346. int failureNum = 0;
  347. StringBuilder successMsg = new StringBuilder();
  348. StringBuilder failureMsg = new StringBuilder();
  349. //deptService
  350. for (PlanQuarter planQuarter : list) {
  351. try {
  352. //验证项目名称是否重复导入
  353. //将录入信息中的值更改为要保存的数据
  354. if (planQuarterMapper.countProjectName(planQuarter.getProjectName()) == 0) {
  355. //采购单位
  356. SysDept info = deptMapper.checkDeptNameOnlyOne(planQuarter.getPurchaseDeptName());
  357. if (!ObjectUtils.isEmpty(info)) {
  358. planQuarter.setPurchaseDeptId(String.valueOf(info.getDeptId()));
  359. } else {
  360. ++failureNum;
  361. failureMsg.append("*" + failureNum + "*采购单位“" + planQuarter.getPurchaseDeptName() + "”不存在 <br/>");
  362. }
  363. planQuarter.setProjectType(projectTypesMap.get(planQuarter.getProjectType()));
  364. planQuarter.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode());
  365. //项目属性是多选字段
  366. StringBuilder builder = new StringBuilder();
  367. if (planQuarter.getProjectAttr().contains(",")) {
  368. String[] split = planQuarter.getProjectAttr().split(",");
  369. for (String s : split) {
  370. if (!planQuarter.getProjectAttr().endsWith(s)) {
  371. builder.append(projectAttributes.get(s) + ",");
  372. } else {
  373. builder.append(projectAttributes.get(s));
  374. }
  375. }
  376. } else {
  377. builder.append(projectAttributes.get(planQuarter.getProjectAttr()));
  378. }
  379. planQuarter.setProjectAttr(builder.toString());
  380. planQuarter.setCreated(String.valueOf(loginUser.getUserId()));
  381. planQuarter.setCreateTime(new Date());
  382. planQuarterMapper.insertPlanQuarter(planQuarter);
  383. successNum++;
  384. successMsg.append("*" + successNum + "、项目 " + planQuarter.getProjectName() + " 导入成功!<br/>");
  385. } else {
  386. failureNum++;
  387. failureMsg.append(failureNum + "*项目 " + planQuarter.getProjectName() + " 已存在!<br/>");
  388. }
  389. } catch (Exception exc) {
  390. String msg = " *" + successNum + "*项目 " + planQuarter.getProjectName() + " 导入失败 <br/>";
  391. failureMsg.append(msg);
  392. log.error(msg, exc);
  393. }
  394. }
  395. if (failureNum > 0) {
  396. failureMsg.insert(0, "导入失败!共 " + failureNum + " 条数据格式不正确: <br/>");
  397. throw new ServiceException(failureMsg.toString());
  398. } else {
  399. successMsg.insert(0, "导入成功!共 " + successNum + " 条。<br/>");
  400. }
  401. return successMsg.toString();
  402. }
  403. @Override
  404. @Transactional
  405. public AjaxResult commit(PlanQuarterStandardVo quarterStandardVo) {
  406. PlanQuarter byId = planQuarterMapper.getById(quarterStandardVo.getPlanPracticalId());
  407. if (!isBetweenValue(byId)) {
  408. return AjaxResult.error("所创计划不在提报日期内!");
  409. }
  410. //申请修改之后再次提交,先清除上一次提交后的审核记录
  411. PmAuditDeptRef ref = new PmAuditDeptRef();
  412. ref.setRefId(byId.getPlanPracticalId());
  413. ref.setRefType("1");
  414. ref.setProjectType(byId.getProjectType());
  415. ref.setEvaluation(byId.getEvaluation());
  416. refIsExist(ref, pmAuditDeptRefMapper);
  417. insertAuditDeptRef(userService, pmAuditDeptRefService, ref);
  418. int commit = planQuarterMapper.commit(quarterStandardVo.getPlanPracticalId());
  419. if (commit != 1) {
  420. return AjaxResult.error("项目状态数据异常");
  421. }
  422. return AjaxResult.success();
  423. }
  424. //是否已存在--关联审核部门
  425. static void refIsExist(PmAuditDeptRef ref, PmAuditDeptRefMapper pmAuditDeptRefMapper) {
  426. LambdaQueryWrapper<PmAuditDeptRef> lp = new LambdaQueryWrapper<>();
  427. lp.eq(PmAuditDeptRef::getRefId, ref.getRefId());
  428. lp.eq(PmAuditDeptRef::getRefType, ref.getRefType());
  429. List<PmAuditDeptRef> refs = pmAuditDeptRefMapper.selectList(lp);
  430. if (!ObjectUtils.isEmpty(refs)) {
  431. pmAuditDeptRefMapper.delete(lp);
  432. }
  433. }
  434. static void insertAuditDeptRef(ISysUserService userService, PmAuditDeptRefService pmAuditDeptRefService, PmAuditDeptRef ref) {
  435. SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
  436. Long deptId = sysUser.getDeptId();
  437. if (!pmAuditDeptRefService.insertPmAuditDeptRefs(ref.getRefId(),
  438. ref.getRefType(),
  439. deptId,
  440. ref.getEvaluation(),
  441. sysUser.getUserId(),
  442. ref.getProjectType())) {
  443. throw new ServiceException("审核关联数据插入失败");
  444. }
  445. }
  446. @Override
  447. @Transactional
  448. public AjaxResult reviewTo(PlanQuarterStandardVo vo) {
  449. SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
  450. Long deptId = sysUser.getDeptId();
  451. SysDept sysDept = deptMapper.selectDeptById(deptId);
  452. String[] ancestors = sysDept.getAncestors().split(",");
  453. String deptLevel = null;
  454. if (ancestors.length == 2) { //C级
  455. deptLevel = "C";
  456. } else if (ancestors.length == 3) { //B级
  457. deptLevel = "B";
  458. } else if (ancestors.length == 4) { //A级
  459. deptLevel = "A";
  460. }
  461. LambdaQueryWrapper<PmAuditDeptRef> lw = new LambdaQueryWrapper();
  462. lw.eq(PmAuditDeptRef::getRefId, vo.getPlanPracticalId());
  463. lw.eq(PmAuditDeptRef::getRefType, "1");
  464. List<PmAuditDeptRef> list = pmAuditDeptRefService.list(lw);
  465. boolean flay = true;
  466. if (!ObjectUtils.isEmpty(list)) {
  467. for (PmAuditDeptRef pmAuditDeptRef : list) {
  468. // 判断 deptLevel 是否还有更高的 且是 待审核的数据
  469. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) > 0
  470. && pmAuditDeptRef.getStatus().equals(Integer.parseInt("0"))) {
  471. flay = false;
  472. }
  473. // 更新当前 deptLevel 级别的审核状态
  474. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) == 0) {
  475. pmAuditDeptRef.setStatus(1);
  476. pmAuditDeptRefService.updateById(pmAuditDeptRef);
  477. }
  478. }
  479. }
  480. realReviewTo(vo, flay);
  481. return AjaxResult.success();
  482. }
  483. public AjaxResult realReviewTo(PlanQuarterStandardVo vo, boolean flay) {
  484. Date now = new Date();
  485. //季度计划审核通过后同步到年度计划和项目管理
  486. PlanQuarter byId = planQuarterMapper.getById(vo.getPlanPracticalId());
  487. //上传审核文件并赋予计划审核通过
  488. upExamineFile(vo);
  489. if (flay) {
  490. //同步到项目管理
  491. PmDemand demand = new PmDemand();
  492. BeanUtils.copyProperties(byId, demand);
  493. demand.setEvaluation(byId.getEvaluation().doubleValue());
  494. demand.setPlanId(byId.getPlanPracticalId());
  495. demand.setPurchaseDeptId(Long.valueOf(byId.getPurchaseDeptId()));
  496. //同步到项目管理状态为需求待填制
  497. demand.setProjectStatus(PmProjectStatus.DEMAND_WAIT_FILL.getCode());
  498. demand.setCreateTime(now);
  499. demand.setCreateBy(byId.getCreated());
  500. demand.setUpdateTime(now);
  501. demand.setUpdateBy(demand.getCreateBy());
  502. pmDemandMapper.insert(demand);
  503. demandService.updateDemandWarnStatus(demand.getDemandId());
  504. //计划附件也进行同步---查询季度计划附件后同步到项目需求附件和年度计划附件
  505. LambdaQueryWrapper<SysFileRef> sysFileRefLp = new LambdaQueryWrapper<>();
  506. sysFileRefLp.eq(SysFileRef::getRedId, vo.getPlanPracticalId());
  507. sysFileRefLp.in(SysFileRef::getType, Arrays.asList(SysFileRefEnum.PLAN_TEMPORARY.getType(), SysFileRefEnum.PLAN_TEMPORARY_EXAMINE.getType()));
  508. List<SysFileRef> sysFileRefs = sysFileRefMapper.selectList(sysFileRefLp);
  509. if (!ObjectUtils.isEmpty(sysFileRefs)) {
  510. for (SysFileRef ref : sysFileRefs) {
  511. ref.setRedId(demand.getDemandId());
  512. ref.setType(SysFileRefEnum.PM_DEMAND.getType());
  513. ref.setId(null);
  514. ref.setCreated(vo.getUpdated());
  515. ref.setCreateTime(now);
  516. ref.setUpdated(vo.getUpdated());
  517. ref.setUpdateTime(now);
  518. sysFileRefMapper.insert(ref);
  519. }
  520. }
  521. //赋予项目状态已审核
  522. vo.setProjectStatus(ProjectStatus.PLANTOEXAMINE.getCode());
  523. return review(vo);
  524. }
  525. return AjaxResult.success("成功");
  526. }
  527. @Override
  528. @Transactional
  529. public AjaxResult reviewReturn(PlanQuarterStandardVo vo) {
  530. vo.setProjectStatus(ProjectStatus.PLANTOBACK.getCode());
  531. //上传审核文件并赋予计划审核退回
  532. upExamineFile(vo);
  533. return review(vo);
  534. }
  535. /**
  536. * 上传审核文件
  537. *
  538. * @param vo
  539. */
  540. @Override
  541. @Transactional
  542. public void upExamineFile(PlanQuarterStandardVo vo) {
  543. Date now = new Date();
  544. List<SysFileRef> sysFileRefuses = vo.getSysFileRefs();
  545. if (!ObjectUtils.isEmpty(sysFileRefuses)) {
  546. for (SysFileRef ref : sysFileRefuses) {
  547. ref.setRedId(vo.getPlanPracticalId());
  548. ref.setType(SysFileRefEnum.PLAN_TEMPORARY_EXAMINE.getType());
  549. ref.setCreated(vo.getUpdated());
  550. ref.setCreateTime(now);
  551. ref.setUpdated(vo.getUpdated());
  552. ref.setUpdateTime(now);
  553. sysFileRefMapper.insert(ref);
  554. }
  555. }
  556. }
  557. private AjaxResult review(PlanQuarterStandardVo vo) {
  558. int review = planQuarterMapper.review(vo);
  559. if (review != 1) {
  560. return AjaxResult.error("项目状态数据异常");
  561. }
  562. return AjaxResult.success();
  563. }
  564. @Override
  565. public AjaxResult appUpdate(PlanQuarterStandardVo vo) {
  566. //申请后会成为未提交的状态,可以进行修改
  567. PlanQuarter planQuarter = new PlanQuarter();
  568. BeanUtils.copyProperties(vo, planQuarter);
  569. planQuarter.setAppUpdate("true");
  570. planQuarterMapper.updateById(planQuarter);
  571. return AjaxResult.success("申请成功");
  572. }
  573. @Override
  574. @Transactional
  575. public AjaxResult handleAppUpdate(PlanQuarterStandardVo vo) {
  576. //getProjectAttr传值1为同意。-1为拒绝
  577. PlanQuarter planQuarter = new PlanQuarter();
  578. planQuarter.setPlanPracticalId(vo.getPlanPracticalId());
  579. //同意修改申请
  580. if ("1".equals(vo.getProjectAttr())) {
  581. //同意申请之后进行修改,提交后可再次申请
  582. planQuarter.setAppUpdate("");
  583. planQuarter.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode());
  584. planQuarterMapper.updateById(planQuarter);
  585. return AjaxResult.success("已同意该修改申请");
  586. }
  587. //拒绝后可以再次申请
  588. planQuarter.setAppUpdate("");
  589. planQuarterMapper.updateById(planQuarter);
  590. return AjaxResult.success("已拒绝改申请");
  591. }
  592. @Override
  593. public AjaxResult sendLetter(PlanQuarterStandardVo quarterStandardVo) {
  594. PlanQuarter quarter = new PlanQuarter();
  595. BeanUtils.copyProperties(quarterStandardVo, quarter);
  596. quarter.setSendLetter("1");
  597. quarter.setLetterTime(new Date());
  598. int review = planQuarterMapper.updateById(quarter);
  599. if (review != 1) {
  600. return AjaxResult.error("项目状态数据异常");
  601. }
  602. return AjaxResult.success();
  603. }
  604. @Override
  605. public AjaxResult upLoadPlanFile(PlanQuarterStandardVo quarterStandardVo) {
  606. List<SysFileRef> sysFileRefs = quarterStandardVo.getSysFileRefs();
  607. if (!ObjectUtils.isEmpty(sysFileRefs)) {
  608. for (SysFileRef ref : sysFileRefs) {
  609. ref.setRedId(quarterStandardVo.getPlanPracticalId());
  610. ref.setType(SysFileRefEnum.PLAN_TEMPORARY.getType());
  611. sysFileRefMapper.insert(ref);
  612. }
  613. }
  614. return AjaxResult.success();
  615. }
  616. @Override
  617. public List<PlanQuarter> queryPage(PlanQuarterStandardVo vo) {
  618. LoginUser loginUser = SecurityUtils.getLoginUser();
  619. if (!loginUser.getUserId().equals(Long.valueOf("1")) && StringUtils.isEmpty(vo.getPurchaseDeptId())) {
  620. vo.setPurchaseDeptId(String.valueOf(loginUser.getDeptId()));
  621. }
  622. List<PlanQuarter> query = planQuarterMapper.query(vo);
  623. List<PlanQuarter> queryTwo = new LinkedList<>();
  624. if (!ObjectUtils.isEmpty(query)) {
  625. for (PlanQuarter quarter : query) {
  626. LambdaQueryWrapper<PmAuditDeptRef> lw = new LambdaQueryWrapper();
  627. lw.eq(PmAuditDeptRef::getRefId, quarter.getPlanPracticalId());
  628. lw.eq(PmAuditDeptRef::getRefType, "1");
  629. List<PmAuditDeptRef> list = pmAuditDeptRefService.list(lw);
  630. //是否显示审核按钮
  631. boolean fl = true;
  632. //是否为本单位已审核过的数据
  633. boolean fg = false;
  634. if (!ObjectUtils.isEmpty(list) && list.size() > 0) {
  635. List<PmAuditDeptRef> collect = list.stream()
  636. .filter(f -> f.getDeptId().equals(Long.valueOf(vo.getPurchaseDeptId())))
  637. .collect(Collectors.toList());
  638. if (ObjectUtils.isEmpty(collect)) {
  639. fl = false;
  640. } else {
  641. String deptLevel = collect.get(0).getDeptLevel();
  642. fl = collect.get(0).getStatus().equals(Integer.parseInt("1")) ? false : true;
  643. //该计划的审核信息
  644. for (PmAuditDeptRef pmAuditDeptRef : list) {
  645. //自己下级单位未进行审核时。不显示审核按钮
  646. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) == -1
  647. && pmAuditDeptRef.getStatus().equals(Integer.parseInt("0"))) {
  648. fl = false;
  649. }
  650. //本单位已审核
  651. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) == 0
  652. && pmAuditDeptRef.getStatus().equals(Integer.parseInt("1"))) {
  653. fg = true;
  654. }
  655. }
  656. }
  657. /*
  658. * String s1="A";
  659. String s2="B";
  660. System.out.println(s1.compareTo(s2));
  661. * over: -1
  662. * */
  663. }
  664. if (vo.getCreated().equals("1")) {
  665. fl = false;
  666. }
  667. quarter.setFlag(fl);
  668. if (fl == true || quarter.getPurchaseDeptId().equals(vo.getPurchaseDeptId())) {
  669. queryTwo.add(quarter);
  670. } else if (fg == true) {
  671. queryTwo.add(quarter);
  672. }
  673. }
  674. }
  675. return queryTwo;
  676. }
  677. /**
  678. * 导入年度计划数据
  679. *
  680. * @param planYearIds
  681. * @return
  682. */
  683. @Override
  684. @Transactional
  685. public AjaxResult importPlanYearsData(List<Long> planYearIds) {
  686. Date now = new Date();
  687. StringBuilder sb = new StringBuilder("项目【'");
  688. for (Long yearId : planYearIds) {
  689. PlanQuarter byPlanYearId = planQuarterMapper.getByPlanYearId(yearId);
  690. if (!ObjectUtils.isEmpty(byPlanYearId)) {
  691. sb.append(byPlanYearId.getProjectName() + "'、'");
  692. } else {
  693. PlanQuarter quarter = new PlanQuarter();
  694. PlanYears years = planYearsMapper.getById(yearId);
  695. BeanUtils.copyProperties(years, quarter);
  696. quarter.setPlanYearId(yearId);
  697. quarter.setPlanType(0);
  698. quarter.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode());
  699. planQuarterMapper.insert(quarter);
  700. //项目上传附件和审核文件进行同步
  701. LambdaQueryWrapper<SysFileRef> lw = new LambdaQueryWrapper<>();
  702. lw.eq(SysFileRef::getRedId, years.getPlanYearId());
  703. lw.in(SysFileRef::getType, Arrays.asList(SysFileRefEnum.PLAN_YEAR.getType(), SysFileRefEnum.PLAN_YEAR_EXAMINE.getType()));
  704. List<SysFileRef> fileRefs = sysFileRefMapper.selectList(lw);
  705. for (SysFileRef fileRef : fileRefs) {
  706. fileRef.setId(null);
  707. fileRef.setRedId(quarter.getPlanPracticalId());
  708. fileRef.setType(SysFileRefEnum.PLAN_TEMPORARY.getType());
  709. fileRef.setCreateTime(now);
  710. fileRef.setCreated(SecurityUtils.getUserId() + "");
  711. sysFileRefMapper.insert(fileRef);
  712. }
  713. }
  714. }
  715. sb.append("】已存在,请勿选择。");
  716. if (sb.length() > 14) {
  717. return AjaxResult.error(sb.toString());
  718. }
  719. return AjaxResult.success();
  720. }
  721. @Override
  722. public AjaxResult appDelete(PlanQuarterStandardVo quarterStandardVo) {
  723. PlanQuarter planQuarter = new PlanQuarter();
  724. BeanUtils.copyProperties(quarterStandardVo, planQuarter);
  725. planQuarter.setAppDelete("true");
  726. planQuarterMapper.updateById(planQuarter);
  727. return AjaxResult.success("申请成功");
  728. }
  729. @Override
  730. public AjaxResult handleApp(PlanQuarterStandardVo quarterStandardVo) {
  731. //getProjectAttr传值1为同意。-1为拒绝
  732. if ("1".equals(quarterStandardVo.getProjectAttr())) {
  733. planQuarterMapper.deletePlanQuarterById(quarterStandardVo.getPlanPracticalId());
  734. return AjaxResult.success("已成功进行撤销");
  735. }
  736. PlanQuarter planQuarter = new PlanQuarter();
  737. planQuarter.setPlanPracticalId(quarterStandardVo.getPlanPracticalId());
  738. planQuarter.setAppDelete("false");
  739. planQuarterMapper.updateById(planQuarter);
  740. return AjaxResult.success("已拒绝改申请");
  741. }
  742. //字段赋值对应的名称
  743. public List<PlanQuarterResponseVo> changeTo(List<PlanQuarter> planQuarters) {
  744. //获取季度计划各个季度提报时间的阈值
  745. List<SysDictData> supTime = dictTypeService.selectDictDataByType("sys_quarterly_plan");
  746. HashMap<String, String> thresholdMap = new LinkedHashMap<>();
  747. //各个季度提报时间的阈值
  748. for (SysDictData dictData : supTime) {
  749. // 季度----阈值
  750. thresholdMap.put(dictData.getDictLabel(), dictData.getDictValue());
  751. }
  752. //提前或延后*天进行提醒
  753. List<SysDictData> alertTime = dictTypeService.selectDictDataByType("alert_time_setting");
  754. HashMap<String, String> alertTimeMap = new LinkedHashMap<>();
  755. //根据时间类别设定的提醒时间
  756. for (SysDictData dictData : alertTime) {
  757. // 字段名称----阈值
  758. alertTimeMap.put(dictData.getDictLabel(), dictData.getDictValue());
  759. }
  760. //获取字典数据
  761. HashMap<String, HashMap<String, String>> planEnums = dictTypeService.getAboutEnums();
  762. //项目属性
  763. HashMap<String, String> projectAttributes = planEnums.get("projectAttributes");
  764. //项目审核状态
  765. HashMap<String, String> projectStatusMap = planEnums.get("projectStatus");
  766. //项目类型
  767. HashMap<String, String> projectTypesMap = planEnums.get("projectTypes");
  768. //预算科目
  769. HashMap<String, String> budgetAccountMap = planEnums.get("budgetAccount");
  770. //采购服务站
  771. HashMap<String, String> purchaseServicesMap = planEnums.get("purchaseServices");
  772. List<PlanQuarterResponseVo> list = new ArrayList<PlanQuarterResponseVo>();
  773. for (PlanQuarter planQuarter : planQuarters) {
  774. PlanQuarterResponseVo responseVo = new PlanQuarterResponseVo();
  775. SysDeptResponseVo sysDeptResponseVo = (SysDeptResponseVo) deptService.selectDeptById(Long.valueOf(planQuarter.getPurchaseDeptId())).get("sysDept");
  776. planQuarter.setPurchaseDeptName(sysDeptResponseVo.getDeptName());
  777. //预算科目
  778. for (Map.Entry<String, String> entry : budgetAccountMap.entrySet()) {
  779. if (!ObjectUtils.isEmpty(planQuarter.getBudgetAccount()) && planQuarter.getBudgetAccount().equals(entry.getValue())) {
  780. planQuarter.setBudgetAccountStr(entry.getKey());
  781. break;
  782. }
  783. }
  784. //采购服务站
  785. for (Map.Entry<String, String> entry : purchaseServicesMap.entrySet()) {
  786. if (!ObjectUtils.isEmpty(planQuarter.getPurchaseServices()) && planQuarter.getPurchaseServices().equals(entry.getValue())) {
  787. planQuarter.setPurchaseServicesStr(entry.getKey());
  788. break;
  789. }
  790. }
  791. //项目审核状态
  792. for (Map.Entry<String, String> entry : projectStatusMap.entrySet()) {
  793. if (!ObjectUtils.isEmpty(planQuarter.getProjectStatus()) && planQuarter.getProjectStatus().equals(entry.getValue())) {
  794. planQuarter.setProjectStatusStr(entry.getKey());
  795. break;
  796. }
  797. }
  798. //项目类型
  799. for (Map.Entry<String, String> entry : projectTypesMap.entrySet()) {
  800. if (!ObjectUtils.isEmpty(planQuarter.getProjectType()) && planQuarter.getProjectType().equals(entry.getValue())) {
  801. planQuarter.setProjectTypeStr(entry.getKey());
  802. break;
  803. }
  804. }
  805. //项目属性为value拼接
  806. if (!ObjectUtils.isEmpty(planQuarter.getProjectAttr())) {
  807. if (planQuarter.getProjectAttr().length() > 1) {
  808. StringBuilder builder = new StringBuilder();
  809. String[] split = planQuarter.getProjectAttr().split(",");
  810. for (String s : split) {
  811. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  812. if (s.equals(entry.getValue())) {
  813. if (!planQuarter.getProjectAttr().endsWith(s)) {
  814. builder.append(entry.getKey() + ",");
  815. } else {
  816. builder.append(entry.getKey());
  817. }
  818. break;
  819. }
  820. }
  821. }
  822. planQuarter.setProjectAttrName(builder.toString());
  823. } else {
  824. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  825. if (planQuarter.getProjectAttr().equals(entry.getValue())) {
  826. planQuarter.setProjectAttrName(entry.getKey());
  827. break;
  828. }
  829. }
  830. }
  831. }
  832. //机关业务指导处(科)为id拼接
  833. String organDivision = planQuarter.getOrganDivision();
  834. if (!ObjectUtils.isEmpty(organDivision)) {
  835. int length = organDivision.split(",").length;
  836. SysDeptOrgan organ = new SysDeptOrgan();
  837. if (length > 1) {
  838. StringBuilder builder = new StringBuilder();
  839. String[] split = organDivision.split(",");
  840. for (String s : split) {
  841. organ = sysDeptOrganMapper.selectById(s);
  842. if (!ObjectUtils.isEmpty(organ)) {
  843. if (!organDivision.endsWith(s)) {
  844. builder.append(organ.getOrganName() + ",");
  845. } else {
  846. builder.append(organ.getOrganName());
  847. }
  848. }
  849. }
  850. planQuarter.setOrganDivisionStr(builder.toString());
  851. } else if (length == 1) {
  852. organ = sysDeptOrganMapper.selectById(organDivision);
  853. if (!ObjectUtils.isEmpty(organ)) {
  854. planQuarter.setOrganDivisionStr(organ.getOrganName());
  855. }
  856. }
  857. }
  858. //是否可以申请撤销和申请修改
  859. //需求待填制可以申请,需求建档就不能申请
  860. PmDemand demand = demandService.selectByPlanId(planQuarter.getPlanPracticalId());
  861. if (!ObjectUtils.isEmpty(demand) && !demand.getProjectStatus().equals(PmProjectStatus.DEMAND_WAIT_FILL.getCode())) {
  862. planQuarter.setAppDeleteDo("false");
  863. planQuarter.setAppUpdateDo("false");
  864. } else {
  865. //能否申请撤销
  866. if (!ObjectUtils.isEmpty(planQuarter.getAppDelete()) && planQuarter.getAppDelete().equals("true")) {
  867. //申请过的不能再申请
  868. planQuarter.setAppDeleteDo("false");
  869. } else if (planQuarter.getProjectStatus().equals("0")) {
  870. planQuarter.setAppDeleteDo("false");
  871. } else {
  872. //提交后可以申请撤销
  873. planQuarter.setAppDeleteDo("true");
  874. }
  875. //能否申请修改
  876. if (!ObjectUtils.isEmpty(planQuarter.getAppUpdate()) && planQuarter.getAppUpdate().equals("true")) {
  877. //申请过的不能再申请
  878. planQuarter.setAppUpdateDo("false");
  879. } else if (planQuarter.getProjectStatus().equals("0")) {
  880. planQuarter.setAppUpdateDo("false");
  881. } else {
  882. //提交后可以申请撤销
  883. planQuarter.setAppUpdateDo("true");
  884. }
  885. }
  886. BeanUtils.copyProperties(planQuarter, responseVo);
  887. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
  888. responseVo.setPlanDemandSubTimeStr(sdf.format(responseVo.getPlanDemandSubTime()));
  889. responseVo.setPlanPurchaseFinishTimeStr(sdf.format(responseVo.getPlanPurchaseFinishTime()));
  890. responseVo.setPlanDeliverTimeStr(sdf.format(responseVo.getPlanDeliverTime()));
  891. //状态在采购需求对接和流废标退回之间的项目可以进行催告---已发函不可再次发函
  892. responseVo.setSendLetterDo("false");
  893. if (!ObjectUtils.isEmpty(demand)) {
  894. if (sendLetterDo(demand.getProjectStatus()) && planQuarter.getSendLetter().equals("0")) {
  895. responseVo.setSendLetterDo("true");
  896. }
  897. }
  898. try {
  899. responseVo.setTipsMessage(planQuarterGetTips(thresholdMap, alertTimeMap));
  900. } catch (ParseException e) {
  901. e.printStackTrace();
  902. }
  903. list.add(responseVo);
  904. }
  905. return list;
  906. }
  907. //是否可以执行发函
  908. @Override
  909. public boolean sendLetterDo(String projectStatus) {
  910. List<String> ls = new ArrayList<>();
  911. ls.add(PmProjectStatus.PURCHASE_DEMAND_DOCKING.getCode());
  912. ls.add(PmProjectStatus.EXPERT_FEEDBACK.getCode());
  913. ls.add(PmProjectStatus.PROCUREMENT_DOCUMENTS_REVIEW.getCode());
  914. ls.add(PmProjectStatus.PROCUREMENT_ANNOUNCEMENT.getCode());
  915. ls.add(PmProjectStatus.PRE_BID_QUERY.getCode());
  916. ls.add(PmProjectStatus.WAIT_OPEN_BID.getCode());
  917. ls.add(PmProjectStatus.BID_RESULT_ANNOUNCEMENT.getCode());
  918. ls.add(PmProjectStatus.WASTE_BID_HANDLE.getCode());
  919. ls.add(PmProjectStatus.POST_BID_QUERY.getCode());
  920. ls.add(PmProjectStatus.WASTE_BID_RETURN.getCode());
  921. return ls.contains(projectStatus);
  922. }
  923. @Override
  924. public List<Integer> idNotDemand() {
  925. return planQuarterMapper.idNotDemand();
  926. }
  927. /**
  928. * 根据季度计划在各个季度提报时间的阈值进行提示
  929. *
  930. * @return
  931. */
  932. public String planQuarterGetTips(HashMap<String, String> thresholdMap, HashMap<String, String> alertTimeMap) throws ParseException {
  933. //提示信息:定义距离结束时间*天内提示
  934. int alertDay = Integer.parseInt(alertTimeMap.get("计划提报时间"));
  935. Integer remindTine = 1000 * 60 * 60 * 24 * alertDay;
  936. String subTips = "";
  937. //季度提报时间的结束时间阈值
  938. Date thresholdTime = null;
  939. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  940. Date date = new Date();
  941. for (QuarterEnum val : QuarterEnum.values()) {
  942. if (val.getInfo().contains(date.getMonth() + "")) {
  943. switch (val.getCode()) {
  944. case "1":
  945. thresholdTime = dateFormat.parse(thresholdMap.get("第一季度结束时间"));
  946. case "2":
  947. thresholdTime = dateFormat.parse(thresholdMap.get("第二季度结束时间"));
  948. case "3":
  949. thresholdTime = dateFormat.parse(thresholdMap.get("第三季度结束时间"));
  950. case "4":
  951. thresholdTime = dateFormat.parse(thresholdMap.get("第四季度结束时间"));
  952. default:
  953. }
  954. break;
  955. }
  956. }
  957. double surplus = thresholdTime.getTime() - date.getTime();
  958. //少于设定时间便提醒
  959. if (surplus < remindTine && surplus > 0) {
  960. //剩余天数(向上取整)
  961. int i = (int) Math.ceil(surplus / 1000 / 60 / 60 / 24);
  962. if (i > 0) {
  963. subTips = "距离计划提报时间不足" + i + "天";
  964. }
  965. }
  966. return subTips;
  967. }
  968. //是否在提报时间内
  969. public Boolean isBetweenValue(PlanQuarter planQuarter) {
  970. //获取年度计划提报时间的阈值
  971. //获取季度计划各个季度提报时间的阈值
  972. List<SysDictData> supTime = dictTypeService.selectDictDataByType("sys_quarterly_plan");
  973. HashMap<String, String> thresholdMap = new LinkedHashMap<>();
  974. //各个季度提报时间的阈值
  975. for (SysDictData dictData : supTime) {
  976. // 季度----阈值
  977. thresholdMap.put(dictData.getDictLabel(), dictData.getDictValue());
  978. }
  979. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  980. Date thresholdTimeStart = null;
  981. Date thresholdTimeEnd = null;
  982. Calendar instance = Calendar.getInstance();
  983. instance.setTime(planQuarter.getPlanDemandSubTime());
  984. try {
  985. for (QuarterEnum val : QuarterEnum.values()) {
  986. if (val.getInfo().contains((instance.get(Calendar.MONTH) + 1) + "")) {
  987. //System.err.println("MONTH" + (instance.get(Calendar.MONTH) + 1));
  988. switch (val.getCode()) {
  989. case "1":
  990. thresholdTimeStart = dateFormat.parse(thresholdMap.get("第一季度开始时间"));
  991. thresholdTimeEnd = dateFormat.parse(thresholdMap.get("第一季度结束时间"));
  992. break;
  993. case "2":
  994. thresholdTimeStart = dateFormat.parse(thresholdMap.get("第二季度开始时间"));
  995. thresholdTimeEnd = dateFormat.parse(thresholdMap.get("第二季度结束时间"));
  996. break;
  997. case "3":
  998. thresholdTimeStart = dateFormat.parse(thresholdMap.get("第三季度开始时间"));
  999. thresholdTimeEnd = dateFormat.parse(thresholdMap.get("第三季度结束时间"));
  1000. break;
  1001. default:
  1002. thresholdTimeStart = dateFormat.parse(thresholdMap.get("第四季度开始时间"));
  1003. thresholdTimeEnd = dateFormat.parse(thresholdMap.get("第四季度结束时间"));
  1004. }
  1005. break;
  1006. }
  1007. }
  1008. if (!ObjectUtils.isEmpty(thresholdTimeStart) && !ObjectUtils.isEmpty(thresholdTimeEnd)) {
  1009. System.err.println("instance=" + new Date(instance.getTime().getTime()));
  1010. System.err.println("thresholdTimeStart=" + thresholdTimeStart);
  1011. System.err.println("thresholdTimeEnd=" + thresholdTimeEnd);
  1012. System.err.println("instance.before(thresholdTimeStart)=" + instance.before(thresholdTimeStart));
  1013. System.err.println("instance.after(thresholdTimeEnd)=" + instance.after(thresholdTimeEnd));
  1014. Date date = new Date(instance.getTime().getTime());
  1015. if (date.before(thresholdTimeStart) || date.after(thresholdTimeEnd)) {
  1016. return false;
  1017. }
  1018. }
  1019. } catch (ParseException e) {
  1020. e.printStackTrace();
  1021. }
  1022. return true;
  1023. }
  1024. }