import ComprehensiveWorkingHourServiceImpl.beforlog;
import com.alibaba.fastjson.JSONObject;
import com.engine.jucailinkq.attendance.attendanceanalysis.service.AttendanceSummaryService;
import com.engine.jucailinkq.attendance.attendanceanalysis.service.impl.AttendanceSummaryServiceImpl;
import com.engine.jucailinkq.attendance.component.ImportAndExport.service.ExcelExportImportService;
import com.engine.jucailinkq.attendance.component.ImportAndExport.service.impl.ExcelExportImportServiceImpl;
import com.engine.jucailinkq.attendance.component.ImportAndExport.service.param.ImportParam;
import com.engine.jucailinkq.attendance.component.persongroup.service.SchedulingResultsService;
import com.engine.jucailinkq.attendance.component.persongroup.service.impl.SchedulingResultsServiceImpl;
import com.engine.jucailinkq.attendance.workflow.service.AskForLeaveService;
import com.engine.jucailinkq.attendance.workflow.service.impl.AskForLeaveServiceImpl;
import com.engine.jucailinkq.common.util.CommonUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.jucailinkq.attendance.attendanceanalysis.service.AttendanceSummaryService;
import com.engine.jucailinkq.common.util.DbTools;
import com.google.common.collect.Maps;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.xmlrpc.webserver.HttpServletRequestImpl;
import org.apache.xmlrpc.webserver.HttpServletResponseImpl;
import org.junit.Test;
import weaver.general.Util;
import weaver.hrm.User;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.Socket;
import java.security.Principal;
import java.util.*;

/**
 * @Author: sy
 * @Description:
 * @Date: 2024/5/13
 **/
public class Test_sy2 extends beforlog {

    private AttendanceSummaryService getAttendanceSummaryService(User user) {
        return ServiceUtil.getService(AttendanceSummaryServiceImpl.class,user);
    }
    private ExcelExportImportService getExcelExportImportService(User user) {
        return ServiceUtil.getService(ExcelExportImportServiceImpl.class,user);
    }

