|
|
@@ -0,0 +1,99 @@
|
|
|
+package cn.iocoder.yudao.module.iscs.service.sop;
|
|
|
+
|
|
|
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
+import cn.iocoder.yudao.module.iscs.controller.admin.sop.vo.SopGroupPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.iscs.controller.admin.sop.vo.SopGroupRespVO;
|
|
|
+import cn.iocoder.yudao.module.iscs.controller.admin.sop.vo.SopGroupSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.iscs.dal.dataobject.sop.SopGroupDO;
|
|
|
+import cn.iocoder.yudao.module.iscs.dal.dataobject.sop.SopPointsDO;
|
|
|
+import cn.iocoder.yudao.module.iscs.dal.dataobject.sop.SopUserDO;
|
|
|
+import cn.iocoder.yudao.module.iscs.dal.mysql.sop.SopGroupMapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.Assert;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * SOP分组 Service 实现类
|
|
|
+ *
|
|
|
+ * @author 芋道源码
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Validated
|
|
|
+public class SopGroupServiceImpl extends ServiceImpl<SopGroupMapper, SopGroupDO> implements SopGroupService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SopGroupMapper sopGroupMapper;
|
|
|
+ @Lazy
|
|
|
+ @Resource
|
|
|
+ private SopUserService sopUserService;
|
|
|
+ @Lazy
|
|
|
+ @Resource
|
|
|
+ private SopPointsService sopPointsService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long createSopGroup(SopGroupSaveReqVO createReqVO) {
|
|
|
+ // 重复分组
|
|
|
+ List<SopGroupDO> list = list(Wrappers.<SopGroupDO>lambdaQuery()
|
|
|
+ .eq(SopGroupDO::getSopId, createReqVO.getSopId())
|
|
|
+ .eq(SopGroupDO::getGroupName, createReqVO.getGroupName()));
|
|
|
+ Assert.isTrue(list.isEmpty(), "该分组已存在");
|
|
|
+ // 插入
|
|
|
+ SopGroupDO sopGroup = BeanUtils.toBean(createReqVO, SopGroupDO.class);
|
|
|
+ sopGroupMapper.insert(sopGroup);
|
|
|
+
|
|
|
+ // 返回
|
|
|
+ return sopGroup.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateSopGroup(SopGroupSaveReqVO updateReqVO) {
|
|
|
+ // 重复分组
|
|
|
+ List<SopGroupDO> list = list(Wrappers.<SopGroupDO>lambdaQuery()
|
|
|
+ .eq(SopGroupDO::getSopId, updateReqVO.getSopId())
|
|
|
+ .eq(SopGroupDO::getGroupName, updateReqVO.getGroupName())
|
|
|
+ .ne(SopGroupDO::getSopId, updateReqVO.getId()));
|
|
|
+ Assert.isTrue(list.isEmpty(), "该分组已存在");
|
|
|
+ // 更新
|
|
|
+ SopGroupDO updateObj = BeanUtils.toBean(updateReqVO, SopGroupDO.class);
|
|
|
+ sopGroupMapper.updateById(updateObj);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void deleteSopGroupListByIds(List<Long> ids) {
|
|
|
+ // 1.同时将sop的隔离点清除分组
|
|
|
+ List<SopPointsDO> list1 = sopPointsService.list(Wrappers.<SopPointsDO>lambdaQuery()
|
|
|
+ .in(SopPointsDO::getGroupId, ids));
|
|
|
+ if (!list1.isEmpty()) {
|
|
|
+ List<Long> sopPointIds = list1.stream().map(SopPointsDO::getId).toList();
|
|
|
+ sopPointsService.deleteSopPointsListByIds(sopPointIds);
|
|
|
+ }
|
|
|
+ // 2.同时将sop的人员清除分组
|
|
|
+ List<SopUserDO> list2 = sopUserService.list(Wrappers.<SopUserDO>lambdaQuery()
|
|
|
+ .in(SopUserDO::getGroupId, ids));
|
|
|
+ if (!list2.isEmpty()) {
|
|
|
+ List<Long> sopUserIds = list2.stream().map(SopUserDO::getId).toList();
|
|
|
+ sopUserService.deleteSopUserListByIds(sopUserIds);
|
|
|
+ }
|
|
|
+ // 3.删除
|
|
|
+ sopGroupMapper.physicalDeleteByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SopGroupDO getSopGroup(Long id) {
|
|
|
+ return sopGroupMapper.selectById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SopGroupRespVO> getSopGroupList(SopGroupPageReqVO pageReqVO) {
|
|
|
+ return BeanUtils.toBean(sopGroupMapper.selectList(pageReqVO), SopGroupRespVO.class);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|