/**
 * Copyright (C), 2015-2019
 * Author:   HJL
 * Date:     2019/7/19 14:39
 * Description:病案召回
 */
package com.emr.controller;

import com.emr.entity.Archive_Master_Vo;
import com.emr.entity.OffsetLimitPage;
import com.emr.service.Archive_MasterService;
import com.emr.util.DatelUtils;
import com.emr.util.ThreadExcelUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import static com.emr.util.DatelUtils.addDayFun;
import static com.emr.util.DatelUtils.compareDate;


//@PropertySource(value = "classpath:config/jdbc.properties", encoding = "UTF-8")
@Controller
@RequestMapping("/copyInfo")
public class CopyListController {

    @Autowired
    private Archive_MasterService archiveMasterService;

    @RequestMapping(value = "/copyDetailList")
    public String faults(Model model) {
        return "copyDir/copyDetailList";
    }

    @ResponseBody
    @RequestMapping(value = "/copyDetailPage")
    public OffsetLimitPage copyDetailPage(HttpServletRequest request, HttpServletResponse response,Archive_Master_Vo archiveMasterVo, Integer offset, Integer limit) throws Exception {
        //判断复制时段类型
        archiveMasterVo=DatelUtils.setMaterVoFun(archiveMasterVo);
        OffsetLimitPage result = (OffsetLimitPage) archiveMasterService.copyDetailList(archiveMasterVo, offset, limit);
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/exportExcel")
    public void exportExcel(HttpServletResponse response, Archive_Master_Vo archiveMasterVo) throws Exception {
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        String[] header = {"记帐号","住院号","住院次数","患者姓名","性别","入院日期","出院日期","出院科室","主管医生","复印内容","复印日期"};
        String[] fileNames = {"patientId","inpNo","visitId","name","sex","admissionDateTime","dischargeDateTime","deptName","doctorInCharge","content","createTime"};
        //文件名
        String fileName = "复印记录明细" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xls";
        //构造excel的数据beHospList
        archiveMasterVo= DatelUtils.setMaterVoFun(archiveMasterVo);
        List<Archive_Master_Vo> list = archiveMasterService.copyDetailList(archiveMasterVo);
        ThreadExcelUtils utils = new ThreadExcelUtils(fileName, "", header, fileNames);
        String result=utils.exportExcelToFilePath(response,utils.listConvert(list));
    }

    /*
     * 复印记录统计
     * */
    @RequestMapping(value = "/copyCountList")
    public String faultsLog(Model model) {
        return "copyDir/copyCountList";
    }

    /*
     * 复印记录统计分页
     * */
    @ResponseBody
    @RequestMapping(value = "/copyCountPage")
    public OffsetLimitPage copyCountPage(HttpServletRequest request, HttpServletResponse response, Archive_Master_Vo archiveMasterVo, Integer offset, Integer limit)throws Exception {
        archiveMasterVo=DatelUtils.setMaterVoFun(archiveMasterVo);
        OffsetLimitPage result = archiveMasterService.copyCountList(archiveMasterVo, offset, limit);
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/exportCountExcel")
    public void exportCountExcel(HttpServletResponse response,Archive_Master_Vo archiveMasterVo) throws Exception {
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        String[] header = {"记帐号","住院号","住院次数","患者姓名","复印日期","复印次数"};
        String[] fileNames = {"patientId","inpNo","visitId","name","createTime","numb"};
        //文件名
        String fileName = "复印记录统计" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xls";
        //构造excel的数据beHospList
        archiveMasterVo=DatelUtils.setMaterVoFun(archiveMasterVo);
        List<Archive_Master_Vo> list = archiveMasterService.copyCountList(archiveMasterVo);
        ThreadExcelUtils utils = new ThreadExcelUtils(fileName, "", header, fileNames);
        String result=utils.exportExcelToFilePath(response,utils.listConvert(list));
    }




}
 

