Explorar el Código

fix : 客服系统功能提交04

bilingfeng hace 1 año
padre
commit
b29ac5b372

+ 1 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/ManageApplication.java

@@ -21,7 +21,7 @@ public class ManageApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(ManageApplication.class, args);
-        System.out.println("赞象Manage服务启动成功 <客服系统03> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 <客服系统04> ( ´・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 57 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/dto/KfMsgResultDTO.java

@@ -0,0 +1,57 @@
+package com.zanxiang.game.module.manage.pojo.dto;
+
+import lombok.Data;
+
+import java.util.Objects;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-11-29
+ * @description : 客服接口返回
+ */
+@Data
+public class KfMsgResultDTO {
+
+    /**
+     * 请求成功
+     */
+    public static final Long SUCCESS = 0L;
+
+    /**
+     * 鉴权失败, token, cookie过期
+     */
+    public static final Long EXPIRE = 30000L;
+
+    /**
+     * 接口结果
+     */
+    private BaseRespBean base_resp;
+
+    @Data
+    public static class BaseRespBean {
+
+        /**
+         * 异常消息
+         */
+        private String err_msg;
+
+        /**
+         * 状态code
+         */
+        private Long ret;
+    }
+
+    public Boolean isSueecss() {
+        if (this.base_resp == null) {
+            return Boolean.FALSE;
+        }
+        return Objects.equals(this.base_resp.getRet(), KfMsgResultDTO.SUCCESS);
+    }
+
+    public Boolean isExpire() {
+        if (this.base_resp == null) {
+            return Boolean.FALSE;
+        }
+        return Objects.equals(this.base_resp.getRet(), KfMsgResultDTO.EXPIRE);
+    }
+}

+ 12 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/vo/KfGameVO.java

@@ -22,4 +22,16 @@ public class KfGameVO {
      */
     @ApiModelProperty(notes = "应用名称")
     private String appName;
+
+    /**
+     * 是否授权
+     */
+    @ApiModelProperty(notes = "是否授权")
+    private Boolean isAuth;
+
+    /**
+     * 是否有效
+     */
+    @ApiModelProperty(notes = "是否有效, isAuth 为false未授权时, 该值为null")
+    private Boolean isValid;
 }

+ 25 - 8
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfMsgContentServiceImpl.java

@@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zanxiang.erp.security.util.SecurityUtil;
+import com.zanxiang.game.module.manage.enums.KfActionEnum;
 import com.zanxiang.game.module.manage.enums.KfApiEnum;
+import com.zanxiang.game.module.manage.pojo.dto.KfMsgResultDTO;
 import com.zanxiang.game.module.manage.pojo.params.KfApiParam;
 import com.zanxiang.game.module.manage.pojo.vo.KfGameVO;
 import com.zanxiang.game.module.manage.service.IGameAppletService;
@@ -21,7 +23,6 @@ import com.zanxiang.module.util.URIUtil;
 import com.zanxiang.module.util.bean.BeanUtil;
 import com.zanxiang.module.util.exception.BaseException;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.logging.log4j.util.Strings;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
@@ -68,21 +69,37 @@ public class KfMsgContentServiceImpl extends ServiceImpl<KfMsgContentMapper, KfM
                 .eq(GameApplet::getType, 1)
                 .in(!SecurityUtil.isAdmin(), GameApplet::getGameId,
                         gameAuthList.stream().map(GameAuth::getGameId).collect(Collectors.toSet()))
-        ).stream().map(gameApplet -> BeanUtil.copy(gameApplet, KfGameVO.class)).collect(Collectors.toList());
+        ).stream().map(this::toVO).collect(Collectors.toList());
+    }
+
+    private KfGameVO toVO(GameApplet gameApplet) {
+        KfGameVO kfGameVO = BeanUtil.copy(gameApplet, KfGameVO.class);
+        if (kfGameVO == null) {
+            return null;
+        }
+        //判断是否存在授权记录
+        KfUser kfUser = kfUserService.getOne(new LambdaQueryWrapper<KfUser>()
+                .eq(KfUser::getKfUserId, SecurityUtil.getUserId())
+                .eq(KfUser::getAppId, kfGameVO.getAppId()));
+        kfGameVO.setIsAuth(kfUser != null ? Boolean.TRUE : Boolean.FALSE);
+        if (kfUser == null) {
+            return kfGameVO;
+        }
+        //判断授权信息是否过期, 请求获取客服信息接口
+        String result = this.commKfApi(kfUser, KfActionEnum.GET_KF_ACCT.getValue(),
+                KfApiEnum.getApiUrl(KfActionEnum.GET_KF_ACCT), Collections.emptyMap());
+        KfMsgResultDTO kfMsgResultDTO = JsonUtil.toObj(result, KfMsgResultDTO.class);
+        kfGameVO.setIsValid(kfMsgResultDTO.isSueecss());
+        return kfGameVO;
     }
 
     @Override
     public String kfApi(KfApiParam param) {
         log.error("请求参数, param : {}", JsonUtil.toString(param));
-        //匹配行为对应的api地址
-        String apiUrl = KfApiEnum.getApiUrl(param.getAction());
-        if (Strings.isBlank(apiUrl)) {
-            throw new BaseException("参数错误, 接口地址匹配异常!");
-        }
         //查询用户授权信息
         KfUser kfUser = kfUserService.getKfUser(SecurityUtil.getUserId(), param.getAppId());
         //请求调用腾讯接口
-        return this.commKfApi(kfUser, param.getAction().getValue(), apiUrl, param.getParam());
+        return this.commKfApi(kfUser, param.getAction().getValue(), KfApiEnum.getApiUrl(param.getAction()), param.getParam());
     }
 
     private String commKfApi(KfUser kfUser, String action, String url, Map<String, Object> param) {