|
@@ -1,22 +1,37 @@
|
|
|
package com.zanxiang.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.common.enums.DeleteEnum;
|
|
|
+import com.zanxiang.common.enums.PromoAccountTypeEnum;
|
|
|
+import com.zanxiang.common.enums.StatusEnum;
|
|
|
+import com.zanxiang.common.exception.BaseException;
|
|
|
import com.zanxiang.common.utils.bean.BeanUtils;
|
|
|
import com.zanxiang.manage.domain.dto.PromoAccountDTO;
|
|
|
+import com.zanxiang.manage.domain.dto.PromoMediaDTO;
|
|
|
+import com.zanxiang.manage.domain.params.PromoAccountAddUpdateParam;
|
|
|
+import com.zanxiang.manage.domain.params.PromoAccountListParam;
|
|
|
import com.zanxiang.manage.domain.vo.PromoAccountChoiceVO;
|
|
|
+import com.zanxiang.manage.domain.vo.PromoAccountListVO;
|
|
|
import com.zanxiang.manage.domain.vo.PromoPitcherChoiceVO;
|
|
|
import com.zanxiang.manage.service.PromoAccountService;
|
|
|
+import com.zanxiang.manage.service.PromoMediaService;
|
|
|
import com.zanxiang.mybatis.entity.PromoAccount;
|
|
|
import com.zanxiang.mybatis.mapper.PromoAccountMapper;
|
|
|
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 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;
|
|
|
|
|
@@ -29,6 +44,124 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class PromoAccountServiceImpl extends ServiceImpl<PromoAccountMapper, PromoAccount> implements PromoAccountService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PromoMediaService promoMediaService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询推广媒体列表
|
|
|
+ *
|
|
|
+ * @param param : 推广媒体列表查询参数
|
|
|
+ * @return : 返回分页信息
|
|
|
+ */
|
|
|
+ @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));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 对象转换
|
|
|
+ *
|
|
|
+ * @param promoAccount 宣传媒体
|
|
|
+ * @return {@link PromoAccountListVO}
|
|
|
+ */
|
|
|
+ private PromoAccountListVO toVo(Map<Long, PromoMediaDTO> promoMediaMap, PromoAccount promoAccount) {
|
|
|
+ PromoAccountListVO promoAccountListVO = BeanUtils.copy(promoAccount, PromoAccountListVO.class);
|
|
|
+ if (Objects.isNull(promoAccountListVO)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ PromoMediaDTO promoMediaDTO = promoMediaMap.get(promoAccount.getMediaId());
|
|
|
+ if (promoMediaDTO != null) {
|
|
|
+ promoAccountListVO.setMediaName(promoMediaDTO.getName());
|
|
|
+ }
|
|
|
+ promoAccountListVO.setAccountTypeName(PromoAccountTypeEnum.getNameByType(promoAccountListVO.getAccountType()));
|
|
|
+ return promoAccountListVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推广账号新增或者更新
|
|
|
+ *
|
|
|
+ * @param param : 更新参数
|
|
|
+ * @return : 返回结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ 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已经存在");
|
|
|
+ }
|
|
|
+ //创建
|
|
|
+ return super.save(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());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据主键更新状态
|
|
|
+ *
|
|
|
+ * @param id : 主键id
|
|
|
+ * @param status : 状态
|
|
|
+ * @return : 返回更新结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 推广账号选择列表查询
|
|
|
*
|
|
@@ -65,6 +198,13 @@ public class PromoAccountServiceImpl extends ServiceImpl<PromoAccountMapper, Pro
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
List<PromoAccountDTO> promoAccountDTOList = BeanUtils.copyList(promoChannelList, PromoAccountDTO.class);
|
|
|
+ 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()));
|
|
|
}
|
|
|
|