using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using System.Text; using System.Collections; using System.Reflection; using System.Web.Script.Serialization; using FangYar.Model; using FangYar.BLL; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using System.Text.RegularExpressions; namespace FangYar.WebUI.ashx { /// /// OaLeaveHandler 的摘要说明 /// public class OaRollcallTaskHandler : IHttpHandler { private FangYar.BLL.OA.OA_ROLLCALL_TASK bll = new FangYar.BLL.OA.OA_ROLLCALL_TASK(); 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 "RollcallTaskListByUID": returnstr = GetRollcallTaskListByUID(context); break; case "RollcallTaskList": returnstr = GetRollcallTaskList(context); break; case "RollcallTaskList2": returnstr = GetRollcallTaskList2(context); break; case "Add": returnstr = AddRollcallTask(context); break; case "Edit": returnstr = EditRollcallTask(context); break; case "Del": returnstr = DelRollcallTask(context); break; case "getRecordList": returnstr = DelRollcallTask(context); break; case "getRollcall": returnstr = getRollcall(context); break; } context.Response.Write(returnstr); } //根据UID查询点名任务 private string GetRollcallTaskListByUID(HttpContext context) { string returnstr = ""; try { string UID = context.Request.Params["UID"]; string where = ""; if (!string.IsNullOrEmpty(UID)) { where += " (instr (USERS_UID,'\"ppl_Id\":\"'||'" + UID + "'||'\"')<>0) or (ISSUEUID = '" + UID + "')"; } else { return "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.GetRecordCount(where); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { where += " ORDER BY REPORT_TIME "; List list = bll.GetModelList(where); returnstr += FangYar.Common.JsonHelper.ToJson(list); } returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "点名任务操作请求", "根据UID查询点名任务异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "点名任务操作请求", "根据UID查询点名任务"); return returnstr; } //查询 private string GetRollcallTaskList(HttpContext context) { string returnstr = ""; try { string ORG_ID = context.Request.Params["ORG_ID"]; string treeID = context.Request.Params["treeID"]; string page = context.Request.Params["page"]; string limit = context.Request.Params["limit"]; string keyword = context.Request.Params["keywords"]; string searchTime = context.Request.Params["searchTime"]; string is_content = context.Request.Params["is_content"]; int pageIndex = 1; int pageSize = 10; int startIndex = 0; int endIndex = 10; if (!string.IsNullOrEmpty(page)) { pageIndex = int.Parse(page); } if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); } startIndex = (pageIndex - 1) * pageSize; endIndex = pageSize; string where = ""; string pOrgID = ORG_ID; //if (!string.IsNullOrEmpty(ORG_ID)) //{ // if (is_content == "1") // { // where += " find_in_set(org_id, cids) "; // } // else // { // where += " ORG_ID = '" + ORG_ID + "'"; // } //} string deptId = context.Request.Params["DeptId"]; if (deptId == "0192a6228fca4ed2bea225ad3bbf0dc9") { where = " ISSUEUID in (select users_uid from tbl_sys_emp where dept_id = '"+ deptId + "')"; } else { if (!string.IsNullOrEmpty(treeID) && treeID != ORG_ID) { pOrgID = treeID; if (is_content == "1") { where = "( find_in_set(org_id, cids) ) "; } else { where = " ORG_ID = '" + treeID + "'"; } } else { pOrgID = ORG_ID; if (is_content == "1") { where = "( find_in_set(org_id, cids) ) "; } else { where = " ORG_ID = '" + ORG_ID + "'"; } } } if (!string.IsNullOrEmpty(keyword)) { where += "and TASK_NAME = '" + keyword + "' "; } if (!string.IsNullOrEmpty(searchTime)) { string startTime = "", endTime = ""; if (searchTime.IndexOf(" 到 ") != -1) { startTime = Regex.Split(searchTime, " 到 ", RegexOptions.IgnoreCase)[0]; endTime = Regex.Split(searchTime, " 到 ", RegexOptions.IgnoreCase)[1]; } where += " and ( STR_TO_DATE(REPORT_TIME,'%Y-%m-%d')>=STR_TO_DATE('" + startTime + "','%Y-%m-%d')" + " and STR_TO_DATE(REPORT_TIME,'%Y-%m-%d')<= STR_TO_DATE('" + endTime + "', '%Y-%m-%d') ) "; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.GetRecordCount(where, pOrgID); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { DataSet list = bll.GetListByPage(where, "REPORT_TIME desc", startIndex, endIndex, pOrgID); returnstr += FangYar.Common.JsonHelper.ToJson(list.Tables[0]); } returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "点名任务操作请求", "查询异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "点名任务操作请求", "查询"); return returnstr; } //APP点名任务列表(APP专属方法) private string GetRollcallTaskList2(HttpContext context) { string returnstr = ""; try { string ORG_ID = context.Request.Params["ORG_ID"]; string treeID = context.Request.Params["treeID"]; string page = context.Request.Params["page"]; string limit = context.Request.Params["limit"]; string keyword = context.Request.Params["keywords"]; string searchTime = context.Request.Params["searchTime"]; string is_content = context.Request.Params["is_content"]; int pageIndex = 1; int pageSize = 10; int startIndex = 0; int endIndex = 10; if (!string.IsNullOrEmpty(page)) { pageIndex = int.Parse(page); } if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); } startIndex = (pageIndex - 1) * pageSize; endIndex = pageSize; string where = ""; string pOrgID = ORG_ID; //if (!string.IsNullOrEmpty(ORG_ID)) //{ // if (is_content == "1") // { // where += " find_in_set(org_id, cids) "; // } // else // { // where += " ORG_ID = '" + ORG_ID + "'"; // } //} string deptId = context.Request.Params["DeptId"]; if (deptId == "0192a6228fca4ed2bea225ad3bbf0dc9") { where = " ISSUEUID in (select users_uid from tbl_sys_emp where dept_id = '" + deptId + "')"; } else { if (!string.IsNullOrEmpty(treeID) && treeID != ORG_ID) { pOrgID = treeID; if (is_content == "1") { where = "( find_in_set(org_id, cids) ) "; } else { where = " ORG_ID = '" + treeID + "'"; } } else { pOrgID = ORG_ID; if (is_content == "1") { where = "( find_in_set(org_id, cids) ) "; } else { where = " ORG_ID = '" + ORG_ID + "'"; } } } if (!string.IsNullOrEmpty(keyword)) { where += "and TASK_NAME = '" + keyword + "' "; } if (!string.IsNullOrEmpty(searchTime)) { string startTime = "", endTime = ""; if (searchTime.IndexOf(" 到 ") != -1) { startTime = Regex.Split(searchTime, " 到 ", RegexOptions.IgnoreCase)[0]; endTime = Regex.Split(searchTime, " 到 ", RegexOptions.IgnoreCase)[1]; } where += " and ( STR_TO_DATE(REPORT_TIME,'%Y-%m-%d')>=STR_TO_DATE('" + startTime + "','%Y-%m-%d')" + " and STR_TO_DATE(REPORT_TIME,'%Y-%m-%d')<= STR_TO_DATE('" + endTime + "', '%Y-%m-%d') ) "; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.GetRecordCount(where, pOrgID); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { DataSet list = bll.GetListByPage2(where, "REPORT_TIME desc", startIndex, endIndex, pOrgID); returnstr += FangYar.Common.JsonHelper.ToJson(list.Tables[0]); } returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "点名任务操作请求", "查询异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "点名任务操作请求", "查询"); return returnstr; } //添加点名任务 private string AddRollcallTask(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string USERS_UID = context.Request.Params["USERS_UID"]; string ID = Guid.NewGuid().ToString("N"); string LOCATION = context.Request.Params["LOCATION"]; string REPORT_TIME = context.Request.Params["REPORT_TIME"]; string USERS_NAME = context.Request.Params["USERS_NAME"]; string ORG_ID = context.Request.Params["ORG_ID"]; string ORG_NAME = context.Request.Params["ORG_NAME"]; string REMARKS = context.Request.Params["REMARKS"]; string EXTEND1 = context.Request.Params["EXTEND1"]; string EXTEND2 = context.Request.Params["EXTEND2"]; string EXTEND3 = context.Request.Params["EXTEND3"]; string EXTEND4 = context.Request.Params["EXTEND4"]; string EXTEND5 = context.Request.Params["EXTEND5"]; string EXTEND6 = context.Request.Params["EXTEND6"]; string ISSUEUID = context.Request.Params["ISSUEUID"]; string ISSUENAME = context.Request.Params["ISSUENAME"]; string TASK_NAME = context.Request.Params["TASK_NAME"]; string TIME_TYPE = context.Request.Params["TIME_TYPE"]; //点名任务表 FangYar.Model.OA.OA_ROLLCALL_TASK model = new Model.OA.OA_ROLLCALL_TASK(); model.ID = ID; model.USERS_UID = USERS_UID; model.LOCATION = LOCATION; model.REPORT_TIME = REPORT_TIME; model.USERS_NAME = USERS_NAME; model.ORG_ID = ORG_ID; model.ORG_NAME = ORG_NAME; model.REMARKS = REMARKS; model.EXTEND1 = EXTEND1; model.EXTEND2 = EXTEND2; model.EXTEND3 = EXTEND3; model.EXTEND4 = EXTEND4; model.EXTEND5 = EXTEND5; model.EXTEND6 = EXTEND6; model.ISSUEUID = ISSUEUID; model.ISSUENAME = ISSUENAME; model.TASK_NAME = TASK_NAME; model.TIME_TYPE = TIME_TYPE; if (bll.Add(model)) { msg = "添加成功!"; code = 1; //app推送消息 try { string receiveIds = ""; JObject ppl_s = JsonConvert.DeserializeObject(USERS_UID); FangYar.FYMQTT.MessagePush mp = new FYMQTT.MessagePush(); foreach (JObject obj in ppl_s.Value("data")) { //消息通知记录入库操作 FangYar.Model.TBL.TBL_MESSAGE_LOG tbl_message_log = new Model.TBL.TBL_MESSAGE_LOG(); tbl_message_log.ID = Guid.NewGuid().ToString("N"); tbl_message_log.TITLE = "点名任务"; tbl_message_log.CONTENT = "[" + ISSUENAME + "]下发了一条点名任务,请及时打卡完成!"; tbl_message_log.SENDID = ISSUEUID; tbl_message_log.SENDNAME = ISSUENAME; tbl_message_log.SENDTIME = DateTime.Now.ToString("G"); tbl_message_log.TYPE = "4"; //点名 tbl_message_log.URL = "/pages/team/dmdk/dmdklist"; tbl_message_log.PARAM = ""; tbl_message_log.RECEIVEID = (string)obj["ppl_Id"]; tbl_message_log.RECEIVENAME = (string)obj["ppl_Name"]; tbl_message_log.OPENTIME = ""; tbl_message_log.STATE = "0"; //未读 tbl_message_log.ORG_ID = ORG_ID; //机构ID FangYar.FYMQTT.MessageLog ml = new FangYar.FYMQTT.MessageLog(); ml.MessageLogAdd(tbl_message_log); //调用手机消息发送服务 mp.AloneMsgPush((string)obj["ppl_Id"], "点名任务", "[" + ISSUENAME + "]下发了一条点名任务,请及时打卡完成!", tbl_message_log.ID); } //FangYar.FYMQTT.MessagePush mp = new FYMQTT.MessagePush(); //mp.MultiMsgPush(receiveIds, "[" + ISSUENAME + "]下发了一条点名任务,请及时打卡完成!"); } catch (Exception e) { } } else { msg = "添加失败!"; } } catch (Exception e) { msg = "添加失败:装备编码有重复数据"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "点名任务操作请求", "添加异常:" + e); } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "点名任务操作请求", "添加"); return returnstr; } //修改点名任务 private string EditRollcallTask(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string USERS_UID = context.Request.Params["USERS_UID"]; string ID = context.Request.Params["ID"]; string LOCATION = context.Request.Params["LOCATION"]; string REPORT_TIME = context.Request.Params["REPORT_TIME"]; string USERS_NAME = context.Request.Params["USERS_NAME"]; string ORG_ID = context.Request.Params["ORG_ID"]; string ORG_NAME = context.Request.Params["ORG_NAME"]; string REMARKS = context.Request.Params["REMARKS"]; string EXTEND1 = context.Request.Params["EXTEND1"]; string EXTEND2 = context.Request.Params["EXTEND2"]; string EXTEND3 = context.Request.Params["EXTEND3"]; string EXTEND4 = context.Request.Params["EXTEND4"]; string EXTEND5 = context.Request.Params["EXTEND5"]; string EXTEND6 = context.Request.Params["EXTEND6"]; string ISSUEUID = context.Request.Params["ISSUEUID"]; string ISSUENAME = context.Request.Params["ISSUENAME"]; string TASK_NAME = context.Request.Params["TASK_NAME"]; string TIME_TYPE = context.Request.Params["TIME_TYPE"]; //点名任务表 FangYar.Model.OA.OA_ROLLCALL_TASK model = new Model.OA.OA_ROLLCALL_TASK(); model.ID = ID; model.USERS_UID = USERS_UID; model.LOCATION = LOCATION; model.REPORT_TIME = REPORT_TIME; model.USERS_NAME = USERS_NAME; model.ORG_ID = ORG_ID; model.ORG_NAME = ORG_NAME; model.REMARKS = REMARKS; model.EXTEND1 = EXTEND1; model.EXTEND2 = EXTEND2; model.EXTEND3 = EXTEND3; model.EXTEND4 = EXTEND4; model.EXTEND5 = EXTEND5; model.EXTEND6 = EXTEND6; model.ISSUEUID = ISSUEUID; model.ISSUENAME = ISSUENAME; model.TASK_NAME = TASK_NAME; model.TIME_TYPE = TIME_TYPE; if (bll.Update(model)) { msg = "修改成功!"; code = 1; } else { msg = "修改失败!"; } } catch (Exception e) { msg = "修改失败!"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "点名任务操作请求", "修改异常:" + e); } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "点名任务操作请求", "修改"); return returnstr; } //删除点名记录 private string DelRollcallTask(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string TaskList = context.Request.Params["TaskList"]; string[] TaskArray = TaskList.Split(','); string TaskListString = ""; for (int i = 0; i < TaskArray.Length; i++) { if (i == 0) { TaskListString = "'" + TaskArray[i] + "'"; } else { TaskListString += ",'" + TaskArray[i] + "'"; } } if (bll.DeleteList(TaskListString)) { msg = "删除成功!"; code = 1; } else { msg = "删除失败!"; } } catch (Exception e) { msg = "删除失败!"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "点名任务操作请求", "删除异常:" + e); } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Delete, "点名任务操作请求", "删除"); return returnstr; } //获取点名任务信息、打卡记录 private string getRollcall(HttpContext context) { string returnstr = ""; try { string taskId = context.Request.Params["taskId"]; returnstr = "{\"code\":0,\"msg\":\"\",\"TaskData\":"; List data = bll.getRollcall(taskId); returnstr += FangYar.Common.JsonHelper.ToJson(data[0]); returnstr += ",\"RecordData\":"; returnstr += FangYar.Common.JsonHelper.ToJson(data[1]); returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"TaskData\":[],\"RecordData\":[] }"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "点名任务操作请求", "获取点名任务信息、打卡记录异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "点名任务操作请求", "获取点名任务信息、打卡记录"); return returnstr; } public bool IsReusable { get { return false; } } } }