Explorar el Código

增加合并时状态处理

欧阳劲驰 hace 2 meses
padre
commit
66260eb624

+ 2 - 0
src/main/java/com/shkpr/service/alambizplugin/constants/GisSurveyImportDefine.java

@@ -45,6 +45,8 @@ public interface GisSurveyImportDefine {
     interface DEFAULT_VALUE {
         String APPLY = "add";
         Short SOURCE = (short) (0xff);
+        Short ACTION = (short) 1;
+        Short STATUS = (short) 4;
     }
 
     /**

+ 5 - 3
src/main/java/com/shkpr/service/alambizplugin/controller/ApiGisSurveyController.java

@@ -436,6 +436,7 @@ public class ApiGisSurveyController {
      * @param strClientType 客户端类型
      * @param strUserAgent  用户信息
      * @param jobId         任务id
+     * @param operator      操作人
      * @return 清除状态
      * @throws SelfException selfException
      */
@@ -443,12 +444,13 @@ public class ApiGisSurveyController {
     public ResponseRes<?> commitImport(HttpServletRequest request
             , @RequestHeader(value = ApiURI.HEADER_CLIENT_TYPE, required = false) String strClientType
             , @RequestHeader(value = ApiURI.HEADER_USER_AGENT, required = false) String strUserAgent
-            , @RequestParam("jobId") String jobId) throws Exception {
+            , @RequestParam("jobId") String jobId, @RequestParam("operator") String operator) throws Exception {
         //入参校验
         final String URI_PATH = request.getRequestURI();
         final String strPlatform = CommTool.getPlatformByAgent(strClientType, strUserAgent);
         final String strUserId = (String) request.getAttribute(TokenAuthenticationService.HEADER_USERID);
-        if (StringUtils.isBlank(jobId) || StringUtils.length(jobId) > 64) {
+        if (StringUtils.isBlank(jobId) || StringUtils.length(jobId) > 64
+                || StringUtils.isBlank(operator) || StringUtils.length(operator) > 64) {
             throw new SelfException(ResponseCode.STATUS_ERROR_PARAM_FORMAT.toStrCode()
                     , String.format(ApiURI.EXCEPTION_FORMAT
                     , strPlatform
@@ -470,7 +472,7 @@ public class ApiGisSurveyController {
         resResult.setResmsg(ResponseCode.RESULT_THIRD_IMPORT_FAILED.toStrMsg());
 
         //提交导入
-        Boolean commitStatus = layerApplyService.mergeCopy(jobId);
+        Boolean commitStatus = layerApplyService.mergeCopy(jobId, operator);
         //成功
         if (Objects.equals(commitStatus, Boolean.TRUE)) {
             resResult.setRescode(ResponseCode.RESULT_NORMAL.toStrCode());

+ 7 - 4
src/main/java/com/shkpr/service/alambizplugin/dbdao/mapper/GisSurveyJobInfoMapper.java

@@ -22,11 +22,14 @@ public interface GisSurveyJobInfoMapper {
     LocalDateTime findRefreshTimeByUid(@Param("uid") String uid);
 
     /**
-     * 根据uid更新刷新时间
+     * 根据uid更新:刷新时间,流转状态,当前状态
      *
-     * @param uid       uid
-     * @param timestamp 时间戳
+     * @param uid         uid
+     * @param refreshTime 刷新时间
+     * @param action      流转状态
+     * @param status      当前状态
      * @return 刷新时间
      */
-    int updateRefreshTimeByUid(@Param("uid") String uid, @Param("timestamp") Long timestamp);
+    int updateRefreshTimeActionStatusByUid(@Param("uid") String uid, @Param("refreshTime") Long refreshTime
+            , @Param("action") Short action, @Param("status") Short status);
 }

+ 21 - 0
src/main/java/com/shkpr/service/alambizplugin/dbdao/mapper/GisSurveyJobStatusTrackMapper.java

@@ -0,0 +1,21 @@
+package com.shkpr.service.alambizplugin.dbdao.mapper;
+
+import com.shkpr.service.alambizplugin.dto.GisSurveyJobStatusTrack;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 采集任务状态流转mapper
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Mapper
+public interface GisSurveyJobStatusTrackMapper {
+    /**
+     * 保存
+     *
+     * @param record 对象
+     * @return 保存数量
+     */
+    int save(GisSurveyJobStatusTrack record);
+}

+ 3 - 3
src/main/java/com/shkpr/service/alambizplugin/dbdao/mapper/GisSurveyProjectInfoMapper.java

@@ -24,9 +24,9 @@ public interface GisSurveyProjectInfoMapper {
     /**
      * 根据任务id更新刷新时间
      *
-     * @param jobId     任务id
-     * @param timestamp 时间戳
+     * @param jobId       任务id
+     * @param refreshTime 刷新时间
      * @return 刷新时间
      */
-    int updateRefreshTimeByUid(@Param("jobId") String jobId, @Param("timestamp") Long timestamp);
+    int updateRefreshTimeByUid(@Param("jobId") String jobId, @Param("refreshTime") Long refreshTime);
 }

+ 58 - 14
src/main/java/com/shkpr/service/alambizplugin/dbdao/services/GisSurveyLayerApplyServiceImpl.java

@@ -2,13 +2,16 @@ package com.shkpr.service.alambizplugin.dbdao.services;
 
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
+import com.shkpr.service.alambizplugin.constants.GisSurveyImportDefine;
 import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
 import com.shkpr.service.alambizplugin.dbdao.mapper.GisSurveyJobInfoMapper;
+import com.shkpr.service.alambizplugin.dbdao.mapper.GisSurveyJobStatusTrackMapper;
 import com.shkpr.service.alambizplugin.dbdao.mapper.GisSurveyLayerApplyMapper;
 import com.shkpr.service.alambizplugin.dbdao.mapper.GisSurveyLayerApplyThirdCopyMapper;
 import com.shkpr.service.alambizplugin.dbdao.mapper.GisSurveyProjectInfoMapper;
 import com.shkpr.service.alambizplugin.dbdao.mapper.GisSurveyPropertyValueMapper;
 import com.shkpr.service.alambizplugin.dbdao.services.intef.GisSurveyLayerApplyService;
+import com.shkpr.service.alambizplugin.dto.GisSurveyJobStatusTrack;
 import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyLine;
 import com.shkpr.service.alambizplugin.dto.GisSurveyLayerApplyPoint;
 import org.apache.ibatis.cursor.Cursor;
@@ -19,6 +22,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.io.IOException;
+import java.sql.Connection;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -239,10 +243,11 @@ public class GisSurveyLayerApplyServiceImpl implements GisSurveyLayerApplyServic
     /**
      * 合并副表
      *
-     * @param jobId 任务id
+     * @param jobId    任务id
+     * @param operator 操作人
      * @return 合并结果
      */
-    public Boolean mergeCopy(String jobId) {
+    public Boolean mergeCopy(String jobId, String operator) {
         LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
                 , String.format(
                         "开始合并副表,开启session和事务 任务ID:%s"
@@ -251,14 +256,19 @@ public class GisSurveyLayerApplyServiceImpl implements GisSurveyLayerApplyServic
         );
         long begin = System.currentTimeMillis();
         //开启session
-        try (SqlSession session = sqlSessionFactory.openSession(false)) {
+        try (SqlSession sqlSession = sqlSessionFactory.openSession(false)) {
             try {
+                //设置手动提交
+                Connection conn = sqlSession.getConnection();
+                conn.setAutoCommit(false);
+
                 //获取需要的mapper
-                GisSurveyLayerApplyMapper layerApplyMapper = session.getMapper(GisSurveyLayerApplyMapper.class);
-                GisSurveyLayerApplyThirdCopyMapper layerApplyThirdCopyMapper = session.getMapper(GisSurveyLayerApplyThirdCopyMapper.class);
-                GisSurveyPropertyValueMapper propertyValueMapper = session.getMapper(GisSurveyPropertyValueMapper.class);
-                GisSurveyProjectInfoMapper projectInfoMapper = session.getMapper(GisSurveyProjectInfoMapper.class);
-                GisSurveyJobInfoMapper jobInfoMapper = session.getMapper(GisSurveyJobInfoMapper.class);
+                GisSurveyLayerApplyMapper layerApplyMapper = sqlSession.getMapper(GisSurveyLayerApplyMapper.class);
+                GisSurveyLayerApplyThirdCopyMapper layerApplyThirdCopyMapper = sqlSession.getMapper(GisSurveyLayerApplyThirdCopyMapper.class);
+                GisSurveyPropertyValueMapper propertyValueMapper = sqlSession.getMapper(GisSurveyPropertyValueMapper.class);
+                GisSurveyProjectInfoMapper projectInfoMapper = sqlSession.getMapper(GisSurveyProjectInfoMapper.class);
+                GisSurveyJobInfoMapper jobInfoMapper = sqlSession.getMapper(GisSurveyJobInfoMapper.class);
+                GisSurveyJobStatusTrackMapper jobStatusTrackMapper = sqlSession.getMapper(GisSurveyJobStatusTrackMapper.class);
 
                 //需要合并的数量
                 long mergeCount = layerApplyThirdCopyMapper.countByJobId(jobId);
@@ -270,14 +280,47 @@ public class GisSurveyLayerApplyServiceImpl implements GisSurveyLayerApplyServic
 
                 //检查合并数量
                 if (mergeCount != layerApply) {
-                    session.rollback();
+                    sqlSession.rollback();
+                    conn.rollback();
+
+                    LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
+                            , String.format(
+                                    "合并副表条数错误 开始回滚操作 任务id:%s"
+                                    , jobId
+                            )
+                    );
+
                     return false;
                 }
 
                 //更新刷新时间
                 long timestamp = System.currentTimeMillis();
-                projectInfoMapper.updateRefreshTimeByUid(jobId, timestamp);
-                jobInfoMapper.updateRefreshTimeByUid(jobId, timestamp);
+                int projectUpdated = projectInfoMapper.updateRefreshTimeByUid(jobId, timestamp);
+                int jobUpdated = jobInfoMapper.updateRefreshTimeActionStatusByUid(jobId, timestamp,
+                        GisSurveyImportDefine.DEFAULT_VALUE.ACTION, GisSurveyImportDefine.DEFAULT_VALUE.STATUS);
+                //写入任务状态
+                int jobStatusTrackSave = jobStatusTrackMapper.save(new GisSurveyJobStatusTrack(
+                        jobId, operator,
+                        GisSurveyImportDefine.DEFAULT_VALUE.ACTION, GisSurveyImportDefine.DEFAULT_VALUE.STATUS,
+                        operator, timestamp));
+                //检查更新和写入
+                if (projectUpdated <= 0 || jobUpdated <= 0 || jobStatusTrackSave <= 0) {
+                    sqlSession.rollback();
+                    conn.rollback();
+
+                    LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
+                            , String.format(
+                                    "合并副表更新任务/项目状态失败 开始回滚操作 任务id:%s"
+                                    , jobId
+                            )
+                    );
+
+                    return false;
+                }
+
+                //提交
+                sqlSession.commit();
+                conn.commit();
 
                 long end = System.currentTimeMillis();
                 LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName
@@ -287,10 +330,12 @@ public class GisSurveyLayerApplyServiceImpl implements GisSurveyLayerApplyServic
                                 , (end - begin)
                         )
                 );
-                //提交
-                session.commit();
+
                 return true;
             } catch (Exception e) {
+                //回滚
+                sqlSession.rollback();
+
                 LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
                         , String.format(
                                 "合并副表失败 开始回滚操作 任务id:%s error:%s"
@@ -299,7 +344,6 @@ public class GisSurveyLayerApplyServiceImpl implements GisSurveyLayerApplyServic
                         )
                 );
 
-                session.rollback();
                 return false;
             }
         }

+ 3 - 2
src/main/java/com/shkpr/service/alambizplugin/dbdao/services/intef/GisSurveyLayerApplyService.java

@@ -47,8 +47,9 @@ public interface GisSurveyLayerApplyService {
     /**
      * 合并副表
      *
-     * @param jobId 任务id
+     * @param jobId    任务id
+     * @param operator 操作人
      * @return 合并结果
      */
-    Boolean mergeCopy(String jobId);
+    Boolean mergeCopy(String jobId, String operator);
 }

+ 57 - 0
src/main/java/com/shkpr/service/alambizplugin/dto/GisSurveyJobStatusTrack.java

@@ -0,0 +1,57 @@
+package com.shkpr.service.alambizplugin.dto;
+
+import lombok.Data;
+
+/**
+ * 采集任务状态流转表
+ */
+@Data
+public class GisSurveyJobStatusTrack {
+    /**
+     * id
+     */
+    private Long id;
+    /**
+     * 任务id
+     */
+    private String jobId;
+
+    /**
+     * 操作人
+     */
+    private String operator;
+
+    /**
+     * 流转阶段
+     */
+    private Short action;
+
+    /**
+     * 当前状态
+     */
+    private Short status;
+
+    /**
+     * 接受者
+     */
+    private String receiver;
+
+    /**
+     * 创建时间
+     */
+    private Long createTime;
+
+    /**
+     * 评论
+     */
+    private String comment;
+
+    public GisSurveyJobStatusTrack(String jobId, String operator, Short action, Short status, String receiver, Long createTime) {
+        this.jobId = jobId;
+        this.operator = operator;
+        this.action = action;
+        this.status = status;
+        this.receiver = receiver;
+        this.createTime = createTime;
+    }
+}

+ 7 - 3
src/main/resources/mapper/GisSurveyJobInfoMapper.xml

@@ -7,9 +7,13 @@
         where uid = #{uid,jdbcType=VARCHAR};
     </select>
 
-    <update id="updateRefreshTimeByUid">
+    <update id="updateRefreshTimeActionStatusByUid">
         update k3_gis_survey_job_info
-        set refresh_time = #{timestamp,jdbcType=BIGINT}
-        where uid = #{uid,jdbcType=VARCHAR};
+        set refresh_time = #{refreshTime,jdbcType=BIGINT},
+        action=#{action,jdbcType=SMALLINT},
+        status=#{status,jdbcType=SMALLINT}
+        where uid = #{uid,jdbcType=VARCHAR}
+        and status = 2
+        and disused = 0;
     </update>
 </mapper>

+ 70 - 0
src/main/resources/mapper/GisSurveyJobStatusTrackMapper.xml

@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.shkpr.service.alambizplugin.dbdao.mapper.GisSurveyJobStatusTrackMapper">
+    <resultMap id="BaseResultMap" type="com.shkpr.service.alambizplugin.dto.GisSurveyJobStatusTrack">
+        <!--@Table k3_gis_survey_job_status_track-->
+        <id column="id" jdbcType="BIGINT" property="id"/>
+        <result column="job_id" jdbcType="VARCHAR" property="jobId"/>
+        <result column="operator" jdbcType="VARCHAR" property="operator"/>
+        <result column="action" jdbcType="SMALLINT" property="action"/>
+        <result column="status" jdbcType="SMALLINT" property="status"/>
+        <result column="receiver" jdbcType="VARCHAR" property="receiver"/>
+        <result column="create_time" jdbcType="BIGINT" property="createTime"/>
+        <result column="comment" jdbcType="VARCHAR" property="comment"/>
+    </resultMap>
+    <insert id="save" parameterType="com.shkpr.service.alambizplugin.dto.GisSurveyJobStatusTrack">
+        insert into k3_gis_survey_job_status_track
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="id != null">
+                id,
+            </if>
+            <if test="jobId != null">
+                job_id,
+            </if>
+            <if test="operator != null">
+                "operator",
+            </if>
+            <if test="action != null">
+                "action",
+            </if>
+            <if test="status != null">
+                "status",
+            </if>
+            <if test="receiver != null">
+                receiver,
+            </if>
+            <if test="createTime != null">
+                create_time,
+            </if>
+            <if test="comment != null">
+                "comment",
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="id != null">
+                #{id,jdbcType=BIGINT},
+            </if>
+            <if test="jobId != null">
+                #{jobId,jdbcType=VARCHAR},
+            </if>
+            <if test="operator != null">
+                #{operator,jdbcType=VARCHAR},
+            </if>
+            <if test="action != null">
+                #{action,jdbcType=SMALLINT},
+            </if>
+            <if test="status != null">
+                #{status,jdbcType=SMALLINT},
+            </if>
+            <if test="receiver != null">
+                #{receiver,jdbcType=VARCHAR},
+            </if>
+            <if test="createTime != null">
+                #{createTime,jdbcType=BIGINT},
+            </if>
+            <if test="comment != null">
+                #{comment,jdbcType=VARCHAR},
+            </if>
+        </trim>
+    </insert>
+</mapper>

+ 1 - 1
src/main/resources/mapper/GisSurveyProjectInfoMapper.xml

@@ -9,7 +9,7 @@
 
     <update id="updateRefreshTimeByUid">
         update k3_gis_survey_project_info pi
-        set refresh_time =#{timestamp,jdbcType=BIGINT}
+        set refresh_time = #{refreshTime,jdbcType=BIGINT}
         where exists (select 1 from k3_gis_survey_job_info ji where ji.uid=#{jobId,jdbcType=VARCHAR} )
         and pi.uid = (select proj_id from k3_gis_survey_job_info ji where ji.uid=#{jobId,jdbcType=VARCHAR} limit 1)
     </update>