Explorar o código

项目日志上链开发

anderx hai 1 ano
pai
achega
c066ef4ed9

+ 17 - 3
ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/ProjectTaskController.java

@@ -407,12 +407,26 @@ public class ProjectTaskController extends BaseController {
      * @param id
      * @return
      */
-    @GetMapping("/saveTianhe")
-    public AjaxResult saveTianhe(@RequestParam("id") String id){
+    @GetMapping("/saveProjectTaskTianhe")
+    public AjaxResult saveProjectTaskTianhe(@RequestParam("id") String id){
         if (StringUtils.isEmpty(id)){
             return AjaxResult.error("项目编号不能为空");
         }
-        projectTaskService.saveText(id);
+        projectTaskService.saveProjectTaskTianhe(id);
+        return AjaxResult.success();
+    }
+
+    /**
+     * 项目及日志上传天河链
+     * @param id
+     * @return
+     */
+    @GetMapping("/saveProjectStaffRecordTianhe")
+    public AjaxResult saveProjectStaffRecordTianhe(@RequestParam("id") String id){
+        if (StringUtils.isEmpty(id)){
+            return AjaxResult.error("项目日志编号不能为空");
+        }
+        projectTaskService.saveProjectStaffRecordTianhe(id);
         return AjaxResult.success();
     }
 }

+ 23 - 1
ruoyi-system/src/main/java/com/ruoyi/project/domain/ProjectStaffRecord.java

@@ -106,6 +106,11 @@ public class ProjectStaffRecord implements Serializable {
      */
     private String tianheUrl;
 
+    /**
+     * 项目存证标记 0=未上链 1=已上链
+     */
+    private Integer tianheType;
+
     private static final long serialVersionUID = 1L;
 
     /**
@@ -375,6 +380,20 @@ public class ProjectStaffRecord implements Serializable {
         this.tianheUrl = tianheUrl;
     }
 
+    /**
+     * 项目存证标记 0=未上链 1=已上链
+     */
+    public Integer getTianheType() {
+        return tianheType;
+    }
+
+    /**
+     * 项目存证标记 0=未上链 1=已上链
+     */
+    public void setTianheType(Integer tianheType) {
+        this.tianheType = tianheType;
+    }
+
     @Override
     public boolean equals(Object that) {
         if (this == that) {
@@ -405,7 +424,8 @@ public class ProjectStaffRecord implements Serializable {
             && (this.getInitDuration() == null ? other.getInitDuration() == null : this.getInitDuration().equals(other.getInitDuration()))
             && (this.getCheckDuration() == null ? other.getCheckDuration() == null : this.getCheckDuration().equals(other.getCheckDuration()))
             && (this.getCheckStatus() == null ? other.getCheckStatus() == null : this.getCheckStatus().equals(other.getCheckStatus()))
-            && (this.getTianheUrl() == null ? other.getTianheUrl() == null : this.getTianheUrl().equals(other.getTianheUrl()));
+            && (this.getTianheUrl() == null ? other.getTianheUrl() == null : this.getTianheUrl().equals(other.getTianheUrl()))
+            && (this.getTianheType() == null ? other.getTianheType() == null : this.getTianheType().equals(other.getTianheType()));
     }
 
     @Override
@@ -431,6 +451,7 @@ public class ProjectStaffRecord implements Serializable {
         result = prime * result + ((getCheckDuration() == null) ? 0 : getCheckDuration().hashCode());
         result = prime * result + ((getCheckStatus() == null) ? 0 : getCheckStatus().hashCode());
         result = prime * result + ((getTianheUrl() == null) ? 0 : getTianheUrl().hashCode());
+        result = prime * result + ((getTianheType() == null) ? 0 : getTianheType().hashCode());
         return result;
     }
 
@@ -459,6 +480,7 @@ public class ProjectStaffRecord implements Serializable {
         sb.append(", checkDuration=").append(checkDuration);
         sb.append(", checkStatus=").append(checkStatus);
         sb.append(", tianheUrl=").append(tianheUrl);
+        sb.append(", tianheType=").append(tianheType);
         sb.append(", serialVersionUID=").append(serialVersionUID);
         sb.append("]");
         return sb.toString();

+ 3 - 1
ruoyi-system/src/main/java/com/ruoyi/project/mapper/ProjectStaffRecordMapper.java

@@ -13,7 +13,7 @@ import java.util.List;
 /**
 * @author Administrator
 * @description 针对表【project_staff_record(项目人员记录表)】的数据库操作Mapper
-* @createDate 2024-06-26 16:41:31
+* @createDate 2024-06-26 16:58:49
 * @Entity com.ruoyi.project.domain.ProjectStaffRecord
 */
 public interface ProjectStaffRecordMapper {
@@ -52,4 +52,6 @@ public interface ProjectStaffRecordMapper {
     List<ProjectStaffRecord> selectByDDUidAndTime(@Param("ddUserId") Long ddUserId, @Param("clockDate") LocalDate clockDate);
 
     void mateUserRecord(@Param("collect") List<Long> collect);
+
+    void updateTianheType(List<ProjectStaffRecord> newList);
 }

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

@@ -25,6 +25,7 @@ public interface ProjectTaskService {
 
     boolean checkProjectNumber(ProjectTask projectTask);
 
-    void saveText(String id);
+    void saveProjectTaskTianhe(String id);
 
+    void saveProjectStaffRecordTianhe(String id);
 }

+ 66 - 10
ruoyi-system/src/main/java/com/ruoyi/project/service/impl/ProjectTaskServiceImpl.java

@@ -335,8 +335,7 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
         }
     }
     @Override
-    @Transactional
-    public void saveText(String ids) {
+    public void saveProjectTaskTianhe(String ids) {
         String[] split = ids.split(",");
         try {
             for (String id : split) {
@@ -348,6 +347,25 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
         }
     }
 
+    @Override
+    public void saveProjectStaffRecordTianhe(String ids) {
+        String[] split = ids.split(",");
+        try {
+            for (String id : split) {
+                saveRecordsText(Long.valueOf(id));
+                Thread.sleep(1000);
+            }
+        } catch (InterruptedException e) {
+            throw new RuntimeException("上链异常,请稍后再试");
+        }
+    }
+    public void saveRecordsText(Long id) throws InterruptedException {
+        ProjectStaffRecord projectStaffRecord = projectStaffRecordMapper.selectByPrimaryKey(Long.valueOf(id));
+        Map<String,Object> map=new HashMap<>();
+        map.put("projectStaffRecord",projectStaffRecord);
+        map.put("date", DateUtils.getTime());
+        saveText(map,null,null,projectStaffRecord);
+    }
 
 
     public void saveProjectText(Long id) throws InterruptedException {
@@ -357,6 +375,13 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
         map.put("projectTask",projectTask);
         map.put("projectStaffRecords",projectStaffRecords);
         map.put("date", DateUtils.getTime());
+        saveText(map,projectTask,projectStaffRecords,null);
+
+    }
+
+    private void saveText(Map<String, Object> map, ProjectTask projectTask,
+                          List<ProjectStaffRecord> projectStaffRecords,
+                          ProjectStaffRecord projectStaffRecord) throws InterruptedException {
         String json = JSONObject.toJSONString(map);
         String address = getAddress();
         String  operateId = DateUtils.dateTimeNow();
@@ -365,16 +390,47 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
         Integer code = (Integer) res.get("code");
         String tianheCloudUrl=null;
         if (code== HttpStatus.OK.value()){
-                sleep(1000);
-
+            sleep(1000);
             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);
+            String code2=res.getString("code");
+            if (code2.equals("200")){
+                log.debug(certificateData.toJSONString());
+                tianheCloudUrl=certificateData.getString("data");
+                if (projectTask!=null){
+                    if (StringUtils.isNotEmpty(tianheCloudUrl)){
+                        ProjectTask newPT=new ProjectTask();
+                        newPT.setTianheUrl(tianheCloudUrl);
+                        newPT.setId(projectTask.getId());
+                        projectTaskMapper.updateByPrimaryKeySelective(newPT);
+                    }
+                    pushProjectStaffRecord(projectStaffRecords);
+                }
+                if (projectStaffRecord!=null){
+                    ProjectStaffRecord newPSR=new ProjectStaffRecord();
+                    newPSR.setTianheUrl(tianheCloudUrl);
+                    newPSR.setId(projectStaffRecord.getId());
+                    projectStaffRecordMapper.updateByPrimaryKeySelective(newPSR);
+                }
+            }else {
+                log.error(res.getString("msg"));
+            }
+
+        }
+    }
+
+    /**
+     * 处理日志跟随项目上链
+     */
+    private void pushProjectStaffRecord(List<ProjectStaffRecord> projectStaffRecords) {
+        int count=50;
+        int i=0;
+        List<ProjectStaffRecord> newList=new ArrayList<>();
+        for (ProjectStaffRecord projectStaffRecord : projectStaffRecords) {
+            newList.add(projectStaffRecord);
+            if (newList.size()==count||i==projectStaffRecords.size()-1){
+                projectStaffRecordMapper.updateTianheType(newList);
+                newList.clear();
             }
         }
     }

+ 20 - 4
ruoyi-system/src/main/resources/mapper/project/ProjectStaffRecordMapper.xml

@@ -24,6 +24,7 @@
             <result property="checkDuration" column="check_duration" jdbcType="DOUBLE"/>
             <result property="checkStatus" column="check_status" jdbcType="INTEGER"/>
             <result property="tianheUrl" column="tianhe_url" jdbcType="VARCHAR"/>
+            <result property="tianheType" column="tianhe_type" jdbcType="INTEGER"/>
     </resultMap>
 
     <sql id="Base_Column_List">
@@ -33,7 +34,7 @@
         duration,examine_id,examine_time,
         examine_name,record_time,examine_content,
         init_duration,check_duration,check_status,
-        tianhe_url
+        tianhe_url,tianhe_type
     </sql>
 
     <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
@@ -55,14 +56,14 @@
         ,duration,examine_id,examine_time
         ,examine_name,record_time,examine_content
         ,init_duration,check_duration,check_status
-        ,tianhe_url)
+        ,tianhe_url,tianhe_type)
         values (#{id,jdbcType=BIGINT},#{pid,jdbcType=BIGINT},#{aid,jdbcType=BIGINT}
         ,#{name,jdbcType=VARCHAR},#{projectStatus,jdbcType=INTEGER},#{content,jdbcType=VARCHAR}
         ,#{annexUrl,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP},#{processStatus,jdbcType=INTEGER}
         ,#{duration,jdbcType=DOUBLE},#{examineId,jdbcType=BIGINT},#{examineTime,jdbcType=TIMESTAMP}
         ,#{examineName,jdbcType=VARCHAR},#{recordTime,jdbcType=TIMESTAMP},#{examineContent,jdbcType=VARCHAR}
         ,#{initDuration,jdbcType=DOUBLE},#{checkDuration,jdbcType=DOUBLE},#{checkStatus,jdbcType=INTEGER}
-        ,#{tianheUrl,jdbcType=VARCHAR})
+        ,#{tianheUrl,jdbcType=VARCHAR},#{tianheType,jdbcType=INTEGER})
     </insert>
     <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ruoyi.project.domain.ProjectStaffRecord" useGeneratedKeys="true">
         insert into project_staff_record
@@ -86,6 +87,7 @@
                 <if test="checkDuration != null">check_duration,</if>
                 <if test="checkStatus != null">check_status,</if>
                 <if test="tianheUrl != null">tianhe_url,</if>
+                <if test="tianheType != null">tianhe_type,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
                 <if test="id != null">#{id,jdbcType=BIGINT},</if>
@@ -107,6 +109,7 @@
                 <if test="checkDuration != null">#{checkDuration,jdbcType=DOUBLE},</if>
                 <if test="checkStatus != null">#{checkStatus,jdbcType=INTEGER},</if>
                 <if test="tianheUrl != null">#{tianheUrl,jdbcType=VARCHAR},</if>
+                <if test="tianheType != null">#{tianheType,jdbcType=INTEGER},</if>
         </trim>
     </insert>
     <update id="updateByPrimaryKeySelective" parameterType="com.ruoyi.project.domain.ProjectStaffRecord">
@@ -166,6 +169,9 @@
                 <if test="tianheUrl != null">
                     tianhe_url = #{tianheUrl,jdbcType=VARCHAR},
                 </if>
+                <if test="tianheType != null">
+                    tianhe_type = #{tianheType,jdbcType=INTEGER},
+                </if>
         </set>
         where   id = #{id,jdbcType=BIGINT} 
     </update>
@@ -189,7 +195,8 @@
             init_duration =  #{initDuration,jdbcType=DOUBLE},
             check_duration =  #{checkDuration,jdbcType=DOUBLE},
             check_status =  #{checkStatus,jdbcType=INTEGER},
-            tianhe_url =  #{tianheUrl,jdbcType=VARCHAR}
+            tianhe_url =  #{tianheUrl,jdbcType=VARCHAR},
+            tianhe_type =  #{tianheType,jdbcType=INTEGER}
         where   id = #{id,jdbcType=BIGINT} 
     </update>
     <select id="selectList" resultType="com.ruoyi.project.bo.ProjectStaffRecordOut">
@@ -325,5 +332,14 @@
             #{e}
         </foreach>
     </update>
+    <update id="updateTianheType">
+        update project_staff_record
+        set tianhe_type=1
+        where tianhe_type=0
+        and id in
+        <foreach collection="collect" open="(" close=")" separator="," item="e">
+            #{e.id}
+        </foreach>
+    </update>
 
 </mapper>