Selaa lähdekoodia

fix : 发码器后台代码提交02

bilingfeng 5 kuukautta sitten
vanhempi
commit
3fe1891127

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

@@ -23,7 +23,7 @@ public class ManageApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(ManageApplication.class, args);
-        System.out.println("赞象Manage服务启动成功 < (发码器后台代码提交01・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 < (发码器后台代码提交02・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 5 - 5
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/controller/GameGiftPackCodeController.java → game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/controller/GameGiftPackController.java

@@ -31,7 +31,7 @@ import java.util.Map;
 @Api(tags = {"游戏发码器"})
 @RestController
 @RequestMapping("/game/gift/pack")
-public class GameGiftPackCodeController {
+public class GameGiftPackController {
 
     @Autowired
     private IGameGiftPackCodeService gameGiftPackCodeService;
@@ -68,8 +68,8 @@ public class GameGiftPackCodeController {
     @PostMapping(value = "/link/update")
     @PreAuthorize(permissionKey = "manage:giftPack:linkUpdate")
     @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
-    public ResultVO<Boolean> updateGiftPackLin(@Validated @RequestBody GameGiftPackLinkUpdateParam param) {
-        return ResultVO.ok(gameGiftPackLinkService.updateGiftPackLin(param));
+    public ResultVO<Boolean> updateGiftPackLink(@Validated @RequestBody GameGiftPackLinkUpdateParam param) {
+        return ResultVO.ok(gameGiftPackLinkService.updateGiftPackLink(param));
     }
 
     @ApiOperation(value = "删除礼包码链接")
@@ -84,8 +84,8 @@ public class GameGiftPackCodeController {
     @PostMapping(value = "/link/add")
     @PreAuthorize(permissionKey = "manage:giftPack:linkAdd")
     @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
-    public ResultVO<Boolean> addGiftPackLin(@Validated @RequestBody GameGiftPackLinkAddParam param) {
-        return ResultVO.ok(gameGiftPackLinkService.addGiftPackLin(param));
+    public ResultVO<Boolean> addGiftPackLink(@Validated @RequestBody GameGiftPackLinkAddParam param) {
+        return ResultVO.ok(gameGiftPackLinkService.addGiftPackLink(param));
     }
 
     @ApiOperation(value = "查询链接礼包码列表")

+ 39 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/controller/api/GameGiftPackApi.java

@@ -0,0 +1,39 @@
+package com.zanxiang.game.module.manage.controller.api;
+
+import com.zanxiang.game.module.manage.pojo.params.GameGiftPackLinkLogPushParam;
+import com.zanxiang.game.module.manage.service.IGameGiftPackLinkLogService;
+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.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-11-04
+ * @description : 发码器外部接口
+ */
+@Slf4j
+@Api(tags = {"发码器外部接口"})
+@RestController
+@RequestMapping("/api/game/gift/pack")
+public class GameGiftPackApi {
+
+    @Autowired
+    private IGameGiftPackLinkLogService gameGiftPackLinkLogService;
+
+    @ApiOperation(value = "链接访问记录推送接口")
+    @PostMapping(value = "/link/log/push")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Long.class)})
+    public ResultVO<Long> linkList(@Validated @RequestBody GameGiftPackLinkLogPushParam param) {
+        return ResultVO.ok(gameGiftPackLinkLogService.linkVisitLogPush(param.getUrl()));
+    }
+
+}

+ 17 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/dto/GameGiftPackLinkVisitDTO.java

@@ -0,0 +1,17 @@
+package com.zanxiang.game.module.manage.pojo.dto;
+
+import lombok.Data;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-11-04
+ * @description :
+ */
+@Data
+public class GameGiftPackLinkVisitDTO {
+
+    /**
+     * 访问日志id
+     */
+    private Long linkLogId;
+}

+ 22 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/params/GameGiftPackLinkLogPushParam.java

@@ -0,0 +1,22 @@
+package com.zanxiang.game.module.manage.pojo.params;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-11-04
+ * @description :
+ */
+@Data
+public class GameGiftPackLinkLogPushParam {
+
+    /**
+     * 网页完整地址
+     */
+    @NotBlank(message = "网页地址不可空")
+    @ApiModelProperty(notes = "网页完整地址")
+    private String url;
+}

+ 8 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/IGameGiftPackLinkLogService.java

@@ -13,6 +13,14 @@ import com.zanxiang.game.module.mybatis.entity.GameGiftPackLinkLog;
  */
 public interface IGameGiftPackLinkLogService extends IService<GameGiftPackLinkLog> {
 
+    /**
+     * 链接访问记录仪提交
+     *
+     * @param url : 链接地址
+     * @return : 返回记录主键id
+     */
+    Long linkVisitLogPush(String url);
+
     /**
      * 分页查新访问记录
      *

+ 2 - 2
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/IGameGiftPackLinkService.java

@@ -37,7 +37,7 @@ public interface IGameGiftPackLinkService extends IService<GameGiftPackLink> {
      * @param param : 更新参数
      * @return : 返回更新结果
      */
-    boolean updateGiftPackLin(GameGiftPackLinkUpdateParam param);
+    boolean updateGiftPackLink(GameGiftPackLinkUpdateParam param);
 
     /**
      * 添加礼包码链接
@@ -45,5 +45,5 @@ public interface IGameGiftPackLinkService extends IService<GameGiftPackLink> {
      * @param param : 添加参数
      * @return : 返回结果
      */
-    boolean addGiftPackLin(GameGiftPackLinkAddParam param);
+    boolean addGiftPackLink(GameGiftPackLinkAddParam param);
 }

+ 77 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GameGiftPackLinkLogServiceImpl.java

@@ -1,27 +1,44 @@
 package com.zanxiang.game.module.manage.service.impl;
 
+import com.alibaba.nacos.common.utils.CollectionUtils;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zanxiang.game.module.manage.pojo.params.GameGiftPackLinkLogListParam;
 import com.zanxiang.game.module.manage.pojo.vo.GameGiftPackLinkLogVO;
 import com.zanxiang.game.module.manage.service.IGameGiftPackLinkLogService;
+import com.zanxiang.game.module.manage.service.IGameGiftPackLinkService;
+import com.zanxiang.game.module.mybatis.entity.GameGiftPackLink;
 import com.zanxiang.game.module.mybatis.entity.GameGiftPackLinkLog;
 import com.zanxiang.game.module.mybatis.mapper.GameGiftPackLinkLogMapper;
 import com.zanxiang.module.util.bean.BeanUtil;
+import com.zanxiang.module.util.exception.BaseException;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.util.Strings;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.net.URLDecoder;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * @author : lingfeng
  * @time : 2022-06-22
  * @description : 游戏礼包码链接访问日志
  */
+@Slf4j
 @Service
 public class GameGiftPackLinkLogServiceImpl extends ServiceImpl<GameGiftPackLinkLogMapper, GameGiftPackLinkLog> implements IGameGiftPackLinkLogService {
 
+    @Autowired
+    private IGameGiftPackLinkService gameGiftPackLinkService;
+
     @Override
     public IPage<GameGiftPackLinkLogVO> list(GameGiftPackLinkLogListParam param) {
         return page(param.toPage(), new QueryWrapper<GameGiftPackLinkLog>().lambda()
@@ -32,6 +49,66 @@ public class GameGiftPackLinkLogServiceImpl extends ServiceImpl<GameGiftPackLink
         ).convert(log -> BeanUtil.copy(log, GameGiftPackLinkLogVO.class));
     }
 
+    @Override
+    public Long linkVisitLogPush(String url) {
+        Map<String, String> urlParameter = this.getUrlParameter(url);
+        String gameId = urlParameter.get("gameId");
+        String codeType = urlParameter.get("codeType");
+        if (CollectionUtils.isMapEmpty(urlParameter) || StringUtils.isAnyEmpty(gameId, codeType)) {
+            throw new BaseException("非法链接请求, 链接参数解析异常");
+        }
+        //查询链接信息
+        GameGiftPackLink gameGiftPackLink = gameGiftPackLinkService.getOne(new LambdaQueryWrapper<GameGiftPackLink>()
+                .eq(GameGiftPackLink::getGameId, Long.valueOf(gameId))
+                .eq(GameGiftPackLink::getCodeType, codeType));
+        assert gameGiftPackLink != null : "非法链接请求, 链接信息不存在";
+        //构造
+        GameGiftPackLinkLog gameGiftPackLinkLog = this.transform(gameGiftPackLink, urlParameter);
+        super.save(gameGiftPackLinkLog);
+        return gameGiftPackLinkLog.getId();
+    }
+
+    private GameGiftPackLinkLog transform(GameGiftPackLink gameGiftPackLink, Map<String, String> urlParameter) {
+        return GameGiftPackLinkLog.builder()
+                .linkId(gameGiftPackLink.getId())
+                .linkUrl(urlParameter.get("linkUrl"))
+                .gameId(gameGiftPackLink.getGameId())
+                .corpId(urlParameter.get("corpId"))
+                .corpUserId(urlParameter.get("corpUserId"))
+                .externalUserId(urlParameter.get("externalUserId"))
+                .createTime(LocalDateTime.now())
+                .build();
+    }
+
+    private Map<String, String> getUrlParameter(String url) {
+        //参数判断
+        if (Strings.isBlank(url)) {
+            return Collections.emptyMap();
+        }
+        //没有拼接参数
+        if (url.indexOf('?') == -1) {
+            return Collections.singletonMap("url", url);
+        }
+        //参数map
+        Map<String, String> map = new HashMap<>(6);
+        map.put("linkUrl", url);
+        try {
+            final String charset = "utf-8";
+            url = URLDecoder.decode(url, charset);
+            //解析参数
+            final String contents = url.substring(url.indexOf('?') + 1);
+            String[] keyValues = contents.split("&");
+            for (String keyValue : keyValues) {
+                String key = keyValue.substring(0, keyValue.indexOf("="));
+                String value = keyValue.substring(keyValue.indexOf("=") + 1);
+                map.put(key, value);
+            }
+        } catch (Exception e) {
+            log.error("url : {}, 链接参数解析异常", url);
+            throw new BaseException("链接参数解析异常");
+        }
+        return map;
+    }
 }
 
 

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

@@ -122,7 +122,7 @@ public class GameGiftPackLinkServiceImpl extends ServiceImpl<GameGiftPackLinkMap
     }
 
     @Override
-    public boolean updateGiftPackLin(GameGiftPackLinkUpdateParam param) {
+    public boolean updateGiftPackLink(GameGiftPackLinkUpdateParam param) {
         return super.update(new LambdaUpdateWrapper<GameGiftPackLink>()
                 .set(GameGiftPackLink::getCodeType, param.getCodeType())
                 .set(GameGiftPackLink::getCondition, param.getConditionDTO() == null ? null : JsonUtil.toString(param.getConditionDTO()))
@@ -144,7 +144,12 @@ public class GameGiftPackLinkServiceImpl extends ServiceImpl<GameGiftPackLinkMap
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public boolean addGiftPackLin(GameGiftPackLinkAddParam param) {
+    public boolean addGiftPackLink(GameGiftPackLinkAddParam param) {
+        //判断该游戏该类型是否已经存在礼包链接
+        assert super.count(new LambdaQueryWrapper<GameGiftPackLink>()
+                .eq(GameGiftPackLink::getGameId, param.getGameId())
+                .eq(GameGiftPackLink::getCodeType, param.getCodeType())
+        ) <= 0 : "该游戏已经存在此类型礼包码链接, 请勿重复添加";
         //查询超父游戏id
         GameDTO gameDTO = gameService.getById(param.getGameId());
         //游戏不可以为空
@@ -158,11 +163,6 @@ public class GameGiftPackLinkServiceImpl extends ServiceImpl<GameGiftPackLinkMap
         assert Strings.isNotBlank(giftPackConfig.getCodeLinkHost()) : "数据错误, 配置链接域名不可为空";
         //礼包码链接
         String codeLink = giftPackConfig.getCodeLinkHost() + "?gameId=" + param.getGameId() + "&codeType=" + param.getCodeType();
-        //判断该游戏该类型是否已经存在礼包链接
-        assert super.count(new LambdaQueryWrapper<GameGiftPackLink>()
-                .eq(GameGiftPackLink::getGameId, param.getGameId())
-                .eq(GameGiftPackLink::getCodeType, param.getCodeType())
-        ) <= 0 : "该游戏已经存在此类型礼包码链接, 请勿重复添加";
         //保存且返回结果
         return super.save(this.transform(giftPackConfig.getId(), codeLink, param));
     }
@@ -172,7 +172,7 @@ public class GameGiftPackLinkServiceImpl extends ServiceImpl<GameGiftPackLinkMap
                 .configId(configId)
                 .gameId(param.getGameId())
                 .codeType(param.getCodeType())
-                .condition(JsonUtil.toString(param))
+                .condition(JsonUtil.toString(param.getConditionDTO()))
                 .codeLink(codeLink)
                 .createBy(SecurityUtil.getUserId())
                 .createTime(LocalDateTime.now())

+ 5 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/GameGiftPackLinkLog.java

@@ -34,6 +34,11 @@ public class GameGiftPackLinkLog implements Serializable {
      */
     private Long linkId;
 
+    /**
+     * 访问链接地址
+     */
+    private String linkUrl;
+
     /**
      * 游戏id
      */