PmDemandServiceImpl.java 101 KB

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