PlanYearsServiceImpl.java 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503
  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. yearsLp.eq(PlanYears::getPurchaseDeptId, user.getDeptId());
  1082. if (isAd.equals("true")) {
  1083. List<PmAuditDeptRef> list = new ArrayList<>();
  1084. LambdaQueryWrapper<PmAuditDeptRef> l = new LambdaQueryWrapper<>();
  1085. l.eq(PmAuditDeptRef::getDeptId, SecurityUtils.getDeptId());
  1086. l.eq(PmAuditDeptRef::getRefType, "0");
  1087. l.eq(PmAuditDeptRef::getStatus, 0);
  1088. list = pmAuditDeptRefService.list(l);
  1089. if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
  1090. if (!ObjectUtils.isEmpty(list)) {
  1091. yearsLp.in(PlanYears::getPlanYearId, list.stream().map(PmAuditDeptRef::getRefId).collect(Collectors.toList()));
  1092. } else {
  1093. //没有要当前用户单位进行审核的,就不显示
  1094. yearsLp.in(PlanYears::getPlanYearId, "0");
  1095. }
  1096. }
  1097. }
  1098. List<PlanYears> planYears = planYearsMapper.selectList(yearsLp);
  1099. LambdaQueryWrapper<PlanQuarter> quarterLp = new LambdaQueryWrapper<PlanQuarter>();
  1100. quarterLp.eq(PlanQuarter::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  1101. quarterLp.eq(PlanQuarter::getProjectStatus, projectStatus);
  1102. quarterLp.eq(PlanQuarter::getPurchaseDeptId, user.getDeptId());
  1103. if (isAd.equals("true")) {
  1104. List<PmAuditDeptRef> listF = new ArrayList<>();
  1105. LambdaQueryWrapper<PmAuditDeptRef> lq = new LambdaQueryWrapper<>();
  1106. lq.eq(PmAuditDeptRef::getDeptId, SecurityUtils.getDeptId());
  1107. lq.eq(PmAuditDeptRef::getRefType, "1");
  1108. lq.eq(PmAuditDeptRef::getStatus, 0);
  1109. listF = pmAuditDeptRefService.list(lq);
  1110. if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
  1111. if (!ObjectUtils.isEmpty(listF)) {
  1112. quarterLp.in(PlanQuarter::getPlanPracticalId, listF.stream().map(PmAuditDeptRef::getRefId).collect(Collectors.toList()));
  1113. } else {
  1114. //没有要当前用户单位进行审核的,就不显示
  1115. quarterLp.in(PlanQuarter::getPlanPracticalId, "0");
  1116. }
  1117. }
  1118. }
  1119. List<PlanQuarter> planQuarters = planQuarterMapper.selectList(quarterLp);
  1120. //融合一起
  1121. List<PlanQuarterResponseVo> vos = planComplex(planYears, planQuarters);
  1122. return vos;
  1123. }
  1124. //计划待提交、计划待审核的数量
  1125. public Integer getNumByProjectStatus(String projectStatus, String isAd) {
  1126. LoginUser user = SecurityUtils.getLoginUser();
  1127. LambdaQueryWrapper<PlanYears> yearsLp = new LambdaQueryWrapper<PlanYears>();
  1128. yearsLp.eq(PlanYears::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  1129. yearsLp.eq(PlanYears::getProjectStatus, projectStatus);
  1130. yearsLp.eq(PlanYears::getPurchaseDeptId, user.getDeptId());
  1131. if (isAd.equals("true")) {
  1132. List<PmAuditDeptRef> list = new ArrayList<>();
  1133. LambdaQueryWrapper<PmAuditDeptRef> l = new LambdaQueryWrapper<>();
  1134. l.eq(PmAuditDeptRef::getDeptId, SecurityUtils.getDeptId());
  1135. l.eq(PmAuditDeptRef::getRefType, "0");
  1136. l.eq(PmAuditDeptRef::getStatus, "0");
  1137. list = pmAuditDeptRefService.list(l);
  1138. if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
  1139. if (!ObjectUtils.isEmpty(list)) {
  1140. yearsLp.in(PlanYears::getPlanYearId, list.stream().map(PmAuditDeptRef::getRefId).collect(Collectors.toList()));
  1141. } else {
  1142. //没有要当前用户单位进行审核的,就不显示
  1143. yearsLp.in(PlanYears::getPlanYearId, "0");
  1144. }
  1145. }
  1146. }
  1147. Long count = planYearsMapper.selectCount(yearsLp);
  1148. LambdaQueryWrapper<PlanQuarter> quarterLp = new LambdaQueryWrapper<PlanQuarter>();
  1149. quarterLp.eq(PlanQuarter::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  1150. quarterLp.eq(PlanQuarter::getProjectStatus, projectStatus);
  1151. quarterLp.eq(PlanQuarter::getPurchaseDeptId, user.getDeptId());
  1152. if (isAd.equals("true")) {
  1153. List<PmAuditDeptRef> listF = new ArrayList<>();
  1154. LambdaQueryWrapper<PmAuditDeptRef> lq = new LambdaQueryWrapper<>();
  1155. lq.eq(PmAuditDeptRef::getDeptId, SecurityUtils.getDeptId());
  1156. lq.eq(PmAuditDeptRef::getRefType, "1");
  1157. lq.eq(PmAuditDeptRef::getStatus, "0");
  1158. listF = pmAuditDeptRefService.list(lq);
  1159. if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
  1160. if (!ObjectUtils.isEmpty(listF)) {
  1161. quarterLp.in(PlanQuarter::getPlanPracticalId, listF.stream().map(PmAuditDeptRef::getRefId).collect(Collectors.toList()));
  1162. } else {
  1163. //没有要当前用户单位进行审核的,就不显示
  1164. quarterLp.in(PlanQuarter::getPlanPracticalId, "0");
  1165. }
  1166. }
  1167. }
  1168. Long aLong = planQuarterMapper.selectCount(quarterLp);
  1169. //融合一起
  1170. return Math.toIntExact(count) + Math.toIntExact(aLong);
  1171. }
  1172. /**
  1173. * 年度计划与季度数据一起
  1174. *
  1175. * @return
  1176. */
  1177. public List<PlanQuarterResponseVo> planComplex(List<PlanYears> planYears, List<PlanQuarter> planQuarters) {
  1178. List<PlanYearsResponseVo> yearsRes = changeTo(planYears);
  1179. List<PlanQuarterResponseVo> quarterRes = quartzServiceImpl.changeTo(planQuarters);
  1180. if (!ObjectUtils.isEmpty(yearsRes) && yearsRes.size() > 0) {
  1181. for (PlanYearsResponseVo yearsRe : yearsRes) {
  1182. PlanQuarterResponseVo responseVo = new PlanQuarterResponseVo();
  1183. BeanUtils.copyProperties(yearsRe, responseVo);
  1184. quarterRes.add(responseVo);
  1185. }
  1186. }
  1187. return quarterRes;
  1188. }
  1189. //字段赋值对应的名称
  1190. @Override
  1191. public List<PlanYearsResponseVo> changeTo(List<PlanYears> planYears) {
  1192. //获取年度计划提报时间的阈值
  1193. List<SysDictData> supTime = dictTypeService.selectDictDataByType("sys_annual_plan");
  1194. HashMap<String, String> thresholdMap = new LinkedHashMap<>();
  1195. //年度提报时间的阈值
  1196. for (SysDictData dictData : supTime) {
  1197. // 字段名称----阈值
  1198. thresholdMap.put(dictData.getDictLabel(), dictData.getDictValue());
  1199. }
  1200. //提前或延后*天进行提醒
  1201. List<SysDictData> alertTime = dictTypeService.selectDictDataByType("alert_time_setting");
  1202. HashMap<String, String> alertTimeMap = new LinkedHashMap<>();
  1203. //根据时间类别设定的提醒时间
  1204. for (SysDictData dictData : alertTime) {
  1205. // 字段名称----阈值
  1206. alertTimeMap.put(dictData.getDictLabel(), dictData.getDictValue());
  1207. }
  1208. //获取字典数据
  1209. HashMap<String, HashMap<String, String>> planEnums = dictTypeService.getAboutEnums();
  1210. //项目属性
  1211. HashMap<String, String> projectAttributes = planEnums.get("projectAttributes");
  1212. //项目审核状态
  1213. HashMap<String, String> projectStatusMap = planEnums.get("projectStatus");
  1214. //项目类型
  1215. HashMap<String, String> projectTypesMap = planEnums.get("projectTypes");
  1216. //项目类型
  1217. HashMap<String, String> projectTypesAdMap = planEnums.get("projectTypesAds");
  1218. //预算科目
  1219. HashMap<String, String> budgetAccountMap = planEnums.get("budgetAccount");
  1220. //采购服务站
  1221. HashMap<String, String> purchaseServicesMap = planEnums.get("purchaseServices");
  1222. List<PlanYearsResponseVo> list = new ArrayList<PlanYearsResponseVo>();
  1223. for (PlanYears planYear : planYears) {
  1224. PlanYearsResponseVo responseVo = new PlanYearsResponseVo();
  1225. SysDeptResponseVo sysDeptResponseVo = (SysDeptResponseVo) deptService.selectDeptById(Long.valueOf(planYear.getPurchaseDeptId())).get("sysDept");
  1226. planYear.setPurchaseDeptName(sysDeptResponseVo.getDeptName());
  1227. //预算科目
  1228. for (Map.Entry<String, String> entry : budgetAccountMap.entrySet()) {
  1229. if (!ObjectUtils.isEmpty(planYear.getBudgetAccount()) && planYear.getBudgetAccount().equals(entry.getValue())) {
  1230. planYear.setBudgetAccountStr(entry.getKey());
  1231. break;
  1232. }
  1233. }
  1234. //采购服务站
  1235. for (Map.Entry<String, String> entry : purchaseServicesMap.entrySet()) {
  1236. if (!ObjectUtils.isEmpty(planYear.getPurchaseServices()) && planYear.getPurchaseServices().equals(entry.getValue())) {
  1237. planYear.setPurchaseServicesStr(entry.getKey());
  1238. break;
  1239. }
  1240. }
  1241. //项目审核状态
  1242. for (Map.Entry<String, String> entry : projectStatusMap.entrySet()) {
  1243. if (!ObjectUtils.isEmpty(planYear.getProjectStatus()) && planYear.getProjectStatus().equals(entry.getValue())) {
  1244. planYear.setProjectStatusStr(entry.getKey());
  1245. break;
  1246. }
  1247. }
  1248. //项目类型
  1249. if (planYear.getProjectStatus().equals(ProjectStatus.PLANWAITCOMMIT)) {
  1250. for (Map.Entry<String, String> entry : projectTypesMap.entrySet()) {
  1251. if (!ObjectUtils.isEmpty(planYear.getProjectType()) && planYear.getProjectType().equals(entry.getValue())) {
  1252. planYear.setProjectTypeStr(entry.getKey());
  1253. break;
  1254. }
  1255. }
  1256. } else {
  1257. for (Map.Entry<String, String> entry : projectTypesAdMap.entrySet()) {
  1258. if (!ObjectUtils.isEmpty(planYear.getProjectType()) && planYear.getProjectType().equals(entry.getValue())) {
  1259. planYear.setProjectTypeStr(entry.getKey());
  1260. break;
  1261. }
  1262. }
  1263. }
  1264. //项目属性为value拼接
  1265. if (!ObjectUtils.isEmpty(planYear.getProjectAttr())) {
  1266. if (planYear.getProjectAttr().length() > 1) {
  1267. StringBuilder builder = new StringBuilder();
  1268. String[] split = planYear.getProjectAttr().split(",");
  1269. for (String s : split) {
  1270. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  1271. if (s.equals(entry.getValue())) {
  1272. if (!planYear.getProjectAttr().endsWith(s)) {
  1273. builder.append(entry.getKey() + ",");
  1274. } else {
  1275. builder.append(entry.getKey());
  1276. }
  1277. break;
  1278. }
  1279. }
  1280. }
  1281. planYear.setProjectAttrName(builder.toString());
  1282. } else {
  1283. for (Map.Entry<String, String> entry : projectAttributes.entrySet()) {
  1284. if (planYear.getProjectAttr().equals(entry.getValue())) {
  1285. planYear.setProjectAttrName(entry.getKey());
  1286. break;
  1287. }
  1288. }
  1289. }
  1290. }
  1291. //机关业务指导处(科)为id拼接
  1292. String organDivision = planYear.getOrganDivision();
  1293. if (!ObjectUtils.isEmpty(organDivision)) {
  1294. int length = organDivision.split(",").length;
  1295. SysDept sysDept = new SysDept();
  1296. if (length > 1) {
  1297. StringBuilder builder = new StringBuilder();
  1298. String[] split = organDivision.split(",");
  1299. for (String s : split) {
  1300. sysDept = deptService.selectById(Long.valueOf(s));
  1301. if (!ObjectUtils.isEmpty(sysDept)) {
  1302. if (!organDivision.endsWith(s)) {
  1303. builder.append(sysDept.getDeptName() + ",");
  1304. } else {
  1305. builder.append(sysDept.getDeptName());
  1306. }
  1307. }
  1308. }
  1309. planYear.setOrganDivisionStr(builder.toString());
  1310. } else if (length == 1) {
  1311. sysDept = deptService.selectById(Long.valueOf(organDivision));
  1312. if (!ObjectUtils.isEmpty(sysDept)) {
  1313. planYear.setOrganDivisionStr(sysDept.getDeptName());
  1314. }
  1315. }
  1316. }
  1317. if (!ObjectUtils.isEmpty(planYear.getAppDelete())) {
  1318. //申请过的不能再申请
  1319. planYear.setAppDeleteDo("false");
  1320. } else if (planYear.getProjectStatus().equals(ProjectStatus.PLANWAIEXAMINE.getCode())) {
  1321. //提交后可以申请撤销
  1322. planYear.setAppDeleteDo("true");
  1323. }
  1324. BeanUtils.copyProperties(planYear, responseVo);
  1325. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
  1326. responseVo.setPlanDemandSubTimeStr(sdf.format(responseVo.getPlanDemandSubTime()));
  1327. responseVo.setPlanPurchaseFinishTimeStr(sdf.format(responseVo.getPlanPurchaseFinishTime()));
  1328. responseVo.setPlanDeliverTimeStr(sdf.format(responseVo.getPlanDeliverTime()));
  1329. try {
  1330. responseVo.setTipsMessage(planYearsGetTips(responseVo, thresholdMap, alertTimeMap));
  1331. } catch (ParseException e) {
  1332. e.printStackTrace();
  1333. }
  1334. list.add(responseVo);
  1335. }
  1336. return list;
  1337. }
  1338. @Override
  1339. @Transactional
  1340. public AjaxResult adPurchaseServices(PlanYearsStandardVo yearsStandardVo) {
  1341. PlanYears years = new PlanYears();
  1342. BeanUtils.copyProperties(yearsStandardVo, years);
  1343. if (planYearsMapper.updateById(years) == 1) {
  1344. return AjaxResult.success("成功");
  1345. }
  1346. return AjaxResult.success("成功");
  1347. }
  1348. @Override
  1349. public AjaxResult appDelete(PlanYearsStandardVo yearsStandardVo) {
  1350. PlanQuarter byPlanYearId = planQuarterMapper.getByPlanYearId(yearsStandardVo.getPlanYearId());
  1351. //需求待填制可以申请,需求建档就不能申请
  1352. if (!ObjectUtils.isEmpty(byPlanYearId)) {
  1353. PmDemand demand = demandService.selectByPlanId(byPlanYearId.getPlanPracticalId());
  1354. if (!ObjectUtils.isEmpty(demand) && !demand.getProjectStatus().equals(PmProjectStatus.DEMAND_WAIT_FILL.getCode())) {
  1355. return AjaxResult.error("改需求已建档,不可进行撤销");
  1356. }
  1357. }
  1358. PlanYears years = new PlanYears();
  1359. BeanUtils.copyProperties(yearsStandardVo, years);
  1360. years.setAppDelete("true");
  1361. planYearsMapper.updateById(years);
  1362. return AjaxResult.success("申请成功");
  1363. }
  1364. @Override
  1365. public AjaxResult handleApp(PlanYearsStandardVo yearsStandardVo) {
  1366. //getProjectAttr传值1为同意。-1为拒绝
  1367. if ("1".equals(yearsStandardVo.getProjectAttr())) {
  1368. planYearsMapper.deletePlanYearsById(yearsStandardVo.getPlanYearId());
  1369. //年度计划撤销后季度计划也同步撤销
  1370. PlanQuarter byPlanYearId = planQuarterMapper.getByPlanYearId(yearsStandardVo.getPlanYearId());
  1371. if (!ObjectUtils.isEmpty(byPlanYearId)) {
  1372. planQuarterMapper.deletePlanQuarterById(byPlanYearId.getPlanPracticalId());
  1373. }
  1374. return AjaxResult.success("已成功进行撤销");
  1375. }
  1376. PlanYears years = new PlanYears();
  1377. BeanUtils.copyProperties(yearsStandardVo, years);
  1378. years.setAppDelete("false");
  1379. planYearsMapper.updateById(years);
  1380. return AjaxResult.success("已拒绝改申请");
  1381. }
  1382. @Override
  1383. public List<Integer> idNotInQuarter() {
  1384. return planYearsMapper.idNotInQuarter();
  1385. }
  1386. /**
  1387. * 根据年度计划提报时间的阈值进行提示
  1388. *
  1389. * @return
  1390. */
  1391. public String planYearsGetTips(PlanYearsResponseVo responseVo, HashMap<String, String> thresholdMap, HashMap<String, String> alertTimeMap) throws ParseException {
  1392. //提示信息:定义距离结束时间*天内提示
  1393. int alertDay = Integer.parseInt(alertTimeMap.get("计划提报时间"));
  1394. Integer remindTime = 1000 * 60 * 60 * 24 * alertDay;
  1395. //提报时间的结束时间阈值
  1396. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  1397. Date thresholdTime = dateFormat.parse(thresholdMap.get("起止时间结束"));
  1398. Date date = new Date();
  1399. thresholdTime.setYear(date.getYear());
  1400. double surplus = thresholdTime.getTime() - date.getTime();
  1401. //少于设定天数便提醒
  1402. if (surplus < remindTime && surplus > 0) {
  1403. //剩余天数(向上取整)
  1404. int i = new Double(Math.ceil(surplus / 1000 / 60 / 60 / 24)).intValue();
  1405. if (i > 0) {
  1406. return "距离计划提报时间不足" + i + "天";
  1407. }
  1408. }
  1409. //距离计划完成采购时间一周内提醒
  1410. Integer alertTime = 1000 * 60 * 60 * 24 * 7;
  1411. double surplusTwo = responseVo.getPlanPurchaseFinishTime().getTime() - System.currentTimeMillis();
  1412. //少于设定阈值便提醒
  1413. if (surplusTwo < alertTime && surplusTwo > 0) {
  1414. //剩余天数(向上取整)
  1415. int i = new Double(Math.ceil(surplusTwo / 1000 / 60 / 60 / 24)).intValue();
  1416. if (i > 0) {
  1417. return "距离计划完成采购时间不足" + i + "天";
  1418. }
  1419. }
  1420. return "";
  1421. }
  1422. }