初始化CRICS
This commit is contained in:
601
WebSite/Controllers/WXController.cs
Normal file
601
WebSite/Controllers/WXController.cs
Normal file
@@ -0,0 +1,601 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
using WebSite.Models;
|
||||
using System.Data;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class WXController : BaseController
|
||||
{
|
||||
private const int AuthorityID = 13;
|
||||
private static string codes = System.Configuration.ConfigurationManager.AppSettings["code"];
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(WeiXinController));
|
||||
public IHostManager HostManager { get; set; }
|
||||
public ISysHotelManager SysHotelManager { get; set; }
|
||||
public IRoomTypeWXMenusManager RoomTypeWXMenusManager { get; set; }
|
||||
public IHostModalManager HostModalManager { get; set; }
|
||||
public IRoomTypeSceneManager RoomTypeSceneManager { get; set; }
|
||||
public ILightControlManager LightControlManager { get; set; }
|
||||
public IHostSceneManager HostSceneManager { get; set; }
|
||||
//public IHostAirManager HostAirManager { get; set; }
|
||||
//public ITvControlManager TvControlManager { get; set; }
|
||||
//public IRoomTypeModalManager RoomTypeModalManager { get; set; }
|
||||
//public IRoomServiceManager RoomServiceManager { get; set; }
|
||||
//public IAlarmSettingManager AlarmSettingManager { get; set; }
|
||||
//public ICurtainControlManager CurtainControlManager { get; set; }
|
||||
//public IUnlockControlManager UnlockControlManager { get; set; }
|
||||
//public IMusicControlManager MusicControlManager { get; set; }
|
||||
//public IAppMenuManager AppMenuManager { get; set; }
|
||||
|
||||
public ActionResult Index(string code, string creatDate, string lang = "zh-cn")
|
||||
{
|
||||
switch (lang.ToLower())
|
||||
{
|
||||
case "en":
|
||||
Session["isCN"] = 1;
|
||||
break;
|
||||
case "zh-tw":
|
||||
Session["isCN"] = 2;
|
||||
break;
|
||||
default:
|
||||
Session["isCN"] = 0;
|
||||
break;
|
||||
}
|
||||
SysHotel sysHotel = SysHotelManager.GetByCode(code, Convert.ToDateTime(creatDate));
|
||||
if (sysHotel == null)
|
||||
{
|
||||
ViewData["Error"] = HttpContext.InnerLanguage("WXHotelNotFound");//"酒店未知,请联系管理员。";
|
||||
return View("Error");
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentHotelID = sysHotel.ID;//缓存当前酒店ID
|
||||
return LoginIndex(code, ReturnNameByLanguage(sysHotel.Name, sysHotel.EName, sysHotel.TWName), sysHotel.LogoPath);
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public ActionResult LoginIndex(string hotelCode, string hotelName, string logo)
|
||||
{
|
||||
if (Request.Cookies["WXRoomNumber"] == null)
|
||||
{
|
||||
ViewData["RoomNumber"] = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewData["RoomNumber"] = Request.Cookies["WXRoomNumber"].Value;
|
||||
}
|
||||
//if (codes.IndexOf(",") == -1)
|
||||
//{
|
||||
// ViewData["HotelCode"] = codes;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
ViewData["HotelCode"] = hotelCode;
|
||||
//}
|
||||
ViewData["HotelName"] = hotelName;
|
||||
ViewData["Logo"] = logo;
|
||||
return View("login");
|
||||
}
|
||||
[HttpPost]
|
||||
public ActionResult Login(string code, string roomNumber, string identity)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("WXInvalidRoom") });
|
||||
}
|
||||
else if (!Common.CSRedisCacheHelper.Contains(host.HostNumber, host.MAC))
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("HostOffine") });
|
||||
}
|
||||
else
|
||||
{
|
||||
using (syncstatus.syncstatusSoapClient wsClient = new syncstatus.syncstatusSoapClient())
|
||||
{
|
||||
if (!wsClient.ValidateNumberByCode(code, roomNumber, identity))
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = "验证码有误。" });
|
||||
}
|
||||
}
|
||||
}
|
||||
//登录成功,cookie存储当前房号
|
||||
Response.Cookies["WXRoomNumber"].Value = roomNumber;
|
||||
Response.Cookies["WXRoomNumber"].Expires = DateTime.Now.AddYears(1);
|
||||
//获取微信显示的菜单
|
||||
IList<WXMenu> WXMenuList = new List<WXMenu>();
|
||||
IList<RoomTypeWXMenus> WXMenus = RoomTypeWXMenusManager.LoadAll(host.RoomType.ID).Where(r => r.ActiveIndicator == true).OrderBy(r => r.Sort).ToList();
|
||||
if (WXMenus.Count == 0)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("WXNotSetMenu") });
|
||||
}
|
||||
foreach (RoomTypeWXMenus menu in WXMenus)
|
||||
{
|
||||
WXMenuList.Add(new WXMenu { Code = menu.Code, Name = ReturnNameByLanguage(menu.Name, menu.EName, menu.TWName), TakePower = menu.TakePower });
|
||||
}
|
||||
Session["WXMenuList"] = WXMenuList;
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("LoginSuccessful"), Target = "/WX/WXIndex?RoomNumber=" + roomNumber });//" + WXMenuList[0].Code + "
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("LoginFailed") + ":" + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult WXIndex(string roomNumber)
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = HttpContext.InnerLanguage("WXInvalidRoom");
|
||||
return View("Error");
|
||||
}
|
||||
ViewData["RoomNumber"] = roomNumber;
|
||||
|
||||
return View("Index");
|
||||
}
|
||||
|
||||
public ActionResult WXIndex1(string code, string creatDate, string roomNumber, string identity)
|
||||
{
|
||||
SysHotel sysHotel = SysHotelManager.GetByCode(code, Convert.ToDateTime(creatDate));
|
||||
if (sysHotel == null)
|
||||
{
|
||||
ViewData["Error"] = HttpContext.InnerLanguage("WXHotelNotFound");//"酒店未知,请联系管理员。";
|
||||
return View("Error");
|
||||
}
|
||||
CurrentHotelID = sysHotel.ID;//缓存当前酒店ID
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = HttpContext.InnerLanguage("WXInvalidRoom");
|
||||
return View("Error");
|
||||
}
|
||||
else if (!Common.CSRedisCacheHelper.Contains(host.HostNumber, host.MAC))
|
||||
{
|
||||
ViewData["Error"] = HttpContext.InnerLanguage("HostOffine");
|
||||
return View("Error");
|
||||
}
|
||||
else
|
||||
{
|
||||
using (syncstatus.syncstatusSoapClient wsClient = new syncstatus.syncstatusSoapClient())
|
||||
{
|
||||
if (!wsClient.ValidateNumberByCode(code, roomNumber, identity))
|
||||
{
|
||||
ViewData["Error"] = "验证码有误。";
|
||||
return View("Error");
|
||||
}
|
||||
}
|
||||
}
|
||||
//登录成功,cookie存储当前房号
|
||||
Response.Cookies["WXRoomNumber"].Value = roomNumber;
|
||||
Response.Cookies["WXRoomNumber"].Expires = DateTime.Now.AddYears(1);
|
||||
//获取微信显示的菜单
|
||||
IList<WXMenu> WXMenuList = new List<WXMenu>();
|
||||
IList<RoomTypeWXMenus> WXMenus = RoomTypeWXMenusManager.LoadAll(host.RoomType.ID).Where(r => r.ActiveIndicator == true).OrderBy(r => r.Sort).ToList();
|
||||
if (WXMenus.Count == 0)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("WXNotSetMenu") });
|
||||
}
|
||||
foreach (RoomTypeWXMenus menu in WXMenus)
|
||||
{
|
||||
WXMenuList.Add(new WXMenu { Code = menu.Code, Name = ReturnNameByLanguage(menu.Name, menu.EName, menu.TWName), TakePower = menu.TakePower });
|
||||
}
|
||||
Session["WXMenuList"] = WXMenuList;
|
||||
ViewData["RoomNumber"] = roomNumber;
|
||||
|
||||
return View("Index");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult GetWXData(string roomNumber, string code, bool takePower)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = HttpContext.InnerLanguage("WXInvalidRoom");
|
||||
return View("Error");
|
||||
}
|
||||
bool isControl = true;
|
||||
if (takePower)//如果需要在取电状态才能控制,获取当前取电状态
|
||||
{
|
||||
var takePowerModal = HostModalManager.GetByModalAddress(host.ID, "004000001");
|
||||
if (takePowerModal.Status != 1) isControl = false;
|
||||
}
|
||||
IList<HostModal> hostModals;
|
||||
IList<WXHostModal> result = new List<WXHostModal>();
|
||||
switch (code)
|
||||
{
|
||||
case "mensuo":
|
||||
WXEntity wxEntity = new WXEntity();
|
||||
wxEntity.RoomNumber = roomNumber;
|
||||
wxEntity.HostID = host.ID;
|
||||
wxEntity.WXLockStatus = host.LockStatus;
|
||||
wxEntity.WXLockModalAddress = "";
|
||||
hostModals = HostModalManager.Load(host.ID, DeviceType.WXLock).Where(r => r.Modal.WXActiveIndicator).ToList();
|
||||
if (hostModals.Count > 0)
|
||||
{
|
||||
wxEntity.WXLockModalAddress = hostModals[0].Modal.ModalAddress;
|
||||
}
|
||||
return Json(new { IsSuccess = true, Result = wxEntity, IsControl = isControl }, JsonRequestBehavior.AllowGet);
|
||||
case "changjing":
|
||||
IList<RoomTypeScene> roomTypeScenes = RoomTypeSceneManager.LoadAll().Where(r => r.RoomType.ID == host.RoomType.ID && r.ActiveIndicator).OrderBy(r => r.Sort).ToList();
|
||||
IList<HostScene> hostScene = HostSceneManager.LoadByHostID(host.ID);
|
||||
IList<WXRoomTypeScene> scenseList = new List<WXRoomTypeScene>();
|
||||
foreach (RoomTypeScene scene in roomTypeScenes)
|
||||
{
|
||||
int status = 2;
|
||||
foreach (HostScene hs in hostScene)
|
||||
{
|
||||
if (scene.ID == hs.Scene.ID)
|
||||
{
|
||||
status = hs.Status;
|
||||
break;
|
||||
}
|
||||
}
|
||||
WXRoomTypeScene wxScene = new WXRoomTypeScene { ID = scene.ID, HostID = host.ID, Name = ReturnNameByLanguage(scene.Name, scene.EnglishName, scene.TWName), TakeInverse = scene.TakeInverse, Status = status };
|
||||
scenseList.Add(wxScene);
|
||||
}
|
||||
return Json(new { IsSuccess = true, Result = scenseList, IsControl = isControl }, JsonRequestBehavior.AllowGet);
|
||||
case "fuwu":
|
||||
hostModals = HostModalManager.Load(host.ID, DeviceType.ServiceInfo).Where(r => r.Modal.WXActiveIndicator).ToList();
|
||||
foreach (HostModal modal in hostModals)
|
||||
{
|
||||
WXHostModal wxModal = new WXHostModal();
|
||||
wxModal.HostID = modal.HostID;
|
||||
wxModal.Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName);
|
||||
wxModal.ModalAddress = modal.Modal.ModalAddress;
|
||||
wxModal.Status = modal.Status;
|
||||
result.Add(wxModal);
|
||||
}
|
||||
break;
|
||||
case "fangkong":
|
||||
hostModals = HostModalManager.Load(host.ID, DeviceType.Relay).Where(r => r.Modal.WXActiveIndicator).ToList();
|
||||
foreach (HostModal modal in hostModals)
|
||||
{
|
||||
WXHostModal wxModal = new WXHostModal();
|
||||
wxModal.HostID = modal.HostID;
|
||||
wxModal.Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName);
|
||||
wxModal.ModalAddress = modal.Modal.ModalAddress;
|
||||
wxModal.Status = modal.Status;
|
||||
result.Add(wxModal);
|
||||
}
|
||||
break;
|
||||
case "tiaoguang":
|
||||
hostModals = HostModalManager.LoadByHostID(host.ID).Where(r => r.Modal.WXActiveIndicator).ToList();
|
||||
foreach (HostModal modal in hostModals)
|
||||
{
|
||||
WXHostModal wxModal = new WXHostModal();
|
||||
switch (modal.Modal.Type)
|
||||
{
|
||||
case DeviceType.Dimmer:
|
||||
case DeviceType.PWMDimmer:
|
||||
case DeviceType.PWMExpand:
|
||||
case DeviceType.PBLED:
|
||||
case DeviceType.Traic:
|
||||
case DeviceType.LVout://弱电输出
|
||||
case DeviceType.PB20:
|
||||
case DeviceType.PB20_LD:
|
||||
case DeviceType.PB20_LS:
|
||||
wxModal.HostID = modal.HostID;
|
||||
wxModal.Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName);
|
||||
wxModal.ModalAddress = modal.Modal.ModalAddress;
|
||||
wxModal.Status = modal.Status;
|
||||
wxModal.Brightness = modal.Brightness;
|
||||
result.Add(wxModal);
|
||||
break;
|
||||
case DeviceType.Strip://灯带:过滤000回路
|
||||
if (modal.Modal.ModalAddress.Substring(6) != "000")
|
||||
{
|
||||
wxModal.HostID = modal.HostID;
|
||||
wxModal.Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName);
|
||||
wxModal.ModalAddress = modal.Modal.ModalAddress;
|
||||
wxModal.Status = modal.Status;
|
||||
wxModal.Brightness = modal.Brightness;
|
||||
result.Add(wxModal);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "tiaose"://调色,只要000回路打勾就显示
|
||||
hostModals = HostModalManager.Load(host.ID, DeviceType.Strip).Where(r => r.Modal.ActiveIndicator).OrderBy(r => r.Modal.ModalAddress).ToList();
|
||||
foreach (HostModal modal in hostModals)
|
||||
{
|
||||
IList<WXHostModal> curModal = new List<WXHostModal>();
|
||||
switch (modal.Modal.ModalAddress.Substring(6))
|
||||
{
|
||||
case "000":
|
||||
if (modal.Modal.WXActiveIndicator)
|
||||
{
|
||||
WXHostModal wxModal = new WXHostModal();
|
||||
wxModal.HostID = modal.HostID;
|
||||
wxModal.Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName);
|
||||
wxModal.Status = modal.Status;
|
||||
wxModal.ModalAddress = modal.Modal.ModalAddress;
|
||||
wxModal.Brightness = modal.Brightness;
|
||||
result.Add(wxModal);
|
||||
}
|
||||
break;
|
||||
case "001":
|
||||
curModal = result.Where(r => r.ModalAddress.Substring(0, 6) == modal.Modal.ModalAddress.Substring(0, 6)).ToList();
|
||||
if (curModal.Count > 0)
|
||||
{
|
||||
curModal[0].ModalAddress1 = modal.Modal.ModalAddress;
|
||||
curModal[0].Brightness1 = modal.Brightness;
|
||||
}
|
||||
break;
|
||||
case "002":
|
||||
curModal = result.Where(r => r.ModalAddress.Substring(0, 6) == modal.Modal.ModalAddress.Substring(0, 6)).ToList();
|
||||
if (curModal.Count > 0)
|
||||
{
|
||||
curModal[0].ModalAddress2 = modal.Modal.ModalAddress;
|
||||
curModal[0].Brightness2 = modal.Brightness;
|
||||
}
|
||||
break;
|
||||
case "003":
|
||||
curModal = result.Where(r => r.ModalAddress.Substring(0, 6) == modal.Modal.ModalAddress.Substring(0, 6)).ToList();
|
||||
if (curModal.Count > 0)
|
||||
{
|
||||
curModal[0].ModalAddress3 = modal.Modal.ModalAddress;
|
||||
curModal[0].Brightness3 = modal.Brightness;
|
||||
}
|
||||
break;
|
||||
case "004":
|
||||
curModal = result.Where(r => r.ModalAddress.Substring(0, 6) == modal.Modal.ModalAddress.Substring(0, 6)).ToList();
|
||||
if (curModal.Count > 0)
|
||||
{
|
||||
curModal[0].ModalAddress4 = modal.Modal.ModalAddress;
|
||||
curModal[0].Brightness4 = modal.Brightness;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "kongtiao":
|
||||
hostModals = HostModalManager.Load(host.ID, DeviceType.AirConditioner).Where(r => r.Modal.WXActiveIndicator).ToList();
|
||||
foreach (HostModal modal in hostModals)
|
||||
{
|
||||
WXHostModal wxModal = new WXHostModal();
|
||||
wxModal.HostID = modal.HostID;
|
||||
wxModal.Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName);
|
||||
wxModal.ModalAddress = modal.Modal.ModalAddress;
|
||||
wxModal.Status = modal.Status;
|
||||
wxModal.CurrentTemp = modal.CurrentTemp;
|
||||
wxModal.SettingTemp = modal.SettingTemp < 16 ? 16 : (modal.SettingTemp > 32 ? 32 : modal.SettingTemp);
|
||||
wxModal.FanSpeed = modal.FanSpeed;
|
||||
wxModal.Mode = modal.Mode;
|
||||
wxModal.Valve = modal.Valve;
|
||||
result.Add(wxModal);
|
||||
}
|
||||
break;
|
||||
case "chuanglian":
|
||||
hostModals = HostModalManager.Load(host.ID, DeviceType.Curtain).Where(r => r.Modal.WXActiveIndicator).ToList();
|
||||
foreach (HostModal modal in hostModals)
|
||||
{
|
||||
WXHostModal wxModal = new WXHostModal();
|
||||
wxModal.HostID = modal.HostID;
|
||||
wxModal.Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName);
|
||||
wxModal.ModalAddress = modal.Modal.ModalAddress;
|
||||
wxModal.Status = modal.Status;
|
||||
result.Add(wxModal);
|
||||
}
|
||||
break;
|
||||
case "dianshi":
|
||||
hostModals = HostModalManager.Load(host.ID, DeviceType.TV).Where(r => r.Modal.WXActiveIndicator).ToList();
|
||||
foreach (HostModal modal in hostModals)
|
||||
{
|
||||
WXHostModal wxModal = new WXHostModal();
|
||||
wxModal.HostID = modal.HostID;
|
||||
wxModal.Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName);
|
||||
wxModal.ModalAddress = modal.Modal.ModalAddress;
|
||||
result.Add(wxModal);
|
||||
}
|
||||
break;
|
||||
case "yinyue":
|
||||
hostModals = HostModalManager.Load(host.ID, DeviceType.Music).Where(r => r.Modal.WXActiveIndicator).ToList();
|
||||
foreach (HostModal modal in hostModals)
|
||||
{
|
||||
WXHostModal wxModal = new WXHostModal();
|
||||
wxModal.HostID = modal.HostID;
|
||||
wxModal.Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName);
|
||||
wxModal.ModalAddress = modal.Modal.ModalAddress;
|
||||
wxModal.Status = modal.Status;
|
||||
wxModal.Brightness = modal.Brightness;
|
||||
wxModal.Mode = modal.Mode;
|
||||
result.Add(wxModal);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return Json(new { IsSuccess = true, Result = result, IsControl = isControl }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex);
|
||||
return Json(new { IsSuccess = false, Result = HttpContext.InnerLanguage("OperationFailed") + ":" + ex.Message }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 设备控制(服务、调光)
|
||||
/// </summary>
|
||||
/// <param name="hostID"></param>
|
||||
/// <param name="modalAddress"></param>
|
||||
/// <param name="status"></param>
|
||||
/// <param name="brightness"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult SetDevice(int hostID, string modalAddress, int status, int brightness, int temperature, int fanSpeed, int mode, int valve)
|
||||
{
|
||||
try
|
||||
{
|
||||
Host host = HostManager.Get(hostID);
|
||||
var hostModal = HostModalManager.GetByModalAddress(hostID, modalAddress);
|
||||
if (hostModal == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Result = HttpContext.InnerLanguage("InvalidControl") }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
HostModalManager.SetDevice(host, hostModal, status, brightness, temperature, fanSpeed, mode, valve);
|
||||
string detail = string.Format("{0}客房{1}{2}({3})回路", (status == 1 ? "打开" : "关闭"), host.RoomNumber, hostModal.Modal.Name, modalAddress);
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("DeviceControl"), detail, true, "微信", host.SysHotel.ID);
|
||||
return Json(new { IsSuccess = true, Result = HttpContext.InnerLanguage("OperationSuccess") }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex);
|
||||
return Json(new { IsSuccess = false, Result = HttpContext.InnerLanguage("OperationFailed") + ":" + ex.Message }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置调色
|
||||
/// </summary>
|
||||
/// <param name="hostID"></param>
|
||||
/// <param name="modalAddress"></param>
|
||||
/// <param name="modalAddress1"></param>
|
||||
/// <param name="brightness1"></param>
|
||||
/// <param name="modalAddress2"></param>
|
||||
/// <param name="brightness2"></param>
|
||||
/// <param name="modalAddress3"></param>
|
||||
/// <param name="brightness3"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult SetTiaoseDevice(int hostID, string modalAddress, string modalAddress1, int brightness1, string modalAddress2, int brightness2, string modalAddress3, int brightness3)
|
||||
{
|
||||
try
|
||||
{
|
||||
Host host = HostManager.Get(hostID);
|
||||
//000回路
|
||||
var hostModal = HostModalManager.GetByModalAddress(hostID, modalAddress);
|
||||
if (hostModal == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Result = HttpContext.InnerLanguage("InvalidControl") }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
int status = 1, brightness = 100;
|
||||
if (brightness1 == 0 && brightness2 == 0 && brightness3 == 0)
|
||||
{
|
||||
status = 2;
|
||||
brightness = 0;
|
||||
}
|
||||
HostModalManager.SetDevice(host, hostModal, status, brightness, 0, 0, 0, 0);
|
||||
//001回路R颜色
|
||||
hostModal = HostModalManager.GetByModalAddress(hostID, modalAddress1);
|
||||
if (hostModal == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Result = HttpContext.InnerLanguage("InvalidControl") }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
HostModalManager.SetDevice(host, hostModal, brightness1 == 0 ? 2 : 1, brightness1, 0, 0, 0, 0);
|
||||
//002回路G颜色
|
||||
hostModal = HostModalManager.GetByModalAddress(hostID, modalAddress2);
|
||||
if (hostModal == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Result = HttpContext.InnerLanguage("InvalidControl") }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
HostModalManager.SetDevice(host, hostModal, brightness2 == 0 ? 2 : 1, brightness2, 0, 0, 0, 0);
|
||||
//003回路B颜色
|
||||
hostModal = HostModalManager.GetByModalAddress(hostID, modalAddress3);
|
||||
if (hostModal == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Result = HttpContext.InnerLanguage("InvalidControl") }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
HostModalManager.SetDevice(host, hostModal, brightness3 == 0 ? 2 : 1, brightness3, 0, 0, 0, 0);
|
||||
|
||||
string detail = string.Format("{0}客房{1}{2}({3}),调色{4}", (status == 1 ? "打开" : "关闭"), host.RoomNumber, hostModal.Modal.Name, modalAddress, brightness);
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("DeviceControl"), detail, true, "微信", host.SysHotel.ID);
|
||||
|
||||
return Json(new { IsSuccess = true, Result = HttpContext.InnerLanguage("OperationSuccess") }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex);
|
||||
return Json(new { IsSuccess = false, Result = HttpContext.InnerLanguage("OperationFailed") + ":" + ex.Message }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 场景控制
|
||||
/// </summary>
|
||||
/// <param name="hostID"></param>
|
||||
/// <param name="sceneID"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult SetScene(int hostID, int sceneID, bool takeInverse)
|
||||
{
|
||||
try
|
||||
{
|
||||
Host host = HostManager.Get(hostID);
|
||||
var scene = RoomTypeSceneManager.Get(sceneID);
|
||||
if (scene == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Result = HttpContext.InnerLanguage("InvalidScene") }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
LightControlManager.ApplyScene(host, scene, takeInverse);
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("SceneControl"), string.Format("打开客房{0}{1}场景", host.RoomNumber, scene.Name), true, "微信", host.SysHotel.ID);
|
||||
return Json(new { IsSuccess = true, Result = HttpContext.InnerLanguage("OperationSuccess") }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex);
|
||||
return Json(new { IsSuccess = false, Result = HttpContext.InnerLanguage("OperationFailed") + ":" + ex.Message }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult Error(string msg)
|
||||
{
|
||||
ViewData["Error"] = msg;
|
||||
return View();
|
||||
}
|
||||
}
|
||||
|
||||
public class WXMenu
|
||||
{
|
||||
public string Code { get; set; }
|
||||
public string Name { get; set; }
|
||||
public bool TakePower { get; set; }
|
||||
}
|
||||
|
||||
public class WXEntity
|
||||
{
|
||||
public int HostID { get; set; }
|
||||
public string RoomNumber { get; set; }
|
||||
public string WXLockModalAddress { get; set; }
|
||||
public int WXLockStatus { get; set; }
|
||||
}
|
||||
|
||||
public class WXHostModal
|
||||
{
|
||||
public int HostID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string ModalAddress { get; set; }
|
||||
public string ModalAddress1 { get; set; }
|
||||
public string ModalAddress2 { get; set; }
|
||||
public string ModalAddress3 { get; set; }
|
||||
public string ModalAddress4 { get; set; }
|
||||
public int Status { get; set; }//状态
|
||||
public int Brightness { get; set; }
|
||||
public int Brightness1 { get; set; }//亮度R
|
||||
public int Brightness2 { get; set; }//亮度G
|
||||
public int Brightness3 { get; set; }//亮度B
|
||||
public int Brightness4 { get; set; }//亮度白光
|
||||
public int CurrentTemp { get; set; }//当前温度
|
||||
public int SettingTemp { get; set; }//设置温度
|
||||
public int FanSpeed { get; set; }//风速
|
||||
public int Mode { get; set; }//模式
|
||||
public int Valve { get; set; }//阀门状态
|
||||
}
|
||||
|
||||
public class WXRoomTypeScene
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public int HostID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Status { get; set; }
|
||||
public bool TakeInverse { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user