|
@@ -1,5 +1,6 @@
|
|
|
package org.springblade.business.sync;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
@@ -14,13 +15,16 @@ import org.springblade.business.service.IInformationQueryService;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.redis.cache.BladeRedis;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.manager.entity.WbsTreeSynchronousRecord;
|
|
|
import org.springblade.manager.feign.ExcelTabClient;
|
|
|
+import org.springblade.system.user.feign.IUserClient;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
@@ -40,42 +44,83 @@ public class TaskSync {
|
|
|
@Resource(name = "taskExecutor1")
|
|
|
private ThreadPoolExecutor executor;
|
|
|
|
|
|
+ //用户
|
|
|
+ @Resource
|
|
|
+ private IUserClient userClient;
|
|
|
|
|
|
- public void reSigningEVisaStatusSync(List<InformationQuery> dtos) {
|
|
|
+
|
|
|
+ public void reSigningEVisaStatusSync(List<InformationQuery> dtos, String header) {
|
|
|
log.info("数据正在重刷,线程名称:{}", Thread.currentThread().getName());
|
|
|
|
|
|
for (InformationQuery dto : dtos) {
|
|
|
informationQueryService.update(new LambdaUpdateWrapper<InformationQuery>()
|
|
|
.eq(InformationQuery::getId, dto.getId())
|
|
|
.set(InformationQuery::getEVisaPdfUrl, null)
|
|
|
+ .set(InformationQuery::getUpdateTime, DateTime.now())
|
|
|
+
|
|
|
.set(InformationQuery::getPdfUrl, null));
|
|
|
- R result = this.saveNodePdf(dto.getClassify() + "", dto.getWbsId() + "", dto.getContractId() + "", dto.getProjectId() + "", null);
|
|
|
+ R result = this.saveNodePdf(dto.getClassify() + "", dto.getWbsId() + "", dto.getContractId() + "", dto.getProjectId() + "", header);
|
|
|
|
|
|
LambdaUpdateWrapper<InformationQuery> lambda = Wrappers.<InformationQuery>update().lambda();
|
|
|
if (result == null || result.getCode() != 200) {
|
|
|
//重签失败
|
|
|
lambda.set(InformationQuery::getSaveAgain, 3)
|
|
|
.set(InformationQuery::getEVisaPdfUrl, dto.getEVisaPdfUrl())
|
|
|
+ .setSql("save_again_count = save_again_count + 1")
|
|
|
.set(InformationQuery::getPdfUrl, dto.getPdfUrl());
|
|
|
} else {
|
|
|
//成功重签
|
|
|
lambda.set(InformationQuery::getSaveAgain, 2);
|
|
|
}
|
|
|
+ lambda.set(InformationQuery::getUpdateTime, DateTime.now());
|
|
|
lambda.eq(InformationQuery::getId, dto.getId());
|
|
|
+
|
|
|
informationQueryService.update(lambda);
|
|
|
}
|
|
|
log.info("数据重刷完毕,线程名称:{}", Thread.currentThread().getName());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 定时检查save-again = 1 的数据 查看更新时间与当前时间是否超过30分钟,如果超过 30分钟,则修改状态为0
|
|
|
+ * 一个小时检查一次
|
|
|
+ */
|
|
|
+ @Scheduled(cron = "0 0 * * * ?")
|
|
|
+ public void updateStuckTask(){
|
|
|
+ List<InformationQuery> list = informationQueryService.list(Wrappers.<InformationQuery>lambdaQuery()
|
|
|
+ .eq(InformationQuery::getSaveAgain, 1)
|
|
|
+ .eq(InformationQuery::getIsDeleted, 0));
|
|
|
+
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ for (InformationQuery informationQuery : list) {
|
|
|
+ //更新时间 + 半个小时 < 当前时间
|
|
|
+ if (informationQuery.getUpdateTime().getTime() + 1800000 < System.currentTimeMillis()) {
|
|
|
+ ids.add(informationQuery.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ informationQueryService.update(null, Wrappers.<InformationQuery>lambdaUpdate()
|
|
|
+ .set(InformationQuery::getSaveAgain, 0)
|
|
|
+ .in(InformationQuery::getId, ids));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 重刷定时任务 使用多线程的方式去跑
|
|
|
*/
|
|
|
@Scheduled(fixedDelay = 60000)
|
|
|
public void saveAgainTask() {
|
|
|
+ //获取token
|
|
|
+ String header = userClient.getTokenByUser("admin");
|
|
|
+
|
|
|
List<InformationQuery> list = informationQueryService.list(Wrappers.<InformationQuery>lambdaQuery()
|
|
|
.in(InformationQuery::getSaveAgain, 0, 3)
|
|
|
.eq(InformationQuery::getIsDeleted, 0)
|
|
|
+ //失败重刷次数小于5次
|
|
|
+ .lt(InformationQuery::getSaveAgainCount, 5)
|
|
|
.last("limit 50"));
|
|
|
+ if(CollectionUtils.isEmpty(list)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
List<List<InformationQuery>> partition = Lists.partition(list, 10);
|
|
|
|
|
@@ -84,12 +129,13 @@ public class TaskSync {
|
|
|
//修改状态之后开始重刷
|
|
|
boolean update = informationQueryService.update(Wrappers.<InformationQuery>update().lambda()
|
|
|
.set(InformationQuery::getSaveAgain, 1)
|
|
|
+ .set(InformationQuery::getUpdateTime, DateTime.now())
|
|
|
.in(InformationQuery::getId, collect));
|
|
|
if (update) {
|
|
|
CompletableFuture.runAsync(() -> {
|
|
|
try {
|
|
|
/*===============执行批量任务===============*/
|
|
|
- this.reSigningEVisaStatusSync(informationQueries);
|
|
|
+ this.reSigningEVisaStatusSync(informationQueries, header);
|
|
|
} catch (Exception e) {
|
|
|
log.error("执行重刷任务失败,任务ID列表:{}", collect, e);
|
|
|
// 可选:回滚状态或标记为失败
|
|
@@ -109,9 +155,6 @@ public class TaskSync {
|
|
|
|
|
|
R saveNodePdf(String classify, String nodePKeyIds, String contractId, String projectId, String header) {
|
|
|
try {
|
|
|
- //创建一个历史用户token用户调用其他地方的controller TODO 用户问题待解决
|
|
|
- header = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZW5hbnRfaWQiOiIwMDAwMDAiLCJ1c2VyX25hbWUiOiJsaWhiIiwicmVhbF9uYW1lIjoi5p2O5rW35YW1IiwiYXZhdGFyIjoiIiwiYXV0aG9yaXRpZXMiOlsiYWRtaW5pc3RyYXRvciJdLCJjbGllbnRfaWQiOiJjbGllbnQiLCJyb2xlX25hbWUiOiJhZG1pbmlzdHJhdG9yIiwibGljZW5zZSI6InBvd2VyZWQgYnkgYmxhZGV4IiwicG9zdF9pZCI6IiIsInVzZXJfaWQiOiIxOTEyNzE1MDg3NjU0Mzk1OTA2Iiwicm9sZV9pZCI6IjExMjM1OTg4MTY3Mzg2NzUyMDEiLCJwaG9uZSI6IjE1MzIwMjU2NTEzIiwic2NvcGUiOlsiYWxsIl0sIm5pY2tfbmFtZSI6Iuadjua1t-WFtSIsIm9hdXRoX2lkIjoiIiwiZGV0YWlsIjp7InR5cGUiOiJ3ZWIifSwiZXhwIjoxNzUzNDUyNjIyLCJkZXB0X2lkIjoiMTUzNjk4MzA1NjM2MjM4MTMxMyIsImp0aSI6Ijc0ZjhkOGE5LWMwZWItNDI4Ni04NGFhLTBhMGI2ODMzMjc3NCIsImFjY291bnQiOiJsaWhiIn0.A9GM1dCZkww-HJoZvwe4yLV8fPA80lPOvfgd-gZyumI";
|
|
|
-
|
|
|
return excelTabClient.synPDFInfo(contractId, nodePKeyIds, classify, projectId, header);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|