package com.emr.controller;

import com.alibaba.fastjson.JSONObject;
import com.emr.vo.GetTime;
import sun.net.www.protocol.http.HttpURLConnection;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.text.*;
import java.util.*;

import com.alibaba.fastjson.JSONObject;
import com.emr.dao.MedicalRecordHomepageCacheMapper;
import com.emr.entity.Archive_Master_Vo;
import com.emr.entity.MedicalRecordHomepageCache;
import com.emr.entity.MedicalRecordHomepageCacheExample;
import com.emr.entity.OffsetLimitPage;
import com.emr.service.Archive_MasterService;
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 java.text.ParseException;

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

@Controller
@RequestMapping("/medicalOverdue")
public class medicalOverdueController {
    @Autowired
    private Archive_MasterService archiveMasterService;

    @Autowired
    private MedicalRecordHomepageCacheMapper medicalRecordHomepageCacheMapper;

    @RequestMapping("/medicalOverdues")
    public String medicalOverdues(Model model){
        return "medicalOverdueDir/medicalOverdueList";
    }

    @ResponseBody
    @RequestMapping(value = "/medicalOverdueList")
    public OffsetLimitPage medicalOverdueList(HttpServletRequest request, HttpServletResponse response, Archive_Master_Vo archiveMasterVo, Integer offset, Integer limit) {
        OffsetLimitPage result =archiveMasterService.selectOverdue(archiveMasterVo, offset, limit);
        return result;
    }

    /*@ResponseBody
    @RequestMapping(value = "/test")
    public String test(Archive_Master_Vo archiveMasterVo) {
        List<Archive_Master_Vo> list = archiveMasterService.selectOverdue(archiveMasterVo);
        System.out.println(list.toString());
        return list.toString();
    }*/

