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.
388 lines
16 KiB
388 lines
16 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Threading;
|
|
using System.Web;
|
|
|
|
namespace FangYar.WebUI.ashx
|
|
{
|
|
/// <summary>
|
|
/// OaLeaveHandler 的摘要说明
|
|
/// </summary>
|
|
public class OaPatrolDangerHandler : IHttpHandler
|
|
{
|
|
private FangYar.BLL.OA_PATROL_DANGER bll = new FangYar.BLL.OA_PATROL_DANGER();
|
|
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 = getDangerlist(context);
|
|
break;
|
|
case "getDangerModelByTaskId":
|
|
returnstr = getDangerModelByTaskId(context);
|
|
break;
|
|
case "Add":
|
|
returnstr = AddDanger(context);
|
|
break;
|
|
case "AddFreeDanger":
|
|
returnstr = AddFreeDanger(context);
|
|
break;
|
|
case "Edit":
|
|
returnstr = EditDanger(context);
|
|
break;
|
|
}
|
|
context.Response.Write(returnstr);
|
|
}
|
|
|
|
//查询
|
|
private string getDangerlist(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
string orgId = context.Request.Params["orgId"];
|
|
string keyword = context.Request.Params["keywords"];
|
|
string page = context.Request.Params["page"];
|
|
string is_content = context.Request.Params["is_content"];
|
|
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;
|
|
}
|
|
if (is_content == "1")
|
|
{
|
|
where += " org_id in ( select o.org_id from fire_org o,(select get_Org_child_list('" + orgId + "') cids ) s where find_in_set(org_id,cids)) ";
|
|
}
|
|
else
|
|
{
|
|
where = " ORG_ID = '" + orgId + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(keyword))
|
|
{
|
|
where += " and TASK_NAME like '%" + keyword + "%' or ADDR 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_DANGER> list = bll.QueryList(pageIndex, pageSize, where, " STATE , date_format(U_TIME,'%Y-%m-%d %H:%i:%s') DESC , date_format(A_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;
|
|
}
|
|
|
|
//根据任务ID,巡查点ID,轨迹ID查询出一条隐患
|
|
private string getDangerModelByTaskId(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
string taskId = context.Request.Params["taskId"];
|
|
string spotId = context.Request.Params["spotId"];
|
|
string traId = context.Request.Params["traId"];
|
|
FangYar.Model.OA_PATROL_DANGER data = bll.getModelByTaskId(taskId, spotId, traId);
|
|
returnstr = "{\"code\":\"1\",\"msg\":\"" + data.A_DES + "\",\"data\":";
|
|
if (data == null)
|
|
{
|
|
returnstr = "[]";
|
|
}
|
|
else
|
|
{
|
|
returnstr += FangYar.Common.JsonHelper.ToJson(data);
|
|
}
|
|
returnstr += "}";
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "巡查隐患操作请求", "根据任务ID,巡查点ID,轨迹ID查询出一条隐患异常:" + e);
|
|
}
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "巡查隐患操作请求", "根据任务ID,巡查点ID,轨迹ID查询出一条隐患");
|
|
return returnstr;
|
|
}
|
|
|
|
//上报隐患(自由巡检用)
|
|
private string AddFreeDanger(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string dangerId = Guid.NewGuid().ToString("N");
|
|
string ORG_ID = context.Request.Params["ORG_ID"];
|
|
string TYPE = context.Request.Params["TYPE"];
|
|
string TASK_ID = context.Request.Params["TASK_ID"];
|
|
string TASK_NAME = context.Request.Params["TASK_NAME"];
|
|
string A_EMP_ID = context.Request.Params["A_EMP_ID"];
|
|
string A_EMP_NAME = context.Request.Params["A_EMP_NAME"];
|
|
string SPOT_ID = context.Request.Params["SPOT_ID"];
|
|
string POINT = context.Request.Params["POINT"];
|
|
string ADDR = context.Request.Params["ADDR"];
|
|
string A_DES = context.Request.Params["A_DES"];
|
|
string STATE = context.Request.Params["STATE"];
|
|
string EXTENDCODE2 = context.Request.Params["PATROL_NAME"];
|
|
string EXTENDCODE3 = context.Request.Params["TRA_ID"];
|
|
|
|
//上传图片
|
|
string A_PHOTO = UploadFile("OaPatrolDanger", context, dangerId);
|
|
|
|
//巡查隐患表
|
|
FangYar.Model.OA_PATROL_DANGER model = new Model.OA_PATROL_DANGER();
|
|
model.ID = dangerId;
|
|
model.TYPE = TYPE;
|
|
model.TASK_ID = TASK_ID;
|
|
model.TASK_NAME = TASK_NAME;
|
|
model.A_EMP_ID = A_EMP_ID;
|
|
model.A_EMP_NAME = A_EMP_NAME;
|
|
model.SPOT_ID = SPOT_ID;
|
|
model.POINT = POINT;
|
|
model.ADDR = ADDR;
|
|
model.A_PHOTO = A_PHOTO;
|
|
model.ORG_ID = ORG_ID;
|
|
model.A_DES = A_DES;
|
|
model.STATE = STATE;
|
|
model.EXTENDCODE2 = EXTENDCODE2;
|
|
model.EXTENDCODE3 = EXTENDCODE3;
|
|
|
|
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 AddDanger(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string dangerId = Guid.NewGuid().ToString("N");
|
|
string ORG_ID = context.Request.Params["ORG_ID"];
|
|
string TYPE = context.Request.Params["TYPE"];
|
|
string TASK_ID = context.Request.Params["TASK_ID"];
|
|
string TASK_NAME = context.Request.Params["TASK_NAME"];
|
|
string A_EMP_ID = context.Request.Params["A_EMP_ID"];
|
|
string A_EMP_NAME = context.Request.Params["A_EMP_NAME"];
|
|
string SPOT_ID = context.Request.Params["SPOT_ID"];
|
|
string POINT = context.Request.Params["POINT"];
|
|
string ADDR = context.Request.Params["ADDR"];
|
|
//string A_PHOTO = context.Request.Params["A_PHOTO"];
|
|
string PATROL_NAME = context.Request.Params["PATROL_NAME"];
|
|
string A_DES = context.Request.Params["A_DES"];
|
|
string STATE = context.Request.Params["STATE"];
|
|
|
|
//上传图片
|
|
string A_PHOTO = UploadFile("OaPatrolDanger", context, dangerId);
|
|
|
|
FangYar.BLL.OA_PATROL_TRAJECTORY tbll = new FangYar.BLL.OA_PATROL_TRAJECTORY();
|
|
//巡查轨迹表
|
|
FangYar.Model.OA_PATROL_TRAJECTORY tmodel = new Model.OA_PATROL_TRAJECTORY();
|
|
tmodel.TASK_ID = TASK_ID;
|
|
tmodel.ORG_ID = ORG_ID;
|
|
tmodel.SPOT_ID = SPOT_ID;
|
|
tmodel.A_PHOTO = A_PHOTO;
|
|
tmodel.EXTENDCODE2 = PATROL_NAME;
|
|
tmodel.STATE = "1";
|
|
tmodel.IS_DANGER = "1";
|
|
|
|
if (tbll.UpdateByTaskIdAndSpotId(tmodel))
|
|
{
|
|
Thread.Sleep(100);
|
|
FangYar.BLL.OA_PATROL_TRAJECTORY ptrabll = new FangYar.BLL.OA_PATROL_TRAJECTORY();
|
|
DataTable data = ptrabll.GetTraCountState(TASK_ID);
|
|
string wxx = data.Rows[0]["WXX"].ToString();
|
|
bool flag = false;
|
|
if (wxx == "0")
|
|
{
|
|
FangYar.BLL.OA_PATROL_TASK ptbll = new FangYar.BLL.OA_PATROL_TASK();
|
|
FangYar.Model.OA_PATROL_TASK ptmodel = ptbll.GetModel(TASK_ID);
|
|
ptmodel.STATE = "1";
|
|
flag = ptbll.Update(ptmodel);
|
|
}
|
|
else
|
|
{
|
|
flag = true;
|
|
}
|
|
if (flag)
|
|
{
|
|
msg = "该巡检点巡检成功!";
|
|
code = 1;
|
|
}
|
|
|
|
//巡查隐患表
|
|
FangYar.Model.OA_PATROL_DANGER model = new Model.OA_PATROL_DANGER();
|
|
model.ID = dangerId;
|
|
model.TYPE = TYPE;
|
|
model.TASK_ID = TASK_ID;
|
|
model.TASK_NAME = TASK_NAME;
|
|
model.A_EMP_ID = A_EMP_ID;
|
|
model.A_EMP_NAME = A_EMP_NAME;
|
|
model.SPOT_ID = SPOT_ID;
|
|
model.POINT = POINT;
|
|
model.ADDR = ADDR;
|
|
model.A_PHOTO = A_PHOTO;
|
|
model.ORG_ID = ORG_ID;
|
|
model.A_DES = A_DES;
|
|
model.STATE = STATE;
|
|
model.EXTENDCODE2 = tmodel.EXTENDCODE2;
|
|
model.EXTENDCODE3 = tmodel.ID;
|
|
|
|
if (bll.Add(model))
|
|
{
|
|
msg = "添加成功!";
|
|
code = 1;
|
|
}
|
|
else { msg = "添加失败!"; }
|
|
}
|
|
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 EditDanger(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string ID = context.Request.Params["ID"];
|
|
string U_EMP_ID = context.Request.Params["U_EMP_ID"];
|
|
string U_EMP_NAME = context.Request.Params["U_EMP_NAME"];
|
|
string U_DES = context.Request.Params["U_DES"];
|
|
//string U_PHOTO = context.Request.Params["U_PHOTO"];
|
|
string STATE = context.Request.Params["STATE"];
|
|
|
|
//上传图片
|
|
string U_PHOTO = UploadFile("OaPatrolDanger", context, "U_" + ID);
|
|
|
|
//巡查隐患表
|
|
FangYar.Model.OA_PATROL_DANGER model = new Model.OA_PATROL_DANGER();
|
|
model.ID = ID;
|
|
model.U_EMP_ID = U_EMP_ID;
|
|
model.U_EMP_NAME = U_EMP_NAME;
|
|
model.U_DES = U_DES;
|
|
model.U_PHOTO = U_PHOTO;
|
|
model.STATE = STATE;
|
|
|
|
if (bll.UpdateState(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 static string UploadFile(string url, HttpContext context, string CONNMOD_ID)
|
|
{
|
|
string result = "";
|
|
if (context.Request.Files.Count > 0)
|
|
{
|
|
string ImageFilePath = "/Upload/" + url + "/" + DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString();
|
|
if (System.IO.Directory.Exists(HttpContext.Current.Server.MapPath(ImageFilePath)) == false)//如果不存在就创建文件夹
|
|
{
|
|
System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath(ImageFilePath));
|
|
}
|
|
for (int i = 0; i < context.Request.Files.Count; i++)
|
|
{
|
|
HttpPostedFile item = context.Request.Files[i];
|
|
string fileName = CONNMOD_ID + i + ".png";
|
|
try
|
|
{
|
|
string rootPath = System.AppDomain.CurrentDomain.BaseDirectory + ImageFilePath;
|
|
item.SaveAs(rootPath + fileName);
|
|
result += ImageFilePath + fileName + ",";
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
result += "";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "巡查隐患操作请求", "上传图片异常:" + e);
|
|
}
|
|
}
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "巡查隐患操作请求", "上传图片");
|
|
result = result.Substring(0, result.Length - 1);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|