package thyyxxk.webserver.service.yibao; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import thyyxxk.webserver.dao.his.yibao.Routines; import thyyxxk.webserver.entity.yibao.patient.FeeCounteract; import thyyxxk.webserver.entity.yibao.patient.Overview; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; /** * @author dj */ @Slf4j @Service public class SettleService { private final Routines routines; @Autowired public SettleService(Routines routines) { this.routines = routines; } public void beforeUpload(Overview o) { List negative = routines.selectNegativeFeesWithOriDetlSn( o.getInpatientNo(), o.getAdmissTimes(), o.getLedgerSn()); if (null == negative || negative.isEmpty()) { log.info("正负相抵完成,抵消费用总条目:0"); return; } List positive = new ArrayList<>(); List tempSn = new ArrayList<>(); for (FeeCounteract feeCounteract : negative) { tempSn.add(feeCounteract.getOriDetailSn()); if (tempSn.size() == 20) { positive.addAll(routines.selectPositiveFeesByDetlSn( o.getInpatientNo(), o.getAdmissTimes(), o.getLedgerSn(), tempSn)); tempSn.clear(); } } if (tempSn.size() > 0) { positive.addAll(routines.selectPositiveFeesByDetlSn( o.getInpatientNo(), o.getAdmissTimes(), o.getLedgerSn(), tempSn)); } AtomicInteger count = new AtomicInteger(); negative.forEach(itm -> { if (positive.contains(itm.getOriDetailSn())) { routines.updateYbTransFlagInPair(o.getInpatientNo(), o.getAdmissTimes(), itm.getDetailSn(), itm.getOriDetailSn()); count.addAndGet(2); } }); log.info("正负相抵完成,抵消费用总条目:{}", count.get()); } }