package com.saye.hrs.controller;

import javax.annotation.Resource;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.saye.hrs.commons.log.ExceptionDUtil;
import com.saye.hrs.commons.log.LogUtil;
import com.saye.hrs.commons.page.PageUtil;
import com.saye.hrs.commons.page.TemplatePage;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.saye.hrs.service.PatientService;
import java.util.HashMap;
import org.springframework.ui.ModelMap;

/**
 * 
 *
 * @author dqzhang
 * @since 2021-09-27 10:24:47
 */
@RequestMapping("patient")
@Controller
public class PatientController {
   
    @Resource
    private PatientService patientService;

    /**
     * 跳转页面
     * @param  modelMap
     * @param 
     * @return 
     */
    @RequestMapping("/toPatient")
	public String toUserManager(ModelMap modelMap){

		//查询所有角色
		return "Patient/Patient";
	}
    /**
     * 分页查询列表
     * @param  page limit
     * @param 
     * @return 查询结果
     */
    @RequestMapping("/findPatientPageList")
    @ResponseBody
    public TemplatePage findPatientPageList(Integer page,Integer limit) {
        HashMap<Object,Object> map=new HashMap<Object,Object>();
        PageHelper.startPage(page, limit);
		PageInfo<HashMap<Object,Object>> appsPageInfo = new PageInfo<HashMap<Object,Object>>(this.patientService.findPatientList(map));
		return PageUtil.loadJsonPage(appsPageInfo);
    }

    /**
     * 通过主键查询单条数据
     * @param map
     * @return 单条数据
     */
    @RequestMapping("/findPatientById")
    @ResponseBody
    public HashMap<Object,Object> findPatientById(@RequestBody HashMap<Object,Object> map) {
        return this.patientService.findPatientById(map);
    }

    /**
     * 新增数据（貌似没有用）
     * @param map
     * @return map
     */
    @RequestMapping("/insertPatient")
    @ResponseBody
    public HashMap<Object,Object> insertPatient(@RequestBody HashMap<Object,Object> map) {
        String errCode = "0";
        String errMsg = "";
        try{  
            this.patientService.insertPatient(map);
        } catch (Exception e) {
            errCode = "999";
            errMsg = "新增失败";
			LogUtil.error(this.getClass(), "新增失败，原因:"+ExceptionDUtil.getDetailExceptionMsg(e));
		}
		HashMap<Object,Object> resultMap = new HashMap<Object,Object>();
		resultMap.put("errCode",errCode);
		resultMap.put("errMsg",errMsg);
		return resultMap;
    }

    /**
     * 编辑数据
     * @param map
     * @return map
     */
    @RequestMapping("/updatePatient")
    @ResponseBody
    public HashMap<Object,Object> updatePatient(@RequestBody HashMap<Object,Object> map) {
        String errCode = "0";
        String errMsg = "";
        try{  
            this.patientService.updatePatient(map);
        } catch (Exception e) {
            errCode = "999";
            errMsg = "修改失败";
			LogUtil.error(this.getClass(), "修改失败，原因:"+ExceptionDUtil.getDetailExceptionMsg(e));
		}
		HashMap<Object,Object> resultMap = new HashMap<Object,Object>();
		resultMap.put("errCode",errCode);
		resultMap.put("errMsg",errMsg);
		return resultMap;
    }

    /**
     * 删除数据
     * @param map
     * @return map
     */
    @RequestMapping("/deletePatientById")
    @ResponseBody
    public HashMap<Object,Object> deletePatientById(@RequestBody HashMap<Object,Object> map) {
        String errCode = "0";
        String errMsg = "";
        try{  
            this.patientService.deletePatientById(map);
        } catch (Exception e) {
            errCode = "999";
            errMsg = "删除失败";
			LogUtil.error(this.getClass(), "删除失败，原因:"+ExceptionDUtil.getDetailExceptionMsg(e));
		}
		HashMap<Object,Object> resultMap = new HashMap<Object,Object>();
		resultMap.put("errCode",errCode);
		resultMap.put("errMsg",errMsg);
        return resultMap;
    }

    /**
     * 跳转到患者消费记录页面
     * @param  modelMap
     * @param
     * @return
     */
    @RequestMapping("/toPatientConsume")
    public String toPatientConsume(ModelMap modelMap){

        return "patient/patientConsume";
    }
    /**
      * 跳转到患者消费记录页面
     */
    @RequestMapping("/toPatientRecharge")
    public String toPatientRecharge(ModelMap modelMap){

        return "patient/patientRecharge";
    }

