|
@@ -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();
|
|
|
|
+ }
|
|
|
|
+}
|