Browse Source

质检-资料查询-save-again
1、重刷功能改成定时任务的形式执行
2、获取admin用户的token信息
3、u_information_query 添加字段save_again,save_again_count

LHB 2 weeks ago
parent
commit
20c9d049ca

+ 3 - 0
blade-service-api/blade-business-api/src/main/java/org/springblade/business/entity/InformationQuery.java

@@ -140,4 +140,7 @@ public class InformationQuery extends BaseEntity {
 
     @ApiModelProperty("重刷状态 0-待重刷,1-正在重刷,2-重刷成功,3-重刷失败")
     private Integer saveAgain;
+
+    @ApiModelProperty("重刷次数:如果次数大于5次 每次都是3,就停止重刷")
+    private Integer saveAgainCount;
 }

+ 2 - 1
blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/feign/IUserClient.java

@@ -185,5 +185,6 @@ public interface IUserClient {
     @GetMapping(API_PREFIX + "/clearContractLocalCacheAndRedisCache")
     void clearContractLocalCacheAndRedisCache();
 
-
+    @GetMapping(API_PREFIX + "/getTokenByUser")
+    String getTokenByUser(@RequestParam String account);
 }

+ 49 - 6
blade-service/blade-business/src/main/java/org/springblade/business/sync/TaskSync.java

@@ -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();

+ 64 - 0
blade-service/blade-user/src/main/java/org/springblade/system/user/controller/UserController.java

@@ -751,4 +751,68 @@ public class UserController {
         }
         return this.getLoginInfo(Authorization, userInfo);
     }
+
+
+    /**
+     * 项目内部获取用户接口
+     * @param account
+     * @param type
+     * @param tenantId
+     * @param request
+     * @return
+     */
+    @PostMapping("/loginByToken4")
+    @ApiOperationSupport(order = 20)
+    @ApiOperation(value = "token验证加密", notes = "token验证登录")
+    public R loginByToken4(String account,Integer type, String tenantId, HttpServletRequest request) {
+        if(account==null || Func.isNull(account) || Func.isEmpty(account)){
+            return R.fail("account值不能为空");
+        }
+        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("account", account);
+        queryWrapper.eq("sys_type", type == null ? 2 : type);
+        if(StringUtil.isNotBlank(tenantId)){
+            queryWrapper.eq("tenant_id", tenantId);
+        }
+        queryWrapper.last("limit 1");
+        User userInfo = userService.getOne(queryWrapper);
+        if (userInfo == null) {
+            return R.fail("用户名或密码错误");
+        }
+
+        String Authorization = request == null ? null : request.getHeader("Authorization");
+
+        if (Authorization == null || StringUtil.isEmpty(Authorization)) {
+            String useType = userInfo.getUserType();
+            List<String> strList = Func.toStrList(useType);
+            for(String sys_id:strList){
+                String dataInfo = "";
+                if(sys_id.equals("1")){ //质量/试验平台
+                    dataInfo ="client:client_secret";
+                }else if(sys_id.equals("2")){ //APP端
+                    dataInfo ="uni-app:app_secret";
+                }else if(sys_id.equals("3")){ //档案平台"
+                    dataInfo ="archives:archives_secret";
+                }else if(sys_id.equals("4")){ //后台管理端"
+                    dataInfo ="saber:saber_secret";
+                }else if(sys_id.equals("5")){ //成本管控系统"
+                    dataInfo ="hac:hac_secret";
+                }else if(sys_id.equals("6")){ //征拆系统"
+                    dataInfo ="lar:lar_secret";
+                }else if(sys_id.equals("7")){ //计量系统"
+                    dataInfo ="measure:measure_secret";
+                }else if(sys_id.equals("8")){ //安全系统"
+                    dataInfo ="measure:measure_secret";
+                }
+                Authorization = "Basic "+Func.encodeBase64(dataInfo);
+                //Basic bWVhc3VyZTptZWFzdXJlX3NlY3JldA==
+                //Basic bWVhc3VyZTptZWFzdXJlX3NlY3JldA==
+                R loginInfo = this.getLoginInfo(Authorization, userInfo);
+                if(loginInfo.getCode()==200){
+                    return loginInfo;
+                }
+            }
+        }
+        return this.getLoginInfo(Authorization,userInfo);
+    }
 }

+ 14 - 0
blade-service/blade-user/src/main/java/org/springblade/system/user/feign/UserClient.java

@@ -16,12 +16,15 @@
  */
 package org.springblade.system.user.feign;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.AllArgsConstructor;
 import org.springblade.core.tenant.annotation.NonDS;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.manager.dto.SaveUserInfoByProjectDTO;
+import org.springblade.system.user.bean.ResultCYData;
+import org.springblade.system.user.controller.UserController;
 import org.springblade.system.user.dto.UserDTO;
 import org.springblade.system.user.entity.User;
 import org.springblade.system.user.entity.UserInfo;
@@ -46,6 +49,7 @@ import java.util.List;
 public class UserClient implements IUserClient {
 
     private final IUserService service;
+    private final UserController userController;
 
     @Override
     public List<User> findUserInfoList() {
@@ -149,5 +153,15 @@ public class UserClient implements IUserClient {
         service.clearContractLocalCacheAndRedisCache();
     }
 
+    @Override
+    public String getTokenByUser(String account) {
+        R r = userController.loginByToken4(account, 1,"000000",null);
+        if(r.isSuccess()){
+            JSONObject data = (JSONObject) r.getData();
+            return (String) data.get("access_token");
+        } else {
 
+            return null;
+        }
+    }
 }