|
@@ -6,14 +6,9 @@ import org.springframework.http.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
import thyyxxk.webserver.config.exception.ExceptionEnum;
|
|
|
-import thyyxxk.webserver.constants.Capacity;
|
|
|
-import thyyxxk.webserver.dao.his.yibao.AdvanceUploadDao;
|
|
|
import thyyxxk.webserver.entity.ResultVo;
|
|
|
import thyyxxk.webserver.entity.yibao.dismiss.YbSettleFee;
|
|
|
-import thyyxxk.webserver.entity.yibao.patient.FeeCounteract;
|
|
|
-import thyyxxk.webserver.entity.yibao.patient.Overview;
|
|
|
import thyyxxk.webserver.entity.yibao.patient.Patient;
|
|
|
-import thyyxxk.webserver.utils.DecimalUtil;
|
|
|
import thyyxxk.webserver.utils.FilterUtil;
|
|
|
import thyyxxk.webserver.utils.ResultVoUtil;
|
|
|
import thyyxxk.webserver.utils.YbLinksUtil;
|
|
@@ -27,93 +22,10 @@ import java.util.*;
|
|
|
@Service
|
|
|
public class SettleService {
|
|
|
private final DismissService service;
|
|
|
- private final AdvanceUploadDao dao;
|
|
|
|
|
|
@Autowired
|
|
|
- public SettleService(DismissService service, AdvanceUploadDao dao) {
|
|
|
+ public SettleService(DismissService service) {
|
|
|
this.service = service;
|
|
|
- this.dao = dao;
|
|
|
- }
|
|
|
-
|
|
|
- public void posNegOffset(Overview overview) {
|
|
|
- Integer offsetFeeSum = dao.selectOffsetFeeSum(overview.getInpatientNo(),
|
|
|
- overview.getAdmissTimes(), overview.getLedgerSn());
|
|
|
- if (null != offsetFeeSum && offsetFeeSum != 0) {
|
|
|
- dao.rollbackOffsetFees(overview.getInpatientNo(),
|
|
|
- overview.getAdmissTimes(), overview.getLedgerSn());
|
|
|
- }
|
|
|
- Queue<FeeCounteract> fees = dao.selectAllNotUploadedFees(overview.getInpatientNo(),
|
|
|
- overview.getAdmissTimes(), overview.getLedgerSn());
|
|
|
- if (null == fees || fees.isEmpty()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- int count = 0;
|
|
|
- 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 {
|
|
|
- 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, Map<String, List<FeeCounteract>>> entry : feeMap.entrySet()) {
|
|
|
- List<FeeCounteract> negativeList = entry.getValue().get("negative");
|
|
|
- if (negativeList.isEmpty()) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- 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(overview.getInpatientNo(), overview.getAdmissTimes(),
|
|
|
- negativeFee.getDetailSn(), positiveFee.getDetailSn());
|
|
|
- count += 2;
|
|
|
- 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(overview.getInpatientNo(), overview.getAdmissTimes(), negativeFee.getDetailSn());
|
|
|
- detailSnList.forEach(detailSn ->
|
|
|
- dao.updateYbTransFlag(overview.getInpatientNo(), overview.getAdmissTimes(), detailSn));
|
|
|
- count += (detailSnList.size() + 1);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("正负相抵完成:{},共抵消 {} 条费用。", overview.getLogBody(), count);
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings({"rawtypes", "unchecked"})
|