    /**
     * 跳转到患者住院消费记录页面
     */
    @RequestMapping("/toZyPatientRecharge")
    public String toZyPatientRecharge(ModelMap modelMap){

        return "patient/zyPatientRecharge";
    }
    
    /**
     * @description跳转到患者消费记录页面
     */
    @RequestMapping("/toPatientRefund")
    public String toPatientRefund(ModelMap modelMap){

       return "patient/patientRefund";
    }
    /**
     * @description 分页查询患者消费列表
     */
    @RequestMapping("/findPatientAccountPageList")
    @ResponseBody
    public TemplatePage findPatientAccountPageList(Integer page,Integer limit,String type) {
        HashMap<Object,Object> map=new HashMap<Object,Object>();
        map.put("type", type);
        PageHelper.startPage(page, limit);
        PageInfo<HashMap<Object,Object>> appsPageInfo = new PageInfo<HashMap<Object,Object>>(this.patientService.findPatientAccountPageList(map));
        return PageUtil.loadJsonPage(appsPageInfo);
    }

    /**
     * @description 分页查询患者消费列表
     */
    @RequestMapping("/findZyPatientAccountPageList")
    @ResponseBody
    public TemplatePage findZyPatientAccountPageList(Integer page,Integer limit,String type) {
        HashMap<Object,Object> map=new HashMap<Object,Object>();
        map.put("type", type);
        PageHelper.startPage(page, limit);
        PageInfo<HashMap<Object,Object>> appsPageInfo = new PageInfo<HashMap<Object,Object>>(this.patientService.findZyPatientAccountPageList(map));
        return PageUtil.loadJsonPage(appsPageInfo);
    }
    
    /**
     * @description跳转到银联商务退款记录页面
     */
    @RequestMapping("/toRefund")
    public String toRefund(ModelMap modelMap){

       return "patient/refund";
    }
    /**
     * @description 分页查询银联商务退款信息
     */
    @RequestMapping("/findRefundPageList")
    @ResponseBody
    public TemplatePage findRefundPageList(Integer page,Integer limit) {
        HashMap<Object,Object> map=new HashMap<Object,Object>();
        PageHelper.startPage(page, limit);
        PageInfo<HashMap<Object,Object>> appsPageInfo = new PageInfo<HashMap<Object,Object>>(this.patientService.findRefundList(map));
        return PageUtil.loadJsonPage(appsPageInfo);
    }
    
    /**
     * @description跳转到银联商务充值记录页面
     */
    @RequestMapping("/toPayRequest")
    public String toPayRequest(ModelMap modelMap){

       return "patient/payRequest";
    }
    
    /**
     * @description 分页查询银联商务充值记录
     */
    @RequestMapping("/findPayRequestPageList")
    @ResponseBody
    public TemplatePage findPayRequestPageList(Integer page,Integer limit) {
        HashMap<Object,Object> map=new HashMap<Object,Object>();
        PageHelper.startPage(page, limit);
        PageInfo<HashMap<Object,Object>> appsPageInfo = new PageInfo<HashMap<Object,Object>>(this.patientService.findPayRequestList(map));
        return PageUtil.loadJsonPage(appsPageInfo);
    }
    
    /**
     * @description 去绑定患者日志页面
     * @author dqzhang       
     * @created 2021年12月17日 下午3:43:39 
     * @param modelMap
     * @return
     */
    @RequestMapping("/toBindCardLog")
    public String toBindCardLog(ModelMap modelMap){

       return "patient/bindCardLog";
    }
    
    /**
     * @description 一句话描述方法作用
     * @author dqzhang       
     * @created 2021年12月17日 下午3:51:09 
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/findBindCardLogList")
    @ResponseBody
    public TemplatePage findBindCardLogList(Integer page,Integer limit,String start_date,String end_date,String status) {
        HashMap<Object,Object> map=new HashMap<Object,Object>();
        map.put("start_date", start_date);
        map.put("end_date", end_date);
        map.put("status", status);
        PageHelper.startPage(page, limit);
        PageInfo<HashMap<Object,Object>> appsPageInfo = new PageInfo<HashMap<Object,Object>>(this.patientService.findBindCardLogList(map));
        return PageUtil.loadJsonPage(appsPageInfo);
    }



}

