using FangYar.Model; using FangYar.Model.OA; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Linq; using System.Web; namespace FangYar.WebUI.ashx { /// /// Oa_PatrolSentryTaskHandler 的摘要说明 /// public class Oa_PatrolSentryTaskHandler : IHttpHandler { private FangYar.BLL.OA.OA_PATROLSENTRYTASK bll = new BLL.OA.OA_PATROLSENTRYTASK(); private FangYar.BLL.FIRE.FIRE_INSPECT ins_bll = new BLL.FIRE.FIRE_INSPECT(); private FangYar.BLL.FIRE.FIRE_SHIFTS shifts_bll = new BLL.FIRE.FIRE_SHIFTS(); private FangYar.BLL.OA_PATROL_SPOT spot_bll = new BLL.OA_PATROL_SPOT(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request.Params["Action"]; string returnstr = ""; switch (action) { case "List": returnstr = getList(context); break; case "getInspectList": returnstr = getInspectList(context); break; case "getInspectModel": returnstr = getInspectModel(context); break; case "getShiftsModel": returnstr = getShiftsModel(context); break; case "AddInspect": returnstr = AddInspect(context); break; case "ListByOrgId": returnstr = ListByOrgId(context); break; case "ListBySentryTask": returnstr = ListBySentryTask(context); break; case "Del": returnstr = Del(context); break; //生成两次查铺查哨任务 case "AddTran": returnstr = AddTran(context); break; case "DelSentryTask": returnstr = DelSentryTask(context); break; case "GetInspectEcharsData": returnstr = GetInspectEcharsData(context); break; } context.Response.Write(returnstr); } //查询 private string getList(HttpContext context) { string returnstr = ""; try { string PATROLLERID = context.Request.Params["PATROLLERID"]; 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); } int endIndex = pageSize; int startIndex = (pageIndex - 1) * pageSize; string where = null; where = " PATROLLERID = '" + PATROLLERID + "' "; returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.GetRecordCount(where); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { DataTable dt = bll.GetListByPage(where, " BEGINDATE desc", startIndex, endIndex).Tables[0]; returnstr += FangYar.Common.JsonHelper.ToJson(dt); } returnstr += "}"; } catch { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } return returnstr; } private string getInspectList(HttpContext context) { string returnstr = ""; try { string SENTRYTASKID = context.Request.Params["SENTRYTASKID"]; string where = null; where = " SENTRYTASKID = '" + SENTRYTASKID + "' "; returnstr = "{\"code\":0,\"msg\":\"\","; int count = ins_bll.GetRecordCount(where); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { DataTable dt = ins_bll.GetList(where).Tables[0]; returnstr += FangYar.Common.JsonHelper.ToJson(dt); } returnstr += "}"; } catch { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } return returnstr; } //根据IFID(芯片编号)得到一个对象实体(查铺查哨判断被查人是否在岗) private string getInspectModel(HttpContext context) { int code = -1; string msg = ""; int count = 0; string data = ""; try { string SENTRYTASKID = context.Request.Params["SENTRYTASKID"]; string FID = context.Request.Params["FID"]; string where = null; where = " SENTRYTASKID = '" + SENTRYTASKID + "' "; where += " and FID = '" + FID + "' "; count = ins_bll.GetRecordCount(where); if (count == 0) { code = 0; msg = "未查询到巡检点信息,请您核对。"; data += "[]"; } else { code = 1; msg = "OK"; DataTable dt = ins_bll.GetList(where).Tables[0]; data += FangYar.Common.JsonHelper.ToJson(dt); } } catch { code = -1; msg = "系统错误,请联系管理员!"; count = 0; data = "[]"; } string returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\",\"count\":" + count + ",\"data\":" + data + "}"; return returnstr; } //添加查铺 private string AddInspect(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string ID = context.Request.Params["ID"]; string CN_ID = context.Request.Params["CN_ID"]; string CN_NAME = context.Request.Params["CN_NAME"]; string SN_ID = context.Request.Params["SN_ID"]; string SN_NAME = context.Request.Params["SN_NAME"]; string FID = context.Request.Params["FID"]; string L_STATE = context.Request.Params["L_STATE"]; string L_WORK = context.Request.Params["L_WORK"]; string ADDR = context.Request.Params["ADDR"]; string LON = context.Request.Params["LON"]; string LAT = context.Request.Params["LAT"]; string ORG_ID = context.Request.Params["ORG_ID"]; string EXTENDCODE1 = context.Request.Params["EXTENDCODE1"]; string EXTENDCODE2 = context.Request.Params["EXTENDCODE2"]; string EXTENDCODE3 = context.Request.Params["EXTENDCODE3"]; string EXTENDCODE4 = context.Request.Params["EXTENDCODE4"]; string EXTENDCODE5 = context.Request.Params["EXTENDCODE5"]; string EXTENDCODE6 = context.Request.Params["EXTENDCODE6"]; string LEAVE_PER = context.Request.Params["LEAVE_PER"]; string LEAVE_NUM = context.Request.Params["LEAVE_NUM"]; string FORMAT = context.Request.Params["FORMAT"]; //上传图片 string A_PHOTO = UploadFile("FireInspect", context, ID); //查铺查哨表 FangYar.Model.FIRE.FIRE_INSPECT2 model = ins_bll.GetModel2(ID); if (model != null) { model.ID = ID; model.CN_ID = CN_ID; model.CN_NAME = CN_NAME; model.L_DATE = DateTime.Now; model.L_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); model.SN_ID = SN_ID; model.SN_NAME = SN_NAME; model.FID = FID; model.L_STATE = L_STATE; model.L_WORK = L_WORK; model.ADDR = ADDR; model.LON = LON; model.LAT = LAT; model.ORG_ID = ORG_ID; model.EXTENDCODE1 = EXTENDCODE1; model.EXTENDCODE2 = EXTENDCODE2; model.EXTENDCODE3 = EXTENDCODE3; model.EXTENDCODE4 = EXTENDCODE4; model.EXTENDCODE5 = EXTENDCODE5; model.EXTENDCODE6 = EXTENDCODE6; model.LEAVE_PER = LEAVE_PER; model.LEAVE_NUM = LEAVE_NUM; model.A_PHOTO = A_PHOTO; model.FORMAT = FORMAT; } if (ins_bll.Update2(model)) { msg = "添加成功!"; code = 1; } else { msg = "添加失败!"; } } catch (Exception e) { msg = "添加失败"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } //根据当前哨位值班人 private string getShiftsModel(HttpContext context) { int code = -1; string msg = ""; int count = 0; string data = ""; try { string FID = context.Request.Params["FID"]; string where = null; where = " EXTENDCODE3 = '" + FID + "' "; count = shifts_bll.GetRecordCount(where); if (count == 0) { code = 0; //msg = "未查询到哨位点配置信息,请您核对。"; msg = "该点不为哨位点或未制定哨兵值班任务!"; data += "[]"; } else { where += " and O_DATE < date_format('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','%Y-%m-%d %H:%i:%s')"; where += " and T_DATE > date_format('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','%Y-%m-%d %H:%i:%s')"; int count2 = shifts_bll.GetRecordCount(where); if (count2 == 0) { code = 0; msg = "当前时间未配置在岗人员!"; data += "[]"; } else { code = 1; msg = "OK"; DataTable dt = shifts_bll.GetList(where).Tables[0]; string datastr = "{ \"data\":["; for (int i = 0; i < dt.Rows.Count; i++) { //此处O_ID应为账号,以后再改 datastr += "{\"ppl_Id\":\"" + dt.Rows[i]["O_UID"].ToString() + "\",\"ppl_Name\":\"" + dt.Rows[i]["O_NAME"].ToString() + "\"}"; if (i < dt.Rows.Count - 1) { datastr += ","; } } datastr += "]}"; data = datastr; } } } catch { code = -1; msg = "系统错误,请联系管理员!"; count = 0; data = "[]"; } string returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\",\"count\":" + count + ",\"data\":" + data + "}"; 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; System.Drawing.Image img = Image.FromStream(item.InputStream); //创建画布 System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img); g.DrawString(DateTime.Now.ToString(), new Font("黑体", 100), new SolidBrush(Color.Black), 10, 10); //释放画布 g.Dispose(); System.Drawing.Image img2 = new Bitmap(img); img.Dispose(); img2.Save(rootPath + fileName); img2.Dispose(); result += ImageFilePath + fileName + ","; } catch (Exception e) { result += ""; } // try // { // string rootPath = System.AppDomain.CurrentDomain.BaseDirectory + ImageFilePath; // item.SaveAs(rootPath + fileName); // result += ImageFilePath + fileName + ","; // } // catch // { // result += ""; // } } result = result.Substring(0, result.Length - 1); } return result; } // private string ListByOrgId(HttpContext context) { string returnstr = ""; try { string OrgId = context.Request.Params["OrgId"]; 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); } int startIndex = (pageIndex - 1) * pageSize; int endIndex = pageSize; string where = ""; if (!string.IsNullOrEmpty(OrgId)) { where = " ORGID ='" + OrgId + "'"; } 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 { DataTable dt = bll.GetListByPage(where, " BEGINDATE desc", startIndex, endIndex).Tables[0]; returnstr += FangYar.Common.JsonHelper.ToJson(dt); } returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } return returnstr; } // private string ListBySentryTask(HttpContext context) { string returnstr = ""; try { string SentryTaskID = context.Request.Params["SentryTaskID"]; string where = ""; if (!string.IsNullOrEmpty(SentryTaskID)) { where = " SENTRYTASKID ='" + SentryTaskID + "'"; } else { return "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = ins_bll.GetRecordCount(where); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { DataTable dt = ins_bll.GetList(where).Tables[0]; returnstr += FangYar.Common.JsonHelper.ToJson(dt); } returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } return returnstr; } private string Del(HttpContext context) { string returnstr = ""; try { string ID = context.Request.Params["ID"]; returnstr = "{\"code\":0,\"msg\":\"\","; if (ins_bll.Delete(ID)) { returnstr = "{\"code\":1,\"msg\":\"删除成功!\",\"data\":[]}"; } else { returnstr = "{\"code\":0,\"msg\":\"删除失败!\",\"data\":[]}"; } } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"删除失败!\",\"data\":[]}"; } return returnstr; } //private string AddTran(HttpContext context) //{ // string returnstr = ""; // try // { // //string ID = Guid.NewGuid().ToString("N"); // string ID = BitConverter.ToString(Guid.NewGuid().ToByteArray()).Replace("-", ""); // string orgid = context.Request.Params["orgid"]; // string patrollerid = context.Request.Params["patrollerid"]; // string patroller = context.Request.Params["patroller"]; // string plandate = context.Request.Params["plandate"]; // string startTime = context.Request.Params["startTime"]; // string endTime = context.Request.Params["endTime"]; // string createby = context.Request.Params["createby"]; // FangYar.Model.OA.OA_PATROLSENTRYTASK model = new Model.OA.OA_PATROLSENTRYTASK(); // model.ID = ID; // model.ORGID = orgid; // //model.TASKNAME = plandate + "-" + Convert.ToDateTime(plandate).AddDays(1).ToString("yyyy-MM-dd") + "查铺查哨任务"; // model.TASKNAME = plandate + "查铺查哨任务"; // model.PATROLLERID = patrollerid; // model.PATROLLER = patroller; // model.BEGINDATE = Convert.ToDateTime(startTime); // model.ENDDATE = Convert.ToDateTime(endTime); // model.STATE = "0"; // model.CREATEDATE = DateTime.Now; // model.CREATEBY = createby; // model.UPDATEDATE = DateTime.Now; // model.UPDATEBY = ""; // //查询巡查点信息 // FangYar.Model.OA_PATROL_SPOT dalpatrolspot = new Model.OA_PATROL_SPOT(); // string where = " 1=1 and ( extendcode1='1' or extendcode1='2') and ORG_ID='" + orgid + "'"; // DataTable patrolspot = spot_bll.GetList(where).Tables[0]; // if (bll.AddTran(model, patrolspot)) // { // returnstr = "{\"code\":1,\"msg\":\"添加成功!\",\"data\":[]}"; // } // else // { // returnstr = "{\"code\":0,\"msg\":\"添加失败!\",\"data\":[]}"; // } // } // catch (Exception e) // { // returnstr = "{\"code\":-1,\"msg\":\"添加失败!\",\"data\":[]}"; // } // return returnstr; //} private string AddTran(HttpContext context) { string returnstr = ""; try { //string ID = Guid.NewGuid().ToString("N"); string ID = ""; string orgid = context.Request.Params["orgid"]; string patrollerid = context.Request.Params["patrollerid"]; string patroller = context.Request.Params["patroller"]; string plandate = context.Request.Params["plandate"]; string startTime = context.Request.Params["startTime"]; string endTime = context.Request.Params["endTime"]; string createby = context.Request.Params["createby"]; string startTime2 = context.Request.Params["startTime2"]; string endTime2 = context.Request.Params["endTime2"]; FangYar.Model.OA.OA_PATROLSENTRYTASK model = new Model.OA.OA_PATROLSENTRYTASK(); model.ID = BitConverter.ToString(Guid.NewGuid().ToByteArray()).Replace("-", ""); model.ORGID = orgid; //model.TASKNAME = plandate + "-" + Convert.ToDateTime(plandate).AddDays(1).ToString("yyyy-MM-dd") + "查铺查哨任务"; model.TASKNAME = plandate + "查铺查哨任务"; model.PATROLLERID = patrollerid; model.PATROLLER = patroller; model.BEGINDATE = Convert.ToDateTime(startTime); model.ENDDATE = Convert.ToDateTime(endTime); model.STATE = "0"; model.CREATEDATE = DateTime.Now; model.CREATEBY = createby; model.UPDATEDATE = DateTime.Now; model.UPDATEBY = ""; //查询巡查点信息 FangYar.Model.OA_PATROL_SPOT dalpatrolspot = new Model.OA_PATROL_SPOT(); string where = " 1=1 and ( extendcode1='1' or extendcode1='2') and ORG_ID='" + orgid + "'"; DataTable patrolspot = spot_bll.GetList(where).Tables[0]; if (bll.AddTran(model, patrolspot)) { returnstr = "{\"code\":1,\"msg\":\"添加成功!\",\"data\":[]}"; } else { returnstr = "{\"code\":0,\"msg\":\"添加失败!\",\"data\":[]}"; } //添加第二次 model.ID = BitConverter.ToString(Guid.NewGuid().ToByteArray()).Replace("-", ""); model.BEGINDATE = Convert.ToDateTime(startTime2); model.ENDDATE = Convert.ToDateTime(endTime2); if (bll.AddTran(model, patrolspot)) { returnstr = "{\"code\":1,\"msg\":\"添加成功!\",\"data\":[]}"; } else { returnstr = "{\"code\":0,\"msg\":\"添加失败!\",\"data\":[]}"; } } catch (Exception e) { returnstr = "{\"code\":-1,\"msg\":\"添加失败!\",\"data\":[]}"; } return returnstr; } private string DelSentryTask(HttpContext context) { string returnstr = ""; try { string idList = context.Request.Params["idList"]; //string[] idArray = idList.Split(','); //string idListString = ""; //for (int i = 0; i < idArray.Length; i++) //{ // if (i == 0) // { // idListString = "'" + idArray[i] + "'"; // } // else // { // idListString += ",'" + idArray[i] + "'"; // } //} if (bll.DeleteList(idList)) { returnstr = "{\"code\":1,\"msg\":\"删除成功!\",\"data\":[]}"; } else { returnstr = "{\"code\":0,\"msg\":\"删除失败!\",\"data\":[]}"; } } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"删除失败!\",\"data\":[]}"; } return returnstr; } #region 询巡查数据统计 wr /// /// 查询巡查数据统计 /// /// /// private string GetInspectEcharsData(HttpContext context) { JsonRetMo retMo = new JsonRetMo() { code = "1", data = new OA_PATROL_StatisticsMO(), msg = "" }; try { //机构信息ID string OrgId = context.Request.Params["OrgId"]; //查询日期 string dayStr = context.Request.Params["day"]; //查询所有巡查详情 string sqlSpotDetails = @"SELECT distinct ORG_ID,SPOT_ID,TASK_ID from OA_PATROL_TRAJECTORY WHERE date_format(TIME,'%Y-%m-%d %H:%i:%s') >= date_format('" + dayStr + @" 0:0:0', '%Y-%m-%d %H:%i:%s') and date_format(TIME,'%Y-%m-%d %H:%i:%s') <= date_format('" + dayStr + @" 23:59:59', '%Y-%m-%d %H:%i:%s') and ORG_ID in (select ORG_ID from FIRE_ORG t,(select get_Org_child_list('" + OrgId + "') cids ) s where find_in_set(org_id,cids) )"; //查询所有巡查点详情结果集 DataTable dtSpotDetails = FangYar.Common.MySqlHelper.QueryTable(sqlSpotDetails); //所有巡查点详情缓存集合 List SpotDetails = new List(); //遍历添加所有巡查点详情信息 for (int i = 0; i < dtSpotDetails.Rows.Count; i++) { SpotDetails.Add(new OA_PATROL_SpotDetailsMO() { ORG_ID = dtSpotDetails.Rows[i]["ORG_ID"] + "", SPOT_ID = dtSpotDetails.Rows[i]["SPOT_ID"] + "", TASK_ID = dtSpotDetails.Rows[i]["TASK_ID"] + "", }); } //查铺查哨任务 string sqlTaskCS = @"select ID TASK_ID,ORGID ORG_ID,'' SPOT_IDS,TASKNAME TASK_NAME from OA_PATROLSENTRYTASK where BEGINDATE >= date_format('" + dayStr + @" 0:0:0', '%Y-%m-%d %H:%i:%s') and ENDDATE <= date_format('" + dayStr + @" 23:59:59', '%Y-%m-%d %H:%i:%s') and ORGID in (select ORG_ID from FIRE_ORG t ,(select get_Org_child_list('" + OrgId + "') cids ) s where find_in_set(org_id,cids) )"; DataTable dtTaskCS = FangYar.Common.MySqlHelper.QueryTable(sqlTaskCS); List listTaskCS = new List(); for (int i = 0; i < dtTaskCS.Rows.Count; i++) { listTaskCS.Add(new OA_PATROL_TaskMO() { ORG_ID = dtTaskCS.Rows[i]["ORG_ID"] + "", SPOT_IDS = dtTaskCS.Rows[i]["SPOT_IDS"] + "", TASK_ID = dtTaskCS.Rows[i]["TASK_ID"] + "", TASK_NAME = dtTaskCS.Rows[i]["TASK_NAME"] + "", }); } //查铺巡查任务 string sqlTaskXC = @"select ID TASK_ID,ORG_ID,SPOT_IDS,NAME TASK_NAME from oa_patrol_task where date_format(S_TIME,'%Y-%m-%d %H:%i:%s') >= date_format('" + dayStr + @" 0:0:0', '%Y-%m-%d %H:%i:%s') and date_format(E_TIME,'%Y-%m-%d %H:%i:%s') <= date_format('" + dayStr + @" 23:59:59', '%Y-%m-%d %H:%i:%s') and ORG_ID in (select ORG_ID from FIRE_ORG t,(select get_Org_child_list('" + OrgId + "') cids ) s where find_in_set(org_id,cids) )"; DataTable dtTaskXC = FangYar.Common.MySqlHelper.QueryTable(sqlTaskXC); List listTaskXC = new List(); for (int i = 0; i < dtTaskXC.Rows.Count; i++) { listTaskXC.Add(new OA_PATROL_TaskMO() { ORG_ID = dtTaskXC.Rows[i]["ORG_ID"] + "", SPOT_IDS = dtTaskXC.Rows[i]["SPOT_IDS"] + "", TASK_ID = dtTaskXC.Rows[i]["TASK_ID"] + "", TASK_NAME = dtTaskXC.Rows[i]["TASK_NAME"] + "", }); } //查询所有巡查点 string sqlSpot = "SELECT * from OA_PATROL_SPOT where ORG_ID in (select ORG_ID from FIRE_ORG t ,(select get_Org_child_list('" + OrgId + "') cids ) s where find_in_set(org_id,cids))"; //查询所有巡查点结果集 DataTable dtSpot = FangYar.Common.MySqlHelper.QueryTable(sqlSpot); //所有巡查点缓存集合 List listSpot = new List(); //遍历添加所有巡查点信息 for (int i = 0; i < dtSpot.Rows.Count; i++) { try { listSpot.Add(new OA_PATROL_SpotDetailsMO() { ORG_ID = dtSpot.Rows[i]["ORG_ID"] + "", SPOT_ID = dtSpot.Rows[i]["ID"] + "", EXTENDCODE1 = dtSpot.Rows[i]["EXTENDCODE1"] + "", NAME = dtSpot.Rows[i]["NAME"] + "", }); } catch (Exception e) { } } //返回echar结果集模型 OA_PATROL_Statistics_EcharMO echarMo = new OA_PATROL_Statistics_EcharMO() { listCPData = new List(), listCSData = new List(), listOrgName = new List(), listXCData = new List(), }; //查询所有机构 string sqlOrg = "select * from FIRE_ORG t,(select get_Org_child_list('" + OrgId + "') cids ) s where type='0' and find_in_set(org_id,cids) "; DataTable dtOrg = FangYar.Common.MySqlHelper.QueryTable(sqlOrg); List listOrg = new List(); for (int i = 0; i < dtOrg.Rows.Count; i++) { try { string ORG_ID = dtOrg.Rows[i]["ORG_ID"] + ""; string ORG_NAME = dtOrg.Rows[i]["ORG_NAME"] + ""; //巡查点 var listPotItem = listSpot.Where(p => p.ORG_ID == ORG_ID); //查铺点集合 var listCP = listPotItem.Where(p => p.EXTENDCODE1 == "1").ToList(); var listCPItem = listCP.Select(p => p.SPOT_ID).ToList(); //查哨点集合 var listCS = listPotItem.Where(p => p.EXTENDCODE1 == "2").ToList(); var listCSItem = listCS.Select(p => p.SPOT_ID).ToList(); //巡查点集合 //var listXC = listPotItem.Where(p => p.EXTENDCODE1 == "0"); //var listXCItem = listXC.Select(p => p.SPOT_ID); //查铺总点数 int SpotCPCount = listTaskCS.Count * listCPItem.Count; //查哨总点数 int SpotCSCount = listTaskCS.Count * listCSItem.Count; //巡查详情 var listPotDetailsItem = SpotDetails.Where(p => p.ORG_ID == ORG_ID); //所有巡查点 List listAllSpotCP = new List(); List listAllSpotCS = new List(); List listAllSpotXC = new List(); //已经巡查点 List listISCKSpotCP = new List(); List listISCKSpotCS = new List(); List listISCKSpotXC = new List(); //没有巡查点 List listNotCKSpotCP = new List(); List listNotCKSpotCS = new List(); List listNotCKSpotXC = new List(); //遍历查铺查哨任务,加载缓存数据 var listTaskCSORG = listTaskCS.Where(p => p.ORG_ID == ORG_ID).ToList(); for (int j = 0; j < listTaskCSORG.Count; j++) { var TASK_ID = listTaskCSORG[j].TASK_ID; var TASK_Name = listTaskCSORG[j].TASK_NAME; //添加查铺 for (int k = 0; k < listCP.Count; k++) { var SPOT_ID = listCP[k].SPOT_ID; var SPOT_Name = listCP[k].NAME; OA_PATROL_SpotNotCKMO addMo = new OA_PATROL_SpotNotCKMO() { SPOT_ID = SPOT_ID, SPOT_Name = SPOT_Name, TASK_ID = TASK_ID, TASK_Name = TASK_Name }; listAllSpotCP.Add(addMo); if (listPotItem.Any(p => p.TASK_ID == TASK_ID && p.SPOT_ID == SPOT_ID)) { listISCKSpotCP.Add(addMo); } else { listNotCKSpotCP.Add(addMo); } } //添加查哨 for (int k = 0; k < listCS.Count; k++) { var SPOT_ID = listCS[k].SPOT_ID; var SPOT_Name = listCS[k].NAME; OA_PATROL_SpotNotCKMO addMo = new OA_PATROL_SpotNotCKMO() { SPOT_ID = SPOT_ID, SPOT_Name = SPOT_Name, TASK_ID = TASK_ID, TASK_Name = TASK_Name }; listAllSpotCS.Add(addMo); if (listPotItem.Any(p => p.TASK_ID == TASK_ID && p.SPOT_ID == SPOT_ID)) { listISCKSpotCS.Add(addMo); } else { listNotCKSpotCS.Add(addMo); } } } //遍历巡查任务,加载缓存数据 var listTaskXCORG = listTaskXC.Where(p => p.ORG_ID == ORG_ID).ToList(); for (int j = 0; j < listTaskXCORG.Count; j++) { var TASK_ID = listTaskXCORG[j].TASK_ID; var TASK_Name = listTaskXCORG[j].TASK_NAME; var SPOT_IDS = listTaskXCORG[j].SPOT_IDS; //SPOT_IDS = SPOT_IDS.Replace("{\"data\":[]}", ""); List list_SPOT_IDS = new List(); try { if (!string.IsNullOrWhiteSpace(SPOT_IDS)) { //Split(new string[] {"o"}, StringSplitOptions.RemoveEmptyEntries)); var arr = SPOT_IDS.Split(new string[] { "}{" }, StringSplitOptions.RemoveEmptyEntries); for (int l = 0; l < arr.Length; l++) { string str1 = arr[l]; if (!string.IsNullOrWhiteSpace(str1)) { if (arr.Length > 1) { if (l > 0) { str1 = "{" + str1; } if (l < arr.Length - 1) { str1 += "}"; } } var lis = Common.JsonHelper.FromJSON(str1); if (lis != null) { if (lis.data != null) { //添加查哨 for (int k = 0; k < lis.data.Count; k++) { var SPOT_ID = lis.data[k].spot_Id; var SPOT_Name = lis.data[k].spot_Name; OA_PATROL_SpotNotCKMO addMo = new OA_PATROL_SpotNotCKMO() { SPOT_ID = SPOT_ID, SPOT_Name = SPOT_Name, TASK_ID = TASK_ID, TASK_Name = TASK_Name }; listAllSpotXC.Add(addMo); if (listPotItem.Any(p => p.TASK_ID == TASK_ID && p.SPOT_ID == SPOT_ID)) { listISCKSpotXC.Add(addMo); } else { listNotCKSpotXC.Add(addMo); } } } } } } } } catch (Exception exc) { } } //巡查总点数 int SpotXCCount = listAllSpotXC.Count; //总巡查点 int SpotCount = SpotCPCount + SpotCSCount + SpotXCCount; int SpotCPCK = listISCKSpotCP.Count; int SpotCSCK = listISCKSpotCS.Count; int SpotXCCK = listISCKSpotXC.Count; listOrg.Add(new OA_PATROL_Statistics_TableMO() { ORG_ID = ORG_ID, PID = dtOrg.Rows[i]["PID"] + "", TYPE = dtOrg.Rows[i]["TYPE"] + "", ADDR = dtOrg.Rows[i]["ADDR"] + "", CONT = dtOrg.Rows[i]["CONT"] + "", PHONE = dtOrg.Rows[i]["PHONE"] + "", ORG_NAME = ORG_NAME, SpotCount = SpotCount, SpotCPCount = SpotCPCount, SpotCSCount = SpotCSCount, SpotXCCount = SpotXCCount, SpotCPCK = SpotCPCK, SpotCSCK = SpotCSCK, SpotXCCK = SpotXCCK, spotCPInfo = new OA_PATROL_SpotNotCKDataMO() { listAllSpot = listAllSpotCP, listISCKSpot = listISCKSpotCP, listNotCKSpot = listNotCKSpotCP }, spotCSInfo = new OA_PATROL_SpotNotCKDataMO() { listAllSpot = listAllSpotCS, listISCKSpot = listISCKSpotCS, listNotCKSpot = listNotCKSpotCS }, spotXCInfo = new OA_PATROL_SpotNotCKDataMO() { listAllSpot = listAllSpotXC, listISCKSpot = listISCKSpotXC, listNotCKSpot = listNotCKSpotXC }, }); //添加Echar数据 echarMo.listXCData.Add(SpotXCCK); echarMo.listOrgName.Add(ORG_NAME); echarMo.listCSData.Add(SpotCSCK); echarMo.listCPData.Add(SpotCPCK); } catch (Exception e) { } } retMo.data.treeSpid = listOrg.Where(p => p.ORG_ID == OrgId).First().PID; retMo.data.tbData = listOrg; retMo.data.echarData = echarMo; } catch (Exception e) { retMo.code = "0"; retMo.msg = "异常:" + e; } return FangYar.Common.JsonHelper.ToJSON1(retMo); } #endregion public bool IsReusable { get { return false; } } } }