|
@@ -1,23 +1,23 @@
|
|
|
package com.imed.costaccount.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
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.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.CostCostingGroupMapper;
|
|
|
import com.imed.costaccount.model.*;
|
|
|
+import com.imed.costaccount.model.dto.StartDTO;
|
|
|
+import com.imed.costaccount.model.vo.AllocationVO;
|
|
|
+import com.imed.costaccount.model.vo.CostingGroupStartVO;
|
|
|
import com.imed.costaccount.model.vo.IncomeErrorMessage;
|
|
|
-import com.imed.costaccount.service.AccountingProductService;
|
|
|
-import com.imed.costaccount.service.CostCostingGroupService;
|
|
|
-import com.imed.costaccount.service.CostIncomeFileService;
|
|
|
+import com.imed.costaccount.service.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
@@ -39,13 +39,107 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
|
|
|
|
|
|
private final CostIncomeFileService costIncomeFileService;
|
|
|
|
|
|
- public CostCostingGroupServiceImpl(CostIncomeGroupServiceImpl costIncomeGroupService, AccountingProductService accountingProductService, CostIncomeFileService costIncomeFileService) {
|
|
|
+ private final ResponsibilityService responsibilityService;
|
|
|
+
|
|
|
+ private final CostCostingCollectionService costingCollectionService;
|
|
|
+
|
|
|
+ public CostCostingGroupServiceImpl(CostIncomeGroupServiceImpl costIncomeGroupService,
|
|
|
+ AccountingProductService accountingProductService,
|
|
|
+ CostIncomeFileService costIncomeFileService,
|
|
|
+ ResponsibilityService responsibilityService,
|
|
|
+ CostCostingCollectionService costingCollectionService) {
|
|
|
this.costIncomeGroupService = costIncomeGroupService;
|
|
|
this.accountingProductService = accountingProductService;
|
|
|
this.costIncomeFileService = costIncomeFileService;
|
|
|
+ this.responsibilityService = responsibilityService;
|
|
|
+ this.costingCollectionService = costingCollectionService;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分摊前查询
|
|
|
+ *
|
|
|
+ * @param current 当前页
|
|
|
+ * @param pageSize 每页数据大小
|
|
|
+ * @param responsibilityCode 责任中心代码
|
|
|
+ * @param accountCode 会计中心代码
|
|
|
+ * @param date 日期 yyyy-MM-dd
|
|
|
+ * @param hospId 医院id
|
|
|
+ * @return 分摊前查询列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PageUtils queryStartAllocation(Integer current, Integer pageSize, String responsibilityCode, String accountCode, String date, Long hospId) {
|
|
|
+ Integer startIndex = (current - 1) * pageSize;
|
|
|
+ DateTime dateTime = DateUtil.parseDate(date);
|
|
|
+ Integer year = DateUtil.year(dateTime);
|
|
|
+ Integer month = DateUtil.month(dateTime) + 1;
|
|
|
+ List<CostingGroupStartVO> list = baseMapper.queryStartAllocation(startIndex, pageSize, responsibilityCode, accountCode, year, month, hospId);
|
|
|
+ int count = baseMapper.queryStartAllocationCount(responsibilityCode, accountCode, year, month, hospId);
|
|
|
+ BigDecimal totalAmount = baseMapper.queryStartAllocationTotalAmount(responsibilityCode, accountCode, year, month, hospId);
|
|
|
+
|
|
|
+ return new PageUtils(list, count, pageSize, current, totalAmount);
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 成本分摊列表
|
|
|
+ *
|
|
|
+ * @param current 当前页
|
|
|
+ * @param pageSize 每页数据大小
|
|
|
+ * @param date 日期 这里是 yyyy-MM-dd
|
|
|
+ * @param hospId
|
|
|
+ * @return 分页对象
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PageUtils queryAllocation(Integer current, Integer pageSize, String date, Long hospId) {
|
|
|
+ Integer year = null;
|
|
|
+ Integer month = null;
|
|
|
+ if (StrUtil.isNotBlank(date)) {
|
|
|
+ DateTime dateTime = DateUtil.parseDate(date);
|
|
|
+ year = DateUtil.year(dateTime);
|
|
|
+ month = DateUtil.month(dateTime) + 1;
|
|
|
+ }
|
|
|
+ Integer startIndex = (current - 1) * pageSize;
|
|
|
+
|
|
|
+ List<AllocationVO> list = baseMapper.queryAllocation(startIndex, pageSize, year, month, hospId);
|
|
|
+ list.forEach(i -> {
|
|
|
+ List<CostCostingCollection> collections = costingCollectionService.list(new LambdaQueryWrapper<CostCostingCollection>().eq(CostCostingCollection::getYear, i.getYear())
|
|
|
+ .eq(CostCostingCollection::getMonth, i.getMonth())
|
|
|
+ .eq(CostCostingCollection::getHospId, hospId)
|
|
|
+ );
|
|
|
+ if (!collections.isEmpty()) {
|
|
|
+ i.setIsAllocation(true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ int count = baseMapper.queryAllocationCount(year, month, hospId);
|
|
|
+ return new PageUtils(list, count, pageSize, current);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开始归集代码
|
|
|
+ *
|
|
|
+ * @param startDTO {@link StartDTO}
|
|
|
+ * @param hospId 医院id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
+ public void startAllocation(StartDTO startDTO, Long hospId) {
|
|
|
+// // 先拿到这个月数据 如果数据量很大 优化处理
|
|
|
+// List<CostCostingGroup> list = this.list(
|
|
|
+// new LambdaQueryWrapper<CostCostingGroup>()
|
|
|
+// .eq(CostCostingGroup::getDateYear, startDTO.getYear())
|
|
|
+// .eq(CostCostingGroup::getDateMonth, startDTO.getMonth())
|
|
|
+// .eq(CostCostingGroup::getHospId, hospId)
|
|
|
+// );
|
|
|
+//
|
|
|
+// // 删除该年月已经归集过的数据
|
|
|
+// costingCollectionService.remove(
|
|
|
+// new LambdaQueryWrapper<CostCostingCollection>()
|
|
|
+// .eq(CostCostingCollection::getYear, startDTO.getYear())
|
|
|
+// .eq(CostCostingCollection::getMonth, startDTO.getMonth())
|
|
|
+// .eq(CostCostingCollection::getHospId, hospId)
|
|
|
+// );
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 批量导入成本数据
|
|
|
*
|
|
@@ -139,6 +233,9 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
|
|
|
return Result.build(200, "数据未成功导入", null);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 检验成本数据
|
|
|
*
|
|
@@ -157,27 +254,28 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
|
|
|
List<Object> departmentNames = list.get(1);
|
|
|
//检验数据是否准确
|
|
|
for (int i = 2; i < list.size(); i++) {
|
|
|
- int row=i+5;
|
|
|
+ int row = i + 5;
|
|
|
List<Object> data = list.get(i);
|
|
|
for (int j = 2; j < departmentCodes.size(); j++) {
|
|
|
- int column=j+1;
|
|
|
- if (data.size() > j ) {
|
|
|
- if (Objects.isNull(data.get(j))){
|
|
|
+ int column = j + 1;
|
|
|
+ if (data.size() > j) {
|
|
|
+ if (Objects.isNull(data.get(j))) {
|
|
|
data.set(j, NumberConstant.ZERO);
|
|
|
- }else if ( data.get(j).toString().contains("-") || !StringUtils.isNumber(data.get(j).toString())){
|
|
|
+ } else if (data.get(j).toString().contains("-") || !StringUtils.isNumber(data.get(j).toString())) {
|
|
|
IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
|
|
|
incomeErrorMessage.setTotal(row);
|
|
|
- incomeErrorMessage.setErrMessage("第"+row+"行 第"+column+"列数据不符合规范");
|
|
|
+ incomeErrorMessage.setErrMessage("第" + row + "行 第" + column + "列数据不符合规范");
|
|
|
incomeErrorMessageList.add(incomeErrorMessage);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
data.set(j, Double.parseDouble(data.get(j).toString()));
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
data.add(NumberConstant.ZERO);
|
|
|
}
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(incomeErrorMessageList)){
|
|
|
- Integer emptyStatus = 0;
|
|
|
+ incomeErrorMessageList=new ArrayList<>();
|
|
|
+ int emptyStatus = 0;
|
|
|
for (int j = 2; j < data.size()-1 ; j++) {
|
|
|
BigDecimal parseInt = new BigDecimal (data.get(j).toString());
|
|
|
if (!BigDecimal.ZERO.equals(parseInt)) {
|
|
@@ -190,16 +288,22 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
|
|
|
String productCode = data.get(0).toString();
|
|
|
String productName = data.get(1).toString();
|
|
|
Product product = productMap.get(productCode + productName);
|
|
|
+ AfterCostGroup afterCostGroupRequest = new AfterCostGroup();
|
|
|
if (Objects.nonNull(product)) {
|
|
|
Long id = product.getId();
|
|
|
Long accountTingId = accountProMap.get(id);
|
|
|
if (Objects.nonNull(accountTingId)) {
|
|
|
Accounting accounting = accountingMap.get(accountTingId);
|
|
|
if (Objects.nonNull(accounting)) {
|
|
|
+
|
|
|
costCostingGroupRequest.setProductCode(productCode);
|
|
|
costCostingGroupRequest.setProductName(productName);
|
|
|
costCostingGroupRequest.setAccountCode(accounting.getAccountingCode());
|
|
|
costCostingGroupRequest.setAccountName(accounting.getAccountingName());
|
|
|
+ afterCostGroupRequest.setProductCode(productCode);
|
|
|
+ afterCostGroupRequest.setProductName(productName);
|
|
|
+ afterCostGroupRequest.setAccountCode(accounting.getAccountingCode());
|
|
|
+ afterCostGroupRequest.setAccountName(accounting.getAccountingName());
|
|
|
} else {
|
|
|
IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
|
|
|
incomeErrorMessage.setTotal(1);
|
|
@@ -221,22 +325,35 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
|
|
|
// 0表示全为0 1表示不全为0
|
|
|
|
|
|
BigDecimal combined = new BigDecimal (data.get(data.size() - 1).toString());
|
|
|
- if (NumberConstant.ZERO.equals(emptyStatus) &&BigDecimal.ZERO.equals(combined)) {
|
|
|
- // 全为0
|
|
|
- } else if (!BigDecimal.ZERO.equals(combined) && NumberConstant.ZERO.equals(emptyStatus)) {
|
|
|
+ if (!BigDecimal.ZERO.equals(combined) && NumberConstant.ZERO.equals(emptyStatus)) {
|
|
|
// 这条数据是保存到其他责任中心的
|
|
|
CostCostingGroup costCostingGroup = costCostingGroupRequest;
|
|
|
+ AfterCostGroup afterCostGroup = BeanUtil.convertObj(afterCostGroupRequest,AfterCostGroup.class);
|
|
|
// TODO 设置其他责任中心
|
|
|
- costCostingGroup.setResponsibilityCode("其他责任中心的Code");
|
|
|
- costCostingGroup.setResponsibilityName("其他责任中心的Name");
|
|
|
+ Responsibility responsibilityServiceOne = responsibilityService.getOne(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId, UserContext.getHospId()).eq(Responsibility::getIsDefault, NumberConstant.ONE));
|
|
|
+ if (Objects.nonNull(responsibilityServiceOne)){
|
|
|
+ costCostingGroup.setResponsibilityCode(responsibilityServiceOne.getResponsibilityCode());
|
|
|
+ costCostingGroup.setResponsibilityName(responsibilityServiceOne.getResponsibilityName());
|
|
|
+ // 设置统计数据
|
|
|
+ afterCostGroup.setOtherResponsibilityCode(responsibilityServiceOne.getResponsibilityCode());
|
|
|
+ afterCostGroup.setOtherResponsibilityName(responsibilityServiceOne.getResponsibilityName());
|
|
|
+ }
|
|
|
+ costCostingGroup.setProductCode(costCostingGroupRequest.getProductCode());
|
|
|
+ costCostingGroup.setProductName(costCostingGroupRequest.getProductName());
|
|
|
+ costCostingGroup.setAccountCode(costCostingGroupRequest.getAccountCode());
|
|
|
+ costCostingGroup.setAccountName(costCostingGroupRequest.getAccountName());
|
|
|
costCostingGroup.setAmount(combined);
|
|
|
costCostingGroup.setHospId(UserContext.getHospId());
|
|
|
costCostingGroup.setCreateTime(System.currentTimeMillis());
|
|
|
costCostingGroup.setDateYear(year);
|
|
|
costCostingGroup.setDateMonth(month);
|
|
|
+ afterCostGroup.setAmount(combined);
|
|
|
+ String s = JsonUtil.toJSONString(afterCostGroup);
|
|
|
+ costCostingGroup.setAfterCostGroup(s);
|
|
|
costCostingGroupArrayList.add(costCostingGroup);
|
|
|
} else {
|
|
|
for (int j = 2; j < data.size() - 1; j++) {
|
|
|
+ AfterCostGroup afterCostGroup = BeanUtil.convertObj(afterCostGroupRequest,AfterCostGroup.class);
|
|
|
CostCostingGroup costCostingGroup = BeanUtil.convertObj(costCostingGroupRequest,CostCostingGroup.class);
|
|
|
// 检验科室信息是否准确
|
|
|
String departmentCode = departmentCodes.get(j).toString();
|
|
@@ -253,7 +370,10 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
|
|
|
costCostingGroup.setDepartmentName(departmentName);
|
|
|
costCostingGroup.setResponsibilityCode(responsibility.getResponsibilityCode());
|
|
|
costCostingGroup.setResponsibilityName(responsibility.getResponsibilityName());
|
|
|
-
|
|
|
+ afterCostGroup.setResponsibilityCode(responsibility.getResponsibilityCode());
|
|
|
+ afterCostGroup.setResponsibilityName(responsibility.getResponsibilityName());
|
|
|
+ afterCostGroup.setDepartmentCode(departmentCode);
|
|
|
+ afterCostGroup.setDepartmentName(departmentName);
|
|
|
} else {
|
|
|
IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
|
|
|
incomeErrorMessage.setTotal(j);
|
|
@@ -277,6 +397,9 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
|
|
|
costCostingGroup.setCreateTime(System.currentTimeMillis());
|
|
|
costCostingGroup.setDateYear(year);
|
|
|
costCostingGroup.setDateMonth(month);
|
|
|
+ afterCostGroup.setAmount(new BigDecimal((Objects.isNull(data.get(j)) || "0".equals(data.get(j).toString())) ? "0.00" : data.get(j).toString()));
|
|
|
+ String s = JsonUtil.toJSONString(afterCostGroup);
|
|
|
+ costCostingGroup.setAfterCostGroup(s);
|
|
|
costCostingGroupArrayList.add(costCostingGroup);
|
|
|
}
|
|
|
}
|