<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="java.time.LocalDate" %>
<%@ page import="java.time.format.DateTimeFormatter" %>
<%@ page import="java.time.temporal.TemporalAdjusters" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%

    User user = HrmUserVarify.getUser(request, response);
    if(user==null) {
        response.sendRedirect("/login/Login.jsp");
        return;
    }

    RecordSet rs = new RecordSet();
    String cjrbm = request.getParameter("cjrbm");
    String pbyf = request.getParameter("pbyf");
    String yg = request.getParameter("yg");
    out.print("cjrbm:"+cjrbm+"</br>");
    out.print("pbyf:"+pbyf+"</br>");
    out.print("yg:"+yg+"</br>");

    String startdate = "";
    String enddate = "";

    if(StringUtils.isNotBlank(pbyf) && pbyf.length() == 7){

//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//        LocalDate dateTime = LocalDate.parse(pbyf+"-01", formatter);
//        LocalDate firstDayOfMonth = dateTime.with(TemporalAdjusters.firstDayOfMonth());
//        LocalDate lastDayOfMonth = dateTime.with(TemporalAdjusters.lastDayOfMonth());
//        startdate = firstDayOfMonth.toString();
//        enddate = lastDayOfMonth.toString();
//        out.print("startdate:"+startdate+"</br>");
//        out.print("enddate:"+enddate+"</br>");

        if(StringUtils.isNotBlank(cjrbm)) {

            String sql =" select ydsxrq " +
                    " from uf_ygddxx " +
                    " where left(ydsxrq,7) = '"+pbyf+"' "+
                    " and xm = "+ yg +
                    " and ydhbm= "+ cjrbm+
                    " and xm in( select id from hrmresource  where status in(0,1,2,3) and jobtitle not in(select id from hrmjobtitles where jobtitlename in('营运经理'))) ";
            out.print("sql:"+sql+"</br>");

            rs.executeQuery(sql);
            if(rs.next()){
                String ydsxrq = Util.null2String(rs.getString("ydsxrq"));
                if(StringUtils.isNotBlank(ydsxrq)){
                    enddate = ydsxrq;
                }
            }
            out.print("enddate:"+enddate+"</br>");
            sql =" select ydsxrq " +
                    " from uf_ygddxx " +
                    " where left(ydsxrq,7) = '"+pbyf+"' "+
                    " and xm ="+ yg +
                    " and ydhbm="+cjrbm+
                    " and xm in( select id from hrmresource  where status in(0,1,2,3) and jobtitle not in(select id from hrmjobtitles where jobtitlename in('营运经理'))) ";
            rs.executeQuery(sql);
            out.print("sql:"+sql+"</br>");
            if(rs.next()){
                String ydsxrq = Util.null2String(rs.getString("ydsxrq"));
                if(StringUtils.isNotBlank(ydsxrq)){
                    startdate = ydsxrq;
                }
            }

            out.print("startdate:"+startdate+"</br>");

        }
    }

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("startdate",startdate);
    jsonObject.put("enddate",enddate);

%>
<%=jsonObject.toJSONString() %>



