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)
{
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 "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
{
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}";
}
return returnstr;
}
//查询
private string GetRollcallTaskList(HttpContext context)
{
string returnstr = "";
try
{
string ORG_ID = context.Request.Params["ORG_ID"];
string keyword = context.Request.Params["keywords"];
string page = context.Request.Params["page"];
string limit = context.Request.Params["limit"];
string treeID = context.Request.Params["treeID"];
string type = context.Request.Params["type"];
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 = " 1=1 ";
if (!string.IsNullOrEmpty(treeID) && treeID != ORG_ID)
{
if (is_content == "1")
{
where += " and org_id in ( select o.org_id from fire_org o,(select get_Org_child_list('" + treeID + "') cids ) s where find_in_set(org_id,cids)) ";
}
else
{
where += " and ORG_ID = '" + treeID + "'";
}
}
else
{
if (is_content == "1")
{
where += " and org_id in ( select o.org_id from fire_org o ,(select get_Org_child_list('" + ORG_ID + "') cids ) s where find_in_set(org_id,cids)) ";
}
else
{
where += " and ORG_ID = '" + ORG_ID + "'";
}
}
if (!string.IsNullOrEmpty(keyword))
{
where += " and (ISSUENAME like '%" + keyword + "%' or TASK_NAME like '%" + 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 date(report_time) between '" + startTime + "' and '" + endTime + "' ";
}
returnstr = "{\"code\":0,\"msg\":\"\",";
int count = bll.GetRecordCount(where);
returnstr += "\"count\":" + count + ",\"data\":";
if (count == 0)
{
returnstr += "[]";
}
else
{
DataSet list = bll.GetListByPage(where, "REPORT_TIME desc", startIndex, endIndex);
returnstr += FangYar.Common.JsonHelper.ToJson(list.Tables[0]);
}
returnstr += "}";
}
catch
{
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}";
}
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"];
//点名任务表
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.CREATETIME = DateTime.Now.ToString();
if (bll.Add(model))
{
msg = "添加成功!";
code = 1;
//app推送消息
try
{
string receiveIds = "";
JObject ppl_s = JsonConvert.DeserializeObject(USERS_UID);
foreach (JObject obj in ppl_s.Value("data"))
{
receiveIds += (string)obj["ppl_Id"] + ",";
}
FangYar.FYMQTT.MessagePush mp = new FYMQTT.MessagePush();
mp.MultiMsgPush(receiveIds, "[" + ISSUENAME + "]下发了一条点名任务,请及时打卡完成!");
}
catch (Exception e) { }
}
else { msg = "添加失败!"; }
}
catch
{
msg = "添加失败:装备编码有重复数据";
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
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"];
//点名任务表
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;
if (bll.Update(model))
{
msg = "修改成功!";
code = 1;
}
else { msg = "修改失败!"; }
}
catch
{
msg = "修改失败!";
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
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
{
msg = "删除失败!";
}
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
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\":[] }";
}
return returnstr;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}