GcBidpublicitySchedul.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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.AreaDataName;
  8. import com.trs.ggzyexchange.controller.BaseController;
  9. import com.trs.ggzyexchange.entity.*;
  10. import com.trs.ggzyexchange.enums.ClassIfy;
  11. import com.trs.ggzyexchange.enums.JobLock;
  12. import com.trs.ggzyexchange.service.*;
  13. import com.trs.ggzyexchange.utils.TenderDetailsVoUtils;
  14. import org.apache.commons.lang3.ObjectUtils;
  15. import org.quartz.Job;
  16. import org.quartz.JobExecutionContext;
  17. import org.quartz.JobExecutionException;
  18. import org.slf4j.Logger;
  19. import org.slf4j.LoggerFactory;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.stereotype.Component;
  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-16
  38. */
  39. @Component
  40. public class GcBidpublicitySchedul implements Job {
  41. private Logger logger = LoggerFactory.getLogger(GcBidpublicitySchedul.class);
  42. @Autowired
  43. private GcNoticeandfileService gcNoticeandfileService;
  44. @Autowired
  45. private AreaDataName areaDataName;
  46. @Autowired
  47. private GcBidpublicityService gcBidpublicityService;
  48. @Autowired
  49. private TenderDetailsVoService tenderDetailsVoService;
  50. @Autowired
  51. private ScheduledTashService scheduledTashService;
  52. @Autowired
  53. private GcAttachmentService gcAttachmentService;
  54. public void queryPageListUpdateEs() throws JsonProcessingException {
  55. /**
  56. * 查询当前在定时任务表当中的最新时间
  57. */
  58. QueryWrapper<ScheduledTash> scheduledTashQueryWrapper = new QueryWrapper<ScheduledTash>();
  59. scheduledTashQueryWrapper.eq("table_name_value","gc_bidpublicity");
  60. Page<ScheduledTash> pageScheduledTash = new Page<ScheduledTash>(1, 1);
  61. Page<ScheduledTash> page = scheduledTashService.page(pageScheduledTash, scheduledTashQueryWrapper);
  62. List<ScheduledTash> records = page.getRecords();
  63. ScheduledTash scheduledTash = null;
  64. if(records.size() > 0){
  65. scheduledTash = records.get(0);
  66. }
  67. Long time = null;
  68. if(ObjectUtils.isEmpty(scheduledTash)){
  69. try {
  70. /**
  71. * 如果scheduledTash为空,证明没有当前定时任务,设置当前的定时任务的时间为0 查询表gcNoticeandfile表当中的最新时间
  72. */
  73. time = gcBidpublicityService.maxDataTimeStamp();
  74. ScheduledTash scheduledTashTash = new ScheduledTash();
  75. scheduledTashTash.setTime(0L);
  76. time = 0L;
  77. scheduledTashTash.setTableNameValue("gc_bidpublicity");
  78. scheduledTashTash.setUpdateTime(new Date());
  79. scheduledTashTash.setCreateTime(new Date());
  80. scheduledTashService.saveOrUpdate(scheduledTashTash,scheduledTashQueryWrapper);
  81. }catch (Exception e){
  82. e.printStackTrace();
  83. }
  84. }else {
  85. /**
  86. * 如果scheduledTash为空,证明没有当前定时任务,设置当前的定时任务的时间为0 查询表gcNoticeandfile表当中的最新时间
  87. */
  88. time = scheduledTash.getTime();
  89. }
  90. try {
  91. //查询表gcNoticeandfile表当中的最新时间
  92. Long newTime = gcBidpublicityService.maxDataTimeStamp();
  93. ScheduledTash scheduledTashTash = new ScheduledTash();
  94. scheduledTashTash.setTime(newTime);
  95. scheduledTashTash.setTableNameValue("gc_bidpublicity");
  96. scheduledTashTash.setUpdateTime(new Date());
  97. scheduledTashService.saveOrUpdate(scheduledTashTash,scheduledTashQueryWrapper);
  98. }catch (Exception e){
  99. e.printStackTrace();
  100. }
  101. if(!ObjectUtils.isEmpty(time)){
  102. try {
  103. QueryWrapper<GcBidpublicity> GcBidpublicityQueryWrapper = new QueryWrapper<GcBidpublicity>();
  104. GcBidpublicityQueryWrapper.gt("DATA_TIMESTAMP",time);
  105. int count = gcBidpublicityService.count(GcBidpublicityQueryWrapper);
  106. Integer pageSize = 1000;
  107. Integer pageNum = (int)Math.ceil((double)count/pageSize);
  108. for(int i = 1; i <= pageNum;i++){
  109. try {
  110. List<TenderDetailsVo> tenderDetailsVoListAll = getTenderDetailsVoListAll(i, pageSize,time);
  111. gcNoticeandfileService.parseTenderDetailsVo(tenderDetailsVoListAll);
  112. }catch (Exception e){
  113. e.printStackTrace();
  114. }
  115. }
  116. }catch (Exception e){
  117. e.printStackTrace();
  118. }
  119. }
  120. }
  121. public List<TenderDetailsVo> getTenderDetailsVoListAll(Integer pageNo,Integer pageSize,Long time){
  122. Page<GcBidpublicity> page = new Page<GcBidpublicity>(pageNo, pageSize);
  123. IPage<TenderDetailsVo> pageList = gcBidpublicityService.queryGcBidpublicityAllListByTime(page,time);
  124. for (TenderDetailsVo record : pageList.getRecords()) {
  125. try {
  126. record.setNoticeTypeCode(ClassIfy.ANNOUNCEMENT_OF_BID_WINNING_RESULTS.getCode());
  127. record.setNoticeTypeName(ClassIfy.ANNOUNCEMENT_OF_BID_WINNING_RESULTS.getName());
  128. record.setTransactionTypeCode(ClassIfy.ENGINEERING_CONSTRUCTION.getCode());
  129. record.setTransactionTypeName(ClassIfy.ENGINEERING_CONSTRUCTION.getName());
  130. record = tenderDetailsVoService.getTenderDetailsVoAllOrther(record);
  131. String bidSectionCodes = record.getBidSectionCodes();
  132. if(!ObjectUtils.isEmpty(bidSectionCodes)) {
  133. int i1 = bidSectionCodes.indexOf(",");
  134. int i2 = bidSectionCodes.indexOf(";");
  135. int i3 = bidSectionCodes.indexOf("<br>");
  136. int i4 = bidSectionCodes.indexOf("ltbrgt");
  137. String splitBidSectionCode = null;
  138. String[] split = null;
  139. boolean flag = false;
  140. if (i1 > 0) {
  141. splitBidSectionCode = bidSectionCodes.split(",")[0];
  142. split = bidSectionCodes.split(",");
  143. flag = true;
  144. }
  145. if (i2 > 0) {
  146. splitBidSectionCode = bidSectionCodes.split(";")[0];
  147. split = bidSectionCodes.split(";");
  148. flag = true;
  149. }
  150. if (i3 > 0) {
  151. splitBidSectionCode = bidSectionCodes.split("<br>")[0];
  152. split = bidSectionCodes.split("<br>");
  153. flag = true;
  154. }
  155. if (i4 > 0) {
  156. splitBidSectionCode = bidSectionCodes.split("ltbrgt")[0];
  157. split = bidSectionCodes.split("ltbrgt");
  158. flag = true;
  159. }
  160. if (!flag) {
  161. splitBidSectionCode = bidSectionCodes;
  162. split = bidSectionCodes.split(",");
  163. }
  164. List<GcAttachment> attachmentList = new ArrayList<GcAttachment>();
  165. if (!ObjectUtils.isEmpty(split)) {
  166. if (split.length >= 1) {
  167. for (String bidSectionCode : split) {
  168. try {
  169. String bidSectionCodeClean = bidSectionCode.replaceAll(">", "").replaceAll("<", "");
  170. String bidSectionCodeClean2 = bidSectionCodeClean.replaceAll("gt", "").replaceAll("lt", "");
  171. //通过标包编号查询对应的附件信息
  172. QueryWrapper<GcAttachment> gcAttachmentQueryWrapper = new QueryWrapper<GcAttachment>();
  173. gcAttachmentQueryWrapper.eq("ATTACHMENT_SET_CODE", "WIN_BID_NOTICE");//add
  174. gcAttachmentQueryWrapper.eq("isshow", "0");//add
  175. //gcAttachmentQueryWrapper.eq("BID_SECTION_CODE",bidSectionCode);
  176. gcAttachmentQueryWrapper.like("BID_SECTION_CODE", bidSectionCodeClean2);
  177. List<GcAttachment> list = gcAttachmentService.list(gcAttachmentQueryWrapper);
  178. if (attachmentList.size() > 0) {
  179. break;
  180. }
  181. if (!ObjectUtils.isEmpty(list)) {
  182. attachmentList.addAll(list);
  183. }
  184. } catch (Exception e) {
  185. e.printStackTrace();
  186. }
  187. }
  188. }
  189. }
  190. String noticeContent = record.getNoticeContent();
  191. String file = "";
  192. if (!ObjectUtils.isEmpty(attachmentList)) {
  193. if (attachmentList.size() > 0) {
  194. file = "<br>附件:<br>";
  195. }
  196. }
  197. for (GcAttachment gcAttachment : attachmentList) {
  198. try {
  199. String attachmentName = gcAttachment.getAttachmentName();
  200. String url = gcAttachment.getUrl();
  201. file += "<a target='_blank' style='color: blue' href='" + url + "'>" + attachmentName + "</a><br/>";
  202. } catch (Exception e) {
  203. e.printStackTrace();
  204. }
  205. }
  206. //招标文件拼接地址
  207. if (!ObjectUtils.isEmpty(noticeContent) && noticeContent != "") {
  208. file = noticeContent + file;
  209. }
  210. record.setNoticeContent(file);
  211. }
  212. TenderDetailsVoUtils.isNull(record);
  213. }catch (Exception e){
  214. e.printStackTrace();
  215. }
  216. }
  217. return pageList.getRecords();
  218. }
  219. @Override
  220. public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
  221. try {
  222. if(JobLock.GcBidpublicityFlag){
  223. JobLock.GcBidpublicityFlag = false;
  224. logger.info("执行GcBidpublicity", new SimpleDateFormat().format(new Date()));
  225. try {
  226. queryPageListUpdateEs();
  227. } catch (Exception e) {
  228. e.printStackTrace();
  229. }
  230. JobLock.GcBidpublicityFlag = true;
  231. }else{
  232. logger.info("不执行GcBidpublicity", new SimpleDateFormat().format(new Date()));
  233. }
  234. }catch (Exception e){
  235. e.printStackTrace();
  236. JobLock.GcBidpublicityFlag = true;
  237. }
  238. }
  239. }