|
@@ -3,6 +3,8 @@ package com.abi.qms.platform.service.impl;
|
|
|
import com.abi.qms.platform.dao.entity.QrRepertory;
|
|
|
import com.abi.qms.platform.dao.enums.QrRepertoryStatusEnum;
|
|
|
import com.abi.qms.platform.dao.enums.QrRepertoryTypeEnum;
|
|
|
+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.vo.result.QrRepertoryVO;
|
|
|
import com.abi.qms.platform.dto.req.*;
|
|
@@ -19,8 +21,11 @@ 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 org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* 码库 Service业务层处理
|
|
@@ -34,26 +39,59 @@ public class QrRepertoryServiceImpl implements QrRepertoryService {
|
|
|
@Autowired
|
|
|
private QrRepertoryMapper qrRepertoryMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private QrRepertoryColumnMapper qrRepertoryColumnMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QrFormatMapper qrFormatMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 保存码库
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void saveQrRepertory(SaveQrRepertoryReq req) {
|
|
|
- // 同部门下码库名称不可重复
|
|
|
+ Long qrRepertoryId = req.getId();
|
|
|
+ // 修改码库时的条件限制
|
|
|
+ QrRepertory qrRepertory;
|
|
|
+ if (qrRepertoryId != null) {
|
|
|
+ qrRepertory = qrRepertoryMapper.selectById(qrRepertoryId);
|
|
|
+ AssertUtil.isNull(qrRepertory, "码库不存在");
|
|
|
+ // 只有待生成、待导入状态下才可编辑
|
|
|
+ Integer qrRepertoryStatus = qrRepertory.getStatus();
|
|
|
+ if (!QrRepertoryStatusEnum.WAIT_GENERATE.is(qrRepertoryStatus) && !QrRepertoryStatusEnum.WAIT_IMPORT.is(qrRepertoryStatus)) {
|
|
|
+ throw new BusinessException("码库不可编辑");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 码库名称不可重复
|
|
|
QueryWrapper<QrRepertory> qrRepertoryQw = new QueryWrapper<>();
|
|
|
- qrRepertoryQw.eq("dept_id", req.getDeptId());
|
|
|
qrRepertoryQw.eq("name", req.getName());
|
|
|
- if (req.getId() != null) {
|
|
|
- qrRepertoryQw.ne("id", req.getId());
|
|
|
+ qrRepertoryQw.eq("is_delete", 0);
|
|
|
+ if (qrRepertoryId != null) {
|
|
|
+ qrRepertoryQw.ne("id", qrRepertoryId);
|
|
|
}
|
|
|
Integer count = qrRepertoryMapper.selectCount(qrRepertoryQw);
|
|
|
if (!count.equals(0)) {
|
|
|
throw new BusinessException("码库名称已存在");
|
|
|
}
|
|
|
|
|
|
+ // 验证:1.码库类型为系统生成时,码格式必填 2.同一个码库内的列别名不可重复
|
|
|
+ List<SaveQrRepertoryColumnReq> qrRepertoryColumnList = req.getQrRepertoryColumnList();
|
|
|
+ Set<String> notRepeat = new HashSet<>();
|
|
|
+ SaveQrRepertoryColumnReq qrRepertoryColumn;
|
|
|
+ for (int i = 0; i < qrRepertoryColumnList.size(); i++) {
|
|
|
+ qrRepertoryColumn = qrRepertoryColumnList.get(i);
|
|
|
+ if (QrRepertoryTypeEnum.SYSTEM_GENERATE.is(req.getType()) && qrRepertoryColumn.getQrFormatId() == null) {
|
|
|
+ throw new BusinessException("码格式为空");
|
|
|
+ }
|
|
|
+ if (!notRepeat.add(qrRepertoryColumn.getAlias())) {
|
|
|
+ throw new BusinessException("列名称已存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// copy属性值
|
|
|
- QrRepertory qrRepertory = PojoConverterUtils.copy(req, QrRepertory.class);
|
|
|
+ qrRepertory = PojoConverterUtils.copy(req, QrRepertory.class);
|
|
|
Integer qrRepertoryType = qrRepertory.getType();
|
|
|
// 文本导入类型设置状态为待导入,其他两种类型设置状态为待生成
|
|
|
if (QrRepertoryTypeEnum.FILE_IMPORT.is(qrRepertoryType)) {
|
|
@@ -65,13 +103,19 @@ public class QrRepertoryServiceImpl implements QrRepertoryService {
|
|
|
// 新增or修改
|
|
|
Long userId = UserUtil.getUser().getId();
|
|
|
qrRepertory.setUpdateBy(userId);
|
|
|
- if (req.getId() != null) {
|
|
|
+ if (qrRepertoryId != null) {
|
|
|
qrRepertoryMapper.updateById(qrRepertory);
|
|
|
+ // 逻辑删除码库的列
|
|
|
+ qrRepertoryColumnMapper.deleteByQrRepertoryId(qrRepertoryId);
|
|
|
} else {
|
|
|
qrRepertory.setCreateBy(userId);
|
|
|
qrRepertoryMapper.insert(qrRepertory);
|
|
|
}
|
|
|
|
|
|
+ // 批量插入码库的列
|
|
|
+ BatchInsertQrRepertoryColumnReq batchInsertQrRepertoryColumnReq = new BatchInsertQrRepertoryColumnReq(qrRepertory, qrRepertoryColumnList);
|
|
|
+ qrRepertoryColumnMapper.batchInsert(batchInsertQrRepertoryColumnReq);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -98,24 +142,44 @@ public class QrRepertoryServiceImpl implements QrRepertoryService {
|
|
|
@Override
|
|
|
public GetQrRepertoryDetailRes getQrRepertoryDetail(GetQrRepertoryDetailReq req) {
|
|
|
// 查询码库对象
|
|
|
- QrRepertory qrRepertory = qrRepertoryMapper.selectById(req.getId());
|
|
|
- AssertUtil.isNull(qrRepertory, "码库不存在");
|
|
|
+ QrRepertoryVO qrRepertoryVO = qrRepertoryMapper.selectQrRepertoryDetailById(req.getId());
|
|
|
+ AssertUtil.isNull(qrRepertoryVO, "码库不存在");
|
|
|
|
|
|
- return PojoConverterUtils.copy(qrRepertory, GetQrRepertoryDetailRes.class);
|
|
|
+ return PojoConverterUtils.copy(qrRepertoryVO, GetQrRepertoryDetailRes.class);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 码库启用
|
|
|
+ * 码库启用:针对的是系统生成和FTP接入,文本导入不存在启用的概念
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void enableQrRepertory(EnableQrRepertoryReq req) {
|
|
|
List<Long> idList = req.getIds();
|
|
|
for (Long id : idList) {
|
|
|
QrRepertory qrRepertory = qrRepertoryMapper.selectById(id);
|
|
|
AssertUtil.isNull(qrRepertory, "码库不存在");
|
|
|
|
|
|
- // TODO
|
|
|
- QrRepertory update = new QrRepertory().setId(id).setStatus(null);
|
|
|
+ // 启用针对的是系统生成和FTP接入类型的码库
|
|
|
+ Integer qrRepertoryType = qrRepertory.getType();
|
|
|
+ if (QrRepertoryTypeEnum.FILE_IMPORT.is(qrRepertoryType)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 在状态为待生成、停用时可启用
|
|
|
+ Integer qrRepertoryStatus = qrRepertory.getStatus();
|
|
|
+ if (!QrRepertoryStatusEnum.WAIT_GENERATE.is(qrRepertoryStatus) && !QrRepertoryStatusEnum.DISABLE.is(qrRepertoryStatus)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 启用时需判断其关联的码格式是否停用,若是,则启用失败
|
|
|
+ if (QrRepertoryTypeEnum.SYSTEM_GENERATE.is(qrRepertoryType)) {
|
|
|
+ List<String> disabledQrFormatList = qrFormatMapper.selectDisabledQrFormat(id);
|
|
|
+ if (!CollectionUtils.isEmpty(disabledQrFormatList)) {
|
|
|
+ throw new BusinessException("该码库关联的码格式" + disabledQrFormatList + "已停用,码库启用失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ QrRepertory update = new QrRepertory().setId(id).setStatus(QrRepertoryStatusEnum.GENERATING.getCode());
|
|
|
qrRepertoryMapper.updateById(update);
|
|
|
}
|
|
|
}
|
|
@@ -124,13 +188,19 @@ public class QrRepertoryServiceImpl implements QrRepertoryService {
|
|
|
* 码库禁用
|
|
|
*/
|
|
|
@Override
|
|
|
- public void disableFormat(DisableQrRepertoryReq req) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void disableQrRepertory(DisableQrRepertoryReq req) {
|
|
|
List<Long> idList = req.getIds();
|
|
|
for (Long id : idList) {
|
|
|
QrRepertory qrRepertory = qrRepertoryMapper.selectById(id);
|
|
|
AssertUtil.isNull(qrRepertory, "码库不存在");
|
|
|
|
|
|
- // TODO
|
|
|
+ // 在状态为已导入、自动生成时可停用
|
|
|
+ Integer qrRepertoryStatus = qrRepertory.getStatus();
|
|
|
+ if (!QrRepertoryStatusEnum.GENERATING.is(qrRepertoryStatus) && !QrRepertoryStatusEnum.IMPORTED.is(qrRepertoryStatus)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
QrRepertory update = new QrRepertory().setId(id).setStatus(QrRepertoryStatusEnum.DISABLE.getCode());
|
|
|
qrRepertoryMapper.updateById(update);
|
|
|
}
|
|
@@ -140,6 +210,7 @@ public class QrRepertoryServiceImpl implements QrRepertoryService {
|
|
|
* 删除码库
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void deleteQrRepertory(DeleteQrRepertoryReq req) {
|
|
|
QrRepertory qrRepertory = qrRepertoryMapper.selectById(req.getId());
|
|
|
AssertUtil.isNull(qrRepertory, "码库不存在");
|
|
@@ -152,5 +223,8 @@ public class QrRepertoryServiceImpl implements QrRepertoryService {
|
|
|
// 逻辑删除
|
|
|
QrRepertory update = new QrRepertory().setId(req.getId()).setIsDelete(1);
|
|
|
qrRepertoryMapper.updateById(update);
|
|
|
+
|
|
|
+ // 逻辑删除码库的列
|
|
|
+ qrRepertoryColumnMapper.deleteByQrRepertoryId(req.getId());
|
|
|
}
|
|
|
}
|