|
@@ -19,10 +19,7 @@ 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 com.imed.costaccount.service.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -31,6 +28,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static cn.hutool.core.date.DatePattern.PURE_DATE_PATTERN;
|
|
@@ -47,14 +45,18 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
|
|
|
|
|
|
private final ResponsibilityService responsibilityService;
|
|
|
|
|
|
+ private final IncomeCollectionService incomeCollectionService;
|
|
|
+
|
|
|
|
|
|
public ShareParamValueServiceImpl(CostIncomeGroupServiceImpl costIncomeGroupService,
|
|
|
CostShareParamService costShareParamService,
|
|
|
- CostIncomeFileService costIncomeFileService, ResponsibilityService responsibilityService) {
|
|
|
+ CostIncomeFileService costIncomeFileService,
|
|
|
+ ResponsibilityService responsibilityService, IncomeCollectionService incomeCollectionService) {
|
|
|
this.costIncomeGroupService = costIncomeGroupService;
|
|
|
this.costShareParamService = costShareParamService;
|
|
|
this.costIncomeFileService = costIncomeFileService;
|
|
|
this.responsibilityService = responsibilityService;
|
|
|
+ this.incomeCollectionService = incomeCollectionService;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -75,7 +77,7 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
|
|
|
throw new CostException("本月已存在对应责任中心和分摊参数中心,请直接修改");
|
|
|
}
|
|
|
// 校验两个code是否存在
|
|
|
- checkCodeIsExist(shareParamValueSaveDTO.getShareParamCode(), shareParamValueSaveDTO.getResponsibilityCode(),hospId);
|
|
|
+ checkCodeIsExist(shareParamValueSaveDTO.getShareParamCode(), shareParamValueSaveDTO.getResponsibilityCode(), hospId);
|
|
|
paramValue.setCreateTime(System.currentTimeMillis())
|
|
|
.setDateYear(DateUtil.year(dateTime))
|
|
|
.setDateMonth(DateUtil.month(dateTime) + 1)
|
|
@@ -86,11 +88,12 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
|
|
|
|
|
|
/**
|
|
|
* 校验两个code是否存在
|
|
|
- * @param shareParamCode
|
|
|
- * @param responsibilityCode
|
|
|
- * @param hospId
|
|
|
+ *
|
|
|
+ * @param shareParamCode 成本分摊参数code
|
|
|
+ * @param responsibilityCode 责任中心代码
|
|
|
+ * @param hospId 医院id
|
|
|
*/
|
|
|
- @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
|
|
|
+ @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));
|
|
@@ -123,10 +126,7 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
|
|
|
.eq(ShareParamValue::getDateYear, DateUtil.year(date))
|
|
|
.eq(ShareParamValue::getDateMonth, DateUtil.month(date) + 1)
|
|
|
);
|
|
|
- if (!list.isEmpty()) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
+ return !list.isEmpty();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -296,7 +296,7 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
|
|
|
i.setDataSourceType(1);
|
|
|
});
|
|
|
// 保存数据的唯一性
|
|
|
- Map<String, List<ShareParamValue>> map = shareParamValues.stream().collect(Collectors.groupingBy(k -> k.getShareParamCode().trim() + "code" + k.getResponsibilityCode().trim()+k.getDateYear().toString().trim()+"code"+k.getDateMonth().toString().trim()
|
|
|
+ Map<String, List<ShareParamValue>> map = shareParamValues.stream().collect(Collectors.groupingBy(k -> k.getShareParamCode().trim() + "code" + k.getResponsibilityCode().trim() + k.getDateYear().toString().trim() + "code" + k.getDateMonth().toString().trim()
|
|
|
));
|
|
|
LinkedList<ShareParamValue> realList = new LinkedList<>();
|
|
|
Set<String> strings = map.keySet();
|
|
@@ -356,7 +356,7 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
|
|
|
}
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(incomeErrorMessageList)) {
|
|
|
- incomeErrorMessageList=new ArrayList<>();
|
|
|
+ incomeErrorMessageList = new ArrayList<>();
|
|
|
// 检验数据是否全为0
|
|
|
int zeroStatus = 0;
|
|
|
for (int j = 2; j < data.size(); j++) {
|
|
@@ -414,4 +414,54 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 计算数值
|
|
|
+ *
|
|
|
+ * @param date 日期 yyyyMM
|
|
|
+ * @param hospId 医院id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
+ public void calcData(String date, Long hospId) {
|
|
|
+ DateTime parse = DateUtil.parse(date, PURE_DATE_PATTERN);
|
|
|
+ int year = DateUtil.year(parse);
|
|
|
+ int month = DateUtil.month(parse) + 1;
|
|
|
+ // 拿到这些年月的数据
|
|
|
+ List<ShareParamValue> list = this.list(
|
|
|
+ new LambdaQueryWrapper<ShareParamValue>()
|
|
|
+ .eq(ShareParamValue::getDateYear, year).eq(ShareParamValue::getDateMonth, month).eq(ShareParamValue::getHospId, hospId)
|
|
|
+ );
|
|
|
+ // 得到这些责任中心代码
|
|
|
+ List<String> responsibilityCodes = list.stream().map(ShareParamValue::getResponsibilityCode).distinct().collect(Collectors.toList());
|
|
|
+ List<IncomeCollection> incomeCollections = incomeCollectionService.list(
|
|
|
+ new LambdaQueryWrapper<IncomeCollection>()
|
|
|
+ .eq(IncomeCollection::getYear, year)
|
|
|
+ .eq(IncomeCollection::getMonth, month)
|
|
|
+ .eq(IncomeCollection::getHospId, hospId)
|
|
|
+ .in(IncomeCollection::getResponsibilityCode, responsibilityCodes)
|
|
|
+ );
|
|
|
+ if (incomeCollections.isEmpty()) {
|
|
|
+ throw new CostException("本月未归集数据,请先归集数据");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, List<IncomeCollection>> collectMap = incomeCollections.stream().collect(Collectors.groupingBy(IncomeCollection::getResponsibilityCode));
|
|
|
+ Set<String> strings = collectMap.keySet();
|
|
|
+ Map<String,BigDecimal> map = new ConcurrentHashMap<>();
|
|
|
+ for (String str : strings) {
|
|
|
+ List<IncomeCollection> collections = collectMap.get(str);
|
|
|
+ if (CollUtil.isNotEmpty(collections)) {
|
|
|
+ BigDecimal reduce = incomeCollections.stream().map(IncomeCollection::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ IncomeCollection incomeCollection = incomeCollections.get(0);
|
|
|
+ incomeCollection.setAmount(reduce);
|
|
|
+ map.put(str, reduce);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ list.forEach(i -> {
|
|
|
+ BigDecimal bigDecimal = map.get(i);
|
|
|
+ if (Objects.nonNull(bigDecimal)) {
|
|
|
+ i.setValueNum(bigDecimal);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.updateBatchById(list);
|
|
|
+ }
|
|
|
}
|