using FangYar.Common; using FangYar.WebUI.WebModel; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; namespace FangYar.WebUI.ashx { /// /// DutyDiyHandler 的摘要说明 /// public class DutyDiyHandler : IHttpHandler { 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 "GetDutyTypeList": returnstr = GetDutyTypeList(context); break; //保存排班类型 case "SaveDutyType": returnstr = SaveDutyType(context); break; //根据信息ID获取排班类型信息 case "GetDutyTypeByID": returnstr = GetDutyTypeByID(context); break; //删除排班分类信息 case "DelDutyTypeByID": returnstr = DelDutyTypeByID(context); break; //查询排班模板 case "GetDutyTemplateList": returnstr = GetDutyTemplateList(context); break; //根据类型查询排班模板 case "GetDutyTemplateByType": returnstr = GetDutyTemplateByType(context); break; //保存排班模板 case "SaveDutyTemplate": returnstr = SaveDutyTemplate(context); break; //根据信息ID获取排班模板信息 case "GetDutyTemplateByID": returnstr = GetDutyTemplateByID(context); break; //删除排班模板信息 case "DelDutyTemplateByID": returnstr = DelDutyTemplateByID(context); break; //查询排班模板关联设备集合 case "GetDutyTemLinkDeviceList": returnstr = GetDutyTemLinkDeviceList(context); break; //查询排班详情 case "GetDutyDetailsList": returnstr = GetDutyDetailsList(context); break; //保存排班详情 case "SaveDutyDetails": returnstr = SaveDutyDetails(context); break; //根据信息ID获取排班详情信息 case "GetDutyDetailsByID": returnstr = GetDutyDetailsByID(context); break; //根据信息ID获取排班详情识别显示信息 case "GetDutyDetailsShowByID": returnstr = GetDutyDetailsShowByID(context); break; //删除排班详情信息 case "DelDutyDetailsByID": returnstr = DelDutyDetailsByID(context); break; } context.Response.Write(returnstr); } #region 排班类型处理 /// /// 查询排班类型 /// /// /// private string GetDutyTypeList(HttpContext context) { string returnstr = ""; try { string OrgId = context.Request.Params["OrgId"]; string sqlStr = " SELECT * from oa_duty_type WHERE ORG_ID = '" + OrgId + "' and is_del='0' order by DUTY_SORT "; returnstr = "{\"code\":0,\"msg\":\"\","; DataTable dtList = FangYar.Common.MySqlHelper.QueryTable(sqlStr); returnstr += "\"count\":" + dtList.Rows.Count + ",\"data\":"; 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 SaveDutyType(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { //分组信息ID string did = context.Request.Params["did"]; string OrgId = context.Request.Params["OrgId"]; string DUTY_TYPE_NAME = context.Request.Params["DUTY_TYPE_NAME"]; string DUTY_SORT = context.Request.Params["DUTY_SORT"]; string DUTY_REMARK = context.Request.Params["DUTY_REMARK"]; //实例化信息ID string ID = Guid.NewGuid().ToString("N"); // 插入摄像头分组信息 string sql = @" insert into oa_duty_type (ID,DUTY_TYPE_NAME,DUTY_SORT,createtime,DUTY_REMARK,ORG_ID) values ('" + ID + "','" + DUTY_TYPE_NAME + "','" + DUTY_SORT + "',now(),'" + DUTY_REMARK + "','" + OrgId + "') "; //判断是否更新数据 if (!string.IsNullOrWhiteSpace(did)) { //拼接更新数据Sql sql = " update oa_duty_type set DUTY_TYPE_NAME='" + DUTY_TYPE_NAME + "',DUTY_SORT='" + DUTY_SORT + "',DUTY_REMARK='" + DUTY_REMARK + "' where id='" + did + "' "; } var num = FangYar.Common.MySqlHelper.Execute(sql); if (num > 0) { msg = "保存成功!"; code = 1; } else { msg = "保存失败!"; } } 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, "自定义排班功能", "保存排班类型"); returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } /// /// 根据信息ID获取排班类型信息 /// /// /// private string GetDutyTypeByID(HttpContext context) { string returnstr = ""; try { //组织机构ID string cgid = context.Request.Params["cgid"]; string sqlQuery = @" SELECT * from oa_duty_type WHERE id ='" + cgid + "' "; var dt1 = FangYar.Common.MySqlHelper.QueryTable(sqlQuery); returnstr = "{\"code\":0,\"msg\":\"\","; returnstr += "\"count\":" + dt1.Rows.Count + ",\"data\":"; returnstr += FangYar.Common.JsonHelper.ToJson(dt1); returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "摄像头分组操作请求", "根据信息ID获取排班类型信息异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "摄像头分组操作请求", "根据信息ID获取排班类型信息"); return returnstr; } /// /// 删除排班分类信息 /// /// /// private string DelDutyTypeByID(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { //分组信息ID string did = context.Request.Params["did"]; //拼接更新数据Sql string sql = " update oa_duty_type set IS_DEL = '1' where id='" + did + "' "; var num = FangYar.Common.MySqlHelper.Execute(sql); if (num > 0) { msg = "操作成功!"; code = 1; } else { msg = "操作失败!"; } } 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, "自定义排班功能", "删除排班分类信息"); returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } #endregion #region 排班模板处理 /// /// 查询排班模板 /// /// /// private string GetDutyTemplateList(HttpContext context) { string returnstr = ""; try { string OrgId = context.Request.Params["OrgId"]; string sqlStr = " SELECT * from oa_duty_template WHERE ORG_ID = '" + OrgId + "' and is_del='0' order by DUTY_SORT "; returnstr = "{\"code\":0,\"msg\":\"\","; DataTable dtList = FangYar.Common.MySqlHelper.QueryTable(sqlStr); returnstr += "\"count\":" + dtList.Rows.Count + ",\"data\":"; 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 GetDutyTemplateByType(HttpContext context) { string returnstr = ""; try { string DutyTypeID = context.Request.Params["DutyTypeID"]; string sqlStr = " SELECT * from oa_duty_template WHERE DUTY_TYPE_ID = '" + DutyTypeID + "' and is_del='0' order by DUTY_SORT "; returnstr = "{\"code\":0,\"msg\":\"\","; DataTable dtList = FangYar.Common.MySqlHelper.QueryTable(sqlStr); returnstr += "\"count\":" + dtList.Rows.Count + ",\"data\":"; 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 SaveDutyTemplate(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { //模板信息ID string did = context.Request.Params["did"]; //信息内容JSON字符串 string dataStr = context.Request.Params["dataStr"]; DutyDiyTemplatePostMo mo = FangYar.Common.JsonHelper.FromJSON(dataStr); string a = ""; //实例化信息ID string ID = Guid.NewGuid().ToString("N"); string DEVICECODE = mo.DEVICECODE.Replace("#", "$"); // 插入摄像头分组信息 string sql = @" insert into oa_duty_template (ID,DUTY_TEMPLATE_NAME,DUTY_SORT,createtime,DUTY_REMARK,ORG_ID,DUTY_TYPE_ID,DeviceCode,DUTY_TEMPLATE_CONTENT) values ('" + ID + "','" + mo.DUTY_TEMPLATE_NAME + "','" + mo.DUTY_SORT + "',now(),'" + mo.DUTY_REMARK + "','" + mo.ORG_ID + "','" + mo.DUTY_TYPE_ID + "','" + DEVICECODE + "','" + dataStr + "') "; //判断是否更新数据 if (!string.IsNullOrWhiteSpace(did)) { //拼接更新数据Sql sql = " update oa_duty_template set DUTY_TEMPLATE_NAME='" + mo.DUTY_TEMPLATE_NAME + "',DUTY_SORT='" + mo.DUTY_SORT + "',DUTY_REMARK='" + mo.DUTY_REMARK + "',DUTY_TYPE_ID='" + mo.DUTY_TYPE_ID + "',DeviceCode='" + DEVICECODE + "',DUTY_TEMPLATE_CONTENT='" + dataStr + "' where id='" + did + "' "; } var num = FangYar.Common.MySqlHelper.Execute(sql); if (num > 0) { msg = "保存成功!"; code = 1; } else { msg = "保存失败!"; } } 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, "自定义排班功能", "保存排班类型"); returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } /// /// 根据信息ID获取排班模板信息 /// /// /// private string GetDutyTemplateByID(HttpContext context) { string returnstr = ""; try { //组织机构ID string cgid = context.Request.Params["cgid"]; string sqlQuery = @" SELECT * from oa_duty_template WHERE id ='" + cgid + "' "; var dt1 = FangYar.Common.MySqlHelper.QueryTable(sqlQuery); DutyDiyTemplatePostMo mo = FangYar.Common.JsonHelper.FromJSON(dt1.Rows[0]["DUTY_TEMPLATE_CONTENT"] + ""); DutyDiyTemplateMo retMo = new DutyDiyTemplateMo() { ORG_ID = mo.ORG_ID, DUTY_SORT = mo.DUTY_SORT, DEVICECODE = mo.DEVICECODE.Replace("$", "#"), DUTY_REMARK = mo.DUTY_REMARK, DUTY_TYPE_ID = mo.DUTY_TYPE_ID, DUTY_DAY = mo.DUTY_DAY, DUTY_TEMPLATE_ID = mo.DUTY_TEMPLATE_ID, DUTY_TEMPLATE_NAME = mo.DUTY_TEMPLATE_NAME, dataAttribList = new List(), dataTableList = new List(), }; List list1 = mo.attList; //熟悉信息集合 var listAtt = list1.Where(p => p.IsTable == "1").ToList(); for (int i = 0; i < listAtt.Count(); i++) { try { retMo.dataAttribList.Add(new DutyDiyTemplateItemMo() { ID = listAtt[i].ID, RowVal = listAtt[i].RowVal, ColNum = listAtt[i].ColNum, DtmStr = listAtt[i].DtmStr, IsTable = listAtt[i].IsTable, RowSpan = listAtt[i].RowSpan, RowType = listAtt[i].RowType, OptionList = listAtt[i].OptionList, RowTitle = listAtt[i].RowTitle, TableNum = listAtt[i].TableNum, ColNumCount = listAtt[i].ColNumCount, RowNumCount = listAtt[i].RowNumCount, DeviceReadTime = listAtt[i].DeviceReadTime, IsDeviceRead = listAtt[i].IsDeviceRead, RowSelEmpName = listAtt[i].RowSelEmpName, DeviceReadImgUrl = listAtt[i].DeviceReadImgUrl, }); } catch (Exception ex) { } } //表格属性集合 var listTab = list1.Where(p => p.IsTable == "0").ToList(); //表格分组 var listTabGroup = listTab.GroupBy(p => p.TableNum).ToList(); for (int i = 0; i < listTabGroup.Count(); i++) { DutyDiyTemplateTableMo itemObj = new DutyDiyTemplateTableMo() { ColNumCount = 0, dataAttribList = new List(), RowNumCount = 0 }; var lisItem = listTabGroup[i].ToList(); for (int j = 0; j < lisItem.Count(); j++) { try { if (itemObj.RowNumCount < 1) { int.TryParse(lisItem[j].RowNumCount, out int RowCount); itemObj.RowNumCount = RowCount; } if (itemObj.ColNumCount < 1) { int.TryParse(lisItem[j].ColNumCount, out int ColCount); itemObj.ColNumCount = ColCount; } itemObj.dataAttribList.Add(new DutyDiyTemplateItemMo() { ID = lisItem[j].ID, RowVal = lisItem[i].RowVal, ColNum = lisItem[j].ColNum, DtmStr = lisItem[j].DtmStr, IsTable = lisItem[j].IsTable, RowSpan = lisItem[j].RowSpan, RowType = lisItem[j].RowType, OptionList = lisItem[j].OptionList, RowTitle = lisItem[j].RowTitle, TableNum = lisItem[j].TableNum, ColNumCount = lisItem[j].ColNumCount, RowNumCount = lisItem[j].RowNumCount, IsDeviceRead = lisItem[i].IsDeviceRead, RowSelEmpName = lisItem[i].RowSelEmpName, DeviceReadTime = lisItem[i].DeviceReadTime, DeviceReadImgUrl = lisItem[i].DeviceReadImgUrl, }); } catch (Exception ex) { } } retMo.dataTableList.Add(itemObj); } returnstr = "{\"code\":0,\"msg\":\"\","; returnstr += "\"count\":" + dt1.Rows.Count + ",\"data\":"; returnstr += FangYar.Common.JsonHelper.ToJSON1(retMo); returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "摄像头分组操作请求", "根据信息ID获取排班类型信息异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "摄像头分组操作请求", "根据信息ID获取排班类型信息"); return returnstr; } /// /// 删除排班模板信息 /// /// /// private string DelDutyTemplateByID(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { //分组信息ID string did = context.Request.Params["did"]; //拼接更新数据Sql string sql = " update oa_duty_template set IS_DEL = '1' where id='" + did + "' "; var num = FangYar.Common.MySqlHelper.Execute(sql); if (num > 0) { msg = "操作成功!"; code = 1; } else { msg = "操作失败!"; } } 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, "自定义排班功能", "删除排班模板信息"); returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } /// /// 查询排班模板关联设备集合 /// /// /// private string GetDutyTemLinkDeviceList(HttpContext context) { string returnstr = ""; try { string OrgId = context.Request.Params["OrgId"]; string sqlStr = @" SELECT REPLACE(EXTEND3,'$','#') DIC_VALUE,C_NAME DIC_TITLE from tbl_camera WHERE ORG_ID = '" + OrgId + @"' and LENGTH(EXTEND3)>0 union all SELECT REPLACE(EPUIP_ID,'$','#') DIC_VALUE, NAME DIC_TITLE from tbl_epuip_org WHERE ORG_ID = '" + OrgId + "' and EXTEND2 = '0' "; returnstr = "{\"code\":0,\"msg\":\"\","; DataTable dtList = FangYar.Common.MySqlHelper.QueryTable(sqlStr); returnstr += "\"count\":" + dtList.Rows.Count + ",\"data\":"; 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; } #endregion #region 排班详情处理 /// /// 查询排班详情 /// /// /// private string GetDutyDetailsList(HttpContext context) { string returnstr = ""; try { string OrgId = context.Request.Params["OrgId"]; //类型 string selDutyTypeId = context.Request.Params["selDutyTypeId"] + ""; string page = context.Request.Params["page"]; string limit = context.Request.Params["limit"]; int.TryParse(page, out int PageIndex); int.TryParse(limit, out int PageSize); PageIndex = PageIndex < 1 ? 1 : PageIndex; PageSize = PageSize < 1 ? 1 : PageSize; int startnum = (PageIndex - 1) * PageSize; string whereStr = " "; if (!string.IsNullOrWhiteSpace(selDutyTypeId)) { whereStr += " and DUTY_TYPE_ID='" + selDutyTypeId + "' "; } string sqlStr = " SELECT * from oa_duty_details WHERE ORG_ID = '" + OrgId + "' and is_del='0' " + whereStr + " order by DUTY_DAY desc limit " + startnum + ", " + PageSize; string sqlCount = " SELECT count(1) from oa_duty_details WHERE ORG_ID = '" + OrgId + "' and is_del='0' " + whereStr + " "; var dtCount = FangYar.Common.MySqlHelper.QueryTable(sqlCount); int rowCount = 0; if (dtCount.Rows.Count > 0) { int.TryParse(dtCount.Rows[0][0] + "", out rowCount); } returnstr = "{\"code\":0,\"msg\":\"\","; DataTable dtList = FangYar.Common.MySqlHelper.QueryTable(sqlStr); returnstr += "\"count\":" + rowCount + ",\"data\":"; 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 SaveDutyDetails(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { //模板信息ID string did = context.Request.Params["did"]; //信息内容JSON字符串 string dataStr = context.Request.Params["dataStr"]; DutyDiyTemplatePostMo mo = FangYar.Common.JsonHelper.FromJSON(dataStr); string a = ""; //实例化信息ID string ID = Guid.NewGuid().ToString("N"); //日期 string DUTY_DAY = mo.DUTY_DAY; //模板类型ID string DUTY_TYPE_ID = mo.DUTY_TYPE_ID; // 插入信息 string sql = @" insert into oa_duty_details (ID,DUTY_DAY,DUTY_TYPE_ID,createtime,DUTY_REMARK,ORG_ID,DUTY_TEMPLATE_ID,DUTY_CONTENT) values ('" + ID + "','" + mo.DUTY_DAY + "','" + mo.DUTY_TYPE_ID + "',now(),'" + mo.DUTY_REMARK + "','" + mo.ORG_ID + "','" + mo.DUTY_TEMPLATE_ID + "','" + dataStr + "') "; //判断是否更新数据 if (!string.IsNullOrWhiteSpace(did)) { //拼接更新数据Sql sql = " update oa_duty_details set DUTY_DAY='" + mo.DUTY_DAY + "',DUTY_REMARK='" + mo.DUTY_REMARK + "',DUTY_CONTENT='" + dataStr + "' where id='" + did + "' "; } var num = FangYar.Common.MySqlHelper.Execute(sql); if (num > 0) { msg = "保存成功!"; code = 1; } else { msg = "保存失败!"; } } 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, "自定义排班功能", "保存排班类型"); returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } /// /// 根据信息ID获取排班模板信息 /// /// /// private string GetDutyDetailsByID(HttpContext context) { string returnstr = ""; try { //组织机构ID string cgid = context.Request.Params["cgid"]; string sqlQuery = @" SELECT * from oa_duty_details WHERE id ='" + cgid + "' "; var dt1 = FangYar.Common.MySqlHelper.QueryTable(sqlQuery); DutyDiyTemplatePostMo mo = FangYar.Common.JsonHelper.FromJSON(dt1.Rows[0]["DUTY_CONTENT"] + ""); DutyDiyTemplateMo retMo = new DutyDiyTemplateMo() { ORG_ID = mo.ORG_ID, DUTY_SORT = mo.DUTY_SORT, DEVICECODE = "", DUTY_REMARK = mo.DUTY_REMARK, DUTY_TYPE_ID = mo.DUTY_TYPE_ID, DUTY_DAY = mo.DUTY_DAY, DUTY_TEMPLATE_ID = mo.DUTY_TEMPLATE_ID, DUTY_TEMPLATE_NAME = mo.DUTY_TEMPLATE_NAME, dataAttribList = new List(), dataTableList = new List(), }; List list1 = mo.attList; //熟悉信息集合 var listAtt = list1.Where(p => p.IsTable == "1").ToList(); for (int i = 0; i < listAtt.Count(); i++) { try { retMo.dataAttribList.Add(new DutyDiyTemplateItemMo() { ID = listAtt[i].ID, RowVal = listAtt[i].RowVal, ColNum = listAtt[i].ColNum, DtmStr = listAtt[i].DtmStr, IsTable = listAtt[i].IsTable, RowSpan = listAtt[i].RowSpan, RowType = listAtt[i].RowType, OptionList = listAtt[i].OptionList, RowTitle = listAtt[i].RowTitle, TableNum = listAtt[i].TableNum, ColNumCount = listAtt[i].ColNumCount, RowNumCount = listAtt[i].RowNumCount, IsDeviceRead = listAtt[i].IsDeviceRead, RowSelEmpName = listAtt[i].RowSelEmpName, DeviceReadTime = listAtt[i].DeviceReadTime, DeviceReadImgUrl = listAtt[i].DeviceReadImgUrl, }); } catch (Exception ex) { } } //表格属性集合 var listTab = list1.Where(p => p.IsTable == "0").ToList(); //表格分组 var listTabGroup = listTab.GroupBy(p => p.TableNum).ToList(); for (int i = 0; i < listTabGroup.Count(); i++) { DutyDiyTemplateTableMo itemObj = new DutyDiyTemplateTableMo() { ColNumCount = 0, dataAttribList = new List(), RowNumCount = 0 }; var lisItem = listTabGroup[i].ToList(); for (int j = 0; j < lisItem.Count(); j++) { try { if (itemObj.RowNumCount < 1) { int.TryParse(lisItem[j].RowNumCount, out int RowCount); itemObj.RowNumCount = RowCount; } if (itemObj.ColNumCount < 1) { int.TryParse(lisItem[j].ColNumCount, out int ColCount); itemObj.ColNumCount = ColCount; } itemObj.dataAttribList.Add(new DutyDiyTemplateItemMo() { ID = lisItem[j].ID, RowVal = lisItem[j].RowVal, ColNum = lisItem[j].ColNum, DtmStr = lisItem[j].DtmStr, IsTable = lisItem[j].IsTable, RowSpan = lisItem[j].RowSpan, RowType = lisItem[j].RowType, OptionList = lisItem[j].OptionList, RowTitle = lisItem[j].RowTitle, TableNum = lisItem[j].TableNum, ColNumCount = lisItem[j].ColNumCount, RowNumCount = lisItem[j].RowNumCount, DeviceReadTime = lisItem[j].DeviceReadTime, IsDeviceRead = lisItem[j].IsDeviceRead, RowSelEmpName = lisItem[j].RowSelEmpName, DeviceReadImgUrl = lisItem[j].DeviceReadImgUrl, }); } catch (Exception ex) { } } retMo.dataTableList.Add(itemObj); } returnstr = "{\"code\":0,\"msg\":\"\","; returnstr += "\"count\":" + dt1.Rows.Count + ",\"data\":"; returnstr += FangYar.Common.JsonHelper.ToJSON1(retMo); returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "摄像头分组操作请求", "根据信息ID获取排班类型信息异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "摄像头分组操作请求", "根据信息ID获取排班类型信息"); return returnstr; } /// /// 根据信息ID获取排班详情识别显示信息 /// /// /// private string GetDutyDetailsShowByID(HttpContext context) { string returnstr = ""; try { //组织机构ID string cgid = context.Request.Params["cgid"]; string sqlQuery = @" SELECT * from oa_duty_details WHERE id ='" + cgid + "' "; var dt1 = FangYar.Common.MySqlHelper.QueryTable(sqlQuery); DutyDiyTemplatePostMo mo = FangYar.Common.JsonHelper.FromJSON(dt1.Rows[0]["DUTY_CONTENT"] + ""); bool isDeviceRead = false; DutyDiyTemplateMo retMo = new DutyDiyTemplateMo() { ORG_ID = mo.ORG_ID, DUTY_SORT = mo.DUTY_SORT, DEVICECODE = "", DUTY_REMARK = mo.DUTY_REMARK, DUTY_TYPE_ID = mo.DUTY_TYPE_ID, DUTY_DAY = mo.DUTY_DAY, DUTY_TEMPLATE_ID = mo.DUTY_TEMPLATE_ID, DUTY_TEMPLATE_NAME = mo.DUTY_TEMPLATE_NAME, dataAttribList = new List(), dataTableList = new List(), }; //查询模板对应设备信息 string sqlDevice = " SELECT DeviceCode from oa_duty_template WHERE id = '" + mo.DUTY_TEMPLATE_ID + "' "; var dtDevice = MySqlHelper.QueryTable(sqlDevice); if (dtDevice.Rows.Count > 0) { //设备编码 string DeviceCode = dtDevice.Rows[0]["DeviceCode"] + ""; if (!string.IsNullOrWhiteSpace(DeviceCode)) { //拆分设备信息 var arr1 = DeviceCode.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (arr1.Length > 0) { isDeviceRead = true; var dayStr = mo.DUTY_DAY; string WhereEmpInOutDtm = " ( date_format(START_TIME,'%Y-%m-%d') = '" + dayStr + "' "; string WhereFacdDtm = " ( formatDateTime(alarm_time,'%Y-%m-%d') = '" + dayStr + "' "; DateTime.TryParse(dayStr, out DateTime dtm1); string DayStrNex = dayStr; if (dtm1.ToString("yyyy-MM-dd") == dayStr) { var dtm2 = dtm1.AddDays(1); var str2 = dtm2.ToString("yyyy-MM-dd"); DayStrNex = str2; WhereEmpInOutDtm += " or date_format(START_TIME,'%Y-%m-%d') = '" + str2 + "' "; WhereFacdDtm += " or formatDateTime(alarm_time,'%Y-%m-%d') = '" + str2 + "' "; } WhereEmpInOutDtm += " ) "; WhereFacdDtm += " ) "; WhereEmpInOutDtm += " and ( EXTEND3 = '" + arr1[0] + "' "; WhereFacdDtm += " and ( dev_serial = '" + arr1[0] + "' "; for (int i = 1; i < arr1.Length; i++) { WhereEmpInOutDtm += " or EXTEND3 = '" + arr1[i] + "' "; WhereFacdDtm += " or dev_serial = '" + arr1[i] + "' "; } WhereEmpInOutDtm += " ) "; WhereFacdDtm += " ) "; //查询所有人员信息 string sqlEmp = " SELECT ID,USERS_UID,EMP_NAME,EMP_MOBILE,IDNUMBER,PHOTO from tbl_sys_emp WHERE ORG_ID = '" + mo.ORG_ID + "' and IS_DEL ='0' and IS_ADMIN = '0' "; //查询所有相关人员出入信息 string sqlEmpInOut = " SELECT `NAME` uName,START_TIME tim,EXTEND3 deviceCode,EXTEND2 uAddress,PICTURE_URL imgUrl,date_format(START_TIME,'%Y-%m-%d') dayStr from tbl_personaccess WHERE " + WhereEmpInOutDtm; //查询所有相关摄像头识别信息 string sqlFace = " SELECT username uName,alarm_time tim,dev_serial deviceCode,id_card uAddress,pic_url imgUrl,formatDateTime(alarm_time,'%Y-%m-%d') dayStr from default.t_face_data WHERE " + WhereFacdDtm; //人员基础信息查询 var dtEmpInfo = MySqlHelper.QueryTable(sqlEmp); //查询人员出入相关数据 var dtEmpInOut = MySqlHelper.QueryTable(sqlEmpInOut); //查询人脸识别记录 var dtFace = ClickHouseHelper.Execute(sqlFace); //人员基础信息集合 List listEmpInfo = new List(); for (int i = 0; i < dtEmpInfo.Rows.Count; i++) { try { listEmpInfo.Add(new DutyDivQueryEmpMo() { ID = dtEmpInfo.Rows[i]["ID"] + "", PHOTO = dtEmpInfo.Rows[i]["PHOTO"] + "", EMP_NAME = dtEmpInfo.Rows[i]["EMP_NAME"] + "", IDNUMBER = dtEmpInfo.Rows[i]["IDNUMBER"] + "", USERS_UID = dtEmpInfo.Rows[i]["USERS_UID"] + "", EMP_MOBILE = dtEmpInfo.Rows[i]["EMP_MOBILE"] + "", }); } catch (Exception ex) { } } //识别人员信息集合 List listEmpRead = new List(); for (int i = 0; i < dtEmpInOut.Rows.Count; i++) { try { listEmpRead.Add(new DutyDiyReadEmpMo() { tim = dtEmpInOut.Rows[i]["tim"] + "", uName = dtEmpInOut.Rows[i]["uName"] + "", dayStr = dtEmpInOut.Rows[i]["dayStr"] + "", imgUrl = dtEmpInOut.Rows[i]["imgUrl"] + "", uAddress = dtEmpInOut.Rows[i]["uAddress"] + "", deviceCode = dtEmpInOut.Rows[i]["deviceCode"] + "", }); } catch (Exception ex) { } } for (int i = 0; i < dtFace.Rows.Count; i++) { try { listEmpRead.Add(new DutyDiyReadEmpMo() { tim = dtFace.Rows[i]["tim"] + "", uName = dtFace.Rows[i]["uName"] + "", imgUrl = dtFace.Rows[i]["imgUrl"] + "", dayStr = dtFace.Rows[i]["dayStr"] + "", uAddress = dtFace.Rows[i]["uAddress"] + "", deviceCode = dtFace.Rows[i]["deviceCode"] + "", }); } catch (Exception ex) { } } //遍历处理人员信息 for (int i = 0; i < mo.attList.Count; i++) { var obj = mo.attList[i]; mo.attList[i].ListEmpRead = new List(); var str1 = obj.RowVal; var arrEmp1 = str1.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); var arrEmpName = obj.RowSelEmpName.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (arrEmp1.Length > 0) { //类型:0、输入项;1、选择项;2、人员选择;3、时间范围; switch (obj.RowType) { case "2": case "3": for (int j = 0; j < arrEmp1.Length; j++) { //手机号 var empPhone = arrEmp1[j]; //人员对象 var empObj = listEmpInfo.Where(p => p.USERS_UID.Equals(empPhone) || p.EMP_MOBILE.Equals(empPhone)).FirstOrDefault(); string empName = ""; string defaultImg = "/images/imgPerDefaut.jpg"; if (arrEmpName.Length > j) { empName = arrEmpName[j]; } if (empObj == null) { mo.attList[i].ListEmpRead.Add(new DutyDiyEmpReadMo() { IsDeviceRead = "0", DeviceReadTime = "", EmpImg = defaultImg, EmpName = empName, DeviceReadImgUrl = defaultImg, EmpPhone = empPhone, }); } else { if (obj.RowType == "2") { //人员选择 var l1 = listEmpRead.Where(p => p.dayStr == dayStr && (p.uAddress == empObj.IDNUMBER || p.uName == empObj.EMP_NAME)).OrderBy(p => p.timDtmType).ToList(); if (l1.Any()) { //已经识别 mo.attList[i].ListEmpRead.Add(new DutyDiyEmpReadMo() { IsDeviceRead = "1", EmpName = empObj.EMP_NAME, EmpImg = "/" + empObj.PHOTO, DeviceReadTime = l1.First().tim, DeviceReadImgUrl = l1.First().imgUrl, EmpPhone = empPhone, }); } else { //未识别 mo.attList[i].ListEmpRead.Add(new DutyDiyEmpReadMo() { IsDeviceRead = "0", DeviceReadTime = "", EmpImg = defaultImg, EmpName = empObj.EMP_NAME, DeviceReadImgUrl = defaultImg, EmpPhone = empPhone, }); } } else { //时间范围 var DtmStr = obj.DtmStr; var arrDtm = DtmStr.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); if (arrDtm.Length == 2) { var sTimStr = arrDtm[0].Trim(); var eTimStr = arrDtm[1].Trim(); var shiStr = sTimStr.Substring(0, 2); int.TryParse(shiStr, out int shiNum); var dayQeury = dayStr; var dayQeuryE = dayStr; //判断是否7点之前,如果是7点之前,则判定为日期是第二天 if (shiNum < 7) { dayQeury = DayStrNex; dayQeuryE = DayStrNex; } else { var shiStrE = eTimStr.Substring(0, 2); int.TryParse(shiStrE, out int shiNumE); if (shiNum > shiNumE) { dayQeuryE = DayStrNex; } } DateTime.TryParse(dayQeury + " " + sTimStr, out DateTime dtmS); DateTime.TryParse(dayQeuryE + " " + eTimStr, out DateTime dtmE); //人员选择 var l1 = listEmpRead.Where(p => (p.timDtmType >= dtmS && p.timDtmType <= dtmE) && (p.uAddress == empObj.IDNUMBER || p.uName == empObj.EMP_NAME)).OrderBy(p => p.timDtmType).ToList(); if (l1.Any()) { //已经识别 mo.attList[i].ListEmpRead.Add(new DutyDiyEmpReadMo() { IsDeviceRead = "1", EmpName = empObj.EMP_NAME, EmpImg = "/" + empObj.PHOTO, DeviceReadTime = l1.First().tim, DeviceReadImgUrl = l1.First().imgUrl, EmpPhone = empPhone, }); } else { //未识别 mo.attList[i].ListEmpRead.Add(new DutyDiyEmpReadMo() { IsDeviceRead = "0", DeviceReadTime = "", EmpImg = "/" + empObj.PHOTO, EmpName = empObj.EMP_NAME, DeviceReadImgUrl = defaultImg, EmpPhone = empPhone, }); } } else { //未识别 mo.attList[i].ListEmpRead.Add(new DutyDiyEmpReadMo() { IsDeviceRead = "0", DeviceReadTime = "", EmpImg = "/" + empObj.PHOTO, EmpName = empObj.EMP_NAME, DeviceReadImgUrl = defaultImg, EmpPhone = empPhone, }); } } } } break; } } } } } } //如果没有设定设备信息 if (!isDeviceRead) { //遍历处理人员信息 for (int i = 0; i < mo.attList.Count; i++) { var obj = mo.attList[i]; mo.attList[i].ListEmpRead = new List(); var str1 = obj.RowVal; var arrEmp1 = str1.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); var arrEmpName = obj.RowSelEmpName.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (arrEmp1.Length > 0) { //类型:0、输入项;1、选择项;2、人员选择;3、时间范围; switch (obj.RowType) { case "2": case "3": for (int j = 0; j < arrEmp1.Length; j++) { //手机号 var empPhone = arrEmp1[j]; string empName = ""; string defaultImg = "/images/imgPerDefaut.jpg"; if (arrEmpName.Length > j) { empName = arrEmpName[j]; } mo.attList[i].ListEmpRead.Add(new DutyDiyEmpReadMo() { IsDeviceRead = "0", DeviceReadTime = "", EmpImg = defaultImg, EmpName = empName, DeviceReadImgUrl = defaultImg, EmpPhone = empPhone, }); } break; } } } } List list1 = mo.attList; //熟悉信息集合 var listAtt = list1.Where(p => p.IsTable == "1").ToList(); for (int i = 0; i < listAtt.Count(); i++) { try { retMo.dataAttribList.Add(new DutyDiyTemplateItemMo() { ID = listAtt[i].ID, RowVal = listAtt[i].RowVal, ColNum = listAtt[i].ColNum, DtmStr = listAtt[i].DtmStr, IsTable = listAtt[i].IsTable, RowSpan = listAtt[i].RowSpan, RowType = listAtt[i].RowType, OptionList = listAtt[i].OptionList, RowTitle = listAtt[i].RowTitle, TableNum = listAtt[i].TableNum, ColNumCount = listAtt[i].ColNumCount, RowNumCount = listAtt[i].RowNumCount, IsDeviceRead = listAtt[i].IsDeviceRead, RowSelEmpName = listAtt[i].RowSelEmpName, DeviceReadTime = listAtt[i].DeviceReadTime, DeviceReadImgUrl = listAtt[i].DeviceReadImgUrl, ListEmpRead = listAtt[i].ListEmpRead, }); } catch (Exception ex) { } } //表格属性集合 var listTab = list1.Where(p => p.IsTable == "0").ToList(); //表格分组 var listTabGroup = listTab.GroupBy(p => p.TableNum).ToList(); for (int i = 0; i < listTabGroup.Count(); i++) { DutyDiyTemplateTableMo itemObj = new DutyDiyTemplateTableMo() { ColNumCount = 0, dataAttribList = new List(), RowNumCount = 0 }; var lisItem = listTabGroup[i].ToList(); for (int j = 0; j < lisItem.Count(); j++) { try { if (itemObj.RowNumCount < 1) { int.TryParse(lisItem[j].RowNumCount, out int RowCount); itemObj.RowNumCount = RowCount; } if (itemObj.ColNumCount < 1) { int.TryParse(lisItem[j].ColNumCount, out int ColCount); itemObj.ColNumCount = ColCount; } itemObj.dataAttribList.Add(new DutyDiyTemplateItemMo() { ID = lisItem[j].ID, RowVal = lisItem[j].RowVal, ColNum = lisItem[j].ColNum, DtmStr = lisItem[j].DtmStr, IsTable = lisItem[j].IsTable, RowSpan = lisItem[j].RowSpan, RowType = lisItem[j].RowType, OptionList = lisItem[j].OptionList, RowTitle = lisItem[j].RowTitle, TableNum = lisItem[j].TableNum, ColNumCount = lisItem[j].ColNumCount, RowNumCount = lisItem[j].RowNumCount, DeviceReadTime = lisItem[j].DeviceReadTime, IsDeviceRead = lisItem[j].IsDeviceRead, RowSelEmpName = lisItem[j].RowSelEmpName, DeviceReadImgUrl = lisItem[j].DeviceReadImgUrl, ListEmpRead = lisItem[j].ListEmpRead, }); } catch (Exception ex) { } } retMo.dataTableList.Add(itemObj); } returnstr = "{\"code\":0,\"msg\":\"\","; returnstr += "\"count\":" + dt1.Rows.Count + ",\"data\":"; returnstr += FangYar.Common.JsonHelper.ToJSON1(retMo); returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "摄像头分组操作请求", "根据信息ID获取排班类型信息异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "摄像头分组操作请求", "根据信息ID获取排班类型信息"); return returnstr; } /// /// 删除排班模板信息 /// /// /// private string DelDutyDetailsByID(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { //分组信息ID string did = context.Request.Params["did"]; //拼接更新数据Sql string sql = " update oa_duty_details set IS_DEL = '1' where id='" + did + "' "; var num = FangYar.Common.MySqlHelper.Execute(sql); if (num > 0) { msg = "操作成功!"; code = 1; } else { msg = "操作失败!"; } } 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, "自定义排班功能", "删除排班模板信息"); returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } #endregion public bool IsReusable { get { return false; } } } }