|
@@ -0,0 +1,156 @@
|
|
|
+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.QrRepertoryMapper;
|
|
|
+import com.abi.qms.platform.dao.vo.result.QrRepertoryVO;
|
|
|
+import com.abi.qms.platform.dto.req.*;
|
|
|
+import com.abi.qms.platform.dto.res.GetQrRepertoryDetailRes;
|
|
|
+import com.abi.qms.platform.dto.res.ListQrRepertoryRes;
|
|
|
+import com.abi.qms.platform.infrastructure.util.AssertUtil;
|
|
|
+import com.abi.qms.platform.infrastructure.util.PageUtil;
|
|
|
+import com.abi.qms.platform.infrastructure.util.UserUtil;
|
|
|
+import com.abi.qms.platform.service.QrRepertoryService;
|
|
|
+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 org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 码库 Service业务层处理
|
|
|
+ *
|
|
|
+ * @author WeiganCai
|
|
|
+ * @date 2021-04-25
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class QrRepertoryServiceImpl implements QrRepertoryService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QrRepertoryMapper qrRepertoryMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存码库
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void saveQrRepertory(SaveQrRepertoryReq req) {
|
|
|
+ // 同部门下码库名称不可重复
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ Integer count = qrRepertoryMapper.selectCount(qrRepertoryQw);
|
|
|
+ if (!count.equals(0)) {
|
|
|
+ throw new BusinessException("码库名称已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // copy属性值
|
|
|
+ QrRepertory qrRepertory = PojoConverterUtils.copy(req, QrRepertory.class);
|
|
|
+ Integer qrRepertoryType = qrRepertory.getType();
|
|
|
+ // 文本导入类型设置状态为待导入,其他两种类型设置状态为待生成
|
|
|
+ if (QrRepertoryTypeEnum.FILE_IMPORT.is(qrRepertoryType)) {
|
|
|
+ qrRepertory.setStatus(QrRepertoryStatusEnum.WAIT_IMPORT.getCode());
|
|
|
+ } else {
|
|
|
+ qrRepertory.setStatus(QrRepertoryStatusEnum.WAIT_GENERATE.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增or修改
|
|
|
+ Long userId = UserUtil.getUser().getId();
|
|
|
+ qrRepertory.setUpdateBy(userId);
|
|
|
+ if (req.getId() != null) {
|
|
|
+ qrRepertoryMapper.updateById(qrRepertory);
|
|
|
+ } else {
|
|
|
+ qrRepertory.setCreateBy(userId);
|
|
|
+ qrRepertoryMapper.insert(qrRepertory);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 码库查询分页
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ListQrRepertoryRes listQrRepertory(ListQrRepertoryReq req) {
|
|
|
+ // 分页查询
|
|
|
+ IPage<QrRepertoryVO> iPage = qrRepertoryMapper.listQrRepertory(PageUtil.createPage(req), req);
|
|
|
+ List<QrRepertoryVO> qrRepertoryList = iPage.getRecords();
|
|
|
+
|
|
|
+ // 封装出参、放入分页信息
|
|
|
+ ListQrRepertoryRes res = new ListQrRepertoryRes();
|
|
|
+ PageUtil.copyPageInfo(res, iPage);
|
|
|
+ List<ListQrRepertoryRes.QrRepertoryBean> qrRepertoryBeanList = PojoConverterUtils.copyList(qrRepertoryList, ListQrRepertoryRes.QrRepertoryBean.class);
|
|
|
+ res.setQrRepertoryBeanList(qrRepertoryBeanList);
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 码库查询详情
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public GetQrRepertoryDetailRes getQrRepertoryDetail(GetQrRepertoryDetailReq req) {
|
|
|
+ // 查询码库对象
|
|
|
+ QrRepertory qrRepertory = qrRepertoryMapper.selectById(req.getId());
|
|
|
+ AssertUtil.isNull(qrRepertory, "码库不存在");
|
|
|
+
|
|
|
+ return PojoConverterUtils.copy(qrRepertory, GetQrRepertoryDetailRes.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 码库启用
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ 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);
|
|
|
+ qrRepertoryMapper.updateById(update);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 码库禁用
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void disableFormat(DisableQrRepertoryReq 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(QrRepertoryStatusEnum.DISABLE.getCode());
|
|
|
+ qrRepertoryMapper.updateById(update);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除码库
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void deleteQrRepertory(DeleteQrRepertoryReq req) {
|
|
|
+ QrRepertory qrRepertory = qrRepertoryMapper.selectById(req.getId());
|
|
|
+ AssertUtil.isNull(qrRepertory, "码库不存在");
|
|
|
+ // 只有待生成、待导入状态下才可删除
|
|
|
+ Integer qrRepertoryStatus = qrRepertory.getStatus();
|
|
|
+ if (!QrRepertoryStatusEnum.WAIT_GENERATE.is(qrRepertoryStatus) && !QrRepertoryStatusEnum.WAIT_IMPORT.is(qrRepertoryStatus)) {
|
|
|
+ throw new BusinessException("码库不可删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 逻辑删除
|
|
|
+ QrRepertory update = new QrRepertory().setId(req.getId()).setIsDelete(1);
|
|
|
+ qrRepertoryMapper.updateById(update);
|
|
|
+ }
|
|
|
+}
|