|
@@ -4,8 +4,13 @@ package com.qmth.distributed.print.api;
|
|
|
import com.qmth.boot.api.annotation.Aac;
|
|
|
import com.qmth.boot.api.annotation.BOOL;
|
|
|
import com.qmth.boot.api.constant.ApiConstant;
|
|
|
+import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.distributed.print.business.bean.flow.CustomFlowSaveDto;
|
|
|
+import com.qmth.distributed.print.business.entity.TFCustomFlow;
|
|
|
+import com.qmth.distributed.print.business.service.TFCustomFlowService;
|
|
|
+import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.teachcloud.common.util.*;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -20,8 +25,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.validation.Valid;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -39,6 +47,12 @@ import java.security.NoSuchAlgorithmException;
|
|
|
public class TFCustomFlowController {
|
|
|
private final static Logger log = LoggerFactory.getLogger(TFCustomFlowController.class);
|
|
|
|
|
|
+ @Resource
|
|
|
+ TFCustomFlowService tfCustomFlowService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ RedisUtil redisUtil;
|
|
|
+
|
|
|
@ApiOperation(value = "保存和发布流程")
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = ResultUtil.class)})
|
|
|
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
|
@@ -49,8 +63,33 @@ public class TFCustomFlowController {
|
|
|
SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
customFlowSaveDto.setSchoolAndOrgInfo(sysUser.getSchoolId(), sysUser.getOrgId());
|
|
|
log.info("customFlowSaveDto:{}", JacksonUtil.parseJson(customFlowSaveDto));
|
|
|
- log.info("customFlowSaveDto.toString:{}", customFlowSaveDto.toString());
|
|
|
- log.info("md5加密后得到id:{}", MD5Util.encoder(customFlowSaveDto.toString()));
|
|
|
+ String flowBpmnId = MD5Util.encoder(customFlowSaveDto.toString());
|
|
|
+ boolean lock = redisUtil.lock(SystemConstant.REDIS_LOCK_CUSTOM_FLOW_PREFIX + flowBpmnId, SystemConstant.REDIS_LOCK_CUSTOM_FLOW_TIME_OUT);
|
|
|
+ if (!lock) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("正在发布中,请稍候再试!");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Integer dbVersion = tfCustomFlowService.findMaxVersion(customFlowSaveDto.getSchoolId(), customFlowSaveDto.getOrgId(), customFlowSaveDto.getType());
|
|
|
+ TFCustomFlow tfCustomFlow = new TFCustomFlow(customFlowSaveDto.getSchoolId(), customFlowSaveDto.getOrgId(), customFlowSaveDto.getName(), customFlowSaveDto.getType(), customFlowSaveDto.getPublish(), JacksonUtil.parseJson(customFlowSaveDto.getCustomFlowLists()), sysUser.getId());
|
|
|
+ AtomicInteger atomicInteger = null;
|
|
|
+ if (Objects.isNull(dbVersion)) {//新增
|
|
|
+ atomicInteger = new AtomicInteger(1);
|
|
|
+ tfCustomFlow.setVersion(atomicInteger.get());
|
|
|
+ } else {//版本号递增
|
|
|
+ atomicInteger = new AtomicInteger(dbVersion);
|
|
|
+ tfCustomFlow.setVersion(atomicInteger.incrementAndGet());
|
|
|
+ }
|
|
|
+ tfCustomFlowService.save(tfCustomFlow);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ if (e instanceof ApiException) {
|
|
|
+ ResultUtil.error((ApiException) e, e.getMessage());
|
|
|
+ } else {
|
|
|
+ ResultUtil.error(e.getMessage());
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ redisUtil.releaseLock(SystemConstant.REDIS_LOCK_CUSTOM_FLOW_PREFIX + flowBpmnId);
|
|
|
+ }
|
|
|
return ResultUtil.ok(true);
|
|
|
}
|
|
|
}
|