Browse Source

Merge remote-tracking branch 'origin/package' into package

Letianhua 1 năm trước cách đây
mục cha
commit
4681439c26
15 tập tin đã thay đổi với 631 bổ sung1 xóa
  1. 1 1
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/ManageApplication.java
  2. 19 0
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/config/RestTemplateConfig.java
  3. 49 0
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/controller/KfMsgController.java
  4. 74 0
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/enums/KfActionEnum.java
  5. 80 0
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/enums/KfApiEnum.java
  6. 37 0
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/params/KfApiParam.java
  7. 25 0
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/vo/KfGameVO.java
  8. 31 0
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/IKfMsgContentService.java
  9. 21 0
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/IKfUserService.java
  10. 103 0
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfMsgContentServiceImpl.java
  11. 31 0
      game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfUserServiceImpl.java
  12. 83 0
      game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/KfMsgContent.java
  13. 53 0
      game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/KfUser.java
  14. 12 0
      game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/mapper/KfMsgContentMapper.java
  15. 12 0
      game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/mapper/KfUserMapper.java

+ 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服务启动成功 <bug修改2> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 <客服系统02> ( ´・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 19 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/config/RestTemplateConfig.java

@@ -0,0 +1,19 @@
+package com.zanxiang.game.module.manage.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @author : lingfeng
+ * @time : 2021-08-18
+ * @description : redis配置
+ */
+@Configuration
+public class RestTemplateConfig {
+
+    @Bean
+    public RestTemplate restTemplate() {
+        return new RestTemplate();
+    }
+}

+ 49 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/controller/KfMsgController.java

@@ -0,0 +1,49 @@
+package com.zanxiang.game.module.manage.controller;
+
+import com.zanxiang.erp.security.annotation.PreAuthorize;
+import com.zanxiang.game.module.manage.pojo.params.KfApiParam;
+import com.zanxiang.game.module.manage.pojo.vo.CpVO;
+import com.zanxiang.game.module.manage.pojo.vo.KfGameVO;
+import com.zanxiang.game.module.manage.service.IKfMsgContentService;
+import com.zanxiang.module.util.pojo.ResultVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-11-29
+ * @description : 客服系统接口
+ */
+@Api(tags = {"客服系统接口"})
+@RestController
+@RequestMapping("/kf")
+@Slf4j
+public class KfMsgController {
+
+    @Autowired
+    private IKfMsgContentService kfMsgContentService;
+
+    @ApiOperation(value = "小游戏列表查询")
+    @GetMapping(value = "/game/list")
+    @PreAuthorize(permissionKey = "manage:kf:gameList")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = CpVO.class)})
+    public ResultVO<List<KfGameVO>> list() {
+        return ResultVO.ok(kfMsgContentService.getKfGameList());
+    }
+
+    @ApiOperation(value = "客服接口通用api")
+    @PostMapping(value = "/comm/api")
+    @PreAuthorize(permissionKey = "manage:kf:commApi")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = CpVO.class)})
+    public ResultVO<String> list(@Validated @RequestBody KfApiParam param) {
+        return ResultVO.ok(kfMsgContentService.kfApi(param));
+    }
+}

+ 74 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/enums/KfActionEnum.java

@@ -0,0 +1,74 @@
+package com.zanxiang.game.module.manage.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-11-29
+ * @description : 客服接口行为枚举
+ */
+@Getter
+@AllArgsConstructor
+public enum KfActionEnum {
+
+    /**
+     * 客服在线状态更改
+     */
+    UPDATE_KF_ACCT("update_kf_acct"),
+
+    /**
+     * 获取客服信息
+     */
+    GET_KF_ACCT("get_kf_acct"),
+
+    /**
+     * 获取待接入信息列表
+     */
+    BATCH_GET_NO_SESSION_EXTRA_INFO("batch_get_nosession_extra_info"),
+
+    /**
+     * 接入房间会话
+     */
+    ACCEPT_ROOM("accept_room"),
+
+    /**
+     * 初始化房间 可获取房间最近的msgID
+     */
+    GET_ROOM_INFO("get_room_info"),
+
+    /**
+     * 获取房间消息
+     */
+    GET_ROOM_MSG("get_room_msg"),
+
+    /**
+     * 获取房间用户标签
+     */
+    GET_USER_TAG("get_user_tag"),
+
+    /**
+     * 每次发送消息前获取msgID
+     */
+    GET_MSG_ID("get_msg_id"),
+
+    /**
+     * 发送会话
+     */
+    SEND_ROOM_MSG("send_room_msg"),
+
+    /**
+     * 结束房间会话
+     */
+    END_ROOM("end_room"),
+
+    /**
+     * 已接入列表
+     */
+    GET_SESSION_SUMMARY("get_session_summary");
+
+    /**
+     * 接口行为
+     */
+    private String value;
+}

