Browse Source

fix: 码格式新增接口修改

fangxinjian 3 years ago
parent
commit
0fe5efab46

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

@@ -18,8 +18,8 @@ import java.util.List;
 @ApiModel
 public class PreviewQrVariableReq implements Serializable {
 
-  @NotNull(message = "paramNameList为空")
-  @ApiModelProperty(value = "paramNameList")
-  private List<Long> paramNameList;
+    @NotNull(message = "paramNameList为空")
+    @ApiModelProperty(value = "paramNameList")
+    private List<String> paramNameList;
 
 }

+ 24 - 27
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/req/SaveQrFormatReq.java

@@ -7,6 +7,7 @@ import lombok.Data;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Pattern;
 import java.io.Serializable;
+import java.util.List;
 
 /**
  * 码格式新增修改入参
@@ -18,41 +19,37 @@ import java.io.Serializable;
 @ApiModel
 public class SaveQrFormatReq implements Serializable {
 
-	@ApiModelProperty("码格式id")
-	private Long id;
+    @ApiModelProperty("码格式id")
+    private Long id;
 
-	@NotNull(message = "码格式名称为空")
-	@Pattern(regexp = "^[a-zA-Z-z0-9\\u4e00-\\u9fa5]{1,20}$", message = "码格式名称限制20字内的汉字or字母or数字")
-	@ApiModelProperty("码格式名称")
-	private String name;
+    @NotNull(message = "码格式名称为空")
+    @Pattern(regexp = "^[a-zA-Z-z0-9\\u4e00-\\u9fa5]{1,20}$", message = "码格式名称限制20字内的汉字or字母or数字")
+    @ApiModelProperty("码格式名称")
+    private String name;
 
-	@NotNull(message = "数据类型为空")
-	@ApiModelProperty("数据类型 0-纯数字 1-数字+字母")
-	private Integer dataType;
+    @NotNull(message = "数据类型为空")
+    @ApiModelProperty("数据类型 0-纯数字 1-数字+字母")
+    private Integer dataType;
 
-	@ApiModelProperty("码变量")
-	private String codeVariable;
+    @ApiModelProperty("码变量")
+    private List<String> codeVariable;
 
-//	@NotNull(message = "选择参数为空")
-//	@ApiModelProperty("码变量对应的类")
-//	private String codeVariableBuildClass;
+    @ApiModelProperty("码组成简介")
+    private String brief;
 
-	@ApiModelProperty("码组成简介")
-	private String brief;
+    @ApiModelProperty("说明")
+    private String illustrate;
 
-	@ApiModelProperty("说明")
-	private String illustrate;
+    @ApiModelProperty("码预览")
+    private String previewCode;
 
-	@ApiModelProperty("码预览")
-	private String previewCode;
+    @ApiModelProperty("位数")
+    private Integer digit;
 
-	@ApiModelProperty("位数")
-	private Integer digit;
+    @ApiModelProperty("理论不重复数量")
+    private Long maxCount;
 
-	@ApiModelProperty("理论不重复数量")
-	private Long maxCount;
-
-	@ApiModelProperty("是否验证唯一性 0-不验证,1-验证")
-	private Integer verifyUnique;
+    @ApiModelProperty("是否验证唯一性 0-不验证,1-验证")
+    private Integer verifyUnique;
 
 }

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

@@ -2,13 +2,19 @@ package com.abi.qms.platform.service.impl;
 
 import com.abi.qms.platform.dao.entity.QrFormat;
 import com.abi.qms.platform.dao.entity.QrRepertoryColumn;
+import com.abi.qms.platform.dao.entity.QrVariable;
 import com.abi.qms.platform.dao.enums.QrFormatUseStatusEnum;
-import com.abi.qms.platform.dao.enums.QrFormatVerifyUniqueEnum;
 import com.abi.qms.platform.dao.mapper.QrFormatMapper;
 import com.abi.qms.platform.dao.mapper.QrRepertoryColumnMapper;
 import com.abi.qms.platform.dao.mapper.QrRepertoryMapper;
+import com.abi.qms.platform.dao.mapper.QrVariableMapper;
 import com.abi.qms.platform.dao.vo.result.QrFormatVO;
-import com.abi.qms.platform.dto.req.*;
+import com.abi.qms.platform.dto.req.DeleteQrFormatReq;
+import com.abi.qms.platform.dto.req.DisableQrFormatReq;
+import com.abi.qms.platform.dto.req.EnableQrFormatReq;
+import com.abi.qms.platform.dto.req.GetQrFormatDetailReq;
+import com.abi.qms.platform.dto.req.ListQrFormatReq;
+import com.abi.qms.platform.dto.req.SaveQrFormatReq;
 import com.abi.qms.platform.dto.res.GetQrFormatDetailRes;
 import com.abi.qms.platform.dto.res.ListQrFormatRes;
 import com.abi.qms.platform.infrastructure.task.VerifyUniqueTask;
@@ -37,164 +43,197 @@ import java.util.concurrent.ExecutorService;
 @Service
 public class QrFormatServiceImpl implements QrFormatService {
 
-	@Autowired
-	private QrFormatMapper qrFormatMapper;
-
-	@Autowired
-	private QrRepertoryMapper qrRepertoryMapper;
-
-	@Autowired
-	private QrRepertoryColumnMapper qrRepertoryColumnMapper;
-
-	@Autowired
-	private ExecutorService executorService;
-
-	/**
-	 * 保存码格式
-	 */
-	@Override
-	@Transactional(rollbackFor = Exception.class)
-	public void saveQrFormat(SaveQrFormatReq req) {
-		Long qrFormatId = req.getId();
-		//1-校验入参
-		// 修改码格式时的条件限制
-		QrFormat qrFormat;
-		if (qrFormatId != null) {
-			qrFormat = qrFormatMapper.selectById(qrFormatId);
-			AssertUtil.isNull(qrFormat, "码格式不存在");
-			// 只有未使用状态下才可编辑
-			if (!QrFormatUseStatusEnum.UN_USE.is(qrFormat.getUseStatus())) {
-				throw new BusinessException("码格式不可编辑");
-			}
-		}
-		//码格式名称不可重复
-		QueryWrapper<QrFormat> qrFormatQw = new QueryWrapper<>();
-		qrFormatQw.eq("name", req.getName());
-		qrFormatQw.eq("is_delete", 0);
-		if (qrFormatId != null) {
-			qrFormatQw.ne("id", qrFormatId);
-		}
-		Integer count = qrFormatMapper.selectCount(qrFormatQw);
-		if (!count.equals(0)) {
-			throw new BusinessException("码格式名称已存在");
-		}
-
-		//2-保存数据
-		// copy属性值
-		qrFormat = PojoConverterUtils.copy(req, QrFormat.class);
-		// 新增or修改
-		Long userId = UserUtil.getUser().getId();
-		qrFormat.setUpdateBy(userId);
-		if (qrFormatId != null) {
-			qrFormatMapper.updateById(qrFormat);
-		} else {
-			qrFormat.setCreateBy(userId);
-			qrFormatMapper.insert(qrFormat);
-		}
-
-		//3-异步进行重复率验证
-		executorService.execute(new VerifyUniqueTask(qrFormat, qrFormatMapper));
-
-	}
-
-	/**
-	 * 码格式查询分页
-	 */
-	@Override
-	public ListQrFormatRes listQrFormat(ListQrFormatReq req) {
-		// 分页查询
-		IPage<QrFormatVO> iPage  = qrFormatMapper.listQrFormat(PageUtil.createPage(req), req);
-		List<QrFormatVO> qrFormatList = iPage.getRecords();
-
-		// 封装出参、放入分页信息
-		ListQrFormatRes res = new ListQrFormatRes();
-		PageUtil.copyPageInfo(res, iPage);
-		List<ListQrFormatRes.QrFormatBean> qrFormatBeanList = PojoConverterUtils.copyList(qrFormatList, ListQrFormatRes.QrFormatBean.class);
-		res.setQrFormatBeanList(qrFormatBeanList);
-
-		return res;
-	}
-
-	/**
-	 * 码格式查询详情
-	 */
-	@Override
-	public GetQrFormatDetailRes getQrFormatDetail(GetQrFormatDetailReq req) {
-		// 查询码格式对象
-		QrFormat qrFormat = qrFormatMapper.selectById(req.getId());
-		AssertUtil.isNull(qrFormat, "码格式不存在");
-
-		return PojoConverterUtils.copy(qrFormat, GetQrFormatDetailRes.class);
-	}
-
-	/**
-	 * 码格式启用
-	 */
-	@Override
-	@Transactional(rollbackFor = Exception.class)
-	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;
-			}
-
-			// 根据是否被码库使用,决定更新状态为未使用还是使用中
-			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);
-		}
-	}
-
-	/**
-	 * 码格式禁用
-	 */
-	@Override
-	@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;
-			}
-
-			// 判断该码格式关联的码库是否全部停用,若否,停用失败
-			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);
-		}
-	}
-
-	/**
-	 * 删除码格式
-	 */
-	@Override
-	@Transactional(rollbackFor = Exception.class)
-	public void deleteQrFormat(DeleteQrFormatReq req) {
-		QrFormat qrFormat = qrFormatMapper.selectById(req.getId());
-		AssertUtil.isNull(qrFormat, "码格式不存在");
-		// 只有未使用状态下才可删除
-		if (!QrFormatUseStatusEnum.UN_USE.is(qrFormat.getUseStatus())) {
-			throw new BusinessException("码格式不可删除");
-		}
-
-		// 逻辑删除
-		QrFormat update = new QrFormat().setId(req.getId()).setIsDelete(1);
-		qrFormatMapper.updateById(update);
-	}
+    @Autowired
+    private QrFormatMapper qrFormatMapper;
+
+    @Autowired
+    private QrRepertoryMapper qrRepertoryMapper;
+
+    @Autowired
+    private QrRepertoryColumnMapper qrRepertoryColumnMapper;
+
+    @Autowired
+    private ExecutorService executorService;
+
+    @Autowired
+    private QrVariableMapper qrVariableMapper;
+
+    /**
+     * 保存码格式
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void saveQrFormat(SaveQrFormatReq req) {
+        Long qrFormatId = req.getId();
+        //1-校验入参
+        // 修改码格式时的条件限制
+        QrFormat qrFormat;
+        if (qrFormatId != null) {
+            qrFormat = qrFormatMapper.selectById(qrFormatId);
+            AssertUtil.isNull(qrFormat, "码格式不存在");
+            // 只有未使用状态下才可编辑
+            if (!QrFormatUseStatusEnum.UN_USE.is(qrFormat.getUseStatus())) {
+                throw new BusinessException("码格式不可编辑");
+            }
+        }
+        //码格式名称不可重复
+        QueryWrapper<QrFormat> qrFormatQw = new QueryWrapper<>();
+        qrFormatQw.eq("name", req.getName());
+        qrFormatQw.eq("is_delete", 0);
+        if (qrFormatId != null) {
+            qrFormatQw.ne("id", qrFormatId);
+        }
+        Integer count = qrFormatMapper.selectCount(qrFormatQw);
+        if (!count.equals(0)) {
+            throw new BusinessException("码格式名称已存在");
+        }
+
+        //2-保存数据
+        // copy属性值
+        qrFormat = addQrFormat(req);
+        // 新增or修改
+        Long userId = UserUtil.getUser().getId();
+        qrFormat.setUpdateBy(userId);
+        if (qrFormatId != null) {
+            qrFormatMapper.updateById(qrFormat);
+        } else {
+            qrFormat.setCreateBy(userId);
+            qrFormatMapper.insert(qrFormat);
+        }
+
+        //3-异步进行重复率验证
+        executorService.execute(new VerifyUniqueTask(qrFormat, qrFormatMapper));
+
+    }
+
+    public QrFormat addQrFormat(SaveQrFormatReq req) {
+
+        QrFormat qrFormat = new QrFormat();
+        qrFormat.setBrief(req.getBrief());
+        qrFormat.setDataType(req.getDataType());
+        qrFormat.setDigit(req.getDigit());
+        qrFormat.setIllustrate(req.getIllustrate());
+        qrFormat.setName(req.getName());
+        qrFormat.setPreviewCode(req.getPreviewCode());
+        qrFormat.setMaxCount(req.getMaxCount());
+        qrFormat.setVerifyUnique(req.getVerifyUnique());
+
+        //根据参数名称获取构造的类
+        QueryWrapper<QrVariable> qrVariableQw = new QueryWrapper<>();
+        qrVariableQw.in("param_name", req.getCodeVariable());
+        List<QrVariable> qrVariableList = qrVariableMapper.selectList(qrVariableQw);
+        StringBuilder codeSb = new StringBuilder();
+        StringBuilder codeVBC = new StringBuilder();
+        for (QrVariable qr : qrVariableList) {
+            codeSb.append(qr.getBuildCodeClass());
+            codeVBC.append(qr.getParamName());
+        }
+        qrFormat.setCodeVariableBuildClass(codeSb.toString());
+        qrFormat.setCodeVariable(codeVBC.toString());
+
+        return qrFormat;
+
+    }
+
+
+    /**
+     * 码格式查询分页
+     */
+    @Override
+    public ListQrFormatRes listQrFormat(ListQrFormatReq req) {
+        // 分页查询
+        IPage<QrFormatVO> iPage = qrFormatMapper.listQrFormat(PageUtil.createPage(req), req);
+        List<QrFormatVO> qrFormatList = iPage.getRecords();
+
+        // 封装出参、放入分页信息
+        ListQrFormatRes res = new ListQrFormatRes();
+        PageUtil.copyPageInfo(res, iPage);
+        List<ListQrFormatRes.QrFormatBean> qrFormatBeanList = PojoConverterUtils.copyList(qrFormatList, ListQrFormatRes.QrFormatBean.class);
+        res.setQrFormatBeanList(qrFormatBeanList);
+
+        return res;
+    }
+
+    /**
+     * 码格式查询详情
+     */
+    @Override
+    public GetQrFormatDetailRes getQrFormatDetail(GetQrFormatDetailReq req) {
+        // 查询码格式对象
+        QrFormat qrFormat = qrFormatMapper.selectById(req.getId());
+        AssertUtil.isNull(qrFormat, "码格式不存在");
+
+        return PojoConverterUtils.copy(qrFormat, GetQrFormatDetailRes.class);
+    }
+
+    /**
+     * 码格式启用
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    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;
+            }
+
+            // 根据是否被码库使用,决定更新状态为未使用还是使用中
+            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);
+        }
+    }
+
+    /**
+     * 码格式禁用
+     */
+    @Override
+    @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;
+            }
+
+            // 判断该码格式关联的码库是否全部停用,若否,停用失败
+            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);
+        }
+    }
+
+    /**
+     * 删除码格式
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deleteQrFormat(DeleteQrFormatReq req) {
+        QrFormat qrFormat = qrFormatMapper.selectById(req.getId());
+        AssertUtil.isNull(qrFormat, "码格式不存在");
+        // 只有未使用状态下才可删除
+        if (!QrFormatUseStatusEnum.UN_USE.is(qrFormat.getUseStatus())) {
+            throw new BusinessException("码格式不可删除");
+        }
+
+        // 逻辑删除
+        QrFormat update = new QrFormat().setId(req.getId()).setIsDelete(1);
+        qrFormatMapper.updateById(update);
+    }
 }