Browse Source

项目上链修改

anderx 1 year ago
parent
commit
e5ef88706b

+ 6 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/ProjectTaskController.java

@@ -408,7 +408,11 @@ public class ProjectTaskController extends BaseController {
      * @return
      */
     @GetMapping("/saveTianhe")
-    public AjaxResult saveTianhe(@RequestParam("id") Long id){
-        return projectTaskService.seveText(id);
+    public AjaxResult saveTianhe(@RequestParam("id") String id){
+        if (StringUtils.isEmpty(id)){
+            return AjaxResult.error("项目编号不能为空");
+        }
+        projectTaskService.saveText(id);
+        return AjaxResult.success();
     }
 }

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/project/service/ProjectTaskService.java

@@ -25,6 +25,6 @@ public interface ProjectTaskService {
 
     boolean checkProjectNumber(ProjectTask projectTask);
 
-    AjaxResult seveText(Long id);
+    void saveText(String id);
 
 }

+ 21 - 8
ruoyi-system/src/main/java/com/ruoyi/project/service/impl/ProjectTaskServiceImpl.java

@@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Validator;
@@ -333,10 +334,23 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
 
         }
     }
+    @Override
+    @Transactional
+    public void saveText(String ids) {
+        String[] split = ids.split(",");
+        try {
+            for (String id : split) {
+                saveProjectText(Long.valueOf(id));
+                Thread.sleep(1000);
+            }
+        } catch (InterruptedException e) {
+            throw new RuntimeException("上链异常,请稍后再试");
+        }
+    }
 
 
-    @Override
-    public AjaxResult seveText(Long id) {
+
+    public void saveProjectText(Long id) throws InterruptedException {
         ProjectTask projectTask = projectTaskMapper.selectByPrimaryKey(id);
         List<ProjectStaffRecord> projectStaffRecords = projectStaffRecordMapper.selectByPidAndAid(id, null);
         Map<String,Object> map=new HashMap<>();
@@ -351,19 +365,18 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
         Integer code = (Integer) res.get("code");
         String tianheCloudUrl=null;
         if (code== HttpStatus.OK.value()){
-            try {
                 sleep(1000);
-            } catch (InterruptedException e) {
-                throw new RuntimeException(e);
-            }
+
             String certificate = tianheService.getCertificate(address, operateId);
             JSONObject certificateData = JSONObject.parseObject(certificate);
             String tianheCloudId=res.getString("data");
             log.debug(certificateData.toJSONString());
             tianheCloudUrl=certificateData.getString("data");
-            
+            if (tianheCloudUrl!=null){
+                projectTask.setTianheUrl(tianheCloudId);
+                projectTaskMapper.updateByPrimaryKey(projectTask);
+            }
         }
-        return AjaxResult.success(tianheCloudUrl);
     }
 
     private String getAddress() {