PmDemandServiceImpl.java 110 KB

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