+ 80 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/enums/KfApiEnum.java

@@ -0,0 +1,80 @@
+package com.zanxiang.game.module.manage.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-11-29
+ * @description : 客服接口API枚举
+ */
+@Getter
+@AllArgsConstructor
+public enum KfApiEnum {
+
+    /**
+     * 客服信息
+     */
+    ACCT("https://mpkf.weixin.qq.com/commkf/acct", new KfActionEnum[]{
+            KfActionEnum.UPDATE_KF_ACCT, KfActionEnum.GET_KF_ACCT
+    }),
+
+    /**
+     * 房间
+     */
+    ROOM("https://mpkf.weixin.qq.com/commkf/room", new KfActionEnum[]{
+            KfActionEnum.ACCEPT_ROOM, KfActionEnum.GET_ROOM_INFO, KfActionEnum.GET_USER_TAG
+    }),
+
+    /**
+     * 消息
+     */
+    MSG("https://mpkf.weixin.qq.com/commkf/msg", new KfActionEnum[]{
+            KfActionEnum.GET_ROOM_MSG, KfActionEnum.GET_MSG_ID, KfActionEnum.SEND_ROOM_MSG, KfActionEnum.END_ROOM
+    }),
+
+    /**
+     * 报告
+     */
+    REPORT("https://mpkf.weixin.qq.com/commkf/report", new KfActionEnum[]{
+            KfActionEnum.ACCEPT_ROOM
+    }),
+
+    /**
+     * 总汇表
+     */
+    SUMMARY("https://mpkf.weixin.qq.com/commkf/summary", new KfActionEnum[]{
+            KfActionEnum.BATCH_GET_NO_SESSION_EXTRA_INFO
+    });
+
+    /**
+     * 接口地址
+     */
+    private String apiUrl;
+
+    /**
+     * 行为枚举
+     */
+    private KfActionEnum[] kfActionEnums;
+
+    /**
+     * 根据行为获取api地址
+     *
+     * @param kfActionEnum : 接口行为枚举
+     * @return : 返回api地址
+     */
+    public static String getApiUrl(KfActionEnum kfActionEnum) {
+        for (KfApiEnum kfApiEnum : KfApiEnum.values()) {
+            KfActionEnum action = Arrays.stream(kfApiEnum.getKfActionEnums())
+                    .filter(actionEnum -> Objects.equals(kfActionEnum, actionEnum))
+                    .findFirst().orElse(null);
+            if (action != null) {
+                return kfApiEnum.getApiUrl();
+            }
+        }
+        return null;
+    }
+}

+ 37 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/params/KfApiParam.java

@@ -0,0 +1,37 @@
+package com.zanxiang.game.module.manage.pojo.params;
+
+import com.zanxiang.game.module.manage.enums.KfActionEnum;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import java.util.Map;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-11-28
+ * @description : 客服接口参数
+ */
+@Data
+public class KfApiParam {
+
+    /**
+     * 游戏应用id
+     */
+    @NotBlank(message = "游戏应用参数不可为空")
+    @ApiModelProperty(notes = "游戏应用参数")
+    private String appId;
+
+    /**
+     * 行为动作
+     */
+    @NotBlank(message = "接口行为")
+    @ApiModelProperty(notes = "行为动作")
+    private KfActionEnum action;
+
+    /**
+     * 接口body参数
+     */
+    @ApiModelProperty(notes = "接口body参数")
+    private Map<String, Object> param;
+}

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

