|
@@ -1,23 +1,30 @@
|
|
|
package com.imed.costaccount.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.druid.util.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.imed.costaccount.common.exception.CostException;
|
|
|
-import com.imed.costaccount.common.util.BeanUtil;
|
|
|
-import com.imed.costaccount.common.util.DateUtils;
|
|
|
-import com.imed.costaccount.common.util.Result;
|
|
|
-import com.imed.costaccount.common.util.UserContext;
|
|
|
+import com.imed.costaccount.common.util.*;
|
|
|
import com.imed.costaccount.constants.NumberConstant;
|
|
|
import com.imed.costaccount.enums.DateStyleEnum;
|
|
|
import com.imed.costaccount.mapper.ShareParamValueMapper;
|
|
|
import com.imed.costaccount.model.*;
|
|
|
+import com.imed.costaccount.model.dto.CopyShareParamValueDTO;
|
|
|
+import com.imed.costaccount.model.dto.ShareParamValueEditDTO;
|
|
|
+import com.imed.costaccount.model.dto.ShareParamValueSaveDTO;
|
|
|
+import com.imed.costaccount.model.dto.ShareParamValueVO;
|
|
|
import com.imed.costaccount.model.vo.IncomeErrorMessage;
|
|
|
import com.imed.costaccount.service.CostIncomeFileService;
|
|
|
import com.imed.costaccount.service.CostShareParamService;
|
|
|
+import com.imed.costaccount.service.ResponsibilityService;
|
|
|
import com.imed.costaccount.service.ShareParamValueService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
@@ -29,6 +36,8 @@ import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static cn.hutool.core.date.DatePattern.PURE_DATE_PATTERN;
|
|
|
+
|
|
|
|
|
|
@Service("shareParamValueService")
|
|
|
public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMapper, ShareParamValue> implements ShareParamValueService {
|
|
@@ -39,15 +48,192 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
|
|
|
|
|
|
private final CostIncomeFileService costIncomeFileService;
|
|
|
|
|
|
+ private final ResponsibilityService responsibilityService;
|
|
|
+
|
|
|
|
|
|
public ShareParamValueServiceImpl(CostIncomeGroupServiceImpl costIncomeGroupService,
|
|
|
CostShareParamService costShareParamService,
|
|
|
- CostIncomeFileService costIncomeFileService) {
|
|
|
+ CostIncomeFileService costIncomeFileService, ResponsibilityService responsibilityService) {
|
|
|
this.costIncomeGroupService = costIncomeGroupService;
|
|
|
this.costShareParamService = costShareParamService;
|
|
|
this.costIncomeFileService = costIncomeFileService;
|
|
|
+ this.responsibilityService = responsibilityService;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加分摊参数值
|
|
|
+ *
|
|
|
+ * @param shareParamValueSaveDTO {@link ShareParamValueSaveDTO}
|
|
|
+ * @param hospId 医院id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
+ public void addData(ShareParamValueSaveDTO shareParamValueSaveDTO, Long hospId) {
|
|
|
+ ShareParamValue paramValue = BeanUtil.convertObj(shareParamValueSaveDTO, ShareParamValue.class);
|
|
|
+ DateTime dateTime = DateUtil.parse(shareParamValueSaveDTO.getDate(), PURE_DATE_PATTERN);
|
|
|
+ // 校验是否唯一
|
|
|
+ Boolean flag = checkUniq(shareParamValueSaveDTO.getShareParamCode(), shareParamValueSaveDTO.getResponsibilityCode(), hospId, dateTime);
|
|
|
+ if (flag) {
|
|
|
+ throw new CostException("本月已存在对应责任中心和分摊参数中心,请直接修改");
|
|
|
+ }
|
|
|
+ // 校验两个code是否存在
|
|
|
+ checkCodeIsExist(shareParamValueSaveDTO.getShareParamCode(), shareParamValueSaveDTO.getResponsibilityCode(),hospId);
|
|
|
+ paramValue.setCreateTime(System.currentTimeMillis())
|
|
|
+ .setDateYear(DateUtil.year(dateTime))
|
|
|
+ .setDateMonth(DateUtil.month(dateTime) + 1)
|
|
|
+ .setHospId(hospId)
|
|
|
+ .setDataSourceType(0);
|
|
|
+ this.save(paramValue);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 校验两个code是否存在
|
|
|
+ * @param shareParamCode
|
|
|
+ * @param responsibilityCode
|
|
|
+ * @param hospId
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
|
|
|
+ public void checkCodeIsExist(String shareParamCode, String responsibilityCode, Long hospId) {
|
|
|
+ List<CostShareParam> shareParams = costShareParamService.list(new LambdaQueryWrapper<CostShareParam>().select(CostShareParam::getId)
|
|
|
+ .eq(CostShareParam::getShareParamCode, shareParamCode).eq(CostShareParam::getHospId, hospId));
|
|
|
+ if (shareParams.isEmpty()) {
|
|
|
+ throw new CostException("分摊参数code非法");
|
|
|
+ }
|
|
|
+ List<Responsibility> responsibilities = responsibilityService.list(
|
|
|
+ new LambdaQueryWrapper<Responsibility>().select(Responsibility::getId)
|
|
|
+ .eq(Responsibility::getResponsibilityCode, responsibilityCode).eq(Responsibility::getHospId, hospId)
|
|
|
+ );
|
|
|
+ if (responsibilities.isEmpty()) {
|
|
|
+ throw new CostException("责任中心code非法");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验是否已存在
|
|
|
+ *
|
|
|
+ * @param shareParamCode 分摊参数代码
|
|
|
+ * @param responsibilityCode 责任中心代码
|
|
|
+ * @param hospId 医院id
|
|
|
+ * @param date 时间
|
|
|
+ */
|
|
|
+ private Boolean checkUniq(String shareParamCode, String responsibilityCode, Long hospId, DateTime date) {
|
|
|
+ List<ShareParamValue> list = this.list(
|
|
|
+ new LambdaQueryWrapper<ShareParamValue>()
|
|
|
+ .eq(ShareParamValue::getHospId, hospId)
|
|
|
+ .eq(ShareParamValue::getShareParamCode, shareParamCode)
|
|
|
+ .eq(ShareParamValue::getResponsibilityCode, responsibilityCode)
|
|
|
+ .eq(ShareParamValue::getDateYear, DateUtil.year(date))
|
|
|
+ .eq(ShareParamValue::getDateMonth, DateUtil.month(date) + 1)
|
|
|
+ );
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分摊参数值列表
|
|
|
+ *
|
|
|
+ * @param current 当前页
|
|
|
+ * @param pageSize 每页数据量大小
|
|
|
+ * @param date 日期
|
|
|
+ * @param shareParamCode 分摊参数代码
|
|
|
+ * @param responsibilityCode 责任中心代码
|
|
|
+ * @param hospId 医院id
|
|
|
+ * @return {@link PageUtils} 分页对象
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PageUtils selectList(Integer current, Integer pageSize, String date, String shareParamCode, String responsibilityCode, Long hospId) {
|
|
|
+ Integer startIndex = (current - 1) * pageSize;
|
|
|
+ if (startIndex < 0) {
|
|
|
+ startIndex = 0;
|
|
|
+ }
|
|
|
+ List<ShareParamValueVO> list = baseMapper.getValues(startIndex, pageSize, date, shareParamCode, responsibilityCode, hospId);
|
|
|
+ int count = baseMapper.getValuesCount(startIndex, pageSize, date, shareParamCode, responsibilityCode, hospId);
|
|
|
+ return new PageUtils(list, count, pageSize, current);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 复制数据从某年月到某年月
|
|
|
+ *
|
|
|
+ * @param copyShareParamValueDTO {@link CopyShareParamValueDTO}
|
|
|
+ * @param hospId 医院id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
+ public void copyData(CopyShareParamValueDTO copyShareParamValueDTO, Long hospId) {
|
|
|
+ // 复制数据 多个医院同时使用的情况下启用线程池处理
|
|
|
+ String fromDate = copyShareParamValueDTO.getFromDate();
|
|
|
+ String toDate = copyShareParamValueDTO.getToDate();
|
|
|
+ Integer dataSourceType = copyShareParamValueDTO.getDataSourceType();
|
|
|
+
|
|
|
+ LambdaQueryWrapper<ShareParamValue> wrapper = new LambdaQueryWrapper<ShareParamValue>()
|
|
|
+ .eq(ShareParamValue::getDateYear, DateUtil.year(DateUtil.parse(fromDate, PURE_DATE_PATTERN)))
|
|
|
+ .eq(ShareParamValue::getDateMonth, DateUtil.month(DateUtil.parse(fromDate, PURE_DATE_PATTERN)) + 1);
|
|
|
+ if (dataSourceType == 0) {
|
|
|
+ wrapper.eq(ShareParamValue::getDataSourceType, 0);
|
|
|
+ } else if (dataSourceType == 1) {
|
|
|
+ wrapper.eq(ShareParamValue::getDataSourceType, 1);
|
|
|
+ } else {
|
|
|
+ wrapper.in(ShareParamValue::getDataSourceType, CollUtil.newArrayList(0, 1));
|
|
|
+ }
|
|
|
+ // 拿到复制的数据
|
|
|
+ List<ShareParamValue> list = this.list(wrapper);
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ throw new CostException("复制日期" + fromDate + "数据不存在");
|
|
|
+ }
|
|
|
+ DateTime toDateTime = DateUtil.parse(toDate, PURE_DATE_PATTERN);
|
|
|
+ int year = DateUtil.year(toDateTime);
|
|
|
+ int month = DateUtil.month(toDateTime) + 1;
|
|
|
+ // 删除之前的数据
|
|
|
+ wrapper.clear();
|
|
|
+ this.remove(
|
|
|
+ wrapper.eq(ShareParamValue::getDateYear, year)
|
|
|
+ .eq(ShareParamValue::getDateMonth, month)
|
|
|
+ .eq(ShareParamValue::getHospId, hospId)
|
|
|
+ );
|
|
|
+ list.forEach(i -> {
|
|
|
+ i.setId(null);
|
|
|
+ i.setCreateTime(System.currentTimeMillis());
|
|
|
+ i.setHospId(hospId);
|
|
|
+ i.setDateYear(year);
|
|
|
+ i.setDateMonth(month);
|
|
|
+ });
|
|
|
+ this.saveBatch(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑某条数据
|
|
|
+ *
|
|
|
+ * @param shareParamValueEditDTO {@link ShareParamValueEditDTO}
|
|
|
+ * @param hospId 医院id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
|
|
|
+ public void editParamValue(ShareParamValueEditDTO shareParamValueEditDTO, Long hospId) {
|
|
|
+ Long id = shareParamValueEditDTO.getId();
|
|
|
+ this.removeById(id);
|
|
|
+
|
|
|
+ DateTime dateTime = DateUtil.parse(shareParamValueEditDTO.getDate(), PURE_DATE_PATTERN);
|
|
|
+
|
|
|
+ Boolean flag = checkUniq(shareParamValueEditDTO.getShareParamCode(), shareParamValueEditDTO.getResponsibilityCode(), hospId, dateTime);
|
|
|
+ if (flag) {
|
|
|
+ throw new CostException("本月已存在对应责任中心和分摊参数中心,请直接修改");
|
|
|
+ }
|
|
|
+ checkCodeIsExist(shareParamValueEditDTO.getShareParamCode(), shareParamValueEditDTO.getResponsibilityCode(), hospId);
|
|
|
+
|
|
|
+ ShareParamValue shareParamValue = BeanUtil.convertObj(shareParamValueEditDTO, ShareParamValue.class);
|
|
|
+ shareParamValue
|
|
|
+ .setId(null)
|
|
|
+ .setCreateTime(System.currentTimeMillis())
|
|
|
+ .setDateYear(DateUtil.year(DateUtil.parse(shareParamValueEditDTO.getDate(), PURE_DATE_PATTERN)))
|
|
|
+ .setDateMonth(DateUtil.month(DateUtil.parse(shareParamValueEditDTO.getDate(), PURE_DATE_PATTERN)) + 1)
|
|
|
+ .setHospId(hospId)
|
|
|
+ .setDataSourceType(0);
|
|
|
+
|
|
|
+ this.save(shareParamValue);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 成本分摊参数导入
|
|
@@ -215,7 +401,7 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
|
|
|
incomeErrorMessage.setErrMessage("第" + j + "列科室信息不存在");
|
|
|
incomeErrorMessageList.add(incomeErrorMessage);
|
|
|
}
|
|
|
- shareParamValue.setValueNum(new BigDecimal(("0".equals(data.get(j).toString()) || StrUtil.isBlank(data.get(j).toString())) ? "0.00" : data.get(j).toString()));
|
|
|
+ shareParamValue.setValueNum(BigDecimal.valueOf(Double.parseDouble(("0".equals(data.get(j).toString()) || StrUtil.isBlank(data.get(j).toString())) ? "0.00" : data.get(j).toString())));
|
|
|
shareParamValue.setHospId(UserContext.getHospId());
|
|
|
shareParamValue.setCreateTime(System.currentTimeMillis());
|
|
|
shareParamValue.setDateYear(year);
|