|
@@ -1,19 +1,36 @@
|
|
|
package com.abi.qms.platform.service.impl;
|
|
|
|
|
|
import com.abi.qms.platform.dao.entity.BaseActive;
|
|
|
+import com.abi.qms.platform.dao.entity.BaseActiveQrPackageMapping;
|
|
|
+import com.abi.qms.platform.dao.entity.BaseBrand;
|
|
|
+import com.abi.qms.platform.dao.enums.ActiveAuditStatusEnum;
|
|
|
+import com.abi.qms.platform.dao.enums.ValidEnum;
|
|
|
import com.abi.qms.platform.dao.mapper.BaseActiveMapper;
|
|
|
+import com.abi.qms.platform.dao.mapper.BaseActiveQrPackageMappingMapper;
|
|
|
+import com.abi.qms.platform.dao.mapper.BaseBrandMapper;
|
|
|
+import com.abi.qms.platform.dao.vo.result.ActivePackageVO;
|
|
|
import com.abi.qms.platform.dto.req.*;
|
|
|
import com.abi.qms.platform.dto.res.GetActiveRes;
|
|
|
+import com.abi.qms.platform.dto.res.ListActivePackage;
|
|
|
import com.abi.qms.platform.dto.res.ListActiveRes;
|
|
|
import com.abi.qms.platform.infrastructure.util.AssertUtil;
|
|
|
import com.abi.qms.platform.infrastructure.util.PageUtil;
|
|
|
+import com.abi.qms.platform.infrastructure.util.UserUtil;
|
|
|
import com.abi.qms.platform.service.ActiveService;
|
|
|
+import com.abi.task.common.api.exception.BusinessException;
|
|
|
import com.abi.task.common.utils.PojoConverterUtils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
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.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -28,32 +45,52 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
@Autowired
|
|
|
private BaseActiveMapper baseActiveMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BaseActiveQrPackageMappingMapper baseActiveQrPackageMappingMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserUtil userUtil;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BaseBrandMapper baseBrandMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 新增活动
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void addActive(AddActiveReq req){
|
|
|
//校验入参
|
|
|
- //TODO
|
|
|
+ //活动ID不可重复创建。
|
|
|
+ QueryWrapper<BaseActive> activeVali = new QueryWrapper<>();
|
|
|
+ activeVali.eq("active_code", req.getActiveCode());
|
|
|
+ activeVali.eq("is_delete", 0);
|
|
|
+ BaseActive baseActive = baseActiveMapper.selectOne(activeVali);
|
|
|
+ if (Objects.nonNull(baseActive)){
|
|
|
+ throw new BusinessException("活动ID" + req.getActiveCode() + "已存在。");
|
|
|
+ }
|
|
|
|
|
|
//1-新增
|
|
|
+ Long userId = userUtil.getUser().getId();
|
|
|
BaseActive active = new BaseActive();
|
|
|
active.setActiveCode(req.getActiveCode());
|
|
|
active.setActiveName(req.getActiveName());
|
|
|
active.setActiveType(req.getActiveType());
|
|
|
- active.setAuditStatus(req.getAuditStatus());
|
|
|
- active.setApplyUserId(req.getApplyUserId());
|
|
|
- active.setApplyUserName(req.getApplyUserName());
|
|
|
- active.setAuditUserId(req.getAuditUserId());
|
|
|
- active.setAuditUserName(req.getAuditUserName());
|
|
|
+ active.setAuditStatus(ActiveAuditStatusEnum.WAIT_REVIEW.getCode());
|
|
|
+ active.setApplyTime(LocalDateTime.now());
|
|
|
+ active.setApplyUserId(userId);
|
|
|
+ active.setApplyUserName(userUtil.getUser().getUserName());
|
|
|
active.setBeginTime(req.getBeginTime());
|
|
|
active.setEndTime(req.getEndTime());
|
|
|
active.setBrandCode(req.getBrandCode());
|
|
|
- active.setSubBrandCode(req.getSubBrandCode());
|
|
|
active.setActiveUrl(req.getActiveUrl());
|
|
|
+ active.setCreateBy(userId);
|
|
|
+ active.setUpdateBy(userId);
|
|
|
baseActiveMapper.insert(active);
|
|
|
|
|
|
+ //添加码活动和码包的关联
|
|
|
+ baseActiveQrPackageMappingMapper.batchInsert(active.getId(), req.getQrPackageIdList(), userId);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -67,21 +104,27 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
AssertUtil.isNull(active,"活动不存在");
|
|
|
|
|
|
//2-修改活动
|
|
|
- active.setActiveCode(req.getActiveCode());
|
|
|
+ Long userId = userUtil.getUser().getId();
|
|
|
active.setActiveName(req.getActiveName());
|
|
|
active.setActiveType(req.getActiveType());
|
|
|
- active.setAuditStatus(req.getAuditStatus());
|
|
|
- active.setApplyUserId(req.getApplyUserId());
|
|
|
- active.setApplyUserName(req.getApplyUserName());
|
|
|
- active.setAuditUserId(req.getAuditUserId());
|
|
|
- active.setAuditUserName(req.getAuditUserName());
|
|
|
+ //只要经过编辑,就恢复成待审核状态
|
|
|
+ active.setAuditStatus(ActiveAuditStatusEnum.WAIT_REVIEW.getCode());
|
|
|
+ active.setApplyTime(LocalDateTime.now());
|
|
|
+ active.setApplyUserId(userId);
|
|
|
+ active.setApplyUserName(userUtil.getUser().getUserName());
|
|
|
active.setBeginTime(req.getBeginTime());
|
|
|
active.setEndTime(req.getEndTime());
|
|
|
active.setBrandCode(req.getBrandCode());
|
|
|
- active.setSubBrandCode(req.getSubBrandCode());
|
|
|
active.setActiveUrl(req.getActiveUrl());
|
|
|
+ active.setUpdateBy(userId);
|
|
|
baseActiveMapper.updateById(active);
|
|
|
|
|
|
+ //删除关联的码包,重新插入
|
|
|
+ UpdateWrapper<BaseActiveQrPackageMapping> aqpmQW = new UpdateWrapper<>();
|
|
|
+ aqpmQW.set("is_delete", 1)
|
|
|
+ .eq("active_id", active.getId());
|
|
|
+ baseActiveQrPackageMappingMapper.update(null, aqpmQW);
|
|
|
+ baseActiveQrPackageMappingMapper.batchInsert(active.getId(), req.getQrPackageIdList(), userId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -90,15 +133,19 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
@Override
|
|
|
public ListActiveRes listActive(ListActiveReq req){
|
|
|
|
|
|
- //1-拼接条件
|
|
|
- QueryWrapper<BaseActive> activeQw = new QueryWrapper<>();
|
|
|
- //activeQw.like(StringUtils.isNotBlank(req.getXxx()), "xxx_xxx", "%" + req.getXxx() + "%");
|
|
|
- //activeQw.eq(req.getXxx2() != null, "xxx_xxx2", req.getXxx2());
|
|
|
-
|
|
|
- //2-分页查询
|
|
|
- IPage<BaseActive> iPage = baseActiveMapper.selectPage(PageUtil.createPage(req), activeQw);
|
|
|
+ //分页查询
|
|
|
+ IPage<BaseActive> iPage = baseActiveMapper.listActivePage(PageUtil.createPage(req), req);
|
|
|
List<BaseActive> activeList = iPage.getRecords();
|
|
|
-
|
|
|
+ //活动状态作处理 1-待审核 2-通过 3-启用 9-驳回 10-停用
|
|
|
+ activeList.forEach(active -> {
|
|
|
+ if(ActiveAuditStatusEnum.REVIEW_PASS.is(active.getAuditStatus())){
|
|
|
+ if(ValidEnum.VALID.is(active.getValid())){
|
|
|
+ active.setAuditStatus(ActiveAuditStatusEnum.ENABLE.getCode());
|
|
|
+ }else{
|
|
|
+ active.setAuditStatus(ActiveAuditStatusEnum.DISABLE.getCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
//封装出参
|
|
|
ListActiveRes res = new ListActiveRes();
|
|
|
//放入分页信息
|
|
@@ -123,11 +170,35 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
|
|
|
//转化出参
|
|
|
GetActiveRes res = PojoConverterUtils.copy(active, GetActiveRes.class);
|
|
|
+ //处理品牌code,品牌名称
|
|
|
+ if(Objects.nonNull(active.getBrandCode())){
|
|
|
+ String[] brandSplit = active.getBrandCode().trim().split(",");
|
|
|
+ res.setBrandCodeList(Arrays.asList(brandSplit));
|
|
|
+ QueryWrapper<BaseBrand> baseBrandQW = new QueryWrapper<>();
|
|
|
+ baseBrandQW.in("brand_code", brandSplit);
|
|
|
+ List<BaseBrand> baseBrands = baseBrandMapper.selectList(baseBrandQW);
|
|
|
+ List<String> baseBrandNameList = baseBrands.stream().map(BaseBrand::getBrandName).collect(Collectors.toList());
|
|
|
+ res.setBrandNameList(baseBrandNameList);
|
|
|
+ }
|
|
|
|
|
|
+ //查询码活动关联的码包列表
|
|
|
+ res.setListActivePackage(listActivePackage(req));
|
|
|
return res;
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ListActivePackage listActivePackage(GetActiveReq req) {
|
|
|
+ //查询码活动关联的码包列表
|
|
|
+ IPage<ActivePackageVO> activePackageVOIPage = baseActiveMapper.listPackageById(PageUtil.createPage(req), req.getId());
|
|
|
+ List<ActivePackageVO> records = activePackageVOIPage.getRecords();
|
|
|
+ ListActivePackage listActivePackage = new ListActivePackage();
|
|
|
+ PageUtil.copyPageInfo(listActivePackage, activePackageVOIPage);
|
|
|
+ List<ListActivePackage.PackageBean> packageBeans = PojoConverterUtils.copyList(records, ListActivePackage.PackageBean.class);
|
|
|
+ listActivePackage.setPackageBeanList(packageBeans);
|
|
|
+ return listActivePackage;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 活动启用
|
|
|
*/
|
|
@@ -141,13 +212,13 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
BaseActive active = baseActiveMapper.selectById(id);
|
|
|
AssertUtil.isNull(active, "活动不存在");
|
|
|
|
|
|
-// if (!ValidEnum.NOT_VALID.is(active.getValid())) {
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-//
|
|
|
-// //2-修改状态
|
|
|
-// active.setValid(ValidEnum.VALID.getCode());
|
|
|
-// baseActiveMapper.updateById(active);
|
|
|
+ if (!ValidEnum.NOT_VALID.is(active.getValid())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //2-修改状态
|
|
|
+ active.setValid(ValidEnum.VALID.getCode());
|
|
|
+ baseActiveMapper.updateById(active);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -164,14 +235,49 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
BaseActive active = baseActiveMapper.selectById(id);
|
|
|
AssertUtil.isNull(active, "活动不存在");
|
|
|
|
|
|
-// if (!ValidEnum.VALID.is(active.getValid())) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-//
|
|
|
-// //2-修改状态
|
|
|
-// active.setValid(ValidEnum.NOT_VALID.getCode());
|
|
|
-// baseActiveMapper.updateById(active);
|
|
|
+ if (!ValidEnum.VALID.is(active.getValid())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //2-修改状态
|
|
|
+ active.setValid(ValidEnum.NOT_VALID.getCode());
|
|
|
+ baseActiveMapper.updateById(active);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void passActive(PassActiveReq req) {
|
|
|
+ BaseActive active = baseActiveMapper.selectById(req.getId());
|
|
|
+ AssertUtil.isNull(active, "活动不存在");
|
|
|
+
|
|
|
+ if(ActiveAuditStatusEnum.WAIT_REVIEW.is(active.getAuditStatus())){
|
|
|
+ throw new BusinessException("该活动不能审核");
|
|
|
+ }
|
|
|
+ Long userId = userUtil.getUser().getId();
|
|
|
+ active.setAuditStatus(ActiveAuditStatusEnum.REVIEW_PASS.getCode());
|
|
|
+ active.setAuditUserId(userId);
|
|
|
+ active.setAuditUserName(userUtil.getUser().getUserName());
|
|
|
+ active.setUpdateBy(userId);
|
|
|
+ baseActiveMapper.updateById(active);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void refuseActive(RefuseActiveReq req) {
|
|
|
+ BaseActive active = baseActiveMapper.selectById(req.getId());
|
|
|
+ AssertUtil.isNull(active, "活动不存在");
|
|
|
+ if(ActiveAuditStatusEnum.WAIT_REVIEW.is(active.getAuditStatus())){
|
|
|
+ throw new BusinessException("该活动不能审核");
|
|
|
+ }
|
|
|
+ Long userId = userUtil.getUser().getId();
|
|
|
+ active.setAuditStatus(ActiveAuditStatusEnum.REVIEW_REFUSE.getCode());
|
|
|
+ active.setAuditUserId(userId);
|
|
|
+ active.setAuditUserName(userUtil.getUser().getUserName());
|
|
|
+ active.setUpdateBy(userId);
|
|
|
+ baseActiveMapper.updateById(active);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|