<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.util.*" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.conn.RecordSetTrans" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.formmode.setup.ModeRightInfo" %>
<%@ page import="weaver.mfbdt.util.MfUtil" %>


<%--
  User: wangj
  Design Ideas：
  铭沣-获取时间段内外勤打卡记录同步到原始外勤打卡审批表

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

    JSONObject data = new JSONObject();
    RecordSet rs = new RecordSet();
    boolean flag = false;
    String sdate = Util.null2String(request.getParameter("sdate"));
    String edate = Util.null2String(request.getParameter("edate"));
//    String sql = "select userId,userType,signType,signDate,signTime,clientAddress,isInCom,timeZone,belongdate,signfrom,longitude,latitude,addr,deviceInfo from HrmScheduleSign where signDate >= '" + sdate + "' and signDate <= '" + edate + "' and addr != ''";
    String sql = "select operater as userId,'1' as userType,'2' as signType,operate_date as signDate,operate_time as signTime,'' as clientAddress,'1' as isInCom, 'GMT+8' as timeZone , operate_date as belongdate,'e9_mobile_out' as signfrom,longitude,latitude,address as addr,'' as deviceInfo from mobile_sign where operate_date >= '" + sdate + "' and operate_date <= '" + edate + "' and address != ''";
    rs.execute(sql);
    int userId = 0;
    String userType = "";
    String signType = "";
    String signDate = "";
    String signTime = "";
    String clientAddress = "";
    String isInCom = "";
    String timeZone = "";
    String belongdate = "";
    String signfrom = "";
    String longitude = "";
    String latitude = "";
    String address = "";
    String deviceInfo = "";
    while (rs.next()) {
        flag = true;
        userId = Util.getIntValue(rs.getString("userId"));
        userType = Util.null2String(rs.getString("userType"));
        signType = "2";
        signDate = Util.null2String(rs.getString("signDate"));
        signTime = Util.null2String(rs.getString("signTime"));
        clientAddress = Util.null2String(rs.getString("clientAddress"));
        isInCom = Util.null2String(rs.getString("isInCom"));
        timeZone = Util.null2String(rs.getString("timeZone"));
        belongdate = Util.null2String(rs.getString("belongdate"));
        signfrom = Util.null2String(rs.getString("signfrom"));

        longitude = Util.null2String(rs.getString("longitude"));
        latitude = Util.null2String(rs.getString("latitude"));
        address = Util.null2String(rs.getString("addr"));
        deviceInfo = Util.null2String(rs.getString("deviceInfo"));
        Map<String, String> usermap = MfUtil.getUserInfo(userId + "");
        String sqr = userId + "";
        String sqrq = signDate;
        String dkrq = signDate;
        String dksj = signTime.substring(0, 5);
        String gsmc = Util.null2String(usermap.get("gsmc"));
        String szzw = Util.null2String(usermap.get("szzw"));
        String szbm = Util.null2String(usermap.get("szbm"));
        String ygbh = Util.null2String(usermap.get("ygbh"));
        String dkwz = address;
        String gzrq = Util.null2String(belongdate);
        String bz = "";
        insetWqSignRecord(sqr, sqrq, dkrq, dksj, gsmc, szzw, szbm, ygbh, dkwz, gzrq, bz, userId, userType, signType, signDate, signTime, clientAddress, isInCom,
                timeZone, belongdate, signfrom, longitude, latitude, address, deviceInfo);

    }



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

<%!
    public void insetWqSignRecord(String sqr, String sqrq, String dkrq, String dksj, String gsmc, String szzw, String szbm, String ygbh, String dkwz, String gzrq, String bz,
                                  int userId, String userType, String signType, String signDate, String signTime, String clientAddress, String isInCom,
                                  String timeZone, String belongdate, String signfrom, String longitude, String latitude, String address, String deviceInfo) {
        RecordSetTrans rst = new RecordSetTrans();
        String modedatacreater = "1";
        String modedatacreatertype = "0";

        String createdate = com.time.util.DateUtil.getCurrentTime("yyyy-MM-dd");
        String createtime = com.time.util.DateUtil.getCurrentTime("HH:mm:ss");

        String modeuuid = UUID.randomUUID().toString();
        rst.setAutoCommit(false);
        BaseBean bb = new BaseBean();
        String formmodeid = Util.null2String(bb.getPropValue("kq_config", "wq_sign_formmodeid"));
        try {
            String sql = " insert into uf_wqdkysjl(sqr,sqrq,dkrq,dksj,gsmc,szzw,szbm,ygbh,dkwz,gzrq,bz,userId,userType,signType,signDate,signTime,clientAddress,isInCom,timeZone,belongdate,signfrom,longitude,latitude,addr,deviceInfo,formmodeid,modedatacreater,modedatacreatertype,modeuuid,modedatacreatedate,modedatacreatetime) " +
                    "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            rst.executeUpdate(sql, sqr, sqrq, dkrq, dksj, gsmc, szzw, szbm, ygbh, dkwz, gzrq, bz, userId, userType, signType, signDate, signTime, clientAddress, isInCom, timeZone, belongdate, signfrom, longitude, latitude, address, deviceInfo, formmodeid, modedatacreater, modedatacreatertype, modeuuid, createdate, createtime);
        } catch (Exception e) {
            e.getMessage();
        }

        rst.commit();
        int dataId = getDataIdByUUID(modeuuid);
        ModeRightInfo modeRightInfo = new ModeRightInfo();
        modeRightInfo.editModeDataShare(1, Integer.parseInt(formmodeid), dataId);
    }
%>

<%!
    /**
     * 根据uuid获取建模的数据id，常用于建模的权限重构
     *
     * @param uuid modeUuid
     * @return dataId
     */
    public static int getDataIdByUUID(String uuid) {
    RecordSet rs = new RecordSet();
    int dataid = -1;
    String sql = "select id from uf_wqdkysjl where modeuuid = ?";
    if (rs.executeQuery(sql, uuid) && rs.next()) {
    dataid = Util.getIntValue(rs.getString(1));
    }
    return dataid;
    }

%>


