|
|
@@ -10,6 +10,8 @@ import cn.tr.module.smart.common.mapper.BizDeptMapper;
|
|
|
import cn.tr.module.smart.common.mapper.BizDocDeptMapper;
|
|
|
import cn.tr.module.smart.common.mapper.BizQuestionDeptMapper;
|
|
|
import cn.tr.module.smart.common.po.BizDeptPO;
|
|
|
+import cn.tr.module.smart.common.po.BizDocDeptPO;
|
|
|
+import cn.tr.module.smart.common.po.BizQuestionDeptPO;
|
|
|
import cn.tr.module.smart.common.repository.BizDeptRepository;
|
|
|
import cn.tr.module.smart.common.repository.BizDocDeptRepository;
|
|
|
import cn.tr.module.smart.common.repository.BizQuestionDeptRepository;
|
|
|
@@ -19,6 +21,7 @@ import cn.tr.module.smart.web.dto.BizDeptLinkQuestionDTO;
|
|
|
import cn.tr.module.smart.wx.controller.vo.BizWxDeptVO;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -26,6 +29,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 科室Service接口实现类
|
|
|
@@ -34,15 +39,16 @@ import java.util.Objects;
|
|
|
* @date 2025/06/04 14:09
|
|
|
**/
|
|
|
@Service
|
|
|
-public class BizDeptServiceImpl implements IBizDeptService {
|
|
|
+public class BizDeptServiceImpl extends ServiceImpl<BizDeptRepository, BizDeptPO> implements IBizDeptService {
|
|
|
@Autowired
|
|
|
private BizDeptRepository baseRepository;
|
|
|
|
|
|
+
|
|
|
@Autowired
|
|
|
- private BizDocDeptRepository bizDocDeptRepository;
|
|
|
+ private BizDocDeptServiceImpl bizDocDeptService;
|
|
|
|
|
|
@Autowired
|
|
|
- private BizQuestionDeptRepository bizQuestionDeptRepository;
|
|
|
+ private BizQuestionDeptServiceImpl bizQuestionDeptService;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
@@ -136,16 +142,30 @@ public class BizDeptServiceImpl implements IBizDeptService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean deptLinkDoc(BizDeptLinkDocDTO source) {
|
|
|
- BizDeptPO bizDeptPO = baseRepository.selectById(source.getDeptId());
|
|
|
+ if (CollectionUtil.isEmpty(source.getDocIds())) {
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "请选择要关联的文档");
|
|
|
+ }
|
|
|
+ String deptId = source.getDeptId();
|
|
|
+ BizDeptPO bizDeptPO = baseRepository.selectById(deptId);
|
|
|
if (bizDeptPO == null) {
|
|
|
throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "科室不存在");
|
|
|
}
|
|
|
- bizDocDeptRepository.insert(BizDocDeptMapper.INSTANCE.convertLinkDocDTOToPO(source));
|
|
|
+ List<String> docIds = source.getDocIds();
|
|
|
+ if (docIds.stream().anyMatch(Objects::isNull)) {
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "问卷组ID列表中包含空值");
|
|
|
+ }
|
|
|
+ List<BizDocDeptPO> bizDocDeptPOS = docIds.stream().map(docId->{
|
|
|
+ BizDocDeptPO bizDocDeptPO = new BizDocDeptPO();
|
|
|
+ bizDocDeptPO.setDocId(docId);
|
|
|
+ bizDocDeptPO.setDeptId(deptId);
|
|
|
+ return bizDocDeptPO;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ bizDocDeptService.saveOrUpdateBatch(bizDocDeptPOS);
|
|
|
//修改 宣教文档关联个数
|
|
|
return baseRepository.update(null,
|
|
|
new LambdaUpdateWrapper<BizDeptPO>()
|
|
|
- .set(BizDeptPO::getMissionDocCount, bizDeptPO.getMissionDocCount() + 1)
|
|
|
- .eq(BizDeptPO::getId, source.getDeptId())) != 0;
|
|
|
+ .set(BizDeptPO::getMissionDocCount, bizDeptPO.getMissionDocCount() + bizDocDeptPOS.size())
|
|
|
+ .eq(BizDeptPO::getId, deptId)) != 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -157,15 +177,29 @@ public class BizDeptServiceImpl implements IBizDeptService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean deptLinkQuestionGroup(BizDeptLinkQuestionDTO source) {
|
|
|
- BizDeptPO bizDeptPO = baseRepository.selectById(source.getDeptId());
|
|
|
+ if (CollectionUtil.isEmpty(source.getQuestionGroupIds())) {
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "请选择要关联的问卷");
|
|
|
+ }
|
|
|
+ String deptId = source.getDeptId();
|
|
|
+ BizDeptPO bizDeptPO = baseRepository.selectById(deptId);
|
|
|
if (Objects.isNull(bizDeptPO)) {
|
|
|
throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "科室不存在");
|
|
|
}
|
|
|
- bizQuestionDeptRepository.insert(BizQuestionDeptMapper.INSTANCE.convertLinkQuestionDTOToPO(source));
|
|
|
+ List<String> questionGroupIds = source.getQuestionGroupIds();
|
|
|
+ if (questionGroupIds.stream().anyMatch(Objects::isNull)) {
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "问卷组ID列表中包含空值");
|
|
|
+ }
|
|
|
+ List<BizQuestionDeptPO> collect = questionGroupIds.stream().map(questionGroupId -> {
|
|
|
+ BizQuestionDeptPO bizQuestionDeptPO = new BizQuestionDeptPO();
|
|
|
+ bizQuestionDeptPO.setDeptId(deptId);
|
|
|
+ bizQuestionDeptPO.setQuestionGroupId(questionGroupId);
|
|
|
+ return bizQuestionDeptPO;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ bizQuestionDeptService.saveOrUpdateBatch(collect);
|
|
|
return baseRepository.update(null,
|
|
|
new LambdaUpdateWrapper<BizDeptPO>()
|
|
|
- .set(BizDeptPO::getQuestionCount, bizDeptPO.getQuestionCount() + 1)
|
|
|
- .eq(BizDeptPO::getId, source.getDeptId())) != 0;
|
|
|
+ .set(BizDeptPO::getQuestionCount, bizDeptPO.getQuestionCount() + collect.size())
|
|
|
+ .eq(BizDeptPO::getId, deptId)) != 0;
|
|
|
}
|
|
|
|
|
|
}
|