You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
762 lines
33 KiB
762 lines
33 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Web;
|
|
|
|
namespace FangYar.WebUI.ashx
|
|
{
|
|
/// <summary>
|
|
/// OaLeaveHandler 的摘要说明
|
|
/// </summary>
|
|
public class OaPatrolTaskHandler : IHttpHandler
|
|
{
|
|
private FangYar.BLL.OA_PATROL_TASK bll = new FangYar.BLL.OA_PATROL_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 "List":
|
|
returnstr = getTasklist(context);
|
|
break;
|
|
case "Add":
|
|
returnstr = AddTask(context);
|
|
break;
|
|
case "Edit":
|
|
returnstr = EditTask(context);
|
|
break;
|
|
case "UserIdList":
|
|
returnstr = getUserIdTasklist(context);
|
|
break;
|
|
case "getShzSbTasklist":
|
|
returnstr = getShzSbTasklist(context);
|
|
break;
|
|
case "Del":
|
|
returnstr = DelTask(context);
|
|
break;
|
|
case "upPatrolTaskPer":
|
|
returnstr = upPatrolTaskPer(context);
|
|
break;
|
|
case "getFreeTaskByUserId":
|
|
returnstr = getFreeTaskByUserId(context);
|
|
break;
|
|
case "AppAddTask":
|
|
returnstr = AppAddTask(context);
|
|
break;
|
|
case "AppUpdateTask":
|
|
returnstr = AppUpdateTask(context);
|
|
break;
|
|
case "patrolSta":
|
|
returnstr = patrolSta(context);
|
|
break;
|
|
case "getTaskCountStaHome":
|
|
returnstr = getTaskCountStaHome(context);
|
|
break;
|
|
}
|
|
context.Response.Write(returnstr);
|
|
}
|
|
|
|
//查询
|
|
private string getTasklist(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 treeID = context.Request.Params["treeID"];
|
|
|
|
int pageIndex = 1;
|
|
int pageSize = 10;//
|
|
if (!string.IsNullOrEmpty(page)) { pageIndex = int.Parse(page); }
|
|
if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); }
|
|
string where = null;
|
|
if (!string.IsNullOrEmpty(treeID))
|
|
{
|
|
orgId = treeID;
|
|
}
|
|
where = "ORG_ID = '" + orgId + "' ";
|
|
if (!string.IsNullOrEmpty(keyword))
|
|
{
|
|
where += " and NAME like '%" + keyword + "%' or EMP_NAME like '%" + keyword + "%' ";
|
|
}
|
|
returnstr = "{\"code\":0,\"msg\":\"\",";
|
|
int count = bll.GetRecordCount(where);
|
|
returnstr += "\"count\":" + count + ",\"data\":";
|
|
if (count == 0)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else
|
|
{
|
|
List<FangYar.Model.OA_PATROL_TASK> list = bll.QueryList(pageIndex, pageSize, where, " date_format(S_TIME,'%Y-%m-%d %H:%i:%s') desc ");
|
|
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, "巡查任务操作请求", "查询异常:" + e);
|
|
}
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "巡查任务操作请求", "查询");
|
|
return returnstr;
|
|
}
|
|
|
|
//根据User_ID查询
|
|
private string getUserIdTasklist(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
string userid = context.Request.Params["userId"];
|
|
string state = context.Request.Params["state"];
|
|
string keywords = context.Request.Params["keywords"];
|
|
|
|
|
|
//FangYar.BLL.TBL.SysEmpBLL ebll = new FangYar.BLL.TBL.SysEmpBLL();
|
|
//FangYar.Model.TBL.TBL_SYS_EMP_Model empModel = ebll.GetModelByUserID(orgId, userid);
|
|
|
|
string page = context.Request.Params["page"];
|
|
string limit = context.Request.Params["limit"];
|
|
int pageIndex = 1;
|
|
int pageSize = 10;//
|
|
if (!string.IsNullOrEmpty(page)) { pageIndex = int.Parse(page); }
|
|
if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); }
|
|
string where = " 1=1";
|
|
if (!string.IsNullOrEmpty(userid))
|
|
{
|
|
where += " and instr(CONCAT(',', EMP_ID, ','), CONCAT(',', '" + userid + "', ',')) <> 0";
|
|
}
|
|
else
|
|
{
|
|
return "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}";
|
|
}
|
|
if (!String.IsNullOrWhiteSpace(keywords))
|
|
{
|
|
where += " and (EMP_NAME like'%" + keywords + "%'" + " or EXTENDCODE2 like '%" + keywords + "%')";
|
|
}
|
|
if (!string.IsNullOrEmpty(state))
|
|
{
|
|
if (state.Contains(","))
|
|
{
|
|
string[] state_s = state.Split(',');
|
|
string states = "";
|
|
for (int i = 0; i < state_s.Length; i++)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
states = "('" + state_s[i] + "'";
|
|
}
|
|
states += ",'" + state_s[i] + "'";
|
|
}
|
|
states += ")";
|
|
where += " and state in " + states + " ";
|
|
}
|
|
else
|
|
{
|
|
where += " and state = '" + state + "' ";
|
|
}
|
|
}
|
|
returnstr = "{\"code\":0,\"msg\":\"\",";
|
|
int count = bll.GetRecordCount(where);
|
|
returnstr += "\"count\":" + count + ",\"data\":";
|
|
if (count == 0)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else
|
|
{
|
|
List<FangYar.Model.OA_PATROL_TASK> list = bll.QueryList(pageIndex, pageSize, where, " date_format(S_TIME,'%Y-%m-%d %H:%i:%s') desc ");
|
|
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, "巡查任务操作请求", "根据User_ID查询异常:" + e);
|
|
}
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "巡查任务操作请求", "根据User_ID查询");
|
|
return returnstr;
|
|
}
|
|
|
|
|
|
//获取石河子的哨兵的夜间巡查任务
|
|
private string getShzSbTasklist(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
string orgId = context.Request.Params["orgId"];
|
|
string state = context.Request.Params["state"];
|
|
|
|
|
|
//FangYar.BLL.TBL.SysEmpBLL ebll = new FangYar.BLL.TBL.SysEmpBLL();
|
|
//FangYar.Model.TBL.TBL_SYS_EMP_Model empModel = ebll.GetModelByUserID(orgId, userid);
|
|
|
|
string page = context.Request.Params["page"];
|
|
string limit = context.Request.Params["limit"];
|
|
int pageIndex = 1;
|
|
int pageSize = 10;//
|
|
if (!string.IsNullOrEmpty(page)) { pageIndex = int.Parse(page); }
|
|
if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); }
|
|
//string where = " ORG_ID = '" + orgId + "' and DATE_FORMAT( s_time, '%Y-%m-%d %H:%i:%S' ) <= DATE_FORMAT( '" + DateTime.Now.ToString("G") + "', '%Y-%m-%d %H:%i:%S' )";
|
|
//where+= " AND DATE_FORMAT(e_time, '%Y-%m-%d %H:%i:%S' ) >= DATE_FORMAT('" + DateTime.Now.ToString("G") + "', '%Y-%m-%d %H:%i:%S') and EXTENDCODE4 ='1'";
|
|
|
|
string where = " ORG_ID = '" + orgId + "' and (DATE_FORMAT( s_time, '%Y-%m-%d' ) = DATE_FORMAT( '" + DateTime.Now.ToString("G") + "', '%Y-%m-%d' )";
|
|
where += " OR DATE_FORMAT(s_time, '%Y-%m-%d' ) = DATE_FORMAT('" + DateTime.Now.AddDays(1).ToString("G") + "', '%Y-%m-%d') )and EXTENDCODE4 ='1'";
|
|
|
|
if (!string.IsNullOrEmpty(state))
|
|
{
|
|
if (state.Contains(","))
|
|
{
|
|
string[] state_s = state.Split(',');
|
|
string states = "";
|
|
for (int i = 0; i < state_s.Length; i++)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
states = "('" + state_s[i] + "'";
|
|
}
|
|
states += ",'" + state_s[i] + "'";
|
|
}
|
|
states += ")";
|
|
where += " and state in " + states + " ";
|
|
}
|
|
else
|
|
{
|
|
where += " and state = '" + state + "' ";
|
|
}
|
|
}
|
|
returnstr = "{\"code\":0,\"msg\":\"\",";
|
|
int count = bll.GetRecordCount(where);
|
|
returnstr += "\"count\":" + count + ",\"data\":";
|
|
if (count == 0)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else
|
|
{
|
|
List<FangYar.Model.OA_PATROL_TASK> list = bll.QueryList(pageIndex, pageSize, where, " date_format(S_TIME,'%Y-%m-%d %H:%i:%s') desc ");
|
|
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, "巡查任务操作请求", "获取石河子的哨兵的夜间巡查任务异常:" + e);
|
|
}
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "巡查任务操作请求", "获取石河子的哨兵的夜间巡查任务");
|
|
return returnstr;
|
|
}
|
|
|
|
|
|
//添加巡查任务
|
|
private string AddTask(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string taskId = Guid.NewGuid().ToString("N");
|
|
string USER_ID = context.Request.Params["UserId"];
|
|
string orgId = context.Request.Params["orgId"];
|
|
string PLAN_ID = context.Request.Params["PLAN_ID"];
|
|
string NAME = context.Request.Params["NAME"];
|
|
string S_TIME = context.Request.Params["S_TIME"];
|
|
string E_TIME = context.Request.Params["E_TIME"];
|
|
string EMP_ID = context.Request.Params["EMP_ID"];
|
|
string EMP_NAME = context.Request.Params["EMP_NAME"];
|
|
string SPOT_IDS = context.Request.Params["SPOT_IDS"];
|
|
string SPOT_NAMES = context.Request.Params["SPOT_NAMES"];
|
|
string STATE = context.Request.Params["STATE"];
|
|
|
|
//巡查任务表
|
|
FangYar.Model.OA_PATROL_TASK model = new Model.OA_PATROL_TASK();
|
|
model.ID = taskId;
|
|
model.PLAN_ID = PLAN_ID;
|
|
model.NAME = NAME;
|
|
model.S_TIME = S_TIME;
|
|
model.E_TIME = E_TIME;
|
|
model.EMP_ID = EMP_ID;
|
|
model.EMP_NAME = EMP_NAME;
|
|
model.SPOT_IDS = SPOT_IDS;
|
|
model.SPOT_NAMES = SPOT_NAMES;
|
|
model.A_PER = USER_ID;
|
|
model.ORG_ID = orgId;
|
|
model.STATE = STATE;
|
|
|
|
if (bll.Add(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.Add, "巡查任务操作请求", "添加巡查任务");
|
|
return returnstr;
|
|
}
|
|
|
|
//修改巡查任务
|
|
private string EditTask(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string ID = context.Request.Params["ID"];
|
|
string USER_ID = context.Request.Params["UserId"];
|
|
string orgId = context.Request.Params["orgId"];
|
|
string PLAN_ID = context.Request.Params["PLAN_ID"];
|
|
string NAME = context.Request.Params["NAME"];
|
|
string S_TIME = context.Request.Params["S_TIME"];
|
|
string E_TIME = context.Request.Params["E_TIME"];
|
|
string EMP_ID = context.Request.Params["EMP_ID"];
|
|
string EMP_NAME = context.Request.Params["EMP_NAME"];
|
|
string SPOT_IDS = context.Request.Params["SPOT_IDS"];
|
|
string SPOT_NAMES = context.Request.Params["SPOT_NAMES"];
|
|
string STATE = context.Request.Params["STATE"];
|
|
|
|
//巡查任务表
|
|
FangYar.Model.OA_PATROL_TASK model = new Model.OA_PATROL_TASK();
|
|
model.ID = ID;
|
|
model.NAME = NAME;
|
|
model.PLAN_ID = PLAN_ID;
|
|
model.S_TIME = S_TIME;
|
|
model.E_TIME = E_TIME;
|
|
model.EMP_ID = EMP_ID;
|
|
model.EMP_NAME = EMP_NAME;
|
|
model.SPOT_IDS = SPOT_IDS;
|
|
model.SPOT_NAMES = SPOT_NAMES;
|
|
model.ORG_ID = orgId;
|
|
model.STATE = STATE;
|
|
model.U_PER = USER_ID;
|
|
|
|
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 DelTask(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 upPatrolTaskPer(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string taskId = context.Request.Params["taskId"]; //巡查任务ID
|
|
string personName = context.Request.Params["personName"]; //巡查员姓名
|
|
|
|
//巡查任务表
|
|
FangYar.Model.OA_PATROL_TASK model = bll.GetModel(taskId);
|
|
model.EXTENDCODE2 = personName;
|
|
DateTime t1 = DateTime.Now;
|
|
bool flag = false;
|
|
if (!string.IsNullOrEmpty(model.E_TIME))
|
|
{
|
|
t1 = Convert.ToDateTime(model.E_TIME);
|
|
flag = true;
|
|
}
|
|
DateTime t2 = DateTime.Now;
|
|
if (flag && t1 < t2)
|
|
{
|
|
msg = "任务已超时无法再巡查!";
|
|
return "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
|
|
}
|
|
else
|
|
{
|
|
if (personName != "" && personName != null)
|
|
{
|
|
if (bll.Update(model))
|
|
{
|
|
FangYar.BLL.OA_PATROL_TRAJECTORY ptbll = new FangYar.BLL.OA_PATROL_TRAJECTORY();
|
|
DataTable data = ptbll.GetTraList(taskId);
|
|
foreach (DataRow dr in data.Rows)
|
|
{
|
|
string state = dr["STATE"].ToString();
|
|
if (state == "0")
|
|
{
|
|
string id = dr["ID"].ToString();
|
|
ptbll.UpdateByIdYToState(id, personName);
|
|
}
|
|
}
|
|
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 getFreeTaskByUserId(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
string userId = context.Request.Params["userId"];
|
|
|
|
if (bll.ExistsFreeTask(userId))
|
|
{
|
|
FangYar.Model.OA_PATROL_TASK data = bll.GetModelByUserId(userId);
|
|
returnstr = "{\"code\":\"1\",\"msg\":\"" + data.NAME + "\",\"data\":";
|
|
returnstr += FangYar.Common.JsonHelper.ToJson(data);
|
|
returnstr += "}";
|
|
}
|
|
else
|
|
{
|
|
returnstr = "{\"code\":\"0\",\"msg\":\"暂无自由巡检任务\",\"data\":\"\"}";
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
returnstr = "{\"code\":\"-1\",\"msg\":\"error\",\"data\":\"\"}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "巡查任务操作请求", "手机端查询正在巡查的自由巡检任务异常:" + e);
|
|
}
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "巡查任务操作请求", "手机端查询正在巡查的自由巡检任务");
|
|
return returnstr;
|
|
}
|
|
|
|
//添加巡查任务(手机端创建自由巡检任务)
|
|
private string AppAddTask(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
string task_id = "", task_name = "", personName = "";
|
|
try
|
|
{
|
|
string taskId = Guid.NewGuid().ToString("N");
|
|
string orgId = context.Request.Params["orgId"];
|
|
string NAME = context.Request.Params["NAME"];
|
|
string EMP_ID = context.Request.Params["EMP_ID"];
|
|
string EMP_NAME = context.Request.Params["EMP_NAME"];
|
|
string EXTENDCODE2 = context.Request.Params["PATROL_NAME"];
|
|
|
|
FangYar.Model.OA_PATROL_TASK oa_patro_task = bll.GetModelByUserId(EMP_ID);
|
|
if (oa_patro_task != null)
|
|
{
|
|
code = 0;
|
|
task_id = oa_patro_task.ID;
|
|
task_name = oa_patro_task.NAME;
|
|
personName = oa_patro_task.EXTENDCODE2;
|
|
}
|
|
else
|
|
{
|
|
//巡查任务表
|
|
FangYar.Model.OA_PATROL_TASK model = new Model.OA_PATROL_TASK();
|
|
model.ID = taskId;
|
|
model.NAME = NAME;
|
|
model.EMP_ID = EMP_ID;
|
|
model.EMP_NAME = EMP_NAME;
|
|
model.A_PER = EMP_ID;
|
|
model.ORG_ID = orgId;
|
|
model.EXTENDCODE2 = EXTENDCODE2;
|
|
model.EXTENDCODE3 = "1";
|
|
model.STATE = "0";
|
|
|
|
if (bll.AddFreeTask(model))
|
|
{
|
|
msg = "开始巡查!";
|
|
code = 1;
|
|
task_id = model.ID;
|
|
task_name = model.NAME;
|
|
personName = model.EXTENDCODE2;
|
|
}
|
|
else { msg = "网络原因,请稍后重试!"; }
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
code = -1;
|
|
msg = "网络原因,请稍后重试!";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "巡查任务操作请求", "手机端创建自由巡检任务异常:" + e);
|
|
}
|
|
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + ",\"taskId\":\"" + task_id + "\",\"taskName\":\"" + task_name + "\",\"personName\":\"" + personName + "\"}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "巡查任务操作请求", "手机端创建自由巡检任务");
|
|
return returnstr;
|
|
}
|
|
|
|
//修改巡查任务(手机端修改自由巡检任务状态)
|
|
private string AppUpdateTask(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string taskId = context.Request.Params["taskId"];
|
|
string userId = context.Request.Params["userId"];
|
|
|
|
//巡查任务表
|
|
FangYar.Model.OA_PATROL_TASK model = new Model.OA_PATROL_TASK();
|
|
model.ID = taskId;
|
|
model.U_PER = userId;
|
|
model.STATE = "1";
|
|
model.E_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
if (bll.UpdateTaskState(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 patrolSta(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
string data = "";
|
|
try
|
|
{
|
|
string org_id = context.Request.Params["org_id"];
|
|
string s_time = context.Request.Params["s_time"];
|
|
|
|
string is_content = context.Request.Params["is_content"];
|
|
string whereStr = "";
|
|
if (is_content == "1")
|
|
{
|
|
whereStr = " find_in_set(j.org_id, cids) ";
|
|
}
|
|
else
|
|
{
|
|
whereStr = " j.org_id ='" + org_id + "' ";
|
|
}
|
|
if (string.IsNullOrEmpty(s_time))
|
|
{
|
|
s_time = DateTime.Now.ToString("yyyy-MM-dd");
|
|
}
|
|
|
|
DataTable dt = bll.patrolSta(org_id, s_time, whereStr).Tables[0];
|
|
code = 1;
|
|
data = FangYar.Common.JsonHelper.ToJson(dt);
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
msg = "网络原因,请稍后重试!";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "巡查任务操作请求", "巡更任务统计异常:" + e);
|
|
}
|
|
returnstr = "{\"code\":\"" + code + "\",\"msg\":\"" + msg + "\",\"data\":" + data + "}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "巡查任务操作请求", "巡更任务统计");
|
|
return returnstr;
|
|
}
|
|
|
|
//首页巡查巡检统计
|
|
private string getTaskCountStaHome(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
string orgId = context.Request.Params["orgId"];
|
|
//列表
|
|
//获取所有子级,以及子级向对应的所有子级
|
|
string sqlOrgs = " select get_Org_child_list(o.ORG_ID) as cids ,o.* from fire_org o where o.PID='" + orgId + "' and o.type='0' order by field(o.EXTENDCODE1,3,0,2,1) ,o.sort";
|
|
DataTable dtOrgs = FangYar.Common.MySqlHelper.QueryTable(sqlOrgs);
|
|
List<OrgsSta> orgStaList = new List<OrgsSta>();
|
|
|
|
for (int i = 0; i < dtOrgs.Rows.Count; i++)
|
|
{
|
|
orgStaList.Add(new OrgsSta()
|
|
{
|
|
ORGID = dtOrgs.Rows[i]["ORG_ID"].ToString(),
|
|
ORGNAME = dtOrgs.Rows[i]["EXTENDCODE3"].ToString(),
|
|
CIDS = dtOrgs.Rows[i]["CIDS"].ToString()
|
|
});
|
|
}
|
|
|
|
string sql = @"with t1 as (
|
|
select * from oa_patrol_task t,( SELECT get_Org_child_list ( '" + orgId + @"' ) cids ) s where find_in_set( t.org_id, cids )
|
|
-- and date_format(s_time,'%Y-%m-%d') = date_format('2022-06-02','%Y-%m-%d') and date_format(e_time,'%Y-%m-%d') >= date_format('2022-06-02','%Y-%m-%d')
|
|
),t2 as (
|
|
select count(1) as sumCount,org_id from t1 group by t.org_id
|
|
) ,t3 as (
|
|
select count(1) as completeCount,org_id from t1 where state = '1' group by t.org_id
|
|
) select t2.org_id,t2.sumCount,ifnull(t3.completeCount,0) as completeCount from t2 left join t3 on t2.org_id = t3.org_id";
|
|
|
|
DataTable dt = FangYar.Common.MySqlHelper.QueryTable(sql);
|
|
|
|
List<patrolTaskSta> Stalist = new List<patrolTaskSta>();
|
|
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
Stalist.Add(new patrolTaskSta()
|
|
{
|
|
ORGID = dt.Rows[i]["ORG_ID"].ToString(),
|
|
SUMCOUNT = Convert.ToInt32(dt.Rows[i]["SUMCOUNT"].ToString()),
|
|
COMPLETECOUNT = Convert.ToInt32(dt.Rows[i]["COMPLETECOUNT"].ToString())
|
|
});
|
|
}
|
|
|
|
string cumCountStr = "[";
|
|
string completeCountStr = "[";
|
|
string completeRateStr = "[";
|
|
string xDataStr = "[";
|
|
for (int i = 0; i < orgStaList.Count; i++)
|
|
{
|
|
if (i > 0)
|
|
{
|
|
cumCountStr += ",";
|
|
completeCountStr += ",";
|
|
completeRateStr += ",";
|
|
xDataStr += ",";
|
|
}
|
|
double sumCounti = Stalist.Where(p => ("," + orgStaList[i].CIDS + ",").Contains(p.ORGID)).Sum(p => p.SUMCOUNT);
|
|
double completeCounti = Stalist.Where(p => ("," + orgStaList[i].CIDS + ",").Contains(p.ORGID)).Sum(p => p.COMPLETECOUNT);
|
|
cumCountStr += sumCounti == null ? 0 : sumCounti;
|
|
completeCountStr += completeCounti == null ? 0 : completeCounti;
|
|
completeRateStr += sumCounti == 0 ? 0.00 : Math.Round(((double)completeCounti / sumCounti) * 100, 2);
|
|
xDataStr += "\"" + orgStaList[i].ORGNAME + "\"";
|
|
}
|
|
cumCountStr += "]";
|
|
completeCountStr += "]";
|
|
completeRateStr += "]";
|
|
xDataStr += "]";
|
|
|
|
returnstr = "{\"code\":\"1\",\"msg\":\"成功!\",\"data\":";
|
|
returnstr += "{\"sumCount\":" + cumCountStr + ",\"completeCount\":" + completeCountStr;
|
|
returnstr += ",\"completeRate\":" + completeRateStr + ",\"xData\":" + xDataStr + "}}";
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
returnstr = "{\"code\":\"-1\",\"msg\":\"请求异常,请联系平台管理员!\",\"error\":\"" + e.Message + "\",\"data\":{}}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "巡查任务操作请求", "首页巡查巡检统计异常:" + e);
|
|
}
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "巡查任务操作请求", "首页巡查巡检统计");
|
|
return returnstr;
|
|
}
|
|
public class patrolTaskSta
|
|
{
|
|
public string ORGID { get; set; }
|
|
public int SUMCOUNT { get; set; }
|
|
public int COMPLETECOUNT { get; set; }
|
|
}
|
|
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|