    private AskForLeaveService getAskForLeaveService(User user) {
        return ServiceUtil.getService(AskForLeaveServiceImpl.class,user);
    }
    @Test
    public void test() throws Exception {
        User user = new User();
        user.setUid(1);
        user.setLanguage(7);
//        String sql = "select id,jqid,sxrq,ktsc,yxsc,wxsc,yqsxrq,ztsc from uf_jcl_kq_jqye order by yqsxrq, modedatacreatedate, modedatacreatetime";
//        List<Map<String, Object>> holidayBalanceList = DbTools.getSqlToList(sql);
//        //获取延期失效日期最晚的一条
//        Map<String, Object> maxYqsxrqMap = holidayBalanceList.stream().reduce((m1, m2) -> m2).orElse(null);

        //批量请假功能-批量生成明细表1请假明细
        //{"szjg":"","qjr":"81","jqlx":"127","mtcfsdjq":"1","ksrq":"2024-07-01","jsrq":"2024-07-05","kssj":"14:29","jssj":"18:00","cxjqj":"1","qjsc":"5.00"}
        Map<String, Object> params = new HashMap<>();
        Map<String,String> mainTableData = new HashMap<>();
//        mainTableData.put("qjr", "41,42,43");
//        mainTableData.put("ksrq", "2024-06-28");
//        mainTableData.put("jsrq", "2024-07-03");
//        mainTableData.put("jqlx", "127");
        mainTableData.put("qjr", "81");
        mainTableData.put("ksrq", "2024-07-01");
        mainTableData.put("jsrq", "2024-07-05");
        mainTableData.put("jqlx", "127");
        mainTableData.put("mtcfsdjq", "1");

//        //请假方式：全天
//        mainTableData.put("qjsc", null);
//        mainTableData.put("kssj", null);
//        mainTableData.put("jssj", null);
//        mainTableData.put("cxjqj", "0");
//        //请假方式：指定时间区间
//        mainTableData.put("qjsc", "");
//        mainTableData.put("kssj", "03:23");
//        mainTableData.put("jssj", "02:00");
//        mainTableData.put("cxjqj", "1");
        //请假方式：指定时间长度
        mainTableData.put("qjsc", "3.1");
        mainTableData.put("kssj", null);
        mainTableData.put("jssj", null);
        mainTableData.put("cxjqj", "3");
//        //请假方式：半天
//        mainTableData.put("qjsc", null);
//        mainTableData.put("kssj", null);
//        mainTableData.put("jssj", null);
//        mainTableData.put("cxjqj", "2");

        List<Map<String, String>> detailTableData = new ArrayList<>();
        Map<String, String> detailDataItem = new HashMap<>();
//        detailDataItem.put("qjlx", "145");detailDataItem.put("jqye", "599_8.0");detailDataItem.put("ksrq", "2024-06-28");detailDataItem.put("qjr", "41");detailDataItem.put("qjsc", "8.0");
//        detailTableData.add(detailDataItem);detailDataItem = new HashMap<>();
//        detailDataItem.put("qjlx", "145");detailDataItem.put("jqye", "599_6.0,602_2.0");detailDataItem.put("ksrq", "2024-07-01");detailDataItem.put("qjr", "41");detailDataItem.put("qjsc", "8.0");
//        detailTableData.add(detailDataItem);detailDataItem = new HashMap<>();
//        detailDataItem.put("qjlx", "145");detailDataItem.put("jqye", "602_5.0");detailDataItem.put("ksrq", "2024-07-02");detailDataItem.put("qjr", "41");detailDataItem.put("qjsc", "5.0");
//        detailTableData.add(detailDataItem);detailDataItem = new HashMap<>();
//        detailDataItem.put("qjlx", "127");detailDataItem.put("jqye", null);detailDataItem.put("ksrq", "2024-07-02");detailDataItem.put("qjr", "41");detailDataItem.put("qjsc", "3.0");
//        detailTableData.add(detailDataItem);detailDataItem = new HashMap<>();
//
//        detailDataItem.put("qjlx", "145");detailDataItem.put("jqye", "597_8.0");detailDataItem.put("ksrq", "2024-06-28");detailDataItem.put("qjr", "42");detailDataItem.put("qjsc", "8.0");
//        detailTableData.add(detailDataItem);detailDataItem = new HashMap<>();
//        detailDataItem.put("qjlx", "145");detailDataItem.put("jqye", "597_4.0,603_4.0");detailDataItem.put("ksrq", "2024-07-01");detailDataItem.put("qjr", "42");detailDataItem.put("qjsc", "8.0");
//        detailTableData.add(detailDataItem);detailDataItem = new HashMap<>();
//        detailDataItem.put("qjlx", "145");detailDataItem.put("jqye", "603_2.0");detailDataItem.put("ksrq", "2024-07-02");detailDataItem.put("qjr", "42");detailDataItem.put("qjsc", "2.0");
//        detailTableData.add(detailDataItem);detailDataItem = new HashMap<>();
//        detailDataItem.put("qjlx", "127");detailDataItem.put("jqye", null);detailDataItem.put("ksrq", "2024-07-02");detailDataItem.put("qjr", "42");detailDataItem.put("qjsc", "6.0");
//        detailTableData.add(detailDataItem);detailDataItem = new HashMap<>();
//
//        detailDataItem.put("qjlx", "145");detailDataItem.put("jqye", "598_8.0");detailDataItem.put("ksrq", "2024-06-28");detailDataItem.put("qjr", "43");detailDataItem.put("qjsc", "8.0");
//        detailTableData.add(detailDataItem);detailDataItem = new HashMap<>();
//        detailDataItem.put("qjlx", "145");detailDataItem.put("jqye", "598_5.0,601_3.0");detailDataItem.put("ksrq", "2024-07-01");detailDataItem.put("qjr", "43");detailDataItem.put("qjsc", "8.0");
//        detailTableData.add(detailDataItem);detailDataItem = new HashMap<>();
//        detailDataItem.put("qjlx", "145");detailDataItem.put("jqye", "601_7.0");detailDataItem.put("ksrq", "2024-07-02");detailDataItem.put("qjr", "43");detailDataItem.put("qjsc", "7.0");
//        detailTableData.add(detailDataItem);detailDataItem = new HashMap<>();
//        detailDataItem.put("qjlx", "127");detailDataItem.put("jqye", null);detailDataItem.put("ksrq", "2024-07-02");detailDataItem.put("qjr", "43");detailDataItem.put("qjsc", "1.0");
//        detailTableData.add(detailDataItem);
//[{"ksrq":"2024-07-02","kssj":"","jsrq":"2024-07-02","jssj":"","qjsc":"5.00","qtj":"0","btj":"0","cxqj":"","cxly":"","cxid":"","qjr":"81","qjlx":"127","jqye":""},
// {"ksrq":"2024-07-03","kssj":"","jsrq":"2024-07-03","jssj":"","qjsc":"5.00","qtj":"0","btj":"0","cxqj":"","cxly":"","cxid":"","qjr":"81","qjlx":"127","jqye":""}]
        detailDataItem.put("qjlx", "127");detailDataItem.put("jqye", "");detailDataItem.put("ksrq", "2024-07-02");detailDataItem.put("qjr", "81");detailDataItem.put("qjsc", "5");
        detailTableData.add(detailDataItem);detailDataItem = new HashMap<>();
        detailDataItem.put("qjlx", "127");detailDataItem.put("jqye", "");detailDataItem.put("ksrq", "2024-07-03");detailDataItem.put("qjr", "81");detailDataItem.put("qjsc", "5");
        detailTableData.add(detailDataItem);

        params.put("mainTableData", mainTableData);
//        params.put("detailTableData", detailTableData);
        getAskForLeaveService(user).generateLeaveInfoList(params);


        ////////////////
//        //测试获得会使用的排班结果
//        SchedulingResultsService schedulingResultsService = ServiceUtil.getService(SchedulingResultsServiceImpl.class);
//        Map<String,Object> params = new HashMap<>();
//        params.put("tableName", "uf_pbjg");
//        params.put("startDate", "2024-06-10");
//        params.put("endDate", "2024-06-20");
//        params.put("pblx", "0");
//        params.put("current", "1");
//        params.put("pageSize", "999");
//        params.put("recurrence", "1");
//        params.put("pbdx", "23");
//        Map<String,Object> schedulingResultsMap = schedulingResultsService.queryDataTableActualUse(params);


//        List<String> getEmpGroupUserIds = CommonUtil.getEmpGroupUserIds("2");
        int i= 0;
//        //导出出勤汇总报表
//        Map<String,Object> param = Maps.newHashMap();
//        param.put("data","{\"pageIndex\":1,\"typeselect\":\"3\",\"viewScope\":\"0\",\"status\":\"8\",\"isNoAccount\":\"0\",\"attendanceSerial\":\"\",\"showColumns\":\"subcompany,kqxm_1,kqxm_2,kqxm_3,kqxm_4,kqxm_5,kqxm_6,kqxm_7,kqxm_8,kqxm_100,kqxm_121\"}");
//        Map<String, Object> apidatas = getAttendanceSummaryService(user).exportCqSummaryReport(param, null, null);
//        JSONObject.toJSONString(apidatas);
//        //刷新考勤日报视图
//        Map<String, Object> apidatas = getAttendanceSummaryService(user).refreshViewAttendanceDaily();
//        JSONObject.toJSONString(apidatas);
//        //日历排班导出
//        Map<String,Object> param = Maps.newHashMap();
//        param.put("dateTime","2024-06");
//        param.put("tableName","uf_pbjg");
//        param.put("type","0");
//        param.put("subcompany","");
//        param.put("deparment","");
//        param.put("employeeIds","");
//        param.put("pageindex","1");
//        param.put("pageSize","10");
//        param.put("total","");
//        XSSFWorkbook workbook = getExcelExportImportService(user).exportSchedule(param);
//        StreamingOutput output = outputStream -> {
//            workbook.write(outputStream);
//            outputStream.flush();
//        };
//        Response response = Response.ok(output).header("Content-disposition", "attachment;filename=" + "日历排班列表").header("Cache-Control", "no-cache").build();
//        System.out.println("111");
//       //日历排班导入
//        ImportParam importParam = new ImportParam();
//        importParam.setImageId("14086");
//        getExcelExportImportService(user).importSchedule(importParam);
    }

}