    @ResponseBody
    @RequestMapping(value = "/exportExcel")
    public void exportExcel(HttpServletResponse response, Archive_Master_Vo archiveMasterVo) throws Exception {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date1=null;
        Date date2=null;
        String overdueDaysTwo = archiveMasterVo.getOverdueDaysTwo();
        if (overdueDaysTwo.equals("")){
            archiveMasterVo.setOverdueDaysTwo("4");
        }else {
            int inum = Integer.parseInt(overdueDaysTwo);
            int inum2=inum+1;
            String s=String.valueOf(inum2);
            archiveMasterVo.setOverdueDaysTwo(s);
        }
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        String[] header = {"住院号","住院次数","姓名","入院科室","出院科室","出院日期","初审日期","初审人","主管医生","是否死亡","间隔天数","超期天数"};
        String[] fileNames = {"inpNo","visitId","name","deptAdmissionTo","deptName","dischargeDateTime","handleTime","handleName","doctorInCharge","deathFlag","diffDay","overTime"};
        //文件名
        String fileName = "初次提交归档列表" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xls";
        //构造excel的数据overdueDays
        List<Archive_Master_Vo> list = archiveMasterService.selectOverdue(archiveMasterVo);
        for (int a = 0; a < list.size(); a++) {
            String overTime1 = list.get(a).getOverTime1();
            String handleTime = list.get(a).getHandleTime();
            String dischargeDateTime = list.get(a).getDischargeDateTime();
            try {
                date1 = format.parse(overTime1);
                date2 = format.parse(handleTime);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            Calendar ca1 = Calendar.getInstance();
            Calendar ca2 = Calendar.getInstance();
            ca1.setTime(date1);
            ca2.setTime(date2);
            long distanceMin = (ca2.getTimeInMillis() - ca1.getTimeInMillis()) / (1000 * 60 * 60 * 24);
            int Min = (int) distanceMin;
            if (Min > 0) {
                list.get(a).setOverTime(Min);
            } else {
                list.get(a).setOverTime(0);
            }
            String deathFlag = list.get(a).getDeathFlag();
            int i = Integer.parseInt(deathFlag);
            if (i==1){
                list.get(a).setDeathFlag("是");
            }else{
                list.get(a).setDeathFlag("否");
            }
        }
        List<MedicalRecordHomepageCache> medicalRecordHomepageCacheList = null;
        if(archiveMasterVo.getOverdueDays()!=null && archiveMasterVo.getOverdueDays()!="") {
            if (list != null && list.size() > 0) {
                for (int i = 0; i < list.size(); i++) {
                    if (list.get(i).getOverdue() != null && !list.get(i).getOverdue().equals("")) {
                        int score = Integer.parseInt(list.get(i).getOverdue()) - Integer.parseInt(archiveMasterVo.getOverdueDays());
                        list.get(i).setScore("" + score);
                    }
//                    if (list.get(i).getDeathFlag() != null && !list.get(i).getDeathFlag().equals("")){
//                        if (list.get(i).getDeathFlag().equals("0")){
//                            list.get(i).setDeathFlag("否");
//                        }else {
//                            list.get(i).setDeathFlag("是");
//                        }
//                    }
                    //2021-09-17
                    String doctorInChargeInHomePage = "";
                    String directorDoctorInHomePage = "";

                    //根据masterId查出该条首页缓存表中content内容
                    MedicalRecordHomepageCacheExample medicalRecordHomepageCacheExample = new MedicalRecordHomepageCacheExample();
                    MedicalRecordHomepageCacheExample.Criteria criteria = medicalRecordHomepageCacheExample.createCriteria();
                    if (!StringUtils.isEmpty(list.get(i).getId())){
                        criteria.andMasterIdEqualTo(list.get(i).getId());
                    }
                    medicalRecordHomepageCacheList = medicalRecordHomepageCacheMapper.selectByExample(medicalRecordHomepageCacheExample);

                    if (medicalRecordHomepageCacheList.size()>0){
                        //查出content
                        String content = medicalRecordHomepageCacheList.get(0).getContent();
                        //根据content内容获取首页中主治医生name、主任（副主任）医生name
                        doctorInChargeInHomePage = JSONObject.parseObject(content).getJSONObject("commonTable").getString("yZY054");
                        directorDoctorInHomePage = JSONObject.parseObject(content).getJSONObject("commonTable1").getString("yZY052");
                    }
//                    //重新赋值主管医生、主任（副主任）医生
//                    if (doctorInChargeInHomePage != null && !doctorInChargeInHomePage.equals("")){
//                        list.get(i).setDoctorInCharge(doctorInChargeInHomePage);
//                    }else {
//                        list.get(i).setDoctorInCharge("首页尚未填写主治医生！");
//                    }

                    if (directorDoctorInHomePage != null && !directorDoctorInHomePage.equals("")){
                        list.get(i).setFirstInstance(directorDoctorInHomePage);
                    }else {
                        list.get(i).setFirstInstance("首页尚未填写主任（副主任）医生！");
                    }
                    //2021-09-17
                }
            }
        }
        ThreadExcelUtils utils = new ThreadExcelUtils(fileName, "", header, fileNames);
        String result=utils.exportExcelToFilePath(response,utils.listConvert(list));
    }


    @ResponseBody
    @RequestMapping(value = "/medicalOverdueList2")
    public OffsetLimitPage medicalOverdueList2(HttpServletRequest request, HttpServletResponse response, Archive_Master_Vo archiveMasterVo, Integer offset, Integer limit) {
        OffsetLimitPage result =archiveMasterService.selectOverdue2(archiveMasterVo, offset, limit);
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/exportExcel2")
    public void exportExcel2(HttpServletResponse response, Archive_Master_Vo archiveMasterVo) throws Exception {
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        String overdueDaysTwo = archiveMasterVo.getOverdueDaysTwo();
        if (overdueDaysTwo.equals("")){
            archiveMasterVo.setOverdueDaysTwo("4");
        }else {
            int inum = Integer.parseInt(overdueDaysTwo);
            int inum2=inum+1;
            String s=String.valueOf(inum2);
            archiveMasterVo.setOverdueDaysTwo(s);
        }
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date1=null;
        Date date2=null;
        String[] header = {"住院号","住院次数","姓名","入院科室","出院科室","出院日期","退回日期","再次提交时间","退回人","主管医生","是否死亡","间隔天数","超期天数"};
        String[] fileNames = {"inpNo","visitId","name","deptAdmissionTo","deptName","dischargeDateTime","handleTime","againTime","handleName","doctorInCharge","deathFlag","diffDay","overTime"};
        //文件名
        String fileName = "住院返修病历列表" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xls";
        //构造excel的数据overdueDays
        List<Archive_Master_Vo> list = archiveMasterService.selectOverdueXls2(archiveMasterVo);
        for (int a = 0; a < list.size(); a++) {
            String overTime1 = list.get(a).getOverTime1();
            String handleTime = list.get(a).getAgainTime();
            try {
                date1 = format.parse(overTime1);
                date2 = format.parse(handleTime);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            Calendar ca1 = Calendar.getInstance();
            Calendar ca2 = Calendar.getInstance();
            ca1.setTime(date1);
            ca2.setTime(date2);
            long distanceMin = (ca2.getTimeInMillis() - ca1.getTimeInMillis()) / (1000 * 60 * 60 * 24);
            int Min = (int) distanceMin;
            if (Min > 0) {
                list.get(a).setOverTime(Min);
            } else {
                list.get(a).setOverTime(0);
            }
        }
        List<MedicalRecordHomepageCache> medicalRecordHomepageCacheList = null;

        if(archiveMasterVo.getOverdueDays()!=null && archiveMasterVo.getOverdueDays()!="") {
            if (list != null && list.size() > 0) {
                for (int i = 0; i < list.size(); i++) {
                    if (list.get(i).getOverdue() != null && !list.get(i).getOverdue().equals("")) {
                        int score = Integer.parseInt(list.get(i).getOverdue()) - Integer.parseInt(archiveMasterVo.getOverdueDays());
                        list.get(i).setScore("" + score);
                    }
                    if (list.get(i).getDeathFlag() != null && !list.get(i).getDeathFlag().equals("")){
                        if (list.get(i).getDeathFlag().equals("0")){
                            list.get(i).setDeathFlag("否");
                        }else {
                            list.get(i).setDeathFlag("是");
                        }
                    }

                    //2021-09-17
                    String doctorInChargeInHomePage = "";
                    String directorDoctorInHomePage = "";

                    //根据masterId查出该条首页缓存表中content内容
                    MedicalRecordHomepageCacheExample medicalRecordHomepageCacheExample = new MedicalRecordHomepageCacheExample();
                    MedicalRecordHomepageCacheExample.Criteria criteria = medicalRecordHomepageCacheExample.createCriteria();
                    if (!StringUtils.isEmpty(list.get(i).getId())){
                        criteria.andMasterIdEqualTo(list.get(i).getId());
                    }
                    medicalRecordHomepageCacheList = medicalRecordHomepageCacheMapper.selectByExample(medicalRecordHomepageCacheExample);

                    if (medicalRecordHomepageCacheList.size()>0){
                        //查出content
                        String content = medicalRecordHomepageCacheList.get(0).getContent();
                        //根据content内容获取首页中主治医生name、主任（副主任）医生name
                        doctorInChargeInHomePage = JSONObject.parseObject(content).getJSONObject("commonTable").getString("yZY054");
                        directorDoctorInHomePage = JSONObject.parseObject(content).getJSONObject("commonTable1").getString("yZY052");
                    }
                    //重新赋值主管医生、主任（副主任）医生
                    if (doctorInChargeInHomePage != null && !doctorInChargeInHomePage.equals("")){
                        list.get(i).setDoctorInCharge(doctorInChargeInHomePage);
                    }else {
                        list.get(i).setDoctorInCharge("首页尚未填写主治医生！");
                    }

                    if (directorDoctorInHomePage != null && !directorDoctorInHomePage.equals("")){
                        list.get(i).setFirstInstance(directorDoctorInHomePage);
                    }else {
                        list.get(i).setFirstInstance("首页尚未填写主任（副主任）医生！");
                    }
                    //2021-09-17
                }
            }
        }
        ThreadExcelUtils utils = new ThreadExcelUtils(fileName, "", header, fileNames);
        String result=utils.exportExcelToFilePath(response,utils.listConvert(list));
    }

    @ResponseBody
    @RequestMapping(value = "/medicalOverdueList3")
    public OffsetLimitPage medicalOverdueList3(HttpServletRequest request, HttpServletResponse response, Archive_Master_Vo archiveMasterVo, Integer offset, Integer limit) {
        OffsetLimitPage result =archiveMasterService.selectOverdue3(archiveMasterVo, offset, limit);
        return result;
    }


    @ResponseBody
    @RequestMapping(value = "/medicalOverdueList4")
    public OffsetLimitPage medicalOverdueList4(HttpServletRequest request, HttpServletResponse response, Archive_Master_Vo archiveMasterVo, Integer offset, Integer limit) {
        OffsetLimitPage result =archiveMasterService.selectOverdue4(archiveMasterVo, offset, limit);
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/exportExcelFirst")
    public void exportExcelFirst(HttpServletResponse response, Archive_Master_Vo archiveMasterVo) throws Exception {
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        String overdueDaysTwo = archiveMasterVo.getOverdueDaysTwo();
        if (overdueDaysTwo.equals("")){
            archiveMasterVo.setOverdueDaysTwo("4");
        }else {
            int inum = Integer.parseInt(overdueDaysTwo);
            int inum2=inum+1;
            String s=String.valueOf(inum2);
            archiveMasterVo.setOverdueDaysTwo(s);
        }
        String[] header = {"住院号","住院次数","姓名","入院科室","出院科室","出院日期","退回人","主管医生","是否死亡","间隔天数","超期天数"};
        String[] fileNames = {"inpNo","visitId","name","deptAdmissionTo","deptName","dischargeDateTime","handleName","doctorInCharge","deathFlag","diffDay","overTime"};
        //文件名
        String fileName = "初次未提交病历" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xls";
        //构造excel的数据overdueDays
        List<Archive_Master_Vo> list = archiveMasterService.selectOverdueFirst(archiveMasterVo);
        for (int a = 0; a < list.size(); a++) {
            String overTime1 = list.get(a).getOverTime1();
            int i = Integer.parseInt(overTime1);
            if (i>0){
                list.get(a).setOverTime(i);
            }else {
                list.get(a).setOverTime(0);
            }
            String deathFlag = list.get(a).getDeathFlag();
            int c = Integer.parseInt(deathFlag);
            if (c==1){
                list.get(a).setDeathFlag("是");
            }else{
                list.get(a).setDeathFlag("否");
            }
        }
        List<MedicalRecordHomepageCache> medicalRecordHomepageCacheList = null;

        if(archiveMasterVo.getOverdueDays()!=null && archiveMasterVo.getOverdueDays()!="") {
            if (list != null && list.size() > 0) {
                for (int i = 0; i < list.size(); i++) {
                    if (list.get(i).getOverdue() != null && !list.get(i).getOverdue().equals("")) {
                        int score = Integer.parseInt(list.get(i).getOverdue()) - Integer.parseInt(archiveMasterVo.getOverdueDays());
                        list.get(i).setScore("" + score);
                    }
                    if (list.get(i).getDeathFlag() != null && !list.get(i).getDeathFlag().equals("")){
                        if (list.get(i).getDeathFlag().equals("0")){
                            list.get(i).setDeathFlag("否");
                        }else {
                            list.get(i).setDeathFlag("是");
                        }
                    }

                    //2021-09-17
                    String doctorInChargeInHomePage = "";
                    String directorDoctorInHomePage = "";

                    //根据masterId查出该条首页缓存表中content内容
                    MedicalRecordHomepageCacheExample medicalRecordHomepageCacheExample = new MedicalRecordHomepageCacheExample();
                    MedicalRecordHomepageCacheExample.Criteria criteria = medicalRecordHomepageCacheExample.createCriteria();
                    if (!StringUtils.isEmpty(list.get(i).getId())){
                        criteria.andMasterIdEqualTo(list.get(i).getId());
                    }
                    medicalRecordHomepageCacheList = medicalRecordHomepageCacheMapper.selectByExample(medicalRecordHomepageCacheExample);

                    if (medicalRecordHomepageCacheList.size()>0){
                        //查出content
                        String content = medicalRecordHomepageCacheList.get(0).getContent();
                        //根据content内容获取首页中主治医生name、主任（副主任）医生name
                        doctorInChargeInHomePage = JSONObject.parseObject(content).getJSONObject("commonTable").getString("yZY054");
                        directorDoctorInHomePage = JSONObject.parseObject(content).getJSONObject("commonTable1").getString("yZY052");
                    }
                    //重新赋值主管医生、主任（副主任）医生
                    if (doctorInChargeInHomePage != null && !doctorInChargeInHomePage.equals("")){
                        list.get(i).setDoctorInCharge(doctorInChargeInHomePage);
                    }else {
                        list.get(i).setDoctorInCharge("首页尚未填写主治医生！");
                    }

                    if (directorDoctorInHomePage != null && !directorDoctorInHomePage.equals("")){
                        list.get(i).setFirstInstance(directorDoctorInHomePage);
                    }else {
                        list.get(i).setFirstInstance("首页尚未填写主任（副主任）医生！");
                    }
                    //2021-09-17
                }
            }
        }
        ThreadExcelUtils utils = new ThreadExcelUtils(fileName, "", header, fileNames);
        String result=utils.exportExcelToFilePath(response,utils.listConvert(list));
    }
    @ResponseBody
    @RequestMapping(value = "/exportExcelFirst1")
    public void exportExcelFirst1(HttpServletResponse response, Archive_Master_Vo archiveMasterVo) throws Exception {
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        String overdueDaysTwo = archiveMasterVo.getOverdueDaysTwo();
        if (overdueDaysTwo.equals("")){
            archiveMasterVo.setOverdueDaysTwo("4");
        }else {
            int inum = Integer.parseInt(overdueDaysTwo);
            int inum2=inum+1;
            String s=String.valueOf(inum2);
            archiveMasterVo.setOverdueDaysTwo(s);
        }
        String[] header = {"住院号","住院次数","姓名","入院科室","出院科室","出院日期","最后退回时间","主管医生","是否死亡","间隔天数","超期天数"};
        String[] fileNames = {"inpNo","visitId","name","deptAdmissionTo","deptName","dischargeDateTime","handleTimeMax1","doctorInCharge","deathFlag","diffDay","overTime"};
        //文件名
        String fileName = "返修未提交病历" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xls";
        //构造excel的数据overdueDays
        List<Archive_Master_Vo> list = archiveMasterService.selectOverdueFirst1(archiveMasterVo);
        for (int a = 0; a < list.size(); a++) {
            String overTime1 = list.get(a).getOverTime1();
            int i = Integer.parseInt(overTime1);
            if (i>0){
                list.get(a).setOverTime(i);
            }else {
                list.get(a).setOverTime(0);
            }
            String deathFlag = list.get(a).getDeathFlag();
            int c = Integer.parseInt(deathFlag);
            if (c==1){
                list.get(a).setDeathFlag("是");
            }else{
                list.get(a).setDeathFlag("否");
            }
        }
        List<MedicalRecordHomepageCache> medicalRecordHomepageCacheList = null;

        if(archiveMasterVo.getOverdueDays()!=null && archiveMasterVo.getOverdueDays()!="") {
            if (list != null && list.size() > 0) {
                for (int i = 0; i < list.size(); i++) {
                    if (list.get(i).getOverdue() != null && !list.get(i).getOverdue().equals("")) {
                        int score = Integer.parseInt(list.get(i).getOverdue()) - Integer.parseInt(archiveMasterVo.getOverdueDays());
                        list.get(i).setScore("" + score);
                    }
                    if (list.get(i).getDeathFlag() != null && !list.get(i).getDeathFlag().equals("")){
                        if (list.get(i).getDeathFlag().equals("0")){
                            list.get(i).setDeathFlag("否");
                        }else {
                            list.get(i).setDeathFlag("是");
                        }
                    }

                    //2021-09-17
                    String doctorInChargeInHomePage = "";
                    String directorDoctorInHomePage = "";

                    //根据masterId查出该条首页缓存表中content内容
                    MedicalRecordHomepageCacheExample medicalRecordHomepageCacheExample = new MedicalRecordHomepageCacheExample();
                    MedicalRecordHomepageCacheExample.Criteria criteria = medicalRecordHomepageCacheExample.createCriteria();
                    if (!StringUtils.isEmpty(list.get(i).getId())){
                        criteria.andMasterIdEqualTo(list.get(i).getId());
                    }
                    medicalRecordHomepageCacheList = medicalRecordHomepageCacheMapper.selectByExample(medicalRecordHomepageCacheExample);

                    if (medicalRecordHomepageCacheList.size()>0){
                        //查出content
                        String content = medicalRecordHomepageCacheList.get(0).getContent();
                        //根据content内容获取首页中主治医生name、主任（副主任）医生name
                        doctorInChargeInHomePage = JSONObject.parseObject(content).getJSONObject("commonTable").getString("yZY054");
                        directorDoctorInHomePage = JSONObject.parseObject(content).getJSONObject("commonTable1").getString("yZY052");
                    }
                    //重新赋值主管医生、主任（副主任）医生
                    if (doctorInChargeInHomePage != null && !doctorInChargeInHomePage.equals("")){
                        list.get(i).setDoctorInCharge(doctorInChargeInHomePage);
                    }else {
                        list.get(i).setDoctorInCharge("首页尚未填写主治医生！");
                    }

                    if (directorDoctorInHomePage != null && !directorDoctorInHomePage.equals("")){
                        list.get(i).setFirstInstance(directorDoctorInHomePage);
                    }else {
                        list.get(i).setFirstInstance("首页尚未填写主任（副主任）医生！");
                    }
                    //2021-09-17
                }
            }
        }
        ThreadExcelUtils utils = new ThreadExcelUtils(fileName, "", header, fileNames);
        String result=utils.exportExcelToFilePath(response,utils.listConvert(list));
    }
//    /**
//     * 两个日期相减
//     * @param beginDateStr
//     * @param endDateStr
//     * @return
//     */
//    public static long getDaySub(String beginDateStr,String endDateStr){
//        long day=0;
//        SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd");
//        Date beginDate;
//        Date endDate;
//        try{
//            beginDate = format.parse(beginDateStr);
//            endDate= format.parse(endDateStr);
//            day=(endDate.getTime()-beginDate.getTime())/(24*60*60*1000);
//            //System.out.println("相隔的天数="+day);
//        } catch (ParseException e){
//            // TODO 自动生成 catch 块
//            e.printStackTrace();
//        }
//        return day+1;
//    }
//    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//    /*
//     * 传入查询工作日api地址,用于查询当天是否是工作日，返回的是JSON格式的数据，需要在代码中进行转换。
//     * */
//    public static  String getData(String addess){
//        URL url = null;
//        HttpURLConnection httpConn = null;
//        BufferedReader in = null;
//        StringBuffer sb = new StringBuffer();
//        try{
//            url = new URL(addess);
//            in = new BufferedReader(new InputStreamReader(url.openStream(),"utf-8") );
//            String str = null;
//            while((str = in.readLine()) != null) {
//                sb.append( str );
//            }
//        } catch (Exception ex) {
//            ex.printStackTrace();
//        } finally{
//            try{
//                if(in!=null) {
//                    in.close();
//                }
//            }catch(IOException ex) {
//                ex.printStackTrace();
//            }
//        }
//        String  data =sb.toString();
//        return data;
//    }
//    /*
//     * 计算两个时间点的工作日
//     *
//     * */
//    @ResponseBody
//    @RequestMapping(value = "/getTimeoutDay")
//    public static long getWorkDayBetweenStartAndEnd(GetTime getTime) throws ParseException {
//        List<GetTime> getTimeList= new ArrayList<>();
//        getTimeList.add(getTime);
//        int timeoutDay = 0;
//        //工作日
//        long workDay = 0;
//        //先算出两个时间中间的天数
//        long dayOfMiddle = getDaySub(getTime.getStartTime(),getTime.getEndTime());
//        long l = dayOfMiddle - 1;
//        System.out.println("dayOfMiddle::::"+dayOfMiddle);
//        //从开始时间起，算出中间的周末和及假日
//        for (int i = 0; i < l; i++) {
//            Date now = sdf.parse(getTime.getStartTime());
//            Calendar c = Calendar.getInstance();
//            c.setTime(now);
//            c.set(Calendar.DATE, c.get(Calendar.DATE) + i);
//            String urlData = sdf.format(c.getTime());
//            System.out.println("urlData::::"+urlData);
//            String urlDress = "http://timor.tech/api/holiday/info/" + urlData;
//
//            System.out.println("urlDress::::"+urlDress);
//            //获得当前是否是工作日
//            String data = getData(urlDress);
//            System.out.println("data::::"+data);
//            JSONObject json = getjson(data);
//            System.out.println("json:::::"+json);
//            String value = json.get("data").toString();
//            if (value.equals("0")) {
//                workDay++;
//            }
//            timeoutDay = Integer.parseInt(String.valueOf(workDay - 3));
//        }
//        if (timeoutDay < 0) {
//            return 0;
//        } else {
//            return timeoutDay;
//        }
//    }
//    //json串转化为json对象
//    public static JSONObject getjson(String data) {
//        JSONObject json = JSONObject.parseObject(data);
//        return json;
//    }

    /*
     * 计算两个时间点的工作日
     *
    * */

   @RequestMapping(value = "/getTimeoutDay")
    public long getWorkDayBetweenStartAndEnd(GetTime getTime) throws ParseException {
       int i = archiveMasterService.selectWorkDateNum(getTime);
       return i;
   }

}
