软测单独项目
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.
 
 
 
 
 
 

328 lines
14 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
namespace FangYar.WebUI.ashx
{
/// <summary>
/// FireLeaveHandler 的摘要说明
/// </summary>
public class FirePatrolDangerHandler : IHttpHandler
{
private FangYar.BLL.FIRE_PATROL_DANGER bll = new FangYar.BLL.FIRE_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 "Add":
returnstr = AddDanger(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 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 = null;
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.FIRE_PATROL_DANGER> list = bll.QueryList(pageIndex, pageSize, where, " STATE , U_TIME DESC , A_TIME 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 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_USERS_UID = context.Request.Params["A_USERS_UID"];
string A_USERS_NAME = context.Request.Params["A_USERS_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 A_DES = context.Request.Params["A_DES"];
string STATE = context.Request.Params["STATE"];
FangYar.BLL.FIRE_PATROL_TRAJECTORY tbll = new FangYar.BLL.FIRE_PATROL_TRAJECTORY();
//巡查轨迹表
FangYar.Model.FIRE_PATROL_TRAJECTORY tmodel = new Model.FIRE_PATROL_TRAJECTORY();
tmodel.TASK_ID = TASK_ID;
tmodel.ORG_ID = ORG_ID;
tmodel.SPOT_ID = SPOT_ID;
tmodel.STATE = "1";
if (tbll.UpdateByTaskIdAndSpotId(tmodel))
{
FangYar.BLL.FIRE_PATROL_TRAJECTORY ptrabll = new FangYar.BLL.FIRE_PATROL_TRAJECTORY();
DataTable data = ptrabll.GetTraCountState(TASK_ID);
string wxx = data.Rows[0]["WXX"].ToString();
bool flag = false;
if (wxx == "0")
{
FangYar.BLL.FIRE_PATROL_TASK ptbll = new FangYar.BLL.FIRE_PATROL_TASK();
FangYar.Model.FIRE_PATROL_TASK ptmodel = ptbll.GetModel(TASK_ID);
ptmodel.STATE = "1";
flag = ptbll.Update(ptmodel);
}
else
{
flag = true;
}
if (flag)
{
msg = "该巡检点巡检成功!";
code = 1;
}
//上传图片
string A_PHOTO = UploadFile(context, dangerId);
//巡查隐患表
FangYar.Model.FIRE_PATROL_DANGER model = new Model.FIRE_PATROL_DANGER();
model.ID = dangerId;
model.TYPE = TYPE;
model.TASK_ID = TASK_ID;
model.TASK_NAME = TASK_NAME;
model.A_USERS_UID = A_USERS_UID;
model.A_USERS_NAME = A_USERS_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;
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_USERS_UID = context.Request.Params["U_USERS_UID"];
string U_USERS_NAME = context.Request.Params["U_USERS_NAME"];
string U_DES = context.Request.Params["U_DES"];
//string U_PHOTO = context.Request.Params["U_PHOTO"];
string STATE = context.Request.Params["STATE"];
string PHOTO_NUM = context.Request.Params["PHOTO_NUM"];
//处理中照片
string ING_PHOTO = UploadFileNum("FirePatrolDanger", "0", PHOTO_NUM, context, "ING_" + ID);
//处理后照片
string U_PHOTO = UploadFileNum("FirePatrolDanger", "1", PHOTO_NUM, context, "U_" + ID);
//巡查隐患表
FangYar.Model.FIRE_PATROL_DANGER model = new Model.FIRE_PATROL_DANGER();
model.ID = ID;
model.U_USERS_UID = U_USERS_UID;
model.U_USERS_NAME = U_USERS_NAME;
model.U_DES = U_DES;
model.ING_PHOTO = ING_PHOTO;
model.U_PHOTO = U_PHOTO;
model.U_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
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(HttpContext context, string CONNMOD_ID)
{
string result = "";
if (context.Request.Files.Count > 0)
{
HttpPostedFile item = context.Request.Files[0];
string imageRootPath = "/upload/OaPatrolDanger/";
string extensionStr = System.IO.Path.GetExtension(item.FileName);
string str = System.DateTime.Now.ToString("yyyyHHddHHmmss");
string fileName = str + CONNMOD_ID + extensionStr + ".png";
try
{
string rootPath = System.AppDomain.CurrentDomain.BaseDirectory + imageRootPath;
if (System.IO.Directory.Exists(rootPath))
{
item.SaveAs(rootPath + fileName);
result = imageRootPath + fileName;
}
else
{
System.IO.Directory.CreateDirectory(rootPath);
item.SaveAs(rootPath + fileName);
result = imageRootPath + fileName;
}
}
catch (Exception e)
{
result = "";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "隐患信息操作请求", "上传图片异常:" + e);
}
}
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "隐患信息操作请求", "上传图片");
return result;
}
//上传图片
private static string UploadFileNum(string url, string type, string num, 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));
}
int i = 0;
int y = context.Request.Files.Count;
if (type == "0")
{
if (num != null && num != "")
{
y = int.Parse(num);
}
}
else if (type == "1")
{
if (num != null && num != "")
{
i = int.Parse(num);
}
}
for (; i < y; 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);
}
}
result = result.Substring(0, result.Length - 1);
}
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "隐患信息操作请求", "上传图片");
return result;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}