package com.saye.hospitalgd.scheduler.jobMethod;

import com.saye.hospitalgd.commons.date.DateDUtil;
import com.saye.hospitalgd.commons.getBean.GetBeanUtil;
import com.saye.hospitalgd.commons.log.LogUtil;
import com.saye.hospitalgd.service.FinancialReconciliation.MobileYbReconciliationService;
import com.saye.hospitalgd.service.impl.FinancialReconciliation.MobileYbReconciliationServiceImpl;
import lombok.extern.slf4j.Slf4j;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;

/**
 * 微信移动医保对账方法
 * 被调度任务调用，传入 trade_date（yyyy-MM-dd），为空则默认昨日
 */
@Slf4j
public class MobileYbReconciliationMethod {

    public HashMap<Object, Object> executeMobileYbReconciliation(String trade_date) {
        HashMap<Object, Object> resp = new HashMap<>();
        String errCode = "0";
        String errMsg = "";
        try {
            String targetDate = trade_date;
            if (targetDate == null || "".equals(targetDate.trim())) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(new Date());
                calendar.add(Calendar.DATE, -1);
                targetDate = DateDUtil.DateToStr(DateDUtil.yyyy_MM_dd, calendar.getTime());
            }
            LogUtil.info(this.getClass(), "开始执行微信移动医保对账，日期：" + targetDate);
            MobileYbReconciliationService svc = GetBeanUtil.getBean(MobileYbReconciliationServiceImpl.class);
            resp = svc.reconcile(targetDate);
            LogUtil.info(this.getClass(), "微信移动医保对账结束，结果：" + resp);
        } catch (Exception e) {
            errCode = "999";
            errMsg = e.getMessage();
            log.error("微信移动医保对账失败：{}", errMsg, e);
        }
        resp.put("errCode", errCode);
        resp.put("errMsg", errMsg);
        return resp;
    }
}

