PlanYearsServiceImpl.java 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508
  1. package com.ozs.plan.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  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.SysDictData;
  9. import com.ozs.common.core.domain.entity.SysRole;
  10. import com.ozs.common.core.domain.entity.SysUser;
  11. import com.ozs.common.core.domain.model.LoginUser;
  12. import com.ozs.common.enums.*;
  13. import com.ozs.common.exception.ServiceException;
  14. import com.ozs.common.utils.DateUtils;
  15. import com.ozs.common.utils.SecurityUtils;
  16. import com.ozs.common.utils.StringUtils;
  17. import com.ozs.common.utils.bean.BeanUtils;
  18. import com.ozs.home.domain.vo.HomeToDoQueryResVo;
  19. import com.ozs.plan.doman.PlanQuarter;
  20. import com.ozs.plan.doman.PlanYears;
  21. import com.ozs.plan.doman.ProvisionalPlan;
  22. import com.ozs.plan.doman.vo.requestVo.PlanYearsStandardVo;
  23. import com.ozs.plan.doman.vo.responseVo.PlanQuarterResponseVo;
  24. import com.ozs.plan.doman.vo.responseVo.PlanYearsResponseVo;
  25. import com.ozs.plan.mapper.PlanQuarterMapper;
  26. import com.ozs.plan.mapper.PlanYearsMapper;
  27. import com.ozs.plan.mapper.ProvisionalPlanMapper;
  28. import com.ozs.plan.service.PlanYearsService;
  29. import com.ozs.pm.doman.*;
  30. import com.ozs.pm.doman.vo.requestVo.PmDemandReqVo;
  31. import com.ozs.pm.doman.vo.responseVo.*;
  32. import com.ozs.pm.mapper.PmAuditDeptRefMapper;
  33. import com.ozs.pm.mapper.PmDemandMapper;
  34. import com.ozs.pm.service.*;
  35. import com.ozs.system.domain.SysFileInfo;
  36. import com.ozs.system.domain.SysFileRef;
  37. import com.ozs.system.domain.vo.responseVo.SysDeptResponseVo;
  38. import com.ozs.system.mapper.SysDeptMapper;
  39. import com.ozs.system.mapper.SysFileRefMapper;
  40. import com.ozs.system.mapper.SysRoleMapper;
  41. import com.ozs.system.service.*;
  42. import lombok.extern.slf4j.Slf4j;
  43. import org.springframework.beans.factory.annotation.Autowired;
  44. import org.springframework.stereotype.Service;
  45. import org.springframework.transaction.annotation.Transactional;
  46. import org.springframework.util.ObjectUtils;
  47. import javax.validation.Validator;
  48. import java.math.BigDecimal;
  49. import java.text.ParseException;
  50. import java.text.SimpleDateFormat;
  51. import java.util.ArrayList;
  52. import java.util.Arrays;
  53. import java.util.Calendar;
  54. import java.util.Date;
  55. import java.util.HashMap;
  56. import java.util.LinkedHashMap;
  57. import java.util.List;
  58. import java.util.Map;
  59. import java.util.stream.Collectors;
  60. /**
  61. * @author buzhanyi
  62. */
  63. @Service
  64. @Slf4j
  65. public class PlanYearsServiceImpl extends ServiceImpl<PlanYearsMapper, PlanYears> implements PlanYearsService {
  66. @Autowired
  67. PlanYearsMapper planYearsMapper;
  68. @Autowired
  69. private PlanQuarterMapper planQuarterMapper;
  70. @Autowired
  71. protected Validator validator;
  72. @Autowired
  73. private ISysDictTypeService dictTypeService;
  74. @Autowired
  75. private ISysDeptService deptService;
  76. @Autowired
  77. private SysFileRefMapper sysFileRefMapper;
  78. @Autowired
  79. private SysDeptMapper deptMapper;
  80. @Autowired
  81. private SysFileService fileService;
  82. @Autowired
  83. private SysRoleMapper sysRoleMapper;
  84. @Autowired
  85. private ISysUserService userService;
  86. @Autowired
  87. private PmDemandMapper pmDemandMapper;
  88. @Autowired
  89. private PlanQuarterServiceImpl quartzServiceImpl;
  90. @Autowired
  91. private IPmDemandService demandService;
  92. @Autowired
  93. private ProvisionalPlanMapper provisionalPlanMapper;
  94. @Autowired
  95. private SysFileRefService sysFileRefService;
  96. @Autowired
  97. private PmAuditDeptRefService pmAuditDeptRefService;
  98. @Autowired
  99. private PmAuditDeptRefMapper pmAuditDeptRefMapper;
  100. @Override
  101. public List<PlanYearsResponseVo> selectPlanYearsListEXP(PlanYearsStandardVo vo, LoginUser loginUser) {
  102. List<PlanYears> list = new ArrayList<>();
  103. List<PlanYearsResponseVo> planYearsList = new ArrayList<>();
  104. try {
  105. int num = 1;
  106. int size = 200;
  107. while (size == 200) {
  108. LambdaQueryWrapper<PlanYears> lw = new LambdaQueryWrapper<PlanYears>();
  109. if (!loginUser.getUserId().equals(Long.valueOf("1"))) {
  110. lw.eq(PlanYears::getPurchaseDeptId, loginUser.getDeptId());
  111. }
  112. if (!ObjectUtils.isEmpty(vo.getProjectName())) {
  113. lw.like(PlanYears::getProjectName, vo.getProjectName());
  114. }
  115. if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) {
  116. lw.eq(PlanYears::getPurchaseServices, vo.getPurchaseServices());
  117. }
  118. if (!ObjectUtils.isEmpty(vo.getProjectStatus())) {
  119. lw.eq(PlanYears::getProjectStatus, vo.getProjectStatus());
  120. }
  121. if (!ObjectUtils.isEmpty(vo.getParams())) {
  122. if (!ObjectUtils.isEmpty(vo.getParams().get("beginTime"))) {
  123. lw.ge(PlanYears::getPlanDemandSubTime, vo.getParams().get("beginTime").toString() + "-01");
  124. }
  125. if (!ObjectUtils.isEmpty(vo.getParams().get("endTime"))) {
  126. SimpleDateFormat dateFormaH = new SimpleDateFormat("yyyy-MM");
  127. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  128. Date ofMonth = DateUtils.getLastDayOfMonth(dateFormaH.parse(vo.getParams().get("endTime").toString()));
  129. lw.le(PlanYears::getPlanDemandSubTime, dateFormat.format(ofMonth) + " 23:59:59:999");
  130. }
  131. }
  132. lw.eq(PlanYears::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  133. Page<PlanYears> page = planYearsMapper.selectPage(new Page<PlanYears>(num, size, false), lw);
  134. list.addAll(page.getRecords());
  135. size = page.getRecords().size();
  136. num++;
  137. }
  138. planYearsList = changeTo(list);
  139. } catch (Exception e) {
  140. e.printStackTrace();
  141. }
  142. return planYearsList;
  143. }
  144. @Override
  145. public List<PlanYearsResponseVo> selectPlanYearsExamineListEXP(PlanYearsStandardVo vo, LoginUser loginUser) {
  146. List<PlanYears> list = new ArrayList<>();
  147. List<PlanYearsResponseVo> planYearsList = new ArrayList<>();
  148. try {
  149. int num = 1;
  150. int size = 200;
  151. while (size == 200) {
  152. LambdaQueryWrapper<PlanYears> lw = new LambdaQueryWrapper<PlanYears>();
  153. if (!loginUser.getUserId().equals(Long.valueOf("1"))) {
  154. lw.eq(PlanYears::getPurchaseDeptId, loginUser.getDeptId());
  155. }
  156. if (!ObjectUtils.isEmpty(vo.getProjectName())) {
  157. lw.like(PlanYears::getProjectName, vo.getProjectName());
  158. }
  159. if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) {
  160. lw.eq(PlanYears::getPurchaseServices, vo.getPurchaseServices());
  161. }
  162. if (!ObjectUtils.isEmpty(vo.getProjectStatus())) {
  163. lw.eq(PlanYears::getProjectStatus, vo.getProjectStatus());
  164. } else {
  165. lw.in(PlanYears::getProjectStatus, "1,3");
  166. }
  167. if (!ObjectUtils.isEmpty(vo.getParams())) {
  168. if (!ObjectUtils.isEmpty(vo.getParams().get("beginTime"))) {
  169. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
  170. Date ofMonth = dateFormat.parse(vo.getParams().get("beginTime").toString() + "-01");
  171. lw.ge(PlanYears::getPlanDemandSubTime, ofMonth);
  172. }
  173. if (!ObjectUtils.isEmpty(vo.getParams().get("endTime"))) {
  174. SimpleDateFormat dateFormaH = new SimpleDateFormat("yyyy-MM");
  175. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  176. SimpleDateFormat dateFormatT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
  177. Date ofMonth = DateUtils.getLastDayOfMonth(dateFormaH.parse(vo.getParams().get("endTime").toString()));
  178. Date parse = dateFormatT.parse(dateFormat.format(ofMonth) + " 23:59:59:999");
  179. lw.le(PlanYears::getPlanDemandSubTime, parse);
  180. }
  181. }
  182. lw.eq(PlanYears::getDelFlay, DataIsDelete.DataNOTDelete);
  183. Page<PlanYears> page = planYearsMapper.selectPage(new Page<PlanYears>(num, size, false), lw);
  184. list.addAll(page.getRecords());
  185. size = page.getRecords().size();
  186. num++;
  187. }
  188. planYearsList = changeTo(list);
  189. } catch (Exception e) {
  190. e.printStackTrace();
  191. }
  192. return planYearsList;
  193. }
  194. @Transactional
  195. @Override
  196. public AjaxResult insertPlanYears(PlanYearsStandardVo yearsStandardVo) {
  197. if (planYearsMapper.countProjectName(yearsStandardVo.getProjectName()) > 0) {
  198. return AjaxResult.error("该项目名称已经存在");
  199. }
  200. PlanYears ofYears = new PlanYears();
  201. try {
  202. BeanUtils.copyProperties(yearsStandardVo, ofYears);
  203. } catch (Exception e) {
  204. e.printStackTrace();
  205. }
  206. //判断是否为超额计划
  207. ofYears.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode());
  208. ofYears.setCreateTime(new Date());
  209. planYearsMapper.insertPlanYears(ofYears);
  210. log.info("id:{}", ofYears.getPlanYearId());
  211. List<SysFileRef> sysFileRefs = yearsStandardVo.getSysFileRefs();
  212. if (!ObjectUtils.isEmpty(sysFileRefs)) {
  213. for (SysFileRef ref : sysFileRefs) {
  214. ref.setRedId(ofYears.getPlanYearId());
  215. ref.setType(SysFileRefEnum.PLAN_YEAR.getType());
  216. ref.setCreated(ofYears.getCreated());
  217. ref.setCreateTime(new Date());
  218. ref.setUpdated(ofYears.getCreated());
  219. ref.setUpdateTime(new Date());
  220. sysFileRefMapper.insert(ref);
  221. }
  222. }
  223. return AjaxResult.success();
  224. }
  225. @Override
  226. public AjaxResult deletePlanYearsByIds(Long[] planIds) {
  227. planYearsMapper.deletePlanYearsByIds(planIds);
  228. return AjaxResult.success();
  229. }
  230. @Override
  231. public AjaxResult deletePlanYearsById(Long planId) {
  232. planYearsMapper.deletePlanYearsById(planId);
  233. return AjaxResult.success();
  234. }
  235. @Override
  236. public AjaxResult view(PlanYearsStandardVo yearsStandardVo) {
  237. PlanYearsResponseVo responseVo = new PlanYearsResponseVo();
  238. PlanYears byId = planYearsMapper.getById(yearsStandardVo.getPlanYearId());
  239. byId.getPlanYearId();
  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, yearsStandardVo.getPlanYearId());
  247. lw.in(SysFileRef::getType, Arrays.asList(SysFileRefEnum.PLAN_YEAR.getType(), SysFileRefEnum.PLAN_YEAR_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. return AjaxResult.success(responseVo);
  259. }
  260. @Transactional
  261. @Override
  262. public AjaxResult update(PlanYearsStandardVo yearsStandardVo) {
  263. if (planYearsMapper.countProjectNameOther(yearsStandardVo.getProjectName(), String.valueOf(yearsStandardVo.getPlanYearId())) > 0) {
  264. return AjaxResult.error("该项目名称已经存在");
  265. }
  266. PlanYears ofYears = new PlanYears();
  267. try {
  268. BeanUtils.copyProperties(yearsStandardVo, ofYears);
  269. } catch (Exception e) {
  270. e.printStackTrace();
  271. }
  272. ofYears.setUpdateTime(new Date());
  273. planYearsMapper.updateById(ofYears);
  274. List<SysFileRef> sysFileRefs = yearsStandardVo.getSysFileRefs();
  275. if (!ObjectUtils.isEmpty(sysFileRefs)) {
  276. // 删关联
  277. LambdaQueryWrapper<SysFileRef> lw = new LambdaQueryWrapper<>();
  278. lw.eq(SysFileRef::getRedId, ofYears.getPlanYearId());
  279. lw.eq(SysFileRef::getType, SysFileRefEnum.PLAN_YEAR.getType());
  280. sysFileRefMapper.delete(lw);
  281. for (SysFileRef ref : sysFileRefs) {
  282. ref.setRedId(ofYears.getPlanYearId());
  283. ref.setType(SysFileRefEnum.PLAN_YEAR.getType());
  284. ref.setCreated(yearsStandardVo.getUpdated());
  285. ref.setCreateTime(new Date());
  286. ref.setUpdated(yearsStandardVo.getUpdated());
  287. ref.setUpdateTime(new Date());
  288. sysFileRefMapper.insert(ref);
  289. }
  290. }
  291. return AjaxResult.success();
  292. }
  293. //是否在提报时间内
  294. public Boolean isBetweenValue(PlanYears planYear) {
  295. //获取年度计划提报时间的阈值
  296. List<SysDictData> supTime = dictTypeService.selectDictDataByType("sys_annual_plan");
  297. HashMap<String, String> thresholdMap = new LinkedHashMap<>();
  298. //年度提报时间的阈值
  299. for (SysDictData dictData : supTime) {
  300. // 字段名称----阈值
  301. thresholdMap.put(dictData.getDictLabel(), dictData.getDictValue());
  302. }
  303. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  304. Date subTime = planYear.getPlanDemandSubTime();
  305. try {
  306. Date thresholdTimeStart = dateFormat.parse(thresholdMap.get("起止时间开始"));
  307. Date thresholdTimeEnd = dateFormat.parse(thresholdMap.get("起止时间结束"));
  308. ;
  309. if (!ObjectUtils.isEmpty(thresholdTimeStart) && !ObjectUtils.isEmpty(thresholdTimeEnd)) {
  310. if (subTime.before(thresholdTimeStart) || subTime.after(thresholdTimeEnd)) {
  311. return false;
  312. }
  313. }
  314. } catch (ParseException e) {
  315. e.printStackTrace();
  316. }
  317. return true;
  318. }
  319. @Transactional
  320. @Override
  321. public String importPlanYears(List<PlanYearsStandardVo> planYears, boolean isUpdateSupport, LoginUser loginUser) {
  322. //获取字典数据
  323. HashMap<String, HashMap<String, String>> planEnums = dictTypeService.getAboutEnums();
  324. //项目属性
  325. HashMap<String, String> projectAttributes = planEnums.get("projectAttributes");
  326. //项目类型
  327. HashMap<String, String> projectTypesMap = planEnums.get("projectTypesAds");
  328. //预算科目
  329. HashMap<String, String> budgetAccountMap = planEnums.get("budgetAccount");
  330. //采购服务站
  331. HashMap<String, String> purchaseServicesMap = planEnums.get("purchaseServices");
  332. if (StringUtils.isNull(planYears) || planYears.size() == 0) {
  333. throw new ServiceException("导入年度计划数据不能为空!");
  334. }
  335. List<PlanYears> plans = new ArrayList<>();
  336. for (PlanYearsStandardVo yearsStandardVo : planYears) {
  337. PlanYears ofYears = new PlanYears();
  338. BeanUtils.copyProperties(yearsStandardVo, ofYears);
  339. ofYears.setPurchaseDeptName(yearsStandardVo.getPurchaseDeptId());
  340. plans.add(ofYears);
  341. }
  342. int successNum = 0;
  343. int failureNum = 0;
  344. StringBuilder successMsg = new StringBuilder();
  345. StringBuilder failureMsg = new StringBuilder();
  346. //deptService
  347. for (PlanYears ofYear : plans) {
  348. try {
  349. //验证项目名称是否重复导入
  350. //将录入信息中的值更改为要保存的数据
  351. if (planYearsMapper.countProjectName(ofYear.getProjectName()) == 0) {
  352. //采购单位
  353. SysDept info = deptMapper.checkDeptNameOnlyOne(ofYear.getPurchaseDeptName());
  354. if (!ObjectUtils.isEmpty(info)) {
  355. ofYear.setPurchaseDeptId(String.valueOf(info.getDeptId()));
  356. } else {
  357. ++failureNum;
  358. failureMsg.append(failureNum + "、采购单位“" + ofYear.getPurchaseDeptName() + "”不存在");
  359. }
  360. //采购单位
  361. SysDept infoTow = deptMapper.checkDeptNameOnlyOne(ofYear.getOrganDivision());
  362. if (!ObjectUtils.isEmpty(infoTow)) {
  363. ofYear.setOrganDivision(String.valueOf(info.getDeptId()));
  364. } else {
  365. ++failureNum;
  366. failureMsg.append(failureNum + "、机关业务指导处(科)“" + ofYear.getOrganDivision() + "”不存在");
  367. }
  368. ofYear.setProjectType(projectTypesMap.get(ofYear.getProjectType()));
  369. ofYear.setPurchaseServices(purchaseServicesMap.get(ofYear.getPurchaseServices()));
  370. ofYear.setBudgetAccount(budgetAccountMap.get(ofYear.getBudgetAccount()));
  371. ofYear.setProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode());
  372. //项目属性是多选字段
  373. StringBuilder builder = new StringBuilder();
  374. if (ofYear.getProjectAttr().contains(",")) {
  375. String[] split = ofYear.getProjectAttr().split(",");
  376. for (String s : split) {
  377. if (!ofYear.getProjectAttr().endsWith(s)) {
  378. builder.append(projectAttributes.get(s) + ",");
  379. } else {
  380. builder.append(projectAttributes.get(s));
  381. }
  382. }
  383. } else {
  384. builder.append(projectAttributes.get(ofYear.getProjectAttr()));
  385. }
  386. ofYear.setProjectAttr(builder.toString());
  387. ofYear.setCreated(String.valueOf(loginUser.getUserId()));
  388. ofYear.setCreateTime(new Date());
  389. planYearsMapper.insertPlanYears(ofYear);
  390. successNum++;
  391. successMsg.append(successNum + "、项目【" + ofYear.getProjectName() + "】导入成功!");
  392. } else {
  393. failureNum++;
  394. failureMsg.append(failureNum + "、项目【" + ofYear.getProjectName() + "】已存在!");
  395. }
  396. } catch (Exception exc) {
  397. failureNum++;
  398. String msg = successNum + "、项目【" + ofYear.getProjectName() + "】导入失败";
  399. failureMsg.append(msg + exc.getMessage());
  400. log.error(msg, exc);
  401. }
  402. }
  403. if (failureNum > 0) {
  404. failureMsg.insert(0, "导入失败!共 " + failureNum + " 条数据格式不正确:");
  405. throw new ServiceException(failureMsg.toString());
  406. } else {
  407. successMsg.insert(0, "导入成功!共 " + successNum + " 条。");
  408. }
  409. return successMsg.toString();
  410. }
  411. @Override
  412. @Transactional
  413. public AjaxResult commit(PlanYearsStandardVo yearsStandardVo) {
  414. PlanYears byId = planYearsMapper.getById(yearsStandardVo.getPlanYearId());
  415. if (!isBetweenValue(byId)) {
  416. return AjaxResult.error("所创计划不在提报日期内!");
  417. }
  418. //申请修改之后再次提交,先清除上一次提交后的审核记录
  419. PmAuditDeptRef ref = new PmAuditDeptRef();
  420. ref.setRefId(byId.getPlanYearId()).setRefType("0").setProjectType(byId.getProjectType()).setEvaluation(byId.getEvaluation());
  421. PlanQuarterServiceImpl.refIsExist(ref, pmAuditDeptRefMapper);
  422. PlanQuarterServiceImpl.insertAuditDeptRef(userService, pmAuditDeptRefService, ref);
  423. int commit = planYearsMapper.commit(yearsStandardVo.getPlanYearId());
  424. if (commit != 1) {
  425. return AjaxResult.error("项目状态数据异常");
  426. }
  427. return AjaxResult.success();
  428. }
  429. @Override
  430. @Transactional
  431. public AjaxResult reviewTo(PlanYearsStandardVo vo) {
  432. SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
  433. Long deptId = sysUser.getDeptId();
  434. SysDept sysDept = deptMapper.selectDeptById(deptId);
  435. String[] ancestors = sysDept.getAncestors().split(",");
  436. String deptLevel = null;
  437. if (ancestors.length == 2) { //C级
  438. deptLevel = "C";
  439. } else if (ancestors.length == 3) { //B级
  440. deptLevel = "B";
  441. } else if (ancestors.length == 4) { //A级
  442. deptLevel = "A";
  443. }
  444. LambdaQueryWrapper<PmAuditDeptRef> lw = new LambdaQueryWrapper();
  445. lw.eq(PmAuditDeptRef::getRefId, vo.getPlanYearId());
  446. lw.eq(PmAuditDeptRef::getRefType, "0");
  447. List<PmAuditDeptRef> list = pmAuditDeptRefService.list(lw);
  448. boolean flay = true;
  449. if (!ObjectUtils.isEmpty(list)) {
  450. for (PmAuditDeptRef pmAuditDeptRef : list) {
  451. // 判断 deptLevel 是否还有更高的 且是 待审核的数据
  452. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) > 0
  453. && pmAuditDeptRef.getStatus().equals(Integer.parseInt("0"))) {
  454. flay = false;
  455. }
  456. // 更新当前 deptLevel 级别的审核状态
  457. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) == 0) {
  458. pmAuditDeptRef.setStatus(1);
  459. pmAuditDeptRefService.updateById(pmAuditDeptRef);
  460. }
  461. }
  462. }
  463. realReviewTo(vo, flay);
  464. return AjaxResult.success();
  465. }
  466. @Transactional
  467. public AjaxResult realReviewTo(PlanYearsStandardVo vo, boolean flay) {
  468. if (flay) {
  469. //赋予项目状态已审核
  470. vo.setProjectStatus(ProjectStatus.PLANTOEXAMINE.getCode());
  471. return review(vo);
  472. }
  473. return AjaxResult.success("成功");
  474. }
  475. @Override
  476. @Transactional
  477. public AjaxResult reviewReturn(PlanYearsStandardVo vo) {
  478. vo.setProjectStatus(ProjectStatus.PLANTOBACK.getCode());
  479. return review(vo);
  480. }
  481. private AjaxResult review(PlanYearsStandardVo vo) {
  482. Date now = new Date();
  483. //上传审核文件
  484. List<SysFileRef> sysFileRefuses = vo.getSysFileRefs();
  485. if (!ObjectUtils.isEmpty(sysFileRefuses)) {
  486. for (SysFileRef ref : sysFileRefuses) {
  487. ref.setRedId(vo.getPlanYearId());
  488. ref.setType(SysFileRefEnum.PLAN_YEAR_EXAMINE.getType());
  489. ref.setCreated(vo.getUpdated());
  490. ref.setCreateTime(now);
  491. ref.setUpdated(vo.getUpdated());
  492. ref.setUpdateTime(now);
  493. sysFileRefMapper.insert(ref);
  494. }
  495. }
  496. int review = planYearsMapper.review(vo);
  497. if (review != 1) {
  498. return AjaxResult.error("项目状态数据异常");
  499. }
  500. return AjaxResult.success();
  501. }
  502. @Override
  503. public AjaxResult sendLetter(PlanYearsStandardVo yearsStandardVo) {
  504. PlanYears plan = new PlanYears();
  505. BeanUtils.copyProperties(yearsStandardVo, plan);
  506. plan.setSendLetter("1");
  507. plan.setLetterTime(new Date());
  508. int review = planYearsMapper.updateById(plan);
  509. if (review != 1) {
  510. return AjaxResult.error("项目状态数据异常");
  511. }
  512. return AjaxResult.success();
  513. }
  514. @Override
  515. public AjaxResult upLoadPlanFile(PlanYearsStandardVo yearsStandardVo) {
  516. List<SysFileRef> sysFileRefs = yearsStandardVo.getSysFileRefs();
  517. if (!ObjectUtils.isEmpty(sysFileRefs)) {
  518. for (SysFileRef ref : sysFileRefs) {
  519. ref.setRedId(yearsStandardVo.getPlanYearId());
  520. ref.setType(SysFileRefEnum.PLAN_YEAR.getType());
  521. sysFileRefMapper.insert(ref);
  522. }
  523. }
  524. return AjaxResult.success();
  525. }
  526. /**
  527. * 需求单位--首页--计划管理总数
  528. *
  529. * @return
  530. */
  531. @Override
  532. public AjaxResult demandUnitPlanManagementTotal() {
  533. // List<PlanYears> planYears = new ArrayList<>();
  534. Long count = null;
  535. try {
  536. // 通过用户ID查询角色
  537. List<SysRole> sysRoles = sysRoleMapper.selectRolePermissionByUserId(SecurityUtils.getUserId());
  538. // 获取角色权限 demand_unit
  539. List<SysRole> sysRoleList = sysRoles.stream().filter(tdto -> tdto.getRoleKey().equals("demand_unit")).collect(Collectors.toList());
  540. if (sysRoleList.size() > 0) {
  541. // 获取用户
  542. SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
  543. // 获取部门
  544. SysDept sysDept = deptMapper.selectDeptById(sysUser.getDeptId());
  545. // 查询年度计划
  546. LambdaQueryWrapper<PlanYears> queryWrapper = new LambdaQueryWrapper<>();
  547. queryWrapper.eq(PlanYears::getPurchaseDeptId, sysDept.getDeptId());
  548. queryWrapper.eq(PlanYears::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  549. // planYears = planYearsMapper.selectList(queryWrapper);
  550. count = planYearsMapper.selectCount(queryWrapper);
  551. }
  552. // 获取角色权限 admin
  553. List<SysRole> sysRoleList2 = sysRoles.stream().filter(tdto -> tdto.getRoleKey().equals("admin")).collect(Collectors.toList());
  554. if (sysRoleList2.size() > 0) {
  555. LambdaQueryWrapper<PlanYears> queryWrapper = new LambdaQueryWrapper<>();
  556. queryWrapper.eq(PlanYears::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  557. // planYears = planYearsMapper.selectList(queryWrapper);
  558. count = planYearsMapper.selectCount(queryWrapper);
  559. }
  560. } catch (Exception e) {
  561. e.printStackTrace();
  562. }
  563. return AjaxResult.success(count);
  564. }
  565. @Override
  566. public AjaxResult purchasingManagementPurchasingManagementTotal() {
  567. LoginUser loginUser = SecurityUtils.getLoginUser();
  568. PlanYearsStandardVo vo = new PlanYearsStandardVo();
  569. vo.setPurchaseDeptId(String.valueOf(loginUser.getDeptId()));
  570. vo.setCreated(String.valueOf(loginUser.getUserId()));
  571. List<PlanYears> planYears = planYearsMapper.query(vo);
  572. return AjaxResult.success(planYears.size());
  573. }
  574. /**
  575. * 需求单位--首页--需求管理总数
  576. *
  577. * @return
  578. */
  579. @Override
  580. public AjaxResult demandUnitDemandManagementTotal() {
  581. List<PmDemand> pmDemands = new ArrayList<>();
  582. try {
  583. // 通过用户ID 查询角色
  584. List<SysRole> sysRoles = sysRoleMapper.selectRolePermissionByUserId(SecurityUtils.getUserId());
  585. // 获取角色权限 demand_unit
  586. List<SysRole> sysRoleList = sysRoles.stream().filter(tdto -> tdto.getRoleKey().equals("demand_unit")).collect(Collectors.toList());
  587. if (sysRoleList.size() > 0) {
  588. SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
  589. SysDept sysDept = deptMapper.selectDeptById(sysUser.getDeptId());
  590. LambdaQueryWrapper<PmDemand> queryWrapper = new LambdaQueryWrapper<>();
  591. queryWrapper.in(PmDemand::getPurchaseDeptId, sysDept.getDeptId());
  592. pmDemands = pmDemandMapper.selectList(queryWrapper);
  593. }
  594. List<SysRole> sysRoleList2 = sysRoles.stream().filter(tdto -> tdto.getRoleKey().equals("admin")).collect(Collectors.toList());
  595. if (sysRoleList2.size() > 0) {
  596. LambdaQueryWrapper<PmDemand> queryWrapper = new LambdaQueryWrapper<>();
  597. pmDemands = pmDemandMapper.selectList(queryWrapper);
  598. }
  599. } catch (Exception e) {
  600. e.printStackTrace();
  601. }
  602. return AjaxResult.success(pmDemands.size());
  603. }
  604. @Override
  605. public AjaxResult purchasingManagementDemandManagementTotal() {
  606. long ii = selectPmDemandCount(1);
  607. return AjaxResult.success(ii);
  608. }
  609. public long selectPmDemandCount(int reqType) {
  610. LambdaQueryWrapper<PmDemand> lw = new LambdaQueryWrapper<>();
  611. // 4 (合同信息管理)、 0(需求单位管理) 、 5(项目建设管理) 需求单位
  612. // 1(需求需求审核) 、2 (任务下达管理) 采购管理部门
  613. // 3(采购执行管理) 采购办
  614. List<PmAuditDeptRef> list = new ArrayList<>();
  615. LambdaQueryWrapper<PmAuditDeptRef> l = new LambdaQueryWrapper<>();
  616. l.eq(PmAuditDeptRef::getDeptId, SecurityUtils.getDeptId());
  617. l.eq(PmAuditDeptRef::getRefType, "2");
  618. list = pmAuditDeptRefService.list(l);
  619. if (Arrays.asList(1, 2, 3).contains(reqType)) {
  620. if (!ObjectUtils.isEmpty(list) && !SysUser.isAdmin(SecurityUtils.getUserId())) {
  621. lw.in(PmDemand::getDemandId, list.stream().map(PmAuditDeptRef::getRefId).collect(Collectors.toList()));
  622. }
  623. lw.eq(PmDemand::getPurchaseDeptId, SecurityUtils.getDeptId());
  624. } else {
  625. lw.eq(PmDemand::getPurchaseDeptId, SecurityUtils.getDeptId());
  626. }
  627. if (reqType == 1) { //需求审核单位列表
  628. lw.apply("(project_status = 6 or project_status = 8 )");
  629. } else if (reqType == 2) { //任务下达列表
  630. lw.apply("(project_status = 8 or project_status = 9 )");
  631. } else if (reqType == 3) { //采购执行列表
  632. lw.apply("(project_status = 9 or project_status = 10 or project_status = 11 or project_status = 12 or project_status = 13 or project_status = 14 or project_status = 15)");
  633. } else if (reqType == 4) { //合同信息列表
  634. lw.apply("(project_status = 15 or project_status = 16 )");
  635. } else if (reqType == 5) { //项目建设列表
  636. lw.apply("(project_status = 16 or project_status = 17 )");
  637. }
  638. lw.last(" order by project_status, plan_demand_sub_time");
  639. long count = demandService.count(lw);
  640. return count;
  641. }
  642. @Override
  643. public AjaxResult demandUnitContractManagementTotal() {
  644. List<PmDemand> pmDemands = new ArrayList<>();
  645. try {
  646. List<SysRole> sysRoles = sysRoleMapper.selectRolePermissionByUserId(SecurityUtils.getUserId());
  647. List<SysRole> sysRoleList = sysRoles.stream().filter(tdto -> tdto.getRoleKey().equals("demand_unit")).collect(Collectors.toList());
  648. if (sysRoleList.size() > 0) {
  649. SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
  650. SysDept sysDept = deptMapper.selectDeptById(sysUser.getDeptId());
  651. LambdaQueryWrapper<PmDemand> queryWrapper = new LambdaQueryWrapper<>();
  652. queryWrapper.eq(PmDemand::getPurchaseDeptId, sysDept.getDeptId());
  653. queryWrapper.in(PmDemand::getProjectStatus, PmProjectStatus.CONTRACT_WAIT_FILL.getCode(), PmProjectStatus.UNDER_CONSTRUCTION.getCode());
  654. pmDemands = pmDemandMapper.selectList(queryWrapper);
  655. }
  656. List<SysRole> sysRoleList2 = sysRoles.stream().filter(tdto -> tdto.getRoleKey().equals("admin")).collect(Collectors.toList());
  657. if (sysRoleList2.size() > 0) {
  658. LambdaQueryWrapper<PmDemand> queryWrapper = new LambdaQueryWrapper<>();
  659. queryWrapper.in(PmDemand::getProjectStatus, PmProjectStatus.CONTRACT_WAIT_FILL.getCode(), PmProjectStatus.UNDER_CONSTRUCTION.getCode());
  660. pmDemands = pmDemandMapper.selectList(queryWrapper);
  661. }
  662. } catch (Exception e) {
  663. e.printStackTrace();
  664. }
  665. return AjaxResult.success(pmDemands.size());
  666. }
  667. @Override
  668. public AjaxResult demandUnitConstructionManagementTotal() {
  669. List<PmDemand> pmDemands = new ArrayList<>();
  670. try {
  671. List<SysRole> sysRoles = sysRoleMapper.selectRolePermissionByUserId(SecurityUtils.getUserId());
  672. List<SysRole> sysRoleList = sysRoles.stream().filter(tdto -> tdto.getRoleKey().equals("demand_unit")).collect(Collectors.toList());
  673. if (sysRoleList.size() > 0) {
  674. SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
  675. SysDept sysDept = deptMapper.selectDeptById(sysUser.getDeptId());
  676. LambdaQueryWrapper<PmDemand> queryWrapper = new LambdaQueryWrapper<>();
  677. queryWrapper.eq(PmDemand::getPurchaseDeptId, sysDept.getDeptId());
  678. queryWrapper.in(PmDemand::getProjectStatus, PmProjectStatus.UNDER_CONSTRUCTION.getCode(), PmProjectStatus.COMPLETION_CONSTRUCTION.getCode());
  679. pmDemands = pmDemandMapper.selectList(queryWrapper);
  680. }
  681. List<SysRole> sysRoleList2 = sysRoles.stream().filter(tdto -> tdto.getRoleKey().equals("admin")).collect(Collectors.toList());
  682. if (sysRoleList2.size() > 0) {
  683. LambdaQueryWrapper<PmDemand> queryWrapper = new LambdaQueryWrapper<>();
  684. queryWrapper.in(PmDemand::getProjectStatus, PmProjectStatus.UNDER_CONSTRUCTION.getCode(), PmProjectStatus.COMPLETION_CONSTRUCTION.getCode());
  685. pmDemands = pmDemandMapper.selectList(queryWrapper);
  686. }
  687. } catch (Exception e) {
  688. e.printStackTrace();
  689. }
  690. return AjaxResult.success(pmDemands.size());
  691. }
  692. @Override
  693. public AjaxResult purchasingManagementTaskReleaseTotal() {
  694. long ii = selectPmDemandCount(2);
  695. return AjaxResult.success(ii);
  696. }
  697. @Override
  698. public AjaxResult procurementOfficeProcurementExecutionTotal() {
  699. PmDemandReqVo pmDemandReqVo = new PmDemandReqVo();
  700. pmDemandReqVo.setPageNum(1L);
  701. pmDemandReqVo.setPageSize(10L);
  702. pmDemandReqVo.setUserId(SecurityUtils.getUserId());
  703. pmDemandReqVo.setIsAdmin(SysUser.isAdmin(SecurityUtils.getUserId()));
  704. pmDemandReqVo.setDeptId(SecurityUtils.getDeptId());
  705. pmDemandReqVo.setPurchaseDeptId(Math.toIntExact(SecurityUtils.getDeptId()));
  706. IPage<PmDemandResVo> page = demandService.selectPmDemandList(pmDemandReqVo, 3);
  707. return AjaxResult.success(page.getTotal());
  708. }
  709. @Override
  710. public AjaxResult procurementOfficeWinningTheBidTotal() {
  711. List<PmDemand> pmDemands = new ArrayList<>();
  712. try {
  713. List<SysRole> sysRoles = sysRoleMapper.selectRolePermissionByUserId(SecurityUtils.getUserId());
  714. List<SysRole> sysRoleList = sysRoles.stream().filter(tdto -> tdto.getRoleKey().equals("procurement_office")).collect(Collectors.toList());
  715. if (sysRoleList.size() > 0) {
  716. SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
  717. SysDept sysDept = deptMapper.selectDeptById(sysUser.getDeptId());
  718. LambdaQueryWrapper<PmDemand> queryWrapper = new LambdaQueryWrapper<>();
  719. queryWrapper.eq(PmDemand::getPurchaseDeptId, sysDept.getDeptId())
  720. .gt(PmDemand::getProjectStatus, PmProjectStatus.CONTRACT_WAIT_FILL.getCode());
  721. pmDemands = pmDemandMapper.selectList(queryWrapper);
  722. }
  723. List<SysRole> sysRoleList2 = sysRoles.stream().filter(tdto -> tdto.getRoleKey().equals("admin")).collect(Collectors.toList());
  724. if (sysRoleList2.size() > 0) {
  725. LambdaQueryWrapper<PmDemand> queryWrapper = new LambdaQueryWrapper<>();
  726. queryWrapper.gt(PmDemand::getProjectStatus, PmProjectStatus.CONTRACT_WAIT_FILL.getCode());
  727. pmDemands = pmDemandMapper.selectList(queryWrapper);
  728. }
  729. } catch (Exception e) {
  730. e.printStackTrace();
  731. }
  732. return AjaxResult.success(pmDemands.size());
  733. }
  734. @Override
  735. public AjaxResult procurementOfficeFailureToWinTheBidTotal() {
  736. List<PmDemand> pmDemands = new ArrayList<>();
  737. try {
  738. List<SysRole> sysRoles = sysRoleMapper.selectRolePermissionByUserId(SecurityUtils.getUserId());
  739. List<SysRole> sysRoleList = sysRoles.stream().filter(tdto -> tdto.getRoleKey().equals("procurement_office")).collect(Collectors.toList());
  740. if (sysRoleList.size() > 0) {
  741. SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
  742. SysDept sysDept = deptMapper.selectDeptById(sysUser.getDeptId());
  743. LambdaQueryWrapper<PmDemand> queryWrapper = new LambdaQueryWrapper<>();
  744. queryWrapper.eq(PmDemand::getPurchaseDeptId, sysDept.getDeptId())
  745. .lt(PmDemand::getProjectStatus, PmProjectStatus.CONTRACT_WAIT_FILL.getCode());
  746. pmDemands = pmDemandMapper.selectList(queryWrapper);
  747. }
  748. List<SysRole> sysRoleList2 = sysRoles.stream().filter(tdto -> tdto.getRoleKey().equals("admin")).collect(Collectors.toList());
  749. if (sysRoleList2.size() > 0) {
  750. LambdaQueryWrapper<PmDemand> queryWrapper = new LambdaQueryWrapper<>();
  751. queryWrapper.lt(PmDemand::getProjectStatus, PmProjectStatus.CONTRACT_WAIT_FILL.getCode());
  752. pmDemands = pmDemandMapper.selectList(queryWrapper);
  753. }
  754. } catch (Exception e) {
  755. e.printStackTrace();
  756. }
  757. return AjaxResult.success(pmDemands.size());
  758. }
  759. /**
  760. * 查询需求单位待办事项(计划待提交)
  761. *
  762. * @return
  763. */
  764. @Override
  765. public List<PlanQuarterResponseVo> planWaitCommit() {
  766. //是否是查询审核(要过滤掉本单位的超额计划)
  767. String isAd = "false";
  768. return getListByProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode(), isAd);
  769. }
  770. /**
  771. * 采购管理部门首页待办事项(计划待审核)
  772. *
  773. * @return
  774. */
  775. @Override
  776. public List<PlanQuarterResponseVo> planWaitExamine() {
  777. //是否是查询审核(要过滤掉本单位的超额计划)
  778. String isAd = "true";
  779. return getListByProjectStatus(ProjectStatus.PLANWAIEXAMINE.getCode(), isAd);
  780. }
  781. /**
  782. * 需求单位待办事项
  783. */
  784. @Override
  785. public AjaxResult demandUnitWillManipulateTotal() {
  786. //计划待提交,需求待提交,合同待填制,项目建设待完成
  787. String isAd = "false";
  788. List<PlanQuarterResponseVo> planRes = getListByProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode(), isAd);
  789. List<PmDemand> demandRes = demandService.demandWaitCommit();
  790. demandRes.addAll(demandService.contractWaitFilled());
  791. demandRes.addAll(demandService.projectWaitFinish());
  792. List<PmDemandResVo> resVos = demandService.listToVoList(demandRes);
  793. return AjaxResult.success(planAndProjectToHome(planRes, resVos));
  794. }
  795. /**
  796. * 需求单位待办事项
  797. */
  798. @Override
  799. public AjaxResult demandUnitWillManipulateTotalNum() {
  800. List<StatisticalChartsResVo> result = new ArrayList<>();
  801. //计划待提交,需求待提交,合同待填制,项目建设待完成
  802. String isAd = "false";
  803. Integer numByProjectStatus = getNumByProjectStatus(ProjectStatus.PLANWAITCOMMIT.getCode(), isAd);
  804. Integer numByStatus = demandService.getNumByStatus(PmProjectStatus.DEMAND_WAIT_COMMIT.getCode());
  805. Integer numByStatus1 = demandService.getNumByStatus(PmProjectStatus.CONTRACT_WAIT_FILL.getCode());
  806. Integer numByStatus2 = demandService.getNumByStatus(PmProjectStatus.UNDER_CONSTRUCTION.getCode());
  807. StatisticalChartsResVo chartsResVo = new StatisticalChartsResVo();
  808. chartsResVo.setColumnName("计划待提交");
  809. chartsResVo.setNum(numByProjectStatus);
  810. result.add(chartsResVo);
  811. StatisticalChartsResVo chartsResVo1 = new StatisticalChartsResVo();
  812. chartsResVo1.setColumnName("需求待提交");
  813. chartsResVo1.setNum(numByStatus);
  814. result.add(chartsResVo1);
  815. StatisticalChartsResVo chartsResVo2 = new StatisticalChartsResVo();
  816. chartsResVo2.setColumnName("合同待填制");
  817. chartsResVo2.setNum(numByStatus1);
  818. result.add(chartsResVo2);
  819. StatisticalChartsResVo chartsResVo3 = new StatisticalChartsResVo();
  820. chartsResVo3.setColumnName("项目建设待完成");
  821. chartsResVo3.setNum(numByStatus2);
  822. result.add(chartsResVo3);
  823. StatisticalChartsResVo chartsResVoT = new StatisticalChartsResVo();
  824. chartsResVoT.setColumnName("全部");
  825. chartsResVoT.setNum(willTotal(result));
  826. result.add(chartsResVoT);
  827. return AjaxResult.success(result);
  828. }
  829. @Override
  830. public AjaxResult purchasingManagementWillManipulateTotal() {
  831. //计划待审核,需求待审核,任务待下达
  832. String isAd = "true";
  833. List<PlanQuarterResponseVo> planRes = getListByProjectStatus(ProjectStatus.PLANWAIEXAMINE.getCode(), isAd);
  834. List<PmDemand> demandRes = demandService.demandWaitExamine();
  835. demandRes.addAll(demandService.taskWaitRelease());
  836. List<PmDemandResVo> resVos = demandService.listToVoList(demandRes);
  837. return AjaxResult.success(planAndProjectToHome(planRes, resVos));
  838. }
  839. /**
  840. * 计划数据和项目数据一起返回给 首页--待办事项
  841. *
  842. * @return
  843. */
  844. public List<HomeToDoQueryResVo> planAndProjectToHome(List<PlanQuarterResponseVo> planRes, List<PmDemandResVo> demandRes) {
  845. List<HomeToDoQueryResVo> homeRes = new ArrayList<>();
  846. //转为首页table展示数据
  847. if (!ObjectUtils.isEmpty(planRes) && planRes.size() > 0) {
  848. for (PlanQuarterResponseVo planVo : planRes) {
  849. HomeToDoQueryResVo home = new HomeToDoQueryResVo();
  850. BeanUtils.copyProperties(planVo, home);
  851. homeRes.add(home);
  852. }
  853. }
  854. if (!ObjectUtils.isEmpty(demandRes) && demandRes.size() > 0) {
  855. for (PmDemandResVo demandResVo : demandRes) {
  856. HomeToDoQueryResVo home = new HomeToDoQueryResVo();
  857. home.setEvaluation(BigDecimal.valueOf(demandResVo.getEvaluation()));
  858. BeanUtils.copyProperties(demandResVo, home);
  859. homeRes.add(home);
  860. }
  861. }
  862. return homeRes;
  863. }
  864. @Override
  865. public AjaxResult purchasingManagementWillManipulateTotalNum() {
  866. List<StatisticalChartsResVo> result = new ArrayList<>();
  867. //计划待审核,需求待审核,任务待下达
  868. String isAd = "true";
  869. Integer status = getNumByProjectStatus(ProjectStatus.PLANWAIEXAMINE.getCode(), isAd);
  870. Integer numByStatus = demandService.getNumByStatus(PmProjectStatus.DEMAND_WAIT_AUDIT.getCode());
  871. Integer numByStatus1 = demandService.getNumByStatus(PmProjectStatus.TASK_WAIT_RELEASE.getCode());
  872. StatisticalChartsResVo chartsResVo = new StatisticalChartsResVo();
  873. chartsResVo.setColumnName("计划待审核");
  874. chartsResVo.setNum(status);
  875. result.add(chartsResVo);
  876. StatisticalChartsResVo chartsResVo1 = new StatisticalChartsResVo();
  877. chartsResVo1.setColumnName("需求待审核");
  878. chartsResVo1.setNum(numByStatus);
  879. result.add(chartsResVo1);
  880. StatisticalChartsResVo chartsResVo2 = new StatisticalChartsResVo();
  881. chartsResVo2.setColumnName("任务待下达");
  882. chartsResVo2.setNum(numByStatus1);
  883. result.add(chartsResVo2);
  884. StatisticalChartsResVo chartsResVoT = new StatisticalChartsResVo();
  885. chartsResVoT.setColumnName("全部");
  886. chartsResVoT.setNum(willTotal(result));
  887. result.add(chartsResVoT);
  888. return AjaxResult.success(result);
  889. }
  890. public Integer willTotal(List<StatisticalChartsResVo> result) {
  891. Integer re = 0;
  892. if (!ObjectUtils.isEmpty(result)) {
  893. for (StatisticalChartsResVo resVo : result) {
  894. re += resVo.getNum();
  895. }
  896. }
  897. return re;
  898. }
  899. /**
  900. * 通过年度ID,查询季度、临时计划详情,通过季度、临时计划ID查询项目
  901. *
  902. * @param yearsStandardVo
  903. * @return
  904. */
  905. @Override
  906. public AjaxResult projectDetails(PlanYearsStandardVo yearsStandardVo) {
  907. Map<String, Object> returnMap = new HashMap<>();
  908. // 通过年度ID查询年度详情
  909. PlanYears byId = planYearsMapper.getById(yearsStandardVo.getPlanYearId());
  910. if (ObjectUtils.isEmpty(byId)) {
  911. return AjaxResult.error("没有查到相关数据!");
  912. }
  913. // 通过年度ID查询季度、临时计划详情
  914. ProvisionalPlan provisionalPlan = provisionalPlanMapper.selectProvisionalPlanByYearId(yearsStandardVo.getPlanYearId().intValue());
  915. if (ObjectUtils.isEmpty(provisionalPlan)) {
  916. return AjaxResult.error("没有查到相关数据!");
  917. }
  918. // 通过季度、临时计划ID查询项目数据
  919. PmDemand pmDemand = demandService.selectByPlanId(provisionalPlan.getPlanPracticalId());
  920. if (!ObjectUtils.isEmpty(pmDemand)) {
  921. String detailType = "";
  922. if (StringUtils.isNotNull(yearsStandardVo.getDetailType())) {
  923. detailType = yearsStandardVo.getDetailType();
  924. } else {
  925. // 详情类型(1项目计划,2需求建档,3任务下达,4中标信息,5合同信息,6建设情况)
  926. // 项目计划 4之前(包括4)
  927. // 需求建党 4之后(不包括4)
  928. // 任务下达 8之后(不包括8)
  929. // 采购执行 9之后(不包括9)
  930. // 合同信息 19之后(不包括19)
  931. // 项目建设 21
  932. Integer projectStatus = Integer.valueOf(pmDemand.getProjectStatus());
  933. if (projectStatus <= 4 || projectStatus == 18) {
  934. detailType = "1";
  935. } else if (4 < projectStatus && projectStatus <= 8) {
  936. detailType = "2";
  937. } else if (8 < projectStatus && projectStatus <= 9) {
  938. detailType = "3";
  939. } else if (9 < projectStatus && projectStatus <= 19 && projectStatus != 18) {
  940. detailType = "4";
  941. } else if (19 < projectStatus && projectStatus < 21) {
  942. detailType = "5";
  943. } else if (projectStatus == 21) {
  944. detailType = "6";
  945. }
  946. }
  947. PmDemandResVo vo = demandService.selectPmDemandByDemandId(pmDemand.getDemandId(), detailType);
  948. return AjaxResult.success(vo);
  949. } else {
  950. if (!ObjectUtils.isEmpty(provisionalPlan)) {
  951. return AjaxResult.success(provisionalPlan);
  952. } else {
  953. if (!ObjectUtils.isEmpty(byId)) {
  954. return AjaxResult.success(byId);
  955. }
  956. }
  957. }
  958. return AjaxResult.error("没有查到相关数据!");
  959. }
  960. @Override
  961. public List<PlanYears> queryPage(PlanYearsStandardVo vo) throws ParseException {
  962. Map<String, Object> params = vo.getParams();
  963. if (!ObjectUtils.isEmpty(vo.getParams())) {
  964. if (!ObjectUtils.isEmpty(vo.getParams().get("beginTime"))) {
  965. params.put("beginTime", vo.getParams().get("beginTime").toString() + "-01");
  966. }
  967. if (!ObjectUtils.isEmpty(vo.getParams().get("endTime"))) {
  968. SimpleDateFormat dateFormaH = new SimpleDateFormat("yyyy-MM");
  969. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  970. Date ofMonth = DateUtils.getLastDayOfMonth(dateFormaH.parse(vo.getParams().get("endTime").toString()));
  971. params.put("endTime", dateFormat.format(ofMonth) + " 23:59:59:999");
  972. }
  973. }
  974. vo.setParams(params);
  975. LoginUser loginUser = SecurityUtils.getLoginUser();
  976. if (!loginUser.getUserId().equals(Long.valueOf("1"))) {
  977. vo.setPurchaseDeptId(String.valueOf(loginUser.getDeptId()));
  978. }
  979. List<PlanYears> planYears = planYearsMapper.query(vo);
  980. if (!ObjectUtils.isEmpty(planYears)) {
  981. planYears.stream().map(o -> {
  982. // 当前年度计划的所有关联审核数据
  983. LambdaQueryWrapper<PmAuditDeptRef> lw = new LambdaQueryWrapper();
  984. lw.eq(PmAuditDeptRef::getRefId, o.getPlanYearId());
  985. lw.eq(PmAuditDeptRef::getRefType, "0");
  986. List<PmAuditDeptRef> list = pmAuditDeptRefService.list(lw);
  987. boolean fl = true;
  988. if (!ObjectUtils.isEmpty(list) && list.size() > 0) {
  989. // 当地 年度计划 当前部门 的 审核数据
  990. List<PmAuditDeptRef> collect = list.stream()
  991. .filter(f -> f.getDeptId().equals(Long.valueOf(vo.getPurchaseDeptId())))
  992. .collect(Collectors.toList());
  993. if (ObjectUtils.isEmpty(collect)) {
  994. fl = false;
  995. } else {
  996. String deptLevel = collect.get(0).getDeptLevel();
  997. fl = collect.get(0).getStatus().equals(Integer.parseInt("1")) ? false : true;
  998. for (PmAuditDeptRef pmAuditDeptRef : list) {
  999. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) == -1
  1000. && pmAuditDeptRef.getStatus().equals(Integer.parseInt("0"))) {
  1001. fl = false;
  1002. }
  1003. }
  1004. }
  1005. /*
  1006. * String s1="A";
  1007. String s2="B";
  1008. System.out.println(s1.compareTo(s2));
  1009. * -1
  1010. * */
  1011. }
  1012. if (vo.getCreated().equals("1")) {
  1013. fl = false;
  1014. }
  1015. o.setFlag(fl);
  1016. return o;
  1017. }).collect(Collectors.toList());
  1018. }
  1019. return planYears;
  1020. }
  1021. private List<SysFileInfo> getSysFileInfoList(Long redId, Integer type) {
  1022. HashMap<String, Object> map = new HashMap<>();
  1023. map.put("red_id", redId);
  1024. map.put("type", type);
  1025. List<SysFileRef> fileRefs = sysFileRefService.listByMap(map);
  1026. if (!ObjectUtils.isEmpty(fileRefs)) {
  1027. List<SysFileInfo> fileInfos = new ArrayList<>();
  1028. for (SysFileRef ref : fileRefs) {
  1029. SysFileInfo fileInfo = fileService.getById(ref.getFileId());
  1030. fileInfos.add(fileInfo);
  1031. }
  1032. return fileInfos;
  1033. } else {
  1034. return null;
  1035. }
  1036. }
  1037. /**
  1038. * 查询已被催告发函的计划
  1039. *
  1040. * @return
  1041. */
  1042. @Override
  1043. public List<PlanQuarterResponseVo> willSendLetter() {
  1044. LoginUser user = SecurityUtils.getLoginUser();
  1045. LambdaQueryWrapper<PlanQuarter> quarterLp = new LambdaQueryWrapper<PlanQuarter>();
  1046. quarterLp.eq(PlanQuarter::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  1047. quarterLp.eq(PlanQuarter::getPurchaseDeptId, user.getDeptId());
  1048. quarterLp.eq(PlanQuarter::getSendLetter, "1");
  1049. List<PlanQuarter> planQuarters = planQuarterMapper.selectList(quarterLp);
  1050. //转换返回类Vo
  1051. List<PlanQuarterResponseVo> quarterRes = quartzServiceImpl.changeTo(planQuarters);
  1052. return quarterRes;
  1053. }
  1054. /**
  1055. * 查询已被催告发函的计划(数量)
  1056. *
  1057. * @return
  1058. */
  1059. @Override
  1060. public Integer willSendLetterNum() {
  1061. //年度计划没有催告,只有临时和季度计划有
  1062. LoginUser user = SecurityUtils.getLoginUser();
  1063. LambdaQueryWrapper<PlanQuarter> quarterLp = new LambdaQueryWrapper<PlanQuarter>();
  1064. quarterLp.eq(PlanQuarter::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  1065. quarterLp.eq(PlanQuarter::getPurchaseDeptId, user.getDeptId());
  1066. quarterLp.eq(PlanQuarter::getSendLetter, "1");
  1067. Long aLong = planQuarterMapper.selectCount(quarterLp);
  1068. return Math.toIntExact(aLong);
  1069. }
  1070. /**
  1071. * 首页待办事项---计划待提交or待审核
  1072. *
  1073. * @param projectStatus
  1074. * @return
  1075. */
  1076. public List<PlanQuarterResponseVo> getListByProjectStatus(String projectStatus, String isAd) {
  1077. LoginUser user = SecurityUtils.getLoginUser();
  1078. LambdaQueryWrapper<PlanYears> yearsLp = new LambdaQueryWrapper<PlanYears>();
  1079. yearsLp.eq(PlanYears::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  1080. yearsLp.eq(PlanYears::getProjectStatus, projectStatus);
  1081. if (isAd.equals("true")) {
  1082. List<PmAuditDeptRef> list = new ArrayList<>();
  1083. LambdaQueryWrapper<PmAuditDeptRef> l = new LambdaQueryWrapper<>();
  1084. l.eq(PmAuditDeptRef::getDeptId, SecurityUtils.getDeptId());
  1085. l.eq(PmAuditDeptRef::getRefType, "0");
  1086. l.eq(PmAuditDeptRef::getStatus, 0);
  1087. list = pmAuditDeptRefService.list(l);
  1088. if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
  1089. if (!ObjectUtils.isEmpty(list)) {
  1090. yearsLp.in(PlanYears::getPlanYearId, list.stream().map(PmAuditDeptRef::getRefId).collect(Collectors.toList()));
  1091. } else {
  1092. //没有要当前用户单位进行审核的,就不显示
  1093. yearsLp.in(PlanYears::getPlanYearId, "0");
  1094. }
  1095. }
  1096. } else {
  1097. yearsLp.eq(PlanYears::getPurchaseDeptId, user.getDeptId());
  1098. }
  1099. List<PlanYears> planYears = planYearsMapper.selectList(yearsLp);
  1100. LambdaQueryWrapper<PlanQuarter> quarterLp = new LambdaQueryWrapper<PlanQuarter>();
  1101. quarterLp.eq(PlanQuarter::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  1102. quarterLp.eq(PlanQuarter::getProjectStatus, projectStatus);
  1103. quarterLp.eq(PlanQuarter::getPurchaseDeptId, user.getDeptId());
  1104. if (isAd.equals("true")) {
  1105. List<PmAuditDeptRef> listF = new ArrayList<>();
  1106. LambdaQueryWrapper<PmAuditDeptRef> lq = new LambdaQueryWrapper<>();
  1107. lq.eq(PmAuditDeptRef::getDeptId, SecurityUtils.getDeptId());
  1108. lq.eq(PmAuditDeptRef::getRefType, "1");
  1109. lq.eq(PmAuditDeptRef::getStatus, 0);
  1110. listF = pmAuditDeptRefService.list(lq);
  1111. if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
  1112. if (!ObjectUtils.isEmpty(listF)) {
  1113. quarterLp.in(PlanQuarter::getPlanPracticalId, listF.stream().map(PmAuditDeptRef::getRefId).collect(Collectors.toList()));
  1114. } else {
  1115. //没有要当前用户单位进行审核的,就不显示
  1116. quarterLp.in(PlanQuarter::getPlanPracticalId, "0");
  1117. }
  1118. }
  1119. } else {
  1120. quarterLp.eq(PlanQuarter::getPurchaseDeptId, user.getDeptId());
  1121. }
  1122. List<PlanQuarter> planQuarters = planQuarterMapper.selectList(quarterLp);
  1123. //融合一起
  1124. List<PlanQuarterResponseVo> vos = planComplex(planYears, planQuarters);
  1125. return vos;
  1126. }
  1127. //计划待提交、计划待审核的数量
  1128. public Integer getNumByProjectStatus(String projectStatus, String isAd) {
  1129. LoginUser user = SecurityUtils.getLoginUser();
  1130. LambdaQueryWrapper<PlanYears> yearsLp = new LambdaQueryWrapper<PlanYears>();
  1131. yearsLp.eq(PlanYears::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  1132. yearsLp.eq(PlanYears::getProjectStatus, projectStatus);
  1133. if (isAd.equals("true")) {
  1134. List<PmAuditDeptRef> list = new ArrayList<>();
  1135. LambdaQueryWrapper<PmAuditDeptRef> l = new LambdaQueryWrapper<>();
  1136. l.eq(PmAuditDeptRef::getDeptId, SecurityUtils.getDeptId());
  1137. l.eq(PmAuditDeptRef::getRefType, "0");
  1138. l.eq(PmAuditDeptRef::getStatus, "0");
  1139. list = pmAuditDeptRefService.list(l);
  1140. if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
  1141. if (!ObjectUtils.isEmpty(list)) {
  1142. yearsLp.in(PlanYears::getPlanYearId, list.stream().map(PmAuditDeptRef::getRefId).collect(Collectors.toList()));
  1143. } else {
  1144. //没有要当前用户单位进行审核的,就不显示
  1145. yearsLp.in(PlanYears::getPlanYearId, "0");
  1146. }
  1147. }
  1148. } else {
  1149. yearsLp.eq(PlanYears::getPurchaseDeptId, user.getDeptId());
  1150. }
  1151. Long count = planYearsMapper.selectCount(yearsLp);
  1152. LambdaQueryWrapper<PlanQuarter> quarterLp = new LambdaQueryWrapper<PlanQuarter>();
  1153. quarterLp.eq(PlanQuarter::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  1154. quarterLp.eq(PlanQuarter::getProjectStatus, projectStatus);
  1155. if (isAd.equals("true")) {
  1156. List<PmAuditDeptRef> listF = new ArrayList<>();
  1157. LambdaQueryWrapper<PmAuditDeptRef> lq = new LambdaQueryWrapper<>();
  1158. lq.eq(PmAuditDeptRef::getDeptId, SecurityUtils.getDeptId());
  1159. lq.eq(PmAuditDeptRef::getRefType, "1");
  1160. lq.eq(PmAuditDeptRef::getStatus, "0");
  1161. listF = pmAuditDeptRefService.list(lq);
  1162. if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
  1163. if (!ObjectUtils.isEmpty(listF)) {
  1164. quarterLp.in(PlanQuarter::getPlanPracticalId, listF.stream().map(PmAuditDeptRef::getRefId).collect(Collectors.toList()));
  1165. } else {
  1166. //没有要当前用户单位进行审核的,就不显示
  1167. quarterLp.in(PlanQuarter::getPlanPracticalId, "0");
  1168. }
  1169. }
  1170. } else {
  1171. quarterLp.eq(PlanQuarter::getPurchaseDeptId, user.getDeptId());
  1172. }
  1173. Long aLong = planQuarterMapper.selectCount(quarterLp);
  1174. //融合一起
  1175. return Math.toIntExact(count) + Math.toIntExact(aLong);
  1176. }
  1177. /**
  1178. * 年度计划与季度数据一起
  1179. *
  1180. * @return
  1181. */
  1182. public List<PlanQuarterResponseVo> planComplex(List<PlanYears> planYears, List<PlanQuarter> planQuarters) {
  1183. List<PlanYearsResponseVo> yearsRes = changeTo(planYears);
  1184. List<PlanQuarterResponseVo> quarterRes = quartzServiceImpl.changeTo(planQuarters);
  1185. if (!ObjectUtils.isEmpty(yearsRes) && yearsRes.size() > 0) {
  1186. for (PlanYearsResponseVo yearsRe : yearsRes) {
  1187. PlanQuarterResponseVo responseVo = new PlanQuarterResponseVo();
  1188. BeanUtils.copyProperties(yearsRe, responseVo);
  1189. quarterRes.add(responseVo);
  1190. }
  1191. }
  1192. return quarterRes;
  1193. }
  1194. //字段赋值对应的名称
  1195. @Override
  1196. public List<PlanYearsResponseVo> changeTo(List<PlanYears> planYears) {
  1197. //获取年度计划提报时间的阈值
  1198. List<SysDictData> supTime = dictTypeService.selectDictDataByType("sys_annual_plan");
  1199. HashMap<String, String> thresholdMap = new LinkedHashMap<>();
  1200. //年度提报时间的阈值
  1201. for (SysDictData dictData : supTime) {
  1202. // 字段名称----阈值
  1203. thresholdMap.put(dictData.getDictLabel(), dictData.getDictValue());
  1204. }
  1205. //提前或延后*天进行提醒
  1206. List<SysDictData> alertTime = dictTypeService.selectDictDataByType("alert_time_setting");
  1207. HashMap<String, String> alertTimeMap = new LinkedHashMap<>();
  1208. //根据时间类别设定的提醒时间
  1209. for (SysDictData dictData : alertTime) {
  1210. // 字段名称----阈值
  1211. alertTimeMap.put(dictData.getDictLabel(), dictData.getDictValue());
  1212. }
  1213. //获取字典数据
  1214. HashMap<String, HashMap<String, String>> planEnums = dictTypeService.getAboutEnums();
  1215. //项目属性
  1216. HashMap<String, String> projectAttributes = planEnums.get("projectAttributes");
  1217. //项目审核状态
  1218. HashMap<String, String> projectStatusMap = planEnums.get("projectStatus");
  1219. //项目类型
  1220. HashMap<String, String> projectTypesMap = planEnums.get("projectTypes");
  1221. //项目类型
  1222. HashMap<String, String> projectTypesAdMap = planEnums.get("projectTypesAds");
  1223. //预算科目
  1224. HashMap<String, String> budgetAccountMap = planEnums.get("budgetAccount");
  1225. //采购服务站
  1226. HashMap<String, String> purchaseServicesMap = planEnums.get("purchaseServices");
  1227. List<PlanYearsResponseVo> list = new ArrayList<PlanYearsResponseVo>();
  1228. for (PlanYears planYear : planYears) {
  1229. PlanYearsResponseVo responseVo = new PlanYearsResponseVo();
  1230. SysDeptResponseVo sysDeptResponseVo = (SysDeptResponseVo) deptService.selectDeptById(Long.valueOf(planYear.getPurchaseDeptId())).get("sysDept");
  1231. planYear.setPurchaseDeptName(sysDeptResponseVo.getDeptName());
  1232. //预算科目
  1233. for (Map.Entry<String, String> entry : budgetAccountMap.entrySet()) {
  1234. if (!ObjectUtils.isEmpty(planYear.getBudgetAccount()) && planYear.getBudgetAccount().equals(entry.getValue())) {
  1235. planYear.setBudgetAccountStr(entry.getKey());
  1236. break;
  1237. }
  1238. }
  1239. //采购服务站
  1240. for (Map.Entry<String, String> entry : purchaseServicesMap.entrySet()) {
  1241. if (!ObjectUtils.isEmpty(planYear.getPurchaseServices()) && planYear.getPurchaseServices().equals(entry.getValue())) {
  1242. planYear.setPurchaseServicesStr(entry.getKey());
  1243. break;
  1244. }
  1245. }
  1246. //项目审核状态
  1247. for (Map.Entry<String, String> entry : projectStatusMap.entrySet()) {
  1248. if (!ObjectUtils.isEmpty(planYear.getProjectStatus()) && planYear.getProjectStatus().equals(entry.getValue())) {
  1249. planYear.setProjectStatusStr(entry.getKey());
  1250. break;
  1251. }
  1252. }
  1253. //项目类型
  1254. if (planYear.getProjectStatus().equals(ProjectStatus.PLANWAITCOMMIT)) {
  1255. for (Map.Entry<String, String> entry : projectTypesMap.entrySet()) {
  1256. if (!ObjectUtils.isEmpty(planYear.getProjectType()) && planYear.getProjectType().equals(entry.getValue())) {
  1257. planYear.setProjectTypeStr(entry.getKey());
  1258. break;
  1259. }
  1260. }
  1261. } else {
  1262. for (Map.Entry<String, String> entry : projectTypesAdMap.entrySet()) {
  1263. if (!ObjectUtils.isEmpty(planYear.getProjectType()) && planYear.getProjectType().equals(entry.getValue())) {
  1264. planYear.setProjectTypeStr(entry.getKey());
  1265. break;
  1266. }
  1267. }
  1268. }
  1269. //项目属性为value拼接
  1270. if (!ObjectUtils.isEmpty(planYear.getProjectAttr())) {
  1271. if (planYear.getProjectAttr().length() > 1) {
  1272. StringBuilder builder = new StringBuilder();
  1273. String[] split = planYear.getProjectAttr().split(",");
  1274. for (String s : split) {
  1275. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  1276. if (s.equals(entry.getValue())) {
  1277. if (!planYear.getProjectAttr().endsWith(s)) {
  1278. builder.append(entry.getKey() + ",");
  1279. } else {
  1280. builder.append(entry.getKey());
  1281. }
  1282. break;
  1283. }
  1284. }
  1285. }
  1286. planYear.setProjectAttrName(builder.toString());
  1287. } else {
  1288. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  1289. if (planYear.getProjectAttr().equals(entry.getValue())) {
  1290. planYear.setProjectAttrName(entry.getKey());
  1291. break;
  1292. }
  1293. }
  1294. }
  1295. }
  1296. //机关业务指导处(科)为id拼接
  1297. String organDivision = planYear.getOrganDivision();
  1298. if (!ObjectUtils.isEmpty(organDivision)) {
  1299. int length = organDivision.split(",").length;
  1300. SysDept sysDept = new SysDept();
  1301. if (length > 1) {
  1302. StringBuilder builder = new StringBuilder();
  1303. String[] split = organDivision.split(",");
  1304. for (String s : split) {
  1305. sysDept = deptService.selectById(Long.valueOf(s));
  1306. if (!ObjectUtils.isEmpty(sysDept)) {
  1307. if (!organDivision.endsWith(s)) {
  1308. builder.append(sysDept.getDeptName() + ",");
  1309. } else {
  1310. builder.append(sysDept.getDeptName());
  1311. }
  1312. }
  1313. }
  1314. planYear.setOrganDivisionStr(builder.toString());
  1315. } else if (length == 1) {
  1316. sysDept = deptService.selectById(Long.valueOf(organDivision));
  1317. if (!ObjectUtils.isEmpty(sysDept)) {
  1318. planYear.setOrganDivisionStr(sysDept.getDeptName());
  1319. }
  1320. }
  1321. }
  1322. if (!ObjectUtils.isEmpty(planYear.getAppDelete())) {
  1323. //申请过的不能再申请
  1324. planYear.setAppDeleteDo("false");
  1325. } else if (planYear.getProjectStatus().equals(ProjectStatus.PLANWAIEXAMINE.getCode())) {
  1326. //提交后可以申请撤销
  1327. planYear.setAppDeleteDo("true");
  1328. }
  1329. BeanUtils.copyProperties(planYear, responseVo);
  1330. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
  1331. responseVo.setPlanDemandSubTimeStr(sdf.format(responseVo.getPlanDemandSubTime()));
  1332. responseVo.setPlanPurchaseFinishTimeStr(sdf.format(responseVo.getPlanPurchaseFinishTime()));
  1333. responseVo.setPlanDeliverTimeStr(sdf.format(responseVo.getPlanDeliverTime()));
  1334. try {
  1335. responseVo.setTipsMessage(planYearsGetTips(responseVo, thresholdMap, alertTimeMap));
  1336. } catch (ParseException e) {
  1337. e.printStackTrace();
  1338. }
  1339. list.add(responseVo);
  1340. }
  1341. return list;
  1342. }
  1343. @Override
  1344. @Transactional
  1345. public AjaxResult adPurchaseServices(PlanYearsStandardVo yearsStandardVo) {
  1346. PlanYears years = new PlanYears();
  1347. BeanUtils.copyProperties(yearsStandardVo, years);
  1348. if (planYearsMapper.updateById(years) == 1) {
  1349. return AjaxResult.success("成功");
  1350. }
  1351. return AjaxResult.success("成功");
  1352. }
  1353. @Override
  1354. public AjaxResult appDelete(PlanYearsStandardVo yearsStandardVo) {
  1355. PlanQuarter byPlanYearId = planQuarterMapper.getByPlanYearId(yearsStandardVo.getPlanYearId());
  1356. //需求待填制可以申请,需求建档就不能申请
  1357. if (!ObjectUtils.isEmpty(byPlanYearId)) {
  1358. PmDemand demand = demandService.selectByPlanId(byPlanYearId.getPlanPracticalId());
  1359. if (!ObjectUtils.isEmpty(demand) && !demand.getProjectStatus().equals(PmProjectStatus.DEMAND_WAIT_FILL.getCode())) {
  1360. return AjaxResult.error("改需求已建档,不可进行撤销");
  1361. }
  1362. }
  1363. PlanYears years = new PlanYears();
  1364. BeanUtils.copyProperties(yearsStandardVo, years);
  1365. years.setAppDelete("true");
  1366. planYearsMapper.updateById(years);
  1367. return AjaxResult.success("申请成功");
  1368. }
  1369. @Override
  1370. public AjaxResult handleApp(PlanYearsStandardVo yearsStandardVo) {
  1371. //getProjectAttr传值1为同意。-1为拒绝
  1372. if ("1".equals(yearsStandardVo.getProjectAttr())) {
  1373. planYearsMapper.deletePlanYearsById(yearsStandardVo.getPlanYearId());
  1374. //年度计划撤销后季度计划也同步撤销
  1375. PlanQuarter byPlanYearId = planQuarterMapper.getByPlanYearId(yearsStandardVo.getPlanYearId());
  1376. if (!ObjectUtils.isEmpty(byPlanYearId)) {
  1377. planQuarterMapper.deletePlanQuarterById(byPlanYearId.getPlanPracticalId());
  1378. }
  1379. return AjaxResult.success("已成功进行撤销");
  1380. }
  1381. PlanYears years = new PlanYears();
  1382. BeanUtils.copyProperties(yearsStandardVo, years);
  1383. years.setAppDelete("false");
  1384. planYearsMapper.updateById(years);
  1385. return AjaxResult.success("已拒绝改申请");
  1386. }
  1387. @Override
  1388. public List<Integer> idNotInQuarter() {
  1389. return planYearsMapper.idNotInQuarter();
  1390. }
  1391. /**
  1392. * 根据年度计划提报时间的阈值进行提示
  1393. *
  1394. * @return
  1395. */
  1396. public String planYearsGetTips(PlanYearsResponseVo responseVo, HashMap<String, String> thresholdMap, HashMap<String, String> alertTimeMap) throws ParseException {
  1397. //提示信息:定义距离结束时间*天内提示
  1398. int alertDay = Integer.parseInt(alertTimeMap.get("计划提报时间"));
  1399. Integer remindTime = 1000 * 60 * 60 * 24 * alertDay;
  1400. //提报时间的结束时间阈值
  1401. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  1402. Date thresholdTime = dateFormat.parse(thresholdMap.get("起止时间结束"));
  1403. Date date = new Date();
  1404. thresholdTime.setYear(date.getYear());
  1405. double surplus = thresholdTime.getTime() - date.getTime();
  1406. //少于设定天数便提醒
  1407. if (surplus < remindTime && surplus > 0) {
  1408. //剩余天数(向上取整)
  1409. int i = new Double(Math.ceil(surplus / 1000 / 60 / 60 / 24)).intValue();
  1410. if (i > 0) {
  1411. return "距离计划提报时间不足" + i + "天";
  1412. }
  1413. }
  1414. //距离计划完成采购时间一周内提醒
  1415. Integer alertTime = 1000 * 60 * 60 * 24 * 7;
  1416. double surplusTwo = responseVo.getPlanPurchaseFinishTime().getTime() - System.currentTimeMillis();
  1417. //少于设定阈值便提醒
  1418. if (surplusTwo < alertTime && surplusTwo > 0) {
  1419. //剩余天数(向上取整)
  1420. int i = new Double(Math.ceil(surplusTwo / 1000 / 60 / 60 / 24)).intValue();
  1421. if (i > 0) {
  1422. return "距离计划完成采购时间不足" + i + "天";
  1423. }
  1424. }
  1425. return "";
  1426. }
  1427. }