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

import com.emr.entity.Emr_Log;
import com.emr.entity.Emr_Log_Vo;
import com.emr.entity.OffsetLimitPage;
import com.emr.service.LogService;
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.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/recallDate")
public class medicalRecallDateController {
    @Autowired
    private LogService logService;

    @RequestMapping(value = "/recallDates")
    public String recallDates(Model model) {
        return "medicalRecallDateDir/recallDateList";
    }

    @ResponseBody
    @RequestMapping(value = "/recallDateList")
    public OffsetLimitPage recallDateList(HttpServletRequest request, HttpServletResponse response, Emr_Log_Vo emrLogVo, Integer offset, Integer limit) {
        response.setCharacterEncoding("utf-8");
        emrLogVo.setLogContent("病案召回");
        emrLogVo.setSysFlag("EMR_Medical_Record");
        OffsetLimitPage result = logService.selectByCol(emrLogVo, offset, limit);
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/exportExcel")
    public void exportExcel(HttpServletResponse response, Emr_Log_Vo emrLogVo) throws Exception {
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        String[] header = {"日志id","病历清单id","住院号","住院次数","名字","性别","身份证","召回人","召回时间","召回原因","状态","归档状态"};
        String[] fileNames = {"logId","archiveDetailId","inpNo","visitId","name","sex","idNo","creater","createDate","recallReason","state","archivestate"};
        //文件名
        String fileName = "日志信息数据" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xls";
        //构造excel的数据
        List<Emr_Log_Vo> list = logService.selectByCol(emrLogVo);
        ThreadExcelUtils utils = new ThreadExcelUtils(fileName, "", header, fileNames);
        String result=utils.exportExcelToFilePath(response,utils.listConvert(list));
    }

    @ResponseBody
    @RequestMapping(value = "/lastBylogTitle")
    public Emr_Log lastBylogTitle(HttpServletRequest request, HttpServletResponse response, String logTitle) {
        Emr_Log result = logService.lastBylogTitle(logTitle);
        return result;
    }
}
 

