package com.saye.hospitalgd.controller;

import com.saye.hospitalgd.commons.date.DateDUtil;
import com.saye.hospitalgd.commons.string.StringDUtil;
import com.saye.hospitalgd.service.FinancialReconciliation.MobileYbReconciliationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

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

@Controller
@RequestMapping("/mobileYbReconciliation")
@Api(tags = "微信移动医保对账")
public class MobileYbReconciliationController {

    @Autowired
    private MobileYbReconciliationService mobileYbReconciliationService;

    @RequestMapping("/toMobileYb")
    public String toMobileYb(ModelMap modelMap) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.DATE, -1);
        String startTime = DateDUtil.DateToStr(DateDUtil.yyyy_MM_dd, calendar.getTime());
        String endTime = DateDUtil.getCurrentDate(DateDUtil.yyyy_MM_dd);
        modelMap.addAttribute("startTime", startTime);
        modelMap.addAttribute("endTime", endTime);
        return "paymentStatistics/mobileYbReconciliation";
    }

    @RequestMapping("/findData")
    @ResponseBody
    @ApiOperation("查询微信移动医保对账数据")
    public HashMap<Object, Object> findData(@RequestBody HashMap<Object, Object> map) {
        HashMap<Object, Object> resp = new HashMap<>();
        String errCode = "0";
        String errMsg = "";
        try {
            String tradeDate = StringDUtil.changeNullToEmpty(map.get("trade_date"));
            if ("".equals(tradeDate)) {
                errCode = "1";
                errMsg = "trade_date不能为空";
            } else {
                resp = mobileYbReconciliationService.reconcile(tradeDate);
            }
        } catch (Exception e) {
            errCode = "999";
            errMsg = e.getMessage();
        }
        resp.put("errCode", errCode);
        resp.put("errMsg", errMsg);
        return resp;
    }
}






