|
@@ -279,40 +279,74 @@ public class PatientService {
|
|
|
|
|
|
public ResultVo<String> updateTransFlag(UpdateTransFlagParam param) {
|
|
|
log.info("正负相抵操作:{}", param);
|
|
|
- String verify = verifyTransFlags(param.getList());
|
|
|
- log.info("正负相抵操作校验:{}", verify);
|
|
|
- if ("success".equals(verify)) {
|
|
|
- for (Fee fee : param.getList()) {
|
|
|
- dao.updateYbTransFlag(param.getInpatientNo(), param.getAdmissTimes(), fee.getDetailSn());
|
|
|
- }
|
|
|
- return ResultVoUtil.success();
|
|
|
- } else {
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, verify);
|
|
|
+ int ledgerSn = dao.getLedgerSn(param.getInpatientNo(), param.getAdmissTimes());
|
|
|
+ Queue<FeeCounteract> fees = dao.selectAllNotUploadedFees(param.getInpatientNo(), param.getAdmissTimes(), ledgerSn);
|
|
|
+ if (null == fees || fees.isEmpty()) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有可以进行正负相抵的费用。");
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- private String verifyTransFlags(List<Fee> list) {
|
|
|
- HashMap<String, List<Fee>> map = new HashMap<>(Capacity.DEFAULT);
|
|
|
- for (Fee fee : list) {
|
|
|
- String code = fee.getHisItemCode();
|
|
|
- if (map.containsKey(code)) {
|
|
|
- map.get(code).add(fee);
|
|
|
+ Map<String, Map<String, List<FeeCounteract>>> feeMap = new HashMap<>(Capacity.DEFAULT);
|
|
|
+ while (!fees.isEmpty()) {
|
|
|
+ FeeCounteract fee = fees.poll();
|
|
|
+ String chargeCodeMx = fee.getChargeCodeMx();
|
|
|
+ if (feeMap.containsKey(chargeCodeMx)) {
|
|
|
+ if (fee.getChargeFee().startsWith("-")) {
|
|
|
+ feeMap.get(chargeCodeMx).get("negative").add(fee);
|
|
|
+ } else {
|
|
|
+ feeMap.get(chargeCodeMx).get("positive").add(fee);
|
|
|
+ }
|
|
|
} else {
|
|
|
- List<Fee> temp = new ArrayList<>();
|
|
|
- temp.add(fee);
|
|
|
- map.put(code, temp);
|
|
|
+ Map<String, List<FeeCounteract>> tempMap = new HashMap<>();
|
|
|
+ tempMap.put("positive", new ArrayList<>());
|
|
|
+ tempMap.put("negative", new ArrayList<>());
|
|
|
+ if (fee.getChargeFee().startsWith("-")) {
|
|
|
+ tempMap.get("negative").add(fee);
|
|
|
+ } else {
|
|
|
+ tempMap.get("positive").add(fee);
|
|
|
+ }
|
|
|
+ feeMap.put(chargeCodeMx, tempMap);
|
|
|
}
|
|
|
}
|
|
|
- for (Map.Entry<String, List<Fee>> entry : map.entrySet()) {
|
|
|
- String sum = "0.00";
|
|
|
- for (Fee fee : entry.getValue()) {
|
|
|
- sum = DecimalUtil.add(sum, fee.getChargeFee());
|
|
|
+ for (Map.Entry<String, Map<String, List<FeeCounteract>>> entry : feeMap.entrySet()) {
|
|
|
+ List<FeeCounteract> negativeList = entry.getValue().get("negative");
|
|
|
+ if (negativeList.isEmpty()) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- if (DecimalUtil.compare(sum, "0") != 0) {
|
|
|
- return "收费码:" + entry.getKey() + "的费用之和不为0,无法进行正负相抵!";
|
|
|
+ List<FeeCounteract> positiveList = entry.getValue().get("positive");
|
|
|
+ List<Integer> updatedSn = new ArrayList<>();
|
|
|
+ for (FeeCounteract negativeFee : negativeList) {
|
|
|
+ boolean found = false;
|
|
|
+ for (FeeCounteract positiveFee : positiveList) {
|
|
|
+ if (updatedSn.contains(positiveFee.getDetailSn())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (DecimalUtil.negativeAndPositive(positiveFee.getChargeFee(), negativeFee.getChargeFee())) {
|
|
|
+ found = true;
|
|
|
+ updatedSn.add(positiveFee.getDetailSn());
|
|
|
+ dao.updateYbTransFlagInPair(param.getInpatientNo(), param.getAdmissTimes(),
|
|
|
+ negativeFee.getDetailSn(), positiveFee.getDetailSn());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!found) {
|
|
|
+ String positiveAmt = "0.00";
|
|
|
+ List<Integer> detailSnList = new ArrayList<>();
|
|
|
+ for (FeeCounteract positiveFee : positiveList) {
|
|
|
+ if (updatedSn.contains(positiveFee.getDetailSn())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ detailSnList.add(positiveFee.getDetailSn());
|
|
|
+ updatedSn.add(positiveFee.getDetailSn());
|
|
|
+ positiveAmt = DecimalUtil.add(positiveAmt, positiveFee.getChargeFee());
|
|
|
+ if (DecimalUtil.negativeAndPositive(positiveAmt, negativeFee.getChargeFee())) {
|
|
|
+ dao.updateYbTransFlag(param.getInpatientNo(), param.getAdmissTimes(), negativeFee.getDetailSn());
|
|
|
+ detailSnList.forEach(detailSn -> dao.updateYbTransFlag(param.getInpatientNo(), param.getAdmissTimes(),detailSn));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- return "success";
|
|
|
+ return ResultVoUtil.success();
|
|
|
}
|
|
|
|
|
|
/**
|