package thyyxxk.webserver.entity.view.patient360;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Data;
import thyyxxk.webserver.utils.ListUtil;
import thyyxxk.webserver.utils.StringUtil;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Data
public class ZyFeeDetail {
    @Data
    public static class ZyFeeDetailParams {

        public QueryWrapper<?> queryWrapper() {
            QueryWrapper<?> qw = new QueryWrapper<>();
            qw.eq("inpatient_no", patNo)
                    .eq("admiss_times", times);

            if (StringUtil.notBlank(start)) {
                qw.ge("charge_date", start)
                        .le("charge_date", end);
            }

            if (StringUtil.notBlank(chargeCodeMx)) {
                qw.eq("rtrim(charge_code_mx) + '_' + rtrim(serial)", chargeCodeMx);
            }

            if (ListUtil.notBlank(orderList)) {
                if (StringUtil.notBlank(actOrderNoStr)) {
                    orderList.add(getActOrderNo());
                }
                qw.in("abs(order_no)", orderList);
            } else if (StringUtil.notBlank(actOrderNoStr)) {
                qw.eq("abs(order_no)", getActOrderNo());
            }

            qw.orderByAsc("charge_date");
            return qw;
        }


        private String patNo;
        private Integer times;
        private String start;
        private String end;
        private String chargeCodeMx;
        private String actOrderNoStr;

        private List<BigDecimal> orderList;

        private BigDecimal getActOrderNo() {
            if (StringUtil.notBlank(actOrderNoStr)) {
                return new BigDecimal(actOrderNoStr).abs();
            }
            return null;
        }


    }

    private int ledgerSn;
    private int detailSn;
    private Date chargeDate;
    private String opIdCode;
    private String opIdCodeName;
    private String chargeCodeMx;
    private String chargeCodeName;
    private BigDecimal chargeAmount;
    private BigDecimal chargeFee;
    private String wardCode;
    private String wardCodeName;
    private String execUnit;
    private String execUnitName;
    private BigDecimal orderNo;
    private String serial;
    private Integer oriDetailSn;
    private String actOrderNoStr;
}