@@ -0,0 +1,25 @@
+package com.zanxiang.game.module.manage.pojo.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-11-29
+ * @description : 客服游戏
+ */
+@Data
+public class KfGameVO {
+
+    /**
+     * 应用id
+     */
+    @ApiModelProperty(notes = "应用id")
+    private String appId;
+
+    /**
+     * 应用名称
+     */
+    @ApiModelProperty(notes = "应用名称")
+    private String appName;
+}

+ 31 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/IKfMsgContentService.java

@@ -0,0 +1,31 @@
+package com.zanxiang.game.module.manage.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zanxiang.game.module.manage.pojo.params.KfApiParam;
+import com.zanxiang.game.module.manage.pojo.vo.KfGameVO;
+import com.zanxiang.game.module.mybatis.entity.KfMsgContent;
+
+import java.util.List;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-11-28
+ * @description :
+ */
+public interface IKfMsgContentService extends IService<KfMsgContent> {
+
+    /**
+     * 获取游戏列表
+     *
+     * @return : 返回游戏列表
+     */
+    List<KfGameVO> getKfGameList();
+
+    /**
+     * 腾讯通用api接口
+     *
+     * @param param : 请求参数
+     * @return : 返回结果
+     */
+    String kfApi(KfApiParam param);
+}

+ 21 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/IKfUserService.java

@@ -0,0 +1,21 @@
+package com.zanxiang.game.module.manage.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zanxiang.game.module.mybatis.entity.KfUser;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-11-28
+ * @description : 客服用户信息
+ */
+public interface IKfUserService extends IService<KfUser> {
+
+    /**
+     * 获取客服用户信息
+     *
+     * @param kfUserId : 用户id
+     * @param appId    : 应用id
+     * @return : 返回用户信息
+     */
+    KfUser getKfUser(Long kfUserId, String appId);
+}

+ 103 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfMsgContentServiceImpl.java

@@ -0,0 +1,103 @@
+package com.zanxiang.game.module.manage.service.impl;
+
+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.KfApiEnum;
+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;
+import com.zanxiang.game.module.manage.service.IGameAuthService;
+import com.zanxiang.game.module.manage.service.IKfMsgContentService;
+import com.zanxiang.game.module.manage.service.IKfUserService;
+import com.zanxiang.game.module.mybatis.entity.GameApplet;
+import com.zanxiang.game.module.mybatis.entity.GameAuth;
+import com.zanxiang.game.module.mybatis.entity.KfMsgContent;
+import com.zanxiang.game.module.mybatis.entity.KfUser;
+import com.zanxiang.game.module.mybatis.mapper.KfMsgContentMapper;
+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;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-11-27
+ * @description : 客服消息
+ */
+@Slf4j
+@Service
+public class KfMsgContentServiceImpl extends ServiceImpl<KfMsgContentMapper, KfMsgContent> implements IKfMsgContentService {
+
+    @Autowired
+    private RestTemplate restTemplate;
+
+    @Autowired
+    private IKfUserService kfUserService;
+
+    @Autowired
+    private IGameAuthService gameAuthService;
+
+    @Autowired
+    private IGameAppletService gameAppletService;
+
+    @Override
+    public List<KfGameVO> getKfGameList() {
+        List<GameAuth> gameAuthList = gameAuthService.list(new LambdaQueryWrapper<GameAuth>()
+                .eq(!SecurityUtil.isAdmin(), GameAuth::getUserId, SecurityUtil.getUserId()));
+        if (!SecurityUtil.isAdmin() && CollectionUtils.isEmpty(gameAuthList)) {
+            return Collections.emptyList();
+        }
+        return gameAppletService.list(new LambdaQueryWrapper<GameApplet>()
+                .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());
+    }
+
+    @Override
+    public String kfApi(KfApiParam 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());
+    }
+
+    private String commKfApi(KfUser kfUser, String action, String url, Map<String, Object> param) {
+        Map<String, String> pathParam = new HashMap<>(3);
+        pathParam.put("action", action);
+        pathParam.put("f", "json");
+        pathParam.put("token", kfUser.getToken());
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("cookie", kfUser.getCookie());
+        ResponseEntity<String> responseEntity;
+        try {
+            responseEntity = restTemplate.exchange(URIUtil.fillUrlParams(url, pathParam, Boolean.FALSE),
+                    HttpMethod.POST, new HttpEntity<>(param, headers), String.class);
+        } catch (Exception e) {
+            log.error("腾讯接口调用异常, e : {}", e.getMessage());
+            throw new BaseException("腾讯接口调用异常!");
+        }
+        return responseEntity.getBody();
+    }
+}

