lrf 8 months ago
parent
commit
0245da5b61

+ 3 - 0
src/main/java/com/free/config/ExceptionEnum.java

@@ -9,6 +9,9 @@ public enum ExceptionEnum {
   UPLOAD_FILE_NOT_FOUND("4002", "未找到上传文件"),
   UPLOAD_PATH_ERROR("4003", "上传文件地址解析失败"),
   UPLOAD_FAILED("4004", "上传文件失败"),
+  APPLY_NOT_AGREE("4005", "您的转人工申请正在等待客服人员受理,请稍等片刻"),
+  APPLY_NOT_ClOSE("4006", "您的转人工服务未关闭,无法再次进行转人工申请"),
+  NEED_CLOSE_OTHER_APPLYS("4007", "该用户存在其他受理中的转人工服务,请关闭该用户其他的转人工服务后,再受理本次转人工申请"),
   ACCOUNT_IS_EXIST("4002", "账号已存在"),
   ACCOUNT_NOT_FOUND("4011", "未找到账号信息"),
   PASSWORD_ERROR("4012", "密码错误"),

+ 53 - 2
src/main/java/com/free/controller/TransferApplyController.java

@@ -37,11 +37,38 @@ public class TransferApplyController {
   private TransferApplyService service;
   @Autowired
   private MqService mqService;
+  /** 转人工申请,受理转人工-受理申请标识 */
+  private final static String TransferApplyAgree = "0";
+  /** 转人工申请,受理转人工-拒绝申请标识 */
+  private final static String TransferApplyNotAgree = "1";
+  /** 转人工申请,受理转人工-结束标识 */
+  private final static String TransferApplyClose = "0";
+  /** 转人工申请,受理转人工-未结束标识 */
+  private final static String TransferApplyNotClose = "1";
 
   /** 创建数据 */
   @ApiOperation("创建数据")
   @PostMapping("")
   public Object save(@RequestBody @Valid TransferApply data) {
+    // 查询是否有申请但是未受理的数据
+    QueryWrapper checkHasAppplyNotAgreeQw = new QueryWrapper<>();
+    checkHasAppplyNotAgreeQw.eq("user_id", data.getUser_id());
+    checkHasAppplyNotAgreeQw.eq("is_agree", TransferApplyNotAgree);
+    Map hasApplyNotAgree = service.getMap(checkHasAppplyNotAgreeQw);
+    if (null != hasApplyNotAgree) {
+      // 抛出异常并发送mq提醒客服人员
+      mqService.sendMsgToAdminForApplyCreate(hasApplyNotAgree);
+      throw new CustomizationException(ExceptionEnum.APPLY_NOT_AGREE);
+    }
+    // 查询是否有申请但是受理中的数据
+    QueryWrapper checkHasApplyNotCloseQw = new QueryWrapper<>();
+    checkHasApplyNotCloseQw.eq("user_id", data.getUser_id());
+    checkHasApplyNotCloseQw.eq("is_agree", TransferApplyAgree);
+    checkHasApplyNotCloseQw.eq("is_close", TransferApplyNotClose);
+    Map hasApplyNotClose = service.getMap(checkHasApplyNotCloseQw);
+    if (null != hasApplyNotClose) {
+      throw new CustomizationException(ExceptionEnum.APPLY_NOT_ClOSE);
+    }
     this.service.save(data);
     QueryWrapper qw = new QueryWrapper<>();
     qw.eq("id", data.getId());
@@ -56,6 +83,22 @@ public class TransferApplyController {
   @ApiOperation("修改数据")
   @PostMapping("/{id}")
   public Object update(@PathVariable long id, @RequestBody TransferApply data) {
+    // 如果是受理申请,需要查看,除该数据外.当前申请的用户 是否有已被受理 且 未关闭 的转人工申请.
+    // 如果有: 则无法受理当前申请, 需要将之前 受理且未关闭的申请先关闭后再受理
+    String is_agree = data.getIs_agree();
+    if (TransferApplyAgree.equals(is_agree)) {
+      TransferApply oldData = this.service.getById(id);
+      QueryWrapper checkHasApplyAgreeNotCloseQw = new QueryWrapper<>();
+      checkHasApplyAgreeNotCloseQw.ne("id", id);
+      checkHasApplyAgreeNotCloseQw.eq("user_id", oldData.getUser_id());
+      checkHasApplyAgreeNotCloseQw.eq("is_agree", TransferApplyAgree);
+      checkHasApplyAgreeNotCloseQw.eq("is_close", TransferApplyNotClose);
+      Long applyAgreeNotCloseNum = service.count(checkHasApplyAgreeNotCloseQw);
+      if (applyAgreeNotCloseNum > 0) {
+        throw new CustomizationException(ExceptionEnum.NEED_CLOSE_OTHER_APPLYS);
+      }
+    }
+
     QueryWrapper qw = new QueryWrapper<>();
     qw.eq("id", id);
     Long num = this.service.count(qw);
@@ -64,7 +107,11 @@ public class TransferApplyController {
     }
     data.setId(id);
     this.service.updateById(data);
-    Object newData = this.service.getById(id);
+    TransferApply newData = this.service.getById(id);
+    // 如果审核通过了, 则需要给申请人发送mq消息.申请人需要知道是谁跟自己对话
+    if (newData.getIs_agree().equals(TransferApplyAgree)) {
+      mqService.sendMsgToApplicant(newData);
+    }
     return ResponseFormat.success(newData);
   }
 
@@ -76,6 +123,7 @@ public class TransferApplyController {
     Long skip = null, limit = null;
     Map map = new HashMap();
     QueryWrapper qw = new QueryWrapper<>();
+    qw.orderByDesc("is_close");
     /** 参数处理处理 */
     for (String key : allParams.keySet()) {
       Object value = allParams.get(key);
@@ -92,7 +140,10 @@ public class TransferApplyController {
         }
       }
     }
-    /** 分页处理 */
+    /**
+     * 分页处理
+     * TODO: 需要返回用户名称,客服名称
+     */
     if (null != skip && null != limit) {
       IPage page = new Page<>(skip, limit);
       IPage pageResult = service.page(page, qw);

+ 27 - 2
src/main/java/com/free/mq/MqService.java

@@ -11,7 +11,9 @@ import org.springframework.stereotype.Service;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.free.entity.TransferApply;
 import com.free.service.system.CustomerService;
+import com.free.utils.Utils;
 
 @Service
 public class MqService {
@@ -28,7 +30,7 @@ public class MqService {
    * @param msg   消息内容
    * @throws JsonProcessingException JSON处理异常
    */
-  public void sendMsg(String ex, String queue, Object msg) throws JsonProcessingException {
+  public void sendMsg(String ex, String queue, Map msg) throws JsonProcessingException {
     String strMsg = null;
     ObjectMapper mapper = new ObjectMapper();
     strMsg = mapper.writeValueAsString(msg);
@@ -43,11 +45,34 @@ public class MqService {
   public void sendMsgToAdminForApplyCreate(Map data) {
     String ex = MqListeners.adminExName;
     String queue = MqListeners.adminQueue;
+    Map map = new HashMap<>();
+    map.put("data", data);
+    map.put("type", "notice");
     try {
-      this.sendMsg(ex, queue, data);
+      this.sendMsg(ex, queue, map);
     } catch (JsonProcessingException e) {
       e.printStackTrace();
       log.error("转人工申请通知mq发送失败", e);
     }
   }
+
+  /**
+   * 转人工已受理通知
+   * 
+   * @param apply
+   */
+  public void sendMsgToApplicant(TransferApply apply) {
+    String ex = MqListeners.exName;
+    String routerKey = MqListeners.queueName + "." + apply.getUser_id();
+    Map map = new HashMap<>();
+    Map data = Utils.objectToMap(apply);
+    map.put("data", map);
+    map.put("type", "notice");
+    try {
+      this.sendMsg(ex, routerKey, map);
+    } catch (JsonProcessingException e) {
+      e.printStackTrace();
+      log.error("转人工申请已通过通知,mq发送失败", e);
+    }
+  }
 }