|
@@ -0,0 +1,191 @@
|
|
|
+package com.zanxiang.game.module.manage.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+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.base.ErpServer;
|
|
|
+import com.zanxiang.erp.base.rpc.ISysUserRpc;
|
|
|
+import com.zanxiang.erp.security.util.SecurityUtil;
|
|
|
+import com.zanxiang.game.module.manage.pojo.dto.AgentDTO;
|
|
|
+import com.zanxiang.game.module.manage.pojo.enums.AccountTypeEnum;
|
|
|
+import com.zanxiang.game.module.manage.pojo.params.AgentAddParam;
|
|
|
+import com.zanxiang.game.module.manage.pojo.params.AgentListParam;
|
|
|
+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.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.commons.lang3.StringUtils;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.apache.logging.log4j.util.Strings;
|
|
|
+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.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author wcc
|
|
|
+ */
|
|
|
+@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;
|
|
|
+
|
|
|
+ @DubboReference(providedBy = ErpServer.SERVER_DUBBO_NAME)
|
|
|
+ private ISysUserRpc sysUserRpc;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<AgentVO> listOfPage(AgentListParam param) {
|
|
|
+ IPage<Agent> agentIPage = page(param.toPage(), new LambdaQueryWrapper<Agent>()
|
|
|
+ .like(StringUtils.isNotEmpty(param.getAgentName()), Agent::getAgentName, param.getAgentName())
|
|
|
+ .eq(param.getAccountType() != null, Agent::getAccountType, param.getAccountType())
|
|
|
+ .eq(param.getAccountId() != null, Agent::getAccountId, param.getAccountId())
|
|
|
+ .eq(param.getGameId() != null, Agent::getGameId, param.getGameId())
|
|
|
+ .eq(param.getBackPolicyId() != null, Agent::getBackPolicyId, param.getBackPolicyId())
|
|
|
+ .eq(param.getPutStatus() != null, Agent::getPutStatus, param.getPutStatus())
|
|
|
+ .ge(param.getCreateBeginTime() != null, Agent::getCreateTime, param.getCreateBeginTime() == null ? null : LocalDateTime.of(param.getCreateBeginTime(), LocalTime.MIDNIGHT))
|
|
|
+ .le(param.getCreateEndTime() != null, Agent::getCreateTime, param.getCreateEndTime() == null ? null : LocalDateTime.of(param.getCreateEndTime(), LocalTime.MIDNIGHT))
|
|
|
+ .eq(Agent::getCreateBy, param.getPutUserId() == null ? SecurityUtil.getUserId() : param.getPutUserId())
|
|
|
+ .orderByDesc(Agent::getCreateTime)
|
|
|
+ );
|
|
|
+ IPage<AgentVO> result = new Page<>(agentIPage.getCurrent(), agentIPage.getSize(), agentIPage.getTotal());
|
|
|
+ if (CollectionUtils.isNotEmpty(agentIPage.getRecords())) {
|
|
|
+ result.setRecords(toVOBatch(agentIPage.getRecords()));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean add(AgentAddParam param) {
|
|
|
+ if (count(new LambdaQueryWrapper<Agent>()
|
|
|
+ .eq(Agent::getAccountType, param.getAccountType())
|
|
|
+ .eq(Agent::getAccountId, param.getAccountId())
|
|
|
+ ) > 0) {
|
|
|
+ throw new BaseException("一个账号只能建一个渠道,投一个游戏!!!");
|
|
|
+ }
|
|
|
+ return save(Agent.builder()
|
|
|
+ .agentName(param.getAgentName())
|
|
|
+ .agentKey(UUID.randomUUID().toString().replaceAll("-", ""))
|
|
|
+ .accountType(param.getAccountType())
|
|
|
+ .accountId(param.getAccountId())
|
|
|
+ .gameId(param.getGameId())
|
|
|
+ .userActionSetId(param.getUserActionSetId())
|
|
|
+ .backPolicyId(param.getBackPolicyId())
|
|
|
+ .putStatus(param.getPutStatus())
|
|
|
+ .createTime(LocalDateTime.now())
|
|
|
+ .createBy(SecurityUtil.getUserId())
|
|
|
+ .build());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean configPutStatus(List<Long> agentIdList, Integer putStatus) {
|
|
|
+ return update(new LambdaUpdateWrapper<Agent>()
|
|
|
+ .set(Agent::getPutStatus, putStatus)
|
|
|
+ .set(Agent::getUpdateBy, SecurityUtil.getUserId())
|
|
|
+ .set(Agent::getUpdateTime, agentIdList)
|
|
|
+ .in(Agent::getId, agentIdList)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean configBackPolicy(List<Long> agentIdList, Long backPolicyId) {
|
|
|
+ return update(new LambdaUpdateWrapper<Agent>()
|
|
|
+ .set(Agent::getBackPolicyId, backPolicyId)
|
|
|
+ .set(Agent::getUpdateBy, SecurityUtil.getUserId())
|
|
|
+ .set(Agent::getUpdateTime, agentIdList)
|
|
|
+ .in(Agent::getId, agentIdList)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ 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> userIds = new HashSet<>(1);
|
|
|
+ agentList.forEach(agent -> {
|
|
|
+ gameIds.add(agent.getGameId());
|
|
|
+ if (AccountTypeEnum.TENCENT.getValue().equals(agent.getAccountType())) {
|
|
|
+ txAccountIds.add(agent.getAccountId());
|
|
|
+ }
|
|
|
+ userIds.add(agent.getCreateBy());
|
|
|
+ });
|
|
|
+ Map<String, UserActionSetRpcVO> userActionSetMap = new HashMap<>();
|
|
|
+ if (CollectionUtils.isNotEmpty(txAccountIds)) {
|
|
|
+ for (Long txAccountId : txAccountIds) {
|
|
|
+ List<UserActionSetRpcVO> userActionSetList = userActionSetRpc.getByAccount(txAccountId).getData();
|
|
|
+ if (CollectionUtils.isEmpty(userActionSetList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ userActionSetMap.putAll(userActionSetList.stream().collect(Collectors.toMap(obj -> obj.getAccountId() + "_" + obj.getUserActionSetId(), Function.identity())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<Long, GameInfoVO> gameMap = gameService.infoByIds(gameIds).stream().collect(Collectors.toMap(GameInfoVO::getId, Function.identity()));
|
|
|
+ Map<Long, String> userMap = sysUserRpc.getUserNameByIds(new ArrayList<>(userIds)).getData();
|
|
|
+ return agentList.stream().map(agent -> {
|
|
|
+ AgentVO vo = BeanUtil.copy(agent, AgentVO.class);
|
|
|
+ vo.setGameInfo(gameMap.get(agent.getGameId()));
|
|
|
+ if (AccountTypeEnum.TENCENT.getValue().equals(agent.getAccountType())) {
|
|
|
+ vo.setUserActionSet(userActionSetMap.get(agent.getAccountId() + "_" + agent.getUserActionSetId()));
|
|
|
+ }
|
|
|
+ vo.setCreateByName(userMap.get(agent.getCreateBy()));
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AgentDTO> listUserAgent(String account, String pitcherId, Long agentId) {
|
|
|
+ List<Agent> agentList;
|
|
|
+ //超管权限
|
|
|
+ if (SecurityUtil.isAdmin()) {
|
|
|
+ agentList = super.list(new LambdaQueryWrapper<Agent>()
|
|
|
+ .eq(Strings.isNotBlank(account), Agent::getAccountId, account)
|
|
|
+ .eq(Strings.isNotBlank(pitcherId), Agent::getCreateBy, pitcherId)
|
|
|
+ .eq(agentId != null, Agent::getId, agentId));
|
|
|
+ } else {
|
|
|
+ agentList = super.list(new LambdaQueryWrapper<Agent>()
|
|
|
+ .eq(Strings.isNotBlank(account), Agent::getAccountId, account)
|
|
|
+ .eq(Agent::getCreateBy, Strings.isBlank(pitcherId) ? SecurityUtil.getUserId() : pitcherId)
|
|
|
+ .eq(agentId != null, Agent::getId, agentId));
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(agentList)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ //设置归属投手
|
|
|
+ List<Long> createByList = agentList.stream().map(Agent::getCreateBy).collect(Collectors.toList());
|
|
|
+ Map<Long, String> userMap = sysUserRpc.getUserNameByIds(createByList).getData();
|
|
|
+ return agentList.stream().map(agent -> {
|
|
|
+ AgentDTO agentDTO = BeanUtil.copy(agent, AgentDTO.class);
|
|
|
+ agentDTO.setCreateByName(userMap.get(agent.getCreateBy()));
|
|
|
+ return agentDTO;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+}
|