PmDemandServiceImpl.java 111 KB

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