
<%@ page import="java.util.Map" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="com.engine.common.util.ParamUtil" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="javax.ws.rs.core.Context" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="java.time.LocalDate" %>
<%@ page import="java.time.format.DateTimeFormatter" %>
<%@ page import="java.time.temporal.ChronoUnit" %>
<%@ page import="weaver.general.StringUtil" %>
<%@ page import="java.time.LocalDateTime" %>
<%@ page import="java.util.Arrays" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>


<%
    out.print(getVersionInfo(request,response));
%>
<%!
    public String getVersionInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        Map<String, Object> paramMap = ParamUtil.request2Map(request);
        RecordSet recordSet = new RecordSet();


        String userId = (String) paramMap.get("userId");
        String[] hlduserIDS = {"29","25","27","28","26","24","23","22"};
        // if (StringUtil.isEmpty(userId)){
        //     return JSONObject.toJSONString(new Result(500,"人员id为空"));
        // }
        String sql = "select * from uf_personreport where ry = ? and nd = ? order by id desc";
        // LocalDate now = LocalDate.now();
        // int year = now.getYear();
        recordSet.executeQuery(sql,userId,2023);
        HashMap<String, String> firstMap = new HashMap<>();
        String inputDateStr = "2023-08-07";

        // 解析输入日期
        LocalDate inputDate = LocalDate.parse(inputDateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        // 转换格式
        String outputDateStr = inputDate.format(DateTimeFormatter.ofPattern("yyyy年M月d日"));
        // 计算距离今天的天数
        LocalDate today = LocalDate.now();
        long daysBetween = ChronoUnit.DAYS.between(inputDate, today);
        // firstMap.put("ksrq",outputDateStr);
        // firstMap.put("jjts",daysBetween+"");


        System.out.println("距离今天的天数: " + daysBetween);
        HashMap<String, String> secondMap = new HashMap<>();
        HashMap<String, String> thirdMap = new HashMap<>();
        HashMap<String, String> fourthMap = new HashMap<>();
        HashMap<String, String> fifthMap = new HashMap<>();
        HashMap<String, String> sixthMap = new HashMap<>();
        HashMap<String, String> seventhMap = new HashMap<>();
        HashMap<String, String> eighthMap = new HashMap<>();
        HashMap<String, Object> ninthMap = new HashMap<>();
        if(recordSet.next()){
            secondMap.put("ksrq",outputDateStr);
            secondMap.put("jjts",daysBetween+"");
            secondMap.put("ddcs",Util.null2String(recordSet.getString("ddcs")));
            secondMap.put("yygs",Util.null2String(recordSet.getString("yygs")));
            secondMap.put("gwbllcxs",Util.null2String(recordSet.getString("gwbllcxs")));
            secondMap.put("swsplcxs",Util.null2String(recordSet.getString("swsplcxs")));
            thirdMap.put("tgwzzs",Util.null2String(recordSet.getString("tgwzzs")));
            thirdMap.put("zshywz1",Util.null2String(recordSet.getString("zshywz1")));
            thirdMap.put("zshywz2",Util.null2String(recordSet.getString("zshywz2")));
            thirdMap.put("zshywz3",Util.null2String(recordSet.getString("zshywz3")));
            fourthMap.put("jsxxzongshu",Util.null2String(recordSet.getString("jsxxzongshu")));
            fourthMap.put("ysxljfqhycs",Util.null2String(recordSet.getString("ysxljfqhycs")));
            fourthMap.put("grhycycs",Util.null2String(recordSet.getString("grhycycs")));
            fourthMap.put("zjgxwd",Util.null2String(recordSet.getString("zjgxwd")));
            fourthMap.put("grwdgx",Util.null2String(recordSet.getString("grwdgx")));
            fourthMap.put("xwhycs",Util.null2String(recordSet.getString("xwhycs")));
            try {
                if (Arrays.asList(hlduserIDS).contains(userId)){
                    fourthMap.put("wlsfzs","0");
                }else {
                    fourthMap.put("wlsfzs","1");
                }
            }catch (Exception e){
                e.printStackTrace();
            }
            fifthMap.put("sktxysfxs",Util.null2String(recordSet.getString("sktxysfxs")));
            fifthMap.put("sktxcycs",Util.null2String(recordSet.getString("sktxcycs")));
            sixthMap.put("gczgw",Util.null2String(recordSet.getString("gczgw")));
            sixthMap.put("ljjyzz",Util.null2String(recordSet.getString("ljjyzz")));
            sixthMap.put("ljjp",Util.null2String(recordSet.getString("ljjp")));
            sixthMap.put("jjrclgw",Util.null2String(recordSet.getString("jjrclgw")));
            sixthMap.put("qnljclgw",Util.null2String(recordSet.getString("qnljclgw")));
            sixthMap.put("cgbl",Util.null2String(recordSet.getString("cgbl")));
            String dycclgwrq = Util.null2String(recordSet.getString("dycclgwrq"));
            if (!(StringUtil.isEmpty(dycclgwrq))){
                LocalDate date = LocalDate.parse(dycclgwrq, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                sixthMap.put("dycclgwrqMM",date.getMonthValue()+"");
                sixthMap.put("dycclgwrqDD",date.getDayOfMonth()+"");
            }else {
                sixthMap.put("dycclgwrqMM","");
                sixthMap.put("dycclgwrqDD","");
            }
            sixthMap.put("dycclgwrq",Util.null2String(recordSet.getString("dycclgwrq")));
            String clgwzwrq = Util.null2String(recordSet.getString("clgwzwrq"));
            if (!(StringUtil.isEmpty(dycclgwrq))){
                LocalDateTime date2 = LocalDateTime.parse(clgwzwrq, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
                sixthMap.put("clgwzwrqMM",date2.getMonthValue()+"");
                sixthMap.put("clgwzwrqDD",date2.getDayOfMonth()+"");
            }else {
                sixthMap.put("clgwzwrqMM","");
                sixthMap.put("clgwzwrqDD","");
            }
            sixthMap.put("clgwzwrq",Util.null2String(recordSet.getString("clgwzwrq")));

            seventhMap.put("ljsyslcs",Util.null2String(recordSet.getString("ljsyslcs")));
            seventhMap.put("qgzydf",Util.null2String(recordSet.getString("qgzydf")));
            seventhMap.put("swsplcgs",Util.null2String(recordSet.getString("swsplcgs")));
            seventhMap.put("nddjlzgyy",Util.null2String(recordSet.getString("nddjlzgyy")));
            seventhMap.put("ljdjcs",Util.null2String(recordSet.getString("ljdjcs")));
            seventhMap.put("zaydyy",Util.null2String(recordSet.getString("zaydyy")));
            seventhMap.put("ljsycs",Util.null2String(recordSet.getString("ljsycs")));
            eighthMap.put("pjmrzxrs",Util.null2String(recordSet.getString("pjmrzxrs")));
            eighthMap.put("pjmrzxrszb",Util.null2String(recordSet.getString("pjmrzxrszb")));
            eighthMap.put("ljdloacs",Util.null2String(recordSet.getString("ljdloacs")));
            // eighthMap.put("dlcscgrszb",Util.null2String(recordSet.getString("dlcscgrszb")));
        }
        String gjc = Util.null2String(recordSet.getString("gjc"));
        String sfwxld = Util.null2String(recordSet.getString("sfwxld"));
        ninthMap.put("sfwxld",sfwxld);
        if ("统筹全局".equals(gjc)){
            ninthMap.put("gjc","统筹全局");
            ninthMap.put("filed1",Util.null2String(recordSet.getString("sktxcycs")));
            ninthMap.put("filed2","2023-12-05 23:24:45");
        }else if("天行守护者".equals(gjc)){
            ninthMap.put("gjc","天行守护者");
            ninthMap.put("filed1",Util.null2String(recordSet.getString("qnljclgw")));
            ninthMap.put("filed2","2023-12-05");
            ninthMap.put("filed3","27");
        }else if("勇担重担实干家".equals(gjc)){
            ninthMap.put("gjc","勇担重担实干家");
            ninthMap.put("filed1",Util.null2String(recordSet.getString("grfsxxs")));
            ninthMap.put("filed2",Util.null2String(recordSet.getString("zwdlrq")));
        }else if("智慧OA最亲密的朋友".equals(gjc)){
            ninthMap.put("gjc","智慧OA最亲密的朋友");
            ninthMap.put("filed1",Util.null2String(recordSet.getString("ljdloacs")));
            ninthMap.put("filed2","90%");
        }else if("社交天花板".equals(gjc)){
            ninthMap.put("gjc","社交天花板");
            ninthMap.put("filed1",112);
            ninthMap.put("filed2","39");
            ninthMap.put("filed3","90%");
        }else if("人形公文处理机".equals(gjc)){
            ninthMap.put("gjc","人形公文处理机");
            ninthMap.put("filed1",Util.null2String(recordSet.getString("qnljclgw")));
            ninthMap.put("filed2","90%");
        }else if("宝藏事务挖掘机".equals(gjc)){
            ninthMap.put("gjc","宝藏事务挖掘机");
            ninthMap.put("filed1",Util.null2String(recordSet.getString("grswsps")));
            ninthMap.put("filed2","90%");
        }else if("走南闯北 遥遥领先".equals(gjc)){
            ninthMap.put("gjc","走南闯北 遥遥领先");
            ninthMap.put("filed1","90%");
        }else if("知识分享之光".equals(gjc)){
            ninthMap.put("gjc","知识分享之光");
            ninthMap.put("filed1",Util.null2String(recordSet.getString("grwdgx")));
            ninthMap.put("filed2","90%");
        }else if("会议守护者".equals(gjc)) {
            ninthMap.put("gjc", "会议守护者");
            ninthMap.put("filed1", Util.null2String(recordSet.getString("grhycycs")));
            ninthMap.put("filed2", "90%");
        }else if("智慧OA探索家".equals(gjc)){
            ninthMap.put("gjc","智慧OA探索家");
        }else if("夙夜在公,庭无留事1".equals(gjc)){
            ninthMap.put("gjc","夙夜在公,庭无留事");
            ninthMap.put("flag","1");
            ninthMap.put("filed1",Util.null2String(recordSet.getString("qnljclgw")));
            ninthMap.put("filed2",Util.null2String(recordSet.getString("cgbl")));
        }else if("夙夜在公,庭无留事2".equals(gjc)){
            ninthMap.put("gjc","夙夜在公,庭无留事");
            ninthMap.put("flag","2");
            ninthMap.put("filed1",Util.null2String(recordSet.getString("qnljclgw")));
            ninthMap.put("filed2",Util.null2String(recordSet.getString("blgwzddyt")));
            ninthMap.put("filed3",Util.null2String(recordSet.getString("ytnblgwzds")));
        }else if("兢兢业业,案无留牍".equals(gjc)){
            ninthMap.put("gjc","兢兢业业,案无留牍");
            ninthMap.put("filed1",Util.null2String(recordSet.getString("qnljclgw")));
            ninthMap.put("filed2",Util.null2String(recordSet.getString("blgwzddyt")));
            ninthMap.put("filed3",Util.null2String(recordSet.getString("ytnblgwzds")));
        }else if("不辞辛劳,雷厉风行".equals(gjc)){
            ninthMap.put("gjc","不辞辛劳,雷厉风行");
            ninthMap.put("filed1",Util.null2String(recordSet.getString("qnljclgw")));
            ninthMap.put("filed2",Util.null2String(recordSet.getString("blgwzddyt")));
            ninthMap.put("filed3",Util.null2String(recordSet.getString("ytnblgwzds")));
        }

        if ("0".equals(sfwxld)){
            // ninthMap.put("gjc","不辞辛劳,雷厉风行");
            ninthMap.put("filed1",Util.null2String(recordSet.getString("xxrdlcs")));
            ninthMap.put("filed2",Util.null2String(recordSet.getString("xxrdlcscgbl")));
            ninthMap.put("filed3",Util.null2String(recordSet.getString("sktx")));
        }
        ninthMap.put("url",getGJCUrl(gjc));
        apidatas.put("first",firstMap);
        apidatas.put("second",secondMap);
        apidatas.put("third",thirdMap);
        apidatas.put("fourth",fourthMap);
        apidatas.put("fifth",fifthMap);
        apidatas.put("sixth",sixthMap);
        apidatas.put("seventh",seventhMap);
        apidatas.put("eighth",eighthMap);
        apidatas.put("ninth",ninthMap);
        Map<String, Object> Result = new HashMap<>();
        Result.put("code",200);
        Result.put("data",apidatas);
        return JSONObject.toJSONString(Result) ;
    }

    private String getGJCUrl(String gjc) {
        RecordSet recordSet = new RecordSet();
        recordSet.executeQuery("select * from uf_reportkeyword where name = ?" ,gjc);
        recordSet.next();
        return recordSet.getString("url");

    }
%>