+ 31 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfUserServiceImpl.java

@@ -0,0 +1,31 @@
+package com.zanxiang.game.module.manage.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zanxiang.game.module.manage.service.IKfUserService;
+import com.zanxiang.game.module.mybatis.entity.KfUser;
+import com.zanxiang.game.module.mybatis.mapper.KfUserMapper;
+import com.zanxiang.module.util.exception.BaseException;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-11-27
+ * @description : 客服用户信息
+ */
+@Slf4j
+@Service
+public class KfUserServiceImpl extends ServiceImpl<KfUserMapper, KfUser> implements IKfUserService {
+
+    @Override
+    public KfUser getKfUser(Long kfUserId, String appId) {
+        KfUser kfUser = super.getOne(new LambdaQueryWrapper<KfUser>()
+                .eq(KfUser::getKfUserId, kfUserId)
+                .eq(KfUser::getAppId, appId));
+        if (kfUser == null) {
+            throw new BaseException("参数错误, 客服用户信息不存在");
+        }
+        return kfUser;
+    }
+}

+ 83 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/KfMsgContent.java

@@ -0,0 +1,83 @@
+package com.zanxiang.game.module.mybatis.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.*;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-11-27
+ * @description : 客服消息记录
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@ToString
+@Builder
+@TableName("t_kf_msg_content")
+public class KfMsgContent implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 消息id
+     */
+    private String msgId;
+
+    /**
+     * 消息类型
+     */
+    private Integer msgType;
+
+    /**
+     * 房间id
+     */
+    private String roomId;
+
+    /**
+     * 消息内容
+     */
+    private String msgKfContent;
+
+    /**
+     * 拓展信息
+     */
+    private String extraInfo;
+
+    /**
+     * 发送账号(客服消息才有值)
+     */
+    private String sendOpenAccount;
+
+    /**
+     * 发送者openid
+     */
+    private String sendOpenid;
+
+    /**
+     * 发送场景
+     */
+    private Integer sendScene;
+
+    /**
+     * session
+     */
+    private String sessionId;
+
+    /**
+     * 是否删除
+     */
+    private Integer isDelete;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updateTime;
+}

+ 53 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/KfUser.java

@@ -0,0 +1,53 @@
+package com.zanxiang.game.module.mybatis.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.*;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-11-27
+ * @description : 客服用户
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@ToString
+@Builder
+@TableName("t_kf_user")
+public class KfUser implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 客服用户id
+     */
+    private Long kfUserId;
+
+    /**
+     * 应用id
+     */
+    private String appId;
+
+    /**
+     * 请求token
+     */
+    private String token;
+
+    /**
+     * 请求cookie
+     */
+    private String cookie;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updateTime;
+}

+ 12 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/mapper/KfMsgContentMapper.java

@@ -0,0 +1,12 @@
+package com.zanxiang.game.module.mybatis.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.zanxiang.game.module.mybatis.entity.KfMsgContent;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-11-27
+ * @description :  ${description}
+ */
+public interface KfMsgContentMapper extends BaseMapper<KfMsgContent> {
+}

+ 12 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/mapper/KfUserMapper.java

@@ -0,0 +1,12 @@
+package com.zanxiang.game.module.mybatis.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.zanxiang.game.module.mybatis.entity.KfUser;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-11-27
+ * @description : ${description}
+ */
+public interface KfUserMapper extends BaseMapper<KfUser> {
+}