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