PmDemandServiceImpl.java 116 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449
  1. package com.ozs.pm.service.impl;
  2. import java.lang.invoke.LambdaConversionException;
  3. import java.math.BigDecimal;
  4. import java.text.DecimalFormat;
  5. import java.text.ParseException;
  6. import java.util.*;
  7. import java.util.stream.Collectors;
  8. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  9. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  10. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  11. import com.baomidou.mybatisplus.core.metadata.IPage;
  12. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  13. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  14. import com.ozs.base.domain.*;
  15. import com.ozs.base.domain.vo.BaseExpertVo;
  16. import com.ozs.base.mapper.BaseExpertMapper;
  17. import com.ozs.base.service.*;
  18. import com.ozs.common.core.domain.AjaxResult;
  19. import com.ozs.common.core.domain.entity.*;
  20. import com.ozs.common.enums.*;
  21. import com.ozs.common.utils.DateUtils;
  22. import com.ozs.common.utils.RandomUtil;
  23. import com.ozs.common.utils.SecurityUtils;
  24. import com.ozs.common.utils.StringUtils;
  25. import com.ozs.common.utils.bean.BeanUtils;
  26. import com.ozs.home.domain.vo.HomeToDoQueryResVo;
  27. import com.ozs.plan.doman.vo.responseVo.PlanQuarterResponseVo;
  28. import com.ozs.plan.service.PlanYearsService;
  29. import com.ozs.pm.doman.*;
  30. import com.ozs.pm.doman.vo.requestVo.*;
  31. import com.ozs.pm.doman.vo.responseVo.*;
  32. import com.ozs.pm.mapper.PmDemandMapper;
  33. import com.ozs.pm.service.*;
  34. import com.ozs.system.domain.SysFileInfo;
  35. import com.ozs.system.domain.SysFileRef;
  36. import com.ozs.system.domain.vo.SysRegionVO;
  37. import com.ozs.system.domain.vo.responseVo.SysDeptResponseVo;
  38. import com.ozs.system.mapper.SysDeptMapper;
  39. import com.ozs.system.mapper.SysRoleMapper;
  40. import com.ozs.system.service.*;
  41. import io.swagger.models.auth.In;
  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.CollectionUtils;
  47. import org.springframework.util.ObjectUtils;
  48. /**
  49. * 采购需求Service业务层处理
  50. *
  51. * @author ruoyi
  52. * @date 2023-01-16
  53. */
  54. @Service
  55. @Slf4j
  56. public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> implements IPmDemandService {
  57. @Autowired
  58. private PmDemandMapper pmDemandMapper;
  59. @Autowired
  60. private ISysDeptService deptService;
  61. @Autowired
  62. private ISysDictDataService dictDataService;
  63. @Autowired
  64. private SysFileService fileService;
  65. @Autowired
  66. private SysFileRefService sysFileRefService;
  67. @Autowired
  68. private IPmFlowChartService iPmFlowChartService;
  69. @Autowired
  70. private PmReleaseAnnouncementService pmReleaseAnnouncementService;
  71. @Autowired
  72. private BaseExpertService baseExpertService;
  73. @Autowired
  74. private PmDemandExpertRefService pmDemandExpertRefService;
  75. @Autowired
  76. private PmBidOpeningService pmBidOpeningService;
  77. @Autowired
  78. private PmBookBuildingService pmBookBuildingService;
  79. @Autowired
  80. private PmBidWinningService pmBidWinningService;
  81. @Autowired
  82. private ISysDictTypeService iSysDictTypeService;
  83. @Autowired
  84. private PmBidFailureService pmBidFailureService;
  85. @Autowired
  86. private PmBidWinningOpeningRefService pmBidWinningOpeningRefService;
  87. @Autowired
  88. private PmContractInfoService pmContractInfoService;
  89. @Autowired
  90. private BaseAgencyService baseAgencyService;
  91. @Autowired
  92. private PmProjectConstructionService pmProjectConstructionService;
  93. @Autowired
  94. private BaseNoticeTypeService baseNoticeTypeService;
  95. @Autowired
  96. private BaseNoticeService baseNoticeService;
  97. @Autowired
  98. private PlanYearsService planYearsService;
  99. @Autowired
  100. private ISysRegionService iSysRegionService;
  101. @Autowired
  102. private SysRoleMapper sysRoleMapper;
  103. @Autowired
  104. private ISysUserService userService;
  105. @Autowired
  106. private SysDeptMapper deptMapper;
  107. @Autowired
  108. private BaseExpertMapper baseExpertMapper;
  109. @Autowired
  110. private SysProcurementStandardService sysProcurementStandardService;
  111. @Autowired
  112. private PmAuditDeptRefService pmAuditDeptRefService;
  113. /**
  114. * 查询采购需求
  115. *
  116. * @param demandId 采购需求主键
  117. * @return 采购需求
  118. */
  119. @Override
  120. public PmDemandResVo selectPmDemandByDemandId(Long demandId, String detailType) {
  121. PmDemand pmDemand = this.getById(demandId);
  122. if (pmDemand != null) {
  123. PmDemandResVo vo = new PmDemandResVo();
  124. vo.setProjectName(pmDemand.getProjectName());
  125. vo.setDemandId(demandId);
  126. if ("1".equals(detailType)) { //项目计划
  127. BeanUtils.copyProperties(pmDemand, vo);
  128. SysDeptResponseVo sysDeptResponseVo = (SysDeptResponseVo) deptService.selectDeptById(vo.getPurchaseDeptId()).get("sysDept");
  129. if (sysDeptResponseVo != null) {
  130. vo.setPurchaseDeptName(sysDeptResponseVo.getDeptName());
  131. }
  132. String purchaseServicesName = dictDataService.selectDictLabel("purchase_services", vo.getPurchaseServices());
  133. if (StringUtils.isNotEmpty(purchaseServicesName)) {
  134. vo.setPurchaseServicesName(purchaseServicesName);
  135. }
  136. //采购需求附件
  137. List<SysFileInfo> demandFileInfos = getSysFileInfoList(vo.getDemandId(), SysFileRefEnum.PM_DEMAND.getType());
  138. if (!ObjectUtils.isEmpty(demandFileInfos)) {
  139. vo.setDemandFileInfos(demandFileInfos);
  140. }
  141. //项目类型
  142. for (ProjectTypes value : ProjectTypes.values()) {
  143. if (vo.getProjectType() != null && vo.getProjectType().equals(value.getCode())) {
  144. vo.setProjectTypeName(value.getInfo());
  145. break;
  146. }
  147. }
  148. //是否为超限额计划
  149. for (IsExcess value : IsExcess.values()) {
  150. if (vo.getIsExcess() != null && vo.getIsExcess().equals(value.getCode())) {
  151. vo.setIsExcessName(value.getInfo());
  152. break;
  153. }
  154. }
  155. //采购方式
  156. for (PlanPurchaseMode value : PlanPurchaseMode.values()) {
  157. if (vo.getPurchaseMode() != null && vo.getPurchaseMode().equals(value.getCode())) {
  158. vo.setPurchaseModeName(value.getInfo());
  159. break;
  160. }
  161. }
  162. //项目属性
  163. for (ProjectAttribute value : ProjectAttribute.values()) {
  164. if (vo.getProjectAttr() != null && vo.getProjectAttr().equals(value.getCode())) {
  165. vo.setProjectAttrName(value.getInfo());
  166. break;
  167. }
  168. }
  169. //预警状态
  170. for (WarnStatus value : WarnStatus.values()) {
  171. if (vo.getWarnStatus() != null && vo.getWarnStatus().equals(value.getCode())) {
  172. vo.setWarnStatusName(value.getInfo());
  173. break;
  174. }
  175. }
  176. //项目状态
  177. for (PmProjectStatus value : PmProjectStatus.values()) {
  178. if (vo.getProjectStatus() != null && vo.getProjectStatus().equals(value.getCode())) {
  179. vo.setProjectStatusName(value.getInfo());
  180. break;
  181. }
  182. }
  183. } else if ("2".equals(detailType)) { //需求建档
  184. //采购需求审核文件
  185. List<SysFileInfo> auditFileInfos = getSysFileInfoList(vo.getDemandId(), SysFileRefEnum.PM_DEMAND_EXAMINE.getType());
  186. if (!ObjectUtils.isEmpty(auditFileInfos)) {
  187. vo.setAuditFileInfos(auditFileInfos);
  188. }
  189. LambdaQueryWrapper<PmBookBuilding> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  190. lambdaQueryWrapper.eq(PmBookBuilding::getDemandId, demandId);
  191. PmBookBuilding pmBookBuilding = pmBookBuildingService.getOne(lambdaQueryWrapper);
  192. if (pmBookBuilding != null) {
  193. PmBookBuildingResVo responseVo = new PmBookBuildingResVo();
  194. BeanUtils.copyProperties(pmBookBuilding, responseVo);
  195. List<SysFileInfo> fileInfos = getSysFileInfoList(pmBookBuilding.getId(), SysFileRefEnum.PM_BOOK_BUILDING.getType());
  196. if (!ObjectUtils.isEmpty(fileInfos)) {
  197. if (!ObjectUtils.isEmpty(auditFileInfos)) {
  198. fileInfos.addAll(auditFileInfos);
  199. }
  200. responseVo.setFileInfos(fileInfos);
  201. }
  202. vo.setPmBookBuildingResVo(responseVo);
  203. }
  204. } else if ("3".equals(detailType)) { //任务下达
  205. //任务下达文件
  206. List<SysFileInfo> taskReleaseFileInfos = getSysFileInfoList(vo.getDemandId(), SysFileRefEnum.PM_TAST_RELEASE.getType());
  207. if (!ObjectUtils.isEmpty(taskReleaseFileInfos)) {
  208. vo.setTaskReleaseFileInfos(taskReleaseFileInfos);
  209. }
  210. } else if ("4".equals(detailType)) { //中标信息
  211. PmPurchaseExecutionResVo pmPurchaseExecutionResVo = new PmPurchaseExecutionResVo();
  212. List<SysFileInfo> fileInfosAll = new ArrayList<>();
  213. //代理商信息
  214. BaseAgency baseAgency = this.baseAgencyService.getById(pmDemand.getAgencyId());
  215. pmPurchaseExecutionResVo.setBaseAgency(baseAgency);
  216. //发布公告列表
  217. LambdaQueryWrapper<PmReleaseAnnouncement> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  218. lambdaQueryWrapper.eq(PmReleaseAnnouncement::getDemandId, demandId);
  219. List<PmReleaseAnnouncement> pmReleaseAnnouncementList = this.pmReleaseAnnouncementService.list(lambdaQueryWrapper);
  220. if (!ObjectUtils.isEmpty(pmReleaseAnnouncementList)) {
  221. List<PmReleaseAnnouncementResVo> pmReleaseAnnouncementResVoList = new ArrayList<>();
  222. for (PmReleaseAnnouncement pmReleaseAnnouncement : pmReleaseAnnouncementList) {
  223. PmReleaseAnnouncementResVo pmReleaseAnnouncementResVo = new PmReleaseAnnouncementResVo();
  224. BeanUtils.copyProperties(pmReleaseAnnouncement, pmReleaseAnnouncementResVo);
  225. List<SysFileInfo> fileInfos = getSysFileInfoList(pmReleaseAnnouncement.getId(), SysFileRefEnum.PM_ANNOUNCEMENT_FILE.getType());
  226. if (!ObjectUtils.isEmpty(fileInfos)) {
  227. fileInfosAll.addAll(fileInfos);
  228. }
  229. pmReleaseAnnouncementResVoList.add(pmReleaseAnnouncementResVo);
  230. }
  231. pmPurchaseExecutionResVo.setPmReleaseAnnouncementResVoList(pmReleaseAnnouncementResVoList);
  232. }
  233. //专家信息列表
  234. List<PmBaseExpertResVo> pmBaseExpertResVoList = this.pmDemandExpertRefService.getPmBaseExpertResVoList(demandId);
  235. pmPurchaseExecutionResVo.setPmBaseExpertResVoList(pmBaseExpertResVoList);
  236. //开标信息列表
  237. List<PmBidOpeningResVo> pmBidOpeningResVoList = this.pmBidOpeningService.getPmBidOpeningResVoList(demandId);
  238. pmPurchaseExecutionResVo.setPmBidOpeningResVoList(pmBidOpeningResVoList);
  239. //中标信息列表
  240. LambdaQueryWrapper<PmBidWinning> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
  241. lambdaQueryWrapper1.eq(PmBidWinning::getDemandId, demandId)
  242. .eq(PmBidWinning::getStatus, BidWinningStatus.NORMAL.getCode());
  243. PmBidWinning pmBidWinning = this.pmBidWinningService.getOne(lambdaQueryWrapper1);
  244. if (!ObjectUtils.isEmpty(pmBidWinning)) {
  245. LambdaQueryWrapper<PmBidWinningOpeningRef> lambdaQueryWrapper2 = new LambdaQueryWrapper<>();
  246. lambdaQueryWrapper2.eq(PmBidWinningOpeningRef::getWinningId, pmBidWinning.getId())
  247. .eq(PmBidWinningOpeningRef::getStatus, BidWinningStatus.NORMAL.getCode());
  248. List<PmBidWinningOpeningRef> pmBidWinningOpeningRefList = this.pmBidWinningOpeningRefService.list(lambdaQueryWrapper2);
  249. if (!ObjectUtils.isEmpty(pmBidWinningOpeningRefList)) {
  250. List<PmBidWinningResVo> pmBidWinningResVoList = new ArrayList<>();
  251. for (PmBidWinningOpeningRef pmBidWinningOpeningRef : pmBidWinningOpeningRefList) {
  252. PmBidOpening pmBidOpening = this.pmBidOpeningService.getById(pmBidWinningOpeningRef.getOpeningId());
  253. if (pmBidOpening != null) {
  254. PmBidWinningResVo pmBidWinningResVo = new PmBidWinningResVo();
  255. BeanUtils.copyProperties(pmBidWinning, pmBidWinningResVo);
  256. pmBidWinningResVo.setBidWinningName(pmBidOpening.getBidderName());
  257. List<SysFileInfo> fileInfos = getSysFileInfoList(pmBidWinning.getId(), SysFileRefEnum.PM_BID_WINNING_FILE.getType());
  258. if (!ObjectUtils.isEmpty(fileInfos)) {
  259. fileInfosAll.addAll(fileInfos);
  260. }
  261. pmBidWinningResVoList.add(pmBidWinningResVo);
  262. }
  263. }
  264. pmPurchaseExecutionResVo.setPmBidWinningResVoList(pmBidWinningResVoList);
  265. }
  266. }
  267. pmPurchaseExecutionResVo.setCallQuestion(pmDemand.getCallQuestion());
  268. //质疑情况
  269. List<SysFileInfo> callRequestFileInfos = getSysFileInfoList(vo.getDemandId(), SysFileRefEnum.PM_BID_CALL_QEUSTION_FILE.getType());
  270. if (!ObjectUtils.isEmpty(callRequestFileInfos)) {
  271. pmPurchaseExecutionResVo.setCallRequestFileInfos(callRequestFileInfos);
  272. }
  273. //流标情况
  274. LambdaQueryWrapper<PmBidFailure> lambdaQueryWrapper2 = new LambdaQueryWrapper<>();
  275. lambdaQueryWrapper2.eq(PmBidFailure::getDemandId, demandId).orderByDesc(PmBidFailure::getBidFailureTime);
  276. List<PmBidFailure> pmBidFailureList = this.pmBidFailureService.list(lambdaQueryWrapper2);
  277. if (!ObjectUtils.isEmpty(pmBidFailureList)) {
  278. List<PmBidFailureResVo> pmBidFailureResVoList = new ArrayList<>();
  279. for (PmBidFailure pmBidFailure : pmBidFailureList) {
  280. PmBidFailureResVo pmBidFailureResVo = new PmBidFailureResVo();
  281. BeanUtils.copyProperties(pmBidFailure, pmBidFailureResVo);
  282. List<SysFileInfo> fileInfos = getSysFileInfoList(pmBidFailure.getId(), SysFileRefEnum.PM_BID_FAILURE_FILE.getType());
  283. if (!ObjectUtils.isEmpty(fileInfos)) {
  284. fileInfosAll.addAll(fileInfos);
  285. }
  286. pmBidFailureResVoList.add(pmBidFailureResVo);
  287. }
  288. pmPurchaseExecutionResVo.setPmBidFailureResVoList(pmBidFailureResVoList);
  289. }
  290. //中标通知书
  291. List<SysFileInfo> pmBidWinningNotificationFileInfos = getSysFileInfoList(vo.getDemandId(), SysFileRefEnum.PM_BID_WINNING_NOTIFICATION.getType());
  292. if (!ObjectUtils.isEmpty(pmBidWinningNotificationFileInfos)) {
  293. fileInfosAll.addAll(pmBidWinningNotificationFileInfos);
  294. }
  295. pmPurchaseExecutionResVo.setFileInfos(fileInfosAll);
  296. vo.setPmPurchaseExecutionResVo(pmPurchaseExecutionResVo);
  297. } else if ("5".equals(detailType)) { //合同信息
  298. LambdaQueryWrapper<PmContractInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  299. lambdaQueryWrapper.eq(PmContractInfo::getDemandId, demandId);
  300. PmContractInfo pmContractInfo = pmContractInfoService.getOne(lambdaQueryWrapper);
  301. if (pmContractInfo != null) {
  302. PmContractInfoResVo pmContractInfoResVo = new PmContractInfoResVo();
  303. BeanUtils.copyProperties(pmContractInfo, pmContractInfoResVo);
  304. //合同信息文件
  305. List<SysFileInfo> fileInfos = getSysFileInfoList(pmContractInfo.getId(), SysFileRefEnum.PM_CONTRACT_INFO.getType());
  306. if (!ObjectUtils.isEmpty(fileInfos)) {
  307. pmContractInfoResVo.setFileInfos(fileInfos);
  308. }
  309. vo.setPmContractInfoResVo(pmContractInfoResVo);
  310. }
  311. } else if ("6".equals(detailType)) { //建设情况
  312. LambdaQueryWrapper<PmProjectConstruction> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  313. lambdaQueryWrapper.eq(PmProjectConstruction::getDemandId, demandId);
  314. PmProjectConstruction pmProjectConstruction = pmProjectConstructionService.getOne(lambdaQueryWrapper);
  315. if (pmProjectConstruction != null) {
  316. PmProjectConstructionResVo pmProjectConstructionResVo = new PmProjectConstructionResVo();
  317. BeanUtils.copyProperties(pmProjectConstruction, pmProjectConstructionResVo);
  318. //建设情况文件
  319. List<SysFileInfo> fileInfos = getSysFileInfoList(pmProjectConstruction.getId(), SysFileRefEnum.PM_PROJECT_CONSTRUCTION.getType());
  320. if (!ObjectUtils.isEmpty(fileInfos)) {
  321. pmProjectConstructionResVo.setFileInfos(fileInfos);
  322. }
  323. vo.setPmProjectConstructionResVo(pmProjectConstructionResVo);
  324. }
  325. }
  326. return vo;
  327. } else {
  328. return null;
  329. }
  330. }
  331. /**
  332. * 查询采购需求列表
  333. *
  334. * @param pmDemandReqVo
  335. * @return 采购需求
  336. */
  337. @Override
  338. public IPage<PmDemandResVo> selectPmDemandList(PmDemandReqVo pmDemandReqVo, int reqType) {
  339. LambdaQueryWrapper<PmDemand> lw = new LambdaQueryWrapper<>();
  340. // 4 (合同信息管理)、 0(需求单位管理) 、 5(项目建设管理) 需求单位
  341. // 1(需求需求审核) 、2 (任务下达管理) 采购管理部门
  342. // 3(采购执行管理) 采购办
  343. List<PmAuditDeptRef> list = new ArrayList<>();
  344. LambdaQueryWrapper<PmAuditDeptRef> l = new LambdaQueryWrapper<>();
  345. l.eq(PmAuditDeptRef::getDeptId, SecurityUtils.getDeptId());
  346. l.eq(PmAuditDeptRef::getRefType, "2");
  347. list = pmAuditDeptRefService.list(l);
  348. if (Arrays.asList(1, 2, 3).contains(reqType)) {
  349. if (!ObjectUtils.isEmpty(list) && !SecurityUtils.getUserId().equals(Integer.parseInt("1"))) {
  350. lw.in(PmDemand::getDemandId, list.stream().map(PmAuditDeptRef::getRefId).collect(Collectors.toList()));
  351. }
  352. } else {
  353. lw.eq(PmDemand::getPurchaseDeptId, SecurityUtils.getDeptId());
  354. }
  355. if (!StringUtils.isBlank(pmDemandReqVo.getProjectName())) {
  356. lw.like(PmDemand::getProjectName, "%" + pmDemandReqVo.getProjectName() + "%");
  357. }
  358. if (!StringUtils.isBlank(pmDemandReqVo.getPurchaseServices())) {
  359. lw.eq(PmDemand::getPurchaseServices, pmDemandReqVo.getPurchaseServices());
  360. }
  361. if (!ObjectUtils.isEmpty(pmDemandReqVo.getProjectStatus())) {
  362. lw.eq(PmDemand::getProjectStatus, pmDemandReqVo.getProjectStatus());
  363. }
  364. if (!ObjectUtils.isEmpty(pmDemandReqVo.getWarnStatus())) {
  365. lw.eq(PmDemand::getWarnStatus, pmDemandReqVo.getWarnStatus());
  366. }
  367. if (!ObjectUtils.isEmpty(pmDemandReqVo.getIsExcess())) {
  368. lw.eq(PmDemand::getIsExcess, pmDemandReqVo.getIsExcess());
  369. }
  370. if (!StringUtils.isBlank(pmDemandReqVo.getBeginDate())) {
  371. lw.apply("(plan_demand_sub_time >= '" + pmDemandReqVo.getBeginDate() + "' or plan_purchase_finish_time >= '" + pmDemandReqVo.getBeginDate() + "' or plan_deliver_time >= '" + pmDemandReqVo.getBeginDate() + "' )");
  372. }
  373. if (!StringUtils.isBlank(pmDemandReqVo.getEndDate())) {
  374. lw.apply("(plan_demand_sub_time <= '" + pmDemandReqVo.getEndDate() + "' or plan_purchase_finish_time <= '" + pmDemandReqVo.getEndDate() + "' or plan_deliver_time <= '" + pmDemandReqVo.getEndDate() + "' )");
  375. }
  376. if (reqType == 1) { //需求审核单位列表
  377. lw.apply("(project_status = 6 or project_status = 8 )");
  378. } else if (reqType == 2) { //任务下达列表
  379. lw.apply("(project_status = 8 or project_status = 9 )");
  380. } else if (reqType == 3) { //采购执行列表
  381. 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)");
  382. } else if (reqType == 4) { //合同信息列表
  383. lw.apply("(project_status = 15 or project_status = 16 )");
  384. } else if (reqType == 5) { //项目建设列表
  385. lw.apply("(project_status = 16 or project_status = 17 )");
  386. }
  387. lw.last(" order by project_status, plan_demand_sub_time");
  388. IPage<PmDemand> pageRes = this.page(new Page<>(pmDemandReqVo.getPageNum(), pmDemandReqVo.getPageSize()), lw);
  389. IPage<PmDemandResVo> results = new Page<>(pageRes.getCurrent(), pageRes.getSize(), pageRes.getTotal());
  390. if (pageRes.getRecords() != null && pageRes.getRecords().size() > 0) {
  391. List<PmDemandResVo> pmDemandResVos = demandChangeTo(pageRes.getRecords());
  392. for (PmDemandResVo vo : pmDemandResVos) {
  393. if (Arrays.asList(1, 2, 3).contains(reqType)) {
  394. // 根据项目id 和 部门id 和 参数类型 获取 部门级别
  395. List<PmAuditDeptRef> collect = list.stream()
  396. .filter(o -> o.getRefId().equals(vo.getDemandId()))
  397. .collect(Collectors.toList());
  398. if (!ObjectUtils.isEmpty(collect)) {
  399. String deptLevel = collect.get(0).getDeptLevel();
  400. // 根据项目id 和 参数类型 获取 所有审核数据
  401. LambdaQueryWrapper<PmAuditDeptRef> ll = new LambdaQueryWrapper<>();
  402. ll.eq(PmAuditDeptRef::getRefId, vo.getDemandId());
  403. ll.eq(PmAuditDeptRef::getRefType, "2");
  404. List<PmAuditDeptRef> listl = pmAuditDeptRefService.list(l);
  405. // 判断当前用户是否有审核权限
  406. boolean flay = true;
  407. List<PmAuditDeptRef> collect1 = listl.stream()
  408. .filter(pmAuditDeptRef -> pmAuditDeptRef.getRefId().equals(vo.getDemandId()))
  409. .collect(Collectors.toList());
  410. for (PmAuditDeptRef pmAuditDeptRef : collect1) {
  411. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) > 0
  412. && pmAuditDeptRef.getStatus().equals(Integer.parseInt("0"))) {
  413. flay = false;
  414. } else if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) == 0
  415. && pmAuditDeptRef.getStatus().equals(Integer.parseInt("1"))) {
  416. flay = false;
  417. }
  418. }
  419. vo.setFlay(flay);
  420. }
  421. }
  422. }
  423. results.setRecords(pmDemandResVos);
  424. }
  425. return results;
  426. }
  427. /**
  428. * 需求建档
  429. *
  430. * @param vo 采购需求
  431. * @return 结果
  432. */
  433. @Override
  434. @Transactional(rollbackFor = Exception.class)
  435. public boolean bookBuilding(PmBookBuildingReqVo vo) throws Exception {
  436. PmDemand pmDemand = this.getById(vo.getDemandId());
  437. LambdaQueryWrapper<PmBookBuilding> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  438. lambdaQueryWrapper.eq(PmBookBuilding::getDemandId, vo.getDemandId());
  439. PmBookBuilding pmBookBuilding = pmBookBuildingService.getOne(lambdaQueryWrapper);
  440. if (pmBookBuilding != null) {
  441. vo.setId(pmBookBuilding.getId());
  442. BeanUtils.copyProperties(vo, pmBookBuilding);
  443. pmBookBuilding.setUpdateBy(vo.getUpdateBy());
  444. pmBookBuilding.setUpdateTime(new Date());
  445. } else {
  446. pmBookBuilding = new PmBookBuilding();
  447. BeanUtils.copyProperties(vo, pmBookBuilding);
  448. pmBookBuilding.setCreateBy(vo.getUpdateBy());
  449. pmBookBuilding.setCreateTime(new Date());
  450. pmBookBuilding.setUpdateBy(vo.getUpdateBy());
  451. pmBookBuilding.setUpdateTime(pmBookBuilding.getCreateTime());
  452. }
  453. if (pmBookBuildingService.saveOrUpdate(pmBookBuilding)) {
  454. List<SysFileRef> sysFileRefs = vo.getSysFileRefs();
  455. uploadFile(pmBookBuilding.getId(), SysFileRefEnum.PM_BOOK_BUILDING.getType(), sysFileRefs, vo.getUpdateBy());
  456. pmDemand.setProjectStatus(PmProjectStatus.DEMAND_WAIT_COMMIT.getCode());
  457. pmDemand.setUpdateBy(vo.getUpdateBy());
  458. pmDemand.setUpdateTime(DateUtils.getNowDate());
  459. return this.updateById(pmDemand);
  460. } else {
  461. return false;
  462. }
  463. }
  464. private List<SysFileInfo> getSysFileInfoList(Long redId, Integer type) {
  465. HashMap<String, Object> map = new HashMap<>();
  466. map.put("red_id", redId);
  467. map.put("type", type);
  468. List<SysFileRef> fileRefs = sysFileRefService.listByMap(map);
  469. if (!ObjectUtils.isEmpty(fileRefs)) {
  470. List<SysFileInfo> fileInfos = new ArrayList<>();
  471. for (SysFileRef ref : fileRefs) {
  472. SysFileInfo fileInfo = fileService.getById(ref.getFileId());
  473. fileInfos.add(fileInfo);
  474. }
  475. return fileInfos;
  476. } else {
  477. return null;
  478. }
  479. }
  480. /**
  481. * 查看流程图
  482. *
  483. * @param demandId 采购需求主键
  484. * @return 采购需求
  485. */
  486. @Override
  487. public Object viewFlowChart(Long demandId) {
  488. PmDemand pmDemand = this.getById(demandId);
  489. String projectStatus = String.valueOf(pmDemand.getProjectStatus());
  490. String moduleName = null;
  491. if (PmProjectStatus.DEMAND_WAIT_FILL.getCode().equals(projectStatus) || PmProjectStatus.DEMAND_AUDIT_RETURN.getCode().equals(projectStatus)) {
  492. moduleName = "需求填制";
  493. } else if (PmProjectStatus.DEMAND_WAIT_COMMIT.getCode().equals(projectStatus)) {
  494. moduleName = "需求提交";
  495. } else if (PmProjectStatus.DEMAND_WAIT_AUDIT.getCode().equals(projectStatus)) {
  496. moduleName = "需求审核";
  497. } else if (PmProjectStatus.TASK_WAIT_RELEASE.getCode().equals(projectStatus)) {
  498. moduleName = "任务下达";
  499. } else if (PmProjectStatus.WAIT_SELECT_AGENT.getCode().equals(projectStatus)) {
  500. moduleName = "选取代理";
  501. } else if (PmProjectStatus.WAIT_UPLOAD_BID_FILE.getCode().equals(projectStatus)) {
  502. moduleName = "上传招标文件";
  503. } else if (PmProjectStatus.WAIT_ANNOUNCEMENT.getCode().equals(projectStatus)) {
  504. moduleName = "发布公告";
  505. } else if (PmProjectStatus.WAIT_OPEN_BID.getCode().equals(projectStatus)) {
  506. moduleName = "填写专家信息,填写开标信息";
  507. } else if (PmProjectStatus.WAIT_BID_ANNOUNCEMENT.getCode().equals(projectStatus)) {
  508. moduleName = "填写中标信息";
  509. } else if (PmProjectStatus.BIDDING_PUBLICITY.getCode().equals(projectStatus)) {
  510. moduleName = "质疑处理,上传中标通知书";
  511. } else if (PmProjectStatus.CONTRACT_WAIT_FILL.getCode().equals(projectStatus)) {
  512. moduleName = "合同填制";
  513. } else if (PmProjectStatus.UNDER_CONSTRUCTION.getCode().equals(projectStatus)) {
  514. moduleName = "建设文档填制";
  515. } else if (PmProjectStatus.COMPLETION_CONSTRUCTION.getCode().equals(projectStatus)) {
  516. moduleName = "项目归档";
  517. }
  518. return moduleName;
  519. }
  520. @Override
  521. public PmFlowChartResVo getModuleInfo(Long demandId, String moduleName) {
  522. LambdaQueryWrapper<PmFlowChart> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  523. lambdaQueryWrapper.eq(PmFlowChart::getModuleName, moduleName);
  524. PmFlowChart pmFlowChart = iPmFlowChartService.getOne(lambdaQueryWrapper);
  525. if (pmFlowChart == null) {
  526. return null;
  527. }
  528. PmFlowChartResVo vo = new PmFlowChartResVo();
  529. BeanUtils.copyProperties(pmFlowChart, vo);
  530. if ("需求填制".equals(moduleName)) {
  531. List<SysFileInfo> fileInfos = getSysFileInfoList(demandId, SysFileRefEnum.PM_DEMAND.getType());
  532. if (!ObjectUtils.isEmpty(fileInfos)) {
  533. vo.setFileInfos(fileInfos);
  534. }
  535. } else if ("需求提交".equals(moduleName)) {
  536. LambdaQueryWrapper<PmBookBuilding> pmBookBuildingLambdaQueryWrapper = new LambdaQueryWrapper<>();
  537. pmBookBuildingLambdaQueryWrapper.eq(PmBookBuilding::getDemandId, demandId);
  538. PmBookBuilding pmBookBuilding = pmBookBuildingService.getOne(pmBookBuildingLambdaQueryWrapper);
  539. if (pmBookBuilding != null) {
  540. List<SysFileInfo> fileInfos = getSysFileInfoList(pmBookBuilding.getId(), SysFileRefEnum.PM_BOOK_BUILDING.getType());
  541. if (!ObjectUtils.isEmpty(fileInfos)) {
  542. vo.setFileInfos(fileInfos);
  543. }
  544. }
  545. } else if ("需求审核".equals(moduleName)) {
  546. List<SysFileInfo> fileInfos = getSysFileInfoList(demandId, SysFileRefEnum.PM_DEMAND_EXAMINE.getType());
  547. if (!ObjectUtils.isEmpty(fileInfos)) {
  548. vo.setFileInfos(fileInfos);
  549. }
  550. } else if ("任务下达".equals(moduleName)) {
  551. List<SysFileInfo> fileInfos = getSysFileInfoList(demandId, SysFileRefEnum.PM_TAST_RELEASE.getType());
  552. if (!ObjectUtils.isEmpty(fileInfos)) {
  553. vo.setFileInfos(fileInfos);
  554. }
  555. } else if ("选取代理".equals(moduleName)) {
  556. //do nothing
  557. } else if ("上传招标文件".equals(moduleName)) {
  558. List<SysFileInfo> fileInfos = getSysFileInfoList(demandId, SysFileRefEnum.PM_BID_FILE.getType());
  559. if (!ObjectUtils.isEmpty(fileInfos)) {
  560. vo.setFileInfos(fileInfos);
  561. }
  562. } else if ("发布公告".equals(moduleName)) {
  563. LambdaQueryWrapper<PmReleaseAnnouncement> pmReleaseAnnouncementLambdaQueryWrapper = new LambdaQueryWrapper<>();
  564. pmReleaseAnnouncementLambdaQueryWrapper.eq(PmReleaseAnnouncement::getDemandId, demandId);
  565. List<PmReleaseAnnouncement> pmReleaseAnnouncementList = pmReleaseAnnouncementService.list(pmReleaseAnnouncementLambdaQueryWrapper);
  566. if (!ObjectUtils.isEmpty(pmReleaseAnnouncementList)) {
  567. List<SysFileInfo> listAll = new ArrayList<>();
  568. for (PmReleaseAnnouncement pmReleaseAnnouncement : pmReleaseAnnouncementList) {
  569. List<SysFileInfo> fileInfos = getSysFileInfoList(pmReleaseAnnouncement.getId(), SysFileRefEnum.PM_ANNOUNCEMENT_FILE.getType());
  570. if (!ObjectUtils.isEmpty(fileInfos)) {
  571. listAll.addAll(fileInfos);
  572. }
  573. }
  574. if (!ObjectUtils.isEmpty(listAll)) {
  575. vo.setFileInfos(listAll);
  576. }
  577. }
  578. } else if ("填写专家信息".equals(moduleName)) {
  579. //do nothing
  580. } else if ("填写开标信息".equals(moduleName)) {
  581. //do nothing
  582. } else if ("填写中标信息".equals(moduleName)) {
  583. List<SysFileInfo> listAll = new ArrayList<>();
  584. LambdaQueryWrapper<PmBidWinning> pmBidWinningLambdaQueryWrapper = new LambdaQueryWrapper<>();
  585. pmBidWinningLambdaQueryWrapper.eq(PmBidWinning::getDemandId, demandId);
  586. List<PmBidWinning> pmBidWinningList = pmBidWinningService.list(pmBidWinningLambdaQueryWrapper);
  587. if (!ObjectUtils.isEmpty(pmBidWinningList)) {
  588. for (PmBidWinning pmBidWinning : pmBidWinningList) {
  589. List<SysFileInfo> fileInfos = getSysFileInfoList(pmBidWinning.getId(), SysFileRefEnum.PM_BID_WINNING_FILE.getType());
  590. if (!ObjectUtils.isEmpty(fileInfos)) {
  591. listAll.addAll(fileInfos);
  592. }
  593. }
  594. }
  595. LambdaQueryWrapper<PmBidFailure> pmBidFailureLambdaQueryWrapper = new LambdaQueryWrapper<>();
  596. pmBidFailureLambdaQueryWrapper.eq(PmBidFailure::getDemandId, demandId);
  597. List<PmBidFailure> pmBidFailureList = pmBidFailureService.list(pmBidFailureLambdaQueryWrapper);
  598. if (!ObjectUtils.isEmpty(pmBidFailureService)) {
  599. for (PmBidFailure pmBidFailure : pmBidFailureList) {
  600. List<SysFileInfo> fileInfos = getSysFileInfoList(pmBidFailure.getId(), SysFileRefEnum.PM_BID_FAILURE_FILE.getType());
  601. if (!ObjectUtils.isEmpty(fileInfos)) {
  602. listAll.addAll(fileInfos);
  603. }
  604. }
  605. }
  606. if (!ObjectUtils.isEmpty(listAll)) {
  607. vo.setFileInfos(listAll);
  608. }
  609. } else if ("质疑处理".equals(moduleName)) {
  610. List<SysFileInfo> fileInfos = getSysFileInfoList(demandId, SysFileRefEnum.PM_BID_CALL_QEUSTION_FILE.getType());
  611. if (!ObjectUtils.isEmpty(fileInfos)) {
  612. vo.setFileInfos(fileInfos);
  613. }
  614. } else if ("上传中标通知书".equals(moduleName)) {
  615. List<SysFileInfo> fileInfos = getSysFileInfoList(demandId, SysFileRefEnum.PM_BID_WINNING_NOTIFICATION.getType());
  616. if (!ObjectUtils.isEmpty(fileInfos)) {
  617. vo.setFileInfos(fileInfos);
  618. }
  619. } else if ("合同填制".equals(moduleName)) {
  620. LambdaQueryWrapper<PmContractInfo> pmContractInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
  621. pmContractInfoLambdaQueryWrapper.eq(PmContractInfo::getDemandId, demandId);
  622. PmContractInfo pmContractInfo = pmContractInfoService.getOne(pmContractInfoLambdaQueryWrapper);
  623. if (pmContractInfo != null) {
  624. List<SysFileInfo> fileInfos = getSysFileInfoList(pmContractInfo.getId(), SysFileRefEnum.PM_CONTRACT_INFO.getType());
  625. if (!ObjectUtils.isEmpty(fileInfos)) {
  626. vo.setFileInfos(fileInfos);
  627. }
  628. }
  629. } else if ("建设文档填制".equals(moduleName)) {
  630. LambdaQueryWrapper<PmProjectConstruction> pmProjectConstructionLambdaQueryWrapper = new LambdaQueryWrapper<>();
  631. pmProjectConstructionLambdaQueryWrapper.eq(PmProjectConstruction::getDemandId, demandId);
  632. PmProjectConstruction pmProjectConstruction = pmProjectConstructionService.getOne(pmProjectConstructionLambdaQueryWrapper);
  633. if (pmProjectConstruction != null) {
  634. List<SysFileInfo> fileInfos = getSysFileInfoList(pmProjectConstruction.getId(), SysFileRefEnum.PM_PROJECT_CONSTRUCTION.getType());
  635. if (!ObjectUtils.isEmpty(fileInfos)) {
  636. vo.setFileInfos(fileInfos);
  637. }
  638. }
  639. } else if ("项目归档".equals(moduleName)) {
  640. //do nothing
  641. }
  642. return vo;
  643. }
  644. /**
  645. * 提交采购需求
  646. *
  647. * @param pmDemandReqVo
  648. * @return 结果
  649. */
  650. @Override
  651. @Transactional(rollbackFor = Exception.class)
  652. public boolean commit(PmDemandReqVo pmDemandReqVo) {
  653. PmDemand pmDemand = this.getById(pmDemandReqVo.getDemandId());
  654. SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
  655. Long deptId = sysUser.getDeptId();
  656. SysDept sysDept = deptMapper.selectDeptById(deptId);
  657. pmAuditDeptRefService.insertPmAuditDeptRefs(pmDemandReqVo.getDemandId()
  658. , "2"
  659. , deptId
  660. , BigDecimal.valueOf(pmDemand.getEvaluation())
  661. , sysUser.getUserId()
  662. , pmDemand.getProjectType());
  663. PmDemand pmDemandUpdate = new PmDemand();
  664. pmDemandUpdate.setDemandId(pmDemand.getDemandId());
  665. pmDemandUpdate.setProjectStatus(PmProjectStatus.DEMAND_WAIT_AUDIT.getCode());
  666. pmDemandUpdate.setRealDemandCommitTime(DateUtils.getNowDate());
  667. pmDemandUpdate.setUpdateBy(pmDemandReqVo.getUpdateBy());
  668. pmDemandUpdate.setUpdateTime(DateUtils.getNowDate());
  669. return this.updateById(pmDemandUpdate);
  670. }
  671. /**
  672. * 审核采购需求通过
  673. *
  674. * @param pmDemandReqVo
  675. * @return 结果
  676. */
  677. @Override
  678. @Transactional(rollbackFor = Exception.class)
  679. public boolean reviewTo(PmDemandReqVo pmDemandReqVo) {
  680. PmDemand pmDemand = this.getById(pmDemandReqVo.getDemandId());
  681. PmDemand pmDemandUpdate = new PmDemand();
  682. pmDemandUpdate.setDemandId(pmDemand.getDemandId());
  683. SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
  684. Long deptId = sysUser.getDeptId();
  685. SysDept sysDept = deptMapper.selectDeptById(deptId);
  686. String[] ancestors = sysDept.getAncestors().split(",");
  687. String deptLevel = null;
  688. if (ancestors.length == 2) { //C级
  689. deptLevel = "C";
  690. } else if (ancestors.length == 3) { //B级
  691. deptLevel = "B";
  692. } else if (ancestors.length == 4) { //A级
  693. deptLevel = "A";
  694. }
  695. LambdaQueryWrapper<PmAuditDeptRef> lw = new LambdaQueryWrapper();
  696. lw.eq(PmAuditDeptRef::getRefId, pmDemandReqVo.getDemandId());
  697. lw.eq(PmAuditDeptRef::getRefType, "2");
  698. List<PmAuditDeptRef> list = pmAuditDeptRefService.list(lw);
  699. boolean flay = true;
  700. if (!ObjectUtils.isEmpty(list)) {
  701. for (PmAuditDeptRef pmAuditDeptRef : list) {
  702. // 判断 deptLevel 是否还有更高的 且是 待审核的数据
  703. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) > 0
  704. && pmAuditDeptRef.getStatus().equals(Integer.parseInt("0"))) {
  705. flay = false;
  706. }
  707. // 更新当前 deptLevel 级别的审核状态
  708. if (pmAuditDeptRef.getDeptLevel().compareTo(deptLevel) == 0) {
  709. pmAuditDeptRef.setStatus(1);
  710. pmAuditDeptRefService.updateById(pmAuditDeptRef);
  711. }
  712. }
  713. }
  714. if (flay) {
  715. pmDemandUpdate.setProjectStatus(PmProjectStatus.TASK_WAIT_RELEASE.getCode());
  716. }
  717. List<SysFileRef> sysFileRefs = pmDemandReqVo.getSysFileRefs();
  718. uploadFile(pmDemandReqVo.getDemandId(), SysFileRefEnum.PM_DEMAND_EXAMINE.getType(), sysFileRefs, pmDemandReqVo.getUpdateBy());
  719. pmDemandUpdate.setUpdateBy(pmDemandReqVo.getUpdateBy());
  720. pmDemandUpdate.setUpdateTime(DateUtils.getNowDate());
  721. pmDemandUpdate.setAuditTime(DateUtils.getNowDate());
  722. return this.updateById(pmDemandUpdate);
  723. }
  724. /**
  725. * 审核采购需求退回
  726. *
  727. * @param pmDemandReqVo
  728. * @return 结果
  729. */
  730. @Override
  731. @Transactional(rollbackFor = Exception.class)
  732. public boolean reviewReturn(PmDemandReqVo pmDemandReqVo) {
  733. UpdateWrapper<PmDemand> updateWrapper = new UpdateWrapper<>();
  734. updateWrapper.lambda().eq(PmDemand::getDemandId, pmDemandReqVo.getDemandId())
  735. .set(PmDemand::getProjectStatus, PmProjectStatus.DEMAND_AUDIT_RETURN.getCode())
  736. .set(PmDemand::getAdjustReason, pmDemandReqVo.getRefuseReason())
  737. .set(PmDemand::getRealDemandCommitTime, null)
  738. .set(PmDemand::getUpdateBy, pmDemandReqVo.getUpdateBy())
  739. .set(PmDemand::getUpdateTime, DateUtils.getNowDate())
  740. .set(PmDemand::getAuditTime, DateUtils.getNowDate());
  741. LambdaQueryWrapper<PmAuditDeptRef> lw = new LambdaQueryWrapper();
  742. lw.eq(PmAuditDeptRef::getRefId, pmDemandReqVo.getDemandId());
  743. lw.eq(PmAuditDeptRef::getRefType, "2");
  744. pmAuditDeptRefService.remove(lw);
  745. return this.update(updateWrapper);
  746. }
  747. /**
  748. * 下达任务
  749. *
  750. * @param pmDemandReqVo
  751. * @return 结果
  752. */
  753. @Override
  754. @Transactional(rollbackFor = Exception.class)
  755. public boolean releaseTask(PmDemandReqVo pmDemandReqVo) {
  756. PmDemand pmDemand = new PmDemand();
  757. pmDemand.setDemandId(pmDemandReqVo.getDemandId());
  758. pmDemand.setProjectStatus(PmProjectStatus.WAIT_SELECT_AGENT.getCode());
  759. List<SysFileRef> sysFileRefs = pmDemandReqVo.getSysFileRefs();
  760. uploadFile(pmDemandReqVo.getDemandId(), SysFileRefEnum.PM_TAST_RELEASE.getType(), sysFileRefs, pmDemandReqVo.getUpdateBy());
  761. pmDemand.setUpdateBy(pmDemandReqVo.getUpdateBy());
  762. pmDemand.setUpdateTime(DateUtils.getNowDate());
  763. pmDemand.setAuditTime(DateUtils.getNowDate());
  764. return this.updateById(pmDemand);
  765. }
  766. @Override
  767. @Transactional(rollbackFor = Exception.class)
  768. public boolean uploadFile(Long redId, Integer fileType, List<SysFileRef> sysFileRefs, String upateBy) {
  769. if (!ObjectUtils.isEmpty(sysFileRefs)) {
  770. //删除老的
  771. QueryWrapper<SysFileRef> queryWrapper = new QueryWrapper<>();
  772. queryWrapper.lambda().eq(SysFileRef::getRedId, redId)
  773. .eq(SysFileRef::getType, fileType);
  774. List<SysFileRef> sysFileRefList = sysFileRefService.list(queryWrapper);
  775. if (!CollectionUtils.isEmpty(sysFileRefList)) {
  776. sysFileRefService.remove(queryWrapper);
  777. }
  778. //添加新的
  779. for (SysFileRef ref : sysFileRefs) {
  780. if (ref.getFileId() == null) {
  781. continue;
  782. }
  783. ref.setRedId(redId);
  784. ref.setType(fileType);
  785. ref.setCreated(upateBy);
  786. ref.setCreateTime(new Date());
  787. ref.setUpdated(upateBy);
  788. ref.setUpdateTime(ref.getCreateTime());
  789. sysFileRefService.save(ref);
  790. }
  791. return true;
  792. } else {
  793. return false;
  794. }
  795. }
  796. @Override
  797. @Transactional(rollbackFor = Exception.class)
  798. public boolean insertPmReleaseAnnouncement(PmReleaseAnnouncementReqVo pmReleaseAnnouncementReqVo) throws Exception {
  799. PmDemand pmDemand = this.getById(pmReleaseAnnouncementReqVo.getDemandId());
  800. if (ObjectUtils.isEmpty(pmDemand)) {
  801. throw new Exception("参数错误");
  802. }
  803. if (ObjectUtils.isEmpty(pmReleaseAnnouncementReqVo.getSysFileRefs())) {
  804. throw new Exception("上传附件不能为空");
  805. }
  806. PmReleaseAnnouncement pmReleaseAnnouncement = new PmReleaseAnnouncement();
  807. BeanUtils.copyProperties(pmReleaseAnnouncementReqVo, pmReleaseAnnouncement);
  808. if (pmReleaseAnnouncementService.saveOrUpdate(pmReleaseAnnouncement)) {
  809. uploadFile(pmReleaseAnnouncement.getId(), SysFileRefEnum.PM_ANNOUNCEMENT_FILE.getType(), pmReleaseAnnouncementReqVo.getSysFileRefs(), pmReleaseAnnouncementReqVo.getUpdateBy());
  810. PmDemand pmDemandUpdate = new PmDemand();
  811. pmDemandUpdate.setDemandId(pmReleaseAnnouncementReqVo.getDemandId());
  812. pmDemandUpdate.setProjectStatus(PmProjectStatus.WAIT_OPEN_BID.getCode());
  813. pmDemandUpdate.setUpdateTime(pmReleaseAnnouncementReqVo.getUpdateTime());
  814. pmDemandUpdate.setUpdateBy(pmReleaseAnnouncementReqVo.getUpdateBy());
  815. if (this.updateById(pmDemandUpdate)) {
  816. //发布公告生成后,会默认将该数据同步到公告管理和首页中
  817. BaseNotice baseNotice = new BaseNotice();
  818. baseNotice.setName(pmDemand.getProjectName());
  819. baseNotice.setTitle(pmDemand.getProjectName() + "招标公告");
  820. LambdaQueryWrapper<BaseNoticeType> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  821. lambdaQueryWrapper.eq(BaseNoticeType::getName, "招标公告");
  822. BaseNoticeType baseNoticeType = baseNoticeTypeService.getOne(lambdaQueryWrapper);
  823. if (baseNoticeType == null) {
  824. throw new Exception("招标公告 公告类型不存在");
  825. }
  826. baseNotice.setDemandId(pmDemand.getDemandId());
  827. baseNotice.setDeptId(pmDemand.getPurchaseDeptId());
  828. baseNotice.setIsExcess(pmDemand.getIsExcess());
  829. baseNotice.setType(baseNoticeType.getId());
  830. baseNotice.setReleaseTime(pmReleaseAnnouncement.getReleaseTime());
  831. baseNotice.setCreated(pmReleaseAnnouncementReqVo.getCreateBy());
  832. baseNotice.setCreateTime(pmReleaseAnnouncementReqVo.getCreateTime());
  833. baseNotice.setUpdated(pmReleaseAnnouncementReqVo.getUpdateBy());
  834. baseNotice.setUpdateTime(pmReleaseAnnouncementReqVo.getUpdateTime());
  835. return this.baseNoticeService.saveOrUpdate(baseNotice);
  836. } else {
  837. return false;
  838. }
  839. } else {
  840. return false;
  841. }
  842. }
  843. @Override
  844. @Transactional(rollbackFor = Exception.class)
  845. public boolean insertExpertBatch(PmBaseExpertFillReqVo pmBaseExpertFillReqVo) throws Exception {
  846. PmDemand pmDemand = this.getById(pmBaseExpertFillReqVo.getDemandId());
  847. if (ObjectUtils.isEmpty(pmDemand)) {
  848. throw new Exception("参数错误");
  849. }
  850. List<BaseExpert> baseExpertList = pmBaseExpertFillReqVo.getBaseExpertList();
  851. if (ObjectUtils.isEmpty(baseExpertList)) {
  852. throw new Exception("参数错误");
  853. }
  854. Date now = new Date();
  855. for (BaseExpert baseExpert : baseExpertList) {
  856. if (NameListType.BLACK.getCode().equals(baseExpert.getStatus())) {
  857. throw new Exception("该专家(身份证号:" + baseExpert.getIdNumber() + ")属于黑名单");
  858. } else {
  859. if (ObjectUtils.isEmpty(baseExpert.getStatus())) {
  860. baseExpert.setStatus(NameListType.WHITE.getCode());
  861. }
  862. }
  863. if (ObjectUtils.isEmpty(baseExpert.getVarietyPurchase()) || !baseExpert.getVarietyPurchase().contains(pmDemand.getProjectType())) {
  864. throw new Exception("该专家(身份证号:" + baseExpert.getIdNumber() + ")所属采购品种和项目类型不匹配");
  865. }
  866. if (ObjectUtils.isEmpty(baseExpert.getCreated())) {
  867. baseExpert.setCreated(pmBaseExpertFillReqVo.getCreateBy());
  868. baseExpert.setCreateTime(now);
  869. }
  870. if (ObjectUtils.isEmpty(baseExpert.getUpdated())) {
  871. baseExpert.setUpdated(pmBaseExpertFillReqVo.getUpdateBy());
  872. baseExpert.setUpdateTime(now);
  873. }
  874. if (baseExpertService.saveOrUpdate(baseExpert)) {
  875. LambdaQueryWrapper<PmDemandExpertRef> pmDemandExpertRefLambdaQueryWrapper = new LambdaQueryWrapper<>();
  876. pmDemandExpertRefLambdaQueryWrapper.eq(PmDemandExpertRef::getDemandId, pmDemand.getDemandId())
  877. .eq(PmDemandExpertRef::getExpertId, baseExpert.getId().longValue())
  878. .eq(PmDemandExpertRef::getAccessTime, pmBaseExpertFillReqVo.getAccessTime());
  879. PmDemandExpertRef pmDemandExpertRef = pmDemandExpertRefService.getOne(pmDemandExpertRefLambdaQueryWrapper);
  880. if (pmDemandExpertRef == null) {
  881. pmDemandExpertRef = new PmDemandExpertRef();
  882. pmDemandExpertRef.setCreateBy(pmBaseExpertFillReqVo.getCreateBy());
  883. pmDemandExpertRef.setCreateTime(now);
  884. }
  885. pmDemandExpertRef.setDemandId(pmDemand.getDemandId());
  886. pmDemandExpertRef.setExpertId(baseExpert.getId().longValue());
  887. pmDemandExpertRef.setAccessTime(DateUtils.parseDate(pmBaseExpertFillReqVo.getAccessTime()));
  888. pmDemandExpertRef.setUpdateBy(pmBaseExpertFillReqVo.getCreateBy());
  889. pmDemandExpertRef.setUpdateTime(pmDemandExpertRef.getCreateTime());
  890. pmDemandExpertRefService.saveOrUpdate(pmDemandExpertRef);
  891. //专家单位
  892. if (StringUtils.isNotNull(baseExpert.getUnitInformation())) {
  893. List<BaseUnitInformation> baseUnitInformationList = baseExpertMapper.selectByUnitInformation(baseExpert.getUnitInformation());
  894. if (baseUnitInformationList.size() <= 0) {
  895. BaseUnitInformation baseUnitInformation = new BaseUnitInformation();
  896. baseUnitInformation.setUnitName(baseExpert.getUnitInformation());
  897. baseUnitInformation.setCreated(baseExpert.getExpertName());
  898. baseUnitInformation.setCreateTime(new Date());
  899. Integer i = baseExpertMapper.insertBaseUnitInformation(baseUnitInformation);
  900. }
  901. }
  902. }
  903. }
  904. return true;
  905. }
  906. @Override
  907. @Transactional(rollbackFor = Exception.class)
  908. public boolean extractExpertBatch(PmBaseExpertExtractReqVo pmBaseExpertExtractReqVo) throws Exception {
  909. Integer technicalExpertNumber = pmBaseExpertExtractReqVo.getTechnicalExpertNumber();
  910. if (technicalExpertNumber == null) {
  911. technicalExpertNumber = 0;
  912. }
  913. Integer economicExpertNumber = pmBaseExpertExtractReqVo.getEconomicExpertNumber();
  914. if (economicExpertNumber == null) {
  915. economicExpertNumber = 0;
  916. }
  917. Integer legalAffairsExpertNumber = pmBaseExpertExtractReqVo.getLegalAffairsExpertNumber();
  918. if (legalAffairsExpertNumber == null) {
  919. legalAffairsExpertNumber = 0;
  920. }
  921. Integer spareExpertNumber = pmBaseExpertExtractReqVo.getSpareExpertNumber();
  922. if (spareExpertNumber == null) {
  923. spareExpertNumber = 0;
  924. }
  925. String professional = pmBaseExpertExtractReqVo.getProfessional();
  926. if (spareExpertNumber > 0 && ObjectUtils.isEmpty(professional)) {
  927. throw new Exception("抽取备用专家必须选择专家专业");
  928. }
  929. PmDemand pmDemand = this.getById(pmBaseExpertExtractReqVo.getDemandId());
  930. if (ObjectUtils.isEmpty(pmDemand)) {
  931. throw new Exception("参数错误");
  932. }
  933. String needAvoidUnit = pmBaseExpertExtractReqVo.getNeedAvoidUnit();
  934. List<String> needAvoidUnitList = null;
  935. if (!ObjectUtils.isEmpty(needAvoidUnit)) {
  936. String[] arr = needAvoidUnit.split(",");
  937. needAvoidUnitList = Arrays.asList(arr);
  938. }
  939. String localArea = pmBaseExpertExtractReqVo.getLocalArea();
  940. List<String> sysRegionCodeList = new ArrayList<>();
  941. if (!ObjectUtils.isEmpty(localArea)) {
  942. if (!StringUtils.isNumeric(localArea)) {
  943. throw new Exception("地域必须传数字代码");
  944. }
  945. sysRegionCodeList.add(localArea);
  946. //找到该地域code对应的子列表
  947. List<SysRegionVO> sysRegionVOList = iSysRegionService.findChildDivisions(localArea);
  948. if (!ObjectUtils.isEmpty(sysRegionVOList)) {
  949. for (SysRegionVO vo : sysRegionVOList) {
  950. sysRegionCodeList.add(vo.getCode());
  951. }
  952. }
  953. }
  954. //从专家库中查询符合项目类型的以及是白名单的全部列表
  955. LambdaQueryWrapper<BaseExpert> lw = new LambdaQueryWrapper<>();
  956. lw.eq(BaseExpert::getVarietyPurchase, pmDemand.getProjectType())
  957. .eq(BaseExpert::getStatus, NameListType.WHITE.getCode())
  958. .notIn(!ObjectUtils.isEmpty(needAvoidUnitList), BaseExpert::getUnitInformation, needAvoidUnitList)
  959. .in(!ObjectUtils.isEmpty(sysRegionCodeList), BaseExpert::getLocalArea, sysRegionCodeList);
  960. List<BaseExpert> baseExpertList = baseExpertService.list(lw);
  961. if (ObjectUtils.isEmpty(baseExpertList)) {
  962. throw new Exception("没抽取到符合条件的专家");
  963. }
  964. //从列表中挑出来各个类型的子列表
  965. List<BaseExpert> technicalExpertList = new ArrayList<>();
  966. List<BaseExpert> economicExpertList = new ArrayList<>();
  967. List<BaseExpert> legalAffairsExpertList = new ArrayList<>();
  968. List<BaseExpert> spareExpertList = new ArrayList<>();
  969. for (BaseExpert baseExpert : baseExpertList) {
  970. if (technicalExpertNumber > 0) {
  971. if (baseExpert.getExpertType().contains(ExpertType.TECHNICAL_EXPERT.getCode())) {
  972. technicalExpertList.add(baseExpert);
  973. }
  974. }
  975. if (economicExpertNumber > 0) {
  976. if (baseExpert.getExpertType().contains(ExpertType.ECONOMIC_EXPERT.getCode())) {
  977. economicExpertList.add(baseExpert);
  978. }
  979. }
  980. if (legalAffairsExpertNumber > 0) {
  981. if (baseExpert.getExpertType().contains(ExpertType.LEGALAFFAIRS_EXPERT.getCode())) {
  982. legalAffairsExpertList.add(baseExpert);
  983. }
  984. }
  985. if (spareExpertNumber > 0) {
  986. String[] arr = professional.split(",");
  987. List<String> professionalList = Arrays.asList(arr);
  988. String majorType = baseExpert.getMajorType();
  989. if (!ObjectUtils.isEmpty(majorType)) {
  990. String[] arr2 = majorType.split(",");
  991. List<String> majorTypeList = Arrays.asList(arr2);
  992. if (hasIntersection(professionalList, majorTypeList)) {
  993. spareExpertList.add(baseExpert);
  994. }
  995. }
  996. }
  997. }
  998. //从子列表中随机抽取符合数据量的
  999. List<BaseExpert> alltExpertList = new ArrayList<>();
  1000. if (!ObjectUtils.isEmpty(technicalExpertList)) {
  1001. alltExpertList.addAll(RandomUtil.getRandomList(technicalExpertList, technicalExpertNumber));
  1002. }
  1003. if (!ObjectUtils.isEmpty(economicExpertList)) {
  1004. alltExpertList.addAll(RandomUtil.getRandomList(economicExpertList, economicExpertNumber));
  1005. }
  1006. if (!ObjectUtils.isEmpty(legalAffairsExpertList)) {
  1007. alltExpertList.addAll(RandomUtil.getRandomList(legalAffairsExpertList, legalAffairsExpertNumber));
  1008. }
  1009. if (!ObjectUtils.isEmpty(spareExpertList)) {
  1010. alltExpertList.addAll(RandomUtil.getRandomList(spareExpertList, spareExpertNumber));
  1011. }
  1012. if (ObjectUtils.isEmpty(alltExpertList)) {
  1013. throw new Exception("没抽取到符合条件的专家");
  1014. } else {
  1015. List<PmDemandExpertRef> pmDemandExpertRefList = new ArrayList<>();
  1016. for (BaseExpert baseExpert : alltExpertList) {
  1017. LambdaQueryWrapper<PmDemandExpertRef> baseExpertLambdaQueryWrapper = new LambdaQueryWrapper<>();
  1018. baseExpertLambdaQueryWrapper.eq(PmDemandExpertRef::getExpertId, baseExpert.getId().longValue())
  1019. .eq(PmDemandExpertRef::getDemandId, pmDemand.getDemandId())
  1020. .eq(PmDemandExpertRef::getAccessTime, pmBaseExpertExtractReqVo.getAccessTime());
  1021. PmDemandExpertRef pmDemandExpertRef = pmDemandExpertRefService.getOne(baseExpertLambdaQueryWrapper);
  1022. if (pmDemandExpertRef == null) {
  1023. pmDemandExpertRef = new PmDemandExpertRef();
  1024. pmDemandExpertRef.setCreateBy(pmBaseExpertExtractReqVo.getCreateBy());
  1025. pmDemandExpertRef.setCreateTime(new Date());
  1026. }
  1027. pmDemandExpertRef.setDemandId(pmDemand.getDemandId());
  1028. pmDemandExpertRef.setExpertId(baseExpert.getId().longValue());
  1029. pmDemandExpertRef.setAccessTime(DateUtils.parseDate(pmBaseExpertExtractReqVo.getAccessTime()));
  1030. pmDemandExpertRef.setUpdateBy(pmBaseExpertExtractReqVo.getCreateBy());
  1031. pmDemandExpertRef.setUpdateTime(pmDemandExpertRef.getCreateTime());
  1032. pmDemandExpertRefList.add(pmDemandExpertRef);
  1033. }
  1034. return pmDemandExpertRefService.saveOrUpdateBatch(pmDemandExpertRefList);
  1035. }
  1036. }
  1037. //二个列表是否有交集
  1038. private boolean hasIntersection(List<String> professionalList, List<String> majorTypeList) {
  1039. for (String professiona : professionalList) {
  1040. for (String majorType : majorTypeList) {
  1041. if (professiona.equals(majorType)) {
  1042. return true;
  1043. }
  1044. }
  1045. }
  1046. return false;
  1047. }
  1048. @Override
  1049. @Transactional(rollbackFor = Exception.class)
  1050. public boolean insertBidOpeningBatch(PmBidOpeningFillReqVo pmBidOpeningFillReqVo) throws Exception {
  1051. PmDemand pmDemand = this.getById(pmBidOpeningFillReqVo.getDemandId());
  1052. if (ObjectUtils.isEmpty(pmDemand)) {
  1053. throw new Exception("参数错误");
  1054. }
  1055. //从发布公告里获取开标时间
  1056. LambdaQueryWrapper<PmReleaseAnnouncement> lw = new LambdaQueryWrapper<>();
  1057. lw.eq(PmReleaseAnnouncement::getDemandId, pmDemand.getDemandId()).orderByDesc(PmReleaseAnnouncement::getReleaseTime)
  1058. .last(" limit 1 ");
  1059. PmReleaseAnnouncement pmReleaseAnnouncement = this.pmReleaseAnnouncementService.getOne(lw);
  1060. if (pmReleaseAnnouncement == null) {
  1061. throw new Exception("发布公告不存在");
  1062. }
  1063. Date tenderOpenTime = pmReleaseAnnouncement.getTenderOpenTime();
  1064. Date now = new Date();
  1065. List<PmBidOpening> pmBidOpeningList = pmBidOpeningFillReqVo.getPmBidOpeningList();
  1066. for (PmBidOpening pmBidOpening : pmBidOpeningList) {
  1067. if (ObjectUtils.isEmpty(pmBidOpening.getBidderName())) {
  1068. throw new Exception("投标人名称不能为空");
  1069. }
  1070. if (ObjectUtils.isEmpty(pmBidOpening.getScore())) {
  1071. throw new Exception("分数不能为空");
  1072. }
  1073. pmBidOpening.setOpenBidTime(tenderOpenTime);
  1074. pmBidOpening.setDemandId(pmBidOpeningFillReqVo.getDemandId());
  1075. pmBidOpening.setCreateBy(pmBidOpeningFillReqVo.getCreateBy());
  1076. pmBidOpening.setCreateTime(now);
  1077. pmBidOpening.setUpdateBy(pmBidOpeningFillReqVo.getUpdateBy());
  1078. pmBidOpening.setUpdateTime(now);
  1079. }
  1080. if (pmBidOpeningService.saveOrUpdateBatch(pmBidOpeningList)) {
  1081. PmDemand pmDemandUpdate = new PmDemand();
  1082. pmDemandUpdate.setDemandId(pmDemand.getDemandId());
  1083. pmDemandUpdate.setProjectStatus(PmProjectStatus.WAIT_BID_ANNOUNCEMENT.getCode());
  1084. pmDemandUpdate.setUpdateTime(now);
  1085. pmDemandUpdate.setUpdateBy(pmBidOpeningFillReqVo.getUpdateBy());
  1086. return this.updateById(pmDemandUpdate);
  1087. } else {
  1088. return false;
  1089. }
  1090. }
  1091. /**
  1092. * 填写中标
  1093. *
  1094. * @param pmBidWinningReqVo
  1095. * @return
  1096. * @throws Exception
  1097. */
  1098. @Override
  1099. @Transactional(rollbackFor = Exception.class)
  1100. public boolean insertPmBidWinning(PmBidWinningReqVo pmBidWinningReqVo) throws Exception {
  1101. List<Long> pmBidOpeningIdList = pmBidWinningReqVo.getPmBidOpeningIdList();
  1102. if (ObjectUtils.isEmpty(pmBidWinningReqVo.getBidWinningAmount())) {
  1103. throw new Exception("中标金额不能为空");
  1104. }
  1105. if (ObjectUtils.isEmpty(pmBidOpeningIdList)) {
  1106. throw new Exception("中标单位信息列表不能为空");
  1107. }
  1108. if (ObjectUtils.isEmpty(pmBidWinningReqVo.getSysFileRefs())) {
  1109. throw new Exception("上传附件不能为空");
  1110. }
  1111. PmBidWinning pmBidWinning = new PmBidWinning();
  1112. BeanUtils.copyProperties(pmBidWinningReqVo, pmBidWinning);
  1113. //修改老的中标信息状态
  1114. if (ObjectUtils.isEmpty(pmBidWinningReqVo.getId())) { //属于新增
  1115. LambdaQueryWrapper<PmBidWinning> pmBidWinningLambdaQueryWrapper = new LambdaQueryWrapper<>();
  1116. pmBidWinningLambdaQueryWrapper.eq(PmBidWinning::getDemandId, pmBidWinningReqVo.getDemandId())
  1117. .eq(PmBidWinning::getStatus, BidWinningStatus.NORMAL.getCode());
  1118. List<PmBidWinning> pmBidWinninglist = pmBidWinningService.list(pmBidWinningLambdaQueryWrapper);
  1119. if (!ObjectUtils.isEmpty(pmBidWinninglist)) {
  1120. for (PmBidWinning item : pmBidWinninglist) {
  1121. UpdateWrapper<PmBidWinning> updateWrapper1 = new UpdateWrapper<>();
  1122. updateWrapper1.lambda().set(PmBidWinning::getStatus, BidWinningStatus.BE_REPLACED.getCode())
  1123. .eq(PmBidWinning::getId, item.getId());
  1124. pmBidWinningService.update(updateWrapper1);
  1125. UpdateWrapper<PmBidWinningOpeningRef> updateWrapper2 = new UpdateWrapper<>();
  1126. updateWrapper2.lambda().set(PmBidWinningOpeningRef::getStatus, BidWinningStatus.BE_REPLACED.getCode())
  1127. .eq(PmBidWinningOpeningRef::getWinningId, item.getId())
  1128. .eq(PmBidWinningOpeningRef::getStatus, BidWinningStatus.NORMAL.getCode());
  1129. pmBidWinningOpeningRefService.update(updateWrapper2);
  1130. }
  1131. }
  1132. }
  1133. if (pmBidWinningService.saveOrUpdate(pmBidWinning)) {
  1134. List<PmBidWinningOpeningRef> pmBidWinningOpeningRefList = new ArrayList<>();
  1135. for (Long pmBidOpeningId : pmBidOpeningIdList) {
  1136. LambdaQueryWrapper<PmBidWinningOpeningRef> pmBidWinningOpeningRefLambdaQueryWrapper = new LambdaQueryWrapper<>();
  1137. pmBidWinningOpeningRefLambdaQueryWrapper.eq(PmBidWinningOpeningRef::getOpeningId, pmBidOpeningId)
  1138. .eq(PmBidWinningOpeningRef::getWinningId, pmBidWinning.getId());
  1139. PmBidWinningOpeningRef pmBidWinningOpeningRef = pmBidWinningOpeningRefService.getOne(pmBidWinningOpeningRefLambdaQueryWrapper);
  1140. if (pmBidWinningOpeningRef == null) {
  1141. pmBidWinningOpeningRef = new PmBidWinningOpeningRef();
  1142. pmBidWinningOpeningRef.setCreateBy(pmBidWinningReqVo.getCreateBy());
  1143. pmBidWinningOpeningRef.setCreateTime(pmBidWinningReqVo.getCreateTime());
  1144. }
  1145. pmBidWinningOpeningRef.setOpeningId(pmBidOpeningId);
  1146. pmBidWinningOpeningRef.setWinningId(pmBidWinning.getId());
  1147. pmBidWinningOpeningRef.setUpdateBy(pmBidWinningReqVo.getUpdateBy());
  1148. pmBidWinningOpeningRef.setUpdateTime(pmBidWinningReqVo.getUpdateTime());
  1149. pmBidWinningOpeningRefList.add(pmBidWinningOpeningRef);
  1150. }
  1151. if (pmBidWinningOpeningRefService.saveOrUpdateBatch(pmBidWinningOpeningRefList)) {
  1152. uploadFile(pmBidWinning.getId(), SysFileRefEnum.PM_BID_WINNING_FILE.getType(), pmBidWinningReqVo.getSysFileRefs(), pmBidWinningReqVo.getUpdateBy());
  1153. //发布公告生成后,会默认将该数据同步到公告管理和首页中
  1154. PmDemand pmDemand = this.getById(pmBidWinningReqVo.getDemandId());
  1155. BaseNotice baseNotice = new BaseNotice();
  1156. baseNotice.setName(pmDemand.getProjectName());
  1157. baseNotice.setTitle(pmDemand.getProjectName() + "中标公告");
  1158. LambdaQueryWrapper<BaseNoticeType> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  1159. lambdaQueryWrapper.eq(BaseNoticeType::getName, "中标公告");
  1160. BaseNoticeType baseNoticeType = baseNoticeTypeService.getOne(lambdaQueryWrapper);
  1161. if (baseNoticeType == null) {
  1162. throw new Exception("中标公告 公告类型不存在");
  1163. }
  1164. baseNotice.setDemandId(pmDemand.getDemandId());
  1165. baseNotice.setDeptId(pmDemand.getPurchaseDeptId());
  1166. baseNotice.setIsExcess(pmDemand.getIsExcess());
  1167. baseNotice.setType(baseNoticeType.getId());
  1168. baseNotice.setReleaseTime(pmBidWinningReqVo.getBidAnnouncementTime());
  1169. baseNotice.setCreated(pmBidWinningReqVo.getCreateBy());
  1170. baseNotice.setCreateTime(pmBidWinningReqVo.getCreateTime());
  1171. baseNotice.setUpdated(pmBidWinningReqVo.getUpdateBy());
  1172. baseNotice.setUpdateTime(pmBidWinningReqVo.getUpdateTime());
  1173. this.baseNoticeService.saveOrUpdate(baseNotice);
  1174. PmDemand pmDemandUpdate = new PmDemand();
  1175. pmDemandUpdate.setDemandId(pmBidWinningReqVo.getDemandId());
  1176. pmDemandUpdate.setProjectStatus(PmProjectStatus.BIDDING_PUBLICITY.getCode());
  1177. pmDemandUpdate.setUpdateTime(pmBidWinningReqVo.getUpdateTime());
  1178. pmDemandUpdate.setUpdateBy(pmBidWinningReqVo.getUpdateBy());
  1179. return this.updateById(pmDemandUpdate);
  1180. } else {
  1181. return false;
  1182. }
  1183. } else {
  1184. return false;
  1185. }
  1186. }
  1187. @Override
  1188. @Transactional(rollbackFor = Exception.class)
  1189. public boolean updatePmBidWinning(PmBidWinningReqVo pmBidWinningReqVo) throws Exception {
  1190. List<Long> pmBidOpeningIdList = pmBidWinningReqVo.getPmBidOpeningIdList();
  1191. if (ObjectUtils.isEmpty(pmBidOpeningIdList)) {
  1192. throw new Exception("中标单位信息列表不能为空");
  1193. }
  1194. if (ObjectUtils.isEmpty(pmBidWinningReqVo.getBidWinningAmount())) {
  1195. throw new Exception("中标金额不能为空");
  1196. }
  1197. if (ObjectUtils.isEmpty(pmBidWinningReqVo.getSysFileRefs())) {
  1198. throw new Exception("上传附件不能为空");
  1199. }
  1200. LambdaQueryWrapper<PmBidWinning> lw = new LambdaQueryWrapper<>();
  1201. lw.eq(PmBidWinning::getDemandId, pmBidWinningReqVo.getDemandId()).eq(PmBidWinning::getStatus, BidWinningStatus.NORMAL.getCode());
  1202. List<PmBidWinning> pmBidWinninglist = pmBidWinningService.list(lw);
  1203. if (ObjectUtils.isEmpty(pmBidWinninglist)) {
  1204. throw new Exception("原中标信息不存在");
  1205. }
  1206. //修改老的状态
  1207. for (PmBidWinning item : pmBidWinninglist) {
  1208. UpdateWrapper<PmBidWinning> updateWrapper1 = new UpdateWrapper<>();
  1209. updateWrapper1.lambda().set(PmBidWinning::getStatus, BidWinningStatus.BE_REPLACED.getCode())
  1210. .eq(PmBidWinning::getId, item.getId());
  1211. pmBidWinningService.update(updateWrapper1);
  1212. UpdateWrapper<PmBidWinningOpeningRef> updateWrapper2 = new UpdateWrapper<>();
  1213. updateWrapper2.lambda().set(PmBidWinningOpeningRef::getStatus, BidWinningStatus.BE_REPLACED.getCode())
  1214. .eq(PmBidWinningOpeningRef::getWinningId, item.getId())
  1215. .eq(PmBidWinningOpeningRef::getStatus, BidWinningStatus.NORMAL.getCode());
  1216. pmBidWinningOpeningRefService.update(updateWrapper2);
  1217. }
  1218. //新增
  1219. PmBidWinning pmBidWinning = new PmBidWinning();
  1220. BeanUtils.copyProperties(pmBidWinninglist.get(0), pmBidWinning);
  1221. pmBidWinning.setId(null);
  1222. pmBidWinning.setBidWinningAmount(pmBidWinningReqVo.getBidWinningAmount());
  1223. pmBidWinning.setStatus(BidWinningStatus.NORMAL.getCode());
  1224. pmBidWinning.setUpdateBy(pmBidWinningReqVo.getUpdateBy());
  1225. pmBidWinning.setUpdateTime(pmBidWinningReqVo.getUpdateTime());
  1226. if (pmBidWinningService.save(pmBidWinning)) {
  1227. List<PmBidWinningOpeningRef> pmBidWinningOpeningRefList = new ArrayList<>();
  1228. for (Long pmBidOpeningId : pmBidOpeningIdList) {
  1229. PmBidWinningOpeningRef pmBidWinningOpeningRef = new PmBidWinningOpeningRef();
  1230. pmBidWinningOpeningRef.setOpeningId(pmBidOpeningId);
  1231. pmBidWinningOpeningRef.setWinningId(pmBidWinning.getId());
  1232. pmBidWinningOpeningRef.setStatus(BidWinningStatus.NORMAL.getCode());
  1233. pmBidWinningOpeningRef.setCreateBy(pmBidWinningReqVo.getCreateBy());
  1234. pmBidWinningOpeningRef.setCreateTime(pmBidWinningReqVo.getCreateTime());
  1235. pmBidWinningOpeningRef.setUpdateBy(pmBidWinningReqVo.getUpdateBy());
  1236. pmBidWinningOpeningRef.setUpdateTime(pmBidWinningReqVo.getUpdateTime());
  1237. pmBidWinningOpeningRefList.add(pmBidWinningOpeningRef);
  1238. }
  1239. LambdaQueryWrapper<SysFileRef> sysFileRefLambdaQueryWrapper = new LambdaQueryWrapper<>();
  1240. sysFileRefLambdaQueryWrapper.eq(SysFileRef::getType, SysFileRefEnum.PM_BID_WINNING_FILE.getType())
  1241. .eq(SysFileRef::getRedId, pmBidWinninglist.get(0));
  1242. List<SysFileRef> sysFileRefs = sysFileRefService.list(sysFileRefLambdaQueryWrapper);
  1243. uploadFile(pmBidWinning.getId(), SysFileRefEnum.PM_BID_WINNING_FILE.getType(), sysFileRefs, pmBidWinningReqVo.getUpdateBy());
  1244. return pmBidWinningOpeningRefService.saveBatch(pmBidWinningOpeningRefList);
  1245. } else {
  1246. return false;
  1247. }
  1248. }
  1249. /**
  1250. * 流标
  1251. *
  1252. * @param pmBidFailureReqVo
  1253. * @return
  1254. * @throws Exception
  1255. */
  1256. @Override
  1257. @Transactional(rollbackFor = Exception.class)
  1258. public boolean insertPmBidFailure(PmBidFailureReqVo pmBidFailureReqVo) throws Exception {
  1259. PmBidFailure pmBidFailure = new PmBidFailure();
  1260. BeanUtils.copyProperties(pmBidFailureReqVo, pmBidFailure);
  1261. if (pmBidFailureService.saveOrUpdate(pmBidFailure)) {
  1262. //把中标信息修改状态
  1263. LambdaQueryWrapper<PmBidWinning> lw = new LambdaQueryWrapper<>();
  1264. lw.eq(PmBidWinning::getDemandId, pmBidFailureReqVo.getDemandId()).eq(PmBidWinning::getStatus, BidWinningStatus.NORMAL.getCode());
  1265. List<PmBidWinning> pmBidWinninglist = pmBidWinningService.list(lw);
  1266. if (!ObjectUtils.isEmpty(pmBidWinninglist)) {
  1267. for (PmBidWinning item : pmBidWinninglist) {
  1268. UpdateWrapper<PmBidWinning> updateWrapper1 = new UpdateWrapper<>();
  1269. updateWrapper1.lambda().set(PmBidWinning::getStatus, BidWinningStatus.BE_BID_FAILURE.getCode())
  1270. .eq(PmBidWinning::getId, item.getId());
  1271. pmBidWinningService.update(updateWrapper1);
  1272. UpdateWrapper<PmBidWinningOpeningRef> updateWrapper2 = new UpdateWrapper<>();
  1273. updateWrapper2.lambda().set(PmBidWinningOpeningRef::getStatus, BidWinningStatus.BE_BID_FAILURE.getCode())
  1274. .eq(PmBidWinningOpeningRef::getWinningId, item.getId())
  1275. .eq(PmBidWinningOpeningRef::getStatus, BidWinningStatus.NORMAL.getCode());
  1276. pmBidWinningOpeningRefService.update(updateWrapper2);
  1277. }
  1278. }
  1279. uploadFile(pmBidFailure.getId(), SysFileRefEnum.PM_BID_FAILURE_FILE.getType(), pmBidFailureReqVo.getSysFileRefs(), pmBidFailureReqVo.getUpdateBy());
  1280. //发布公告生成后,会默认将该数据同步到公告管理和首页中
  1281. PmDemand pmDemand = this.getById(pmBidFailureReqVo.getDemandId());
  1282. BaseNotice baseNotice = new BaseNotice();
  1283. baseNotice.setName(pmDemand.getProjectName());
  1284. baseNotice.setTitle(pmDemand.getProjectName() + "流标公告");
  1285. LambdaQueryWrapper<BaseNoticeType> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  1286. lambdaQueryWrapper.eq(BaseNoticeType::getName, "流标公告");
  1287. BaseNoticeType baseNoticeType = baseNoticeTypeService.getOne(lambdaQueryWrapper);
  1288. if (baseNoticeType == null) {
  1289. throw new Exception("流标公告 公告类型不存在");
  1290. }
  1291. baseNotice.setDemandId(pmDemand.getDemandId());
  1292. baseNotice.setDeptId(pmDemand.getPurchaseDeptId());
  1293. baseNotice.setIsExcess(pmDemand.getIsExcess());
  1294. baseNotice.setType(baseNoticeType.getId());
  1295. baseNotice.setReleaseTime(pmBidFailureReqVo.getBidFailureTime());
  1296. baseNotice.setCreated(pmBidFailureReqVo.getCreateBy());
  1297. baseNotice.setCreateTime(pmBidFailureReqVo.getCreateTime());
  1298. baseNotice.setUpdated(pmBidFailureReqVo.getUpdateBy());
  1299. baseNotice.setUpdateTime(pmBidFailureReqVo.getUpdateTime());
  1300. this.baseNoticeService.saveOrUpdate(baseNotice);
  1301. PmDemand pmDemandUpdate = new PmDemand();
  1302. pmDemandUpdate.setDemandId(pmBidFailureReqVo.getDemandId());
  1303. pmDemandUpdate.setProjectStatus(PmProjectStatus.WAIT_ANNOUNCEMENT.getCode());
  1304. pmDemandUpdate.setUpdateTime(pmBidFailureReqVo.getUpdateTime());
  1305. pmDemandUpdate.setUpdateBy(pmBidFailureReqVo.getUpdateBy());
  1306. return this.updateById(pmDemandUpdate);
  1307. } else {
  1308. return false;
  1309. }
  1310. }
  1311. @Override
  1312. @Transactional(rollbackFor = Exception.class)
  1313. public boolean insertContractInfo(PmContractInfoReqVo pmContractInfoReqVo) throws Exception {
  1314. Long demandId = pmContractInfoReqVo.getDemandId();
  1315. if (ObjectUtils.isEmpty(demandId)) {
  1316. throw new Exception("采购需求ID不能为空");
  1317. }
  1318. PmDemand pmDemand = this.getById(demandId);
  1319. if (ObjectUtils.isEmpty(pmDemand)) {
  1320. throw new Exception("采购需求ID错误");
  1321. }
  1322. List<SysFileRef> sysFileRefs = pmContractInfoReqVo.getSysFileRefs();
  1323. if (ObjectUtils.isEmpty(sysFileRefs)) {
  1324. throw new Exception("上传附件不能为空");
  1325. }
  1326. LambdaQueryWrapper<PmContractInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  1327. lambdaQueryWrapper.eq(PmContractInfo::getDemandId, demandId);
  1328. PmContractInfo pmContractInfo = pmContractInfoService.getOne(lambdaQueryWrapper);
  1329. if (pmContractInfo != null) {
  1330. pmContractInfoReqVo.setId(pmContractInfo.getId());
  1331. BeanUtils.copyProperties(pmContractInfoReqVo, pmContractInfo);
  1332. pmContractInfo.setUpdateTime(pmContractInfoReqVo.getUpdateTime());
  1333. pmContractInfo.setUpdateBy(pmContractInfoReqVo.getUpdateBy());
  1334. } else {
  1335. pmContractInfo = new PmContractInfo();
  1336. BeanUtils.copyProperties(pmContractInfoReqVo, pmContractInfo);
  1337. pmContractInfo.setCreateBy(pmContractInfoReqVo.getCreateBy());
  1338. pmContractInfo.setCreateTime(pmContractInfoReqVo.getCreateTime());
  1339. pmContractInfo.setUpdateTime(pmContractInfoReqVo.getUpdateTime());
  1340. pmContractInfo.setUpdateBy(pmContractInfoReqVo.getUpdateBy());
  1341. }
  1342. if (pmContractInfoService.saveOrUpdate(pmContractInfo)) {
  1343. this.uploadFile(pmContractInfo.getId(), SysFileRefEnum.PM_CONTRACT_INFO.getType(), sysFileRefs, pmContractInfoReqVo.getUpdateBy());
  1344. PmDemand pmDemandUpdate = new PmDemand();
  1345. pmDemandUpdate.setDemandId(demandId);
  1346. pmDemandUpdate.setProjectStatus(PmProjectStatus.UNDER_CONSTRUCTION.getCode());
  1347. pmDemandUpdate.setUpdateTime(pmContractInfoReqVo.getUpdateTime());
  1348. pmDemandUpdate.setUpdateBy(pmContractInfoReqVo.getUpdateBy());
  1349. return this.updateById(pmDemandUpdate);
  1350. } else {
  1351. return false;
  1352. }
  1353. }
  1354. @Override
  1355. @Transactional(rollbackFor = Exception.class)
  1356. public boolean insertProjectConstruction(PmProjectConstructionReqVo pmProjectConstructionReqVo) throws Exception {
  1357. Long demandId = pmProjectConstructionReqVo.getDemandId();
  1358. if (ObjectUtils.isEmpty(demandId)) {
  1359. throw new Exception("采购需求ID不能为空");
  1360. }
  1361. PmDemand pmDemand = this.getById(demandId);
  1362. if (ObjectUtils.isEmpty(pmDemand)) {
  1363. throw new Exception("采购需求ID错误");
  1364. }
  1365. List<SysFileRef> sysFileRefs = pmProjectConstructionReqVo.getSysFileRefs();
  1366. if (ObjectUtils.isEmpty(sysFileRefs)) {
  1367. throw new Exception("上传附件不能为空");
  1368. }
  1369. LambdaQueryWrapper<PmProjectConstruction> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  1370. lambdaQueryWrapper.eq(PmProjectConstruction::getDemandId, demandId);
  1371. PmProjectConstruction pmProjectConstruction = pmProjectConstructionService.getOne(lambdaQueryWrapper);
  1372. if (pmProjectConstruction != null) {
  1373. pmProjectConstructionReqVo.setId(pmProjectConstruction.getId());
  1374. BeanUtils.copyProperties(pmProjectConstructionReqVo, pmProjectConstruction);
  1375. pmProjectConstruction.setUpdateBy(pmProjectConstructionReqVo.getUpdateBy());
  1376. pmProjectConstruction.setUpdateTime(pmProjectConstructionReqVo.getUpdateTime());
  1377. } else {
  1378. pmProjectConstruction = new PmProjectConstruction();
  1379. BeanUtils.copyProperties(pmProjectConstructionReqVo, pmProjectConstruction);
  1380. pmProjectConstruction.setCreateBy(pmProjectConstructionReqVo.getCreateBy());
  1381. pmProjectConstruction.setCreateTime(pmProjectConstructionReqVo.getCreateTime());
  1382. pmProjectConstruction.setUpdateBy(pmProjectConstructionReqVo.getUpdateBy());
  1383. pmProjectConstruction.setUpdateTime(pmProjectConstructionReqVo.getUpdateTime());
  1384. }
  1385. if (pmProjectConstructionService.saveOrUpdate(pmProjectConstruction)) {
  1386. this.uploadFile(pmProjectConstruction.getId(), SysFileRefEnum.PM_PROJECT_CONSTRUCTION.getType(), sysFileRefs, pmProjectConstructionReqVo.getUpdateBy());
  1387. PmDemand pmDemandUpdate = new PmDemand();
  1388. pmDemandUpdate.setDemandId(demandId);
  1389. pmDemandUpdate.setProjectStatus(PmProjectStatus.COMPLETION_CONSTRUCTION.getCode());
  1390. pmDemandUpdate.setRealDeliverTime(pmProjectConstructionReqVo.getUpdateTime());
  1391. pmDemandUpdate.setUpdateTime(pmProjectConstructionReqVo.getUpdateTime());
  1392. pmDemandUpdate.setUpdateBy(pmProjectConstructionReqVo.getUpdateBy());
  1393. return this.updateById(pmDemandUpdate);
  1394. } else {
  1395. return false;
  1396. }
  1397. }
  1398. /**
  1399. * 更新需求预警状态
  1400. *
  1401. * @param demnadId
  1402. * @return
  1403. */
  1404. @Override
  1405. @Transactional(rollbackFor = Exception.class)
  1406. public void updateDemandWarnStatus(Long demnadId) {
  1407. PmDemand pmDemand = this.getById(demnadId);
  1408. List<SysDictData> data = iSysDictTypeService.selectDictDataByType("alert_time_setting");
  1409. int setting1 = Integer.parseInt(data.stream().filter(item -> item.getDictLabel().equals("计划提报时间")).collect(Collectors.toList()).get(0).getDictValue());
  1410. log.info("******** setting1 == " + setting1);
  1411. //需求提报时间:根据数据阈值中设置的提报时间进行判断,进行预警
  1412. int diff1 = DateUtils.differentDaysByMillisecond(pmDemand.getPlanDemandSubTime(), DateUtils.parseDate(DateUtils.getDate()));
  1413. if (ObjectUtils.isEmpty(pmDemand.getRealDemandCommitTime()) && diff1 >= setting1) {
  1414. PmDemand pmDemandUpdate = new PmDemand();
  1415. pmDemandUpdate.setDemandId(demnadId);
  1416. pmDemandUpdate.setWarnStatus(WarnStatus.DEMAND_COMMT_WARNING.getCode());
  1417. this.updateById(pmDemandUpdate);
  1418. }
  1419. }
  1420. /**
  1421. * 通过需求ID列表 查询采购执行列表 sunhh
  1422. *
  1423. * @param demandIdList
  1424. * @return
  1425. */
  1426. @Override
  1427. public List<PmDemand> selectByDemandIdList(List<Integer> demandIdList) {
  1428. return this.baseMapper.selectByDemandIdList(demandIdList);
  1429. }
  1430. /**
  1431. * 专家库--查询抽取专家列表 非必传条件:专家名称,开始结束时间 sunhh
  1432. *
  1433. * @param baseExpertVo
  1434. * @return
  1435. */
  1436. @Override
  1437. public List<PmDemand> selectExtractionExpert(BaseExpertVo baseExpertVo) {
  1438. return this.baseMapper.selectExtractionExpert(baseExpertVo);
  1439. }
  1440. @Override
  1441. public List<PmDemandResVo> demandWaitCommit() {
  1442. return getListByStatus(PmProjectStatus.DEMAND_WAIT_COMMIT.getCode());
  1443. }
  1444. @Override
  1445. public List<PmDemandResVo> contractWaitFilled() {
  1446. return getListByStatus(PmProjectStatus.CONTRACT_WAIT_FILL.getCode());
  1447. }
  1448. @Override
  1449. public List<PmDemandResVo> projectWaitFinish() {
  1450. return getListByStatus(PmProjectStatus.UNDER_CONSTRUCTION.getCode());
  1451. }
  1452. @Override
  1453. public List<PmDemandResVo> demandWaitExamine() {
  1454. return getListByStatus(PmProjectStatus.DEMAND_WAIT_AUDIT.getCode());
  1455. }
  1456. @Override
  1457. public List<PmDemandResVo> taskWaitRelease() {
  1458. return getListByStatus(PmProjectStatus.TASK_WAIT_RELEASE.getCode());
  1459. }
  1460. @Override
  1461. public List<PmDemandResVo> waitSelectAgent() {
  1462. return getListByStatus(PmProjectStatus.WAIT_SELECT_AGENT.getCode());
  1463. }
  1464. @Override
  1465. public List<PmDemandResVo> waitUpBidFile() {
  1466. return getListByStatus(PmProjectStatus.WAIT_UPLOAD_BID_FILE.getCode());
  1467. }
  1468. @Override
  1469. public List<PmDemandResVo> waitAnnouncement() {
  1470. return getListByStatus(PmProjectStatus.WAIT_ANNOUNCEMENT.getCode());
  1471. }
  1472. @Override
  1473. public List<PmDemandResVo> waitOpenBid() {
  1474. return getListByStatus(PmProjectStatus.WAIT_OPEN_BID.getCode());
  1475. }
  1476. @Override
  1477. public List<PmDemandResVo> waitBidAnnouncement() {
  1478. return getListByStatus(PmProjectStatus.WAIT_BID_ANNOUNCEMENT.getCode());
  1479. }
  1480. @Override
  1481. public List<PmDemandResVo> biddingPublicity() {
  1482. return getListByStatus(PmProjectStatus.BIDDING_PUBLICITY.getCode());
  1483. }
  1484. @Override
  1485. public AjaxResult procurementOfficeWillManipulateTotal() {
  1486. List<HomeToDoQueryResVo> homeRes = new ArrayList<>();
  1487. // 待选取代理, 待上传招标文件, 待发布公告, 待开标, 待发布中标公告, 中标公示中
  1488. List<PmDemandResVo> demandRes = new ArrayList<>();
  1489. demandRes.addAll(getListByStatus(PmProjectStatus.WAIT_SELECT_AGENT.getCode()));
  1490. demandRes.addAll(getListByStatus(PmProjectStatus.WAIT_UPLOAD_BID_FILE.getCode()));
  1491. demandRes.addAll(getListByStatus(PmProjectStatus.WAIT_ANNOUNCEMENT.getCode()));
  1492. demandRes.addAll(getListByStatus(PmProjectStatus.WAIT_OPEN_BID.getCode()));
  1493. demandRes.addAll(getListByStatus(PmProjectStatus.WAIT_BID_ANNOUNCEMENT.getCode()));
  1494. demandRes.addAll(getListByStatus(PmProjectStatus.BIDDING_PUBLICITY.getCode()));
  1495. //计划数据--发函催告
  1496. List<PlanQuarterResponseVo> planRes = planYearsService.willSendLetter();
  1497. //转为首页table展示数据
  1498. if (!ObjectUtils.isEmpty(demandRes) && demandRes.size() > 0) {
  1499. for (PmDemandResVo demandResVo : demandRes) {
  1500. HomeToDoQueryResVo home = new HomeToDoQueryResVo();
  1501. home.setEvaluation(BigDecimal.valueOf(demandResVo.getEvaluation()));
  1502. BeanUtils.copyProperties(demandResVo, home);
  1503. homeRes.add(home);
  1504. }
  1505. }
  1506. if (!ObjectUtils.isEmpty(planRes) && planRes.size() > 0) {
  1507. for (PlanQuarterResponseVo planVo : planRes) {
  1508. HomeToDoQueryResVo home = new HomeToDoQueryResVo();
  1509. BeanUtils.copyProperties(planVo, home);
  1510. homeRes.add(home);
  1511. }
  1512. }
  1513. return AjaxResult.success(homeRes);
  1514. }
  1515. /**
  1516. * 统计分析-采购项目信息统计
  1517. *
  1518. * @param pmDemandReqVo
  1519. * @return
  1520. */
  1521. @Override
  1522. public Map<String, Integer> purchaseProjectStatistical(PmDemandReqVo pmDemandReqVo) {
  1523. Map<String, Integer> mapReturn = new HashMap<>();
  1524. // 查询项目总数量
  1525. Map<String, Integer> mapCount = pmDemandMapper.purchaseProjectStatistical(pmDemandReqVo);
  1526. // 查询已完成项目数量,预算金额数量
  1527. Map<String, Integer> mapYWC = pmDemandMapper.purchaseProjectStatisticalYWC(pmDemandReqVo);
  1528. // 查询新创建项目数量,预算金额数量
  1529. Map<String, Integer> mapXCJ = pmDemandMapper.purchaseProjectStatisticalXCJ(pmDemandReqVo);
  1530. // 查询去年完成项目数量,预算金额数量
  1531. Map<String, Integer> mapQNWC = pmDemandMapper.purchaseProjectStatisticalQNWC(pmDemandReqVo);
  1532. mapReturn.putAll(mapCount);
  1533. mapReturn.putAll(mapYWC);
  1534. mapReturn.putAll(mapXCJ);
  1535. mapReturn.putAll(mapQNWC);
  1536. return mapReturn;
  1537. }
  1538. @Override
  1539. public List<StatisticalChartsResVo> countByProjectAttr() {
  1540. List<StatisticalChartsResVo> resVos = pmDemandMapper.countByProjectAttr();
  1541. for (StatisticalChartsResVo chartsResVo : resVos) {
  1542. for (PmProjectStatus value : PmProjectStatus.values()) {
  1543. if (value.getCode().equals(chartsResVo.getColumnName())) {
  1544. chartsResVo.setColumnName(value.getInfo());
  1545. break;
  1546. }
  1547. }
  1548. }
  1549. return resVos;
  1550. }
  1551. @Override
  1552. public List<StatisticalChartsResVo> countByPurchaseMode() {
  1553. List<StatisticalChartsResVo> resVos = pmDemandMapper.countByPurchaseMode();
  1554. for (StatisticalChartsResVo chartsResVo : resVos) {
  1555. for (ProcurementMethodSuggest value : ProcurementMethodSuggest.values()) {
  1556. if (value.getCode().equals(chartsResVo.getColumnName())) {
  1557. chartsResVo.setColumnName(value.getInfo());
  1558. break;
  1559. }
  1560. }
  1561. }
  1562. return resVos;
  1563. }
  1564. @Override
  1565. public List<StatisticalChartsResVo> countByEvaluation(PmDemandReqVo pmDemandReqVo) {
  1566. List<StatisticalChartsResVo> resVos = new ArrayList<>();
  1567. //概算金额包括:100万以下采购任务、100至500万元采购任务、500至1000万元采购任务、1000至5000万元采购任务、5000至1亿元采购任务、1亿元及以上采购任务
  1568. StatisticalChartsResVo resVo = pmDemandMapper.countByEvaluationLt(100);
  1569. resVo.setColumnName("100万以下采购任务");
  1570. resVos.add(resVo);
  1571. StatisticalChartsResVo resVo1 = pmDemandMapper.countByEvaluationBet(100, 500);
  1572. resVo1.setColumnName("100至500万元采购任务");
  1573. resVos.add(resVo1);
  1574. StatisticalChartsResVo resVo2 = pmDemandMapper.countByEvaluationBet(500, 1000);
  1575. resVo2.setColumnName("500至1000万元采购任务");
  1576. resVos.add(resVo2);
  1577. StatisticalChartsResVo resVo3 = pmDemandMapper.countByEvaluationBet(1000, 5000);
  1578. resVo3.setColumnName("1000至5000万元采购任务");
  1579. resVos.add(resVo3);
  1580. StatisticalChartsResVo resVo4 = pmDemandMapper.countByEvaluationBet(5000, 10000);
  1581. resVo4.setColumnName("5000至1亿元采购任务");
  1582. resVos.add(resVo4);
  1583. StatisticalChartsResVo resVo5 = pmDemandMapper.countByEvaluationGt(10000);
  1584. resVo5.setColumnName("1亿元及以上采购任务");
  1585. resVos.add(resVo5);
  1586. return resVos;
  1587. }
  1588. @Override
  1589. public AjaxResult countProjectExceed(PmDemandReqVo pmDemandReqVo) {
  1590. HashMap<String, String> resMap = new HashMap<>();
  1591. //执行滞后采购项目:本年度所有的逾期项目数
  1592. //预算金额:本年度所有逾期项目累加的预算金额
  1593. StatisticalChartsResVo resVo = pmDemandMapper.countProjectExceed();
  1594. resMap.put("执行滞后采购项目", resVo.getNum());
  1595. resMap.put("预算金额", resVo.getEvaluationTotal());
  1596. //滞后项目数量占比:指本年度逾期项目数量/本年度所有项目数量
  1597. Integer thisYear = pmDemandMapper.countThisYear();
  1598. resMap.put("滞后项目数量占比", getPercent(Integer.parseInt(resVo.getNum()), thisYear));
  1599. return AjaxResult.success(resMap);
  1600. }
  1601. /**
  1602. * 统计不同时间维度的逾期项目
  1603. *
  1604. * @return
  1605. */
  1606. @Override
  1607. public AjaxResult exceedAnalysis(PmDemandReqVo pmDemandReqVo) {
  1608. HashMap<String, List<StatisticalChartsResVo>> resMap = new HashMap<>();
  1609. List<StatisticalChartsResVo> byYear = pmDemandMapper.countProjectExceedYear();
  1610. if (pmDemandReqVo.getTimeType().equals("1")) {
  1611. resMap.put("年", byYear);
  1612. } else if (pmDemandReqVo.getTimeType().equals("2")) {
  1613. List<StatisticalChartsResVo> byQuarter = new LinkedList<>();
  1614. for (StatisticalChartsResVo chartsResVo : byYear) {
  1615. for (int i = 1; i <= 4; i++) {
  1616. StatisticalChartsResVo quarter = pmDemandMapper.countProjectExceedQuarter(i, Integer.parseInt(chartsResVo.getColumnName()));
  1617. if (ObjectUtils.isEmpty(quarter)) {
  1618. StatisticalChartsResVo vo = new StatisticalChartsResVo("", "0", "0");
  1619. quarter = vo;
  1620. quarter.setColumnName(chartsResVo.getColumnName() + "年第" + i + "季度");
  1621. }
  1622. quarter.setColumnName(chartsResVo.getColumnName() + "年第" + i + "季度");
  1623. byQuarter.add(quarter);
  1624. }
  1625. }
  1626. resMap.put("季度", byQuarter);
  1627. } else if (pmDemandReqVo.getTimeType().equals("3")) {
  1628. List<StatisticalChartsResVo> byMonth = new LinkedList<>();
  1629. for (StatisticalChartsResVo chartsResVo : byYear) {
  1630. for (int i = 1; i <= 12; i++) {
  1631. StatisticalChartsResVo month = pmDemandMapper.countProjectExceedMonth(i, Integer.parseInt(chartsResVo.getColumnName()));
  1632. if (ObjectUtils.isEmpty(month)) {
  1633. StatisticalChartsResVo vo = new StatisticalChartsResVo("", "0", "0");
  1634. month = vo;
  1635. month.setColumnName(chartsResVo.getColumnName() + "年" + i + "月");
  1636. }
  1637. month.setColumnName(chartsResVo.getColumnName() + "年" + i + "月");
  1638. byMonth.add(month);
  1639. }
  1640. }
  1641. resMap.put("月", byMonth);
  1642. }
  1643. return AjaxResult.success(resMap);
  1644. }
  1645. @Override
  1646. public AjaxResult taskQuantityAnalysis(PmDemandReqVo pmDemandReqVo) {
  1647. HashMap<String, List<StatisticalChartsResVo>> resMap = new HashMap<>();
  1648. //任务数量趋势分析:按照月、季度、年统计“项目属性”字段中“重大规划”属性的项目
  1649. List<StatisticalChartsResVo> byYear = pmDemandMapper.countProjectMajorByYear();
  1650. if (pmDemandReqVo.getTimeType().equals("1")) {
  1651. resMap.put("年", byYear);
  1652. } else if (pmDemandReqVo.getTimeType().equals("2")) {
  1653. List<StatisticalChartsResVo> byQuarter = new LinkedList<>();
  1654. for (StatisticalChartsResVo chartsResVo : byYear) {
  1655. for (int i = 1; i <= 4; i++) {
  1656. StatisticalChartsResVo quarter = pmDemandMapper.countProjectMajorByQuarter(i, Integer.parseInt(chartsResVo.getColumnName()));
  1657. quarter.setColumnName(chartsResVo.getColumnName() + "年第" + i + "季度");
  1658. byQuarter.add(quarter);
  1659. }
  1660. }
  1661. resMap.put("季度", byQuarter);
  1662. } else if (pmDemandReqVo.getTimeType().equals("3")) {
  1663. List<StatisticalChartsResVo> byMonth = pmDemandMapper.countProjectMajorByMonth();
  1664. resMap.put("月", byMonth);
  1665. }
  1666. return AjaxResult.success(resMap);
  1667. }
  1668. @Override
  1669. public AjaxResult countEveryStatusNum(PmDemandReqVo pmDemandReqVo) {
  1670. //指项目进行到各个阶段的数量
  1671. //阶段包括:待选取代理、待上传招标文件、待发布公告、待开标、待发布中标公告、中标公式中
  1672. List<StatisticalChartsResVo> everyStatusNum = pmDemandMapper.countEveryStatusNum();
  1673. if (!ObjectUtils.isEmpty(everyStatusNum) && everyStatusNum.size() > 0) {
  1674. for (StatisticalChartsResVo vo : everyStatusNum) {
  1675. switch (vo.getColumnName()) {
  1676. case "9":
  1677. vo.setColumnName(PmProjectStatus.WAIT_SELECT_AGENT.getInfo());
  1678. break;
  1679. case "10":
  1680. vo.setColumnName(PmProjectStatus.WAIT_UPLOAD_BID_FILE.getInfo());
  1681. break;
  1682. case "11":
  1683. vo.setColumnName(PmProjectStatus.WAIT_ANNOUNCEMENT.getInfo());
  1684. break;
  1685. case "12":
  1686. vo.setColumnName(PmProjectStatus.WAIT_OPEN_BID.getInfo());
  1687. break;
  1688. case "13":
  1689. vo.setColumnName(PmProjectStatus.WAIT_BID_ANNOUNCEMENT.getInfo());
  1690. break;
  1691. case "14":
  1692. vo.setColumnName(PmProjectStatus.BIDDING_PUBLICITY.getInfo());
  1693. break;
  1694. default: {
  1695. }
  1696. }
  1697. }
  1698. }
  1699. return AjaxResult.success(everyStatusNum);
  1700. }
  1701. @Override
  1702. public AjaxResult exceedMarketAnalysis(PmDemandReqVo pmDemandReqVo) {
  1703. //所有滞后
  1704. List<PmDemand> demandList = pmDemandMapper.countProjectExceedAll();
  1705. //滞后时长包括:滞后1个月以内的采购任务、滞后1至3个月采购任务、滞后3至6个月采购任务、滞后6个月至1年采购任务、滞后1年以上采购任务
  1706. HashMap<String, Integer> map = new LinkedHashMap<>();
  1707. map.put("滞后1个月以内的采购任务", 0);
  1708. map.put("滞后1至3个月采购任务", 0);
  1709. map.put("滞后3至6个月采购任务", 0);
  1710. map.put("滞后6个月至1年采购任务", 0);
  1711. map.put("滞后1年以上采购任务", 0);
  1712. if (!ObjectUtils.isEmpty(demandList) && demandList.size() > 0) {
  1713. for (PmDemand demand : demandList) {
  1714. //滞后时间
  1715. Long exTime = null;
  1716. if (!ObjectUtils.isEmpty(demand.getRealDemandCommitTime()) && demand.getRealDemandCommitTime().getTime() - demand.getPlanDemandSubTime().getTime() > 0) {
  1717. exTime = demand.getRealDemandCommitTime().getTime() - demand.getPlanDemandSubTime().getTime();
  1718. } else if (!ObjectUtils.isEmpty(demand.getRealPurchaseFinishTime()) && demand.getRealPurchaseFinishTime().getTime() - demand.getPlanPurchaseFinishTime().getTime() > 0) {
  1719. exTime = demand.getRealPurchaseFinishTime().getTime() - demand.getPlanPurchaseFinishTime().getTime();
  1720. } else if (!ObjectUtils.isEmpty(demand.getRealDeliverTime()) && demand.getRealDeliverTime().getTime() - demand.getPlanDeliverTime().getTime() > 0) {
  1721. exTime = demand.getRealDeliverTime().getTime() - demand.getPlanDeliverTime().getTime();
  1722. }
  1723. if (exTime < Long.valueOf("2592000000")) {
  1724. map.put("滞后1个月以内的采购任务", map.get("滞后1个月以内的采购任务") + 1);
  1725. }
  1726. if (exTime >= Long.valueOf("2592000000") && exTime < Long.valueOf("7776000000")) {
  1727. map.put("滞后1至3个月采购任务", map.get("滞后1至3个月采购任务") + 1);
  1728. }
  1729. if (exTime >= Long.valueOf("7776000000") && exTime < Long.valueOf("15552000000")) {
  1730. map.put("滞后3至6个月采购任务", map.get("滞后3至6个月采购任务") + 1);
  1731. }
  1732. if (exTime >= Long.valueOf("15552000000") && exTime < Long.valueOf("31104000000")) {
  1733. map.put("滞后6个月至1年采购任务", map.get("滞后6个月至1年采购任务") + 1);
  1734. }
  1735. if (exTime > Long.valueOf("31104000000")) {
  1736. map.put("滞后1年以上采购任务", map.get("滞后1年以上采购任务") + 1);
  1737. }
  1738. }
  1739. }
  1740. return AjaxResult.success(map);
  1741. }
  1742. @Override
  1743. public AjaxResult countMajorProject(PmDemandReqVo pmDemandReqVo) {
  1744. List<StatisticalChartsResVo> resVos = new ArrayList<>();
  1745. //数量:指本年度状态为“项目建设完成”的项目属性为“重大规划”的项目数
  1746. //预算金额:指本年度状态为“项目建设完成”的项目属性为“重大规划”的项目累加的预算金额
  1747. StatisticalChartsResVo resVo = new StatisticalChartsResVo();
  1748. resVo = pmDemandMapper.majorProjectByStatus(PmProjectStatus.COMPLETION_CONSTRUCTION.getCode());
  1749. resVo.setColumnName("今年已完成数量");
  1750. resVos.add(resVo);
  1751. //正常推进项目:指本年度正在进行中的项目属性为“重大规划”的项目数
  1752. //预算金额:指本年度正在进行中的项目属性为“重大规划”的项目累加的预算金额
  1753. StatisticalChartsResVo resVo1 = new StatisticalChartsResVo();
  1754. resVo1 = pmDemandMapper.majorProjectByStatus(PmProjectStatus.UNDER_CONSTRUCTION.getCode());
  1755. resVo1.setColumnName("正常推进数量");
  1756. resVos.add(resVo1);
  1757. //执行滞后数量:指本年度逾期项目中,项目属性为“重大规划”的项目数
  1758. //预算金额:指本年度正在进行中的项目属性为“重大规划”的项目累加的预算金额
  1759. StatisticalChartsResVo resVo2 = new StatisticalChartsResVo();
  1760. resVo2 = pmDemandMapper.countMajorProjectExceed();
  1761. resVo2.setColumnName("执行滞后数量");
  1762. resVos.add(resVo2);
  1763. //上年度重大规划采购任务数量:指上年度项目中,项目属性为“重大规划”的项目数
  1764. //预算金额:指上年度项目中,项目属性为“重大规划”的项目累加的预算金额
  1765. StatisticalChartsResVo resVo3 = new StatisticalChartsResVo();
  1766. resVo3 = pmDemandMapper.countMajorProjectLastYear();
  1767. resVo3.setColumnName("上年度重大规划采购任务数量");
  1768. resVos.add(resVo3);
  1769. //resVo2=pmDemandMapper.majorProjectByStatus(PmProjectStatus.COMPLETION_CONSTRUCTION.getCode());
  1770. return AjaxResult.success(resVos);
  1771. }
  1772. /**
  1773. * 通过计划ID查询项目数据
  1774. *
  1775. * @param planId
  1776. * @return
  1777. */
  1778. @Override
  1779. public PmDemand selectByPlanId(Long planId) {
  1780. return pmDemandMapper.selectByPlanId(planId);
  1781. }
  1782. /**
  1783. * 采购项目--项目数量分析
  1784. *
  1785. * @param pmDemandReqVo
  1786. * @return
  1787. */
  1788. @Override
  1789. public Map<String, Integer> purchaseProjectNumber(PmDemandReqVo pmDemandReqVo) {
  1790. return null;
  1791. }
  1792. /**
  1793. * 项目执行进度统计
  1794. * 1、正常推进项目数量:指未完成并且没有逾期的项目
  1795. * 预算金额:指未完成并且没有逾期的项目累加的预算金额
  1796. * 2、未完成采购任务:“合同待填制”状态之前的项目
  1797. * 预算金额:“合同待填制”状态之前的项目累加的预算金额
  1798. *
  1799. * @param pmDemandReqVo
  1800. * @return
  1801. */
  1802. @Override
  1803. public Map<String, Integer> purchaseProjectExecute(PmDemandReqVo pmDemandReqVo) {
  1804. Map<String, Integer> mapReturn = new HashMap<>();
  1805. // 正常推进项目数量、预算金额
  1806. Map<String, Integer> mapNormalPropulsion = pmDemandMapper.purchaseProjectExecuteNormalPropulsion(pmDemandReqVo);
  1807. // 未完成采购任务,预算金额
  1808. Map<String, Integer> mapIncomplete = pmDemandMapper.purchaseProjectExecuteIncomplete(pmDemandReqVo);
  1809. mapReturn.putAll(mapNormalPropulsion);
  1810. mapReturn.putAll(mapIncomplete);
  1811. return mapReturn;
  1812. }
  1813. /**
  1814. * 已完成项目数量统计
  1815. *
  1816. * @param pmDemandReqVo
  1817. * @return
  1818. */
  1819. @Override
  1820. public List<Map<String, Integer>> purchaseProjectCompleteNumber(PmDemandReqVo pmDemandReqVo) {
  1821. List<Map<String, Integer>> mapReturn = new ArrayList<>();
  1822. // 统计时间类型 1:年度,2:季度,3:月份
  1823. if ("1".equals(pmDemandReqVo.getTimeType())) {
  1824. // 查询数据库中最小的年份
  1825. int minYear = pmDemandMapper.selectMinYear();
  1826. // 获取当前年份
  1827. Calendar calendar = Calendar.getInstance();
  1828. int year = calendar.get(Calendar.YEAR);
  1829. // 获取统计数据
  1830. List<Map<String, Integer>> listMap = pmDemandMapper.selectpurchaseProjectCompleteNumberYear(pmDemandReqVo);
  1831. mapReturn.addAll(listMap);
  1832. for (int i = minYear; i <= year; i++) {
  1833. boolean isYear = false;
  1834. for (Map<String, Integer> map : listMap) {
  1835. if (i == Integer.valueOf(map.get("yy"))) {
  1836. isYear = true;
  1837. }
  1838. }
  1839. if (!isYear) {
  1840. Map<String, Integer> map1 = new HashMap<>();
  1841. map1.put("yy", i);
  1842. map1.put("evaluation", 0);
  1843. map1.put("contractAmount", 0);
  1844. map1.put("countNum", 0);
  1845. mapReturn.add(map1);
  1846. }
  1847. }
  1848. } else if ("2".equals(pmDemandReqVo.getTimeType())) {
  1849. // 当前年份季度统计
  1850. // 获取统计数据
  1851. List<Map<String, Integer>> listMap = pmDemandMapper.selectpurchaseProjectCompleteNumberQuarter(pmDemandReqVo);
  1852. mapReturn.addAll(listMap);
  1853. for (int i = 1; i <= 4; i++) {
  1854. boolean isYear = false;
  1855. for (Map<String, Integer> map : listMap) {
  1856. if (i == map.get("yy")) {
  1857. isYear = true;
  1858. }
  1859. }
  1860. if (!isYear) {
  1861. Map<String, Integer> map1 = new HashMap<>();
  1862. map1.put("yy", i);
  1863. map1.put("evaluation", 0);
  1864. map1.put("contractAmount", 0);
  1865. map1.put("countNum", 0);
  1866. mapReturn.add(map1);
  1867. }
  1868. }
  1869. } else if ("3".equals(pmDemandReqVo.getTimeType())) {
  1870. // 当前年份月份统计
  1871. // 获取统计数据
  1872. List<Map<String, Integer>> listMap = pmDemandMapper.selectpurchaseProjectCompleteNumberMonth(pmDemandReqVo);
  1873. mapReturn.addAll(listMap);
  1874. for (int i = 1; i <= 12; i++) {
  1875. boolean isYear = false;
  1876. for (Map<String, Integer> map : listMap) {
  1877. if (i == Integer.parseInt(String.valueOf(map.get("yy")))) {
  1878. isYear = true;
  1879. }
  1880. }
  1881. if (!isYear) {
  1882. Map<String, Integer> map1 = new HashMap<>();
  1883. map1.put("yy", i);
  1884. map1.put("evaluation", 0);
  1885. map1.put("contractAmount", 0);
  1886. map1.put("countNum", 0);
  1887. mapReturn.add(map1);
  1888. }
  1889. }
  1890. }
  1891. return mapReturn;
  1892. }
  1893. /**
  1894. * 已完成采购任务数量统计
  1895. *
  1896. * @param pmDemandReqVo
  1897. * @return
  1898. */
  1899. @Override
  1900. public List<Map<String, Integer>> purchaseTaskFinish(PmDemandReqVo pmDemandReqVo) {
  1901. List<Map<String, Integer>> mapReturn = new ArrayList<>();
  1902. // 统计时间类型 1:年度,2:季度,3:月份
  1903. if ("1".equals(pmDemandReqVo.getTimeType())) {
  1904. // 查询数据库中最小的年份
  1905. int minYear = pmDemandMapper.selectMinYear();
  1906. // 获取当前年份
  1907. Calendar calendar = Calendar.getInstance();
  1908. int year = calendar.get(Calendar.YEAR);
  1909. // 获取统计数据
  1910. List<Map<String, Integer>> listMap = pmDemandMapper.selectPurchaseTaskFinishYear(pmDemandReqVo);
  1911. mapReturn.addAll(listMap);
  1912. for (int i = minYear; i <= year; i++) {
  1913. boolean isYear = false;
  1914. for (Map<String, Integer> map : listMap) {
  1915. if (i == Integer.valueOf(map.get("yy"))) {
  1916. isYear = true;
  1917. }
  1918. }
  1919. if (!isYear) {
  1920. Map<String, Integer> map1 = new HashMap<>();
  1921. map1.put("yy", i);
  1922. map1.put("evaluation", 0);
  1923. map1.put("contractAmount", 0);
  1924. map1.put("countNum", 0);
  1925. mapReturn.add(map1);
  1926. }
  1927. }
  1928. } else if ("2".equals(pmDemandReqVo.getTimeType())) {
  1929. // 当前年份季度统计
  1930. // 获取统计数据
  1931. List<Map<String, Integer>> listMap = pmDemandMapper.selectPurchaseTaskFinishQuarter(pmDemandReqVo);
  1932. mapReturn.addAll(listMap);
  1933. for (int i = 1; i <= 4; i++) {
  1934. boolean isYear = false;
  1935. for (Map<String, Integer> map : listMap) {
  1936. if (i == map.get("yy")) {
  1937. isYear = true;
  1938. }
  1939. }
  1940. if (!isYear) {
  1941. Map<String, Integer> map1 = new HashMap<>();
  1942. map1.put("yy", i);
  1943. map1.put("evaluation", 0);
  1944. map1.put("contractAmount", 0);
  1945. map1.put("countNum", 0);
  1946. mapReturn.add(map1);
  1947. }
  1948. }
  1949. } else if ("3".equals(pmDemandReqVo.getTimeType())) {
  1950. // 当前年份月份统计
  1951. // 获取统计数据
  1952. List<Map<String, Integer>> listMap = pmDemandMapper.selectPurchaseTaskFinishMonth(pmDemandReqVo);
  1953. mapReturn.addAll(listMap);
  1954. for (int i = 1; i <= 12; i++) {
  1955. boolean isYear = false;
  1956. for (Map<String, Integer> map : listMap) {
  1957. if (i == Integer.parseInt(String.valueOf(map.get("yy")))) {
  1958. isYear = true;
  1959. }
  1960. }
  1961. if (!isYear) {
  1962. Map<String, Integer> map1 = new HashMap<>();
  1963. map1.put("yy", i);
  1964. map1.put("evaluation", 0);
  1965. map1.put("contractAmount", 0);
  1966. map1.put("countNum", 0);
  1967. mapReturn.add(map1);
  1968. }
  1969. }
  1970. }
  1971. return mapReturn;
  1972. }
  1973. /**
  1974. * 各阶段项目数量分布
  1975. *
  1976. * @param pmDemandReqVo
  1977. * @return
  1978. */
  1979. @Override
  1980. public List<Map<String, String>> purchaseProjectDistribution(PmDemandReqVo pmDemandReqVo) {
  1981. // 项目计划 4之前(包括4)
  1982. List<String> xmjh = new ArrayList<>();
  1983. xmjh.add("4");
  1984. pmDemandReqVo.setProjectStatusList(xmjh);
  1985. Map<String, String> returnMapxmjh = pmDemandMapper.purchaseProjectDistribution(pmDemandReqVo);
  1986. returnMapxmjh.put("name", "计划管理");
  1987. // 需求建党 4之后(不包括4)
  1988. List<String> xqjd = new ArrayList<>();
  1989. xqjd.add("5");
  1990. xqjd.add("6");
  1991. xqjd.add("7");
  1992. xqjd.add("8");
  1993. pmDemandReqVo.setProjectStatusList(xqjd);
  1994. Map<String, String> returnMapxqjd = pmDemandMapper.purchaseProjectDistribution(pmDemandReqVo);
  1995. returnMapxqjd.put("name", "需求管理");
  1996. // 任务下达 8之后(不包括8)
  1997. List<String> rwxd = new ArrayList<>();
  1998. rwxd.add("9");
  1999. pmDemandReqVo.setProjectStatusList(rwxd);
  2000. Map<String, String> returnMaprwxd = pmDemandMapper.purchaseProjectDistribution(pmDemandReqVo);
  2001. returnMaprwxd.put("name", "任务下达");
  2002. // 采购执行 9之后(不包括9)
  2003. List<String> cgzx = new ArrayList<>();
  2004. cgzx.add("10");
  2005. cgzx.add("11");
  2006. cgzx.add("12");
  2007. cgzx.add("13");
  2008. cgzx.add("14");
  2009. cgzx.add("15");
  2010. pmDemandReqVo.setProjectStatusList(cgzx);
  2011. Map<String, String> returnMapcgzx = pmDemandMapper.purchaseProjectDistribution(pmDemandReqVo);
  2012. returnMapcgzx.put("name", "采购执行");
  2013. // 合同管理 15之后(不包括15)
  2014. List<String> htxx = new ArrayList<>();
  2015. htxx.add("16");
  2016. pmDemandReqVo.setProjectStatusList(htxx);
  2017. Map<String, String> returnMaphtxx = pmDemandMapper.purchaseProjectDistribution(pmDemandReqVo);
  2018. returnMaphtxx.put("name", "合同管理");
  2019. // 项目建设 17
  2020. List<String> xmjs = new ArrayList<>();
  2021. xmjs.add("16");
  2022. pmDemandReqVo.setProjectStatusList(xmjs);
  2023. Map<String, String> returnMapxmjs = pmDemandMapper.purchaseProjectDistribution(pmDemandReqVo);
  2024. returnMapxmjs.put("name", "合同管理");
  2025. List<Map<String, String>> returnMap = new ArrayList<>();
  2026. returnMap.add(returnMapxmjh);
  2027. returnMap.add(returnMapxqjd);
  2028. returnMap.add(returnMaprwxd);
  2029. returnMap.add(returnMapcgzx);
  2030. returnMap.add(returnMaphtxx);
  2031. returnMap.add(returnMapxmjs);
  2032. return returnMap;
  2033. }
  2034. /**
  2035. * 项目数量分析
  2036. *
  2037. * @param pmDemandReqVo
  2038. * @return
  2039. */
  2040. @Override
  2041. public List<Map<String, String>> purchaseProjectNumberAnalysis(PmDemandReqVo pmDemandReqVo) {
  2042. List<Map<String, String>> mapReturn = new ArrayList<>();
  2043. // 统计时间类型 1:年度,2:季度,3:月份
  2044. if ("1".equals(pmDemandReqVo.getTimeType())) {
  2045. // *** 年度的同比和环比不展示 *** //
  2046. // 查询数据库中最小的年份
  2047. int minYear = pmDemandMapper.selectMinYear();
  2048. // 获取当前年份
  2049. Calendar calendar = Calendar.getInstance();
  2050. int year = calendar.get(Calendar.YEAR);
  2051. // 获取统计数据
  2052. // 获取项目统计
  2053. List<Map<String, String>> listMap = pmDemandMapper.purchaseProjectNumberAnalysisYear(pmDemandReqVo);
  2054. mapReturn.addAll(listMap);
  2055. for (int i = minYear; i <= year; i++) {
  2056. boolean isYear = false;
  2057. for (Map<String, String> map : listMap) {
  2058. if (i == Integer.valueOf(map.get("yy"))) {
  2059. isYear = true;
  2060. }
  2061. }
  2062. if (!isYear) {
  2063. Map<String, String> map1 = new HashMap<>();
  2064. map1.put("yy", i + "");
  2065. map1.put("countNum", 0 + "");
  2066. mapReturn.add(map1);
  2067. }
  2068. }
  2069. } else if ("2".equals(pmDemandReqVo.getTimeType())) {
  2070. // 当前年份季度统计
  2071. // 获取统计数据
  2072. List<Map<String, String>> listMap = pmDemandMapper.purchaseProjectNumberAnalysisQuarter(pmDemandReqVo);
  2073. mapReturn.addAll(listMap);
  2074. for (int i = 1; i <= 4; i++) {
  2075. boolean isYear = false;
  2076. for (Map<String, String> map : listMap) {
  2077. if (i == Integer.parseInt(String.valueOf(map.get("yy")))) {
  2078. isYear = true;
  2079. }
  2080. }
  2081. if (!isYear) {
  2082. Map<String, String> map1 = new HashMap<>();
  2083. map1.put("yy", i + "");
  2084. map1.put("countNum", 0 + "");
  2085. mapReturn.add(map1);
  2086. }
  2087. }
  2088. } else if ("3".equals(pmDemandReqVo.getTimeType())) {
  2089. // 当前年份月份统计
  2090. // 获取统计数据
  2091. List<Map<String, String>> listMap = pmDemandMapper.purchaseProjectNumberAnalysisMonth(pmDemandReqVo);
  2092. mapReturn.addAll(listMap);
  2093. for (int i = 1; i <= 12; i++) {
  2094. boolean isYear = false;
  2095. for (Map<String, String> map : listMap) {
  2096. if (i == Integer.parseInt(String.valueOf(map.get("yy")))) {
  2097. isYear = true;
  2098. }
  2099. }
  2100. if (!isYear) {
  2101. Map<String, String> map1 = new HashMap<>();
  2102. map1.put("yy", i + "");
  2103. map1.put("countNum", 0 + "");
  2104. mapReturn.add(map1);
  2105. }
  2106. }
  2107. }
  2108. return mapReturn;
  2109. }
  2110. //查询不同状态下的项目数据
  2111. public List<PmDemandResVo> getListByStatus(String projectStatus) {
  2112. LambdaQueryWrapper<PmDemand> lw = new LambdaQueryWrapper<PmDemand>();
  2113. lw.eq(PmDemand::getProjectStatus, projectStatus);
  2114. List<PmDemand> demandList = this.baseMapper.selectList(lw);
  2115. //数据转换
  2116. List<PmDemandResVo> pmDemandResponseVoList = new ArrayList<>();
  2117. if (!ObjectUtils.isEmpty(demandList) && demandList.size() > 0) {
  2118. pmDemandResponseVoList = demandChangeTo(demandList);
  2119. }
  2120. return pmDemandResponseVoList;
  2121. }
  2122. //字段转换and赋值
  2123. public List<PmDemandResVo> demandChangeTo(List<PmDemand> pmDemandList) {
  2124. List<PmDemandResVo> pmDemandResponseVoList = new ArrayList<>();
  2125. for (PmDemand pmDemand1 : pmDemandList) {
  2126. PmDemandResVo vo = new PmDemandResVo();
  2127. BeanUtils.copyProperties(pmDemand1, vo);
  2128. if (vo.getPurchaseDeptId() != null) {
  2129. Map<String, Object> deptMap = deptService.selectDeptById(vo.getPurchaseDeptId());
  2130. if (deptMap != null) {
  2131. SysDeptResponseVo sysDeptResponseVo = (SysDeptResponseVo) deptMap.get("sysDept");
  2132. if (sysDeptResponseVo != null) {
  2133. vo.setPurchaseDeptName(sysDeptResponseVo.getDeptName());
  2134. }
  2135. }
  2136. }
  2137. String purchaseServicesName = dictDataService.selectDictLabel("purchase_services", vo.getPurchaseServices());
  2138. if (StringUtils.isNotEmpty(purchaseServicesName)) {
  2139. vo.setPurchaseServicesName(purchaseServicesName);
  2140. }
  2141. //项目类型
  2142. for (ProjectTypes value : ProjectTypes.values()) {
  2143. if (vo.getProjectType() != null && vo.getProjectType().equals(value.getCode())) {
  2144. vo.setProjectTypeName(value.getInfo());
  2145. break;
  2146. }
  2147. }
  2148. //是否为超限额计划
  2149. for (IsExcess value : IsExcess.values()) {
  2150. if (vo.getIsExcess() != null && vo.getIsExcess().equals(value.getCode())) {
  2151. vo.setIsExcessName(value.getInfo());
  2152. break;
  2153. }
  2154. }
  2155. //采购方式
  2156. for (PlanPurchaseMode value : PlanPurchaseMode.values()) {
  2157. if (vo.getPurchaseMode() != null && vo.getPurchaseMode().equals(value.getCode())) {
  2158. vo.setPurchaseModeName(value.getInfo());
  2159. break;
  2160. }
  2161. }
  2162. //项目属性
  2163. for (ProjectAttribute value : ProjectAttribute.values()) {
  2164. if (vo.getProjectAttr() != null && vo.getProjectAttr().equals(value.getCode())) {
  2165. vo.setProjectAttrName(value.getInfo());
  2166. break;
  2167. }
  2168. }
  2169. //预警状态
  2170. for (WarnStatus value : WarnStatus.values()) {
  2171. if (vo.getWarnStatus() != null && vo.getWarnStatus().equals(value.getCode())) {
  2172. vo.setWarnStatusName(value.getInfo());
  2173. break;
  2174. }
  2175. }
  2176. //项目状态
  2177. for (PmProjectStatus value : PmProjectStatus.values()) {
  2178. if (vo.getProjectStatus() != null && vo.getProjectStatus().equals(value.getCode())) {
  2179. vo.setProjectStatusName(value.getInfo());
  2180. break;
  2181. }
  2182. }
  2183. try {
  2184. vo.setTipsMessage(pmDemandGetTips(vo.getPlanDeliverTime()));
  2185. if (vo.getTipsMessage().contains("超过")) {
  2186. vo.setIsExceedProject("1");
  2187. }
  2188. } catch (ParseException e) {
  2189. e.printStackTrace();
  2190. }
  2191. pmDemandResponseVoList.add(vo);
  2192. }
  2193. return pmDemandResponseVoList;
  2194. }
  2195. /**
  2196. * 根据年度计划提报时间的阈值进行提示
  2197. *
  2198. * @return
  2199. */
  2200. public String pmDemandGetTips(Date planDeliverTime) throws ParseException {
  2201. if (!ObjectUtils.isEmpty(planDeliverTime)) {
  2202. //提示信息:定义距离结束时间一周内提示
  2203. Integer remindTine = 1000 * 60 * 60 * 24 * 7;
  2204. //少于一周便提醒
  2205. double surplus = planDeliverTime.getTime() - System.currentTimeMillis();
  2206. if (surplus < remindTine) {
  2207. int i = new Double(Math.ceil(surplus / 1000 / 60 / 60 / 24)).intValue();
  2208. //剩余天数(向上取整)
  2209. if (i > 0) {
  2210. return "距离计划交付时间不足" + i + "天";
  2211. } else {
  2212. return "已超过计划完成时间" + Math.abs(i) + "天";
  2213. }
  2214. }
  2215. }
  2216. return "";
  2217. }
  2218. /**
  2219. * 计算百分比:使用java.text.DecimalFormat实现
  2220. *
  2221. * @param x
  2222. * @param y
  2223. * @return
  2224. */
  2225. public static String getPercent(int x, int y) {
  2226. double d1 = x * 1.0;
  2227. double d2 = y * 1.0;
  2228. // 设置保留几位小数, “.”后面几个零就保留几位小数,这里设置保留2位小数
  2229. DecimalFormat decimalFormat = new DecimalFormat("##.00%");
  2230. return decimalFormat.format(d1 / d2);
  2231. }
  2232. }