package com.saye.hrs.controller;

import com.saye.hrs.commons.log.LogUtil;
import com.saye.hrs.model.WxResult;
import com.saye.hrs.model.WxybResult;
import com.saye.hrs.service.WxPayService;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/***
 * @title WxPayController
 * @description TODO 请填写注释
 * @author thuang
 * @create 2023/8/15 9:34
 **/
@RestController
public class WxPayController {

    @Resource
    private WxPayService wxPayService;

    @PostMapping("/api/addWxPayInfo")
    public HashMap<Object,Object> addWxPayInfo(@RequestBody WxResult reqDTO){
        HashMap<Object,Object> resultMap=new HashMap<>();
        String errCode="0";
        String errMsg="";

        try {

            wxPayService.addWxPayInfo(reqDTO);
        }catch (Exception e){
            e.printStackTrace();
            errCode="999";
            errMsg="保存微信门诊及医保支付记录失败，原因："+e.getMessage();
        }

        resultMap.put("errCode",errCode);
        resultMap.put("errMsg",errMsg);
        return resultMap;
    }

    @PostMapping("/api/findWxPayInfo")
    public HashMap<Object,Object> findWxPayInfo(@RequestBody WxResult reqDTO){
        HashMap<Object,Object> resultMap=new HashMap<>();
        String errCode="0";
        String errMsg="";

        try {

            WxResult map = wxPayService.findWxPayInfo(reqDTO);
            resultMap.put("data",map);
        }catch (Exception e){
            e.printStackTrace();
            errCode="999";
            errMsg="查询微信门诊及医保支付记录失败，原因："+e.getMessage();
        }

        resultMap.put("errCode",errCode);
        resultMap.put("errMsg",errMsg);
        return resultMap;
    }


    @PostMapping("/api/addWxybPayInfo")
    public HashMap<Object,Object> addWxybPayInfo(@RequestBody WxybResult reqDTO){
        HashMap<Object,Object> resultMap=new HashMap<>();
        String errCode="0";
        String errMsg="";

        try {
            wxPayService.addWxybPayInfo(reqDTO);
        }catch (Exception e){
            e.printStackTrace();
            errCode="999";
            errMsg="保存微信医保支付记录失败，原因："+e.getMessage();
        }

        resultMap.put("errCode",errCode);
        resultMap.put("errMsg",errMsg);
        return resultMap;
    }

    @PostMapping("/api/findWxybPayInfo")
    public HashMap<Object,Object> findWxybPayInfo(@RequestBody WxybResult reqDTO){
        HashMap<Object,Object> resultMap=new HashMap<>();
        String errCode="0";
        String errMsg="";

        try {
            WxybResult map = wxPayService.findWxybPayInfo(reqDTO);
            resultMap.put("data",map);
        }catch (Exception e){
            e.printStackTrace();
            errCode="999";
            errMsg="查询微信医保支付记录失败，原因："+e.getMessage();
        }

        resultMap.put("errCode",errCode);
        resultMap.put("errMsg",errMsg);
        return resultMap;
    }

    @PostMapping("/api/getWxNotSendInfo")
    public HashMap<Object,Object> getWxNotSendInfo(@RequestBody HashMap<Object,Object> map){
        HashMap<Object,Object> resultMap=new HashMap<>();
        String errCode="0";
        String errMsg="";

        try {
            List<WxResult> list = wxPayService.getWxNotSendInfo(map);
            resultMap.put("List",list);
        }catch (Exception e){
            e.printStackTrace();
            errCode="999";
            errMsg="查询微信未支付记录失败，原因："+e.getMessage();
        }

        resultMap.put("errCode",errCode);
        resultMap.put("errMsg",errMsg);
        return resultMap;
    }

    @PostMapping("/api/getWxybNotSendInfo")
    public HashMap<Object,Object> getWxybNotSendInfo(@RequestBody HashMap<Object,Object> map){
        HashMap<Object,Object> resultMap=new HashMap<>();
        String errCode="0";
        String errMsg="";

        try {
            List<WxybResult> list = wxPayService.getWxybNotSendInfo(map);
            resultMap.put("List",list);
        }catch (Exception e){
            e.printStackTrace();
            errCode="999";
            errMsg="查询微信医保未支付记录失败，原因："+e.getMessage();
        }

        resultMap.put("errCode",errCode);
        resultMap.put("errMsg",errMsg);
        return resultMap;
    }

