package com.trs.ggzyexchange.schedul;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.trs.ggzyexchange.api.vo.Result;
import com.trs.ggzyexchange.controller.AreaDataName;
import com.trs.ggzyexchange.controller.BaseController;
import com.trs.ggzyexchange.entity.*;
import com.trs.ggzyexchange.enums.ClassIfy;
import com.trs.ggzyexchange.enums.JobLock;
import com.trs.ggzyexchange.service.*;
import com.trs.ggzyexchange.utils.TenderDetailsVoUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
*
* 招标文件/招标文件澄清与修改 定时任务
*
*
* @author trs
* @since 2023-02-16
*/
@Component
public class GcTenderbidfileSchedul implements Job {
private Logger logger = LoggerFactory.getLogger(GcTenderbidfileSchedul.class);
@Autowired
private GcTenderbidfileService gcTenderbidfileService;
@Autowired
private AreaDataName areaDataName;
@Autowired
private GcNoticeandfileService gcNoticeandfileService;
@Autowired
private TenderDetailsVoService tenderDetailsVoService;
@Autowired
private GcAttachmentService gcAttachmentService;
@Autowired
private ScheduledTashService scheduledTashService;
public void queryPageListUpdateEs() throws JsonProcessingException {
/**
* 查询当前在定时任务表当中的最新时间
*/
QueryWrapper scheduledTashQueryWrapper = new QueryWrapper();
scheduledTashQueryWrapper.eq("table_name_value","gc_tenderbidfile");
Page pageScheduledTash = new Page(1, 1);
Page page = scheduledTashService.page(pageScheduledTash, scheduledTashQueryWrapper);
List records = page.getRecords();
ScheduledTash scheduledTash = null;
if(records.size() > 0){
scheduledTash = records.get(0);
}
Long time = null;
if(ObjectUtils.isEmpty(scheduledTash)){
try {
/**
* 如果scheduledTash为空,证明没有当前定时任务,设置当前的定时任务的时间为0 查询表gcNoticeandfile表当中的最新时间
*/
time = gcTenderbidfileService.maxDataTimeStamp();
ScheduledTash scheduledTashTash = new ScheduledTash();
scheduledTashTash.setTime(0L);
time = 0L;
scheduledTashTash.setTableNameValue("gc_tenderbidfile");
scheduledTashTash.setUpdateTime(new Date());
scheduledTashTash.setCreateTime(new Date());
scheduledTashService.saveOrUpdate(scheduledTashTash,scheduledTashQueryWrapper);
}catch (Exception e){
e.printStackTrace();
}
}else {
/**
* 如果scheduledTash为空,证明没有当前定时任务,设置当前的定时任务的时间为0 查询表gcNoticeandfile表当中的最新时间
*/
time = scheduledTash.getTime();
}
try {
//查询表gcNoticeandfile表当中的最新时间
Long newTime = gcTenderbidfileService.maxDataTimeStamp();
ScheduledTash scheduledTashTash = new ScheduledTash();
scheduledTashTash.setTime(newTime);
scheduledTashTash.setTableNameValue("gc_tenderbidfile");
scheduledTashTash.setUpdateTime(new Date());
scheduledTashService.saveOrUpdate(scheduledTashTash,scheduledTashQueryWrapper);
}catch (Exception e){
e.printStackTrace();
}
if(!ObjectUtils.isEmpty(time)){
try {
QueryWrapper gcPerformanceQueryWrapper = new QueryWrapper();
gcPerformanceQueryWrapper.gt("DATA_TIMESTAMP",time);
int count = gcTenderbidfileService.count(gcPerformanceQueryWrapper);
Integer pageSize = 1000;
Integer pageNum = (int)Math.ceil((double)count/pageSize);
for(int i = 1; i <= pageNum;i++){
try {
List tenderDetailsVoListAll = getTenderDetailsVoListAll(i, pageSize,time);
Boolean aBoolean = gcNoticeandfileService.parseTenderDetailsVo(tenderDetailsVoListAll);
}catch (Exception e){
e.printStackTrace();
}
}
}catch (Exception e){
e.printStackTrace();
}
}
}
public List getTenderDetailsVoListAll(Integer pageNo,Integer pageSize,Long time){
Page page = new Page(pageNo, pageSize);
IPage tenderDetailsVoIPage = gcTenderbidfileService.queryGcTenderbidfileAllListByTime(page,time);
for (TenderDetailsVo record : tenderDetailsVoIPage.getRecords()) {
String noticeName = record.getNoticeName();
if(!ObjectUtils.isEmpty(noticeName)){
record.setNoticeName(noticeName);
}
record.setNoticeTypeCode(ClassIfy.BIDDING_DOCUMENTS.getCode());
record.setNoticeTypeName(ClassIfy.BIDDING_DOCUMENTS.getName());
//电力交易
if(!ObjectUtils.isEmpty(record.getSourceDataCode()) && "7089bc24".equals(record.getSourceDataCode())) {
record.setTransactionTypeCode(ClassIfy.ELECTRICITY.getCode());
record.setTransactionTypeName(ClassIfy.ELECTRICITY.getName());
}else if(!ObjectUtils.isEmpty(record.getSourceDataCode()) && "d844782a".equals(record.getSourceDataCode())) {
record.setTransactionTypeCode(ClassIfy.WEITUO.getCode());
record.setTransactionTypeName(ClassIfy.WEITUO.getName());
}else {
record.setTransactionTypeCode(ClassIfy.ENGINEERING_CONSTRUCTION.getCode());
record.setTransactionTypeName(ClassIfy.ENGINEERING_CONSTRUCTION.getName());
}
record = tenderDetailsVoService.getTenderDetailsVoAllOrther(record);
try {
String bidSectionCodes = record.getBidSectionCodes();
int i1 = bidSectionCodes.indexOf(",");
int i2 = bidSectionCodes.indexOf(";");
int i3 = bidSectionCodes.indexOf("
");
int i4 = bidSectionCodes.indexOf("ltbrgt");
String splitBidSectionCode = null;
boolean flag = false;
String[] split = null;
if(i1 > 0){
split = bidSectionCodes.split(",");
flag = true;
}
if(i2 > 0){
split = bidSectionCodes.split(";");
flag = true;
}
if(i3 > 0){
split = bidSectionCodes.split("
");
flag = true;
}
if(i4 > 0){
split = bidSectionCodes.split("ltbrgt");
flag = true;
}
if(!flag){
split = new String[]{bidSectionCodes};
}
List attachmentList = new ArrayList();
if(record.getDataTimestamp()>20250324000000L){
//通过标包编号查询对应的附件信息
QueryWrapper gcAttachmentQueryWrapper3 = new QueryWrapper();
// gcAttachmentQueryWrapper3.eq("ATTACHMENT_SET_CODE","TENDER_FILE");//add
gcAttachmentQueryWrapper3.eq("ASSOCIATION_CODE", record.getSourceDataKey());
gcAttachmentQueryWrapper3.notLike("ATTACHMENT_NAME","%xml");
gcAttachmentQueryWrapper3.notLike("ATTACHMENT_NAME","%nmgzf");
List list3 = gcAttachmentService.list(gcAttachmentQueryWrapper3);
/* //通过标包编号查询对应的附件信息
QueryWrapper gcAttachmentQueryWrapper = new QueryWrapper();
// gcAttachmentQueryWrapper.eq("ATTACHMENT_SET_CODE","TENDER_FILE_FILE");//add
gcAttachmentQueryWrapper.eq("ASSOCIATION_CODE", record.getSourceDataKey());
gcAttachmentQueryWrapper.notLike("ATTACHMENT_NAME","%xml");
gcAttachmentQueryWrapper.notLike("ATTACHMENT_NAME","%nmgzf");
List list = gcAttachmentService.list(gcAttachmentQueryWrapper);
//通过标包编号查询对应的附件信息
QueryWrapper gcAttachmentQueryWrapper2 = new QueryWrapper();
// gcAttachmentQueryWrapper2.eq("ATTACHMENT_SET_CODE","FILE_EX_TDOC");//add
gcAttachmentQueryWrapper2.eq("ASSOCIATION_CODE", record.getSourceDataKey());
gcAttachmentQueryWrapper2.notLike("ATTACHMENT_NAME","%xml");
gcAttachmentQueryWrapper2.notLike("ATTACHMENT_NAME","%nmgzf");
List list2 = gcAttachmentService.list(gcAttachmentQueryWrapper2);*/
if(!ObjectUtils.isEmpty(list3)){
attachmentList.addAll(list3);
}
/* if(!ObjectUtils.isEmpty(list2)){
attachmentList.addAll(list2);
}
if(!ObjectUtils.isEmpty(list)){
attachmentList.addAll(list);
}*/
}else{
if(!ObjectUtils.isEmpty(split)){
if(split.length >=1){
for (String bidSectionCode : split) {
try {
//通过标包编号查询对应的附件信息
QueryWrapper gcAttachmentQueryWrapper = new QueryWrapper();
gcAttachmentQueryWrapper.eq("ATTACHMENT_SET_CODE","TENDER_FILE_FILE");//add
gcAttachmentQueryWrapper.eq("BID_SECTION_CODE",bidSectionCode);
gcAttachmentQueryWrapper.notLike("ATTACHMENT_NAME","%xml");
gcAttachmentQueryWrapper.notLike("ATTACHMENT_NAME","%nmgzf");
List list = gcAttachmentService.list(gcAttachmentQueryWrapper);
//通过标包编号查询对应的附件信息
QueryWrapper gcAttachmentQueryWrapper2 = new QueryWrapper();
gcAttachmentQueryWrapper2.eq("ATTACHMENT_SET_CODE","FILE_EX_TDOC");//add
gcAttachmentQueryWrapper2.eq("BID_SECTION_CODE",bidSectionCode);
gcAttachmentQueryWrapper2.notLike("ATTACHMENT_NAME","%xml");
gcAttachmentQueryWrapper2.notLike("ATTACHMENT_NAME","%nmgzf");
List list2 = gcAttachmentService.list(gcAttachmentQueryWrapper2);
if(!ObjectUtils.isEmpty(list2)){
attachmentList.addAll(list2);
}
if(!ObjectUtils.isEmpty(list)){
attachmentList.addAll(list);
}
}catch (Exception e){
e.printStackTrace();
}
}
}
}
}
String noticeContent = record.getNoticeContent();
String file = "";
if(!ObjectUtils.isEmpty(attachmentList)){
if(attachmentList.size() > 0){
file = "
附件:
";
}
}
for (GcAttachment gcAttachment : attachmentList) {
try{
String attachmentName = gcAttachment.getAttachmentName();
String url = gcAttachment.getUrl();
file += ""+ attachmentName +"
";
}catch (Exception e){
e.printStackTrace();
}
}
//招标文件拼接地址
if(!ObjectUtils.isEmpty(noticeContent) && noticeContent != ""){
file = noticeContent + file;
}
record.setNoticeContent(file);
}catch (Exception e){
e.printStackTrace();
}
TenderDetailsVoUtils.isNull(record);
}
return tenderDetailsVoIPage.getRecords();
}
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
try {
if(JobLock.GcTenderbidfileFlag){
JobLock.GcTenderbidfileFlag = false;
logger.info("执行GcTenderbidfile", new SimpleDateFormat().format(new Date()));
try {
queryPageListUpdateEs();
} catch (Exception e) {
e.printStackTrace();
}
JobLock.GcTenderbidfileFlag = true;
}else{
logger.info("不执行GcTenderbidfile", new SimpleDateFormat().format(new Date()));
}
}catch (Exception e){
e.printStackTrace();
JobLock.GcTenderbidfileFlag = true;
}
}
}