package com.emr.controller;

import com.emr.entity.Archive_Master_Vo;
import com.emr.entity.OffsetLimitPage;
import com.emr.service.Observation_ReportService;
import com.emr.util.ThreadExcelUtils;
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.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/observationReport")
public class ObservationReportController {
    @Autowired
    private Observation_ReportService observationReportService;

    @RequestMapping(value = "/observationReport")
    public String inHospitals(Model model) {
        //return "beHospitaledDir/beHospListNow";
        return "observationReport/observationReportList";
    }

    @ResponseBody
    @RequestMapping(value = "/getObservationReportPage")
    public OffsetLimitPage getObservationReportList(Archive_Master_Vo archiveMasterVo, Integer offset, Integer limit) {
        OffsetLimitPage result = observationReportService.getObservationReportList(archiveMasterVo, offset, limit);
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/exportExcel")
    public void exportExcel(HttpServletResponse response, Archive_Master_Vo master) throws Exception {
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        String[] header = {"归档病历总数","迟交病历总数","已质控病历总数","退回急诊室总数","主管医生"};
        String[] fileNames = {"fileNum","delayNum","qualityNum","backNum","doctorInCharge"};
        //文件名
        String fileName = "急诊留观病历报表" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xls";
        //构造excel的数据
        List<Archive_Master_Vo> list = observationReportService.getObservationReportList(master);
        ThreadExcelUtils utils = new ThreadExcelUtils(fileName, "", header, fileNames);
        utils.exportExcelToFilePath(response,utils.listConvert(list));
    }
}

