|
@@ -1,21 +1,18 @@
|
|
|
package com.abi.qms.platform.service.impl;
|
|
|
|
|
|
import com.abi.qms.platform.dao.entity.QrFormat;
|
|
|
-import com.abi.qms.platform.dao.entity.QrVariable;
|
|
|
import com.abi.qms.platform.dao.enums.QrFormatUniqueStatusEunm;
|
|
|
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.QrVariableMapper;
|
|
|
-import com.abi.qms.platform.dto.req.GetQrFormatDetailReq;
|
|
|
-import com.abi.qms.platform.dto.req.ListQrFormatReq;
|
|
|
-import com.abi.qms.platform.dto.req.SaveFormatReq;
|
|
|
-import com.abi.qms.platform.dto.res.GetFactoryDetailRes;
|
|
|
+import com.abi.qms.platform.dao.vo.result.QrFormatVO;
|
|
|
+import com.abi.qms.platform.dto.req.*;
|
|
|
import com.abi.qms.platform.dto.res.GetQrFormatDetailRes;
|
|
|
import com.abi.qms.platform.dto.res.ListQrFormatRes;
|
|
|
-import com.abi.qms.platform.dto.res.ListQrVariableRes;
|
|
|
import com.abi.qms.platform.infrastructure.task.VerifyUniqueTask;
|
|
|
import com.abi.qms.platform.infrastructure.util.AssertUtil;
|
|
|
import com.abi.qms.platform.infrastructure.util.PageUtil;
|
|
|
+import com.abi.qms.platform.service.BoxCodeFormatService;
|
|
|
import com.abi.qms.platform.service.QrFormatService;
|
|
|
import com.abi.task.common.api.exception.BusinessException;
|
|
|
import com.abi.task.common.utils.PojoConverterUtils;
|
|
@@ -23,6 +20,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
@@ -42,12 +40,25 @@ public class QrFormatServiceImpl implements QrFormatService {
|
|
|
@Autowired
|
|
|
private ExecutorService executorService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BoxCodeFormatService boxCodeFormatService;
|
|
|
+
|
|
|
/**
|
|
|
* 保存码格式
|
|
|
*/
|
|
|
@Override
|
|
|
- public void saveFormat(SaveFormatReq req) {
|
|
|
- // 汉字or字母or数字,20字内
|
|
|
+ @Transactional
|
|
|
+ public void saveQrFormat(SaveQrFormatReq req) {
|
|
|
+ // 修改码格式时的条件限制
|
|
|
+ QrFormat qrFormat;
|
|
|
+ if (req.getId() != null) {
|
|
|
+ qrFormat = qrFormatMapper.selectById(req.getId());
|
|
|
+ AssertUtil.isNull(qrFormat, "码格式不存在");
|
|
|
+ // 只有未使用状态下才可编辑
|
|
|
+ if (QrFormatUseStatusEnum.UN_USE.is(qrFormat.getUseStatus())) {
|
|
|
+ throw new BusinessException("码格式不可编辑");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
// 同部门下码格式名称不可重复
|
|
|
QueryWrapper<QrFormat> qrFormatQw = new QueryWrapper<>();
|
|
@@ -61,12 +72,6 @@ public class QrFormatServiceImpl implements QrFormatService {
|
|
|
throw new BusinessException("码格式名称已存在");
|
|
|
}
|
|
|
|
|
|
- // 声明对象
|
|
|
- QrFormat qrFormat;
|
|
|
- if (req.getId() != null) {
|
|
|
- qrFormat = qrFormatMapper.selectById(req.getId());
|
|
|
- AssertUtil.isNull(qrFormat, "码格式不存在");
|
|
|
- }
|
|
|
qrFormat = PojoConverterUtils.copy(req, QrFormat.class);
|
|
|
PojoConverterUtils.copy(req, qrFormat);
|
|
|
// 重复率状态 未验证
|
|
@@ -74,15 +79,18 @@ public class QrFormatServiceImpl implements QrFormatService {
|
|
|
// 使用状态 未使用
|
|
|
qrFormat.setUseStatus(QrFormatUseStatusEnum.UN_USE.getCode());
|
|
|
|
|
|
- // 新增or修改
|
|
|
+ // 新增or修改 TODO 设置createBy和updateBy
|
|
|
if (req.getId() != null) {
|
|
|
qrFormatMapper.updateById(qrFormat);
|
|
|
} else {
|
|
|
qrFormatMapper.insert(qrFormat);
|
|
|
}
|
|
|
|
|
|
- // 重复率验证
|
|
|
- executorService.execute(new VerifyUniqueTask(qrFormat, qrFormatMapper));
|
|
|
+ // 是否进行重复率验证
|
|
|
+ if (QrFormatVerifyUniqueEnum.VERIFY_UNIQUE.is(qrFormat.getVerifyUnique())) {
|
|
|
+ executorService.execute(new VerifyUniqueTask(qrFormat, qrFormatMapper));
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -90,15 +98,12 @@ public class QrFormatServiceImpl implements QrFormatService {
|
|
|
*/
|
|
|
@Override
|
|
|
public ListQrFormatRes listQrFormat(ListQrFormatReq req) {
|
|
|
- // 1-拼接条件
|
|
|
- QueryWrapper<QrFormat> qrFormatQw = new QueryWrapper<>();
|
|
|
- qrFormatQw.eq(req.getUniqueStatus() != null, "unique_status", req.getUniqueStatus());
|
|
|
|
|
|
- // 2-分页查询
|
|
|
- IPage<QrFormat> iPage = qrFormatMapper.selectPage(PageUtil.createPage(req), qrFormatQw);
|
|
|
- List<QrFormat> qrFormatList = iPage.getRecords();
|
|
|
+ // 分页查询
|
|
|
+ IPage<QrFormatVO> iPage = qrFormatMapper.listQrFormat(PageUtil.createPage(req), req);
|
|
|
+ List<QrFormatVO> qrFormatList = iPage.getRecords();
|
|
|
|
|
|
- // 3-封装出参、放入分页信息
|
|
|
+ // 封装出参、放入分页信息
|
|
|
ListQrFormatRes res = new ListQrFormatRes();
|
|
|
PageUtil.copyPageInfo(res, iPage);
|
|
|
List<ListQrFormatRes.QrFormatBean> qrFormatBeanList = PojoConverterUtils.copyList(qrFormatList, ListQrFormatRes.QrFormatBean.class);
|
|
@@ -112,11 +117,67 @@ public class QrFormatServiceImpl implements QrFormatService {
|
|
|
*/
|
|
|
@Override
|
|
|
public GetQrFormatDetailRes getQrFormatDetail(GetQrFormatDetailReq req) {
|
|
|
- // 1-查询码格式对象
|
|
|
+ // 查询码格式对象
|
|
|
QrFormat qrFormat = qrFormatMapper.selectById(req.getId());
|
|
|
AssertUtil.isNull(qrFormat, "码格式不存在");
|
|
|
|
|
|
GetQrFormatDetailRes res = PojoConverterUtils.copy(qrFormat, GetQrFormatDetailRes.class);
|
|
|
return res;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 码格式启用
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO 根据是否被码库使用,决定更新状态为未使用还是使用中
|
|
|
+ QrFormat update = new QrFormat().setId(id).setUseStatus(QrFormatUseStatusEnum.UN_USE.getCode());
|
|
|
+ qrFormatMapper.updateById(update);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 码格式禁用
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void disableFormat(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;
|
|
|
+ }
|
|
|
+
|
|
|
+ QrFormat update = new QrFormat().setId(id).setUseStatus(QrFormatUseStatusEnum.DISABLE.getCode());
|
|
|
+ qrFormatMapper.updateById(update);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除码格式
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|