using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Web; namespace FangYar.WebUI.ashx { /// /// DoorAttendance 的摘要说明 /// public class DoorAttendance : IHttpHandler { private FangYar.BLL.TBL_DoorAttendance bll = new FangYar.BLL.TBL_DoorAttendance(); public void ProcessRequest(HttpContext context) { // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Other, "人员出入操作请求", ""); context.Response.ContentType = "text/plain"; string action = context.Request.Params["Action"]; string returnstr = ""; switch (action) { case "List": returnstr = perList(context); break; case "HomeList": returnstr = HomeList(context); break; } context.Response.Write(returnstr); } /// /// 列表数据获取 /// /// /// private string perList(HttpContext context) { string returnstr = ""; try { string OrgId = context.Request.Params["OrgId"]; string keyword = context.Request.Params["keywords"]; string page = context.Request.Params["page"]; string limit = context.Request.Params["limit"]; string startTime = context.Request.Params["startTime"]; string endTime = context.Request.Params["endTime"]; string treeID = context.Request.Params["treeID"]; string type = context.Request.Params["type"]; string is_content = context.Request.Params["is_content"]; //是否只看考勤设备 string IS_Attendance = context.Request.Params["IS_Attendance"] + ""; string selDeptId = context.Request.Params["selDeptId"]; //登录账号所属部门 string DeptID = context.Request.Params["DeptID"] + ""; //是否管理员账号 string IsAdmin = context.Request.Params["IsAdmin"] + ""; int pageIndex = 1; int pageSize = 10; string pOrgID = ""; pOrgID = OrgId; if (!string.IsNullOrEmpty(page)) { pageIndex = int.Parse(page); } if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); } int startIndex = (pageIndex - 1) * pageSize; ; startIndex = startIndex < 0 ? 0 : startIndex; string where = "1=1"; if (!string.IsNullOrWhiteSpace(IS_Attendance)) { //if (IS_Attendance == "1") //{ // where += " and t.EXTEND3 in (SELECT EPUIP_ID from tbl_epuip_org WHERE ORG_ID='" + OrgId + "' and IS_Attendance='1') "; //} where += " and IS_Attendance='1' "; } //string where = " EXTEND3 in (SELECT EPUIP_ID from tbl_epuip_org WHERE ORG_ID='" + OrgId + "' and IS_Attendance='1') "; if (!OrgId.IsNullOrEmpty()) { if (is_content == "1") { where += " and ( find_in_set(t.org_id, cids) ) "; } else { where += " and ( ORG_ID = '" + OrgId + "' )"; } } if (!string.IsNullOrWhiteSpace(selDeptId)) { where += " and EMPID in ( SELECT id from tbl_sys_emp WHERE ORG_ID='" + OrgId + "' and DEPT_ID='" + selDeptId + "' )"; } //判断是否管理员账号,如果不是管理员则只查询本部门数据 if (IsAdmin != "1") { if (!string.IsNullOrWhiteSpace(DeptID)) { where += " and EMPID in ( SELECT id from tbl_sys_emp WHERE ORG_ID='" + OrgId + "' and DEPT_ID='" + DeptID + "' )"; } } if (!string.IsNullOrEmpty(startTime)) { if (!startTime.Contains("请选择")) { where += " and start_time >= date_format('" + startTime + "','%Y-%m-%d %H:%i:%s')"; } } if (!string.IsNullOrEmpty(endTime)) { if (!endTime.Contains("请选择")) { where += " and start_time <= date_format('" + endTime + "','%Y-%m-%d %H:%i:%s')"; } } if (!string.IsNullOrEmpty(keyword)) { where += " and ( name like '%" + keyword + "%' or ADDR like '%" + keyword + "%' or EXTEND2 like '%" + keyword + "%')"; } returnstr = "{\"code\":0,\"msg\":\"\","; string sqlCount = @"select count(1) from (SELECT e.EPUIP_ID,IFNULL(e.IS_Attendance,0) IS_Attendance,t.* from TBL_PERSONACCESS t LEFT JOIN tbl_epuip_org e on t.EXTEND3 = e.EPUIP_ID) t ,(select get_Org_child_list('" + pOrgID + "') cids) s where " + where; int count = FangYar.Common.MySqlHelper.GetCount(sqlCount); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { //string sqlList = @"select * from (SELECT tp.* ,fo.org_name as org_name, tse.dept_ID as dept_ID FROM TBL_PERSONACCESS tp // left join tbl_sys_emp tse on tp.EMPID = tse.ID left join fire_org fo on tp.ORG_ID = fo.org_id )ccs // where " + where + // @"order by START_TIME DESC limit " + startIndex + @"," + pageSize; string sqlList = @" WITH t1 as( SELECT * from (SELECT e.EPUIP_ID,IFNULL(e.IS_Attendance,0) IS_Attendance,t.* from TBL_PERSONACCESS t LEFT JOIN tbl_epuip_org e on t.EXTEND3 = e.EPUIP_ID) t ,(select get_Org_child_list('" + pOrgID + "') cids) s where " + where + " order by START_TIME DESC limit " + startIndex + "," + pageSize + @" ) SELECT *,(SELECT org_name from fire_org o WHERE o.ORG_ID = t1.ORG_ID ) org_name ,(SELECT org_name from fire_org o WHERE o.ORG_ID = (SELECT DEPT_ID from tbl_sys_emp e WHERE t1.EMPID = e.ID ) ) deptName from t1 "; DataTable dtList = FangYar.Common.MySqlHelper.QueryTable(sqlList); returnstr += FangYar.Common.JsonHelper.ToJson(dtList); } returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"\",\"count\":0,\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "人员出入操作请求", "列表数据获取异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "人员出入操作请求", "列表数据获取"); return returnstr; } //首页人员数据获取 private string HomeList(HttpContext context) { string returnstr = ""; try { string OrgId = context.Request.Params["OrgId"]; //是否考勤:0、否;1、是 string IS_Attendance = context.Request.Params["IS_Attendance"]; IS_Attendance = string.IsNullOrWhiteSpace(IS_Attendance) ? "0" : IS_Attendance; int pageIndex = 1; int pageSize = 2000; string pOrgID = ""; pOrgID = OrgId; string where = " ORG_ID = '" + OrgId + "' "; //where += " and date_format(start_time,'%Y-%m-%d ') = date_format(now(),'%Y-%m-%d ') "; where += " and start_time > date_format(now(),'%Y-%m-%d ') "; where += " and EXTEND3 in (SELECT EPUIP_ID from tbl_epuip_org WHERE ORG_ID='" + OrgId + "' and EXTEND2='0' AND IS_Attendance='" + IS_Attendance + "') "; returnstr = "{\"code\":0,\"msg\":\"\","; //int count = bll.GetRecordCount(where); //if (count == 0) //{ // returnstr += "[]"; //} //else //{ string data = "["; List list = bll.QueryList(pageIndex, pageSize, where, " (START_TIME) DESC ", ""); returnstr += "\"count\":" + list.Count + " ,\"data\":"; for (int i = 0; i < list.Count; i++) { string pic1 = ""; string pic2 = ""; if (list[i].PICTURE != null && list[i].PICTURE.ToString() != "") { pic1 = Convert.ToBase64String((byte[])list[i].PICTURE); } if (list[i].CLOSEUP_PIC != null && list[i].CLOSEUP_PIC.ToString() != "") { pic2 = Convert.ToBase64String((byte[])list[i].CLOSEUP_PIC); } data += "{\"NAME\":\"" + list[i].NAME.Replace("\0", "") + "\",\"START_TIME\":\"" + list[i].START_TIME + "\","; data += "\"ADDR\":\"" + list[i].ADDR + "\",\"CLOSEUP_PIC_URL\":\"" + list[i].CLOSEUP_PIC_URL + "\"}"; if (i != list.Count - 1) { data += ","; } } returnstr += data + "]"; //} returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"\",\"count\":0,\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "人员出入操作请求", "首页人员数据获取异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "人员出入操作请求", "首页人员数据获取"); return returnstr; } public bool IsReusable { get { return false; } } } }