Przeglądaj źródła

Merge branch 'feature/1.0.0' of github.com:ab-inbev-apac/abi-cloud-qr-platform into feature/1.0.0

tanzhongran 4 lat temu
rodzic
commit
0194b67534
16 zmienionych plików z 345 dodań i 73 usunięć
  1. 15 8
      abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/controller/console/ActiveController.java
  2. 4 0
      abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dao/mapper/BaseBrandMapper.java
  3. 12 0
      abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dao/mapper/QrPackageMapper.java
  4. 7 12
      abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dao/tablestore/entity/QrCode.java
  5. 42 0
      abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dao/vo/result/PackageActiveSearchVO.java
  6. 6 3
      abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/req/AddActiveReq.java
  7. 34 0
      abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/req/ListActivePackageAddReq.java
  8. 4 1
      abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/req/UpdateActiveReq.java
  9. 1 1
      abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/res/GetActiveRes.java
  10. 61 0
      abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/res/ListActivePackageAddRes.java
  11. 1 1
      abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/res/ListActivePackage.java
  12. 15 20
      abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/infrastructure/mq/GenerateCodeConsumer.java
  13. 11 3
      abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/ActiveService.java
  14. 92 21
      abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/impl/ActiveServiceImpl.java
  15. 0 3
      abi-cloud-qr-platform-server/src/main/resources/dao/mapper/BaseBrandMapper.xml
  16. 40 0
      abi-cloud-qr-platform-server/src/main/resources/dao/mapper/QrPackageMapper.xml

+ 15 - 8
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/controller/console/ActiveController.java

@@ -2,7 +2,8 @@ package com.abi.qms.platform.controller.console;
 
 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.service.ActiveService;
 import com.abi.task.common.api.base.BaseResponse;
@@ -13,9 +14,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
-import javax.servlet.http.HttpServletResponse;
-import java.util.List;
-
 /**
  * <p>
  * 活动管理
@@ -26,7 +24,7 @@ import java.util.List;
 @Slf4j
 @RestController
 @RequestMapping("active")
-@Api(tags = "活动管理")
+@Api(tags = "活动管理")
 public class ActiveController {
 
     @Autowired
@@ -60,11 +58,20 @@ public class ActiveController {
         return BaseResponse.create(result);
     }
 
-    @ApiOperation("分页查询关联码包列表")
+    @ApiOperation("分页查询码活动未关联的码包列表(新增修改页面)")
+    @GetMapping("listActivePackageAdd")
+    public BaseResponse<ListActivePackageAddRes> listActivePackageAdd(@Validated ListActivePackageAddReq req) throws Exception{
+        //分页查询
+        ListActivePackageAddRes result = activeService.listActivePackageAdd(req);
+        //包装出参
+        return BaseResponse.create(result);
+    }
+
+    @ApiOperation("分页查询关联码包列表(编辑审核页面)")
     @GetMapping("listActivePackage")
-    public BaseResponse<ListActivePackage> listActivePackage(@Validated GetActiveReq getActiveReq) throws Exception{
+    public BaseResponse<ListActivePackageRes> listActivePackage(@Validated GetActiveReq getActiveReq) throws Exception{
         //分页查询
-        ListActivePackage result = activeService.listActivePackage(getActiveReq);
+        ListActivePackageRes result = activeService.listActivePackage(getActiveReq);
         //包装出参
         return BaseResponse.create(result);
     }

+ 4 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dao/mapper/BaseBrandMapper.java

@@ -1,7 +1,11 @@
 package com.abi.qms.platform.dao.mapper;
 
 import com.abi.qms.platform.dao.entity.BaseBrand;
+import com.abi.qms.platform.dao.vo.result.ActivePackageVO;
+import com.abi.qms.platform.dto.req.ListActivePackageAddReq;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * <p>

+ 12 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dao/mapper/QrPackageMapper.java

@@ -1,10 +1,14 @@
 package com.abi.qms.platform.dao.mapper;
 
 import com.abi.qms.platform.dao.entity.QrPackage;
+import com.abi.qms.platform.dao.vo.result.ActivePackageVO;
+import com.abi.qms.platform.dao.vo.result.PackageActiveSearchVO;
 import com.abi.qms.platform.dao.vo.result.QrPackageVO;
+import com.abi.qms.platform.dto.req.ListActivePackageAddReq;
 import com.abi.qms.platform.dto.req.ListQrPackageReq;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 码包 Mapper接口
@@ -23,4 +27,12 @@ public interface QrPackageMapper extends BaseMapper<QrPackage> {
 	 * 查询码包详细信息
 	 */
 	QrPackageVO selectQrPackageDetailById(Long id);
