فهرست منبع

自定义流程接口新增

wangliang 3 سال پیش
والد
کامیت
2dca7d47be

+ 1 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TFCustomFlow.java

@@ -56,6 +56,7 @@ public class TFCustomFlow extends BaseEntity implements Serializable {
     private String flowKey;
 
     @ApiModelProperty(value = "流程版本id")
+    @TableField(value = "act_flow_id", updateStrategy = FieldStrategy.IGNORED)
     private String actFlowId;
 
     @ApiModelProperty(value = "流程过程变量数据")

+ 10 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/TFCustomFlowEntityService.java

@@ -3,6 +3,8 @@ package com.qmth.distributed.print.business.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.distributed.print.business.entity.TFCustomFlowEntity;
 
+import java.util.List;
+
 /**
  * <p>
  * 自定义流程列表 服务类
@@ -28,4 +30,12 @@ public interface TFCustomFlowEntityService extends IService<TFCustomFlowEntity>
      * @return
      */
     TFCustomFlowEntity findByFlowId(Long flowId);
+
+    /**
+     * 根据自定义流程id查找list
+     *
+     * @param customFlowId
+     * @return
+     */
+    List<TFCustomFlowEntity> findListByCustomFlowId(Long customFlowId);
 }

+ 3 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ActivitiServiceImpl.java

@@ -2047,6 +2047,7 @@ public class ActivitiServiceImpl implements ActivitiService {
                 }
             }
         }
+        flowProcessVarMap.put(SystemConstant.VERSION, version);
         //生成图像信息
         new BpmnAutoLayout(model).execute();
 
@@ -2215,6 +2216,7 @@ public class ActivitiServiceImpl implements ActivitiService {
         map.computeIfAbsent(SystemConstant.FLOW_ENTITY_ID, v -> String.valueOf(tfCustomFlowEntity.getId()));
         map.computeIfAbsent(SystemConstant.APPROVE_ID, v -> String.valueOf(approveId));
         map.computeIfAbsent(SystemConstant.EXAM_TASK_ID, v -> taskId);
+        map.computeIfAbsent(SystemConstant.CUSTOM_FLOW_ID, v -> tfCustomFlow.getId());
         this.flowStart(map);
 
         tfCustomFlow.setActFlowId((String) map.get(SystemConstant.PROCESS_DEFINITION_ID));
@@ -2224,6 +2226,7 @@ public class ActivitiServiceImpl implements ActivitiService {
         map.remove(SystemConstant.FLOW_ENTITY_ID);
         map.remove(SystemConstant.PROCESS_DEFINITION_ID);
         map.remove(SystemConstant.FLOW_STATUS);
+        map.computeIfAbsent(SystemConstant.ACT_FLOW_ID, v -> tfCustomFlow.getActFlowId());
         tfCustomFlowEntity.setFlowProcessVar(JacksonUtil.parseJson(map));
         tfCustomFlow.setUpdateId(sysUser.getId());
         tfCustomFlowEntityService.save(tfCustomFlowEntity);

+ 15 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TFCustomFlowEntityServiceImpl.java

@@ -7,6 +7,8 @@ import com.qmth.distributed.print.business.mapper.TFCustomFlowEntityMapper;
 import com.qmth.distributed.print.business.service.TFCustomFlowEntityService;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  * 自定义流程列表 服务实现类
@@ -43,4 +45,17 @@ public class TFCustomFlowEntityServiceImpl extends ServiceImpl<TFCustomFlowEntit
         tfCustomFlowListQueryWrapper.lambda().eq(TFCustomFlowEntity::getFlowId, flowId);
         return this.getOne(tfCustomFlowListQueryWrapper);
     }
+
+    /**
+     * 根据自定义流程id查找list
+     *
+     * @param customFlowId
+     * @return
+     */
+    @Override
+    public List<TFCustomFlowEntity> findListByCustomFlowId(Long customFlowId) {
+        QueryWrapper<TFCustomFlowEntity> tfCustomFlowListQueryWrapper = new QueryWrapper<>();
+        tfCustomFlowListQueryWrapper.lambda().eq(TFCustomFlowEntity::gettFCustomFlowId, customFlowId);
+        return this.list(tfCustomFlowListQueryWrapper);
+    }
 }

+ 6 - 12
distributed-print-business/src/main/resources/mapper/TFCustomFlowMapper.xml

@@ -36,24 +36,18 @@
     </select>
 
     <select id="list" resultType="com.qmth.distributed.print.business.entity.TFCustomFlow">
-        select
-            tfcf.id,
-            tfcf.school_id as schoolId,
-            tfcf.org_id as orgId,
-            tfcf.name,
-            tfcf.enable,
-            tfcf.publish
-        from <where>
+        select tfcf.id,tfcf.school_id as schoolId,tfcf.org_id as orgId,tfcf.name,tfcf.enable,tfcf.publish from t_f_custom_flow tfcf
+        <where>
             <if test="schoolId != null and schoolId != ''">
-                and tff.school_id = #{schoolId}
+                and tfcf.school_id = #{schoolId}
             </if>
             <if test="name != null and name != ''">
