Bläddra i källkod

渠道逻辑变更

wcc 1 år sedan
förälder
incheckning
aad2a32e65

+ 6 - 0
game-module/game-module-manage/pom.xml

@@ -103,6 +103,12 @@
             <artifactId>advertising-oceanengine-track-base</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <!-- 腾讯广告服务 -->
+        <dependency>
+            <groupId>com.zanxiang.advertising.tencent</groupId>
+            <artifactId>advertising-tencent-base</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 28 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/dto/AgentDTO.java

@@ -0,0 +1,28 @@
+package com.zanxiang.game.module.manage.pojo.dto;
+
+import lombok.Data;
+
+@Data
+public class AgentDTO {
+
+    /**
+     * 渠道名称
+     */
+    private String agentName;
+    /**
+     * 推广账号类型(1:腾讯、2:头条)
+     */
+    private Integer accountType;
+    /**
+     * 账号类型
+     */
+    private Long accountId;
+    /**
+     * 游戏id
+     */
+    private Long gameId;
+    /**
+     * 腾讯用户行为数据源 id
+     */
+    private Long userActionSetId;
+}

+ 34 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/dto/AgentListDTO.java

@@ -0,0 +1,34 @@
+package com.zanxiang.game.module.manage.pojo.dto;
+
+import com.zanxiang.game.module.mybatis.entity.Agent;
+import com.zanxiang.module.web.pojo.BaseListDTO;
+import lombok.Data;
+
+import java.time.LocalDate;
+
+@Data
+public class AgentListDTO extends BaseListDTO<Agent> {
+
+
+    private String agentName;
+
+    private Integer accountType;
+
+    private Long accountId;
+    /**
+     * 游戏id
+     */
+    private Long gameId;
+    /**
+     * 回传策略 id
+     */
+    private Long backPolicyId;
+    /**
+     * 投放状态
+     */
+    private Integer putStatus;
+
+    private LocalDate createBeginTime;
+
+    private LocalDate createEndTime;
+}

+ 27 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/enums/AccountTypeEnum.java

@@ -0,0 +1,27 @@
+package com.zanxiang.game.module.manage.pojo.enums;
+
+import lombok.Getter;
+
+@Getter
+public enum AccountTypeEnum {
+    TENCENT(1),
+    BYTE(2);
+
+    private final Integer value;
+
+    AccountTypeEnum(Integer value) {
+        this.value = value;
+    }
+
+    public static AccountTypeEnum getByValue(Integer value) {
+        if (value == null) {
+            return null;
+        }
+        for (AccountTypeEnum accountType : AccountTypeEnum.values()) {
+            if (accountType.getValue().equals(value)) {
+                return accountType;
+            }
+        }
+        return null;
+    }
+}

+ 45 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/vo/AgentVO.java

@@ -0,0 +1,45 @@
+package com.zanxiang.game.module.manage.pojo.vo;
+
+import com.zanxiang.advertising.tencent.base.pojo.vo.AdAccountRpcVO;
+import com.zanxiang.advertising.tencent.base.pojo.vo.UserActionSetRpcVO;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+@Data
+public class AgentVO {
+
+    private Long id;
+    /**
+     * 渠道名称
+     */
+    private String agentName;
+    /**
+     * 渠道唯一标识
+     */
+    private String agentKey;
+    /**
+     * 推广账号类型(1:腾讯、2:头条)
+     */
+    private Integer accountType;
+    /**
+     * 账号类型
+     */
+    private Long accountId;
+    /**
+     * 游戏id
+     */
+    private Long gameId;
+    /**
+     * 腾讯用户行为数据源 id
+     */
+    private Long userActionSetId;
+
+    private LocalDateTime createTime;
+
+    private Long createBy;
+
+    private GameInfoVO gameInfo;
+
+    private UserActionSetRpcVO userActionSet;
+}

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

@@ -1,7 +1,15 @@
 package com.zanxiang.game.module.manage.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.zanxiang.game.module.manage.pojo.dto.AgentDTO;
 import com.zanxiang.game.module.mybatis.entity.Agent;
 
 public interface IAgentService extends IService<Agent> {
+    /**
+     * 建渠道
+     *
+     * @param dto
+     * @return
+     */
+    boolean add(AgentDTO dto);
 }

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

