|
@@ -1,271 +0,0 @@
|
|
|
-package com.zanxiang.game.module.manage.service.impl;
|
|
|
-
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.zanxiang.game.module.base.pojo.enums.DeleteEnum;
|
|
|
-import com.zanxiang.game.module.base.pojo.enums.PromoAccountTypeEnum;
|
|
|
-import com.zanxiang.game.module.base.pojo.enums.StatusEnum;
|
|
|
-import com.zanxiang.game.module.manage.pojo.dto.PromoAccountDTO;
|
|
|
-import com.zanxiang.game.module.manage.pojo.dto.PromoMediaDTO;
|
|
|
-import com.zanxiang.game.module.manage.pojo.params.PromoAccountAddUpdateParam;
|
|
|
-import com.zanxiang.game.module.manage.pojo.params.PromoAccountAssignParam;
|
|
|
-import com.zanxiang.game.module.manage.pojo.params.PromoAccountListParam;
|
|
|
-import com.zanxiang.game.module.manage.pojo.vo.PromoAccountChoiceVO;
|
|
|
-import com.zanxiang.game.module.manage.pojo.vo.PromoAccountLinkageChoiceVO;
|
|
|
-import com.zanxiang.game.module.manage.pojo.vo.PromoAccountListVO;
|
|
|
-import com.zanxiang.game.module.manage.pojo.vo.PromoPitcherChoiceVO;
|
|
|
-import com.zanxiang.game.module.manage.service.IPromoAccountLogService;
|
|
|
-import com.zanxiang.game.module.manage.service.IPromoAccountService;
|
|
|
-import com.zanxiang.game.module.manage.service.IPromoMediaService;
|
|
|
-import com.zanxiang.game.module.mybatis.entity.PromoAccount;
|
|
|
-import com.zanxiang.game.module.mybatis.entity.PromoAccountLog;
|
|
|
-import com.zanxiang.game.module.mybatis.mapper.PromoAccountMapper;
|
|
|
-import com.zanxiang.module.util.bean.BeanUtil;
|
|
|
-import com.zanxiang.module.util.exception.BaseException;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-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.util.Collections;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.function.Function;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author : lingfeng
|
|
|
- * @time : 2022-11-03
|
|
|
- * @description : 推广账号
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-@Service
|
|
|
-public class PromoAccountServiceImpl extends ServiceImpl<PromoAccountMapper, PromoAccount> implements IPromoAccountService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IPromoMediaService promoMediaService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IPromoAccountLogService promoAccountLogService;
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<PromoAccountLinkageChoiceVO> promoAccountLinkageChoiceList() {
|
|
|
- List<PromoAccountLinkageChoiceVO> choiceVOList = super.list().stream()
|
|
|
- .map(promoAccount -> BeanUtil.copy(promoAccount, PromoAccountLinkageChoiceVO.class))
|
|
|
- .collect(Collectors.toList());
|
|
|
- Map<Long, PromoMediaDTO> promoMediaMap = promoMediaService.promoMediaMap();
|
|
|
- choiceVOList.forEach(promoAccountDTO -> {
|
|
|
- Long mediaId = promoAccountDTO.getMediaId();
|
|
|
- if (promoMediaMap.get(mediaId) != null) {
|
|
|
- promoAccountDTO.setMediaName(promoMediaMap.get(mediaId).getName());
|
|
|
- }
|
|
|
- promoAccountDTO.setAccountTypeName(PromoAccountTypeEnum.getNameByType(promoAccountDTO.getAccountType()));
|
|
|
- });
|
|
|
- return choiceVOList;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public IPage<PromoAccountListVO> list(PromoAccountListParam param) {
|
|
|
- Map<Long, PromoMediaDTO> promoMediaMap = promoMediaService.promoMediaMap();
|
|
|
- return page(param.toPage(), new QueryWrapper<PromoAccount>().lambda()
|
|
|
- .eq(param.getMediaId() != null, PromoAccount::getMediaId, param.getMediaId())
|
|
|
- .eq(param.getAccountType() != null, PromoAccount::getAccountType, param.getAccountType())
|
|
|
- .like(Strings.isNotBlank(param.getName()), PromoAccount::getName, param.getName())
|
|
|
- .like(Strings.isNotBlank(param.getAccount()), PromoAccount::getAccount, param.getAccount())
|
|
|
- .eq(param.getPitcherGroupId() != null, PromoAccount::getPitcherGroupId, param.getPitcherGroupId())
|
|
|
- .eq(param.getPitcherId() != null, PromoAccount::getPitcherId, param.getPitcherId())
|
|
|
- .eq(param.getStatus() != null, PromoAccount::getStatus, param.getStatus())
|
|
|
- .orderByDesc(PromoAccount::getCreateTime))
|
|
|
- .convert(promoAccount -> this.toVo(promoMediaMap, promoAccount));
|
|
|
- }
|
|
|
-
|
|
|
- private PromoAccountListVO toVo(Map<Long, PromoMediaDTO> promoMediaMap, PromoAccount promoAccount) {
|
|
|
- PromoAccountListVO promoAccountListVO = BeanUtil.copy(promoAccount, PromoAccountListVO.class);
|
|
|
- if (Objects.isNull(promoAccountListVO)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- PromoMediaDTO promoMediaDTO = promoMediaMap.get(promoAccount.getMediaId());
|
|
|
- if (promoMediaDTO != null) {
|
|
|
- promoAccountListVO.setMediaName(promoMediaDTO.getName());
|
|
|
- }
|
|
|
- PromoAccountLog promoAccountLog = promoAccountLogService.getOne(new LambdaQueryWrapper<PromoAccountLog>()
|
|
|
- .eq(PromoAccountLog::getAccountId, promoAccountListVO.getId())
|
|
|
- .isNull(PromoAccountLog::getEndTime));
|
|
|
- if (promoAccountLog != null) {
|
|
|
- promoAccountListVO.setStartTime(promoAccountLog.getStartTime() == null ? null : promoAccountLog.getStartTime().toLocalDate());
|
|
|
- }
|
|
|
- promoAccountListVO.setAccountTypeName(PromoAccountTypeEnum.getNameByType(promoAccountListVO.getAccountType()));
|
|
|
- return promoAccountListVO;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean addOrUpdate(PromoAccountAddUpdateParam param) {
|
|
|
- Long id = param.getId();
|
|
|
- //更新
|
|
|
- if (id != null) {
|
|
|
- PromoAccount promoAccount = super.getById(id);
|
|
|
- if (promoAccount == null) {
|
|
|
- throw new BaseException("参数错误, 推广账号信息不存在");
|
|
|
- }
|
|
|
- //更新标签名字, 不可重复
|
|
|
- if (!Objects.equals(promoAccount.getAccount(), param.getAccount())) {
|
|
|
- //判断名称是否已经存在
|
|
|
- int count = super.count(new LambdaQueryWrapper<PromoAccount>()
|
|
|
- .eq(PromoAccount::getAccount, param.getAccount()));
|
|
|
- if (count > 0) {
|
|
|
- throw new BaseException("推广账号id已经存在");
|
|
|
- }
|
|
|
- }
|
|
|
- promoAccount.setAccount(param.getAccount());
|
|
|
- promoAccount.setName(param.getName());
|
|
|
- promoAccount.setPitcherGroupId(param.getPitcherGroupId());
|
|
|
- promoAccount.setPitcherGroupName(param.getPitcherGroupName());
|
|
|
- promoAccount.setPitcherId(param.getPitcherId());
|
|
|
- promoAccount.setPitcherName(param.getPitcherName());
|
|
|
- promoAccount.setMediaId(param.getMediaId());
|
|
|
- promoAccount.setAccountType(param.getAccountType());
|
|
|
- promoAccount.setRemark(param.getRemark());
|
|
|
- promoAccount.setUpdateTime(LocalDateTime.now());
|
|
|
- return super.updateById(promoAccount);
|
|
|
- }
|
|
|
- //判断名称是否已经存在
|
|
|
- int count = super.count(new LambdaQueryWrapper<PromoAccount>()
|
|
|
- .eq(PromoAccount::getAccount, param.getAccount()));
|
|
|
- if (count > 0) {
|
|
|
- throw new BaseException("推广账号id已经存在");
|
|
|
- }
|
|
|
- //创建
|
|
|
- PromoAccount promoAccount = PromoAccount.builder()
|
|
|
- .account(param.getAccount())
|
|
|
- .name(param.getName())
|
|
|
- .pitcherGroupId(param.getPitcherGroupId())
|
|
|
- .pitcherGroupName(param.getPitcherGroupName())
|
|
|
- .pitcherId(param.getPitcherId())
|
|
|
- .pitcherName(param.getPitcherName())
|
|
|
- .mediaId(param.getMediaId())
|
|
|
- .accountType(param.getAccountType())
|
|
|
- .status(StatusEnum.YES.getCode())
|
|
|
- .remark(param.getRemark())
|
|
|
- .isDelete(DeleteEnum.NO.getCode())
|
|
|
- .createTime(LocalDateTime.now())
|
|
|
- .updateTime(LocalDateTime.now())
|
|
|
- .build();
|
|
|
- super.save(promoAccount);
|
|
|
- return promoAccountLogService.create(promoAccount);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Boolean accountAssign(PromoAccountAssignParam param) {
|
|
|
- PromoAccount promoAccount = super.getById(param.getId());
|
|
|
- if (promoAccount == null) {
|
|
|
- throw new BaseException("参数错误, 推广账号信息不存在");
|
|
|
- }
|
|
|
- //生成指派记录
|
|
|
- if (!Objects.equals(promoAccount.getPitcherId(), param.getPitcherId())) {
|
|
|
- promoAccountLogService.assignUpdate(param);
|
|
|
- } else {
|
|
|
- //投手没变, 开始时间更新
|
|
|
- promoAccountLogService.update(new LambdaUpdateWrapper<PromoAccountLog>()
|
|
|
- .set(PromoAccountLog::getStartTime, param.getStartTime())
|
|
|
- .set(PromoAccountLog::getPitcherGroupId, param.getPitcherGroupId())
|
|
|
- .set(PromoAccountLog::getUpdateTime, LocalDateTime.now())
|
|
|
- .eq(PromoAccountLog::getAccountId, param.getId())
|
|
|
- .isNull(PromoAccountLog::getEndTime));
|
|
|
- }
|
|
|
- //账号更新
|
|
|
- promoAccount.setPitcherId(param.getPitcherId());
|
|
|
- promoAccount.setPitcherName(param.getPitcherName());
|
|
|
- promoAccount.setPitcherGroupId(param.getPitcherGroupId());
|
|
|
- promoAccount.setPitcherGroupName(param.getPitcherGroupName());
|
|
|
- promoAccount.setRemark(param.getRemark());
|
|
|
- promoAccount.setUpdateTime(LocalDateTime.now());
|
|
|
- return super.updateById(promoAccount);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean statusUpdate(Long id, Integer status) {
|
|
|
- return super.update(new LambdaUpdateWrapper<PromoAccount>()
|
|
|
- .set(PromoAccount::getStatus, status)
|
|
|
- .set(PromoAccount::getUpdateTime, LocalDateTime.now())
|
|
|
- .eq(PromoAccount::getId, id));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<PromoAccountChoiceVO> promoAccountChoiceList() {
|
|
|
- List<PromoAccount> promoAccountList = super.list(new LambdaQueryWrapper<PromoAccount>().
|
|
|
- select(PromoAccount::getAccount, PromoAccount::getName));
|
|
|
- return promoAccountList.stream()
|
|
|
- .map(promoAccount -> BeanUtil.copy(promoAccount, PromoAccountChoiceVO.class))
|
|
|
- .collect(Collectors.toList());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<PromoPitcherChoiceVO> promoPitcherChoiceList() {
|
|
|
- List<PromoAccount> promoAccountList = super.list(new LambdaQueryWrapper<PromoAccount>().
|
|
|
- select(PromoAccount::getPitcherId, PromoAccount::getPitcherName));
|
|
|
- return promoAccountList.stream()
|
|
|
- .map(promoAccount -> BeanUtil.copy(promoAccount, PromoPitcherChoiceVO.class))
|
|
|
- .collect(Collectors.toList());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Map<Long, PromoAccountDTO> promoAccountMap() {
|
|
|
- List<PromoAccount> promoChannelList = super.list();
|
|
|
- if (CollectionUtils.isEmpty(promoChannelList)) {
|
|
|
- return Collections.emptyMap();
|
|
|
- }
|
|
|
- List<PromoAccountDTO> promoAccountDTOList = promoChannelList.stream()
|
|
|
- .map(promoAccount -> BeanUtil.copy(promoAccount, PromoAccountDTO.class))
|
|
|
- .collect(Collectors.toList());
|
|
|
- Map<Long, PromoMediaDTO> promoMediaMap = promoMediaService.promoMediaMap();
|
|
|
- promoAccountDTOList.forEach(promoAccountDTO -> {
|
|
|
- Long mediaId = promoAccountDTO.getMediaId();
|
|
|
- if (promoMediaMap.get(mediaId) != null) {
|
|
|
- promoAccountDTO.setMediaName(promoMediaMap.get(mediaId).getName());
|
|
|
- }
|
|
|
- });
|
|
|
- return promoAccountDTOList.stream().collect(Collectors.toMap(PromoAccountDTO::getId, Function.identity()));
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<Long> listByAccountOrPitcherId(String account, String pitcherId) {
|
|
|
- List<PromoAccount> promoAccountList = super.list(new LambdaQueryWrapper<PromoAccount>()
|
|
|
- .eq(Strings.isNotBlank(account), PromoAccount::getAccount, account)
|
|
|
- .eq(Strings.isNotBlank(pitcherId), PromoAccount::getPitcherId, pitcherId));
|
|
|
- if (CollectionUtils.isEmpty(promoAccountList)) {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- return promoAccountList.stream().map(PromoAccount::getId).collect(Collectors.toList());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Map<Long, PromoAccountDTO> promoAccountCondition(String pitcherGroupId, String pitcherId, Long mediaId,
|
|
|
- String account, Integer accountType) {
|
|
|
- //条件判断
|
|
|
- if (Strings.isBlank(pitcherGroupId) && Strings.isBlank(pitcherId) && mediaId == null
|
|
|
- && Strings.isBlank(account) && accountType == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- List<PromoAccount> promoAccountList = super.list(new LambdaQueryWrapper<PromoAccount>()
|
|
|
- .eq(Strings.isNotBlank(pitcherGroupId), PromoAccount::getPitcherGroupId, pitcherGroupId)
|
|
|
- .eq(Strings.isNotBlank(pitcherId), PromoAccount::getPitcherId, pitcherId)
|
|
|
- .eq(mediaId != null, PromoAccount::getMediaId, mediaId)
|
|
|
- .eq(Strings.isNotBlank(account), PromoAccount::getAccount, account)
|
|
|
- .eq(accountType != null, PromoAccount::getAccountType, accountType));
|
|
|
-
|
|
|
- List<PromoAccountDTO> promoAccountDTOList = promoAccountList.stream()
|
|
|
- .map(promoAccount -> BeanUtil.copy(promoAccount, PromoAccountDTO.class))
|
|
|
- .collect(Collectors.toList());
|
|
|
- return promoAccountDTOList.stream().collect(Collectors.toMap(PromoAccountDTO::getId, Function.identity()));
|
|
|
- }
|
|
|
-}
|