|
@@ -1,17 +1,12 @@
|
|
|
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.entity.*;
|
|
|
import com.abi.qms.platform.dao.enums.ActiveAuditStatusEnum;
|
|
|
+import com.abi.qms.platform.dao.enums.ActiveModifyTypeEnum;
|
|
|
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.mapper.*;
|
|
|
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.*;
|
|
@@ -60,6 +55,12 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
|
|
|
@Autowired
|
|
|
private QrPackageMapper qrPackageMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BaseActiveModifyApplyMapper baseActiveModifyApplyMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BaseActiveModifyApplyQrPackageMappingMapper baseActiveModifyApplyQrPackageMappingMapper;
|
|
|
|
|
|
/**
|
|
|
* 新增活动
|
|
@@ -108,12 +109,17 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
* 编辑活动
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void updateActive(UpdateActiveReq req){
|
|
|
|
|
|
//1-查询活动
|
|
|
BaseActive active = baseActiveMapper.selectById(req.getId());
|
|
|
AssertUtil.isNull(active,"活动不存在");
|
|
|
|
|
|
+ if(ActiveAuditStatusEnum.REVIEW_PASS.is(active.getAuditStatus())){
|
|
|
+ throw new BusinessException("该数据已审核通过,请调用重新提交审核的接口。");
|
|
|
+ }
|
|
|
+
|
|
|
//2-修改活动
|
|
|
Long userId = userUtil.getUser().getId();
|
|
|
active.setActiveName(req.getActiveName());
|
|
@@ -132,7 +138,50 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
|
|
|
|
|
|
//删除添加关联的码包,重新插入
|
|
|
- updateActivePackageMappiing(req.getId(), req.getQrPackageIdList());
|
|
|
+ updateActivePackageMappiing(req.getId(), req.getQrPackageIdAddList(), req.getQrPackageIdDeleteList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void resubmitActive(ResubmitActiveReq req) {
|
|
|
+ //1-查询活动
|
|
|
+ BaseActive active = baseActiveMapper.selectById(req.getActiveId());
|
|
|
+ AssertUtil.isNull(active,"活动不存在");
|
|
|
+
|
|
|
+ if(ActiveAuditStatusEnum.REVIEW_PASS.is(active.getAuditStatus())){
|
|
|
+ throw new BusinessException("该数据已审核通过,请调用重新提交审核的接口。");
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除原有申请单数据
|
|
|
+ UpdateWrapper<BaseActiveModifyApply> basmaUpdate = new UpdateWrapper<>();
|
|
|
+ basmaUpdate.set("is_delete", 1)
|
|
|
+ .eq("active_id", req.getActiveId());
|
|
|
+ baseActiveModifyApplyMapper.update(null, basmaUpdate);
|
|
|
+ UpdateWrapper<BaseActiveModifyApplyQrPackageMapping> basmamUpdate = new UpdateWrapper<>();
|
|
|
+ basmamUpdate.set("is_delete", 1)
|
|
|
+ .eq("active_id", req.getActiveId());
|
|
|
+ baseActiveModifyApplyQrPackageMappingMapper.update(null, basmamUpdate);
|
|
|
+
|
|
|
+ //新增活动申请单
|
|
|
+ Long userId = userUtil.getUser().getId();
|
|
|
+ BaseActiveModifyApply baseActiveModifyApply = new BaseActiveModifyApply();
|
|
|
+ baseActiveModifyApply.setActiveId(req.getActiveId());
|
|
|
+ baseActiveModifyApply.setActiveName(req.getActiveName());
|
|
|
+ baseActiveModifyApply.setActiveType(req.getActiveType());
|
|
|
+ baseActiveModifyApply.setAuditStatus(ActiveAuditStatusEnum.WAIT_REVIEW.getCode());
|
|
|
+ baseActiveModifyApply.setApplyTime(LocalDateTime.now());
|
|
|
+ baseActiveModifyApply.setApplyUserId(userId);
|
|
|
+ baseActiveModifyApply.setApplyUserName(userUtil.getUser().getUserName());
|
|
|
+ baseActiveModifyApply.setBeginTime(req.getBeginTime());
|
|
|
+ baseActiveModifyApply.setEndTime(req.getEndTime());
|
|
|
+ baseActiveModifyApply.setBrandCode(CollectionUtil.isNotEmpty(req.getBrandCodeList()) ? String.join(",", req.getBrandCodeList()) : null);
|
|
|
+ baseActiveModifyApply.setActiveUrl(req.getActiveUrl());
|
|
|
+ baseActiveModifyApply.setUpdateBy(userId);
|
|
|
+ baseActiveModifyApply.setCreateBy(userId);
|
|
|
+ baseActiveModifyApplyMapper.insert(baseActiveModifyApply);
|
|
|
+
|
|
|
+ //批量插入 活动编辑申请码包关联子表
|
|
|
+ batchInsertActiveModifyApplyPackageMappiing(baseActiveModifyApply.getId(), req.getActiveId(), req.getQrPackageIdAddList(), req.getQrPackageIdDeleteList());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -213,6 +262,7 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
* 活动启用
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void enableActive(EnableActiveReq req){
|
|
|
List<Long> ids = req.getIds();
|
|
|
|
|
@@ -236,6 +286,7 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
* 活动禁用
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void disableActive(DisableActiveReq req){
|
|
|
List<Long> ids = req.getIds();
|
|
|
|
|
@@ -291,36 +342,33 @@ 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);
|
|
|
+ /**
|
|
|
+ * 更新码活动和码包关联子表
|
|
|
+ * @param activeId
|
|
|
+ * @param qrPackageIdAddList
|
|
|
+ */
|
|
|
+ private void updateActivePackageMappiing(Long activeId, List<Long> qrPackageIdAddList, List<Long> qrPackageIdDeleteList){
|
|
|
+ //添加和删除的去重
|
|
|
+ List<Long> distinctBatch = new ArrayList<>(qrPackageIdAddList);
|
|
|
+ distinctBatch.retainAll(qrPackageIdAddList);
|
|
|
+ qrPackageIdAddList.removeAll(distinctBatch);
|
|
|
+ qrPackageIdDeleteList.removeAll(distinctBatch);
|
|
|
|
|
|
Long loginUserId = userUtil.getUser().getId();
|
|
|
|
|
|
//批量删除
|
|
|
- if(CollectionUtil.isNotEmpty(deleteBatch)){
|
|
|
+ if(CollectionUtil.isNotEmpty(qrPackageIdDeleteList)){
|
|
|
UpdateWrapper<BaseActiveQrPackageMapping> aqpmQW = new UpdateWrapper<>();
|
|
|
aqpmQW.set("is_delete", 1)
|
|
|
.set("update_by", loginUserId)
|
|
|
.eq("active_id", activeId)
|
|
|
- .in("qr_package_id", deleteBatch);
|
|
|
+ .in("qr_package_id", qrPackageIdDeleteList);
|
|
|
baseActiveQrPackageMappingMapper.update(null, aqpmQW);
|
|
|
}
|
|
|
|
|
|
//批量添加
|
|
|
- if(CollectionUtil.isNotEmpty(addBatch)){
|
|
|
- List<QrPackage> qrPackages = searchReviewPassPackageByPackageIds(addBatch);
|
|
|
+ if(CollectionUtil.isNotEmpty(qrPackageIdAddList)){
|
|
|
+ List<QrPackage> qrPackages = searchReviewPassPackageByPackageIds(qrPackageIdAddList);
|
|
|
List<Long> qrPackageIdsAdd = qrPackages.stream().map(QrPackage::getId).collect(Collectors.toList());
|
|
|
if(CollectionUtil.isNotEmpty(qrPackageIdsAdd)) {
|
|
|
baseActiveQrPackageMappingMapper.batchInsert(activeId, qrPackageIdsAdd, loginUserId);
|
|
@@ -341,4 +389,42 @@ public class ActiveServiceImpl implements ActiveService {
|
|
|
return qrPackageMapper.selectList(qrPackageQueryWrapper);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 批量插入 活动编辑申请码包关联子表
|
|
|
+ * @param activeId
|
|
|
+ * @param qrPackageIdAddList
|
|
|
+ */
|
|
|
+ private void batchInsertActiveModifyApplyPackageMappiing(Long applyId, Long activeId, List<Long> qrPackageIdAddList, List<Long> qrPackageIdDeleteList){
|
|
|
+ //添加和删除的去重
|
|
|
+ List<Long> distinctBatch = new ArrayList<>(qrPackageIdAddList);
|
|
|
+ distinctBatch.retainAll(qrPackageIdAddList);
|
|
|
+ qrPackageIdAddList.removeAll(distinctBatch);
|
|
|
+ qrPackageIdDeleteList.removeAll(distinctBatch);
|
|
|
+
|
|
|
+ List<BatchInsertActiveModifyApplyQrPackageColumnReq.PackageAndModifyType> batchInsertamaqpcrpam = new ArrayList<>();
|
|
|
+ Long loginUserId = userUtil.getUser().getId();
|
|
|
+ qrPackageIdAddList.forEach(qrPackageIdAdd -> {
|
|
|
+ BatchInsertActiveModifyApplyQrPackageColumnReq.PackageAndModifyType packageAndModifyType = new BatchInsertActiveModifyApplyQrPackageColumnReq.PackageAndModifyType();
|
|
|
+ packageAndModifyType.setQrPackageId(qrPackageIdAdd);
|
|
|
+ packageAndModifyType.setModifyType(ActiveModifyTypeEnum.ADD.getCode());
|
|
|
+ batchInsertamaqpcrpam.add(packageAndModifyType);
|
|
|
+ });
|
|
|
+
|
|
|
+ qrPackageIdDeleteList.forEach(qrPackageIdDelete -> {
|
|
|
+ BatchInsertActiveModifyApplyQrPackageColumnReq.PackageAndModifyType packageAndModifyType = new BatchInsertActiveModifyApplyQrPackageColumnReq.PackageAndModifyType();
|
|
|
+ packageAndModifyType.setQrPackageId(qrPackageIdDelete);
|
|
|
+ packageAndModifyType.setModifyType(ActiveModifyTypeEnum.DELETE.getCode());
|
|
|
+ batchInsertamaqpcrpam.add(packageAndModifyType);
|
|
|
+ });
|
|
|
+
|
|
|
+ //批量插入
|
|
|
+ BatchInsertActiveModifyApplyQrPackageColumnReq columnReq = new BatchInsertActiveModifyApplyQrPackageColumnReq();
|
|
|
+ columnReq.setApplyId(applyId);
|
|
|
+ columnReq.setActiveId(activeId);
|
|
|
+ columnReq.setCreateBy(loginUserId);
|
|
|
+ columnReq.setUpdateBy(loginUserId);
|
|
|
+ columnReq.setPackageAndModifyTypeList(batchInsertamaqpcrpam);
|
|
|
+ baseActiveModifyApplyQrPackageMappingMapper.batchInsert(columnReq);
|
|
|
+ }
|
|
|
+
|
|
|
}
|