@@ -97,6 +97,8 @@ public interface IGameService extends IService<Game> {
      */
     List<GameChoiceVO> choiceList();
 
+    List<GameInfoVO> infoByIds(Collection<Long>  gameIds);
+
     /**
      * 根据id查询游戏信息
      *

+ 116 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/AgentServiceImpl.java

@@ -1,14 +1,130 @@
 package com.zanxiang.game.module.manage.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zanxiang.advertising.tencent.base.AdvertisingTencentServer;
+import com.zanxiang.advertising.tencent.base.pojo.vo.UserActionSetRpcVO;
+import com.zanxiang.advertising.tencent.base.rpc.IAdAccountRpc;
+import com.zanxiang.advertising.tencent.base.rpc.IUserActionSetRpc;
+import com.zanxiang.erp.security.util.SecurityUtil;
+import com.zanxiang.game.module.base.utils.StringUtils;
+import com.zanxiang.game.module.manage.pojo.dto.AgentDTO;
+import com.zanxiang.game.module.manage.pojo.dto.AgentListDTO;
+import com.zanxiang.game.module.manage.pojo.enums.AccountTypeEnum;
+import com.zanxiang.game.module.manage.pojo.vo.AgentVO;
+import com.zanxiang.game.module.manage.pojo.vo.GameInfoVO;
 import com.zanxiang.game.module.manage.service.IAgentService;
+import com.zanxiang.game.module.manage.service.IGameService;
 import com.zanxiang.game.module.mybatis.entity.Agent;
+import com.zanxiang.game.module.mybatis.entity.Game;
 import com.zanxiang.game.module.mybatis.mapper.AgentMapper;
+import com.zanxiang.module.util.bean.BeanUtil;
+import com.zanxiang.module.util.exception.BaseException;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 @Slf4j
 @Service
 public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent>
         implements IAgentService {
+    @Autowired
+    private IGameService gameService;
+    @DubboReference(providedBy = AdvertisingTencentServer.SERVER_DUBBO_NAME)
+    private IAdAccountRpc adAccountRpc;
+    @DubboReference(providedBy = AdvertisingTencentServer.SERVER_DUBBO_NAME)
+    private IUserActionSetRpc userActionSetRpc;
+
+    public IPage<AgentVO> listOfPage(AgentListDTO dto) {
+        IPage<Agent> agentIPage = page(dto.toPage(), new LambdaQueryWrapper<Agent>()
+                .like(StringUtils.isNotEmpty(dto.getAgentName()), Agent::getAgentName, dto.getAgentName())
+                .eq(dto.getAccountType() != null, Agent::getAccountType, dto.getAccountType())
+                .eq(dto.getAccountId() != null, Agent::getAccountId, dto.getAccountId())
+                .eq(dto.getGameId() != null, Agent::getGameId, dto.getGameId())
+                .eq(dto.getBackPolicyId() != null, Agent::getBackPolicyId, dto.getBackPolicyId())
+                .eq(dto.getPutStatus() != null, Agent::getPutStatus, dto.getPutStatus())
+                .ge(dto.getCreateBeginTime() != null, Agent::getCreateTime, dto.getCreateBeginTime() == null ? null : LocalDateTime.of(dto.getCreateBeginTime(), LocalTime.MIDNIGHT))
+                .le(dto.getCreateEndTime() != null, Agent::getCreateTime, dto.getCreateEndTime() == null ? null : LocalDateTime.of(dto.getCreateEndTime(), LocalTime.MIDNIGHT))
+                .orderByDesc(Agent::getCreateTime)
+        );
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean add(AgentDTO dto) {
+        if (count(new LambdaQueryWrapper<Agent>()
+                .eq(Agent::getAccountType, dto.getAccountType())
+                .eq(Agent::getAccountId, dto.getAccountId())
+        ) > 0) {
+            throw new BaseException("一个账号只能建一个渠道,投一个游戏!!!");
+        }
+        Agent agent = Agent.builder()
+                .agentName(dto.getAgentName())
+                .agentKey(UUID.randomUUID().toString().replaceAll("-", ""))
+                .accountType(dto.getAccountType())
+                .accountId(dto.getAccountId())
+                .gameId(dto.getGameId())
+                .userActionSetId(dto.getUserActionSetId())
+                .createTime(LocalDateTime.now())
+                .createBy(SecurityUtil.getUserId())
+                .build();
+        return save(agent);
+    }
+
+    private List<AgentVO> toVOBatch(List<Agent> agentList) {
+        if (CollectionUtils.isEmpty(agentList)) {
+            return Collections.emptyList();
+        }
+        Set<Long> gameIds = new HashSet<>(agentList.size());
+        Set<Long> txAccountIds = new HashSet<>(agentList.size());
+        Set<Long> txUserActionSetIds = new HashSet<>(agentList.size());
+        Set<Long> byteAccountIds = new HashSet<>(agentList.size());
+        agentList.forEach(agent -> {
+            gameIds.add(agent.getGameId());
+            if (AccountTypeEnum.TENCENT.getValue().equals(agent.getAccountType())) {
+                txAccountIds.add(agent.getAccountId());
+                txUserActionSetIds.add(agent.getUserActionSetId());
+            } else {
+                byteAccountIds.add(agent.getAccountId());
+            }
+        });
+        Map<Long, UserActionSetRpcVO> userActionSetMap = new HashMap<>(0);
+        if (CollectionUtils.isNotEmpty(txAccountIds)) {
+            for(Long txAccountId : txAccountIds) {
+                userActionSetMap = userActionSetRpc.getByAccount(txAccountId).getData();
+            }
+        }
+        Map<Long, GameInfoVO> gameMap = gameService.infoByIds(gameIds).stream().collect(Collectors.toMap(GameInfoVO::getId, Function.identity()));
+        return agentList.stream().map(agent -> {
+            AgentVO vo = BeanUtil.copy(agent, AgentVO.class);
+            vo.setGameInfo(gameMap.get(agent.getGameId()));
+            vo.setUserActionSet();
+            return vo;
+        }).collect(Collectors.toList());
+
+    }
+
+    private AgentVO toVOSimple(Agent agent) {
+        if (agent == null) {
+            return null;
+        }
+        return BeanUtil.copy(agent, AgentVO.class);
+    }
 }

+ 6 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GameServiceImpl.java

@@ -15,6 +15,7 @@ import com.zanxiang.game.module.manage.pojo.vo.*;
 import com.zanxiang.game.module.manage.service.*;
 import com.zanxiang.game.module.mybatis.entity.*;
 import com.zanxiang.game.module.mybatis.mapper.GameMapper;
+import com.zanxiang.module.util.bean.BeanUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.logging.log4j.util.Strings;
@@ -188,6 +189,11 @@ public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements IG
                 .eq(Game::getId, param.getId()));
     }
 
+    @Override
+    public List<GameInfoVO> infoByIds(Collection<Long>  gameIds) {
+        return listByIds(gameIds).stream().map(game -> BeanUtil.copy(game, GameInfoVO.class)).collect(Collectors.toList());
+    }
+
     @Override
     public GameInfoVO getGameInfo(Long gameId) {
         Game game = super.getById(gameId);

+ 14 - 4
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/Agent.java

@@ -8,6 +8,7 @@ import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
+import java.io.Serializable;
 import java.time.LocalDateTime;
 
 /**
@@ -18,11 +19,12 @@ import java.time.LocalDateTime;
 @AllArgsConstructor
 @Builder
 @TableName("t_agent")
-public class Agent {
+public class Agent implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    public static final Integer PUT_STATUS_ING = 1;
+    public static final Integer PUT_STATUS_STOP = 2;
 
-    /**
-     * 主键id
-     */
     @TableId(value = "id", type = IdType.AUTO)
     private Long id;
     /**
@@ -49,6 +51,14 @@ public class Agent {
      * 腾讯用户行为数据源 id
      */
     private Long userActionSetId;
+    /**
+     * 回传策略 id
+     */
+    private Long backPolicyId;
+    /**
+     * 投放状态
+     */
+    private Integer putStatus;
 
     private LocalDateTime createTime;