From d4f8d4b7b624628fbcaf3459546aaa55334a9922 Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期四, 19 十二月 2024 19:03:02 +0800
Subject: [PATCH] 防护管理接口

---
 medicalWaste-system/src/main/java/com/sinata/system/service/impl/MwProtectionEquipmentServiceImpl.java |   65 ++++++++++++++++++++++++++++++++
 1 files changed, 64 insertions(+), 1 deletions(-)

diff --git a/medicalWaste-system/src/main/java/com/sinata/system/service/impl/MwProtectionEquipmentServiceImpl.java b/medicalWaste-system/src/main/java/com/sinata/system/service/impl/MwProtectionEquipmentServiceImpl.java
index 41caada..8b46c63 100644
--- a/medicalWaste-system/src/main/java/com/sinata/system/service/impl/MwProtectionEquipmentServiceImpl.java
+++ b/medicalWaste-system/src/main/java/com/sinata/system/service/impl/MwProtectionEquipmentServiceImpl.java
@@ -6,20 +6,29 @@
 import com.sinata.common.entity.PageDTO;
 import com.sinata.common.exception.ServiceException;
 import com.sinata.common.utils.BeanUtils;
+import com.sinata.common.utils.CollUtils;
+import com.sinata.system.domain.MwAttachment;
 import com.sinata.system.domain.MwProtectionEquipment;
 import com.sinata.system.domain.MwProtectionEquipmentRecord;
 import com.sinata.system.domain.dto.MwProtectionEquipmentDTO;
 import com.sinata.system.domain.dto.MwProtectionEquipmentRecordDTO;
 import com.sinata.system.domain.query.MwProtectionEquipmentQuery;
+import com.sinata.system.domain.query.MwProtectionEquipmentRecordQuery;
+import com.sinata.system.domain.vo.MwAttachmentVO;
+import com.sinata.system.domain.vo.MwProtectionEquipmentRecordVO;
 import com.sinata.system.domain.vo.MwProtectionEquipmentVO;
+import com.sinata.system.enums.AttachmentTypeEnum;
 import com.sinata.system.mapper.MwProtectionEquipmentMapper;
 import com.sinata.system.service.ISysDictDataService;
+import com.sinata.system.service.MwAttachmentService;
 import com.sinata.system.service.MwProtectionEquipmentRecordService;
 import com.sinata.system.service.MwProtectionEquipmentService;
 import com.sinata.system.service.SysDepartmentService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.util.List;
 import java.util.Objects;
 
 /**
@@ -36,6 +45,7 @@
     private final SysDepartmentService sysDepartmentService;
     private final ISysDictDataService sysDictDataService;
     private final MwProtectionEquipmentRecordService mwProtectionEquipmentRecordService;
+    private final MwAttachmentService mwAttachmentService;
 
     /**
      * 防护器具分页列表
@@ -58,7 +68,11 @@
      */
     @Override
     public MwProtectionEquipmentVO detail(Long id) {
-        return BeanUtils.copyBean(this.getById(id), MwProtectionEquipmentVO.class);
+        MwProtectionEquipmentVO mwProtectionEquipmentVO = BeanUtils.copyBean(this.getById(id), MwProtectionEquipmentVO.class);
+        //查询附件列表
+        List<MwAttachment> list = mwAttachmentService.lambdaQuery().eq(MwAttachment::getType, AttachmentTypeEnum.PROTECTION_EQUIPMENT.getCode()).eq(MwAttachment::getTargetId, id).list();
+        mwProtectionEquipmentVO.setAttachmentList(BeanUtils.copyToList(list, MwAttachmentVO.class));
+        return mwProtectionEquipmentVO;
     }
 
     /**
@@ -68,6 +82,7 @@
      * @return
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void add(MwProtectionEquipmentDTO dto) {
         MwProtectionEquipment mwProtectionEquipment = BeanUtils.copyBean(dto, MwProtectionEquipment.class);
         SysDictData dictData = sysDictDataService.lambdaQuery().eq(SysDictData::getDictCode, dto.getProtectionEquipmentType()).one();
@@ -75,6 +90,15 @@
             mwProtectionEquipment.setProtectionEquipmentTypeStr(dictData.getDictLabel());
         }
         save(mwProtectionEquipment);
+        //保存附件
+        if (CollUtils.isNotEmpty(dto.getAttachmentList())) {
+            List<MwAttachment> mwAttachments = BeanUtils.copyToList(dto.getAttachmentList(), MwAttachment.class);
+            mwAttachments.forEach(attachment -> {
+                attachment.setTargetId(mwProtectionEquipment.getId());
+                attachment.setType(AttachmentTypeEnum.PROTECTION_EQUIPMENT.getCode());
+            });
+            mwAttachmentService.saveBatch(mwAttachments);
+        }
     }
 
     /**
@@ -84,6 +108,7 @@
      * @return
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void edit(MwProtectionEquipmentDTO dto) {
         if (Objects.isNull(dto.getId())) {
             throw new ServiceException("防护器具id不能为空");
@@ -94,6 +119,31 @@
             mwProtectionEquipment.setProtectionEquipmentTypeStr(dictData.getDictLabel());
         }
         updateById(mwProtectionEquipment);
+        //保存附件
+        if (CollUtils.isNotEmpty(dto.getAttachmentList())) {
+            //删除原有的附件
+            mwAttachmentService.lambdaUpdate().eq(MwAttachment::getType, AttachmentTypeEnum.PROTECTION_EQUIPMENT.getCode()).eq(MwAttachment::getTargetId, dto.getId()).remove();
+            List<MwAttachment> mwAttachments = BeanUtils.copyToList(dto.getAttachmentList(), MwAttachment.class);
+            mwAttachments.forEach(attachment -> {
+                attachment.setTargetId(mwProtectionEquipment.getId());
+                attachment.setType(AttachmentTypeEnum.PROTECTION_EQUIPMENT.getCode());
+            });
+            mwAttachmentService.saveBatch(mwAttachments);
+        }
+    }
+
+    /**
+     * 删除
+     *
+     * @param id
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void delete(Long id) {
+        removeById(id);
+        //删除原有的附件
+        mwAttachmentService.lambdaUpdate().eq(MwAttachment::getType, AttachmentTypeEnum.PROTECTION_EQUIPMENT.getCode()).eq(MwAttachment::getTargetId, id).remove();
     }
 
     @Override
@@ -109,4 +159,17 @@
         mwProtectionEquipmentRecord.setType(1);
         mwProtectionEquipmentRecordService.save(mwProtectionEquipmentRecord);
     }
+
+    /**
+     * 增减记录分页列表
+     *
+     * @param query
+     * @return
+     */
+    @Override
+    public PageDTO<MwProtectionEquipmentRecordVO> recordPage(MwProtectionEquipmentRecordQuery query) {
+        Page<MwProtectionEquipmentRecordVO> page = baseMapper.recordPage(new Page<>(query.getPageCurr(), query.getPageSize()), query.getId());
+        return PageDTO.of(page);
+    }
+
 }

--
Gitblit v1.7.1