Browse Source

码格式批量启用,新增接口更改

v_KaixiangGuo 3 years ago
parent
commit
1bf48ad737

+ 2 - 2
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dao/enums/QrFormatUniqueStatusEunm.java

@@ -21,8 +21,8 @@ public enum QrFormatUniqueStatusEunm {
 
 	UN_VERIFY(0,"未验证"),
 	VERIFYING(1,"验证中"),
-	VERIFY_FAIL(2,"验证通过"),
-	VERIFY_SUCCESS(3,"验证不通过");
+	VERIFY_SUCCESS(2,"验证通过"),
+	VERIFY_FAIL(3,"验证不通过");
 
 	@EnumValue
 	private Integer code;

+ 2 - 2
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dao/mapper/BaseActiveMapper.java

@@ -22,8 +22,8 @@ public interface BaseActiveMapper extends BaseMapper<BaseActive> {
 
     /**
      * 通过物料ID查询对应一个活动
-     * @param materialId 物料ID
+     * @param id 活动ID
      * @return
      */
-    PackageActiveVO getPackageActive(@Param("materialId") Long materialId);
+    PackageActiveVO getPackageActive(@Param("id") Long id);
 }

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

@@ -69,5 +69,8 @@ public class QrSingleCheckVO implements Serializable {
 	@ApiModelProperty("条码序号")
 	private String boxCode;
 
+	@ApiModelProperty("活动ID")
+	private Long activeId;
+
 
 }

+ 63 - 29
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/impl/QrFormatServiceImpl.java

@@ -28,6 +28,7 @@ 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.metadata.IPage;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -43,6 +44,7 @@ import java.util.concurrent.ExecutorService;
  * @date 2021-04-19
  */
 @Service
+@Slf4j
 public class QrFormatServiceImpl implements QrFormatService {
 
     @Autowired
@@ -71,6 +73,10 @@ public class QrFormatServiceImpl implements QrFormatService {
     public void saveQrFormat(SaveQrFormatReq req) {
         Long qrFormatId = req.getId();
         //1-校验入参
+        //码格式位数不在规定区间内
+        if (null == req.getDigit() || req.getDigit() <= 0 || req.getDigit() > 32){
+            throw new BusinessException("码格式位数不在0~32位之内");
+        }
         // 修改码格式时的条件限制
         QrFormat qrFormat;
         if (qrFormatId != null) {
@@ -179,22 +185,36 @@ public class QrFormatServiceImpl implements QrFormatService {
     public void enableQrFormat(EnableQrFormatReq req) {
         List<Long> idList = req.getIds();
         for (Long id : idList) {
-            QrFormat qrFormat = qrFormatMapper.selectById(id);
-            AssertUtil.isNull(qrFormat, "码格式不存在");
-            // 如果不是停用状态的码格式,跳过循环
-            if (!QrFormatUseStatusEnum.DISABLE.is(qrFormat.getUseStatus())) {
-                continue;
+            try{
+                QrFormat qrFormat = qrFormatMapper.selectById(id);
+                AssertUtil.isNull(qrFormat, "码格式不存在");
+                // 如果不是停用状态的码格式,跳过循环
+                if (!QrFormatUseStatusEnum.DISABLE.is(qrFormat.getUseStatus())) {
+                    continue;
+                }
+                //不是验证通过的码格式,跳过循环,不可启用
+                if (!QrFormatUniqueStatusEunm.VERIFY_SUCCESS.is(qrFormat.getUniqueStatus())){
+                    throw new BusinessException("码格式不是验证通过,不可启用");
+                }
+
+                // 根据是否被码库使用,决定更新状态为未使用还是使用中
+                QueryWrapper<QrRepertoryColumn> qrRepertoryColumnQw = new QueryWrapper<>();
+                qrRepertoryColumnQw.eq("is_delete", 0);
+                qrRepertoryColumnQw.eq("qr_format_id", id);
+                Integer count = qrRepertoryColumnMapper.selectCount(qrRepertoryColumnQw);
+                Integer useStatus = count.compareTo(0) > 0 ? QrFormatUseStatusEnum.USING.getCode() : QrFormatUseStatusEnum.UN_USE.getCode();
+
+                QrFormat update = new QrFormat().setId(id).setUseStatus(useStatus);
+                qrFormatMapper.updateById(update);
+            }catch(BusinessException e){
+                //单条不通过通知前端
+                if (idList.size() == 1){
+                    throw e;
+                }else{
+                    log.info("批量处理发现异常",e);
+                }
             }
 
-            // 根据是否被码库使用,决定更新状态为未使用还是使用中
-            QueryWrapper<QrRepertoryColumn> qrRepertoryColumnQw = new QueryWrapper<>();
-            qrRepertoryColumnQw.eq("is_delete", 0);
-            qrRepertoryColumnQw.eq("qr_format_id", id);
-            Integer count = qrRepertoryColumnMapper.selectCount(qrRepertoryColumnQw);
-            Integer useStatus = count.compareTo(0) > 0 ? QrFormatUseStatusEnum.USING.getCode() : QrFormatUseStatusEnum.UN_USE.getCode();
-
-            QrFormat update = new QrFormat().setId(id).setUseStatus(useStatus);
-            qrFormatMapper.updateById(update);
         }
     }
 
@@ -205,22 +225,36 @@ public class QrFormatServiceImpl implements QrFormatService {
     @Transactional(rollbackFor = Exception.class)
     public void disableQrFormat(DisableQrFormatReq req) {
         List<Long> idList = req.getIds();
-        for (Long id : idList) {
-            QrFormat qrFormat = qrFormatMapper.selectById(id);
-            AssertUtil.isNull(qrFormat, "码格式不存在");
-            // 如果是停用状态的码格式,跳过循环
-            if (QrFormatUseStatusEnum.DISABLE.is(qrFormat.getUseStatus())) {
-                continue;
+        try{
+            for (Long id : idList) {
+                QrFormat qrFormat = qrFormatMapper.selectById(id);
+                AssertUtil.isNull(qrFormat, "码格式不存在");
+                // 如果是停用状态的码格式,跳过循环
+                if (QrFormatUseStatusEnum.DISABLE.is(qrFormat.getUseStatus())) {
+                    continue;
+                }
+
+                //不是验证通过的码格式,跳过循环,不可禁用
+                if (!QrFormatUniqueStatusEunm.VERIFY_SUCCESS.is(qrFormat.getUniqueStatus())){
+                    throw new BusinessException("码格式不是验证通过,不可禁用");
+                }
+
+                // 判断该码格式关联的码库是否全部停用,若否,停用失败
+                List<String> notDisabledQrRepertoryList = qrRepertoryMapper.selectNotDisabledQrRepertory(id);
+                if (!CollectionUtils.isEmpty(notDisabledQrRepertoryList)) {
+                    throw new BusinessException("该码格式已与码库" + notDisabledQrRepertoryList + "关联,请停用码库后再试");
+                }
+
+                QrFormat update = new QrFormat().setId(id).setUseStatus(QrFormatUseStatusEnum.DISABLE.getCode());
+                qrFormatMapper.updateById(update);
             }
-
-            // 判断该码格式关联的码库是否全部停用,若否,停用失败
-            List<String> notDisabledQrRepertoryList = qrRepertoryMapper.selectNotDisabledQrRepertory(id);
-            if (!CollectionUtils.isEmpty(notDisabledQrRepertoryList)) {
-                throw new BusinessException("该码格式已与码库" + notDisabledQrRepertoryList + "关联,请停用码库后再试");
+        }catch(BusinessException e){
+            //单条不通过通知前端
+            if (idList.size() == 1){
+                throw e;
+            }else{
+                log.info("批量处理发现异常",e);
             }
-
-            QrFormat update = new QrFormat().setId(id).setUseStatus(QrFormatUseStatusEnum.DISABLE.getCode());
-            qrFormatMapper.updateById(update);
         }
     }
 
@@ -251,7 +285,7 @@ public class QrFormatServiceImpl implements QrFormatService {
         ListFormatSelectRes res = new ListFormatSelectRes();
 
         QueryWrapper<QrFormat> qw = new QueryWrapper<>();
-        qw.eq("unique_status", QrFormatUniqueStatusEunm.VERIFY_FAIL.getCode());
+        qw.eq("unique_status", QrFormatUniqueStatusEunm.VERIFY_SUCCESS.getCode());
         qw.eq("is_delete", 0);
         qw.eq("is_sys",0);
         List<QrFormat> formatList = qrFormatMapper.selectList(qw);

+ 8 - 7
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/impl/QrPackageServiceImpl.java

@@ -816,17 +816,18 @@ public class QrPackageServiceImpl implements QrPackageService {
         QrRepertoryColumn qrRepertoryColumn = repertoryColumnMapper.selectById(qrCode.getQrRepertoryColumnId());
 
         //存在别名(隐形码)
-        if (ObjectUtils.isNotEmpty(qrRepertoryColumn)) {
+        if (!ObjectUtils.isEmpty(qrRepertoryColumn)) {
             qrSingleCheckVO.setAlias(qrRepertoryColumn.getAlias());//隐形码
         }
 
         //查询码包对应活动单条数据
-        PackageActiveVO packageActive = baseActiveMapper.getPackageActive(qrCode.getPackageId());
-
-        //存在活动数据
-        if (ObjectUtils.isNotEmpty(packageActive)) {
-            qrSingleCheckVO.setActiveName(packageActive.getActiveName());
-            qrSingleCheckVO.setActiveUrl(packageActive.getActiveUrl());
+        if(null != qrSingleCheckVO.getActiveId()) {
+            //存在活动数据
+            PackageActiveVO packageActive = baseActiveMapper.getPackageActive(qrSingleCheckVO.getActiveId());
+            if (!ObjectUtils.isEmpty(packageActive)) {
+                qrSingleCheckVO.setActiveName(packageActive.getActiveName());
+                qrSingleCheckVO.setActiveUrl(packageActive.getActiveUrl());
+            }
         }
 
         //查询批次号id

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

@@ -59,20 +59,19 @@
     </select>
 
     <select id="getPackageActive" resultType="com.abi.qms.platform.dao.vo.result.PackageActiveVO">
+         SELECT
+             ba.id,
+             ba.active_code,
+             ba.active_name,
+             ba.active_url,
+             ba.active_type,
+             ba.begin_time,
+             ba.end_time,
+             ba.brand_code
+         FROM
+             base_active ba
+         WHERE
+         ba.id = #{id} limit 1
     </select>
 
 

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

@@ -166,7 +166,8 @@
         qp.generate_time,
         bm.material_name,
         bfa.factory_name AS factory_cover_name,
-        bfb.factory_name AS factory_beer_name
+        bfb.factory_name AS factory_beer_name,
+        bm.active_id
         FROM
         qr_package qp
         LEFT JOIN base_material bm ON qp.material_id = bm.id