|
@@ -21,7 +21,6 @@ import com.imed.costaccount.model.vo.*;
|
|
|
import com.imed.costaccount.service.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
-import org.apache.xmlbeans.impl.xb.xsdschema.All;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -80,12 +79,7 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
}
|
|
|
Map<String, List<ShareParamValue>> paramValueRespCodeMap = shareParamValues.stream().collect(Collectors.groupingBy(ShareParamValue::getResponsibilityCode));
|
|
|
// 删除该年月已经分摊过的数据
|
|
|
- this.remove(
|
|
|
- new LambdaQueryWrapper<Allocation>()
|
|
|
- .eq(Allocation::getDateYear, startDTO.getYear())
|
|
|
- .eq(Allocation::getDateMonth, startDTO.getMonth())
|
|
|
- .eq(Allocation::getHospId, hospId)
|
|
|
- );
|
|
|
+ removeData(startDTO, hospId);
|
|
|
// 得到这个医院所有的分摊层级列表排序
|
|
|
List<CostShareLevelVO> shareLevelVOs = shareLevelService.getAll(hospId);
|
|
|
if (CollUtil.isEmpty(shareLevelVOs)) {
|
|
@@ -206,7 +200,22 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
this.saveAllocationQuery(list, costingGroups, hospId);
|
|
|
}
|
|
|
|
|
|
- @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Throwable.class)
|
|
|
+ private void removeData(StartDTO startDTO, Long hospId) {
|
|
|
+ this.remove(
|
|
|
+ new LambdaQueryWrapper<Allocation>()
|
|
|
+ .eq(Allocation::getDateYear, startDTO.getYear())
|
|
|
+ .eq(Allocation::getDateMonth, startDTO.getMonth())
|
|
|
+ .eq(Allocation::getHospId, hospId)
|
|
|
+ );
|
|
|
+ allocationQueryService.remove(
|
|
|
+ new LambdaQueryWrapper<AllocationQuery>()
|
|
|
+ .eq(AllocationQuery::getDateYear, startDTO.getYear())
|
|
|
+ .eq(AllocationQuery::getDateMonth, startDTO.getMonth())
|
|
|
+ .eq(AllocationQuery::getHospId, hospId)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
public void saveAllocationQuery(List<Allocation> list, List<CostCostingGroup> costingGroups, Long hospId) {
|
|
|
List<AllocationQuery> saveList = new ArrayList<>();
|
|
|
list.forEach(i -> {
|
|
@@ -370,7 +379,6 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 分摊报表导出
|
|
|
*
|
|
@@ -388,8 +396,8 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
// 设置导出
|
|
|
Map<String, List<AllocationReportVO>> responsibilityMap = allocationReportVOList.stream().collect(Collectors.groupingBy(AllocationReportVO::getResponsibilityCode));
|
|
|
Map<String, List<AllocationReportVO>> targetResponsibilityMap = allocationReportVOList.stream().collect(Collectors.groupingBy(AllocationReportVO::getTargetResponsibilityCode));
|
|
|
- Map<String, AllocationReportVO> allAccMap = allocationReportVOList.stream().collect(Collectors.toMap(k -> k.getResponsibilityName()+k.getAccountName()+k.getTargetResponsibilityName()+k.getShareParamName(), synOne -> synOne));
|
|
|
- Map<String, AllocationReportVO> allAliMap = allocationReportVOList.stream().collect(Collectors.toMap(k -> k.getResponsibilityName()+k.getAlias()+k.getTargetResponsibilityName()+k.getShareParamName(), synOne -> synOne));
|
|
|
+ Map<String, AllocationReportVO> allAccMap = allocationReportVOList.stream().collect(Collectors.toMap(k -> k.getResponsibilityName() + k.getAccountName() + k.getTargetResponsibilityName() + k.getShareParamName(), synOne -> synOne));
|
|
|
+ Map<String, AllocationReportVO> allAliMap = allocationReportVOList.stream().collect(Collectors.toMap(k -> k.getResponsibilityName() + k.getAlias() + k.getTargetResponsibilityName() + k.getShareParamName(), synOne -> synOne));
|
|
|
// 当前责任中心下面有几个会计科目 后面进行合并使用
|
|
|
int numResponsibility;
|
|
|
// // 从第几列开始编写数据
|
|
@@ -410,23 +418,23 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
for (String s : strings) {
|
|
|
AllocationReportVO allocationReportVO = linkedHashMap.get(s);
|
|
|
if (StrUtil.isBlank(allocationReportVO.getAlias())) {
|
|
|
- writer.writeCellValue(column,0,allocationReportVO.getResponsibilityName());
|
|
|
+ writer.writeCellValue(column, 0, allocationReportVO.getResponsibilityName());
|
|
|
// 别名不存在
|
|
|
writer.writeCellValue(column, 1, allocationReportVO.getAccountName());
|
|
|
} else {
|
|
|
// 不为空 设置别名
|
|
|
- writer.writeCellValue(column,0,allocationReportVO.getResponsibilityName());
|
|
|
+ writer.writeCellValue(column, 0, allocationReportVO.getResponsibilityName());
|
|
|
writer.writeCellValue(column, 1, allocationReportVO.getAlias());
|
|
|
}
|
|
|
writer.writeCellValue(column, 2, allocationReportVO.getTotalAmounts());
|
|
|
column++;
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
// 不需要合并单元格
|
|
|
writer.writeCellValue(column, 0, allocationReportVOS.get(0).getResponsibilityName());
|
|
|
- if (StrUtil.isNotBlank(allocationReportVOS.get(0).getAlias())){
|
|
|
+ if (StrUtil.isNotBlank(allocationReportVOS.get(0).getAlias())) {
|
|
|
writer.writeCellValue(column, 1, allocationReportVOS.get(0).getAlias());
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
writer.writeCellValue(column, 1, allocationReportVOS.get(0).getAccountName());
|
|
|
}
|
|
|
writer.writeCellValue(column, 2, allocationReportVOS.get(0).getTotalAmounts());
|
|
@@ -456,18 +464,18 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
// 责任中心
|
|
|
AllocationReportVO costCostingVO = allocationReportVOS.get(0);
|
|
|
// 设置第几次分摊的值
|
|
|
- for (int k = 0; k < levelSort-1; k++) {
|
|
|
+ for (int k = 0; k < levelSort - 1; k++) {
|
|
|
writer.merge(num, num + shareParamSize - 1, k + 1, k + 1, costCostingVO.getTargetShareMoneys().get(k), false);
|
|
|
}
|
|
|
// 设置对应的分摊参数值
|
|
|
Set<String> strings = linkedHashMap.keySet();
|
|
|
for (String s : strings) {
|
|
|
AllocationReportVO allocationReportVO = linkedHashMap.get(s);
|
|
|
- writer.writeCellValue(0,num,allocationReportVO.getTargetResponsibilityName());
|
|
|
+ writer.writeCellValue(0, num, allocationReportVO.getTargetResponsibilityName());
|
|
|
writer.writeCellValue(levelSort, num, allocationReportVO.getShareParamName());
|
|
|
- writer.writeCellValue(levelSort +1, num, allocationReportVO.getShareParamValueNums());
|
|
|
+ writer.writeCellValue(levelSort + 1, num, allocationReportVO.getShareParamValueNums());
|
|
|
writer.writeCellValue(levelSort + 2, num, allocationReportVO.getShareParamRates());
|
|
|
- for (int m=levelSort+3;m<column;m++){
|
|
|
+ for (int m = levelSort + 3; m < column; m++) {
|
|
|
// x是m y是num
|
|
|
// 获取当前这一列对应的责任中心 以及会计科目
|
|
|
// 第一行责任中心
|
|
@@ -478,17 +486,17 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
String otherResponsibilityName = sheet.getRow(num).getCell(0).getStringCellValue();
|
|
|
// 分摊参数
|
|
|
String shareName = sheet.getRow(num).getCell(levelSort).getStringCellValue();
|
|
|
- String sss= responsibilityName + accountNameOrAlias + otherResponsibilityName + shareName;
|
|
|
+ String sss = responsibilityName + accountNameOrAlias + otherResponsibilityName + shareName;
|
|
|
AllocationReportVO vo = allAliMap.get(sss);
|
|
|
AllocationReportVO allocationReportVO2 = allAccMap.get(responsibilityName + accountNameOrAlias + otherResponsibilityName + shareName);
|
|
|
AllocationReportVO allocationReportVO3 = allAliMap.get(responsibilityName + accountNameOrAlias + otherResponsibilityName + shareName);
|
|
|
|
|
|
- if (Objects.nonNull(allocationReportVO2)){
|
|
|
- writer.writeCellValue(m,num,allocationReportVO2.getAmounts());
|
|
|
- }else if (Objects.nonNull(allocationReportVO3)){
|
|
|
- writer.writeCellValue(m,num,allocationReportVO3.getAmounts());
|
|
|
- }else {
|
|
|
- writer.writeCellValue(m,num,0);
|
|
|
+ if (Objects.nonNull(allocationReportVO2)) {
|
|
|
+ writer.writeCellValue(m, num, allocationReportVO2.getAmounts());
|
|
|
+ } else if (Objects.nonNull(allocationReportVO3)) {
|
|
|
+ writer.writeCellValue(m, num, allocationReportVO3.getAmounts());
|
|
|
+ } else {
|
|
|
+ writer.writeCellValue(m, num, 0);
|
|
|
}
|
|
|
}
|
|
|
num++;
|
|
@@ -496,13 +504,13 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
}
|
|
|
if (shareParamSize < NumberConstant.TWO) {
|
|
|
writer.writeCellValue(0, num, allocationReportVOS.get(0).getTargetResponsibilityName());
|
|
|
- for (int k = 0; k < levelSort-1; k++) {
|
|
|
+ for (int k = 0; k < levelSort - 1; k++) {
|
|
|
writer.writeCellValue(k + 1, num, allocationReportVOS.get(0).getTargetShareMoneys().get(k));
|
|
|
}
|
|
|
- writer.writeCellValue(levelSort , num, allocationReportVOS.get(0).getShareParamName());
|
|
|
+ writer.writeCellValue(levelSort, num, allocationReportVOS.get(0).getShareParamName());
|
|
|
writer.writeCellValue(levelSort + 1, num, allocationReportVOS.get(0).getShareParamValueNums());
|
|
|
writer.writeCellValue(levelSort + 2, num, allocationReportVOS.get(0).getShareParamRates());
|
|
|
- for (int m=levelSort+4;m<column;m++){
|
|
|
+ for (int m = levelSort + 4; m < column; m++) {
|
|
|
// x是m y是num
|
|
|
// 获取当前这一列对应的责任中心 以及会计科目
|
|
|
// 第一行责任中心
|
|
@@ -515,12 +523,12 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
String shareName = sheet.getRow(num).getCell(levelSort).getStringCellValue();
|
|
|
AllocationReportVO allocationReportVO2 = allAccMap.get(responsibilityName + accountNameOrAlias + otherResponsibilityName + shareName);
|
|
|
AllocationReportVO allocationReportVO3 = allAliMap.get(responsibilityName + accountNameOrAlias + otherResponsibilityName + shareName);
|
|
|
- if (Objects.nonNull(allocationReportVO2)){
|
|
|
- writer.writeCellValue(m,num,allocationReportVO2.getAmounts());
|
|
|
- }else if (Objects.nonNull(allocationReportVO3)){
|
|
|
- writer.writeCellValue(m,num,allocationReportVO3.getAmounts());
|
|
|
- }else {
|
|
|
- writer.writeCellValue(m,num,0);
|
|
|
+ if (Objects.nonNull(allocationReportVO2)) {
|
|
|
+ writer.writeCellValue(m, num, allocationReportVO2.getAmounts());
|
|
|
+ } else if (Objects.nonNull(allocationReportVO3)) {
|
|
|
+ writer.writeCellValue(m, num, allocationReportVO3.getAmounts());
|
|
|
+ } else {
|
|
|
+ writer.writeCellValue(m, num, 0);
|
|
|
}
|
|
|
}
|
|
|
num++;
|
|
@@ -537,6 +545,7 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
|
|
|
/**
|
|
|
* 查询数据
|
|
|
+ *
|
|
|
* @param levelSort
|
|
|
* @param year
|
|
|
* @param month
|
|
@@ -579,7 +588,7 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
money.updateAndGet(v -> v.add(m.getAmount()));
|
|
|
shareMoney.add(month.toString());
|
|
|
});
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
// TODO 封装测试数据
|
|
|
shareMoney.add("1000");
|
|
|
}
|
|
@@ -601,10 +610,78 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
*
|
|
|
* @param year 年月(yyyy-MM-dd)
|
|
|
* @param responsibilityCode 责任中心代码
|
|
|
+ * @param hospId 医院id
|
|
|
* @return List
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<CollectDataFormVO> queryAfterAllocationForm(String year, String responsibilityCode) {
|
|
|
- return null;
|
|
|
+ public CollectDataFormVO queryAfterAllocationForm(String year, String responsibilityCode, Long hospId) {
|
|
|
+ DateTime dateTime = DateUtil.parseDate(year);
|
|
|
+ int dateYear = DateUtil.year(dateTime);
|
|
|
+ int month = DateUtil.month(dateTime) + 1;
|
|
|
+ List<CodeAndNameVO> responsibilityCodeAndNames = allocationQueryService.getRespCodeAndName(hospId, dateYear, month);
|
|
|
+ List<CodeAndNameVO> accountCodeAndNames = allocationQueryService.getAccountCodeAndName(hospId, dateYear, month);
|
|
|
+ // todo 校验两个List是否为空
|
|
|
+ // 填充
|
|
|
+ responsibilityCodeAndNames.add(0, new CodeAndNameVO("#", "#"));
|
|
|
+ responsibilityCodeAndNames.add(responsibilityCodeAndNames.size(), new CodeAndNameVO("合计", "合计"));
|
|
|
+
|
|
|
+ List<String> titleData = responsibilityCodeAndNames.stream().map(CodeAndNameVO::getName).collect(Collectors.toList());
|
|
|
+ List<String> respCodes = responsibilityCodeAndNames.stream().map(CodeAndNameVO::getCode).collect(Collectors.toList());
|
|
|
+ Map<Integer, String> titleMap = new HashMap<>();
|
|
|
+ for (int i = 0; i < titleData.size(); i++) {
|
|
|
+ titleMap.put(i + 1, titleData.get(i));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<Integer, Object>> realDatas = new ArrayList<>();
|
|
|
+ List<String> accountCodes = accountCodeAndNames.stream().map(CodeAndNameVO::getCode).collect(Collectors.toList());
|
|
|
+ for (CodeAndNameVO account : accountCodeAndNames) {
|
|
|
+ Map<Integer, Object> map = new HashMap<>();
|
|
|
+ for (int i = 0; i < responsibilityCodeAndNames.size(); i++) {
|
|
|
+ if (i == 0) {
|
|
|
+ map.put(i + 1, account.getName());
|
|
|
+ continue;
|
|
|
+ } else if (i == responsibilityCodeAndNames.size() - 1) {
|
|
|
+ // todo 计算最右侧合计的钱
|
|
|
+ BigDecimal amount = allocationQueryService.getTotalByAccountAndResps(hospId, dateYear, month, account.getCode(), respCodes);
|
|
|
+ map.put(i + 1, amount);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // TODO: 2021/8/26 计算 中间的钱
|
|
|
+ BigDecimal amount = allocationQueryService.getTotalByAccountAndRespCode(hospId, dateYear, month, account.getCode(), respCodes.get(i));
|
|
|
+ map.put(i + 1, amount);
|
|
|
+
|
|
|
+ }
|
|
|
+ realDatas.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 尾栏计算
|
|
|
+ Map<Integer, Object> map = new HashMap<>();
|
|
|
+ for (int i = 0; i < titleData.size(); i++) {
|
|
|
+ if (i == 0) {
|
|
|
+ map.put(i + 1, "合计");
|
|
|
+ continue;
|
|
|
+ } else if (i == titleData.size() - 1) {
|
|
|
+ // TODO: 2021/8/26 计算
|
|
|
+ BigDecimal bigDecimal = allocationQueryService.getTotalMoney(dateYear, month, hospId);
|
|
|
+ map.put(i + 1, bigDecimal);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ BigDecimal bigDecimal = allocationQueryService.getCountByRespAndAccounts(hospId, dateYear, month, responsibilityCodeAndNames.get(i).getCode(), accountCodes);
|
|
|
+ map.put(i + 1, bigDecimal);
|
|
|
+ }
|
|
|
+ return new CollectDataFormVO(titleMap, realDatas, map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 这年月的数据
|
|
|
+ */
|
|
|
+ private List<AllocationQuery> getAllocationQueriesByYear(Long hospId, int dateYear, int month) {
|
|
|
+ List<AllocationQuery> list = allocationQueryService.list(
|
|
|
+ new LambdaQueryWrapper<AllocationQuery>()
|
|
|
+ .eq(AllocationQuery::getDateYear, dateYear)
|
|
|
+ .eq(AllocationQuery::getDateMonth, month)
|
|
|
+ .eq(AllocationQuery::getHospId, hospId)
|
|
|
+ );
|
|
|
+ return list;
|
|
|
}
|
|
|
}
|