|
@@ -1,20 +1,47 @@
|
|
|
package com.imed.costaccount.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.imed.costaccount.common.exception.CostException;
|
|
|
+import com.imed.costaccount.mapper.ReportFormMapper;
|
|
|
import com.imed.costaccount.mapper.ReportRelationMapper;
|
|
|
+import com.imed.costaccount.model.Accounting;
|
|
|
+import com.imed.costaccount.model.CostShareParam;
|
|
|
+import com.imed.costaccount.model.ReportForm;
|
|
|
import com.imed.costaccount.model.ReportRelation;
|
|
|
+import com.imed.costaccount.model.dto.ReportRelationDTO;
|
|
|
import com.imed.costaccount.model.vo.RelationVO;
|
|
|
+import com.imed.costaccount.service.AccountingService;
|
|
|
+import com.imed.costaccount.service.CostShareParamService;
|
|
|
+import com.imed.costaccount.service.ReportFormService;
|
|
|
import com.imed.costaccount.service.ReportRelationService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
@Service("reportRelationService")
|
|
|
public class ReportRelationServiceImpl extends ServiceImpl<ReportRelationMapper, ReportRelation> implements ReportRelationService {
|
|
|
|
|
|
+ private final AccountingService accountingService;
|
|
|
+ private final CostShareParamService shareParamService;
|
|
|
+ private final ReportFormMapper reportFormMapper;
|
|
|
+
|
|
|
+ public ReportRelationServiceImpl(AccountingService accountingService, CostShareParamService shareParamService, ReportFormMapper reportFormMapper) {
|
|
|
+ this.accountingService = accountingService;
|
|
|
+ this.shareParamService = shareParamService;
|
|
|
+ this.reportFormMapper = reportFormMapper;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 报表项目关联的会计科目对象
|
|
|
*
|
|
@@ -38,4 +65,125 @@ public class ReportRelationServiceImpl extends ServiceImpl<ReportRelationMapper,
|
|
|
public List<RelationVO> getShareParam(Long reportId, Long hospId) {
|
|
|
return baseMapper.getShareParam(reportId, hospId);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据关系类型,获取可绑定的关系数据(包含回显)
|
|
|
+ *
|
|
|
+ * @param reportId 报表项目id
|
|
|
+ * @param relation 1.对应会计科目设置,2.对应分摊参数设置,根据列表中showAddRelation字段是否存在判断
|
|
|
+ * @param hospId 医院id
|
|
|
+ * @return 返回所有列表 并便是已选择的元素
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<RelationVO> getRelationList(Long reportId, Integer relation, Long hospId) {
|
|
|
+ List<RelationVO> list = new ArrayList<>();
|
|
|
+ if (relation == 1) {
|
|
|
+ List<RelationVO> accountRelation = this.getAccountRelation(reportId, hospId);
|
|
|
+ List<Accounting> accounts = accountingService.list(new LambdaQueryWrapper<Accounting>().select(Accounting::getAccountingCode, Accounting::getAccountingName).eq(Accounting::getHospId, hospId));
|
|
|
+ if (accounts.isEmpty()) {
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ list = accounts.stream().map(i -> {
|
|
|
+ RelationVO relationVO = new RelationVO();
|
|
|
+ relationVO.setIsSelect(false);
|
|
|
+ relationVO.setRelation(1);
|
|
|
+ relationVO.setCode(i.getAccountingCode());
|
|
|
+ relationVO.setName(i.getAccountingName());
|
|
|
+ return relationVO;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ for (RelationVO relationVO : accountRelation) {
|
|
|
+ for (RelationVO vo : list) {
|
|
|
+ if (vo.getCode().equals(relationVO.getCode())) {
|
|
|
+ vo.setIsSelect(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (relation == 2) {
|
|
|
+ List<RelationVO> accountRelation = this.getShareParam(reportId, hospId);
|
|
|
+ List<CostShareParam> accounts = shareParamService.list(new LambdaQueryWrapper<CostShareParam>().select(CostShareParam::getShareParamCode, CostShareParam::getShareParamName).eq(CostShareParam::getHospId, hospId));
|
|
|
+ if (accounts.isEmpty()) {
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ list = accounts.stream().map(i -> {
|
|
|
+ RelationVO relationVO = new RelationVO();
|
|
|
+ relationVO.setIsSelect(false);
|
|
|
+ relationVO.setRelation(1);
|
|
|
+ relationVO.setCode(i.getShareParamCode());
|
|
|
+ relationVO.setName(i.getShareParamName());
|
|
|
+ return relationVO;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ for (RelationVO relationVO : accountRelation) {
|
|
|
+ for (RelationVO vo : list) {
|
|
|
+ if (vo.getCode().equals(relationVO.getCode())) {
|
|
|
+ vo.setIsSelect(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑相关关系
|
|
|
+ *
|
|
|
+ * @param reportRelationDTO {@link ReportRelationDTO}
|
|
|
+ * @param hospId
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
+ public void saveReportRelation(ReportRelationDTO reportRelationDTO, Long hospId) {
|
|
|
+
|
|
|
+ Integer relation = reportRelationDTO.getRelation();
|
|
|
+ List<String> relationCodes = reportRelationDTO.getRelationCodes();
|
|
|
+ Long reportId = reportRelationDTO.getReportId();
|
|
|
+
|
|
|
+ // 校验这个report是否能绑定
|
|
|
+ ReportForm byId = reportFormMapper.selectById(reportId);
|
|
|
+ if (Objects.isNull(byId)) {
|
|
|
+ throw new CostException("选择的报表项目不存在");
|
|
|
+ }
|
|
|
+ Integer calcType = byId.getCalcType();
|
|
|
+ if (calcType != 1 && calcType != 2) {
|
|
|
+ throw new CostException("选择的报表项目不能绑定关联关系");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ReportRelation> list = this.list(
|
|
|
+ new LambdaQueryWrapper<ReportRelation>().eq(ReportRelation::getReportId, reportId).eq(ReportRelation::getHospId, hospId)
|
|
|
+ );
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ baseMapper.deleteBatchIds(list);
|
|
|
+ }
|
|
|
+ List<ReportRelation> reportRelations = relationCodes.stream().map(code -> {
|
|
|
+ ReportRelation reportRelation = new ReportRelation();
|
|
|
+ reportRelation.setRelation(relation);
|
|
|
+ reportRelation.setReportId(reportId);
|
|
|
+ reportRelation.setHospId(hospId);
|
|
|
+ reportRelation.setRelationCode(code);
|
|
|
+ reportRelation.setCreateTime(System.currentTimeMillis());
|
|
|
+ return reportRelation;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ // 校验 关联关系的id 是否已绑定过其他的报表项目
|
|
|
+ checkIfExist(hospId, relation, relationCodes);
|
|
|
+ this.saveBatch(reportRelations);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验 关联关系的id 是否已绑定过其他的报表项目
|
|
|
+ *
|
|
|
+ * @param hospId 医院id
|
|
|
+ * @param relation 关系
|
|
|
+ * @param relationCodes 所有需要绑定的code 列表
|
|
|
+ */
|
|
|
+ private void checkIfExist(Long hospId, Integer relation, List<String> relationCodes) {
|
|
|
+ List<ReportRelation> relations = this.list(
|
|
|
+ new LambdaQueryWrapper<ReportRelation>().select(ReportRelation::getRelationCode)
|
|
|
+ .in(ReportRelation::getRelationCode, relationCodes)
|
|
|
+ .eq(ReportRelation::getRelation, relation)
|
|
|
+ .eq(ReportRelation::getHospId, hospId)
|
|
|
+ );
|
|
|
+ if (CollUtil.isNotEmpty(relations)) {
|
|
|
+ throw new CostException(500, "编码为:" + StrUtil.join(StrUtil.COMMA, relation) + "已被绑定");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|