+
+	/**
+	 * 通过品牌code查询关联码包列表
+	 * @param page
+	 * @param req
+	 * @return
+	 */
+	IPage<PackageActiveSearchVO> listPackageByBrandCode(IPage page, @Param("param") ListActivePackageAddReq req);
 }

+ 7 - 12
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dao/tablestore/entity/QrCode.java

@@ -14,16 +14,11 @@ import java.time.LocalDateTime;
  */
 @Data
 @NoArgsConstructor
-@TableStore(tableName = "qr_code",primaryKeyName = "id")
+@TableStore(tableName = "qr_code",primaryKeyName = "code")
 public class QrCode implements TableStoreEntity, Serializable {
 
     /**
-     * 主键
-     */
-    private String id;
-
-    /**
-     * 码
+     * 主键码
      */
     private String code;
 
@@ -37,11 +32,6 @@ public class QrCode implements TableStoreEntity, Serializable {
      */
     private Long batchNumberId;
 
-    /**
-     * url
-     */
-    private String url;
-
     /**
      * 创建时间
      */
@@ -51,4 +41,9 @@ public class QrCode implements TableStoreEntity, Serializable {
      * 已生成码包位置
      */
     private Long codeIndex;
+
+    /**
+     * 码库列ID
+     */
+    private Long qrRepertoryColumnId;
 }

+ 42 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dao/vo/result/PackageActiveSearchVO.java

@@ -0,0 +1,42 @@
+package com.abi.qms.platform.dao.vo.result;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author Eurus
+ * @date 2021/5/27 16:00
+ * @Description: 码活动未关联码包列表查询(通过所属品牌)
+ */
+@Data
+@ApiModel
+public class PackageActiveSearchVO implements Serializable {
+
+    @ApiModelProperty("码包id")
+    private Long packageId;
+
+    @ApiModelProperty("码类型 1-箱码 2-盖码")
+    private Integer qrType;
+
+    @ApiModelProperty("sku名称")
+    private String skuName;
+
+    @ApiModelProperty("品牌名称")
+    private String brandName;
+
+    @ApiModelProperty("上级品牌名称")
+    private String parentBrandName;
+
+    @ApiModelProperty("码数量")
+    private Long qrNumber;
+
+    @ApiModelProperty("是否参与活动")
+    private Integer isJoinActive;
+
+    @ApiModelProperty("参与活动名称")
+    private String activeName;
+
+}

+ 6 - 3
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/req/AddActiveReq.java

@@ -1,5 +1,6 @@
 package com.abi.qms.platform.dto.req;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -30,17 +31,19 @@ public class AddActiveReq implements Serializable {
     @ApiModelProperty(value = "活动类型 1-utc 2-bof 3-品质信息")
     private Integer activeType;
 
-    @NotEmpty(message = "活动开始日期为空")
+    @NotNull(message = "活动开始日期为空")
     @ApiModelProperty(value = "活动开始日期")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime beginTime;
 
-    @NotEmpty(message = "活动结束日期为空")
+    @NotNull(message = "活动结束日期为空")
     @ApiModelProperty(value = "活动结束日期")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime endTime;
 
     @NotEmpty(message = "所属品牌为空")
     @ApiModelProperty(value = "所属品牌")
-    private String brandCode;
+    private List<String> brandCodeList;
 
     @NotEmpty(message = "活动域名为空")
     @ApiModelProperty(value = "活动域名")

+ 34 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/req/ListActivePackageAddReq.java

@@ -0,0 +1,34 @@
+package com.abi.qms.platform.dto.req;
+
+import com.abi.task.common.api.base.PageReq;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author Eurus
+ * @date 2021/5/27 11:34
+ * @Description: 分页查询关联的码包列表(新增页面) 入参
+ */
+@Data
+@ApiModel
+public class ListActivePackageAddReq extends PageReq implements Serializable {
+
+    @ApiModelProperty("活动id")
+    private Long activeId;
+
+    @ApiModelProperty("码包id")
+    private Long packageId;
+
+    @ApiModelProperty("码类型 1-箱码 2-盖码")
+    private Integer qrType;
+
+    @ApiModelProperty("sku名称")
+    private String skuName;
+
+    @ApiModelProperty("所属品牌code")
+    private List<String> brandCodeList;
+}

+ 4 - 1
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/req/UpdateActiveReq.java

@@ -1,5 +1,6 @@
 package com.abi.qms.platform.dto.req;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -27,13 +28,15 @@ public class UpdateActiveReq implements Serializable {
     private Integer activeType;
 
     @ApiModelProperty(value = "活动开始日期")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime beginTime;
 
     @ApiModelProperty(value = "活动结束日期")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime endTime;
 
     @ApiModelProperty(value = "品牌code")
-    private String brandCode;
+    private List<String> brandCodeList;
 
     @ApiModelProperty(value = "活动域名")
     private String activeUrl;

+ 1 - 1
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/res/GetActiveRes.java

@@ -47,6 +47,6 @@ public class GetActiveRes implements Serializable {
     private String activeUrl;
 
     @ApiModelProperty(value = "码包列表")
-    private ListActivePackage listActivePackage;
+    private ListActivePackageRes listActivePackageRes;
 
 }

+ 61 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/res/ListActivePackageAddRes.java

@@ -0,0 +1,61 @@
+package com.abi.qms.platform.dto.res;
+
+import com.abi.task.common.api.base.PageResp;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author Eurus
+ * @date 2021/5/27 11:39
+ * @Description: 分页查询关联的码包列表(新增页面) 出参
+ */
+@Data
+@ApiModel
+public class ListActivePackageAddRes extends PageResp implements Serializable {
+
+    @ApiModelProperty("码包列表")
+    private List<PackageBean> packageBeanList;
+
+
+    /**
+     * 码包bean
+     */
+    @Data
+    @NoArgsConstructor
+    @AllArgsConstructor
+    @ToString
+    @ApiModel(value = "ListActivePackageAddRes_Package")
+    public static class PackageBean implements Serializable {
+
+        @ApiModelProperty("码包id")
+        private Long packageId;
+
+        @ApiModelProperty("码类型 1-箱码 2-盖码")
+        private Integer qrType;
+
+        @ApiModelProperty("sku名称")
+        private String skuName;
+
+        @ApiModelProperty("品牌名称")
+        private String brandName;
+
+        @ApiModelProperty("上级品牌名称")
+        private String parentBrandName;
+
+        @ApiModelProperty("码数量")
+        private Long qrNumber;
+
+        @ApiModelProperty("是否参与活动")
+        private Integer isJoinActive;
+
+        @ApiModelProperty("参与活动名称")
+        private String activeName;
+    }
+}

+ 1 - 1
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/res/ListActivePackage.java

@@ -18,7 +18,7 @@ import java.util.List;
  */
 @Data
 @ApiModel
-public class ListActivePackage extends PageResp implements Serializable {
+public class ListActivePackageRes extends PageResp implements Serializable {
 
     @ApiModelProperty("码包列表")
     private List<PackageBean> packageBeanList;

+ 15 - 20
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/infrastructure/mq/GenerateCodeConsumer.java

@@ -130,10 +130,6 @@ public class GenerateCodeConsumer {
 	/** 声明码对应的值 */
 	public Long codeIndex = 0L;
 
-	/** 系统url */
-	@Value("${system.url}")
-	private String systemUrl;
-
 	@SneakyThrows
 	@RabbitHandler
 	@RabbitListener(queues = GenerateCodeConsumer.GENERATE_CODE_BY_REPERTORY_QUEUE)
@@ -336,19 +332,18 @@ public class GenerateCodeConsumer {
 			List<QrInnerData> innerDataList = qrData.getInnerDataList();
 			for (QrInnerData qrInnerData:innerDataList) {
 				QrCode qrCode = new QrCode();
-				qrCode.setId(String.valueOf(IdWorker.getId()));
 				//码
 				qrCode.setCode(qrInnerData.getCode());
 				//批次id
 				qrCode.setBatchNumberId(qrPackageBatch.getId());
 				//码包id
 				qrCode.setPackageId(qrPackageBatch.getPackageId());
-				//要拼接的url
-				qrCode.setUrl(qrInnerData.getUrl());
 				//创建时间
 				qrCode.setCreateTime(LocalDateTime.now());
 				//已生成码包位置
 				qrCode.setCodeIndex(qrInnerData.getCodeIndex());
+				//生成码库列id
+				qrCode.setQrRepertoryColumnId(qrInnerData.getQrRepertoryColumnId());
 				codeSave.add(qrCode);
 			}
 		}
@@ -425,14 +420,14 @@ public class GenerateCodeConsumer {
 							List<char[]> codeStr = a(code, splitNum);
 							for (char[] chars:codeStr) {
 								QrInnerData qrInnerData = new QrInnerData();
-								qrInnerData.setCode(String.valueOf(chars)).setUrl(url);
+								qrInnerData.setCode(String.valueOf(chars));
 								qrInnerData.setQrRepertoryColumnId(qrRepertoryColumnId).setSortNumber(qrRepertoryColumn.getSortNumber());
 								qrInnerData.setCodeIndex(codeIndex+=1);
 								qrInnerDataList.add(qrInnerData);
 							}
 						} else {
 							QrInnerData qrInnerData = new QrInnerData();
-							qrInnerData.setCode(code).setUrl(url);
+							qrInnerData.setCode(code);
 							qrInnerData.setQrRepertoryColumnId(qrRepertoryColumnId).setSortNumber(qrRepertoryColumn.getSortNumber());
 							qrInnerData.setCodeIndex(codeIndex+=1);
 							qrInnerDataList.add(qrInnerData);
@@ -465,16 +460,16 @@ public class GenerateCodeConsumer {
 			Long qrRepertoryColumnId = qrRepertoryColumn.getId();
 
 			// 每列的url格式
-			Integer urlType = qrRepertoryColumn.getUrlType();
-			String url = "";
-			if (QrFormatUrlEnum.SYSTEM_URL.is(urlType)) {
-				url = systemUrl;
-			}
-			// 如果url没有以/结尾,则加上/
-			if (StringUtils.isNotBlank(url) && !url.endsWith("/")) {
-				url += "/";
-			}
-			urlMap.put(qrRepertoryColumnId, url);
+//			Integer urlType = qrRepertoryColumn.getUrlType();
+//			String url = "";
+//			if (QrFormatUrlEnum.SYSTEM_URL.is(urlType)) {
+//				url = systemUrl;
+//			}
+//			// 如果url没有以/结尾,则加上/
+//			if (StringUtils.isNotBlank(url) && !url.endsWith("/")) {
+//				url += "/";
+//			}
+			urlMap.put(qrRepertoryColumnId, "");
 
 			// 使用到流水号参数的列
 			String[] buildClassArr = qrRepertoryColumn.getQrFormatVO().getCodeVariableBuildClass().split(",");
@@ -534,7 +529,7 @@ public class GenerateCodeConsumer {
 		String innerData;
 		for (QrData qrData : qrDataList) {
 			innerDataList = qrData.getInnerDataList();
-			innerData = innerDataList.stream().map(qrInnerData -> qrInnerData.getUrl() + qrInnerData.getCode()).collect(Collectors.joining(","));
+			innerData = innerDataList.stream().map(qrInnerData -> qrInnerData.getCode()).collect(Collectors.joining(","));
 			content.append(innerData).append("\r\n");
 		}
 		//如果文件不存在,创建一个文件

+ 11 - 3
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/ActiveService.java

@@ -3,7 +3,8 @@ package com.abi.qms.platform.service;
 
 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;
 
 /**
@@ -44,11 +45,18 @@ public interface ActiveService{
     GetActiveRes getActive(GetActiveReq getActiveReq);
 
     /**
-     * 分页查询关联的码包列表
+     * 分页查询关联的码包列表(编辑审核页面)
      * @param getActiveReq
      * @return
      */
-    ListActivePackage listActivePackage(GetActiveReq getActiveReq);
+    ListActivePackageRes listActivePackage(GetActiveReq getActiveReq);
+
+    /**
+     * 分页查询码活动未关联的码包列表(新增修改页面)
+     * @param listActivePackageAddReq
+     * @return
+     */
+    ListActivePackageAddRes listActivePackageAdd(ListActivePackageAddReq listActivePackageAddReq);
 
     /**
      * 活动启用

+ 92 - 21
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/impl/ActiveServiceImpl.java

@@ -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);
+    }
+
 }

+ 0 - 3
abi-cloud-qr-platform-server/src/main/resources/dao/mapper/BaseBrandMapper.xml

@@ -22,21 +22,4 @@
         ID, BRAND_CODE, BRAND_NAME, BRAND_LEVEL, PARENT_BRAND_CODE, PARENT_BRAND_NAME, CREATE_TIME, CREATE_BY, UPDATE_TIME, UPDATE_BY, IS_DELETE
     </sql>
 
-    <!--通过品牌code查询关联码包列表-->
-    <select id="listPackageById" resultType="com.abi.qms.platform.dao.vo.result.ActivePackageVO">
-    </select>
 </mapper>

+ 40 - 0
abi-cloud-qr-platform-server/src/main/resources/dao/mapper/QrPackageMapper.xml

@@ -159,4 +159,44 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
 
+    <!--通过品牌code查询关联码包列表-->
+    <select id="listPackageByBrandCode" resultType="com.abi.qms.platform.dao.vo.result.ActivePackageVO">
+        select
+        qp.id as packageId,
+        qp.qr_type,
+        bs.sku_name,
+        bb.brand_name,
+        bb.parent_brand_name,
+        qp.qr_number,
+        ba.active_name,
+        (CASE WHEN act.active_name = null or act.active_name = '' THEN '0' ELSE '1' END) AS is_join_active
+        from qr_package qp
+        inner join base_material bm on bm.id=qp.material_id
+        inner join base_sku bs on bs.id=bm.sku_id
+        inner join base_brand bb on bb.id=bs.sub_brand_code
+        left join base_active_qr_package_mapping baqpm on baqpm.qr_package_id=p.id
+        left join base_active ba on ba.id = baqpm.active_id
+        where
+        bb.brand_code IN(
+        <foreach collection="param.brandCodeList" separator="," item="item">
+            #{item}
+        </foreach>
+        )
+        and qp.apply_status = 1
+        <if test="param.activeId != null">
+            AND ba.id is null or ba.id != #{param.activeId}
+        </if>
+        <if test="param.packageId != null">
+            AND qp.id = {param.packageId}
+        </if>
+        <if test="param.skuName != null and param.skuName != ''">
+            AND bs.sku_name like concat('%',#{param.skuName},'%')
+        </if>
+        <if test="param.qrType != null">
+            AND qp.qr_type = #{param.qrType}
+        </if>
+        and qp.qr_type = 2
+        and bb.is_delete = 0
+        order by qp.generate_time
+    </select>
 </mapper>