GcPubContractSchedul.java 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. package com.trs.ggzyexchange.schedul;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.fasterxml.jackson.core.JsonProcessingException;
  6. import com.trs.ggzyexchange.api.vo.Result;
  7. import com.trs.ggzyexchange.controller.BaseController;
  8. import com.trs.ggzyexchange.entity.*;
  9. import com.trs.ggzyexchange.enums.ClassIfy;
  10. import com.trs.ggzyexchange.enums.JobLock;
  11. import com.trs.ggzyexchange.service.*;
  12. import com.trs.ggzyexchange.utils.TenderDetailsVoUtils;
  13. import org.apache.commons.lang3.ObjectUtils;
  14. import org.quartz.Job;
  15. import org.quartz.JobExecutionContext;
  16. import org.quartz.JobExecutionException;
  17. import org.slf4j.Logger;
  18. import org.slf4j.LoggerFactory;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Component;
  21. import org.springframework.util.CollectionUtils;
  22. import org.springframework.web.bind.annotation.GetMapping;
  23. import org.springframework.web.bind.annotation.RequestMapping;
  24. import org.springframework.web.bind.annotation.RequestParam;
  25. import org.springframework.web.bind.annotation.RestController;
  26. import javax.servlet.http.HttpServletRequest;
  27. import java.text.SimpleDateFormat;
  28. import java.util.ArrayList;
  29. import java.util.Date;
  30. import java.util.List;
  31. /**
  32. * <p>
  33. * 合同签订 定时任务
  34. * </p>
  35. *
  36. * @author trs
  37. * @since 2023-02-23
  38. */
  39. @Component
  40. public class GcPubContractSchedul implements Job {
  41. private Logger logger = LoggerFactory.getLogger(GcPubContractSchedul.class);
  42. @Autowired
  43. private GcPubContractService gcPubContractService;
  44. @Autowired
  45. private TenderDetailsVoService tenderDetailsVoService;
  46. @Autowired
  47. private GcNoticeandfileService gcNoticeandfileService;
  48. @Autowired
  49. private ScheduledTashService scheduledTashService;
  50. @Autowired
  51. private GcAttachmentService gcAttachmentService;
  52. public void queryPageListUpdateEs() throws JsonProcessingException {
  53. /**
  54. * 查询当前在定时任务表当中的最新时间
  55. */
  56. QueryWrapper<ScheduledTash> scheduledTashQueryWrapper = new QueryWrapper<ScheduledTash>();
  57. scheduledTashQueryWrapper.eq("table_name_value","gc_pub_contract");
  58. Page<ScheduledTash> pageScheduledTash = new Page<ScheduledTash>(1, 1);
  59. Page<ScheduledTash> page = scheduledTashService.page(pageScheduledTash, scheduledTashQueryWrapper);
  60. List<ScheduledTash> records = page.getRecords();
  61. ScheduledTash scheduledTash = null;
  62. if(records.size() > 0){
  63. scheduledTash = records.get(0);
  64. }
  65. Long time = null;
  66. if(ObjectUtils.isEmpty(scheduledTash)){
  67. try {
  68. /**
  69. * 如果scheduledTash为空,证明没有当前定时任务,设置当前的定时任务的时间为0 查询表gcNoticeandfile表当中的最新时间
  70. */
  71. time = gcPubContractService.maxDataTimeStamp();
  72. ScheduledTash scheduledTashTash = new ScheduledTash();
  73. scheduledTashTash.setTime(0L);
  74. time = 0L;
  75. scheduledTashTash.setTableNameValue("gc_pub_contract");
  76. scheduledTashTash.setUpdateTime(new Date());
  77. scheduledTashTash.setCreateTime(new Date());
  78. scheduledTashService.saveOrUpdate(scheduledTashTash,scheduledTashQueryWrapper);
  79. }catch (Exception e){
  80. e.printStackTrace();
  81. }
  82. }else {
  83. /**
  84. * 如果scheduledTash为空,证明没有当前定时任务,设置当前的定时任务的时间为0 查询表gcNoticeandfile表当中的最新时间
  85. */
  86. time = scheduledTash.getTime();
  87. }
  88. try {
  89. //查询表gcNoticeandfile表当中的最新时间
  90. Long newTime = gcPubContractService.maxDataTimeStamp();
  91. ScheduledTash scheduledTashTash = new ScheduledTash();
  92. scheduledTashTash.setTime(newTime);
  93. scheduledTashTash.setTableNameValue("gc_pub_contract");
  94. scheduledTashTash.setUpdateTime(new Date());
  95. scheduledTashService.saveOrUpdate(scheduledTashTash,scheduledTashQueryWrapper);
  96. }catch (Exception e){
  97. e.printStackTrace();
  98. }
  99. if(!ObjectUtils.isEmpty(time)){
  100. QueryWrapper<GcPubContract> gcPerformanceQueryWrapper = new QueryWrapper<GcPubContract>();
  101. gcPerformanceQueryWrapper.gt("DATA_TIMESTAMP",time);
  102. int count = gcPubContractService.count(gcPerformanceQueryWrapper);
  103. Integer pageSize = 1000;
  104. Integer pageNum = (int)Math.ceil((double)count/pageSize);
  105. for(int i = 1; i <= pageNum;i++){
  106. List<TenderDetailsVo> tenderDetailsVoListAll = getTenderDetailsVoListAll(i, pageSize,time);
  107. gcNoticeandfileService.parseTenderDetailsVo(tenderDetailsVoListAll);
  108. }
  109. }
  110. }
  111. public List<TenderDetailsVo> getTenderDetailsVoListAll(Integer pageNo,Integer pageSize,Long time){
  112. Page<GcPubContract> page = new Page<GcPubContract>(pageNo, pageSize);
  113. IPage<TenderDetailsVo> tenderDetailsVoIPage = gcPubContractService.queryGcBidcandidateAllListByTime(page,time);
  114. for (TenderDetailsVo record : tenderDetailsVoIPage.getRecords()) {
  115. try {
  116. record.setNoticeTypeCode(ClassIfy.CONTRACT_PUBLICITY.getCode());
  117. record.setNoticeTypeName(ClassIfy.CONTRACT_PUBLICITY.getName());
  118. //电力交易
  119. if(!ObjectUtils.isEmpty(record.getSourceDataCode()) && "7089bc24".equals(record.getSourceDataCode())) {
  120. record.setTransactionTypeCode(ClassIfy.ELECTRICITY.getCode());
  121. record.setTransactionTypeName(ClassIfy.ELECTRICITY.getName());
  122. }else if(!ObjectUtils.isEmpty(record.getSourceDataCode()) && "d844782a".equals(record.getSourceDataCode())) {
  123. record.setTransactionTypeCode(ClassIfy.WEITUO.getCode());
  124. record.setTransactionTypeName(ClassIfy.WEITUO.getName());
  125. }else {
  126. record.setTransactionTypeCode(ClassIfy.ENGINEERING_CONSTRUCTION.getCode());
  127. record.setTransactionTypeName(ClassIfy.ENGINEERING_CONSTRUCTION.getName());
  128. }
  129. List<GcAttachment> attachmentList = new ArrayList<GcAttachment>();
  130. //通过标包编号查询对应的附件信息
  131. QueryWrapper<GcAttachment> gcAttachmentQueryWrapper = new QueryWrapper<GcAttachment>();
  132. gcAttachmentQueryWrapper.eq("ASSOCIATION_CODE", record.getSourceDataKey());
  133. List<GcAttachment> list = gcAttachmentService.list(gcAttachmentQueryWrapper);
  134. if (!CollectionUtils.isEmpty(list)) {
  135. attachmentList.addAll(list);
  136. }
  137. String noticeContent = record.getNoticeContent();
  138. String file = "";
  139. if(!CollectionUtils.isEmpty(attachmentList)){
  140. if(attachmentList.size() > 0){
  141. file = "<br>附件:<br>";
  142. }
  143. }
  144. for (GcAttachment gcAttachment : attachmentList) {
  145. try{
  146. String attachmentName = gcAttachment.getAttachmentName();
  147. String url = gcAttachment.getUrl();
  148. file += "<a target='_blank' style='color: blue' href='"+ url +"'>"+ attachmentName +"</a><br/>";
  149. }catch (Exception e){
  150. e.printStackTrace();
  151. }
  152. }
  153. //招标文件拼接地址
  154. if(!ObjectUtils.isEmpty(noticeContent) && noticeContent != ""){
  155. file = noticeContent + file;
  156. }
  157. record.setNoticeContent(file);
  158. record.setSourceDataKey("pubc-"+record.getSourceDataKey());
  159. record = tenderDetailsVoService.getTenderDetailsVoAllOrther(record);
  160. TenderDetailsVoUtils.isNull(record);
  161. }catch (Exception e){
  162. e.printStackTrace();
  163. }
  164. }
  165. return tenderDetailsVoIPage.getRecords();
  166. }
  167. @Override
  168. public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
  169. try {
  170. if(JobLock.GcPubContractFlag){
  171. JobLock.GcPubContractFlag = false;
  172. logger.info("执行GcPubContract", new SimpleDateFormat().format(new Date()));
  173. try {
  174. queryPageListUpdateEs();
  175. } catch (Exception e) {
  176. e.printStackTrace();
  177. }
  178. JobLock.GcPubContractFlag = true;
  179. }else{
  180. logger.info("不执行GcPubContract", new SimpleDateFormat().format(new Date()));
  181. }
  182. }catch (Exception e){
  183. e.printStackTrace();
  184. JobLock.GcPubContractFlag = true;
  185. }
  186. }
  187. }