|
@@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
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;
|
|
@@ -25,6 +26,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
@Service("costCostingGroupService")
|
|
@@ -113,7 +116,11 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
|
|
|
CostIncomeFile costIncomeFile = costIncomeFileService.saveCostIncomeFile(list, user, file, hospId, incomeErrorMessageList, uploadFile, fileType);
|
|
|
return Result.build(500, "数据未成功导入", null);
|
|
|
}
|
|
|
- // 检验收入数据
|
|
|
+ // 检验数据的合理性
|
|
|
+
|
|
|
+ Pattern pattern = Pattern.compile("[0-9]+(.[0-9]+)?");
|
|
|
+ Matcher isNum = pattern.matcher("str");
|
|
|
+ // 检验成本数据
|
|
|
checkCostData(list, incomeErrorMessageList, departmentMap, productMap, responsibilityMap, accountingMap, responsibilityDepMap, accountProMap, costCostingGroupArrayList, year, month);
|
|
|
// 文件上传
|
|
|
String uploadFile = costIncomeGroupService.uploadFile(file, UserContext.getCurrentUser());
|
|
@@ -135,7 +142,14 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
|
|
|
return Result.build(500, "数据未成功导入", null);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ public static boolean isNumeric(String str){
|
|
|
+ Pattern pattern = Pattern.compile("[0-9]+(.[0-9]+)?");
|
|
|
+ Matcher isNum = pattern.matcher(str);
|
|
|
+ if( !isNum.matches() ){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
/**
|
|
|
* 检验成本数据
|
|
|
*
|
|
@@ -154,34 +168,51 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
|
|
|
List<Object> departmentNames = list.get(1);
|
|
|
//检验数据是否准确
|
|
|
for (int i = 2; i < list.size(); i++) {
|
|
|
+ int row=i+5;
|
|
|
List<Object> data = list.get(i);
|
|
|
for (int j = 2; j < departmentCodes.size(); j++) {
|
|
|
if (data.size() > j ) {
|
|
|
if (Objects.isNull(data.get(j))){
|
|
|
data.set(j, NumberConstant.ZERO);
|
|
|
}else {
|
|
|
+
|
|
|
data.set(j, Integer.parseInt(data.get(j).toString()));
|
|
|
}
|
|
|
- }else if (data.size()<=departmentCodes.size()){
|
|
|
+ }else {
|
|
|
data.add(NumberConstant.ZERO);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 检验成本项目是否正确
|
|
|
- CostCostingGroup costCostingGroupRequest = new CostCostingGroup();
|
|
|
- String productCode = data.get(0).toString();
|
|
|
- String productName = data.get(1).toString();
|
|
|
- Product product = productMap.get(productCode + productName);
|
|
|
- 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());
|
|
|
+ // 检验输入的数字是否合法
|
|
|
+ for (int j=2;j<data.size();j++){
|
|
|
+ if (!isNumeric(data.get(j).toString())){
|
|
|
+ IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
|
|
|
+ incomeErrorMessage.setTotal(row);
|
|
|
+ incomeErrorMessage.setErrMessage("第"+row+"行 第"+j+"列数据不符合规范");
|
|
|
+ incomeErrorMessageList.add(incomeErrorMessage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(incomeErrorMessageList)){
|
|
|
+ // 检验成本项目是否正确
|
|
|
+ CostCostingGroup costCostingGroupRequest = new CostCostingGroup();
|
|
|
+ String productCode = data.get(0).toString();
|
|
|
+ String productName = data.get(1).toString();
|
|
|
+ Product product = productMap.get(productCode + productName);
|
|
|
+ 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());
|
|
|
+ } else {
|
|
|
+ IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
|
|
|
+ incomeErrorMessage.setTotal(1);
|
|
|
+ incomeErrorMessage.setErrMessage("成本代码" + productCode + " 成本名称" + productName + " 不存在对应的会计科目不存在");
|
|
|
+ incomeErrorMessageList.add(incomeErrorMessage);
|
|
|
+ }
|
|
|
} else {
|
|
|
IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
|
|
|
incomeErrorMessage.setTotal(1);
|
|
@@ -191,86 +222,79 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
|
|
|
} else {
|
|
|
IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
|
|
|
incomeErrorMessage.setTotal(1);
|
|
|
- incomeErrorMessage.setErrMessage("成本代码" + productCode + " 成本名称" + productName + " 不存在对应的会计科目不存在");
|
|
|
+ incomeErrorMessage.setErrMessage("成本代码" + productCode + " 成本名称" + productName + "不存在");
|
|
|
incomeErrorMessageList.add(incomeErrorMessage);
|
|
|
}
|
|
|
- } else {
|
|
|
- IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
|
|
|
- incomeErrorMessage.setTotal(1);
|
|
|
- incomeErrorMessage.setErrMessage("成本代码" + productCode + " 成本名称" + productName + "不存在");
|
|
|
- incomeErrorMessageList.add(incomeErrorMessage);
|
|
|
- }
|
|
|
- // 0表示全为0 1表示不全为0
|
|
|
- Integer emptyStatus = 0;
|
|
|
- for (int j = 2; j < data.size()-1 ; j++) {
|
|
|
- int parseInt = Integer.parseInt(data.get(j).toString());
|
|
|
- if (!NumberConstant.ZERO.equals(parseInt)) {
|
|
|
- emptyStatus = 1;
|
|
|
- break;
|
|
|
+ // 0表示全为0 1表示不全为0
|
|
|
+ Integer emptyStatus = 0;
|
|
|
+ for (int j = 2; j < data.size()-1 ; j++) {
|
|
|
+ int parseInt = Integer.parseInt(data.get(j).toString());
|
|
|
+ if (!NumberConstant.ZERO.equals(parseInt)) {
|
|
|
+ emptyStatus = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- Integer combined = Integer.parseInt(data.get(data.size() - 1).toString());
|
|
|
- if (NumberConstant.ZERO.equals(emptyStatus) && NumberConstant.ZERO.equals(combined)) {
|
|
|
- // 全为0
|
|
|
- continue;
|
|
|
- } else if (!NumberConstant.ZERO.equals(combined) && NumberConstant.ZERO.equals(emptyStatus)) {
|
|
|
- // 这条数据是保存到其他责任中心的
|
|
|
- CostCostingGroup costCostingGroup = costCostingGroupRequest;
|
|
|
- // TODO 设置其他责任中心
|
|
|
- costCostingGroup.setResponsibilityCode("其他责任中心的Code");
|
|
|
- costCostingGroup.setResponsibilityName("其他责任中心的Name");
|
|
|
- costCostingGroup.setAmount(BigDecimal.valueOf(Double.parseDouble(combined.toString())));
|
|
|
- costCostingGroup.setHospId(UserContext.getHospId());
|
|
|
- costCostingGroup.setCreateTime(System.currentTimeMillis());
|
|
|
- costCostingGroup.setDateYear(year);
|
|
|
- costCostingGroup.setDateMonth(month);
|
|
|
- costCostingGroupArrayList.add(costCostingGroup);
|
|
|
- } else {
|
|
|
- for (int j = 2; j < data.size() - 1; j++) {
|
|
|
+ Integer combined = Integer.parseInt(data.get(data.size() - 1).toString());
|
|
|
+ if (NumberConstant.ZERO.equals(emptyStatus) && NumberConstant.ZERO.equals(combined)) {
|
|
|
+ // 全为0
|
|
|
+ } else if (!NumberConstant.ZERO.equals(combined) && NumberConstant.ZERO.equals(emptyStatus)) {
|
|
|
+ // 这条数据是保存到其他责任中心的
|
|
|
CostCostingGroup costCostingGroup = costCostingGroupRequest;
|
|
|
- // 检验科室信息是否准确
|
|
|
- String departmentCode = departmentCodes.get(j).toString();
|
|
|
- String departmentName = departmentNames.get(j).toString();
|
|
|
- Department department = departmentMap.get(departmentCode + departmentName);
|
|
|
- if (Objects.nonNull(department)) {
|
|
|
- // 检测责任中心是否存在
|
|
|
- Long id = department.getId();
|
|
|
- Long responsibilityId = responsibilityDepMap.get(id);
|
|
|
- if (Objects.nonNull(responsibilityId)) {
|
|
|
- Responsibility responsibility = responsibilityMap.get(responsibilityId);
|
|
|
- if (Objects.nonNull(responsibility)) {
|
|
|
- costCostingGroup.setDepartmentCode(departmentCode);
|
|
|
- costCostingGroup.setDepartmentName(departmentName);
|
|
|
- costCostingGroup.setResponsibilityCode(responsibility.getResponsibilityCode());
|
|
|
- costCostingGroup.setResponsibilityName(responsibility.getResponsibilityName());
|
|
|
+ // TODO 设置其他责任中心
|
|
|
+ costCostingGroup.setResponsibilityCode("其他责任中心的Code");
|
|
|
+ costCostingGroup.setResponsibilityName("其他责任中心的Name");
|
|
|
+ costCostingGroup.setAmount(BigDecimal.valueOf(Double.parseDouble(combined.toString())));
|
|
|
+ costCostingGroup.setHospId(UserContext.getHospId());
|
|
|
+ costCostingGroup.setCreateTime(System.currentTimeMillis());
|
|
|
+ costCostingGroup.setDateYear(year);
|
|
|
+ costCostingGroup.setDateMonth(month);
|
|
|
+ costCostingGroupArrayList.add(costCostingGroup);
|
|
|
+ } else {
|
|
|
+ for (int j = 2; j < data.size() - 1; j++) {
|
|
|
+ CostCostingGroup costCostingGroup = BeanUtil.convertObj(costCostingGroupRequest,CostCostingGroup.class);
|
|
|
+ // 检验科室信息是否准确
|
|
|
+ String departmentCode = departmentCodes.get(j).toString();
|
|
|
+ String departmentName = departmentNames.get(j).toString();
|
|
|
+ Department department = departmentMap.get(departmentCode + departmentName);
|
|
|
+ if (Objects.nonNull(department)) {
|
|
|
+ // 检测责任中心是否存在
|
|
|
+ Long id = department.getId();
|
|
|
+ Long responsibilityId = responsibilityDepMap.get(id);
|
|
|
+ if (Objects.nonNull(responsibilityId)) {
|
|
|
+ Responsibility responsibility = responsibilityMap.get(responsibilityId);
|
|
|
+ if (Objects.nonNull(responsibility)) {
|
|
|
+ costCostingGroup.setDepartmentCode(departmentCode);
|
|
|
+ costCostingGroup.setDepartmentName(departmentName);
|
|
|
+ costCostingGroup.setResponsibilityCode(responsibility.getResponsibilityCode());
|
|
|
+ costCostingGroup.setResponsibilityName(responsibility.getResponsibilityName());
|
|
|
|
|
|
+ } else {
|
|
|
+ IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
|
|
|
+ incomeErrorMessage.setTotal(j);
|
|
|
+ incomeErrorMessage.setErrMessage("第" + j + "列科室信息对应的责任中心不存在");
|
|
|
+ incomeErrorMessageList.add(incomeErrorMessage);
|
|
|
+ }
|
|
|
} else {
|
|
|
IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
|
|
|
incomeErrorMessage.setTotal(j);
|
|
|
- incomeErrorMessage.setErrMessage("第" + j + "列科室信息对应的责任中心不存在");
|
|
|
+ incomeErrorMessage.setErrMessage("第" + j + "列科室信息不存在对应的责任中心");
|
|
|
incomeErrorMessageList.add(incomeErrorMessage);
|
|
|
}
|
|
|
} else {
|
|
|
IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
|
|
|
incomeErrorMessage.setTotal(j);
|
|
|
- incomeErrorMessage.setErrMessage("第" + j + "列科室信息不存在对应的责任中心");
|
|
|
+ incomeErrorMessage.setErrMessage("第" + j + "列科室信息不存在");
|
|
|
incomeErrorMessageList.add(incomeErrorMessage);
|
|
|
}
|
|
|
- } else {
|
|
|
- IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
|
|
|
- incomeErrorMessage.setTotal(j);
|
|
|
- incomeErrorMessage.setErrMessage("第" + j + "列科室信息不存在");
|
|
|
- incomeErrorMessageList.add(incomeErrorMessage);
|
|
|
+ costCostingGroup.setAmount(BigDecimal.valueOf(Double.parseDouble((Objects.isNull(data.get(j)) || "0".equals(data.get(j).toString())) ? "0.00" : data.get(j).toString())));
|
|
|
+ costCostingGroup.setHospId(UserContext.getHospId());
|
|
|
+ costCostingGroup.setCreateTime(System.currentTimeMillis());
|
|
|
+ costCostingGroup.setDateYear(year);
|
|
|
+ costCostingGroup.setDateMonth(month);
|
|
|
+ costCostingGroupArrayList.add(costCostingGroup);
|
|
|
}
|
|
|
- costCostingGroup.setAmount(BigDecimal.valueOf(Double.parseDouble((Objects.isNull(data.get(j)) || "0".equals(data.get(j).toString())) ? "0.00" : data.get(j).toString())));
|
|
|
- costCostingGroup.setHospId(UserContext.getHospId());
|
|
|
- costCostingGroup.setCreateTime(System.currentTimeMillis());
|
|
|
- costCostingGroup.setDateYear(year);
|
|
|
- costCostingGroup.setDateMonth(month);
|
|
|
- costCostingGroupArrayList.add(costCostingGroup);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|