|
@@ -3,17 +3,21 @@ package com.imed.costaccount.service.impl;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
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.ReportFormMapper;
|
|
import com.imed.costaccount.model.ReportForm;
|
|
import com.imed.costaccount.model.ReportForm;
|
|
import com.imed.costaccount.model.User;
|
|
import com.imed.costaccount.model.User;
|
|
|
|
+import com.imed.costaccount.model.dto.ReportFormEditDTO;
|
|
|
|
+import com.imed.costaccount.model.dto.ReportFormSaveDTO;
|
|
import com.imed.costaccount.model.vo.RelationVO;
|
|
import com.imed.costaccount.model.vo.RelationVO;
|
|
import com.imed.costaccount.model.vo.ReportFormVO;
|
|
import com.imed.costaccount.model.vo.ReportFormVO;
|
|
import com.imed.costaccount.service.ReportFormService;
|
|
import com.imed.costaccount.service.ReportFormService;
|
|
import com.imed.costaccount.service.ReportRelationService;
|
|
import com.imed.costaccount.service.ReportRelationService;
|
|
import com.imed.costaccount.utils.BeanUtil;
|
|
import com.imed.costaccount.utils.BeanUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
@@ -21,6 +25,9 @@ import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
+import static com.imed.costaccount.common.constants.NumberConstant.THREE;
|
|
|
|
+import static com.imed.costaccount.constants.CommonConstant.LIMIT_ONE;
|
|
|
|
+
|
|
@Slf4j
|
|
@Slf4j
|
|
@Service("reportFormService")
|
|
@Service("reportFormService")
|
|
public class ReportFormServiceImpl extends ServiceImpl<ReportFormMapper, ReportForm> implements ReportFormService {
|
|
public class ReportFormServiceImpl extends ServiceImpl<ReportFormMapper, ReportForm> implements ReportFormService {
|
|
@@ -41,7 +48,10 @@ public class ReportFormServiceImpl extends ServiceImpl<ReportFormMapper, ReportF
|
|
@Override
|
|
@Override
|
|
public List<ReportFormVO> selectList(Integer reportType, User user) {
|
|
public List<ReportFormVO> selectList(Integer reportType, User user) {
|
|
List<ReportForm> list = this.list(
|
|
List<ReportForm> list = this.list(
|
|
- new LambdaQueryWrapper<ReportForm>().eq(ReportForm::getReportType, reportType).eq(ReportForm::getHospId, user.getHospId())
|
|
|
|
|
|
+ new LambdaQueryWrapper<ReportForm>()
|
|
|
|
+ .eq(ReportForm::getReportType, reportType)
|
|
|
|
+ .eq(ReportForm::getHospId, user.getHospId())
|
|
|
|
+ .orderByAsc(ReportForm::getSort)
|
|
);
|
|
);
|
|
if (CollUtil.isEmpty(list)) {
|
|
if (CollUtil.isEmpty(list)) {
|
|
return Collections.emptyList();
|
|
return Collections.emptyList();
|
|
@@ -65,7 +75,7 @@ public class ReportFormServiceImpl extends ServiceImpl<ReportFormMapper, ReportF
|
|
for (ReportFormVO reportFormVO : reportFormVOS) {
|
|
for (ReportFormVO reportFormVO : reportFormVOS) {
|
|
if (reportFormVO.getParentId().equals(root.getId())) {
|
|
if (reportFormVO.getParentId().equals(root.getId())) {
|
|
children.add(reportFormVO);
|
|
children.add(reportFormVO);
|
|
- this.setRelation(reportFormVO,user.getHospId());
|
|
|
|
|
|
+// this.setRelation(reportFormVO, user.getHospId());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
root.setChildren(children);
|
|
root.setChildren(children);
|
|
@@ -75,6 +85,7 @@ public class ReportFormServiceImpl extends ServiceImpl<ReportFormMapper, ReportF
|
|
|
|
|
|
/**
|
|
/**
|
|
* 填充对应的关联关系
|
|
* 填充对应的关联关系
|
|
|
|
+ *
|
|
* @param reportFormVO {@link ReportFormVO}
|
|
* @param reportFormVO {@link ReportFormVO}
|
|
* @param hospId
|
|
* @param hospId
|
|
*/
|
|
*/
|
|
@@ -94,4 +105,126 @@ public class ReportFormServiceImpl extends ServiceImpl<ReportFormMapper, ReportF
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 新增一个报表项目
|
|
|
|
+ *
|
|
|
|
+ * @param reportFormDTO {@link ReportFormSaveDTO}
|
|
|
|
+ * @param hospId 医院id
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
|
+ public void saveReport(ReportFormSaveDTO reportFormDTO, Long hospId) {
|
|
|
|
+ ReportForm reportForm = BeanUtil.convertObj(reportFormDTO, ReportForm.class);
|
|
|
|
+ Integer num = this.createNum(hospId);
|
|
|
|
+ // TODO: 2021/8/4 控制唯一性
|
|
|
|
+ reportForm.setHospId(hospId)
|
|
|
|
+ .setNum(num)
|
|
|
|
+ .setCreateTime(System.currentTimeMillis());
|
|
|
|
+ // 如果新增的是父节点
|
|
|
|
+ Long parentId = reportFormDTO.getParentId();
|
|
|
|
+ // 根据是否父节点设置必要的数据
|
|
|
|
+ setDataByParentId(hospId, reportForm, parentId);
|
|
|
|
+
|
|
|
|
+ this.save(reportForm);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据是否父节点设置必要的数据
|
|
|
|
+ * ***后台默认处理报表节点不一致的问题***
|
|
|
|
+ * @param hospId 医院id
|
|
|
|
+ * @param reportForm 需要构建的实体
|
|
|
|
+ * @param parentId 父级id
|
|
|
|
+ */
|
|
|
|
+ private void setDataByParentId(Long hospId, ReportForm reportForm, Long parentId) {
|
|
|
|
+ if (parentId == 0L) {
|
|
|
|
+ reportForm.setCalcType(0);
|
|
|
|
+ reportForm.setCalcFormula("");
|
|
|
|
+// reportForm.setReportType(0);
|
|
|
|
+ // 如果编辑的时候子集的reportType 要和父级一致
|
|
|
|
+ Long id = reportForm.getId();
|
|
|
|
+ List<ReportForm> list = this.list(
|
|
|
|
+ new LambdaQueryWrapper<ReportForm>().eq(ReportForm::getParentId, id).eq(ReportForm::getHospId, hospId)
|
|
|
|
+ );
|
|
|
|
+ if (!list.isEmpty()) {
|
|
|
|
+ list.forEach(i -> i.setReportType(reportForm.getReportType()));
|
|
|
|
+ this.updateBatchById(list);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 父子节点报表类型必须一致
|
|
|
|
+ ReportForm byId = this.getById(parentId);
|
|
|
|
+ checkExist(byId,"选择的父报表层级不正确");
|
|
|
|
+ reportForm.setReportType(byId.getReportType());
|
|
|
|
+ // 如果子节点 小计只能存在一个
|
|
|
|
+ this.isSubtotal(parentId, hospId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 子类型中小计计算类型只能存在一个
|
|
|
|
+ * 判断是否存在小计的计算类型,存在抛出异常
|
|
|
|
+ * @param parentId 父级id
|
|
|
|
+ * @param hospId 医院id
|
|
|
|
+ */
|
|
|
|
+ private void isSubtotal(Long parentId, Long hospId) {
|
|
|
|
+ List<ReportForm> list = this.list(
|
|
|
|
+ new LambdaQueryWrapper<ReportForm>().select(ReportForm::getId)
|
|
|
|
+ .eq(ReportForm::getParentId, parentId).eq(ReportForm::getHospId, hospId).eq(ReportForm::getCalcType, THREE)
|
|
|
|
+ );
|
|
|
|
+ if (list.isEmpty()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ throw new CostException("小计类型已存在,请修改计算类型");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 创建最新的num 获取最大的num + 1
|
|
|
|
+ *
|
|
|
|
+ * @param hospId 医院id
|
|
|
|
+ * @return 返回本医院最新编号
|
|
|
|
+ */
|
|
|
|
+ private Integer createNum(Long hospId) {
|
|
|
|
+ ReportForm one = this.getOne(
|
|
|
|
+ new LambdaQueryWrapper<ReportForm>().select(ReportForm::getNum)
|
|
|
|
+ .eq(ReportForm::getHospId, hospId)
|
|
|
|
+ .orderByDesc(ReportForm::getNum).last(LIMIT_ONE)
|
|
|
|
+ );
|
|
|
|
+ if (Objects.isNull(one)) {
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+ return one.getNum() + 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新某个报表项目
|
|
|
|
+ *
|
|
|
|
+ * @param formEditDTO {@link ReportFormEditDTO}
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
|
+ public void updateReport(ReportFormEditDTO formEditDTO) {
|
|
|
|
+ Long id = formEditDTO.getId();
|
|
|
|
+ ReportForm byId = this.getById(id);
|
|
|
|
+ checkExist(byId,"选择的报表项目不存在");
|
|
|
|
+
|
|
|
|
+ BeanUtil.convertObj(formEditDTO, byId);
|
|
|
|
+
|
|
|
|
+ Long parentId = byId.getParentId();
|
|
|
|
+ // 根据是否父节点设置必要的数据
|
|
|
|
+ this.setDataByParentId(byId.getHospId(), byId, parentId);
|
|
|
|
+
|
|
|
|
+ this.updateById(byId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 抛出异常
|
|
|
|
+ * @param byId POJO类
|
|
|
|
+ * @param errorMsg 抛出信息
|
|
|
|
+ */
|
|
|
|
+ private void checkExist(ReportForm byId,String errorMsg) {
|
|
|
|
+ if (Objects.isNull(byId)) {
|
|
|
|
+ throw new CostException(errorMsg);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|