-                and tff.name like concat('%',#{name},'%')
+                and tfcf.name like concat('%',#{name},'%')
             </if>
-            and tff.enable = 1
             <if test="orgId != null and orgId != ''">
-                and tff.org_id = #{orgId}
+                and tfcf.org_id = #{orgId}
             </if>
+            and tfcf.enable = 1
         </where>
     </select>
 

+ 24 - 5
distributed-print/src/main/java/com/qmth/distributed/print/api/TFCustomFlowController.java

@@ -12,20 +12,24 @@ import com.qmth.distributed.print.business.bean.params.customFlowParam;
 import com.qmth.distributed.print.business.bean.result.FlowTaskApprovePeopleAllResult;
 import com.qmth.distributed.print.business.bean.result.FlowTaskResult;
 import com.qmth.distributed.print.business.entity.TFCustomFlow;
+import com.qmth.distributed.print.business.entity.TFCustomFlowEntity;
 import com.qmth.distributed.print.business.entity.TFFlowApprove;
 import com.qmth.distributed.print.business.service.ActivitiService;
+import com.qmth.distributed.print.business.service.TFCustomFlowEntityService;
 import com.qmth.distributed.print.business.service.TFCustomFlowService;
 import com.qmth.distributed.print.business.service.TFFlowApproveService;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicSchool;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+import com.qmth.teachcloud.common.enums.FieldUniqueEnum;
 import com.qmth.teachcloud.common.enums.FlowStatusEnum;
 import com.qmth.teachcloud.common.service.CommonCacheService;
 import com.qmth.teachcloud.common.util.*;
 import io.swagger.annotations.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.dao.DuplicateKeyException;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.BindingResult;
 import org.springframework.validation.annotation.Validated;
@@ -36,10 +40,7 @@ import javax.validation.Valid;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
 import java.security.NoSuchAlgorithmException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 
 /**
@@ -73,6 +74,9 @@ public class TFCustomFlowController {
     @Resource
     TFFlowApproveService tfFlowApproveService;
 
+    @Resource
+    TFCustomFlowEntityService tfCustomFlowEntityService;
+
     @ApiOperation(value = "保存和发布流程")
     @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = ResultUtil.class)})
     @RequestMapping(value = "/save", method = RequestMethod.POST)
@@ -97,7 +101,12 @@ public class TFCustomFlowController {
                 tfCustomFlow = new TFCustomFlow(customFlowSaveDto.getSchoolId(), customFlowSaveDto.getOrgId(), customFlowSaveDto.getName(), customFlowSaveDto.getType(), customFlowSaveDto.getPublish(), JacksonUtil.parseJson(customFlowSaveDto.getCustomFlowLists()), sysUser.getId(), flowBpmnId);
             } else {
                 tfCustomFlow = tfCustomFlowService.getById(customFlowSaveDto.getCustomFlowId());
+                Optional.ofNullable(tfCustomFlow).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("自定义流程数据为空"));
+                if (!tfCustomFlow.getEnable()) {
+                    throw ExceptionResultEnum.ERROR.exception("自定义流程数据已删除");
+                }
                 tfCustomFlow.updateInfo(sysUser.getId());
+                tfCustomFlow.setActFlowId(null);
             }
             AtomicInteger atomicInteger = null;
             if (Objects.isNull(dbTfCustomFlow)) {//新增
@@ -113,7 +122,11 @@ public class TFCustomFlowController {
             tfCustomFlowService.saveOrUpdate(tfCustomFlow);
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
-            if (e instanceof ApiException) {
+            if (e instanceof DuplicateKeyException) {
+                String errorColumn = e.getCause().toString();
+                String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
+                throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
+            } else if (e instanceof ApiException) {
                 ResultUtil.error((ApiException) e, e.getMessage());
             } else {
                 ResultUtil.error(e.getMessage());
@@ -227,6 +240,12 @@ public class TFCustomFlowController {
         }
         TFCustomFlow tfCustomFlow = tfCustomFlowService.getById(customFlowParam.getId());
         Optional.ofNullable(tfCustomFlow).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("自定义流程数据为空"));
+        if (!customFlowParam.getEnable()) {
+            List<TFCustomFlowEntity> tfCustomFlowEntityList = tfCustomFlowEntityService.findListByCustomFlowId(customFlowParam.getId());
+            if (Objects.nonNull(tfCustomFlowEntityList) && tfCustomFlowEntityList.size() > 0) {
+                throw ExceptionResultEnum.ERROR.exception("已存在流程数据,不能删除");
+            }
+        }
         tfCustomFlow.setEnable(customFlowParam.getEnable());
         return ResultUtil.ok(tfCustomFlowService.updateById(tfCustomFlow));
     }

+ 2 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java

@@ -59,6 +59,8 @@ public class SystemConstant {
     public static final String MODEL = "model";
     public static final String VERSION = "version";
     public static final String FLOW_ENTITY_ID = "flowEntityId";
+    public static final String CUSTOM_FLOW_ID = "customFlowId";
+    public static final String ACT_FLOW_ID = "actFlowId";
     public static final String FLOW_PROCESS_VAR_MAP = "flowProcessVarMap";
     public static final String PROCESS_DEFINITION_ID = "processDefinitionId";
     public static final String FILE = "file";

+ 3 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/enums/FieldUniqueEnum.java

@@ -31,7 +31,9 @@ public enum FieldUniqueEnum {
 
     semester_schoolId_name_idx("学期名称"),
 
-    student_schoolId_code_orgId_idx("学生学号");
+    student_schoolId_code_orgId_idx("学生学号"),
+
+    custom_flow_schoolId_type_idx("流程类型");
 
     private String title;