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