|
@@ -1,17 +1,23 @@
|
|
|
package com.abi.qms.platform.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
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.entity.QrPackage;
|
|
|
import com.abi.qms.platform.dao.enums.ActiveAuditStatusEnum;
|
|
|
+import com.abi.qms.platform.dao.enums.QrPackageApplyStatusEnum;
|
|
|
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.mapper.QrPackageMapper;
|
|
|
import com.abi.qms.platform.dao.vo.result.ActivePackageVO;
|
|
|
+import com.abi.qms.platform.dao.vo.result.PackageActiveSearchVO;
|
|
|
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.ListActivePackageAddRes;
|
|
|
+import com.abi.qms.platform.dto.res.ListActivePackageRes;
|
|
|
import com.abi.qms.platform.dto.res.ListActiveRes;
|
|
|
import com.abi.qms.platform.infrastructure.util.AssertUtil;
|
|
|
import com.abi.qms.platform.infrastructure.util.PageUtil;
|
|
@@ -27,9 +33,7 @@ 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.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -53,6 +57,9 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
|
|
|
@Autowired
|
|
|
private BaseBrandMapper baseBrandMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QrPackageMapper qrPackageMapper;
|
|
|
|
|
|
/**
|
|
|
* 新增活动
|
|
@@ -67,7 +74,7 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
activeVali.eq("is_delete", 0);
|
|
|
BaseActive baseActive = baseActiveMapper.selectOne(activeVali);
|
|
|
if (Objects.nonNull(baseActive)){
|
|
|
- throw new BusinessException("活动ID" + req.getActiveCode() + "已存在。");
|
|
|
+ throw new BusinessException("码活动ID" + req.getActiveCode() + "已存在。");
|
|
|
}
|
|
|
|
|
|
//1-新增
|
|
@@ -82,14 +89,18 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
active.setApplyUserName(userUtil.getUser().getUserName());
|
|
|
active.setBeginTime(req.getBeginTime());
|
|
|
active.setEndTime(req.getEndTime());
|
|
|
- active.setBrandCode(req.getBrandCode());
|
|
|
+ active.setBrandCode(CollectionUtil.isNotEmpty(req.getBrandCodeList()) ? String.join(",", req.getBrandCodeList()) : null);
|
|
|
active.setActiveUrl(req.getActiveUrl());
|
|
|
active.setCreateBy(userId);
|
|
|
active.setUpdateBy(userId);
|
|
|
baseActiveMapper.insert(active);
|
|
|
|
|
|
//添加码活动和码包的关联
|
|
|
- baseActiveQrPackageMappingMapper.batchInsert(active.getId(), req.getQrPackageIdList(), userId);
|
|
|
+ List<QrPackage> qrPackages = searchReviewPassPackageByPackageIds(req.getQrPackageIdList());
|
|
|
+ List<Long> qrPackageIdsAdd = qrPackages.stream().map(QrPackage::getId).collect(Collectors.toList());
|
|
|
+ if(CollectionUtil.isNotEmpty(qrPackageIdsAdd)) {
|
|
|
+ baseActiveQrPackageMappingMapper.batchInsert(active.getId(), qrPackageIdsAdd, userId);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -114,17 +125,14 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
active.setApplyUserName(userUtil.getUser().getUserName());
|
|
|
active.setBeginTime(req.getBeginTime());
|
|
|
active.setEndTime(req.getEndTime());
|
|
|
- active.setBrandCode(req.getBrandCode());
|
|
|
+ active.setBrandCode(CollectionUtil.isNotEmpty(req.getBrandCodeList()) ? String.join(",", req.getBrandCodeList()) : null);
|
|
|
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);
|
|
|
+
|
|
|
+ //删除添加关联的码包,重新插入
|
|
|
+ updateActivePackageMappiing(req.getId(), req.getQrPackageIdList());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -182,21 +190,33 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
}
|
|
|
|
|
|
//查询码活动关联的码包列表
|
|
|
- res.setListActivePackage(listActivePackage(req));
|
|
|
+ res.setListActivePackageRes(listActivePackage(req));
|
|
|
return res;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ListActivePackage listActivePackage(GetActiveReq req) {
|
|
|
+ public ListActivePackageRes 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;
|
|
|
+ ListActivePackageRes listActivePackageRes = new ListActivePackageRes();
|
|
|
+ PageUtil.copyPageInfo(listActivePackageRes, activePackageVOIPage);
|
|
|
+ List<ListActivePackageRes.PackageBean> packageBeans = PojoConverterUtils.copyList(records, ListActivePackageRes.PackageBean.class);
|
|
|
+ listActivePackageRes.setPackageBeanList(packageBeans);
|
|
|
+ return listActivePackageRes;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ListActivePackageAddRes listActivePackageAdd(ListActivePackageAddReq req) {
|
|
|
+ //查询码活动关联的码包列表
|
|
|
+ IPage<PackageActiveSearchVO> packageActiveSearchVOIPage = qrPackageMapper.listPackageByBrandCode(PageUtil.createPage(req), req);
|
|
|
+ List<PackageActiveSearchVO> records = packageActiveSearchVOIPage.getRecords();
|
|
|
+ ListActivePackageAddRes listActivePackageAddRes = new ListActivePackageAddRes();
|
|
|
+ PageUtil.copyPageInfo(listActivePackageAddRes, packageActiveSearchVOIPage);
|
|
|
+ List<ListActivePackageAddRes.PackageBean> packageBeans = PojoConverterUtils.copyList(records, ListActivePackageAddRes.PackageBean.class);
|
|
|
+ listActivePackageAddRes.setPackageBeanList(packageBeans);
|
|
|
+ return listActivePackageAddRes;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -280,4 +300,55 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private void updateActivePackageMappiing(Long activeId, List<Long> qrPackageIdList){
|
|
|
+ //查询已存在的码活动和码包的关联
|
|
|
+ QueryWrapper<BaseActiveQrPackageMapping> baseActiveQrPackageMappingQW = new QueryWrapper<>();
|
|
|
+ baseActiveQrPackageMappingQW.eq("active_id", activeId);
|
|
|
+ baseActiveQrPackageMappingQW.eq("is_delete", 0);
|
|
|
+ List<BaseActiveQrPackageMapping> baseActiveQrPackageMappings = baseActiveQrPackageMappingMapper.selectList(baseActiveQrPackageMappingQW);
|
|
|
+ //聚合绑定的码包
|
|
|
+ List<Long> oldPackageIdList = baseActiveQrPackageMappings.stream().map(BaseActiveQrPackageMapping::getQrPackageId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //排除要添加的关联码包,和要删除的关联码包
|
|
|
+ List<Long> deleteBatch = new ArrayList<>(oldPackageIdList);
|
|
|
+ deleteBatch.removeAll(qrPackageIdList);
|
|
|
+ List<Long> addBatch = new ArrayList<>(qrPackageIdList);
|
|
|
+ addBatch.removeAll(oldPackageIdList);
|
|
|
+
|
|
|
+ Long loginUserId = userUtil.getUser().getId();
|
|
|
+
|
|
|
+ //批量删除
|
|
|
+ if(CollectionUtil.isNotEmpty(deleteBatch)){
|
|
|
+ UpdateWrapper<BaseActiveQrPackageMapping> aqpmQW = new UpdateWrapper<>();
|
|
|
+ aqpmQW.set("is_delete", 1)
|
|
|
+ .set("update_by", loginUserId)
|
|
|
+ .eq("active_id", activeId)
|
|
|
+ .in("qr_package_id", deleteBatch);
|
|
|
+ baseActiveQrPackageMappingMapper.update(null, aqpmQW);
|
|
|
+ }
|
|
|
+
|
|
|
+ //批量添加
|
|
|
+ if(CollectionUtil.isNotEmpty(addBatch)){
|
|
|
+ List<QrPackage> qrPackages = searchReviewPassPackageByPackageIds(addBatch);
|
|
|
+ List<Long> qrPackageIdsAdd = qrPackages.stream().map(QrPackage::getId).collect(Collectors.toList());
|
|
|
+ if(CollectionUtil.isNotEmpty(qrPackageIdsAdd)) {
|
|
|
+ baseActiveQrPackageMappingMapper.batchInsert(activeId, qrPackageIdsAdd, loginUserId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据packgeId列表查询有效的且审核通过的码包列表
|
|
|
+ * @param packageIdList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<QrPackage> searchReviewPassPackageByPackageIds(List<Long> packageIdList){
|
|
|
+ QueryWrapper<QrPackage> qrPackageQueryWrapper = new QueryWrapper<>();
|
|
|
+ qrPackageQueryWrapper.in("id", packageIdList);
|
|
|
+ qrPackageQueryWrapper.eq("apply_status", QrPackageApplyStatusEnum.REVIEW_PASS.getCode());
|
|
|
+ qrPackageQueryWrapper.eq("is_delete", 0);
|
|
|
+ return qrPackageMapper.selectList(qrPackageQueryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
}
|