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