From 71542a84d8461b3ae216ee35fda214752a94d350 Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期一, 23 十二月 2024 19:08:51 +0800
Subject: [PATCH] 执法监管、审核管理、职工管理、协议内容管理接口

---
 medicalWaste-system/src/main/java/com/sinata/system/service/impl/MwRegulatoryRecordServiceImpl.java |  125 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 122 insertions(+), 3 deletions(-)

diff --git a/medicalWaste-system/src/main/java/com/sinata/system/service/impl/MwRegulatoryRecordServiceImpl.java b/medicalWaste-system/src/main/java/com/sinata/system/service/impl/MwRegulatoryRecordServiceImpl.java
index 1396871..94717c6 100644
--- a/medicalWaste-system/src/main/java/com/sinata/system/service/impl/MwRegulatoryRecordServiceImpl.java
+++ b/medicalWaste-system/src/main/java/com/sinata/system/service/impl/MwRegulatoryRecordServiceImpl.java
@@ -1,10 +1,29 @@
 package com.sinata.system.service.impl;
 
-import com.sinata.system.domain.MwRegulatoryRecord;
-import com.sinata.system.mapper.MwRegulatoryRecordMapper;
-import com.sinata.system.service.MwRegulatoryRecordService;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+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.MwRegulatoryRecord;
+import com.sinata.system.domain.SysDepartment;
+import com.sinata.system.domain.dto.MwRegulatoryRecordDTO;
+import com.sinata.system.domain.query.MwRegulatoryRecordQuery;
+import com.sinata.system.domain.vo.MwAttachmentVO;
+import com.sinata.system.domain.vo.MwRegulatoryRecordVO;
+import com.sinata.system.enums.AttachmentTypeEnum;
+import com.sinata.system.mapper.MwRegulatoryRecordMapper;
+import com.sinata.system.service.MwAttachmentService;
+import com.sinata.system.service.MwRegulatoryRecordService;
+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;
 
 /**
  * <p>
@@ -15,6 +34,106 @@
  * @since 2024-12-02
  */
 @Service
+@RequiredArgsConstructor
 public class MwRegulatoryRecordServiceImpl extends ServiceImpl<MwRegulatoryRecordMapper, MwRegulatoryRecord> implements MwRegulatoryRecordService {
+    private final SysDepartmentService sysDepartmentService;
+    private final MwAttachmentService mwAttachmentService;
 
+    /**
+     * 分页列表
+     *
+     * @param query
+     * @return
+     */
+    @Override
+    public PageDTO<MwRegulatoryRecordVO> pageList(MwRegulatoryRecordQuery query) {
+        String treeCode = sysDepartmentService.getTreeCodeByDepartmentId(query.getDepartmentId());
+        Page<MwRegulatoryRecordVO> page = baseMapper.pageList(new Page<>(), query, treeCode);
+        return PageDTO.of(page);
+    }
+
+    /**
+     * 详情
+     *
+     * @param id
+     * @return
+     */
+    @Override
+    public MwRegulatoryRecordVO detail(Long id) {
+        MwRegulatoryRecord regulatoryRecord = getById(id);
+        MwRegulatoryRecordVO vo = BeanUtils.copyBean(regulatoryRecord, MwRegulatoryRecordVO.class);
+        if (Objects.nonNull(vo)) {
+            List<MwAttachment> list = mwAttachmentService.lambdaQuery().eq(MwAttachment::getType, AttachmentTypeEnum.REGULATORY.getCode()).eq(MwAttachment::getTargetId, id).list();
+            vo.setAttachmentList(BeanUtils.copyToList(list, MwAttachmentVO.class));
+            SysDepartment department = sysDepartmentService.getById(vo.getDepartmentId());
+            if (Objects.nonNull(department)) {
+                vo.setDepartmentName(department.getDepartmentName());
+            }
+
+        }
+        return vo;
+    }
+
+    /**
+     * 新增检查记录
+     *
+     * @param dto
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void add(MwRegulatoryRecordDTO dto) {
+        MwRegulatoryRecord mwRegulatoryRecord = BeanUtils.copyBean(dto, MwRegulatoryRecord.class);
+        save(mwRegulatoryRecord);
+        //保存附件
+        if (CollUtils.isNotEmpty(dto.getAttachmentList())) {
+            List<MwAttachment> mwAttachments = BeanUtils.copyToList(dto.getAttachmentList(), MwAttachment.class);
+            mwAttachments.forEach(attachment -> {
+                attachment.setTargetId(mwRegulatoryRecord.getId());
+                attachment.setType(AttachmentTypeEnum.REGULATORY.getCode());
+            });
+            mwAttachmentService.saveBatch(mwAttachments);
+        }
+    }
+
+    /**
+     * 编辑检查记录
+     *
+     * @param dto
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void edit(MwRegulatoryRecordDTO dto) {
+        if (Objects.isNull(dto.getId())) {
+            throw new ServiceException("检查记录id不能为空");
+        }
+        MwRegulatoryRecord mwRegulatoryRecord = BeanUtils.copyBean(dto, MwRegulatoryRecord.class);
+        updateById(mwRegulatoryRecord);
+        //删除原来的附件
+        mwAttachmentService.lambdaUpdate().eq(MwAttachment::getType, AttachmentTypeEnum.REGULATORY.getCode()).eq(MwAttachment::getTargetId, dto.getId()).remove();
+        //保存附件
+        if (CollUtils.isNotEmpty(dto.getAttachmentList())) {
+            List<MwAttachment> mwAttachments = BeanUtils.copyToList(dto.getAttachmentList(), MwAttachment.class);
+            mwAttachments.forEach(attachment -> {
+                attachment.setTargetId(mwRegulatoryRecord.getId());
+                attachment.setType(AttachmentTypeEnum.REGULATORY.getCode());
+            });
+            mwAttachmentService.saveBatch(mwAttachments);
+        }
+    }
+
+    /**
+     * 删除
+     *
+     * @param id
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void delete(Long id) {
+        //删除附件
+        mwAttachmentService.lambdaUpdate().eq(MwAttachment::getType, AttachmentTypeEnum.REGULATORY.getCode()).eq(MwAttachment::getTargetId, id).remove();
+        removeById(id);
+    }
 }

--
Gitblit v1.7.1