gyhlw_dotnet/网站项目/VRS/Handler/Tanhei.ashx.cs

228 lines
7.6 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace VRS.Handler
{
/// <summary>
/// Tanhei 的摘要说明
/// </summary>
public class Tanhei : BaseHandler, IHttpHandler
{
DataService.BLL.pro_base_gateway bll_gateway = new DataService.BLL.pro_base_gateway();
DataService.BLL.pro_base_sensor bll_sensor = new DataService.BLL.pro_base_sensor();
DataService.BLL.pro_base_device bll_device = new DataService.BLL.pro_base_device();
DataService.BLL.pro_base_device_point bll_device_point = new DataService.BLL.pro_base_device_point();
DataService.BLL.pro_scene_open bll_scene_open = new DataService.BLL.pro_scene_open();
DataService.BLL.pro_scene_base bll_scene_base = new DataService.BLL.pro_scene_base();
DataService.BLL.admin_user bll_user = new DataService.BLL.admin_user();
public void ProcessRequest(HttpContext context)
{
baseContext = context;
context.Response.ContentType = "application/json";
CrossDomain();
if (null == context.Request["action"])
{
var result = GetResult(false, "缺少参数action");
context.Response.Write(result);
context.Response.End();
}
string action = context.Request["action"].ToLower();
//log.write_log("登录接口:" + action);
switch (action)
{
//通过用户获取开放场景
case "queryscenebyuser":
QuerySceneByUser(context);
break;
//获取六个基础网关和属性
case "querygateway":
QueryGateway(context);
break;
//获取基础传感器及答案配置
case "querysensor":
QuerySensor(context);
break;
case "querydevice":
QueryDevice(context);
break;
case "querydevicepoint":
QueryDevicePoint(context);
break;
default:
var result = GetResult(false, "方法名不存在:" + action);
context.Response.Write(result);
break;
}
}
public void QueryGateway(HttpContext context)
{
var lang = context.Request.Params["lang"];
string msg = "";
if (string.IsNullOrEmpty(lang))
{
lang = "0";
msg = "中文";
}
if (lang == "1")
{
msg = "英文";
}
else if (lang == "0")
{
msg = "中文";
}
var list = bll_gateway.GetModelList(string.Format(" r1 ='{0}' ", lang));
var result = GetResult(true, list, msg);
context.Response.Write(result);
context.Response.End();
}
public void QuerySensor(HttpContext context)
{
var lang = context.Request.Params["lang"];
string msg = "";
if (string.IsNullOrEmpty(lang))
{
lang = "0";
msg = "中文";
}
if (lang == "1")
{
msg = "英文";
}
else if (lang == "0")
{
msg = "中文";
}
var list = bll_sensor.GetModelList(string.Format(" r1 ='{0}' ", lang));
var result = GetResult(true, list, msg);
context.Response.Write(result);
context.Response.End();
}
public void QueryDevice(HttpContext context)
{
var lang = context.Request.Params["lang"];
string msg = "";
if (string.IsNullOrEmpty(lang))
{
lang = "0";
msg = "中文";
}
if (lang == "1")
{
msg = "英文";
}
else if (lang == "0")
{
msg = "中文";
}
var list = bll_device.GetModelList(string.Format(" r1 ='{0}' ", lang));
var result = GetResult(true, list, msg);
context.Response.Write(result);
context.Response.End();
}
public void QueryDevicePoint(HttpContext context)
{
var lang = context.Request.Params["lang"];
string msg = "";
if (string.IsNullOrEmpty(lang))
{
lang = "0";
msg = "中文";
}
if (lang == "1")
{
msg = "英文";
}
else if (lang == "0")
{
msg = "中文";
}
var list = bll_device_point.GetModelList(string.Format(" r1 ='{0}' ", lang));
var result = GetResult(true, list, msg);
context.Response.Write(result);
context.Response.End();
}
/// <summary>
/// 查询开放的场景
/// </summary>
/// <param name="context"></param>
public void QuerySceneByUser(HttpContext context)
{
var user_id = context.Request.Params["user_id"];
var user = bll_user.GetModel(user_id);
if (null == user)
{
var ret = GetResult(false, "用户不存在 , user_id:" + user_id);
context.Response.Write(ret);
context.Response.End();
}
var now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
var qry = " 1=1 and state=1 ";
qry = qry + string.Format(" and school_id='{0}' ", user.school_id);
//now>start && now< end
//qry = qry + string.Format(" and start_time<'{0}' ", now);
//qry = qry + string.Format(" and end_time>'{0}' ", now);
qry = qry + string.Format(" and start_time<now() ");
qry = qry + string.Format(" and end_time>now() ");
var list = bll_scene_open.GetModelList(qry);
var user_grade = user.grade;
var dic_scene = new Dictionary<string, DataService.Model.pro_scene_base>();
foreach (var open in list)
{
if (!string.IsNullOrEmpty(open.grade))
{
var array_grade = open.grade.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (array_grade.Contains(user_grade))
{
if (!dic_scene.ContainsKey(open.scene_id))
{
var model = bll_scene_base.GetModel(open.scene_id);
dic_scene.Add(open.scene_id, model);
}
}
}
else
{
if (!dic_scene.ContainsKey(open.scene_id))
{
var model = bll_scene_base.GetModel(open.scene_id);
dic_scene.Add(open.scene_id, model);
}
}
}
var list_scene = dic_scene.Values.Select(s => s.scene_name).ToArray();
var scenes = string.Join(",", list_scene);
var result = GetResult(true, scenes, "");
context.Response.Write(result);
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}