浏览代码

新增派单sop发布

wangliang 1 年之前
父节点
当前提交
b02e8705d6

+ 60 - 5
sop-api/src/main/java/com/qmth/sop/server/api/TBCrmDetailController.java

@@ -66,7 +66,25 @@ public class TBCrmDetailController {
         if (bindingResult.hasErrors()) {
             return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
         }
-        return ResultUtil.ok(tbCrmDetailService.sopVarSave(crmDetailSopParam));
+        boolean lock = memoryLock.lock(SystemConstant.LOCK_CRM_DETAIL_SOP_VAR_PREFIX + crmDetailSopParam.getCrmNo(),
+                crmDetailSopParam.getCrmNo(), SystemConstant.LOCK_CRM_DETAIL_SOP_TIME_OUT);
+        if (!lock) {
+            throw ExceptionResultEnum.ERROR.exception("正在保存数据,请稍候再试!");
+        }
+        boolean result = false;
+        try {
+            result = tbCrmDetailService.sopVarSave(crmDetailSopParam);
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        } finally {
+            memoryLock.unlock(SystemConstant.LOCK_CRM_DETAIL_SOP_VAR_PREFIX + crmDetailSopParam.getCrmNo());
+        }
+        return ResultUtil.ok(result);
     }
 
     @ApiOperation(value = "获取派单明细sop信息")
@@ -88,7 +106,27 @@ public class TBCrmDetailController {
         if (bindingResult.hasErrors()) {
             return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
         }
-        return ResultUtil.ok(tbCrmDetailService.sopSave(tbCrmDetail));
+        boolean lock = memoryLock.lock(SystemConstant.LOCK_CRM_DETAIL_SOP_CREATE_PREFIX + tbCrmDetail.getCrmNo() + "_"
+                        + tbCrmDetail.getCourseName(), tbCrmDetail.getCrmNo() + "_" + tbCrmDetail.getCourseName(),
+                SystemConstant.LOCK_CRM_DETAIL_SOP_TIME_OUT);
+        if (!lock) {
+            throw ExceptionResultEnum.ERROR.exception("正在保存数据,请稍候再试!");
+        }
+        boolean result = false;
+        try {
+            result = tbCrmDetailService.sopSave(tbCrmDetail);
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        } finally {
+            memoryLock.unlock(SystemConstant.LOCK_CRM_DETAIL_SOP_CREATE_PREFIX + tbCrmDetail.getCrmNo() + "_"
+                    + tbCrmDetail.getCourseName());
+        }
+        return ResultUtil.ok(result);
     }
 
     @ApiOperation(value = "编辑派单明细sop")
@@ -105,9 +143,26 @@ public class TBCrmDetailController {
     @RequestMapping(value = "/sop/publish", method = RequestMethod.POST)
     @OperationLog(logType = LogTypeEnum.EDIT)
     @ApiResponses({ @ApiResponse(code = 200, message = "派单明细sop发布", response = EditResult.class) })
-    public Result sopPublish(@ApiParam(value = "派单明细sopId", required = true) @RequestParam Long id)
-            throws InterruptedException {
-        return ResultUtil.ok(tbCrmDetailService.sopPublish(id));
+    public Result sopPublish(@ApiParam(value = "派单明细sopId", required = true) @RequestParam Long id) {
+        boolean lock = memoryLock.lock(SystemConstant.LOCK_CRM_DETAIL_SOP_PUBLISH_PREFIX + id, id,
+                SystemConstant.LOCK_CRM_DETAIL_SOP_TIME_OUT);
+        if (!lock) {
+            throw ExceptionResultEnum.ERROR.exception("正在保存数据,请稍候再试!");
+        }
+        boolean result = false;
+        try {
+            result = tbCrmDetailService.sopPublish(id);
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        } finally {
+            memoryLock.unlock(SystemConstant.LOCK_CRM_DETAIL_SOP_PUBLISH_PREFIX + id);
+        }
+        return ResultUtil.ok();
     }
 
     @ApiOperation(value = "派单明细sop删除")

+ 3 - 0
sop-common/src/main/java/com/qmth/sop/common/contant/SystemConstant.java

@@ -355,6 +355,9 @@ public class SystemConstant {
     public static final String LOCK_SEQUENCE_PREFIX = "lock:sequence:";//序列锁
     public static final String LOCK_JOB_PREFIX = "lock:job:";//定时任务锁
     public static final String LOCK_CRM_DETAIL_SOP_PREFIX = "lock:crm:detail:sop:";//派单明细sop锁
+    public static final String LOCK_CRM_DETAIL_SOP_VAR_PREFIX = "lock:crm:detail:sop:var";//派单明细sop变量锁
+    public static final String LOCK_CRM_DETAIL_SOP_CREATE_PREFIX = "lock:crm:detail:sop:create";//派单明细创建sop锁
+    public static final String LOCK_CRM_DETAIL_SOP_PUBLISH_PREFIX = "lock:crm:detail:sop:publish";//派单明细创建sop锁
 
     public static final Long LOCK_FLOW_TIME_OUT = 60L * 2 * 1000;
     public static final Long LOCK_SEQUENCE_TIME_OUT = 60L * 1 * 1000;