<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="com.time.util.DateUtil" %>
<%@ page import="java.util.*" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>


<%--
  User: wangj
  Design Ideas：
  铭沣-更新时间范围内的外勤打卡原始记录ids
    表名：uf_rzygxxb
    需要：根据证件号码查询候选人信息id

--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%

    JSONObject data = new JSONObject();
    boolean flag = false;
    JSONArray datarr = new JSONArray();
    String sdate = Util.null2String(request.getParameter("sdate"));
    String edate = Util.null2String(request.getParameter("edate"));
    String sql = "";
    if("".equals(sdate)||"".equals(edate)){
        sql = "select id,requestid,sqr from formtable_main_632 where wqdkysjlid is null";
    }
    RecordSet rs = new RecordSet();
    rs.execute(sql);
    while (rs.next()){
        String id = Util.null2String(rs.getString("id"));
        String sqr = Util.null2String(rs.getString("sqr"));
        String requestid = Util.null2String(rs.getString("requestid"));
        flag = true;
        String wqdkysjlid = getWqdkysjlid(id,sqr);
        if(!"".equals(wqdkysjlid)){
            updateWqdkysjlid(id,wqdkysjlid);
            datarr.add(requestid);
        }

    }
    data.put("flag", flag);
    data.put("datarr", datarr);
    out.print(data.toJSONString());
%>

<%!
    private String getWqdkysjlid(String id,String sqr){
        String wqdkysjlid = "";

        String sql = "select distinct(b.id) as id from formtable_main_632_dt1 a left join uf_wqdkysjl b on a.dkrq = b.dkrq and a.dksj = b.dksj and a.dkwz = b.dkwz where a.mainid = '"+id+"' and b.sqr = '"+sqr+"'";

        RecordSet rs = new RecordSet();
        rs.execute(sql);
        while (rs.next()){
            String dtid = Util.null2String(rs.getString("id"));
            wqdkysjlid = wqdkysjlid + "," + dtid;
        }
        if(!"".equals(wqdkysjlid)){
            wqdkysjlid = wqdkysjlid.substring(1,wqdkysjlid.length());
        }

        return wqdkysjlid;
    }
%>

<%!
    private void updateWqdkysjlid(String id,String wqdkysjlid){
        String sql = "update formtable_main_632 set wqdkysjlid = '"+wqdkysjlid+"' where id = '"+id+"'";
        RecordSet rs = new RecordSet();
        rs.executeUpdate(sql);

    }
%>