    @PostMapping("/api/addOrderInfo")
    public HashMap<Object,Object> addOrderInfo(@RequestBody HashMap<Object,Object> map){
        HashMap<Object,Object> resultMap=new HashMap<>();
        String errCode="0";
        String errMsg="";
        try {
            wxPayService.addOrderInfo(map);
        }catch (Exception e){
            e.printStackTrace();
            errCode="999";
            errMsg="保存订单支付状态失败，原因："+e.getMessage();
        }
        resultMap.put("errCode",errCode);
        resultMap.put("errMsg",errMsg);
        return resultMap;
    }

    @PostMapping("/api/updateOrderInfoPay")
    public HashMap<Object,Object> updateOrderInfoPay(@RequestBody HashMap<Object,Object> map){
        HashMap<Object,Object> resultMap=new HashMap<>();
        String errCode="0";
        String errMsg="";
        try {
            wxPayService.updateOrderInfoPay(map);
        }catch (Exception e){
            e.printStackTrace();
            errCode="999";
            errMsg="保存订单支付状态失败，原因："+e.getMessage();
        }
        resultMap.put("errCode",errCode);
        resultMap.put("errMsg",errMsg);
        return resultMap;
    }

    @PostMapping("/api/updateYBOrderInfoPay")
    public HashMap<Object,Object> updateYBOrderInfoPay(@RequestBody HashMap<Object,Object> map){
        HashMap<Object,Object> resultMap=new HashMap<>();
        String errCode="0";
        String errMsg="";
        try {
            wxPayService.updateYBOrderInfoPay(map);
        }catch (Exception e){
            e.printStackTrace();
            errCode="999";
            errMsg="更新订单支付状态失败，原因："+e.getMessage();
        }
        resultMap.put("errCode",errCode);
        resultMap.put("errMsg",errMsg);
        return resultMap;
    }

    @PostMapping("/api/updateOrderInfoComplete")
    public HashMap<Object,Object> updateOrderInfoComplete(@RequestBody HashMap<Object,Object> map){
        HashMap<Object,Object> resultMap=new HashMap<>();
        String errCode="0";
        String errMsg="";
        try {
            wxPayService.updateOrderInfoComplete(map);
        }catch (Exception e){
            e.printStackTrace();
            errCode="999";
            errMsg="更新订单状态为完成失败，原因："+e.getMessage();
        }
        resultMap.put("errCode",errCode);
        resultMap.put("errMsg",errMsg);
        return resultMap;
    }

    @PostMapping("/api/findOrderInfo")
    public HashMap<Object,Object> findOrderInfo(@RequestBody HashMap<Object,Object> map){
        HashMap<Object,Object> resultMap=new HashMap<>();
        String errCode="0";
        String errMsg="";
        try {
            List<HashMap<Object,Object>> list = wxPayService.findOrderInfo(map);
            resultMap.put("list",list);
        }catch (Exception e){
            e.printStackTrace();
            errCode="999";
            errMsg="查询未完成订单内容失败，原因："+e.getMessage();
        }
        resultMap.put("errCode",errCode);
        resultMap.put("errMsg",errMsg);
        return resultMap;
    }

    @PostMapping("/api/updateOrderInfoEnd")
    public HashMap<Object,Object> updateOrderInfoEnd(@RequestBody HashMap<Object,Object> map){
        HashMap<Object,Object> resultMap=new HashMap<>();
        String errCode="0";
        String errMsg="";
        try {
            wxPayService.updateOrderInfoEnd(map);
        }catch (Exception e){
            e.printStackTrace();
            errCode="999";
            errMsg="查询未完成订单内容失败，原因："+e.getMessage();
        }
        resultMap.put("errCode",errCode);
        resultMap.put("errMsg",errMsg);
        return resultMap;
    }
}
