初始化CRICS
This commit is contained in:
21
WebSite/Controllers/AirAPIController.cs
Normal file
21
WebSite/Controllers/AirAPIController.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class AirAPIController : Controller
|
||||
{
|
||||
//
|
||||
// GET: /AirAPI/
|
||||
|
||||
[HttpPost()]
|
||||
public string Index()
|
||||
{
|
||||
return "hello";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
706
WebSite/Controllers/AirConditionControlController.cs
Normal file
706
WebSite/Controllers/AirConditionControlController.cs
Normal file
@@ -0,0 +1,706 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Common;
|
||||
using Domain;
|
||||
using Service;
|
||||
using CommonEntity;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class AirConditionControlController : BaseController
|
||||
{
|
||||
private const int AUTHORITY_AirConditionControl = 12;
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(AirConditionControlController));
|
||||
|
||||
#region Services
|
||||
|
||||
public IRoomTypeManager RoomTypeManager { get; set; }
|
||||
public IHostManager HostManager { get; set; }
|
||||
public IGroupManager GroupManager { get; set; }
|
||||
public IRoomStatusManager RoomStatusManager { get; set; }
|
||||
public IHostAirManager HostAirManager { get; set; }
|
||||
public ISysUserManager SysUserManager { get; set; }
|
||||
public IRoomTypeAirManager RoomTypeAirManager { get; set; }
|
||||
public IHotelSeasonManager HotelSeasonManager { get; set; }
|
||||
public IHotelAirControlManager HotelAirControlManager { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 阿宝添加的
|
||||
/// </summary>
|
||||
public IRoomNoBodyMananger RoomNoBodyMananger { get; set; }
|
||||
public ISysHotelManager SysHotelManager { get; set; }
|
||||
public IECO_SettingMananger ECO_SettingManager { get; set; }
|
||||
public ILieECOMananger LieECOManager { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 风速设置权限ID
|
||||
/// </summary>
|
||||
private const int AUTHORITY_SPEEDSETTING = 1002;
|
||||
|
||||
#region Actions
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Index()
|
||||
{
|
||||
ViewData["EnableSpeed"] = SysUserManager.HasAuthority(User.Identity.Name, AUTHORITY_SPEEDSETTING);
|
||||
return View("SimonIndex");
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取季节设置信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadSeason()
|
||||
{
|
||||
HotelSeason hotelSeason = HotelSeasonManager.LoadByHotelID(CurrentHotelID);
|
||||
List<HotelAirControl> hotelAirControls = HotelAirControlManager.LoadByHotelID(CurrentHotelID);//控制设置信息
|
||||
SysHotel hotelData = SysHotelManager.Get(CurrentHotelID);//获取上下午时间
|
||||
RoomNobodyHowTo nn = RoomNoBodyMananger.LoadAll().FirstOrDefault(A => A.CurrentHotelID == CurrentHotelID);
|
||||
|
||||
ECO_Setting ECO = ECO_SettingManager.LoadAll().FirstOrDefault(A => A.HotelID == CurrentHotelID);
|
||||
var LLL = LieECOManager.LoadAll().Where(A => A.HotelID == CurrentHotelID).OrderBy(A => A.ID).ToList();
|
||||
|
||||
string GGG = CacheKey.KT_Timer_Controller + "_" + CurrentHotelCode;
|
||||
var LLL1= CSRedisCacheHelper.Get_Partition<List<LingChenECO>>(GGG, 5);
|
||||
|
||||
string LieKey = CacheKey.LieECOKey + "_" + CurrentHotelID;
|
||||
if (LLL != null && LLL.Count > 0)
|
||||
{
|
||||
var LLLData = LieECOManager.LoadAll().Where(A => A.HotelID == CurrentHotelID && A.IsEnable).ToList();
|
||||
CSRedisCacheHelper.Set_Partition<List<LieECO>>(LieKey,LLLData,1);
|
||||
}
|
||||
if (nn != null)
|
||||
{
|
||||
return Json(new
|
||||
{
|
||||
IsSuccess = true,
|
||||
Data = hotelSeason,
|
||||
AirControlData = hotelAirControls,
|
||||
HotelData = new { StartDayTime = hotelData.StartDayTime, EndDayTime = hotelData.EndDayTime },
|
||||
RoomNoBodyHowTo = nn,
|
||||
ECO_Setting = ECO,
|
||||
LieECOList = LLL,
|
||||
TimerECO=LLL1
|
||||
}, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new
|
||||
{
|
||||
IsSuccess = true,
|
||||
Data = hotelSeason,
|
||||
AirControlData = hotelAirControls,
|
||||
HotelData = new { StartDayTime = hotelData.StartDayTime, EndDayTime = hotelData.EndDayTime },
|
||||
ECO_Setting = ECO,
|
||||
LieECOList = LLL,
|
||||
TimerECO=LLL1
|
||||
}, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 季节下发
|
||||
/// </summary>
|
||||
/// <param name="hostID"></param>
|
||||
/// <param name="groupID"></param>
|
||||
/// <param name="roomStatusID"></param>
|
||||
/// <param name="roomTypeID"></param>
|
||||
/// <param name="airNo"></param>
|
||||
/// <param name="property"></param>
|
||||
/// <param name="status"></param>
|
||||
/// <param name="month1"></param>
|
||||
/// <param name="month2"></param>
|
||||
/// <param name="month3"></param>
|
||||
/// <param name="month4"></param>
|
||||
/// <param name="month5"></param>
|
||||
/// <param name="month6"></param>
|
||||
/// <param name="month7"></param>
|
||||
/// <param name="month8"></param>
|
||||
/// <param name="month9"></param>
|
||||
/// <param name="month10"></param>
|
||||
/// <param name="month11"></param>
|
||||
/// <param name="month12"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult SetAirProperty(int? hostID, int? groupID, int? roomStatusID, int? roomTypeID, int airNo, AirProperty property, int status,
|
||||
int? month1, int? month2, int? month3, int? month4, int? month5, int? month6, int? month7, int? month8, int? month9, int? month10, int? month11, int? month12)
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<string> roomNumberList = new List<string>();
|
||||
IList<Host> hosts = FindHosts(hostID, groupID, roomStatusID, roomTypeID);
|
||||
IList<string> offlineRoomNumberList = new List<string>();
|
||||
foreach (var host in hosts)
|
||||
{
|
||||
if (host != null)
|
||||
{
|
||||
if (host.Status)
|
||||
{
|
||||
byte[] seasonData = new byte[12];
|
||||
if (property == AirProperty.Season)
|
||||
{
|
||||
seasonData[0] = (byte)month1;
|
||||
seasonData[1] = (byte)month2;
|
||||
seasonData[2] = (byte)month3;
|
||||
seasonData[3] = (byte)month4;
|
||||
seasonData[4] = (byte)month5;
|
||||
seasonData[5] = (byte)month6;
|
||||
seasonData[6] = (byte)month7;
|
||||
seasonData[7] = (byte)month8;
|
||||
seasonData[8] = (byte)month9;
|
||||
seasonData[9] = (byte)month10;
|
||||
seasonData[10] = (byte)month11;
|
||||
seasonData[11] = (byte)month12;
|
||||
}
|
||||
HostAirManager.SetAirProperty(host, airNo, property, status, seasonData);
|
||||
roomNumberList.Add(host.RoomNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
offlineRoomNumberList.Add(host.RoomNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
string logDetail = "【" + String.Join(",", roomNumberList.ToArray()) + "】【" + HttpContext.InnerLanguage("AirProperty" + property.ToString()) + "】";
|
||||
SaveSystemLog(AUTHORITY_AirConditionControl, HttpContext.InnerLanguage("SetRoomAirProperty"), logDetail);
|
||||
if (offlineRoomNumberList.Count > 0)
|
||||
{
|
||||
string message = String.Format(HttpContext.InnerLanguage("SendFailedHostOffline"), String.Join(",", offlineRoomNumberList.ToArray()));
|
||||
return Json(new { IsSuccess = true, Message = message });
|
||||
}
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("IssuedSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (logger.IsErrorEnabled)
|
||||
{
|
||||
logger.Error(HttpContext.InnerLanguage("SingleAirconditioningSettingsIssuedFail"), ex);
|
||||
}
|
||||
SaveSystemLog(AUTHORITY_AirConditionControl, HttpContext.InnerLanguage("SetRoomAirProperty"), ex.Message, false);
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("IssuedFailedFecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存空调设置
|
||||
/// </summary>
|
||||
/// <param name="conditionType"></param>
|
||||
/// <param name="delayTime"></param>
|
||||
/// <param name="id1"></param>
|
||||
/// <param name="season1"></param>
|
||||
/// <param name="activeIndicator1"></param>
|
||||
/// <param name="status1"></param>
|
||||
/// <param name="settingTemp1"></param>
|
||||
/// <param name="mode1"></param>
|
||||
/// <param name="fanSpeed1"></param>
|
||||
/// <param name="id2"></param>
|
||||
/// <param name="season2"></param>
|
||||
/// <param name="activeIndicator2"></param>
|
||||
/// <param name="status2"></param>
|
||||
/// <param name="settingTemp2"></param>
|
||||
/// <param name="mode2"></param>
|
||||
/// <param name="fanSpeed2"></param>
|
||||
/// <param name="id3"></param>
|
||||
/// <param name="season3"></param>
|
||||
/// <param name="activeIndicator3"></param>
|
||||
/// <param name="status3"></param>
|
||||
/// <param name="settingTemp3"></param>
|
||||
/// <param name="mode3"></param>
|
||||
/// <param name="fanSpeed3"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult SaveAirControl(int yanchitime, string how, string temp, int id, int conditionType, int delayTime,
|
||||
int id1, int season1, bool activeIndicator1, int status1, int settingTemp1, int mode1, int fanSpeed1,
|
||||
int id2, int season2, bool activeIndicator2, int status2, int settingTemp2, int mode2, int fanSpeed2,
|
||||
int id3, int season3, bool activeIndicator3, int status3, int settingTemp3, int mode3, int fanSpeed3)
|
||||
{
|
||||
|
||||
//阿宝修改了
|
||||
try
|
||||
{
|
||||
SysHotel currentHotel = SysHotelManager.Get(CurrentHotelID);
|
||||
//春季
|
||||
HotelAirControl entity = new HotelAirControl() { ID = id1, SysHotel = currentHotel, ConditionType = conditionType, DelayTime = delayTime, Season = season1, ActiveIndicator = activeIndicator1, Status = status1, SettingTemp = settingTemp1, Mode = mode1, FanSpeed = fanSpeed1, ModifiedDate = DateTime.Now };
|
||||
HotelAirControlManager.SaveOrUpdate(entity);
|
||||
id1 = entity.ID;
|
||||
//夏季
|
||||
entity = new HotelAirControl() { ID = id2, SysHotel = currentHotel, ConditionType = conditionType, DelayTime = delayTime, Season = season2, ActiveIndicator = activeIndicator2, Status = status2, SettingTemp = settingTemp2, Mode = mode2, FanSpeed = fanSpeed2, ModifiedDate = DateTime.Now };
|
||||
HotelAirControlManager.SaveOrUpdate(entity);
|
||||
id2 = entity.ID;
|
||||
//冬季
|
||||
entity = new HotelAirControl() { ID = id3, SysHotel = currentHotel, ConditionType = conditionType, DelayTime = delayTime, Season = season3, ActiveIndicator = activeIndicator3, Status = status3, SettingTemp = settingTemp3, Mode = mode3, FanSpeed = fanSpeed3, ModifiedDate = DateTime.Now };
|
||||
HotelAirControlManager.SaveOrUpdate(entity);
|
||||
id3 = entity.ID;
|
||||
|
||||
string ti = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
RoomNobodyHowTo no = new RoomNobodyHowTo();
|
||||
no.ID = id;
|
||||
no.CurrentHotelID = CurrentHotelID;
|
||||
no.DelayTime = yanchitime;
|
||||
no.How = how;
|
||||
no.Temperature = int.Parse(temp);
|
||||
no.CreateTime = ti;
|
||||
int id4 = 0;
|
||||
if (id == 0)
|
||||
{
|
||||
id4 = RoomNoBodyMananger.Add(no);
|
||||
}
|
||||
else
|
||||
{
|
||||
RoomNoBodyMananger.Update(no);
|
||||
id4 = id;
|
||||
}
|
||||
//string logDetail = "【" + String.Join(",", roomNumberList.ToArray()) + "】【" + HttpContext.InnerLanguage("AirProperty" + property.ToString()) + "】";
|
||||
//SaveSystemLog(AUTHORITY_AirConditionControl, HttpContext.InnerLanguage("SetRoomAirProperty"), logDetail);
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess"), ID1 = id1, ID2 = id2, ID3 = id3, ID4 = id4 });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (logger.IsErrorEnabled)
|
||||
{
|
||||
logger.Error(HttpContext.InnerLanguage("SingleAirconditioningSettingsIssuedFail"), ex);
|
||||
}
|
||||
SaveSystemLog(AUTHORITY_AirConditionControl, HttpContext.InnerLanguage("SetRoomAirProperty"), ex.Message, false);
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SaveFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost()]
|
||||
public ActionResult SaveAirControlRoomNoBody(TempClass obj)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 空调设置整体下发
|
||||
/// </summary>
|
||||
/// <param name="hostID"></param>
|
||||
/// <param name="groupID"></param>
|
||||
/// <param name="roomStatusID"></param>
|
||||
/// <param name="roomTypeID"></param>
|
||||
/// <param name="jsonAirConditionSetting"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult Send(int? hostID, int? groupID, int? roomStatusID, int? roomTypeID, string jsonAirConditionSetting)
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<string> roomNumberList = new List<string>();
|
||||
IList<Host> hosts = FindHosts(hostID, groupID, roomStatusID, roomTypeID);
|
||||
IDictionary<string, string> data = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonAirConditionSetting);
|
||||
IList<string> offlineRoomNumberList = new List<string>();
|
||||
foreach (var host in hosts)
|
||||
{
|
||||
if (host == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!host.Status)
|
||||
{
|
||||
offlineRoomNumberList.Add(host.RoomNumber);
|
||||
continue;
|
||||
}
|
||||
var hostAir = HostAirManager.GetByModalTypeID(host.ID, Convert.ToInt32(data["ModalTypeID"]));
|
||||
if (hostAir == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("AirConditioner") + "【" + data["ModalTypeID"] + "】" + HttpContext.InnerLanguage("NotExist") + "。");
|
||||
}
|
||||
hostAir.SettingTemp = Convert.ToInt32(data["SettingTemp"]);
|
||||
hostAir.CompensatoryTemp = Convert.ToSingle(data["CompensatoryTemp"]);
|
||||
hostAir.Speed = Convert.ToInt32(data["Speed"]);
|
||||
hostAir.Mode = Convert.ToInt32(data["Mode"]);
|
||||
hostAir.IsLockTemp = Convert.ToBoolean(data["IsLockTemp"]);
|
||||
hostAir.LockTemp = Convert.ToInt32(data["LockTemp"]);
|
||||
|
||||
hostAir.KeepTemp = Convert.ToInt32(data["KeepTemp"]);
|
||||
hostAir.InitTemp = Convert.ToInt32(data["InitTemp"]);
|
||||
hostAir.HightTemp = Convert.ToInt32(data["HightTemp"]);
|
||||
hostAir.LowerTemp = Convert.ToInt32(data["LowerTemp"]);
|
||||
hostAir.ColdHotSwitchDelayTime = Convert.ToInt32(data["ColdHotSwitchDelayTime"]);
|
||||
hostAir.ColdHotMode = Convert.ToInt32(data["ColdHotMode"]);
|
||||
hostAir.DeadTemp = Convert.ToInt32(data["DeadTemp"]);
|
||||
hostAir.HotDevition = Convert.ToInt32(data["HotDevition"]);
|
||||
hostAir.ColdDevition = Convert.ToInt32(data["ColdDevition"]);
|
||||
hostAir.WelcomeTime = Convert.ToInt32(data["WelcomeTime"]);
|
||||
hostAir.RelateRoomStatus = Convert.ToBoolean(data["RelateRoomStatus"]);
|
||||
hostAir.RelateDoorContact = Convert.ToBoolean(data["RelateDoorContact"]);
|
||||
hostAir.FanStop = Convert.ToBoolean(data["FanStop"]);
|
||||
hostAir.DisableFanHighSpeed = Convert.ToBoolean(data["DisableFanHighSpeed"]);
|
||||
|
||||
hostAir.SleepFlag = Convert.ToBoolean(data["SleepFlag"]);
|
||||
hostAir.SleepStartTime = data["SleepStartTime"];
|
||||
hostAir.SleepEndTime = data["SleepEndTime"];
|
||||
hostAir.SleepDevition = Convert.ToInt32(data["SleepDevition"]);
|
||||
|
||||
hostAir.TimeFlag = Convert.ToBoolean(data["TimeFlag"]);
|
||||
hostAir.TimeStartTime1 = data["TimeStartTime1"];
|
||||
hostAir.TimeEndTime1 = data["TimeEndTime1"];
|
||||
hostAir.TimeStartTime2 = data["TimeStartTime2"];
|
||||
hostAir.TimeEndTime2 = data["TimeEndTime2"];
|
||||
hostAir.TimeStartTime3 = data["TimeStartTime3"];
|
||||
hostAir.TimeEndTime3 = data["TimeEndTime3"];
|
||||
|
||||
HostAirManager.ApplyAirConditionSetting(hostAir, host);
|
||||
|
||||
roomNumberList.Add(host.RoomNumber);
|
||||
}
|
||||
SaveSystemLog(AUTHORITY_AirConditionControl, HttpContext.InnerLanguage("SetRoomAirAllProperties"), "【" + String.Join(",", roomNumberList.ToArray()) + "】");
|
||||
if (offlineRoomNumberList.Count > 0)
|
||||
{
|
||||
string message = String.Format(HttpContext.InnerLanguage("SendFailedHostOffline"), String.Join(",", offlineRoomNumberList.ToArray()));
|
||||
return Json(new { IsSuccess = true, Message = message });
|
||||
}
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("IssuedSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (logger.IsErrorEnabled)
|
||||
{
|
||||
logger.Error(HttpContext.InnerLanguage("AirConditioningSettingOverallIssuedFailed"), ex);
|
||||
}
|
||||
SaveSystemLog(AUTHORITY_AirConditionControl, HttpContext.InnerLanguage("SetRoomAirAllProperties"), ex.Message, false);
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("IssuedFailedFecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置空调锁定温度
|
||||
/// </summary>
|
||||
/// <param name="hostID"></param>
|
||||
/// <param name="groupID"></param>
|
||||
/// <param name="roomStatusID"></param>
|
||||
/// <param name="roomTypeID"></param>
|
||||
/// <param name="airNo"></param>
|
||||
/// <param name="isLock"></param>
|
||||
/// <param name="lockTemp"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult SetAirLockTemp(int? hostID, int? groupID, int? roomStatusID, int? roomTypeID, int airNo, bool isLock, int lockTemp)
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<string> roomNumberList = new List<string>();
|
||||
|
||||
IList<Host> hosts = FindHosts(hostID, groupID, roomStatusID, roomTypeID);
|
||||
|
||||
IList<string> offlineRoomNumberList = new List<string>();
|
||||
|
||||
foreach (var host in hosts)
|
||||
{
|
||||
if (host != null)
|
||||
{
|
||||
if (host.Status)
|
||||
{
|
||||
HostAirManager.SetLockTemp(host, airNo, isLock, lockTemp);
|
||||
|
||||
roomNumberList.Add(host.RoomNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
offlineRoomNumberList.Add(host.RoomNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string logDetail = "【" + String.Join(",", roomNumberList.ToArray()) + "】【" + HttpContext.InnerLanguage("AirPropertyLockTemp") + "】";
|
||||
|
||||
SaveSystemLog(AUTHORITY_AirConditionControl, HttpContext.InnerLanguage("SetRoomAirProperty"), logDetail);
|
||||
|
||||
if (offlineRoomNumberList.Count > 0)
|
||||
{
|
||||
string message = String.Format(HttpContext.InnerLanguage("SendFailedHostOffline"), String.Join(",", offlineRoomNumberList.ToArray()));
|
||||
|
||||
return Json(new { IsSuccess = true, Message = message });
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("IssuedSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (logger.IsErrorEnabled)
|
||||
{
|
||||
logger.Error(HttpContext.InnerLanguage("SettingTemperatureAirConditionerLockFailure"), ex);
|
||||
}
|
||||
|
||||
SaveSystemLog(AUTHORITY_AirConditionControl, HttpContext.InnerLanguage("SetRoomAirProperty"), ex.Message, false);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("IssuedFailedFecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置空调睡眠模式
|
||||
/// </summary>
|
||||
/// <param name="hostID"></param>
|
||||
/// <param name="groupID"></param>
|
||||
/// <param name="roomStatusID"></param>
|
||||
/// <param name="roomTypeID"></param>
|
||||
/// <param name="airNo"></param>
|
||||
/// <param name="sleepFlag"></param>
|
||||
/// <param name="SleepDevition"></param>
|
||||
/// <param name="sleepStartTime"></param>
|
||||
/// <param name="sleepEndTime"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult SetAirSleepMode(int? hostID, int? groupID, int? roomStatusID, int? roomTypeID, int airNo, bool sleepFlag, int sleepDevition, string sleepStartTime, string sleepEndTime)
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<string> roomNumberList = new List<string>();
|
||||
|
||||
IList<Host> hosts = FindHosts(hostID, groupID, roomStatusID, roomTypeID);
|
||||
|
||||
IList<string> offlineRoomNumberList = new List<string>();
|
||||
|
||||
foreach (var host in hosts)
|
||||
{
|
||||
if (host != null)
|
||||
{
|
||||
if (host.Status)
|
||||
{
|
||||
HostAirManager.SetSleepMode(host, airNo, sleepFlag, sleepDevition, sleepStartTime, sleepEndTime);
|
||||
|
||||
roomNumberList.Add(host.RoomNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
offlineRoomNumberList.Add(host.RoomNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string logDetail = "【" + String.Join(",", roomNumberList.ToArray()) + "】【" + HttpContext.InnerLanguage("AirPropertySleepMode") + "】";
|
||||
|
||||
SaveSystemLog(AUTHORITY_AirConditionControl, HttpContext.InnerLanguage("SetRoomAirProperty"), logDetail);
|
||||
|
||||
if (offlineRoomNumberList.Count > 0)
|
||||
{
|
||||
string message = String.Format(HttpContext.InnerLanguage("SendFailedHostOffline"), String.Join(",", offlineRoomNumberList.ToArray()));
|
||||
|
||||
return Json(new { IsSuccess = true, Message = message });
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("IssuedSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (logger.IsErrorEnabled)
|
||||
{
|
||||
logger.Error(HttpContext.InnerLanguage("SettingAirConditionerSleepModeFailure"), ex);
|
||||
}
|
||||
|
||||
SaveSystemLog(AUTHORITY_AirConditionControl, HttpContext.InnerLanguage("SetRoomAirProperty"), ex.Message, false);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("IssuedFailedFecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置空调定时设置
|
||||
/// </summary>
|
||||
/// <param name="hostID"></param>
|
||||
/// <param name="groupID"></param>
|
||||
/// <param name="roomStatusID"></param>
|
||||
/// <param name="roomTypeID"></param>
|
||||
/// <param name="airNo"></param>
|
||||
/// <param name="sleepFlag"></param>
|
||||
/// <param name="SleepDevition"></param>
|
||||
/// <param name="sleepStartTime"></param>
|
||||
/// <param name="sleepEndTime"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult SetAirTimeSetting(int? hostID, int? groupID, int? roomStatusID, int? roomTypeID,
|
||||
int airNo, bool timeFlag, string startTime1, string endTime1,
|
||||
string startTime2, string endTime2, string startTime3, string endTime3)
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<string> roomNumberList = new List<string>();
|
||||
|
||||
IList<Host> hosts = FindHosts(hostID, groupID, roomStatusID, roomTypeID);
|
||||
|
||||
IList<string> offlineRoomNumberList = new List<string>();
|
||||
|
||||
foreach (var host in hosts)
|
||||
{
|
||||
if (host != null)
|
||||
{
|
||||
if (host.Status)
|
||||
{
|
||||
HostAirManager.SetTimeSetting(host, airNo, timeFlag, startTime1, endTime1, startTime2, endTime2, startTime3, endTime3);
|
||||
|
||||
roomNumberList.Add(host.RoomNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
offlineRoomNumberList.Add(host.RoomNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string logDetail = "【" + String.Join(",", roomNumberList.ToArray()) + "】【" + HttpContext.InnerLanguage("AirPropertyTime") + "】";
|
||||
|
||||
SaveSystemLog(AUTHORITY_AirConditionControl, HttpContext.InnerLanguage("SetRoomAirProperty"), logDetail);
|
||||
|
||||
if (offlineRoomNumberList.Count > 0)
|
||||
{
|
||||
string message = String.Format(HttpContext.InnerLanguage("SendFailedHostOffline"), String.Join(",", offlineRoomNumberList.ToArray()));
|
||||
|
||||
return Json(new { IsSuccess = true, Message = message });
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("IssuedSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (logger.IsErrorEnabled)
|
||||
{
|
||||
logger.Error(HttpContext.InnerLanguage("SettingTemperatureAirConditionerLockFailure"), ex);
|
||||
}
|
||||
|
||||
SaveSystemLog(AUTHORITY_AirConditionControl, HttpContext.InnerLanguage("SetRoomAirProperty"), ex.Message, false);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("IssuedFailedFecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置空调补偿温度
|
||||
/// </summary>
|
||||
/// <param name="hostID"></param>
|
||||
/// <param name="groupID"></param>
|
||||
/// <param name="roomStatusID"></param>
|
||||
/// <param name="roomTypeID"></param>
|
||||
/// <param name="airNo"></param>
|
||||
/// <param name="status"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult SetAirCompensatoryTemp(int? hostID, int? groupID, int? roomStatusID, int? roomTypeID, int airNo, float status)
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<string> roomNumberList = new List<string>();
|
||||
|
||||
IList<Host> hosts = FindHosts(hostID, groupID, roomStatusID, roomTypeID);
|
||||
|
||||
IList<string> offlineRoomNumberList = new List<string>();
|
||||
|
||||
foreach (var host in hosts)
|
||||
{
|
||||
if (host != null)
|
||||
{
|
||||
if (host.Status)
|
||||
{
|
||||
HostAirManager.SetCompensatoryTemp(host, airNo, status);
|
||||
|
||||
roomNumberList.Add(host.RoomNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
offlineRoomNumberList.Add(host.RoomNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string logDetail = "【" + String.Join(",", roomNumberList.ToArray()) + "】【" + HttpContext.InnerLanguage("AirPropertyCompensatoryTemp") + ":" + status + "】";
|
||||
|
||||
SaveSystemLog(AUTHORITY_AirConditionControl, HttpContext.InnerLanguage("SetRoomAirProperty"), logDetail);
|
||||
|
||||
if (offlineRoomNumberList.Count > 0)
|
||||
{
|
||||
string message = String.Format(HttpContext.InnerLanguage("SendFailedHostOffline"), String.Join(",", offlineRoomNumberList.ToArray()));
|
||||
|
||||
return Json(new { IsSuccess = true, Message = message });
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("IssuedSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (logger.IsErrorEnabled)
|
||||
{
|
||||
logger.Error(HttpContext.InnerLanguage("SettingAirConditionerCompensationTemperatureFailure"), ex);
|
||||
}
|
||||
|
||||
SaveSystemLog(AUTHORITY_AirConditionControl, HttpContext.InnerLanguage("SetRoomAirProperty"), ex.Message, false);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("IssuedFailedFecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
#region 加载控件数据
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAirConditionsForCombobox(int roomTypeID)
|
||||
{
|
||||
var roomType = RoomTypeManager.Get(roomTypeID);
|
||||
List<object> result = new List<object>();
|
||||
if (roomType != null)
|
||||
{
|
||||
var airs = RoomTypeAirManager.LoadAll(roomType);
|
||||
result = airs.Select(r => new
|
||||
{
|
||||
r.ID,
|
||||
CustomerName = ((Boolean)Session["isCN"]) ? r.CustomerName : r.EnglishName,
|
||||
ModalTypeID = r.ModalType.ID,
|
||||
roomType.ControlType,
|
||||
//ControlTypeName = EnumDescription.GetDescription(roomType.ControlType)
|
||||
ControlTypeName = roomType.ControlType == ControlType.Two ? HttpContext.InnerLanguage("TwoControl") : HttpContext.InnerLanguage("FourControl")
|
||||
}).ToList<object>();
|
||||
}
|
||||
|
||||
return Json(result);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
/// <summary>
|
||||
/// 获取主机
|
||||
/// </summary>
|
||||
/// <param name="hostID"></param>
|
||||
/// <param name="groupID"></param>
|
||||
/// <param name="roomStatusID"></param>
|
||||
/// <param name="roomTypeID"></param>
|
||||
/// <returns></returns>
|
||||
private IList<Host> FindHosts(int? hostID, int? groupID, int? roomStatusID, int? roomTypeID)
|
||||
{
|
||||
IList<Host> hosts = new List<Host>();
|
||||
if (hostID.HasValue)
|
||||
{
|
||||
var host = HostManager.Get(hostID.GetValueOrDefault());
|
||||
if (host != null)
|
||||
{
|
||||
hosts.Add(host);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IList<Group> groups = new List<Group>();
|
||||
if (groupID.HasValue)
|
||||
{
|
||||
groups = GroupManager.GetGroupList(GroupManager.Get(groupID));
|
||||
}
|
||||
RoomStatus roomStatus = null;
|
||||
if (roomStatusID.HasValue)
|
||||
{
|
||||
roomStatus = RoomStatusManager.Get(roomStatusID);
|
||||
}
|
||||
RoomType roomType = null;
|
||||
if (roomTypeID.HasValue)
|
||||
{
|
||||
roomType = RoomTypeManager.Get(roomTypeID);
|
||||
}
|
||||
hosts = HostManager.LoadAll(groups, roomStatus, roomType);
|
||||
}
|
||||
return hosts;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class TempClass
|
||||
{
|
||||
public string How { get; set; }
|
||||
public int Temperature { get; set; }
|
||||
}
|
||||
}
|
||||
135
WebSite/Controllers/AirConditionStatusController.cs
Normal file
135
WebSite/Controllers/AirConditionStatusController.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Service;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class AirConditionStatusController : BaseController
|
||||
{
|
||||
public IHostModalRecordManager HostModalRecordManager { get; set; }
|
||||
|
||||
public IHostAirRecordManager HostAirRecordManager { get; set; }
|
||||
|
||||
#region Actions
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult LoadAirNos()
|
||||
{
|
||||
var result = new List<object>();
|
||||
|
||||
//result.Add(new { Value = DeviceType.AirConditioner1, Name = HttpContext.InnerLanguage(DeviceType.AirConditioner1.ToString()) });
|
||||
//result.Add(new { Value = DeviceType.AirConditioner2, Name = HttpContext.InnerLanguage(DeviceType.AirConditioner2.ToString()) });
|
||||
//result.Add(new { Value = DeviceType.AirConditioner3, Name = HttpContext.InnerLanguage(DeviceType.AirConditioner3.ToString()) });
|
||||
//result.Add(new { Value = DeviceType.AirConditioner4, Name = HttpContext.InnerLanguage(DeviceType.AirConditioner4.ToString()) });
|
||||
|
||||
return Json(result);
|
||||
}
|
||||
|
||||
public ActionResult LoadDeviceSubtypes()
|
||||
{
|
||||
var result = new List<object>();
|
||||
|
||||
var enumType = typeof(DeviceSubtype);
|
||||
|
||||
var values = Enum.GetValues(enumType);
|
||||
|
||||
foreach (var value in values)
|
||||
{
|
||||
string name = Enum.GetName(enumType, value);
|
||||
result.Add(new { Value = value, Name = HttpContext.InnerLanguage(name) });
|
||||
}
|
||||
|
||||
return Json(new { total = result.Count, rows = result });
|
||||
}
|
||||
|
||||
|
||||
public ActionResult LoadACDeviceSubtypes()
|
||||
{
|
||||
var result = new List<object>();
|
||||
|
||||
result.Add(new { Value = DeviceSubtype.SpeedHigh, Name = HttpContext.InnerLanguage(DeviceSubtype.SpeedHigh.ToString()) });
|
||||
result.Add(new { Value = DeviceSubtype.SpeedMiddle, Name = HttpContext.InnerLanguage(DeviceSubtype.SpeedMiddle.ToString()) });
|
||||
result.Add(new { Value = DeviceSubtype.SpeedLow, Name = HttpContext.InnerLanguage(DeviceSubtype.SpeedLow.ToString()) });
|
||||
result.Add(new { Value = DeviceSubtype.HotValve, Name = HttpContext.InnerLanguage(DeviceSubtype.HotValve.ToString()) });
|
||||
result.Add(new { Value = DeviceSubtype.ColdValve, Name = HttpContext.InnerLanguage(DeviceSubtype.ColdValve.ToString()) });
|
||||
|
||||
return Json(new { total = result.Count, rows = result });
|
||||
}
|
||||
|
||||
|
||||
public ActionResult LoadTempTypes()
|
||||
{
|
||||
var result = new List<object>();
|
||||
|
||||
var enumType = typeof(TempType);
|
||||
|
||||
var values = Enum.GetValues(enumType);
|
||||
|
||||
foreach (var value in values)
|
||||
{
|
||||
string name = Enum.GetName(enumType, value);
|
||||
result.Add(new { Value = value, Name = HttpContext.InnerLanguage(name) });
|
||||
}
|
||||
|
||||
return Json(new { total = result.Count, rows = result });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询空调记录
|
||||
/// </summary>
|
||||
/// <param name="roomNumber">房号</param>
|
||||
/// <param name="airNo">空调序号</param>
|
||||
/// <param name="startTime">开始时间</param>
|
||||
/// <param name="endTime">截止时间</param>
|
||||
/// <param name="airRecordtype">空调记录查询类型:AirCircuit/空调回路,RoomTemp/客房温度</param>
|
||||
/// <param name="deviceSubtypes">空调回路类型</param>
|
||||
/// <param name="tempTypes">温度类型</param>
|
||||
/// <returns></returns>
|
||||
public ActionResult LoadHostAirRecords(int page, int rows, string order, string sort, string roomNumber, int airNo, string startTime, string endTime, string airRecordtype, string deviceSubtypes, string tempTypes)
|
||||
{
|
||||
try
|
||||
{
|
||||
long total = 0;
|
||||
|
||||
if (airRecordtype == "AirCircuit")
|
||||
{
|
||||
var table = HostModalRecordManager.LoadHostModalRecords(out total, page, rows, order, sort, roomNumber, airNo.ToString(), deviceSubtypes, startTime, endTime, CurrentHotelID);
|
||||
|
||||
table.Columns.Add("SubtypeName", typeof(string));
|
||||
foreach (DataRow dr in table.Rows)
|
||||
{
|
||||
var subtypeName = Enum.GetName(typeof(DeviceSubtype), dr["Subtype"]);
|
||||
dr["SubtypeName"] = HttpContext.InnerLanguage(subtypeName);
|
||||
}
|
||||
|
||||
return Content(JsonConvert.SerializeObject(new { total = total, rows = table }, new DataTableConverter()));
|
||||
}
|
||||
else if (airRecordtype == "RoomTemp")
|
||||
{
|
||||
var table = HostAirRecordManager.LoadHostAirRecords(out total, page, rows, order, sort, roomNumber, airNo, startTime, endTime, tempTypes, CurrentHotelID);
|
||||
|
||||
return Content(JsonConvert.SerializeObject(new { total = total, rows = table }, new DataTableConverter()));
|
||||
}
|
||||
|
||||
return Json(new { total = 0, rows = new object[0] });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("LoadDataFailedReason") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
154
WebSite/Controllers/AlarmSettingController.cs
Normal file
154
WebSite/Controllers/AlarmSettingController.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Service;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class AlarmSettingController : BaseController
|
||||
{
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(AlarmSettingController));
|
||||
|
||||
private const int AUTHORITY_AlarmSetting = 21;
|
||||
|
||||
public IAlarmSettingManager AlarmSettingManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View("SimonIndex");
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Edit()
|
||||
{
|
||||
return View(AlarmSettingManager.LoadAll().Where(r => r.HotelID == CurrentHotelID));
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAll()
|
||||
{
|
||||
var settings = AlarmSettingManager.LoadAll().Where(r => r.HotelID == CurrentHotelID);
|
||||
|
||||
var result = new Dictionary<string, object>();
|
||||
|
||||
foreach(var s in settings)
|
||||
{
|
||||
result.Add(s.Code, s);
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Data = result }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAll2()
|
||||
{
|
||||
List<AlarmSetting> list = AlarmSettingManager.LoadAll().Where(r => r.HotelID == CurrentHotelID).OrderBy(r => r.Sort).ToList();
|
||||
|
||||
if (list.Count == 0)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Data = "当前酒店没有报警信息数据。" }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
IEnumerable<IGrouping<char, AlarmSetting>> list2 = list.GroupBy(r => r.Type);
|
||||
|
||||
IDictionary<string, IList<object>> list3 = new Dictionary<string, IList<object>>();
|
||||
|
||||
foreach (var item in list2)
|
||||
{
|
||||
var type = item.Key.ToString();
|
||||
list3[type] = new List<object>();
|
||||
foreach (var setting in item)
|
||||
{
|
||||
|
||||
list3[type].Add(new
|
||||
{
|
||||
setting.Type,
|
||||
setting.Code,
|
||||
Name = ((Boolean)Session["isCN"]) ? setting.Name : setting.EName,
|
||||
Value = int.Parse(setting.Value),
|
||||
setting.Color,
|
||||
setting.Sort,
|
||||
setting.Beep
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Data = list3 }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载服务和异常设置
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ActionResult LoadServicesAndAbnormities()
|
||||
{
|
||||
var list = new List<AlarmSetting>();
|
||||
|
||||
list.AddRange(AlarmSettingManager.LoadAll('B').Where(r => r.HotelID == CurrentHotelID));
|
||||
|
||||
list.AddRange(AlarmSettingManager.LoadAll('C').Where(r => r.HotelID == CurrentHotelID));
|
||||
|
||||
var result = list.Select(r => new { r.Code, Name = r.Name != null ? r.Name:r.EName});// ((Boolean)Session["isCN"]) ? r.Name : r.EName });
|
||||
|
||||
return Json(new { total = result.Count(), rows = result });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前服务信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadCurrentMsg()
|
||||
{
|
||||
var settings = AlarmSettingManager.LoadAll().Where(r => r.HotelID == CurrentHotelID && r.Type == 'B' && r.Value == "1").OrderBy(r => r.Sort);
|
||||
|
||||
return Json(new { IsSuccess = true, Data = settings }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Save(string jsonData)
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<AlarmSetting> settings = Newtonsoft.Json.JsonConvert.DeserializeObject<IList<AlarmSetting>>(jsonData);
|
||||
|
||||
if (settings != null)
|
||||
{
|
||||
foreach (var setting in settings)
|
||||
{
|
||||
var entity = AlarmSettingManager.Get(CurrentHotelID, setting.Type, setting.Code);
|
||||
|
||||
entity.Value = setting.Value;
|
||||
entity.Beep = setting.Beep;
|
||||
|
||||
AlarmSettingManager.Update(entity);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
SaveSystemLog(AUTHORITY_AlarmSetting, HttpContext.InnerLanguage("EditAlarmSetting"), "");
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (logger.IsErrorEnabled)
|
||||
{
|
||||
logger.Error(HttpContext.InnerLanguage("FailedToSaveTheAlarmSettings"), ex);
|
||||
}
|
||||
|
||||
SaveSystemLog(AUTHORITY_AlarmSetting, HttpContext.InnerLanguage("EditAlarmSetting"), "", false);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SaveFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
6398
WebSite/Controllers/ApiController.cs
Normal file
6398
WebSite/Controllers/ApiController.cs
Normal file
File diff suppressed because it is too large
Load Diff
636
WebSite/Controllers/AppController.cs
Normal file
636
WebSite/Controllers/AppController.cs
Normal file
@@ -0,0 +1,636 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Service;
|
||||
using WebSite.Models;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class AppController : BaseController
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public IHostManager HostManager { get; set; }
|
||||
|
||||
public IHostModalManager HostModalManager { get; set; }
|
||||
|
||||
public IHostAirManager HostAirManager { get; set; }
|
||||
|
||||
public IRoomServiceManager RoomServiceManager { get; set; }
|
||||
|
||||
public IRoomTypeSceneManager RoomTypeSceneManager { get; set; }
|
||||
|
||||
public ILightControlManager LightControlManager { get; set; }
|
||||
|
||||
public IAppRoomManager AppRoomManager { get; set; }
|
||||
|
||||
public IAppHotelManager AppHotelManager { get; set; }
|
||||
|
||||
public IAppMenuManager AppMenuManager { get; set; }
|
||||
|
||||
public ITvControlManager TvControlManager { get; set; }
|
||||
|
||||
public IRoomTypeModalManager RoomTypeModalManager { get; set; }
|
||||
|
||||
public IAlarmSettingManager AlarmSettingManager { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
public ActionResult Login(string mac)
|
||||
{
|
||||
if (!Regex.IsMatch(mac, @"^([0-9a-fA-F]{2})(([/\s:-][0-9a-fA-F]{2}){5})$") &&
|
||||
!Regex.IsMatch(mac, @"^\d{6}$"))
|
||||
{
|
||||
return Json(new { IsSuccess = false, Result = "房号未知,请联系管理员。" }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
AppRoom appRoom = AppRoomManager.GetRoomNumber(mac);
|
||||
if (appRoom == null)
|
||||
{
|
||||
appRoom = new AppRoom();
|
||||
appRoom.MAC = mac;
|
||||
appRoom.RoomNumber = "";
|
||||
AppRoomManager.Save(appRoom);
|
||||
|
||||
return Json(new { IsSuccess = false, Result = "房号未知,请联系管理员。" }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(appRoom.RoomNumber))
|
||||
{
|
||||
return Json(new { IsSuccess = true, Result = appRoom.RoomNumber }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = false, Result = "房号未知,请联系管理员。" }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
public ActionResult Index(string roomNumber)
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
if (host != null)
|
||||
{
|
||||
ViewData["RoomNumber"] = host.RoomNumber;
|
||||
//ViewData["CurrentTemp"] = host.CurrentTemp;
|
||||
|
||||
IList<HostModal> hostModals = HostModalManager.LoadByHostID(host.ID);
|
||||
|
||||
var list = HostAirManager.LoadAll().Where(r => r.HostID == host.ID).Take(1).Select(r => r.CurrentTemp).ToList();
|
||||
|
||||
if (list.Count() > 0)
|
||||
{
|
||||
ViewData["Temp"] = list[0];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewData["RoomNumber"] = "";
|
||||
ViewData["CurrentTemp"] = "";
|
||||
ViewData["Temp"] = 0;
|
||||
ViewData["AlarmList"] = new List<AlarmService>();
|
||||
}
|
||||
|
||||
var AppMenus = AppMenuManager.LoadAll().Where(r => r.ActiveIndicator == true).OrderBy(r => r.Sort).ToList();
|
||||
|
||||
ViewData["AppMenuControl"] = AppMenus;
|
||||
|
||||
ViewData["Date"] = DateTime.Now.ToString("dd/MM");
|
||||
ViewData["Week"] = GetWeek(DateTime.Now.DayOfWeek);
|
||||
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
public ActionResult LoadAlarm(string roomNumber)
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
IList<AlarmSetting> AlarmList = AlarmSettingManager.LoadAll('B').Where(r => r.AppApply).ToList();
|
||||
|
||||
IList<AlarmService> Service = new List<AlarmService>();
|
||||
|
||||
bool isCN = (Request.Cookies["isCN"].Value == "zh-cn");
|
||||
|
||||
for (int i = 0; i < AlarmList.Count; i++)
|
||||
{
|
||||
AlarmService alarmService = new AlarmService();
|
||||
|
||||
alarmService.Status = RoomServiceManager.Get(host.ID, AlarmList[i].Code).Status;
|
||||
alarmService.Name = isCN ? AlarmList[i].Name : AlarmList[i].EName;
|
||||
alarmService.Code = AlarmList[i].Code;
|
||||
|
||||
Service.Add(alarmService);
|
||||
}
|
||||
|
||||
return Json(Service);
|
||||
}
|
||||
|
||||
public ActionResult Validate(string roomNumber)
|
||||
{
|
||||
if (String.IsNullOrEmpty(roomNumber))
|
||||
{
|
||||
return Content("房号不能为空。");
|
||||
}
|
||||
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null)
|
||||
{
|
||||
return Content("无效的房号。");
|
||||
}
|
||||
|
||||
return Content(String.Empty);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult ServiceControl(string roomNumber, string groupAddress, int status)
|
||||
{
|
||||
try
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null)
|
||||
{
|
||||
throw new ApplicationException("无效的房号!");
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(groupAddress))
|
||||
{
|
||||
throw new ApplicationException("无效的服务编号!");
|
||||
}
|
||||
|
||||
RoomServiceManager.SetService(host, groupAddress, status);
|
||||
|
||||
return Json(new { IsSuccess = true });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ActionResult LightControl(string roomNumber)
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
//IList<HostModal> hostModals = HostModalManager.Load(host.ID, DeviceType.Light).Where(r => r.Modal.AppApply).ToList();
|
||||
IList<HostModal> hostModals = HostModalManager.Load(host.ID, DeviceType.Relay).Where(r => r.Modal.AppApply).ToList();
|
||||
|
||||
IList<Light> lightList = new List<Light>();
|
||||
|
||||
bool isCN = (Request.Cookies["isCN"].Value == "zh-cn");
|
||||
|
||||
foreach (HostModal modal in hostModals)
|
||||
{
|
||||
Light light = new Light { Name = isCN ? modal.Modal.Name : modal.Modal.EnglishName, ModalAddress = modal.Modal.ModalAddress, Status = modal.Status };
|
||||
|
||||
lightList.Add(light);
|
||||
}
|
||||
|
||||
ViewData["LightList"] = lightList;
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult LoadLightDimmer(string roomNumber)
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
IList<HostModal> DimmerModals = HostModalManager.Load(host.ID, DeviceType.Dimmer).Where(r => r.Modal.AppApply).ToList();
|
||||
|
||||
IList<Light> DimmerLightList = new List<Light>();
|
||||
|
||||
bool isCN = (Request.Cookies["isCN"].Value == "zh-cn");
|
||||
|
||||
foreach (HostModal modal in DimmerModals)
|
||||
{
|
||||
Light light = new Light { Name = isCN ? modal.Modal.Name : modal.Modal.EnglishName, ModalAddress = modal.Modal.ModalAddress, Status = modal.Brightness };
|
||||
|
||||
DimmerLightList.Add(light);
|
||||
}
|
||||
|
||||
return Json(DimmerLightList);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult LightControl(string roomNumber, string groupAddress, int status)
|
||||
{
|
||||
try
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null)
|
||||
{
|
||||
throw new ApplicationException("无效的房号。");
|
||||
}
|
||||
|
||||
var hostModal = HostModalManager.GetByModalAddress(host.ID, groupAddress);
|
||||
if (hostModal == null)
|
||||
{
|
||||
throw new ApplicationException("无效的灯光。");
|
||||
}
|
||||
|
||||
HostModalManager.SetDevice(host, hostModal, (status == 1 ? 1 : 2), status);
|
||||
|
||||
return Json(new { IsSuccess = true });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = true, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult Television(string roomNumber)
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null)
|
||||
{
|
||||
throw new ApplicationException("无效的房号。");
|
||||
}
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Television(string roomNumber, TvKey key)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
if (host == null)
|
||||
{
|
||||
throw new ApplicationException("无效的房号。");
|
||||
}
|
||||
|
||||
TvControlManager.SendKey(host, key);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = "操作成功。" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult LoadAirCondition(string roomNumber)
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
if (host == null)
|
||||
{
|
||||
throw new ApplicationException("无效的房号。");
|
||||
}
|
||||
|
||||
List<HostAir> hostAir = HostAirManager.LoadAll().Where(r => r.HostID == host.ID).ToList();
|
||||
|
||||
List<Air> list = new List<Air>();
|
||||
|
||||
bool isCN = (Request.Cookies["isCN"].Value == "zh-cn");
|
||||
|
||||
foreach (HostAir item in hostAir)
|
||||
{
|
||||
Air air = new Air { HostID = item.HostID, Name = isCN ? item.Modal.CustomerName : item.Modal.EnglishName, RoomTypeAirID = item.Modal.ModalType.ID };
|
||||
|
||||
list.Add(air);
|
||||
}
|
||||
|
||||
return Json(list);
|
||||
}
|
||||
[HttpPost]
|
||||
public ActionResult LoadAirSetting(int hostId, int airId)
|
||||
{
|
||||
HostAir hostAir = HostAirManager.GetByModalTypeID(hostId, airId);
|
||||
|
||||
object air = new
|
||||
{
|
||||
Running = hostAir.OnOff,
|
||||
SettingTemp = hostAir.SettingTemp,
|
||||
Speed = hostAir.Speed,
|
||||
HightTemp = hostAir.HightTemp,
|
||||
LowerTemp = hostAir.LowerTemp,
|
||||
Mode = hostAir.Mode
|
||||
};
|
||||
|
||||
return Json(air);
|
||||
}
|
||||
|
||||
public ActionResult AirConditionControl(string roomNumber)
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
if (host == null)
|
||||
{
|
||||
throw new ApplicationException("无效的房号。");
|
||||
}
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult AirConditionControl(string roomNumber, int hostId, int airId, AirProperty property, int status)
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
if (host == null)
|
||||
{
|
||||
throw new ApplicationException("无效的房号。");
|
||||
}
|
||||
|
||||
if (host != null)
|
||||
{
|
||||
HostAirManager.SetAirProperty(host, airId, property, status);
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true });
|
||||
}
|
||||
|
||||
public ActionResult LoadCurtain(string roomNumber, DeviceType deviceType)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
if (host == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidRoomNumber"));
|
||||
}
|
||||
|
||||
var hostModals = HostModalManager.Load(host.ID, deviceType).OrderBy(r => r.Modal.Sort).ToList();
|
||||
if (hostModals.Count % 2 != 0)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("CurtainConfigNotCorrect"));
|
||||
}
|
||||
|
||||
var curtainList = new List<CurtainModel>();
|
||||
|
||||
var num = hostModals.Count / 2;
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
var curtain = CreateCurtainModel(hostModals.Skip(i * 2).Take(2).ToList());
|
||||
if (curtain.CurtainOpen == null ||
|
||||
curtain.CurtainClose == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("CurtainConfigNotCorrect"));
|
||||
}
|
||||
|
||||
curtainList.Add(curtain);
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Data = curtainList });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult CurtainControl(string roomNumber)
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
if (host == null)
|
||||
{
|
||||
throw new ApplicationException("无效的房号。");
|
||||
}
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult CurtainControl(string roomNumber, string groupAddress, int status)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
if (host == null)
|
||||
{
|
||||
throw new ApplicationException("无效的房号。");
|
||||
}
|
||||
|
||||
HostModalManager.UpdateHostModalStatus(host, groupAddress, status);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = "操作成功。" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult Scene(string roomNumber)
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
List<RoomTypeScene> list = RoomTypeSceneManager.LoadAll().Where(r => r.RoomType.ID == host.RoomType.ID).OrderBy(r => r.Sort).ToList();
|
||||
|
||||
ViewData["AppSceneControl"] = list;
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Scene(string roomNumber, int sceneID)
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null && sceneID < 1)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = "无效的房号。" });
|
||||
}
|
||||
|
||||
var scene = RoomTypeSceneManager.Get(sceneID);
|
||||
if (scene == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = "无效的场景。" });
|
||||
}
|
||||
|
||||
LightControlManager.ApplyScene(host, scene);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = "设置场景成功!" });
|
||||
}
|
||||
|
||||
public ActionResult SystemSetting()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult HotelIntroduction()
|
||||
{
|
||||
IList<AppHotel> result = AppHotelManager.LoadAll().ToList();
|
||||
|
||||
bool isCN = (Request.Cookies["isCN"].Value == "zh-cn");
|
||||
|
||||
foreach (AppHotel appHotel in result)
|
||||
{
|
||||
if (!isCN)
|
||||
{
|
||||
if (appHotel.Code == "H03")
|
||||
{
|
||||
ViewData["HoteName"] = appHotel.Value;
|
||||
}
|
||||
else if (appHotel.Code == "H04")
|
||||
{
|
||||
ViewData["Introduction"] = appHotel.Value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (appHotel.Code == "H01")
|
||||
{
|
||||
ViewData["HoteName"] = appHotel.Value;
|
||||
}
|
||||
else if (appHotel.Code == "H02")
|
||||
{
|
||||
ViewData["Introduction"] = appHotel.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult About()
|
||||
{
|
||||
string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
version = version.Substring(0, version.LastIndexOf("."));
|
||||
|
||||
ViewData["Version"] = version;
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private CurtainModel CreateCurtainModel(IList<HostModal> hostModals)
|
||||
{
|
||||
var curtain = new CurtainModel();
|
||||
|
||||
//bool isCN = (Request.Cookies["isCN"].Value == "zh-cn");
|
||||
|
||||
//if (hostModals.Count >= 2)
|
||||
//{
|
||||
// var curtainOpenModal = hostModals.FirstOrDefault(r => r.Modal != null &&
|
||||
// r.Modal.Subtype.HasValue &&
|
||||
// (r.Modal.Subtype.Value == DeviceSubtype.CurtainOpen ||
|
||||
// r.Modal.Subtype.Value == DeviceSubtype.GauzeOpen));
|
||||
// if (curtainOpenModal != null)
|
||||
// {
|
||||
// curtain.CurtainOpen = new CurtainOpenCloseModel
|
||||
// {
|
||||
// Address = curtainOpenModal.Modal.ModalAddress,
|
||||
// Name = isCN ? curtainOpenModal.Modal.Name : curtainOpenModal.Modal.EnglishName,
|
||||
// Subtype = curtainOpenModal.Modal.Subtype.Value,
|
||||
// Status = curtainOpenModal.Status
|
||||
// };
|
||||
// }
|
||||
|
||||
// var closeSubtype = curtain.CurtainOpen.Subtype == DeviceSubtype.CurtainOpen ? DeviceSubtype.CurtainClose : DeviceSubtype.GauzeClose;
|
||||
|
||||
// var curtainCloseModal = hostModals.FirstOrDefault(r => r.Modal != null && r.Modal.Subtype.HasValue && r.Modal.Subtype.Value == closeSubtype);
|
||||
// if (curtainCloseModal != null)
|
||||
// {
|
||||
// curtain.CurtainClose = new CurtainOpenCloseModel
|
||||
// {
|
||||
// Address = curtainCloseModal.Modal.ModalAddress,
|
||||
// Name = isCN ? curtainCloseModal.Modal.Name : curtainCloseModal.Modal.EnglishName,
|
||||
// Subtype = curtainCloseModal.Modal.Subtype.Value
|
||||
// };
|
||||
// }
|
||||
//}
|
||||
|
||||
return curtain;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换星期到中文+英文简写形式
|
||||
/// </summary>
|
||||
/// <param name="week"></param>
|
||||
/// <returns></returns>
|
||||
private string GetWeek(DayOfWeek week)
|
||||
{
|
||||
switch (week)
|
||||
{
|
||||
case DayOfWeek.Monday:
|
||||
return "Mon.";
|
||||
case DayOfWeek.Tuesday:
|
||||
return "Tues.";
|
||||
case DayOfWeek.Wednesday:
|
||||
return "Wed.";
|
||||
case DayOfWeek.Thursday:
|
||||
return "Thur.";
|
||||
case DayOfWeek.Friday:
|
||||
return "Fri.";
|
||||
case DayOfWeek.Saturday:
|
||||
return "Sat.";
|
||||
case DayOfWeek.Sunday:
|
||||
return "Sun.";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class Air
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string ModalAddress { get; set; }
|
||||
public int HostID { get; set; }
|
||||
public int RoomTypeAirID { get; set; }
|
||||
public int Status { get; set; }//空调开关状态,2/关,1/开
|
||||
public int CurrentTemp { get; set; }
|
||||
public int SettingTemp { get; set; }
|
||||
public int Mode { get; set; }
|
||||
public int FanSpeed { get; set; }
|
||||
public int Valve { get; set; }
|
||||
}
|
||||
|
||||
public class Curtain
|
||||
{
|
||||
public string ModalAddress { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Status { get; set; }
|
||||
}
|
||||
|
||||
public class Music
|
||||
{
|
||||
/// <summary>
|
||||
/// 回路名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// 回路地址
|
||||
/// </summary>
|
||||
public string ModalAddress { get; set; }
|
||||
/// <summary>
|
||||
/// 1开,2关
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
/// <summary>
|
||||
/// 音量大小1~10
|
||||
/// </summary>
|
||||
public int Brightness { get; set; }
|
||||
/// <summary>
|
||||
/// 1播放,2暂停,3上一曲,4下一曲,5音量加,6音量减
|
||||
/// </summary>
|
||||
public int Mode { get; set; }
|
||||
}
|
||||
|
||||
public class Light
|
||||
{
|
||||
public string ModalAddress { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Status { get; set; }
|
||||
public int Brightness { get; set; }
|
||||
}
|
||||
|
||||
public class AlarmService
|
||||
{
|
||||
public string Code { get; set; }
|
||||
public string Name { get; set; }
|
||||
public bool Status { get; set; }
|
||||
}
|
||||
}
|
||||
194
WebSite/Controllers/BaseController.cs
Normal file
194
WebSite/Controllers/BaseController.cs
Normal file
@@ -0,0 +1,194 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
[HandleError]
|
||||
public class BaseController : Controller
|
||||
{
|
||||
public static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(BaseController));
|
||||
public ISysSystemLogsManager SysSystemLogsManager { get; set; }
|
||||
|
||||
protected override void HandleUnknownAction(string actionName)
|
||||
{
|
||||
this.View(actionName).ExecuteResult(this.ControllerContext);
|
||||
}
|
||||
|
||||
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
|
||||
{
|
||||
base.Initialize(requestContext);
|
||||
}
|
||||
|
||||
protected Language Language
|
||||
{
|
||||
get
|
||||
{
|
||||
//语言判断
|
||||
int? isCN = Session["isCN"] as int?;
|
||||
if (!isCN.HasValue)
|
||||
{
|
||||
isCN = 0;
|
||||
Session["isCN"] = isCN;
|
||||
}
|
||||
switch (isCN)
|
||||
{
|
||||
case 1:
|
||||
return Language.EN;
|
||||
case 2:
|
||||
return Language.ZH_TW;
|
||||
default:
|
||||
return Language.CN;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 当前酒店ID
|
||||
/// </summary>
|
||||
protected int CurrentHotelID
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Session["CurrentHotelID"] == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return (int)Session["CurrentHotelID"];
|
||||
}
|
||||
set
|
||||
{
|
||||
Session["CurrentHotelID"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected string CurrentHotelCode
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Session["CurrentHotelCode"] == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return Session["CurrentHotelCode"].ToString();
|
||||
}
|
||||
set
|
||||
{
|
||||
Session["CurrentHotelCode"] = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 当前酒店名称
|
||||
/// </summary>
|
||||
protected string CurrentHotelName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Session["CurrentHotelName"] == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return (string)Session["CurrentHotelName"];
|
||||
}
|
||||
set
|
||||
{
|
||||
Session["CurrentHotelName"] = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 当前酒店logo路径
|
||||
/// </summary>
|
||||
protected string CurrentLogoPath
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Session["CurrentLogoPath"] == null)
|
||||
{
|
||||
return "../Uploads/logo/1001.png";
|
||||
}
|
||||
return (string)Session["CurrentLogoPath"];
|
||||
}
|
||||
set
|
||||
{
|
||||
Session["CurrentLogoPath"] = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 当前酒店是否到期提醒
|
||||
/// </summary>
|
||||
protected bool CurrentHotelIsExpire
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Session["CurrentHotelIsExpire"] == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return Convert.ToBoolean(Session["CurrentHotelIsExpire"]);
|
||||
}
|
||||
set
|
||||
{
|
||||
Session["CurrentHotelIsExpire"] = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 记录操作日志
|
||||
/// </summary>
|
||||
/// <param name="authorityID">权限ID</param>
|
||||
/// <param name="action">动作</param>
|
||||
/// <param name="detail">详细</param>
|
||||
/// <param name="result">操作结果</param>
|
||||
/// <param name="account">帐号</param>
|
||||
/// <param name="hotelID">所属酒店ID</param>
|
||||
protected void SaveSystemLog(int authorityID, string action, string detail, bool result = true, string account = "", int hotelID = 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
Domain.SysSystemLogs entity = new Domain.SysSystemLogs();
|
||||
entity.ID = 0;
|
||||
entity.AuthorityID = authorityID;
|
||||
entity.Action = action;
|
||||
entity.Detail = detail;
|
||||
entity.Result = result ? HttpContext.InnerLanguage("OperationSuccess") : HttpContext.InnerLanguage("OperationFailed");
|
||||
entity.Account = string.IsNullOrEmpty(this.User.Identity.Name) ? account : this.User.Identity.Name;
|
||||
entity.IP = GetClientIP();
|
||||
entity.Time = DateTime.Now;
|
||||
entity.HotelID = CurrentHotelID == 0 ? hotelID : CurrentHotelID;
|
||||
|
||||
SysSystemLogsManager.Save(entity);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
protected string GetClientIP()
|
||||
{
|
||||
return Common.Tools.GetClientIP(Request);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据语言返回对应名称
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="ename"></param>
|
||||
/// <param name="twname"></param>
|
||||
/// <returns></returns>
|
||||
protected string ReturnNameByLanguage(string name, string ename, string twname)
|
||||
{
|
||||
//语言判断
|
||||
int? isCN = Session["isCN"] as int?;
|
||||
if (!isCN.HasValue)
|
||||
{
|
||||
isCN = 0;
|
||||
Session["isCN"] = isCN;
|
||||
}
|
||||
switch ((int)Session["isCN"])
|
||||
{
|
||||
case 1:
|
||||
return ename;
|
||||
case 2:
|
||||
return twname;
|
||||
default:
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
WebSite/Controllers/CacheController.cs
Normal file
31
WebSite/Controllers/CacheController.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
using Common;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class CacheController : BaseController
|
||||
{
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(CacheController));
|
||||
|
||||
#region Action
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult LoadAllByPage(int page, int rows, string order, string sort)
|
||||
{
|
||||
var list = "";
|
||||
return Json(new { total = 0, rows = list });
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
114
WebSite/Controllers/CoulometricStatisticsController.cs
Normal file
114
WebSite/Controllers/CoulometricStatisticsController.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Service;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class CoulometricStatisticsController : BaseController
|
||||
{
|
||||
public IOverviewManager OverviewManager { get; set; }
|
||||
|
||||
public IEnergyConsumptionStatisticsManager EnergyConsumptionStatisticsManager { get; set; }
|
||||
|
||||
#region Actions
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult LoadRoomNumbers()
|
||||
{
|
||||
IList<object> result = new List<object>();
|
||||
|
||||
IList<string> roomNumbers = EnergyConsumptionStatisticsManager.LoadRoomNumbers();
|
||||
|
||||
foreach (string roomNumber in roomNumbers)
|
||||
{
|
||||
result.Add(new { Value = roomNumber, Name = roomNumber });
|
||||
}
|
||||
|
||||
return Json(result, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
public ActionResult LoadModals(string roomNumber, DeviceType? deviceType)
|
||||
{
|
||||
var table = EnergyConsumptionStatisticsManager.LoadModals(roomNumber, deviceType);
|
||||
|
||||
var list = new List<object>();
|
||||
|
||||
foreach (DataRow row in table.Rows)
|
||||
{
|
||||
list.Add(new
|
||||
{
|
||||
RoomType = row["RoomType"],
|
||||
ModalAddress = row["ModalAddress"],
|
||||
Outlet = row["Outlet"],
|
||||
Name = (Language == Language.CN) ? row["Name"] : row["EnglishName"]
|
||||
});
|
||||
}
|
||||
|
||||
return Json(new { total = list.Count, rows = list });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载图表数据
|
||||
/// </summary>
|
||||
/// <param name="roomNumber"></param>
|
||||
/// <param name="dateUint"></param>
|
||||
/// <param name="startDate"></param>
|
||||
/// <param name="endDate"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult LoadChartData(string roomNumbers, DateTimeUnit dateUnit, string startDate, string endDate, DeviceType? deviceType, string modalIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
var table = OverviewManager.LoadEnergyStatitics(roomNumbers, dateUnit, startDate, endDate, deviceType, modalIds);
|
||||
|
||||
IList<string> legend = new List<string>();
|
||||
|
||||
IList<object> data = new List<object>();
|
||||
|
||||
IList<string> xAxis = new List<string>();
|
||||
|
||||
for (int i = 1; i < table.Columns.Count; i++)
|
||||
{
|
||||
xAxis.Add(table.Columns[i].ToString());
|
||||
}
|
||||
|
||||
foreach (DataRow row in table.Rows)
|
||||
{
|
||||
string name = row["回路"].ToString();
|
||||
|
||||
legend.Add(name);
|
||||
|
||||
IList<float> data1 = new List<float>();
|
||||
|
||||
for (int i = 1; i < table.Columns.Count; i++)
|
||||
{
|
||||
data1.Add(Convert.ToSingle(row[i]));
|
||||
}
|
||||
|
||||
data.Add(new { name = name, data = data1 });
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Legend = legend, XAxis = xAxis, Data = data });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex.GetType() == typeof(IndexOutOfRangeException))
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("NotFoundData") });
|
||||
}
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("LoadDataFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
148
WebSite/Controllers/FaultRecordsController.cs
Normal file
148
WebSite/Controllers/FaultRecordsController.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Service;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class FaultRecordsController : BaseController
|
||||
{
|
||||
private const int AUTHORITY_FautRecords = 14;
|
||||
|
||||
private const int AUTHORITY_Repair = 15;
|
||||
|
||||
public IFaultRecordsManager FaultRecordsManager { get; set; }
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAllByPage(int page, int rows, string order, string sort)
|
||||
{
|
||||
long total = 0;
|
||||
|
||||
var list = FaultRecordsManager.LoadAllByPage(out total, page, rows, order, sort, CurrentHotelID);
|
||||
|
||||
var result = list.Select(r => new
|
||||
{
|
||||
r.ID,
|
||||
r.Status,
|
||||
r.IsCancel,
|
||||
r.Number,
|
||||
r.RoomNumber,
|
||||
FaultTypeID = r.FaultType.ID,
|
||||
FaultTypeCode = r.FaultType.Code,
|
||||
FaultType = r.FaultType.Name,
|
||||
FaultTime = r.FaultTime.HasValue ? r.FaultTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
|
||||
r.Description,
|
||||
r.RegisteredPerson,
|
||||
r.RegisteredTime,
|
||||
r.RepairPerson,
|
||||
RepairTime = r.RepairTime.HasValue ? r.RepairTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
|
||||
r.RepairContent,
|
||||
r.CancelPerson,
|
||||
CancelTime = r.CancelTime.HasValue ? r.CancelTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
|
||||
r.CancelReason
|
||||
});
|
||||
|
||||
return Json(new { total = total, rows = result });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult GenerateFaultNumber()
|
||||
{
|
||||
return Json(new { IsSuccess = true, Data = new { Number = FaultRecordsManager.GenerateFaultNumber() } }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Delete(IList<int> idList)
|
||||
{
|
||||
FaultRecordsManager.Delete(idList.Cast<object>().ToList());
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Save(string jsonData)
|
||||
{
|
||||
FaultRecord entity = Newtonsoft.Json.JsonConvert.DeserializeObject<FaultRecord>(jsonData);
|
||||
|
||||
if (entity.ID == 0)
|
||||
{
|
||||
entity.RegisteredPerson = User.Identity.Name;
|
||||
entity.RegisteredTime = DateTime.Now;
|
||||
entity.HotelID = CurrentHotelID;
|
||||
FaultRecordsManager.Save(entity);
|
||||
|
||||
SaveSystemLog(AUTHORITY_FautRecords, HttpContext.InnerLanguage("FailureRegistration"), String.Format(HttpContext.InnerLanguage("FaultID")+":{0}", entity.Number));
|
||||
}
|
||||
else
|
||||
{
|
||||
FaultRecord fault = FaultRecordsManager.Get(entity.ID);
|
||||
if (fault != null)
|
||||
{
|
||||
fault.FaultTime = entity.FaultTime;
|
||||
fault.RoomNumber = entity.RoomNumber;
|
||||
fault.FaultType = entity.FaultType;
|
||||
fault.Description = entity.Description;
|
||||
FaultRecordsManager.Update(fault);
|
||||
|
||||
SaveSystemLog(AUTHORITY_FautRecords, HttpContext.InnerLanguage("FailureEdit"), String.Format(HttpContext.InnerLanguage("FaultID") + ":{0}", entity.Number));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveFailed")});
|
||||
}
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Cancel(int id, DateTime cancelTime, string cancelReason)
|
||||
{
|
||||
FaultRecord fault = FaultRecordsManager.Get(id);
|
||||
|
||||
if (fault != null)
|
||||
{
|
||||
fault.IsCancel = true;
|
||||
fault.CancelPerson = User.Identity.Name;
|
||||
fault.CancelTime = cancelTime;
|
||||
fault.CancelReason = cancelReason;
|
||||
FaultRecordsManager.Update(fault);
|
||||
|
||||
SaveSystemLog(AUTHORITY_FautRecords, HttpContext.InnerLanguage("Logout"), String.Format(HttpContext.InnerLanguage("FaultID") + ":{0}", fault.Number));
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("LogoutSuccess")});
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("LogoutFailed")});
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Repair(int id, DateTime repairTime, string repairPerson, string repairContent)
|
||||
{
|
||||
FaultRecord fault = FaultRecordsManager.Get(id);
|
||||
|
||||
if (fault != null)
|
||||
{
|
||||
fault.Status = 1;
|
||||
fault.RepairTime = repairTime;
|
||||
fault.RepairPerson = repairPerson;
|
||||
fault.RepairContent = repairContent;
|
||||
FaultRecordsManager.Update(fault);
|
||||
|
||||
SaveSystemLog(AUTHORITY_Repair, HttpContext.InnerLanguage("RepairRecord"), String.Format(String.Format(HttpContext.InnerLanguage("FaultID") + ":{0}", fault.Number)));
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("RegistrationSuccess") });
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("RegistrationFailed") });
|
||||
}
|
||||
}
|
||||
}
|
||||
101
WebSite/Controllers/FaultTypeController.cs
Normal file
101
WebSite/Controllers/FaultTypeController.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class FaultTypeController : BaseController
|
||||
{
|
||||
private const int AuthorityID = 22;
|
||||
|
||||
public IFaultTypeManager FaultTypeManager { get; set; }
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 维修登记页面
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ActionResult RepairRecord()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAllForCombobox()
|
||||
{
|
||||
return Json(FaultTypeManager.LoadAll().Select(r => new { r.ID, r.Code, r.Name }).ToList());
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAllByPage(int page, int rows, string order, string sort)
|
||||
{
|
||||
long total = 0;
|
||||
|
||||
var list = FaultTypeManager.LoadAllByPage(out total, page, rows, order, sort, CurrentHotelID);
|
||||
|
||||
return Json(new { total = total, rows = list });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Save(string jsonData)
|
||||
{
|
||||
FaultType entity = Newtonsoft.Json.JsonConvert.DeserializeObject<FaultType>(jsonData);
|
||||
|
||||
FaultType existFaultType = FaultTypeManager.Get(entity.Code);
|
||||
|
||||
if (existFaultType != null)
|
||||
{
|
||||
if (entity.ID == 0 || entity.ID != existFaultType.ID)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("FaultID") + "【" + entity.Code + "】" + HttpContext.InnerLanguage("AlreadyExist") });
|
||||
}
|
||||
}
|
||||
|
||||
if (entity.ID == 0)
|
||||
{
|
||||
entity.HotelID = CurrentHotelID;
|
||||
FaultTypeManager.Save(entity);
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("New"), String.Format(HttpContext.InnerLanguage("FaultID") + ":{0}," + HttpContext.InnerLanguage("FaultType") + ":{1}。", entity.Code, entity.Name));
|
||||
}
|
||||
else
|
||||
{
|
||||
FaultType faultType = FaultTypeManager.Get(entity.ID);
|
||||
faultType.Code = entity.Code;
|
||||
faultType.Name = entity.Name;
|
||||
faultType.Remark = entity.Remark;
|
||||
faultType.HotelID = CurrentHotelID;
|
||||
|
||||
FaultTypeManager.Update(faultType);
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Edit"), String.Format(HttpContext.InnerLanguage("FaultID") + ":{0}," + HttpContext.InnerLanguage("FaultType") + ":{1}。", entity.Code, entity.Name));
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Delete(IList<int> idList, IList<string> nameList)
|
||||
{
|
||||
try
|
||||
{
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Delete"), String.Join(",", nameList.ToArray()));
|
||||
|
||||
FaultTypeManager.Delete(idList.Cast<object>().ToList());
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
229
WebSite/Controllers/GroupController.cs
Normal file
229
WebSite/Controllers/GroupController.cs
Normal file
@@ -0,0 +1,229 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class GroupController : BaseController
|
||||
{
|
||||
private const int AuthorityID = 30;
|
||||
|
||||
public IGroupManager GroupManager { get; set; }
|
||||
|
||||
public IHostManager HostManager { get; set; }
|
||||
|
||||
public ISysUserManager SysUserManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
//
|
||||
// GET: /Group/
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Edit(int? id, int? parentId)
|
||||
{
|
||||
if (id.HasValue)
|
||||
{
|
||||
return View(GroupManager.Get(id));
|
||||
}
|
||||
return View(new Group { ID = 0, Name = "", Parent = new Group { ID = parentId.GetValueOrDefault() }, Sort = 1 });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadGroupTree(int? hotelID)
|
||||
{
|
||||
if (!hotelID.HasValue)
|
||||
{
|
||||
hotelID = CurrentHotelID;
|
||||
}
|
||||
IList<Group> groups = GroupManager.LoadAll().Where(r => r.HotelID == hotelID).ToList();
|
||||
return Json(BuildGroupTree(groups, null), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadGroupTree2(int? hotelID)
|
||||
{
|
||||
if (!hotelID.HasValue || hotelID == 0)
|
||||
{
|
||||
hotelID = CurrentHotelID;
|
||||
}
|
||||
return Json(GroupManager.CreateGroupTree(null, Convert.ToInt16(hotelID)), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadGroupTreeWithRoom()
|
||||
{
|
||||
var groupTree = GroupManager.CreateGroupTreeWithRoom(null, null, CurrentHotelID);
|
||||
return Json(groupTree, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadCurrentUserGroupTree()
|
||||
{
|
||||
SysUsers currentUser = SysUserManager.Get(User.Identity.Name);
|
||||
if (currentUser.HotelID > 0 && currentUser.Group == null)//酒店用户没有楼层分组权限
|
||||
{
|
||||
return Json(null, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
IList<object> groupTree = new List<object>();
|
||||
groupTree.Add(new { id = 0, text = HttpContext.InnerLanguage("HotelFloor"), iconCls = "tree-node-no-icon" });
|
||||
//如果该用户所在分组同属于当前酒店,则获取该分组下客房,否则获取该酒店下所有客房
|
||||
if (currentUser.Group != null && currentUser.Group.HotelID == CurrentHotelID)
|
||||
{
|
||||
groupTree.Add(GroupManager.CreateGroupTree2(currentUser.Group, CurrentHotelID));
|
||||
}
|
||||
else
|
||||
{
|
||||
IList<Group> currentGroup = GroupManager.GetGroupList(CurrentHotelID);
|
||||
if (currentGroup.Count > 0)
|
||||
{
|
||||
groupTree.Add(GroupManager.CreateGroupTree2(currentGroup[0], CurrentHotelID));
|
||||
}
|
||||
}
|
||||
|
||||
return Json(groupTree, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
#region 加载控件数据
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadDataForGroupComboTree()
|
||||
{
|
||||
SysUsers currentUser = SysUserManager.Get(User.Identity.Name);
|
||||
if (currentUser.Group == null)
|
||||
{
|
||||
return Json(null, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
IList<object> groupTree = new List<object>();
|
||||
//如果该用户所在分组同属于当前酒店,则获取该分组下客房,否则获取该酒店下所有客房
|
||||
if (currentUser.Group.HotelID == CurrentHotelID)
|
||||
{
|
||||
groupTree.Add(GroupManager.CreateGroupTree2(currentUser.Group, CurrentHotelID));
|
||||
}
|
||||
else
|
||||
{
|
||||
IList<Group> currentGroup = GroupManager.GetGroupList(CurrentHotelID);
|
||||
groupTree.Add(GroupManager.CreateGroupTree2(currentGroup[0], CurrentHotelID));
|
||||
}
|
||||
|
||||
return Json(groupTree, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public ActionResult Save(string jsonData)
|
||||
{
|
||||
try
|
||||
{
|
||||
Group entity = Newtonsoft.Json.JsonConvert.DeserializeObject<Group>(jsonData);
|
||||
entity.HotelID = CurrentHotelID;
|
||||
if (entity.ID == 0)
|
||||
{
|
||||
GroupManager.Save(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
GroupManager.Update(entity);
|
||||
}
|
||||
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Edit"), entity.Name);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SaveFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public ActionResult Delete(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Delete"), GroupManager.Get(id).Name);
|
||||
|
||||
GroupManager.Delete(id);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
|
||||
}
|
||||
catch (ApplicationException ex)
|
||||
{
|
||||
return Json(new { IsSuccess = true, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// 构造楼层树,用于 easyui-treegrid
|
||||
/// </summary>
|
||||
/// <param name="groups"></param>
|
||||
/// <param name="parent"></param>
|
||||
/// <returns></returns>
|
||||
private IList<object> BuildGroupTree(IList<Group> groups, Group parent)
|
||||
{
|
||||
IList<object> groupTree = new List<object>();
|
||||
|
||||
IList<Group> subGroups = groups.Where(r => r.Parent == parent).OrderBy(o => o.Sort).ToList();
|
||||
|
||||
foreach (Group group in subGroups)
|
||||
{
|
||||
IList<object> children = BuildGroupTree(groups, group);
|
||||
|
||||
if (children.Count != 0)
|
||||
{
|
||||
groupTree.Add(new { ID = group.ID, Name = group.Name, Sort = group.Sort, children = children });
|
||||
}
|
||||
else
|
||||
{
|
||||
groupTree.Add(new { ID = group.ID, Name = group.Name, Sort = group.Sort});
|
||||
}
|
||||
}
|
||||
|
||||
return groupTree;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造当前用户所属楼层树
|
||||
/// </summary>
|
||||
/// <param name="groups"></param>
|
||||
/// <param name="group"></param>
|
||||
/// <returns></returns>
|
||||
private object BuildCurrentUserGroupTree(IList<Group> groups, Group group)
|
||||
{
|
||||
IList<Group> subGroups = groups.Where(r => r.Parent == group).OrderBy(o => o.Sort).ToList();
|
||||
|
||||
if (subGroups.Count == 0)
|
||||
{
|
||||
return new { id = group.ID, text = group.Name, iconCls = "tree-node-no-icon" };
|
||||
}
|
||||
|
||||
IList<object> children = new List<object>();
|
||||
|
||||
foreach (Group subGroup in subGroups)
|
||||
{
|
||||
children.Add(BuildCurrentUserGroupTree(groups, subGroup));
|
||||
}
|
||||
|
||||
return new { id = group.ID, text = group.Name, iconCls = "tree-node-no-icon", children = children };
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
590
WebSite/Controllers/HomeController.cs
Normal file
590
WebSite/Controllers/HomeController.cs
Normal file
@@ -0,0 +1,590 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Security;
|
||||
using Domain;
|
||||
using Service;
|
||||
using WebSite.Models;
|
||||
using System.Web.Caching;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
[HandleError]
|
||||
public class HomeController : BaseController
|
||||
{
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(HomeController));
|
||||
|
||||
private const int AuthorityID = 1001;
|
||||
|
||||
public ISysUserManager SysUserManager { get; set; }
|
||||
public ISysAuthorityManager SysAuthorityManager { get; set; }
|
||||
public IHostManager HostManager { get; set; }
|
||||
public IGroupManager GroupManager { get; set; }
|
||||
public ISysActiveUserManager SysActiveUserManager { get; set; }
|
||||
public ISysSettingManager SysSettingManager { get; set; }
|
||||
public ISysRoleManager SysRoleManager { get; set; }
|
||||
public ISysHotelManager SysHotelManager { get; set; }
|
||||
public ISysHotelGroupManager SysHotelGroupManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Index()
|
||||
{
|
||||
//ViewData["Account"] = User.Identity.Name;
|
||||
return View("SimonIndex");
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult MenuIndex()
|
||||
{
|
||||
//ViewData["Account"] = User.Identity.Name;
|
||||
return View("SimonIndex");
|
||||
}
|
||||
|
||||
private static IList<Menu> GetSubMenu(IList<SysAuthority> roleAuthority, int parentID)
|
||||
{
|
||||
IList<Menu> subMenu = new List<Menu>();
|
||||
IList<SysAuthority> Authories = roleAuthority.Where(r => r.ParentID == parentID).ToList();
|
||||
for (int i = 0; i < Authories.Count; i++)
|
||||
{
|
||||
subMenu.Add(new Menu
|
||||
{
|
||||
Name = Authories[i].Name,
|
||||
Url = HttpUtility.UrlEncode(Authories[i].Url),
|
||||
Icon = Authories[i].Icon
|
||||
});
|
||||
}
|
||||
return subMenu;
|
||||
}
|
||||
|
||||
private void ResultMenu()
|
||||
{
|
||||
IList<SysAuthority> roleAuthority = new List<SysAuthority>();
|
||||
SysUsers user = SysUserManager.LoadAll().FirstOrDefault(r => r.Account == this.User.Identity.Name);
|
||||
if (this.User.Identity.Name != "admin" && user.Role.Name != "超级管理员")
|
||||
{
|
||||
roleAuthority = SysRoleManager.GetAuthorities(user.Role);
|
||||
}
|
||||
else
|
||||
{
|
||||
roleAuthority = SysAuthorityManager.LoadAll().Where(r => r.ParentID != 0 && r.IsMenu && r.ActiveIndicator).OrderBy(o => o.Sort).ToList();
|
||||
}
|
||||
//客房管理
|
||||
ViewData["RoomManager"] = GetSubMenu(roleAuthority, 1);
|
||||
//参数设置
|
||||
ViewData["Setting"] = GetSubMenu(roleAuthority, 2);
|
||||
//设备管理
|
||||
ViewData["DeviceManager"] = GetSubMenu(roleAuthority, 3);
|
||||
//查询统计
|
||||
ViewData["QueryStatistics"] = GetSubMenu(roleAuthority, 4);
|
||||
//系统管理
|
||||
ViewData["SysMaintenance"] = GetSubMenu(roleAuthority, 5);
|
||||
}
|
||||
|
||||
public ActionResult MenuMain()
|
||||
{
|
||||
ViewData["Account"] = this.User.Identity.Name;
|
||||
ResultMenu();
|
||||
return View("MenuMain");
|
||||
}
|
||||
/// <summary>
|
||||
///选中语言触发事件引用方法
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult ChangeLanguage(string language)
|
||||
{
|
||||
switch (language.ToLower())
|
||||
{
|
||||
case "en":
|
||||
Session["isCN"] = 1;
|
||||
break;
|
||||
case "zh-tw":
|
||||
Session["isCN"] = 2;
|
||||
break;
|
||||
default:
|
||||
Session["isCN"] = 0;
|
||||
break;
|
||||
}
|
||||
return Redirect("/");//Request.UrlReferrer.ToString());
|
||||
}
|
||||
|
||||
public ActionResult LogOn()
|
||||
{
|
||||
string result = "";
|
||||
if (!Common.MyDes.Validate(ref result))
|
||||
{
|
||||
ViewData["Msg"] = result;
|
||||
return View("License");
|
||||
}
|
||||
if (Request.Cookies["Account"] != null)
|
||||
{
|
||||
ViewData["Account"] = HttpUtility.UrlDecode(Request.Cookies["Account"].Value);
|
||||
ViewData["RememberMe"] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewData["Account"] = "";
|
||||
ViewData["RememberMe"] = false;
|
||||
}
|
||||
ViewData["Language"] = Language;
|
||||
return View("SimonLogOn");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult ActiveUsersView()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
/// <summary>
|
||||
/// 在线用户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public ActionResult ActiveUsers()
|
||||
{
|
||||
var activeUsers = GetActiveUsers();
|
||||
var footer = new List<object>();
|
||||
footer.Add(new { Account = "在线人数", LoginIP = activeUsers.Count });
|
||||
footer.Add(new { Account = "用户总数", LoginIP = SysUserManager.GetCount() });
|
||||
return Json(new { total = activeUsers.Count, rows = activeUsers, footer = footer }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
public ActionResult LogOut()
|
||||
{
|
||||
Session.Clear();
|
||||
//var activeUsers = GetActiveUsers();
|
||||
//var activeUser = activeUsers.FirstOrDefault(r => r.ID == Session.SessionID);
|
||||
//if (activeUser != null)
|
||||
//{
|
||||
// activeUsers.Remove(activeUser);
|
||||
//}
|
||||
FormsAuthentication.SignOut();
|
||||
return Redirect("/LogOn/");
|
||||
}
|
||||
|
||||
public ActionResult LogOnByAndPassword(string account, string password, string code, bool rememberMe)
|
||||
{
|
||||
if (this.Session["ValidateCode"] == null || code != this.Session["ValidateCode"].ToString())
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("VerificationCodeErrorPleaseReEenter") });
|
||||
}
|
||||
var entity = SysUserManager.Get(account, password);
|
||||
if (entity == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("UsernameOrPasswordWrong") });
|
||||
}
|
||||
if (!entity.ActiveIndicator)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("YourAccountHasBeenDisabledPleaseContactTheAdministrator") });
|
||||
}
|
||||
if (account.ToLower() != "admin")
|
||||
{
|
||||
if (entity.Hotels.Count == 0)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("UserNotSetHotel") });
|
||||
}
|
||||
if (DateTime.Now > entity.Hotels[0].ValidateDate)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("CurrentHotelExpire") });
|
||||
}
|
||||
}
|
||||
entity.LoginIP = GetClientIP();
|
||||
SysUserManager.Update(entity);
|
||||
|
||||
if (rememberMe)
|
||||
{
|
||||
HttpCookie accountCookie = new HttpCookie("Account");
|
||||
accountCookie.Value = HttpUtility.UrlEncode(entity.Account);
|
||||
accountCookie.Expires = DateTime.Now.AddYears(1);
|
||||
Response.Cookies.Add(accountCookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
Response.Cookies["Account"].Value = "";
|
||||
}
|
||||
Session["CurrentHotelID"] = 0;
|
||||
FormsAuthentication.SetAuthCookie(entity.Account, false);//保存当前用户
|
||||
|
||||
Session["Account"] = entity.Account;
|
||||
//var activeUsers = GetActiveUsers();
|
||||
//if (activeUsers.FirstOrDefault(r => r.ID == Session.SessionID) == null)
|
||||
//{
|
||||
// activeUsers.Add(new ActiveUserModel { ID = Session.SessionID, Account = entity.Account, LoginIP = entity.LoginIP });
|
||||
//}
|
||||
//SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Login"), account);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("LoginSuccessful") });
|
||||
}
|
||||
|
||||
//public ActionResult LoginInfo()
|
||||
//{
|
||||
// SysUsers user = SysUserManager.Get(User.Identity.Name);
|
||||
// if (null == user || user.Hotels.Count == 0)
|
||||
// {
|
||||
// return LogOut();
|
||||
// }
|
||||
// if (User.Identity.Name.ToLower() == "admin")
|
||||
// {
|
||||
// user.Hotels = SysHotelManager.LoadAll();
|
||||
// }
|
||||
// var curHotel = user.Hotels[0].Code + "-" + ReturnNameByLanguage(user.Hotels[0].Name, user.Hotels[0].EName, user.Hotels[0].TWName);//SysHotelGroupManager.BuildGroupName(user.Hotels[0].SysHotelGroup) +
|
||||
// foreach (SysHotel hotel in user.Hotels)
|
||||
// {
|
||||
// if (hotel.ID == CurrentHotelID)
|
||||
// {
|
||||
// curHotel = hotel.Code + "-" + ReturnNameByLanguage(hotel.Name, hotel.EName, hotel.TWName);//SysHotelGroupManager.BuildGroupName(hotel.SysHotelGroup) +
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// return Json(new { IsSuccess = true, User = new { Account = user.Account, Hotel = curHotel } }, JsonRequestBehavior.AllowGet);//Role = user.Role.Name,
|
||||
//}
|
||||
/// <summary>
|
||||
/// 获取有权限菜单和酒店
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadMenu()
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<SysAuthority> authorities = new List<SysAuthority>();//用户所拥有权限
|
||||
SysHotel hotel = new SysHotel();
|
||||
switch (User.Identity.Name.ToLower())
|
||||
{
|
||||
case "admin":
|
||||
case "leo":
|
||||
case "blw":
|
||||
authorities = SysAuthorityManager.LoadAll().Where(r => r.IsMenu && r.ActiveIndicator).ToList();
|
||||
hotel = SysHotelManager.LoadAll().OrderBy(o => o.Sort).FirstOrDefault();
|
||||
break;
|
||||
default:
|
||||
SysUsers user = this.SysUserManager.Get(User.Identity.Name);
|
||||
hotel = user.Hotels.OrderBy(o => o.Sort).FirstOrDefault();
|
||||
IList<SysAuthority> firstMenus = SysAuthorityManager.LoadAll().Where(r => r.ParentID == 1000).ToList();//获取后台一级菜单
|
||||
foreach (var authority in user.Role.Authorities)
|
||||
{
|
||||
if (!authorities.Contains(authority))
|
||||
{
|
||||
authorities.Add(authority);
|
||||
var firstMenu = firstMenus.Where(r => r.ID == authority.ParentID).FirstOrDefault();//判断其上级菜单是否存在,如果不存在,则添加进来
|
||||
if (firstMenu != null)// && !authorities.Contains(firstMenu) && !user.Role.Authorities.Contains(firstMenu))
|
||||
{
|
||||
bool isExit = false;
|
||||
foreach (var exitAuthority in authorities)
|
||||
{
|
||||
if (exitAuthority.ID == firstMenu.ID)
|
||||
{
|
||||
isExit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isExit)
|
||||
{
|
||||
authorities.Add(firstMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
IList<object> menuTree = BuildMenu(authorities, 1000);//获取后台菜单权限
|
||||
if (CurrentHotelID == 0)
|
||||
{
|
||||
CurrentHotelID = hotel.ID;//缓存当前酒店ID
|
||||
CurrentHotelCode = hotel.Code;
|
||||
CurrentHotelName = hotel.Code + "-" + ReturnNameByLanguage(hotel.Name, hotel.EName, hotel.TWName);
|
||||
CurrentLogoPath = hotel.LogoPath;
|
||||
CurrentHotelIsExpire = DateTime.Now.AddMonths(1) > hotel.ValidateDate ? true : false;
|
||||
}
|
||||
return Json(new { MenuData = menuTree, HotelName = CurrentHotelName, LogoPath = CurrentLogoPath, IsExpire = CurrentHotelIsExpire });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex.ToString());
|
||||
return Json(ex.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 缓存当前酒店ID
|
||||
/// </summary>
|
||||
/// <param name="hotelID"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult GetCurrentHotel(string query, int? groupId)
|
||||
{
|
||||
string key = "GetCurrentHotel_" + query + "_" + groupId.ToString();
|
||||
object data = HttpContext.Cache.Get(key);
|
||||
if (data != null)
|
||||
{
|
||||
return Json(new { total = 3000, rows = data }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
else
|
||||
{
|
||||
IList<SysHotel> hotels = new List<SysHotel>();
|
||||
switch (User.Identity.Name.ToLower())
|
||||
{
|
||||
case "admin":
|
||||
case "leo":
|
||||
case "blw":
|
||||
hotels = SysHotelManager.LoadAll().Where(r => !r.IsDeleted).ToList();
|
||||
break;
|
||||
default:
|
||||
hotels = SysHotelManager.LoadAll().Where(r => r.IsApprove && !r.IsDeleted).ToList();//装载已审核的酒店
|
||||
break;
|
||||
}
|
||||
if (groupId.HasValue && groupId != 1)//过滤分组
|
||||
{
|
||||
hotels = hotels.Where(r => r.SysHotelGroup.ID == groupId ||
|
||||
(r.SysHotelGroup.Parent != null && r.SysHotelGroup.Parent.ID == groupId) ||
|
||||
(r.SysHotelGroup.Parent != null && r.SysHotelGroup.Parent.Parent != null && r.SysHotelGroup.Parent.Parent.ID == groupId)).ToList();
|
||||
}
|
||||
if (!string.IsNullOrEmpty(query))
|
||||
{
|
||||
hotels = hotels.Where(r => r.Code.Contains(query) || r.Name.Contains(query)).ToList();
|
||||
}
|
||||
hotels = hotels.OrderByDescending(o => o.ID).ThenBy(o => o.SysHotelGroup.Sort).ToList();
|
||||
var hotelData = hotels.Select(r => new
|
||||
{
|
||||
r.ID,
|
||||
r.Code,
|
||||
GroupName = SysHotelGroupManager.BuildGroupName(r.SysHotelGroup),
|
||||
Name = ReturnNameByLanguage(r.Name, r.EName, r.TWName)
|
||||
}).ToList();
|
||||
|
||||
HttpContext.Cache.Add(key, hotelData, null, DateTime.Now.AddMinutes(10), Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
|
||||
return Json(new { total = hotels.Count, rows = hotelData }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 缓存当前酒店ID
|
||||
/// </summary>
|
||||
/// <param name="hotelID"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult SetCurrentHotel(int hotelID)
|
||||
{
|
||||
CurrentHotelID = hotelID;//缓存当前酒店ID
|
||||
var curHotel = SysHotelManager.Get(hotelID);
|
||||
CurrentHotelName = curHotel.Code + "-" + ReturnNameByLanguage(curHotel.Name, curHotel.EName, curHotel.TWName);
|
||||
CurrentLogoPath = curHotel.LogoPath;
|
||||
CurrentHotelIsExpire = DateTime.Now.AddMonths(1) > curHotel.ValidateDate ? true : false;
|
||||
return Json(new { IsSuccess = true }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult ChangedPassword(string password, string oldPassword)
|
||||
{
|
||||
SysUsers userEntity = this.SysUserManager.Get(this.User.Identity.Name, oldPassword);
|
||||
if (userEntity == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("OldPasswordIsIncorrectPleaseReEnter") }, "text/x-json", JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
this.SysUserManager.Update(userEntity, password);
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("ChangePassword"), userEntity.Account);
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("PasswordChangeSuccessful") }, "text/x-json", JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
public ActionResult ValidateCode()
|
||||
{
|
||||
var code = Common.Tools.CreateValidateNumber(4);
|
||||
this.Session["ValidateCode"] = code;
|
||||
return File(Common.Tools.CreateValidateGraphic(code), "image/jpeg");
|
||||
}
|
||||
|
||||
public ActionResult GetMachineCode()
|
||||
{
|
||||
var code = Common.Tools.GetMachineCode();
|
||||
return Json(new { IsSuccess = true, Message = code });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入授权文件
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ActionResult UploadLicense()
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;
|
||||
|
||||
if (hfc.Count < 1 || hfc[0].ContentLength <= 0 || String.IsNullOrEmpty(hfc[0].FileName))
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("PleaseSelectAuthorizationFile") });
|
||||
}
|
||||
|
||||
string file = Common.MyDes.GetLicensePath();
|
||||
string path = Path.GetDirectoryName(file);
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
hfc[0].SaveAs(file);
|
||||
|
||||
string result = "";
|
||||
if (!Common.MyDes.ImportValidate(hfc[0].InputStream, ref result))
|
||||
{
|
||||
System.IO.File.Delete(file);
|
||||
return Json(new { IsSuccess = false, Message = result });
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (logger.IsErrorEnabled)
|
||||
{
|
||||
logger.Error(ex);
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult ProductInfo()
|
||||
{
|
||||
string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
version = version.Substring(0, version.LastIndexOf("."));
|
||||
Common.License license = Common.MyDes.GetLicense();
|
||||
SysHotel hotel = SysHotelManager.Get(CurrentHotelID);
|
||||
|
||||
string expires = hotel.ValidateDate.ToString("yyyy.MM.dd"); //license.EndDate.ToString("yyyy.MM.dd");
|
||||
if (hotel.ValidateDate >= new DateTime(2037, 12, 31))//license.EndDate
|
||||
{
|
||||
expires = HttpContext.InnerLanguage("UnlimitedDuration");
|
||||
}
|
||||
else if (DateTime.Now.AddMonths(1) > hotel.ValidateDate)
|
||||
{
|
||||
expires = string.Format("<font style='color:red'>{0}</font>", expires);
|
||||
}
|
||||
var result = new
|
||||
{
|
||||
Version = version,
|
||||
SerialNumber = license.SN,
|
||||
Limit = license.Limit,
|
||||
Expires = expires,
|
||||
CurrentHotel = ReturnNameByLanguage(hotel.Name, hotel.EName, hotel.TWName)
|
||||
};
|
||||
return Json(new { IsSuccess = true, Data = result });
|
||||
}
|
||||
|
||||
public ActionResult SaveSystemConfig(string jsonData)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sysConfig = Newtonsoft.Json.JsonConvert.DeserializeObject<SystemConfigModel>(jsonData);
|
||||
|
||||
var sysSetting = SysSettingManager.Get("MessageIP");
|
||||
if (sysSetting != null)
|
||||
{
|
||||
sysSetting.Value = sysConfig.MessageIP;
|
||||
SysSettingManager.Update(sysSetting);
|
||||
}
|
||||
|
||||
sysSetting = SysSettingManager.Get("MessagePort");
|
||||
if (sysSetting != null)
|
||||
{
|
||||
sysSetting.Value = sysConfig.MessagePort.ToString();
|
||||
SysSettingManager.Update(sysSetting);
|
||||
}
|
||||
|
||||
|
||||
return Json(new { IsSuccess = true, Message = "保存成功。" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// 构造菜单用于easyui-tree
|
||||
/// </summary>
|
||||
/// <param name="role"></param>
|
||||
/// <param name="parentId"></param>
|
||||
/// <returns></returns>
|
||||
private IList<object> BuildMenuForEasyUITree(IList<SysAuthority> authorities, int parentId)
|
||||
{
|
||||
IList<object> menuTree = new List<object>();
|
||||
IList<SysAuthority> subAuthorities = authorities.Where(r => r.ParentID == parentId).OrderBy(o => o.Sort).ToList();
|
||||
foreach (SysAuthority authority in subAuthorities)
|
||||
{
|
||||
IList<object> children = BuildMenuForEasyUITree(authorities, authority.ID);
|
||||
if (authority.ActiveIndicator && authority.IsMenu)
|
||||
{
|
||||
if (children.Count != 0)
|
||||
{
|
||||
menuTree.Add(new { text = authority.Name, iconCls = authority.Icon, url = authority.Url, children = children });
|
||||
}
|
||||
else
|
||||
{
|
||||
menuTree.Add(new { text = authority.Name, iconCls = authority.Icon, url = authority.Url });
|
||||
}
|
||||
}
|
||||
}
|
||||
return menuTree;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造菜单
|
||||
/// </summary>
|
||||
/// <param name="role"></param>
|
||||
/// <param name="parentId"></param>
|
||||
/// <returns></returns>
|
||||
private IList<object> BuildMenu(IList<SysAuthority> authorities, int parentId)
|
||||
{
|
||||
IList<object> menuTree = new List<object>();
|
||||
IList<SysAuthority> subAuthorities = authorities.Where(r => r.ParentID == parentId).OrderBy(o => o.Sort).ToList();
|
||||
foreach (SysAuthority authority in subAuthorities)
|
||||
{
|
||||
IList<object> children = BuildMenu(authorities, authority.ID);
|
||||
if (authority.ActiveIndicator && authority.IsMenu)
|
||||
{
|
||||
if (children.Count != 0)
|
||||
{
|
||||
menuTree.Add(new { Name = ReturnNameByLanguage(authority.Name, authority.EName, authority.TWName), Icon = authority.Icon, Url = authority.Url, Items = children });
|
||||
}
|
||||
else
|
||||
{
|
||||
menuTree.Add(new { Name = ReturnNameByLanguage(authority.Name, authority.EName, authority.TWName), Icon = authority.Icon, Url = authority.Url });
|
||||
}
|
||||
}
|
||||
}
|
||||
return menuTree;
|
||||
}
|
||||
|
||||
private IList<ActiveUserModel> GetActiveUsers()
|
||||
{
|
||||
var activeUsers = HttpContext.Application["ActiveUsers"] as List<ActiveUserModel>;
|
||||
if (activeUsers == null)
|
||||
{
|
||||
activeUsers = new List<ActiveUserModel>();
|
||||
HttpContext.Application.Lock();
|
||||
HttpContext.Application["ActiveUsers"] = activeUsers;
|
||||
HttpContext.Application.UnLock();
|
||||
}
|
||||
return activeUsers;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
/// <summary>
|
||||
/// 菜单类
|
||||
/// </summary>
|
||||
public class Menu
|
||||
{
|
||||
public string Url { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Icon { get; set; }
|
||||
}
|
||||
}
|
||||
176
WebSite/Controllers/HostAirController.cs
Normal file
176
WebSite/Controllers/HostAirController.cs
Normal file
@@ -0,0 +1,176 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Common;
|
||||
using Domain;
|
||||
using Service;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class HostAirController : BaseController
|
||||
{
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(HostAirController));
|
||||
|
||||
public IHostAirManager HostAirManager { get; set; }
|
||||
|
||||
public IHostManager HostManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadHostAirs(int hostID)
|
||||
{
|
||||
var list = HostAirManager.LoadByHostID(hostID);
|
||||
|
||||
var result = list.Select(r => new {
|
||||
r.HostID,
|
||||
ModalTypeID = r.Modal.ModalType.ID,
|
||||
CustomerName = (Language == Language.CN ? r.Modal.CustomerName : r.Modal.EnglishName),
|
||||
r.No,
|
||||
r.OnOff,
|
||||
r.CurrentTemp,
|
||||
r.SettingTemp,
|
||||
r.Speed,
|
||||
r.KeepTemp,
|
||||
r.InitTemp,
|
||||
r.HightTemp,
|
||||
r.LowerTemp,
|
||||
r.DeadTemp,
|
||||
r.HotDevition,
|
||||
r.ColdDevition,
|
||||
r.WelcomeTime,
|
||||
r.IsLockTemp,
|
||||
r.LockTemp,
|
||||
r.Mode,
|
||||
Valve = HttpContext.InnerLanguage(r.Valve.ToString()),
|
||||
r.ControlType,
|
||||
ControlTypeName = HttpContext.InnerLanguage(r.ControlType.ToString() + "Control"),
|
||||
r.CompensatoryTemp,
|
||||
r.RelateRoomStatus,
|
||||
r.RelateDoorContact,
|
||||
r.ColdHotMode,
|
||||
r.ColdHotSwitchDelayTime,
|
||||
r.FanStop,
|
||||
r.DisableFanHighSpeed,
|
||||
r.SleepFlag,
|
||||
r.SleepStartTime,
|
||||
r.SleepEndTime,
|
||||
r.SleepDevition,
|
||||
r.TimeFlag,
|
||||
r.TimeStartTime1,
|
||||
r.TimeEndTime1,
|
||||
r.TimeStartTime2,
|
||||
r.TimeEndTime2,
|
||||
r.TimeStartTime3,
|
||||
r.TimeEndTime3
|
||||
});
|
||||
|
||||
return Json(result, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Save(string jsonData)
|
||||
{
|
||||
try
|
||||
{
|
||||
IDictionary<string, string> data = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonData);
|
||||
if (data == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("PleaseChooseAirConditioning"));
|
||||
}
|
||||
|
||||
if (!data.ContainsKey("HostID"))
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidRoom"));
|
||||
}
|
||||
|
||||
var host = HostManager.Get(Convert.ToInt32(data["HostID"]));
|
||||
if (host == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidRoom"));
|
||||
}
|
||||
|
||||
if (!host.Status)
|
||||
{
|
||||
string message = String.Format(HttpContext.InnerLanguage("SendFailedHostOffline"), host.RoomNumber);
|
||||
return Json(new { IsSuccess = false, Message = message });
|
||||
}
|
||||
|
||||
if (host.RoomCard != null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("ThisRoomIsInTheCardAndCanNotSetAirConditioningInformation"));
|
||||
}
|
||||
|
||||
int modalTypeId = 0;
|
||||
if (!data.ContainsKey("ModalTypeID") || !int.TryParse(data["ModalTypeID"], out modalTypeId))
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidAirConditioning"));
|
||||
}
|
||||
|
||||
var hostAir = HostAirManager.GetByModalTypeID(host.ID, modalTypeId);
|
||||
if (hostAir == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidAirConditioning"));
|
||||
}
|
||||
|
||||
hostAir.SettingTemp = Convert.ToInt32(data["SettingTemp"]);
|
||||
hostAir.CompensatoryTemp = Convert.ToSingle(data["CompensatoryTemp"]);
|
||||
hostAir.Speed = Convert.ToInt32(data["Speed"]);
|
||||
hostAir.Mode = Convert.ToInt32(data["Mode"]);
|
||||
hostAir.IsLockTemp = Convert.ToBoolean(data["IsLockTemp"]);
|
||||
hostAir.LockTemp = Convert.ToInt32(data["LockTemp"]);
|
||||
|
||||
hostAir.KeepTemp = Convert.ToInt32(data["KeepTemp"]);
|
||||
hostAir.InitTemp = Convert.ToInt32(data["InitTemp"]);
|
||||
hostAir.HightTemp = Convert.ToInt32(data["HightTemp"]);
|
||||
hostAir.LowerTemp = Convert.ToInt32(data["LowerTemp"]);
|
||||
hostAir.ColdHotSwitchDelayTime = Convert.ToInt32(data["ColdHotSwitchDelayTime"]);
|
||||
hostAir.ColdHotMode = Convert.ToInt32(data["ColdHotMode"]);
|
||||
hostAir.DeadTemp = Convert.ToInt32(data["DeadTemp"]);
|
||||
hostAir.HotDevition = Convert.ToInt32(data["HotDevition"]);
|
||||
hostAir.ColdDevition = Convert.ToInt32(data["ColdDevition"]);
|
||||
hostAir.WelcomeTime = Convert.ToInt32(data["WelcomeTime"]);
|
||||
hostAir.RelateRoomStatus = Convert.ToBoolean(data["RelateRoomStatus"]);
|
||||
hostAir.RelateDoorContact = Convert.ToBoolean(data["RelateDoorContact"]);
|
||||
hostAir.FanStop = Convert.ToBoolean(data["FanStop"]);
|
||||
hostAir.DisableFanHighSpeed = Convert.ToBoolean(data["DisableFanHighSpeed"]);
|
||||
|
||||
hostAir.SleepFlag = false;
|
||||
hostAir.SleepStartTime = "00:00";
|
||||
hostAir.SleepEndTime = "00:00";
|
||||
hostAir.SleepDevition = 0;
|
||||
|
||||
hostAir.TimeFlag = false;
|
||||
hostAir.TimeStartTime1 = "00:00";
|
||||
hostAir.TimeEndTime1 = "00:00";
|
||||
hostAir.TimeStartTime2 = "00:00";
|
||||
hostAir.TimeEndTime2 = "00:00";
|
||||
hostAir.TimeStartTime3 = "00:00";
|
||||
hostAir.TimeEndTime3 = "00:00";
|
||||
|
||||
HostAirManager.Update(hostAir);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SentSuccessfully") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (logger.IsErrorEnabled)
|
||||
{
|
||||
logger.Error(HttpContext.InnerLanguage("SendAirconditioningSettingsFailed"), ex);
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SendFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
1872
WebSite/Controllers/HostController.cs
Normal file
1872
WebSite/Controllers/HostController.cs
Normal file
File diff suppressed because it is too large
Load Diff
153
WebSite/Controllers/HostModalController.cs
Normal file
153
WebSite/Controllers/HostModalController.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
using CommonEntity;
|
||||
using Common;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class HostModalController : BaseController
|
||||
{
|
||||
public IHostManager HostManager { get; set; }
|
||||
public IHostModalManager HostModalManager { get; set; }
|
||||
public IRoomTypeModalManager RoomTypeModalManager { get; set; }
|
||||
public IRoomTypeChannelsManager RoomTypeChannelsManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(HostModalController));
|
||||
/// <summary>
|
||||
/// 加载回路
|
||||
/// </summary>
|
||||
/// <param name="hostID"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadHostModals(int hostID)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = HostManager.Get(hostID);
|
||||
var list1 = HostModalManager.LoadByHostID(hostID);
|
||||
if (list1.ToList().Count == 0)//如果没有回路,则根据所属房型,新建回路
|
||||
{
|
||||
if (UpdateHostModals(host))
|
||||
{
|
||||
list1 = HostModalManager.LoadByHostID(hostID);
|
||||
}
|
||||
}
|
||||
var list = list1.Where(r => r.Modal.ActiveIndicator).OrderBy(r => r.Modal.ModalAddress);//只装置标志启动的
|
||||
var channelList = RoomTypeChannelsManager.LoadAll(host.RoomType.ID);//获取该主机电视频道
|
||||
string strChannels = Newtonsoft.Json.JsonConvert.SerializeObject(channelList.Select(r => new { Code = r.Code, Name = r.Name }));
|
||||
//var result = list.Select(r => new
|
||||
//{
|
||||
// HostID = r.HostID,
|
||||
// ModalID = r.Modal.ID,
|
||||
// r.Modal.Outlet,
|
||||
// Name = ReturnNameByLanguage(r.Modal.Name, r.Modal.EnglishName, r.Modal.TWName),//(Language == Domain.Language.CN ? r.Modal.Name : r.Modal.EnglishName),
|
||||
// r.Modal.ModalAddress,
|
||||
// Type = r.Modal.Type.ToString(),
|
||||
// TypeName = HttpContext.InnerLanguage(r.Modal.Type.ToString()),
|
||||
// Status = r.Status,
|
||||
// r.Brightness,
|
||||
// r.CurrentTemp,
|
||||
// r.SettingTemp,
|
||||
// r.FanSpeed,
|
||||
// r.Mode,
|
||||
// r.Valve,
|
||||
// Channels = strChannels
|
||||
// //+ (r.Status == 1 ?
|
||||
// //Convert.ToInt32((DateTime.Now - HostModalRecordManager.GetLastHostModalRecord(r.HostID, r.Modal.ID).StartTime).TotalMinutes) : 0)//如果当前灯光处于开的状态,计算截止到当前开的时长
|
||||
//});
|
||||
var result = list.Select(r => new ResultData()
|
||||
{
|
||||
HostID = r.HostID,
|
||||
ModalID = r.Modal.ID,
|
||||
Outlet= r.Modal.Outlet,
|
||||
Name = ReturnNameByLanguage(r.Modal.Name, r.Modal.EnglishName, r.Modal.TWName),//(Language == Domain.Language.CN ? r.Modal.Name : r.Modal.EnglishName),
|
||||
ModalAddress= r.Modal.ModalAddress,
|
||||
Type = r.Modal.Type.ToString(),
|
||||
TypeName = HttpContext.InnerLanguage(r.Modal.Type.ToString()),
|
||||
Status = r.Status,
|
||||
Brightness= r.Brightness,
|
||||
CurrentTemp= r.CurrentTemp,
|
||||
SettingTemp= r.SettingTemp,
|
||||
FanSpeed= r.FanSpeed,
|
||||
Mode= r.Mode,
|
||||
Valve= r.Valve,
|
||||
Channels = strChannels
|
||||
}).ToList();
|
||||
|
||||
|
||||
|
||||
foreach (var item in result)
|
||||
{
|
||||
string KKey = CacheKey.HostModalStatus_Prefix + "_" + item.HostID + "_" + item.ModalAddress;
|
||||
var hostModal = CSRedisCacheHelper.Get_Partition<HostModal_Cache>(KKey);
|
||||
if (hostModal != null)
|
||||
{
|
||||
item.Status = hostModal.Status;
|
||||
item.Brightness = hostModal.Brightness;
|
||||
var aaa = hostModal.AirConditionData;
|
||||
item.CurrentTemp = aaa.CurrentTemp;
|
||||
item.SettingTemp = aaa.SettingTemp;
|
||||
item.FanSpeed = aaa.FanSpeed;
|
||||
item.Mode = aaa.Mode;
|
||||
item.Valve = aaa.Valve;
|
||||
}
|
||||
}
|
||||
return Json(new { total = result.Count(), rows = result });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("LoadDataFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
private bool UpdateHostModals(Host host)
|
||||
{
|
||||
if (host == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
HostModalManager.DeteleByHostID(host.ID);
|
||||
var list = RoomTypeModalManager.LoadAll().Where(r => r.RoomType == host.RoomType);
|
||||
DateTime now = DateTime.Now;
|
||||
foreach (var modal in list)
|
||||
{
|
||||
HostModalManager.Save(new HostModal { HostID = host.ID, Modal = modal, Status = 2, Time = 0, UpdateTime = now });
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
public class ResultData
|
||||
{
|
||||
public int HostID { get; set; }
|
||||
public int ModalID;
|
||||
public string Outlet;
|
||||
public string Name; //(Language == Domain.Language.CN ? r.Modal.Name : r.Modal.EnglishName),
|
||||
public string ModalAddress;
|
||||
public string Type;
|
||||
public string TypeName;
|
||||
public int Status;
|
||||
public int Brightness;
|
||||
public int CurrentTemp;
|
||||
public int SettingTemp;
|
||||
public int FanSpeed;
|
||||
public int Mode;
|
||||
public int Valve;
|
||||
public string Channels;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
54
WebSite/Controllers/HostModalRecordController.cs
Normal file
54
WebSite/Controllers/HostModalRecordController.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Service;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class HostModalRecordController : BaseController
|
||||
{
|
||||
public IHostModalRecordManager HostModalRecordManager { get; set; }
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult LoadRoomNumbers()
|
||||
{
|
||||
IList<object> result = new List<object>();
|
||||
|
||||
IList<string> roomNumbers = HostModalRecordManager.LoadRoomNumbers(CurrentHotelID);
|
||||
|
||||
foreach (string roomNumber in roomNumbers)
|
||||
{
|
||||
result.Add(new { Value = roomNumber, Name = roomNumber });
|
||||
}
|
||||
|
||||
return Json(result, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
public ActionResult LoadModals(string roomNumber)
|
||||
{
|
||||
var table = HostModalRecordManager.LoadModals(roomNumber, CurrentHotelID);
|
||||
var list = new List<object>();
|
||||
foreach (DataRow row in table.Rows)
|
||||
{
|
||||
list.Add(new
|
||||
{
|
||||
RoomType = row["RoomType"],
|
||||
ModalAddress = row["ModalAddress"],
|
||||
Outlet = row["Outlet"],
|
||||
Name = ReturnNameByLanguage(row["Name"].ToString(), row["EnglishName"].ToString(), row["TWName"].ToString())// (Language == Language.CN) ? row["Name"] : row["EnglishName"]
|
||||
});
|
||||
}
|
||||
return Json(new { total = list.Count, rows = list });
|
||||
}
|
||||
}
|
||||
}
|
||||
219
WebSite/Controllers/HostRoomCardController.cs
Normal file
219
WebSite/Controllers/HostRoomCardController.cs
Normal file
@@ -0,0 +1,219 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Service;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class HostRoomCardController : BaseController
|
||||
{
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(HostRoomCardController));
|
||||
|
||||
private const int AUTHORITY_HostRoomCard = 1004;
|
||||
|
||||
public IHostRoomCardManager HostRoomCardManager { get; set; }
|
||||
|
||||
public IRoomCardManager RoomCardManager { get; set; }
|
||||
|
||||
public IRoomCardTypeManager RoomCardTypeManager { get; set; }
|
||||
|
||||
public ISysUserManager SysUserManager { get; set; }
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
ViewData["EnableDelData"] = SysUserManager.HasAuthority(User.Identity.Name, AUTHORITY_HostRoomCard);
|
||||
#if SIMON
|
||||
return View("SimonIndex");
|
||||
#else
|
||||
return View();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载刷卡记录数据
|
||||
/// </summary>
|
||||
/// <param name="roomNumber"></param>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="cardNumber"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="rows"></param>
|
||||
/// <param name="order"></param>
|
||||
/// <param name="sort"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult LoadAllByPage(int page, int rows, string order, string sort, string roomNumber = "", string cardTypeID = "", string cardNumber = "", string startDate = "", string endDate = "")
|
||||
{
|
||||
long total = 0;
|
||||
|
||||
var lists = HostRoomCardManager.LoadAllByPage(out total, page, rows, order, sort, CurrentHotelID, roomNumber,
|
||||
Convert.ToInt16(cardTypeID), cardNumber, "", Convert.ToDateTime(startDate), Convert.ToDateTime(endDate));
|
||||
|
||||
var result = lists.Select(r => new
|
||||
{
|
||||
r.ID,
|
||||
r.RoomNumber,
|
||||
CardType = ReturnNameByLanguage(r.CardType.Name, r.CardType.EName, r.CardType.TWName),
|
||||
r.CardNumber,
|
||||
r.UserNumber,
|
||||
r.UserName,
|
||||
InCardTime = Convert.ToDateTime(r.InCardTime).ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
OutCardTime = Convert.ToDateTime(r.OutCardTime).ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
r.Duration
|
||||
|
||||
}).ToList<object>();
|
||||
|
||||
//var table = HostRoomCardManager.LoadHostRoomCard(out total, page, rows, order, sort, CurrentHotelID, CardType, RoomNumber, UserName, CardNumber, StartDate, EndDate);
|
||||
//IList<object> services = new List<object>();
|
||||
//if (lists != null)
|
||||
//{
|
||||
// foreach (System.Data.DataRow row in table.Rows)
|
||||
// {
|
||||
// services.Add(new
|
||||
// {
|
||||
// ID = row[0],
|
||||
// RoomNumber = row[1],
|
||||
// CardNumber = row[2],
|
||||
// CardType = ReturnNameByLanguage(row[3].ToString(), row[4].ToString(), row[5].ToString()),
|
||||
// UserNumber = row[6],
|
||||
// UserName = row[7],
|
||||
// InCardTime = Convert.ToDateTime(row[8]).ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
// OutCardTime = Convert.ToDateTime(row[9]).ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
// Duration = row[10]
|
||||
// });
|
||||
// }
|
||||
//}
|
||||
return Json(new { total = total, rows = result }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除多条数据
|
||||
/// </summary>
|
||||
/// <param name="idList"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult Delete(IList<long> idList)
|
||||
{
|
||||
HostRoomCardManager.Delete(idList.Cast<object>().ToList());
|
||||
SaveSystemLog(AUTHORITY_HostRoomCard, HttpContext.InnerLanguage("Delete"), "【" + String.Join(",", CurrentHotelID) + "】");
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult DeleteAll()
|
||||
{
|
||||
HostRoomCardManager.DeleteAll(CurrentHotelID);
|
||||
SaveSystemLog(AUTHORITY_HostRoomCard, HttpContext.InnerLanguage("Delete"), "【" + String.Join(",", CurrentHotelID) + "】");
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("EmptySuccess") });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///导出刷卡记录信息
|
||||
/// </summary>
|
||||
/// <param name="roomNumber"></param>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult Export(string roomNumber, string userName)
|
||||
{
|
||||
var list = HostRoomCardManager.LoadAll(CurrentHotelID, roomNumber, userName);
|
||||
|
||||
NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
|
||||
|
||||
NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
|
||||
|
||||
sheet1.SetColumnWidth(0, 10 * 256);
|
||||
sheet1.SetColumnWidth(1, 10 * 256);
|
||||
sheet1.SetColumnWidth(2, 10 * 256);
|
||||
sheet1.SetColumnWidth(3, 10 * 256);
|
||||
sheet1.SetColumnWidth(4, 10 * 256);
|
||||
sheet1.SetColumnWidth(5, 20 * 256);
|
||||
sheet1.SetColumnWidth(6, 20 * 256);
|
||||
sheet1.SetColumnWidth(7, 10 * 256);
|
||||
|
||||
NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
|
||||
row1.CreateCell(0).SetCellValue(HttpContext.InnerLanguage("RoomNumber"));
|
||||
row1.CreateCell(1).SetCellValue(HttpContext.InnerLanguage("CardNumber"));
|
||||
row1.CreateCell(2).SetCellValue(HttpContext.InnerLanguage("CardType"));
|
||||
row1.CreateCell(3).SetCellValue(HttpContext.InnerLanguage("UserNumber"));
|
||||
row1.CreateCell(4).SetCellValue(HttpContext.InnerLanguage("UserName"));
|
||||
row1.CreateCell(5).SetCellValue(HttpContext.InnerLanguage("InCardTime"));
|
||||
row1.CreateCell(6).SetCellValue(HttpContext.InnerLanguage("OutCardTime"));
|
||||
row1.CreateCell(7).SetCellValue(HttpContext.InnerLanguage("DurationMinute"));
|
||||
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
NPOI.SS.UserModel.IRow row = sheet1.CreateRow(i + 1);
|
||||
row.CreateCell(0).SetCellValue(list[i].RoomNumber);
|
||||
row.CreateCell(1).SetCellValue(list[i].CardNumber);
|
||||
row.CreateCell(2).SetCellValue(list[i].CardType != null ? list[i].CardType.Name : "");
|
||||
row.CreateCell(3).SetCellValue(list[i].UserNumber);
|
||||
row.CreateCell(4).SetCellValue(list[i].UserName);
|
||||
row.CreateCell(5).SetCellValue(list[i].InCardTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
row.CreateCell(6).SetCellValue(list[i].OutCardTime.HasValue ? list[i].OutCardTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : "");
|
||||
row.CreateCell(7).SetCellValue(list[i].Duration);
|
||||
}
|
||||
|
||||
using (MemoryStream stream = new MemoryStream())
|
||||
{
|
||||
book.Write(stream);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return File(stream, "application/vnd.ms-excel", "刷卡记录.xls");
|
||||
}
|
||||
}
|
||||
|
||||
#region 加载控件数据
|
||||
/// <summary>
|
||||
/// 房卡类型
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadDataForCardTypeCombobox()
|
||||
{
|
||||
var cardType = RoomCardTypeManager.LoadAll();
|
||||
var result = cardType.Select(r => new { r.ID, CardType = ReturnNameByLanguage(r.Name,r.EName,r.TWName) }).ToList<object>();
|
||||
result.Insert(0, new { ID = -1, CardType = HttpContext.InnerLanguage("Choice") });
|
||||
return Json(result);
|
||||
}
|
||||
/// <summary>
|
||||
/// 房卡编号
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadDataForCardNumberCombobox()
|
||||
{
|
||||
var cardNumber = RoomCardManager.LoadAll().Where(r => r.HotelID == CurrentHotelID && r.RoomCardType != null).ToList();
|
||||
var result = cardNumber.Select(r => new
|
||||
{
|
||||
r.ID,
|
||||
CardNumber = r.CardNumber,
|
||||
Name = r.CardNumber + "(" + ReturnNameByLanguage(r.RoomCardType.Name, r.RoomCardType.EName, r.RoomCardType.TWName) + "|" + r.UserName + ")"
|
||||
}).ToList<object>();
|
||||
|
||||
result.Insert(0, new { ID = 0, CardNumber = "", Name = HttpContext.InnerLanguage("CheckAll") });
|
||||
|
||||
return Json(result);
|
||||
}
|
||||
/// <summary>
|
||||
/// 员工姓名
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadDataForUserNameCombobox()
|
||||
{
|
||||
var userName = RoomCardManager.LoadAll().Where(r => r.HotelID == CurrentHotelID).ToList();
|
||||
var result = userName.Select(r => new { r.ID, UserName = r.UserName }).ToList<object>();
|
||||
result.Insert(0, new { ID = 0, UserName = HttpContext.InnerLanguage("CheckAll") });
|
||||
return Json(result);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
569
WebSite/Controllers/HostUpdateController.cs
Normal file
569
WebSite/Controllers/HostUpdateController.cs
Normal file
@@ -0,0 +1,569 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Service;
|
||||
using Common;
|
||||
using System.Xml;
|
||||
using Newtonsoft.Json;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class HostUpdateController : BaseController
|
||||
{
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(HostUpdateController));
|
||||
private static string get_update_url = System.Configuration.ConfigurationManager.AppSettings["get_update_url"];
|
||||
private const int AUTHORITY_Host = 30;
|
||||
public IHostUpdateManager HostUpdateManager { get; set; }
|
||||
public IHostUpdateStatusManager HostUpdateStatusManager { get; set; }
|
||||
public IHostManager HostManager { get; set; }
|
||||
public ISysUserManager SysUserManager { get; set; }
|
||||
public IGroupManager GroupManager { get; set; }
|
||||
public ISysHotelManager SysHotelManager { get; set; }
|
||||
public IRoomTypeManager RoomTypeManager { get; set; }
|
||||
public IHostRCUManager HostRCUManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAllByPage(int page, int rows, string order, string sort)
|
||||
{
|
||||
long total = 0;
|
||||
var list = this.HostUpdateManager.LoadAllByPage(out total, page, rows, order, sort, CurrentHotelID);
|
||||
|
||||
IList<HostUpdate> lists = new List<HostUpdate>();
|
||||
foreach (HostUpdate h in list)
|
||||
{
|
||||
if (h.FileType == FileType.Config && h.Href.LastIndexOf(".xml") > 0)
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
string filePath = Tools.GetApplicationPath() + h.Href;
|
||||
try
|
||||
{
|
||||
doc.Load(filePath);
|
||||
XmlElement proNode = doc.DocumentElement;
|
||||
XmlNodeList proGANodes = proNode.GetElementsByTagName("ProjectGroupAddr");
|
||||
foreach (XmlNode node in proGANodes)
|
||||
{
|
||||
if (node.Attributes["Level"].Value == "2")
|
||||
{
|
||||
HostUpdate item = new HostUpdate();
|
||||
item.ID = h.ID;
|
||||
item.FileName = h.FileName.Substring(0, h.FileName.Length - 4) + "_" + node.Attributes["Version"].Value + "_" + node.Attributes["Name"].Value + ".cfg";
|
||||
item.FileType = h.FileType;
|
||||
item.Size = h.Size;
|
||||
item.UploadTime = h.UploadTime;
|
||||
item.Account = h.Account;
|
||||
item.Href = h.Href;
|
||||
item.HotelID = Convert.ToInt16(node.Attributes["ID"].Value);
|
||||
lists.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(string.Format("解释xml文件({0})失败:{1}", filePath, ex.ToString()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lists.Add(h);
|
||||
}
|
||||
}
|
||||
|
||||
var result = new { total = lists.Count, rows = lists };
|
||||
|
||||
return Json(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上传升级包
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult Upload(HttpPostedFileBase file, FileType fileType)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (file == null || file.ContentLength <= 0)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("PleaseSelectTheUpgradePackageFile"));
|
||||
}
|
||||
string ext = System.IO.Path.GetExtension(file.FileName).ToLower();
|
||||
if (fileType == FileType.Firmware && ext != ".bin")
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("UploadErrorTheFirmwareFileMustFormat"));
|
||||
}
|
||||
else if (fileType == FileType.Config)
|
||||
{
|
||||
if (ext != ".xml" && ext != ".dat")
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("UploadErrorTheConfigurationFileMustFormat"));
|
||||
}
|
||||
}
|
||||
//else if (fileType == FileType.ConfigPrj && ext != ".prj")
|
||||
//{
|
||||
// throw new ApplicationException(HttpContext.InnerLanguage("UploadErrorTheConfigurationFileMustFormat"));
|
||||
//}
|
||||
else if (fileType == FileType.RCUValidate && ext != ".lic")
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("UploadErrorTheRCUFileMustFormat"));
|
||||
}
|
||||
|
||||
var sysHotel = SysHotelManager.Get(CurrentHotelID);
|
||||
HostUpdate entity = new HostUpdate
|
||||
{
|
||||
ID = 0,
|
||||
FileType = fileType,
|
||||
FileName = file.FileName,
|
||||
Md5 = Tools.ComputeFileHash(file.InputStream),
|
||||
Size = file.ContentLength,
|
||||
Href = "Uploads/" + sysHotel.Code + "/" + file.FileName,
|
||||
UploadTime = DateTime.Now,
|
||||
Account = this.User.Identity.Name,
|
||||
HotelID = CurrentHotelID
|
||||
};
|
||||
string filePath = Server.MapPath("~/Uploads/" + sysHotel.Code + "/");
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
filePath += file.FileName;
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("TheUpgradePackageHasBeenUploadedPleaseReSelect"));
|
||||
}
|
||||
HostUpdateManager.Save(entity);
|
||||
file.SaveAs(filePath);
|
||||
SaveSystemLog(AUTHORITY_Host, HttpContext.InnerLanguage("UploadUpgradeFile"), "【" + entity.FileName + "】");
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("UploadSuccessful") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveSystemLog(AUTHORITY_Host, HttpContext.InnerLanguage("UploadUpgradeFile"), ex.Message, false);
|
||||
return Json(new { IsSuccess = false, Message = HttpUtility.HtmlEncode(ex.Message) });
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Delete(IList<int> idList)
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<string> updateList = new List<string>();
|
||||
foreach (int id in idList)
|
||||
{
|
||||
HostUpdate hostUpdate = HostUpdateManager.Get(id);
|
||||
if (hostUpdate != null)
|
||||
{
|
||||
string file = Server.MapPath("~/" + hostUpdate.Href);
|
||||
if (System.IO.File.Exists(file))
|
||||
{
|
||||
System.IO.File.Delete(file);
|
||||
}
|
||||
updateList.Add(hostUpdate.FileName);
|
||||
}
|
||||
}
|
||||
HostUpdateManager.Delete(idList.Cast<object>().ToList());
|
||||
SaveSystemLog(AUTHORITY_Host, HttpContext.InnerLanguage("DeleteUpgradeFile"), "【" + String.Join(",", updateList.ToArray()) + "】");
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveSystemLog(AUTHORITY_Host, HttpContext.InnerLanguage("DeleteUpgradeFile"), ex.Message, false);
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("DeleteFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 升级主机(C主机):获取升级文件内容,保存到本地
|
||||
/// </summary>
|
||||
/// <param name="hostIDs"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult GetUpdatedFile(int roomTypeID)
|
||||
{
|
||||
if (string.IsNullOrEmpty(get_update_url))
|
||||
{
|
||||
throw new ApplicationException("未配置获取升级包的服务器地址!");
|
||||
}
|
||||
try
|
||||
{
|
||||
List<string> fileNames = GetUpdateFileByRoomTypeID(roomTypeID);
|
||||
return Json(new { IsSuccess = true, Data = fileNames });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error("获取文件失败", ex);
|
||||
return Json(new { IsSuccess = false, Message = "获取文件失败:" + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static List<string> GetUpdateFileNameByRoomTypeID(int roomTypeID)
|
||||
{
|
||||
//List<string> fileNames = new List<string>();
|
||||
ConcurrentBag<string> fileNames = new ConcurrentBag<string>();
|
||||
CountdownEvent count = new CountdownEvent(2);
|
||||
for (int j = 1; j < 3; j++)//1:固件升级bin或hex,2:配置升级dat
|
||||
{
|
||||
Task.Factory.StartNew((state) =>
|
||||
{
|
||||
int i = (int)state;
|
||||
string type = (i == 1 ? "固件" : "配置");
|
||||
string url = string.Format(get_update_url + "?RoomTypeid={0}&DataType={1}", roomTypeID, i);
|
||||
string result = HttpWebRequestHelper.PostWebRequest(url, "");
|
||||
Domain.HostUpdateApi apiResult = JsonConvert.DeserializeObject<Domain.HostUpdateApi>(result);
|
||||
string modelName = "";
|
||||
if (apiResult == null || string.IsNullOrEmpty(apiResult.ModelName))
|
||||
{
|
||||
modelName = "无";
|
||||
}
|
||||
else
|
||||
{
|
||||
modelName = apiResult.ModelName;
|
||||
}
|
||||
if (apiResult != null)
|
||||
{
|
||||
if (apiResult.Status)
|
||||
{
|
||||
foreach (HostUpdateApiDataList item in apiResult.datalist)
|
||||
{
|
||||
string fileName = item.Filename;//文件名
|
||||
fileNames.Add(string.Format("{0}:{1} || {2} || {3}", type, modelName, (string.IsNullOrEmpty(item.LuncherVer) ? "无" : item.LuncherVer), fileName));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fileNames.Add(type + ":" + apiResult.ErrMsg);
|
||||
}
|
||||
}
|
||||
count.Signal();
|
||||
}, j);
|
||||
}
|
||||
count.Wait();
|
||||
return fileNames.ToList<string>();
|
||||
}
|
||||
public static List<string> GetUpdateFileByRoomTypeID(int roomTypeID)
|
||||
{
|
||||
List<string> fileNames = new List<string>();
|
||||
for (int i = 1; i < 3; i++)//1:固件升级bin或hex,2:配置升级dat
|
||||
{
|
||||
string type = (i == 1 ? "固件" : "配置");
|
||||
string url = string.Format(get_update_url + "?RoomTypeid={0}&DataType={1}", roomTypeID, i);
|
||||
string result = HttpWebRequestHelper.PostWebRequest(url, "");
|
||||
Domain.HostUpdateApi apiResult = JsonConvert.DeserializeObject<Domain.HostUpdateApi>(result);
|
||||
string modelName = "";
|
||||
if (apiResult == null || string.IsNullOrEmpty(apiResult.ModelName))
|
||||
{
|
||||
modelName = "无";
|
||||
}
|
||||
else
|
||||
{
|
||||
modelName = apiResult.ModelName;
|
||||
}
|
||||
//string modelName = (string.IsNullOrEmpty(apiResult.ModelName) ? "无" : apiResult.ModelName);
|
||||
if (apiResult != null)
|
||||
{
|
||||
if (apiResult.Status)
|
||||
{
|
||||
foreach (HostUpdateApiDataList item in apiResult.datalist)
|
||||
{
|
||||
string fileName = item.Filename;//文件名
|
||||
byte[] bytes = Convert.FromBase64String(item.data);//升级数据base64
|
||||
string fileHref = "Uploads/room_type/" + roomTypeID + "/" + fileName;
|
||||
string filePath = Tools.GetApplicationPath() + "Uploads/room_type/" + roomTypeID + "/";
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
filePath += fileName;
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
System.IO.File.Delete(filePath);
|
||||
}
|
||||
using (FileStream fs = new FileStream(filePath, System.IO.FileMode.Create, System.IO.FileAccess.Write))//写入文件到指定位置
|
||||
{
|
||||
fs.Write(bytes, 0, bytes.Length);
|
||||
fs.Flush();
|
||||
}
|
||||
fileNames.Add(string.Format("{0}:{1} || {2} || {3}", type, modelName, (string.IsNullOrEmpty(item.LuncherVer) ? "无" : item.LuncherVer), fileName));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fileNames.Add(type + ":" + apiResult.ErrMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
fileNames.Reverse();
|
||||
return fileNames;
|
||||
}
|
||||
/// <summary>
|
||||
/// 升级主机(C主机)
|
||||
/// </summary>
|
||||
/// <param name="idList">升级主机ID集合</param>
|
||||
/// <param name="fileName">升级文件名</param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult UpdateHostC(IList<int> idList, string fileName)
|
||||
{
|
||||
return this.ShengJI(idList, fileName);
|
||||
}
|
||||
public ActionResult ShengJI(IList<int> idList, string fileName)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
IList<Host> hosts = new List<Host>();
|
||||
foreach (int id in idList)
|
||||
{
|
||||
Host host = HostManager.Get(id);
|
||||
if (host != null)
|
||||
{
|
||||
hosts.Add(host);
|
||||
}
|
||||
}
|
||||
FileType fileType = FileType.Config;
|
||||
switch (fileName.Substring(fileName.Length - 3).ToLower())
|
||||
{
|
||||
case "bin":
|
||||
case "hex":
|
||||
fileType = FileType.Firmware;
|
||||
break;
|
||||
case "dat":
|
||||
fileType = FileType.Config;
|
||||
break;
|
||||
default:
|
||||
return Json(new { IsSuccess = false, Message = "升级文件不合法!" });
|
||||
}
|
||||
string fileHref = "Uploads/room_type/" + hosts[hosts.Count - 1].RoomType.ID + "/" + fileName;//升级文件相对路径
|
||||
string fileMd5 = "";
|
||||
using (Stream stream = System.IO.File.Open(Tools.GetApplicationPath() + fileHref, FileMode.Open))
|
||||
{
|
||||
fileMd5 = Tools.ComputeFileHash(stream);
|
||||
stream.Close();
|
||||
}
|
||||
//HostUpdate hostUpdate = HostUpdateManager.Get(fileMd5, CurrentHotelID);
|
||||
//if (null == hostUpdate)
|
||||
//{
|
||||
// hostUpdate = new HostUpdate();
|
||||
// hostUpdate.FileType = fileType;
|
||||
// hostUpdate.FileName = fileName;
|
||||
// hostUpdate.Href = fileHref;
|
||||
// hostUpdate.Md5 = fileMd5;
|
||||
// hostUpdate.Size = 0;
|
||||
// hostUpdate.UploadTime = DateTime.Now;
|
||||
// hostUpdate.Account = this.User.Identity.Name;
|
||||
// hostUpdate.HotelID = CurrentHotelID;
|
||||
// HostUpdateManager.Save(hostUpdate);
|
||||
//}
|
||||
HostManager.UpdateHostC(null, fileType, fileHref, fileMd5, hosts);
|
||||
IList<string> hostNumberList = new List<string>();
|
||||
foreach (Host h in hosts)
|
||||
{
|
||||
hostNumberList.Add(h.RoomNumber);
|
||||
}
|
||||
string logDetail = String.Format(HttpContext.InnerLanguage("UpdateHostLogDetailFormat"), String.Join(",", hostNumberList.ToArray()), fileHref);
|
||||
SaveSystemLog(AUTHORITY_Host, HttpContext.InnerLanguage("UpdateHost"), logDetail);
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("IsUpgrading") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(HttpContext.InnerLanguage("ReleaseUpgradeFails"), ex);
|
||||
SaveSystemLog(AUTHORITY_Host, HttpContext.InnerLanguage("UpdateHost"), ex.Message, false);
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("ReleaseUpgradeFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ActionResult ShengJI_NEW(IList<int> idList, string fileName, IHostManager HostManager1)
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<Host> hosts = new List<Host>();
|
||||
foreach (int id in idList)
|
||||
{
|
||||
Host host = HostManager1.Get(id);
|
||||
if (host != null)
|
||||
{
|
||||
hosts.Add(host);
|
||||
}
|
||||
}
|
||||
FileType fileType = FileType.Config;
|
||||
switch (fileName.Substring(fileName.Length - 3).ToLower())
|
||||
{
|
||||
case "bin":
|
||||
case "hex":
|
||||
fileType = FileType.Firmware;
|
||||
break;
|
||||
case "dat":
|
||||
fileType = FileType.Config;
|
||||
break;
|
||||
default:
|
||||
return Json(new { IsSuccess = false, Message = "升级文件不合法!" });
|
||||
}
|
||||
string fileHref = "Uploads/room_type/" + hosts[hosts.Count - 1].RoomType.ID + "/" + fileName;//升级文件相对路径
|
||||
string fileMd5 = "";
|
||||
using (Stream stream = System.IO.File.Open(Tools.GetApplicationPath() + fileHref, FileMode.Open))
|
||||
{
|
||||
fileMd5 = Tools.ComputeFileHash(stream);
|
||||
stream.Close();
|
||||
}
|
||||
HostManager1.UpdateHostC(null, fileType, fileHref, fileMd5, hosts);
|
||||
IList<string> hostNumberList = new List<string>();
|
||||
foreach (Host h in hosts)
|
||||
{
|
||||
hostNumberList.Add(h.RoomNumber);
|
||||
}
|
||||
return Json(new { IsSuccess = true, Message = "shengji" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex.Message);
|
||||
logger.Error(ex.StackTrace);
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 升级主机
|
||||
/// </summary>
|
||||
/// <param name="hostUpdateID"></param>
|
||||
/// <param name="groupIDs"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult UpdateHost(int hostUpdateID, int subGroupID, string hostIDs, bool isTFTP)
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<int> ids = Newtonsoft.Json.JsonConvert.DeserializeObject<IList<int>>(hostIDs);
|
||||
HostUpdate hostUpdate = HostUpdateManager.Get(hostUpdateID);
|
||||
if (hostUpdate == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("InvalidFirmwareOrConfigurationFiles") });
|
||||
}
|
||||
FileType fileType = hostUpdate.FileType;
|
||||
string fileHref = hostUpdate.Href;
|
||||
string fileMd5 = hostUpdate.Md5;
|
||||
//通过xml文件解释对应的子群cfg
|
||||
if (hostUpdate.FileType == FileType.Config && hostUpdate.Href.LastIndexOf(".xml") > 0)
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.Load(Tools.GetApplicationPath() + hostUpdate.Href);
|
||||
XmlElement proNode = doc.DocumentElement;
|
||||
XmlNodeList proGANodes = proNode.GetElementsByTagName("ProjectGroupAddr");
|
||||
foreach (XmlNode node in proGANodes)
|
||||
{
|
||||
if (Convert.ToInt16(node.Attributes["ID"].Value) == subGroupID)
|
||||
{
|
||||
List<List<byte>> sendDatas = ProtocalData.GetSubgroupSendData(node);
|
||||
fileHref = hostUpdate.Href.Substring(0, hostUpdate.Href.Length - 4) + "_" + node.Attributes["Version"].Value + "_" + node.Attributes["Name"].Value + ".cfg";
|
||||
string path = Tools.GetApplicationPath() + fileHref;
|
||||
int totalLength = 0;//计算配置文件总字节数,如果不是4的倍数,以0xFF补上
|
||||
using (System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create, System.IO.FileAccess.Write))
|
||||
{
|
||||
foreach (List<byte> sendData in sendDatas)
|
||||
{
|
||||
totalLength += sendData.ToArray().Length;
|
||||
fs.Write(sendData.ToArray(), 0, sendData.ToArray().Length);
|
||||
}
|
||||
totalLength = 4 - (totalLength % 4);
|
||||
for (int i = 0; i < totalLength; i++)
|
||||
{
|
||||
fs.Write((new byte[] { 0xFF }), 0, 1);
|
||||
}
|
||||
}
|
||||
using (Stream stream = System.IO.File.Open(path, FileMode.Open))
|
||||
{
|
||||
fileMd5 = Tools.ComputeFileHash(stream);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
IList<Host> hosts = new List<Host>();
|
||||
IList<string> hostNumberList = new List<string>();
|
||||
foreach (int id in ids)
|
||||
{
|
||||
Host host = HostManager.Get(id);
|
||||
if (host != null)
|
||||
{
|
||||
hosts.Add(host);
|
||||
hostNumberList.Add(host.RoomNumber);
|
||||
}
|
||||
}
|
||||
HostManager.UpdateHost(hostUpdate, fileType, fileHref, fileMd5, hosts, isTFTP);
|
||||
string logDetail = String.Format(HttpContext.InnerLanguage("UpdateHostLogDetailFormat"), String.Join(",", hostNumberList.ToArray()), fileHref);
|
||||
SaveSystemLog(AUTHORITY_Host, HttpContext.InnerLanguage("UpdateHost"), logDetail);
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("IsUpgrading") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(HttpContext.InnerLanguage("ReleaseUpgradeFails"), ex);
|
||||
SaveSystemLog(AUTHORITY_Host, HttpContext.InnerLanguage("UpdateHost"), ex.Message, false);
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("ReleaseUpgradeFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取升级状态
|
||||
/// </summary>
|
||||
/// <param name="hostUpdateID"></param>
|
||||
/// <param name="hostIDs"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult UpdateHostStatus(int hostUpdateID)
|
||||
{
|
||||
try
|
||||
{
|
||||
var statusList = HostUpdateStatusManager.LoadAll().Where(r => r.HostUpdate.ID == hostUpdateID).Select(r => new { id = r.ID, hostID = r.Host.ID, status = r.Status }).OrderBy(A => A.hostID);
|
||||
|
||||
return Json(new { IsSuccess = true, Data = statusList });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(HttpContext.InnerLanguage("ReleaseUpgradeFails"), ex);
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("ReleaseUpgradeFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadGroupTreeWithRoom(int? hostUpdateID)
|
||||
{
|
||||
IList<Host> updatedHosts = new List<Host>();
|
||||
if (hostUpdateID.HasValue)
|
||||
{
|
||||
HostUpdate hostUpdate = HostUpdateManager.Get(hostUpdateID);
|
||||
updatedHosts = HostUpdateStatusManager.LoadAllByHostUpdate(hostUpdate).Select(r => r.Host).Distinct().ToList();
|
||||
}
|
||||
var groupTree = GroupManager.CreateGroupTreeWithRoom(null, updatedHosts, CurrentHotelID);
|
||||
IList<object> result = new List<object>();
|
||||
result.Add(new { id = 0, text = HttpContext.InnerLanguage("RoomNumber"), iconCls = "tree-node-no-icon", children = groupTree, attributes = new { isHost = false, roomTypeID = 0 } });
|
||||
return Json(result, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadRoomType()
|
||||
{
|
||||
var roomTypeList = RoomTypeManager.LoadAll().Where(r => r.HotelID == CurrentHotelID);
|
||||
IList<object> list = new List<object>();
|
||||
foreach (RoomType rt in roomTypeList)
|
||||
{
|
||||
list.Add(new { id = rt.ID, text = rt.Name, iconCls = "tree-node-no-icon" });
|
||||
}
|
||||
IList<object> result = new List<object>();
|
||||
result.Add(new { id = 0, text = HttpContext.InnerLanguage("RoomType"), iconCls = "tree-node-no-icon", children = list });
|
||||
|
||||
return Json(result, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
43
WebSite/Controllers/HostWordsReportController.cs
Normal file
43
WebSite/Controllers/HostWordsReportController.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
using Common;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class HostWordsReportController : BaseController
|
||||
{
|
||||
//private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(HostWordsReportController));
|
||||
public IHostWordsReportManager HostWordsReportManager { get; set; }
|
||||
public IHostManager HostManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult LoadAllByPage(int page, int rows, string order, string sort, string roomNumber)
|
||||
{
|
||||
long total = 0;
|
||||
IList<Host> lstHosts = HostManager.LoadAll(CurrentHotelID);
|
||||
IList<HostWordsReport> list = HostWordsReportManager.LoadAllByPage(out total, page, rows, order, sort, CurrentHotelID);
|
||||
var rsult = list.Select(r => new
|
||||
{
|
||||
RoomNumber = lstHosts.Where(t => t.ID == r.HostID).FirstOrDefault().RoomNumber,
|
||||
ModalAddress = r.ModalAddress,
|
||||
Type = r.Type,
|
||||
Sentence = r.Sentence,
|
||||
CreatedDate = r.CreatedDate
|
||||
});
|
||||
return Json(new { total = total, rows = rsult });
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
7233
WebSite/Controllers/IoTController.cs
Normal file
7233
WebSite/Controllers/IoTController.cs
Normal file
File diff suppressed because it is too large
Load Diff
205
WebSite/Controllers/LightControlController.cs
Normal file
205
WebSite/Controllers/LightControlController.cs
Normal file
@@ -0,0 +1,205 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Service;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class LightControlController : BaseController
|
||||
{
|
||||
private const int AUTHORITY_LightControl = 13;
|
||||
|
||||
public ILightControlManager LightControlManager { get; set; }
|
||||
|
||||
public IHostManager HostManager { get; set; }
|
||||
|
||||
public IHostModalManager HostModalManager { get; set; }
|
||||
|
||||
public IGroupManager GroupManager { get; set; }
|
||||
|
||||
public IRoomStatusManager RoomStatusManager { get; set; }
|
||||
|
||||
public IRoomTypeManager RoomTypeManager { get; set; }
|
||||
|
||||
public IRoomTypeSceneManager RoomTypeSceneManager { get; set; }
|
||||
|
||||
#region Actions
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View("SimonIndex");
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult SendScene(string jsonScene, int? hostID, int? groupID, int? roomStatusID, int? roomTypeID, bool? takeInverse)
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<string> roomNumberList = new List<string>();
|
||||
var hostList = FindHosts(hostID, groupID, roomStatusID, roomTypeID);
|
||||
var sceneSetting = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSceneSetting>(jsonScene);
|
||||
if (sceneSetting == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("InvalidScene") });
|
||||
}
|
||||
var scene = RoomTypeSceneManager.Get(sceneSetting.SceneID);
|
||||
if (scene == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("InvalidScene") });
|
||||
}
|
||||
else if((bool)takeInverse && !scene.TakeInverse)//如果取反下发,但是该场景没设置容许取反,则提示不下发
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SceneNotTakeInverseIssue") });
|
||||
}
|
||||
|
||||
IList<string> offlineRoomNumberList = new List<string>();
|
||||
foreach (var host in hostList)
|
||||
{
|
||||
if (host != null)
|
||||
{
|
||||
if (host.Status)
|
||||
{
|
||||
LightControlManager.ApplyScene(host, scene,(bool)takeInverse);
|
||||
roomNumberList.Add(host.RoomNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
offlineRoomNumberList.Add(host.RoomNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string logDetail = "【" + String.Join(",", roomNumberList) + "】" + "【" + (Language == Language.CN ? scene.Name : scene.EnglishName) + "】";
|
||||
|
||||
SaveSystemLog(AUTHORITY_LightControl, HttpContext.InnerLanguage("SetRoomScene"), logDetail);
|
||||
|
||||
if (offlineRoomNumberList.Count > 0)
|
||||
{
|
||||
string message = String.Format(HttpContext.InnerLanguage("SendFailedHostOffline"), String.Join(",", offlineRoomNumberList.ToArray()));
|
||||
|
||||
return Json(new { IsSuccess = true, Message = message });
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("IssuedSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveSystemLog(AUTHORITY_LightControl, HttpContext.InnerLanguage("SetRoomScene"), ex.Message, false);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("IssuedFailedFecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置灯光状态
|
||||
/// </summary>
|
||||
/// <param name="hostId"></param>
|
||||
/// <param name="modalId"></param>
|
||||
/// <param name="onoff"></param>
|
||||
/// <param name="brightness"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult SetLight(int hostId, int modalId, int status, int brightness, int temperature, int fanSpeed, int mode, int valve)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = HostManager.Get(hostId);
|
||||
if (host == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidRoom"));
|
||||
}
|
||||
if (!Common.CSRedisCacheHelper.Contains(host.HostNumber, host.MAC))
|
||||
{
|
||||
string message = String.Format(HttpContext.InnerLanguage("SendFailedHostOffline"), host.RoomNumber);
|
||||
throw new ApplicationException(message);
|
||||
}
|
||||
HostModal hostModal = HostModalManager.Get(hostId, modalId);
|
||||
if (hostModal == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidLight"));
|
||||
}
|
||||
//if (status != 2 && status != 1)
|
||||
//{
|
||||
// throw new ApplicationException(HttpContext.InnerLanguage("InvalidState"));
|
||||
//}
|
||||
//if (brightness < 0 || brightness > 100)
|
||||
//{
|
||||
// throw new ApplicationException(HttpContext.InnerLanguage("InvalidBrightness"));
|
||||
//}
|
||||
HostModalManager.SetDevice(host, hostModal, status, brightness, temperature, fanSpeed, mode, valve);
|
||||
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
||||
sb.Append("控制客房(" + host.RoomNumber + ")设备(" + hostModal.Modal.Name + hostModal.Modal.ModalAddress + "):状态:" + HttpContext.InnerLanguage(status == 1 ? "On" : "Off"));
|
||||
if (hostModal.Brightness != brightness)
|
||||
{
|
||||
sb.Append(",亮度:" + brightness);
|
||||
}
|
||||
if (hostModal.SettingTemp != temperature)
|
||||
{
|
||||
sb.Append(",温度:" + temperature);
|
||||
}
|
||||
if (hostModal.FanSpeed != fanSpeed)
|
||||
{
|
||||
sb.Append(",风速:" + fanSpeed);
|
||||
}
|
||||
if (hostModal.Mode != mode)
|
||||
{
|
||||
sb.Append(",模式:" + mode);
|
||||
}
|
||||
if (hostModal.Valve != valve)
|
||||
{
|
||||
sb.Append(",阀门:" + valve);
|
||||
}
|
||||
SaveSystemLog(AUTHORITY_LightControl, HttpContext.InnerLanguage("DeviceControl"), sb.ToString());
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SettingSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveSystemLog(AUTHORITY_LightControl, HttpContext.InnerLanguage("SetRoomLight"), ex.Message, false);
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SetFailedbecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private IList<Host> FindHosts(int? hostID, int? groupID, int? roomStatusID, int? roomTypeID)
|
||||
{
|
||||
IList<Host> hosts = new List<Host>();
|
||||
|
||||
if (hostID.HasValue)
|
||||
{
|
||||
hosts.Add(HostManager.Get(hostID.GetValueOrDefault()));
|
||||
}
|
||||
else
|
||||
{
|
||||
IList<Group> groups = new List<Group>();
|
||||
if (groupID.HasValue)
|
||||
{
|
||||
groups = GroupManager.GetGroupList(GroupManager.Get(groupID));
|
||||
}
|
||||
|
||||
RoomStatus roomStatus = null;
|
||||
if (roomStatusID.HasValue)
|
||||
{
|
||||
roomStatus = RoomStatusManager.Get(roomStatusID);
|
||||
}
|
||||
|
||||
RoomType roomType = null;
|
||||
if (roomTypeID.HasValue)
|
||||
{
|
||||
roomType = RoomTypeManager.Get(roomTypeID);
|
||||
}
|
||||
|
||||
hosts = HostManager.LoadAll(groups, roomStatus, roomType);
|
||||
}
|
||||
|
||||
return hosts;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
21
WebSite/Controllers/MachineRegisterLogController.cs
Normal file
21
WebSite/Controllers/MachineRegisterLogController.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class MachineRegisterLogController : BaseController
|
||||
{
|
||||
//
|
||||
// GET: /MachineRegisterLog/
|
||||
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(MachineRegisterLogController));
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
93
WebSite/Controllers/ManualVisitController.cs
Normal file
93
WebSite/Controllers/ManualVisitController.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
using Common;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class ManualVisitController : BaseController
|
||||
{
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(ManualVisitController));
|
||||
public IManualVisitManager ManualVisitManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取验证码
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="companyName"></param>
|
||||
/// <param name="phoneNumber"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult GetValidateCode(string name, string companyName, string phoneNumber)
|
||||
{
|
||||
try
|
||||
{
|
||||
string validateCode = Tools.CreateValidateNumber(4);
|
||||
AliyunSMSHelper.SendVerifySMS(phoneNumber, validateCode);//发送短信验证码
|
||||
ManualVisit entity = new ManualVisit();
|
||||
entity.Name = name;
|
||||
entity.CompanyName = companyName;
|
||||
entity.PhoneNumber = phoneNumber;
|
||||
entity.ValidateCode = validateCode;
|
||||
entity.CreatedDate = DateTime.Now;
|
||||
ManualVisitManager.Save(entity);
|
||||
return Json(new { IsSuccess = true, Message = "验证码发送成功" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex.ToString());
|
||||
return Json(new { IsSuccess = false, Message = "验证码发送失败" });
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 验证验证码
|
||||
/// </summary>
|
||||
/// <param name="phoneNumber"></param>
|
||||
/// <param name="validateCode"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult GetManual(string phoneNumber, string validateCode)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool result = ManualVisitManager.ValidateCode(phoneNumber, validateCode);
|
||||
if (result)
|
||||
{
|
||||
return Json(new { IsSuccess = true, Message = "验证码验证成功", Target = "/uploads/boonlive.pdf" });
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = "验证码错误" });
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex.ToString());
|
||||
return Json(new { IsSuccess = false, Message = "验证码验证失败" });
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult List()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult LoadAllByPage(int page, int rows, string order, string sort, DateTime? startDate, DateTime? endDate)
|
||||
{
|
||||
long total = 0;
|
||||
var list = this.ManualVisitManager.LoadAllByPage(out total, page, rows, order, sort, startDate, endDate);
|
||||
|
||||
return Json(new { total = total, rows = list });
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
518
WebSite/Controllers/MobileAppController.cs
Normal file
518
WebSite/Controllers/MobileAppController.cs
Normal file
@@ -0,0 +1,518 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class MobileAppController : BaseController
|
||||
{
|
||||
private const int AUTHORITY_MobileApp = 33;
|
||||
|
||||
public IAppMenuManager AppMenuManager { get; set; }
|
||||
|
||||
public IAppHotelManager AppHotelManager { get; set; }
|
||||
|
||||
public IAlarmSettingManager AlarmSettingManager { get; set; }
|
||||
|
||||
public IRoomTypeModalManager RoomTypeModalManager { get; set; }
|
||||
|
||||
public IRoomTypeSceneManager RoomTypeSceneManager { get; set; }
|
||||
|
||||
public IAppRoomManager AppRoomManager { get; set; }
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
#if SIMON
|
||||
return View("SimonIndex");
|
||||
#else
|
||||
return View();
|
||||
#endif
|
||||
}
|
||||
|
||||
#region 菜单
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="type">0app,1微信</param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadMenus(int type)
|
||||
{
|
||||
var list = this.AppMenuManager.LoadAll(type, CurrentHotelID);
|
||||
return Json(new { total = list.Count, rows = list });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAppMenusByPage(int page, int rows, string order, string sort)
|
||||
{
|
||||
long total = 0;
|
||||
|
||||
var list = this.AppMenuManager.LoadAllByPage(out total, page, rows, order, sort).Where(r => r.Type == 0);
|
||||
|
||||
return Json(new { total = total, rows = list });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult SaveAppMenu(int id, string name, HttpPostedFileBase icon, int sort, bool activeIndicator)
|
||||
{
|
||||
try
|
||||
{
|
||||
var menu = AppMenuManager.Get(id);
|
||||
if (menu == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidMenu"));
|
||||
}
|
||||
|
||||
if (String.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("TheMenuNameCanNotBeEmpty"));
|
||||
}
|
||||
|
||||
if (icon != null)
|
||||
{
|
||||
if (icon.ContentLength == 0)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidMenuIcon"));
|
||||
}
|
||||
|
||||
if (icon.ContentType != "image/png" &&
|
||||
icon.ContentType != "image/jpeg" &&
|
||||
icon.ContentType != "image/gif")
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidFormatMenuIconMenuIconFormatCanOnlyBe") + "png、jpg/jpeg、gif。");
|
||||
}
|
||||
|
||||
string filePath = Server.MapPath("~/Uploads/AppIcons/");
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
string fileName = Path.GetFileName(icon.FileName);
|
||||
filePath += fileName;
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("IconFiles") + "【" + fileName + "】" + HttpContext.InnerLanguage("AlreadyExistsRenameAndThenUpload"));
|
||||
}
|
||||
icon.SaveAs(filePath);
|
||||
menu.Icon = "Uploads/AppIcons/" + fileName;
|
||||
}
|
||||
|
||||
menu.Name = name;
|
||||
menu.Sort = sort;
|
||||
menu.ActiveIndicator = activeIndicator;
|
||||
|
||||
AppMenuManager.Update(menu);
|
||||
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("EditMenu"), Language == Domain.Language.CN ? menu.Name : menu.EnglishName);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") }, "text/html");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("EditMenu"), ex.Message, false);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveFailedBecause") + ex.Message }, "text/html");
|
||||
}
|
||||
}
|
||||
[Authorize]
|
||||
public ActionResult SaveWXMenu(int id, bool activeIndicator)
|
||||
{
|
||||
try
|
||||
{
|
||||
var menu = AppMenuManager.Get(id);
|
||||
if (menu == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidMenu"));
|
||||
}
|
||||
|
||||
menu.ActiveIndicator = activeIndicator;
|
||||
|
||||
AppMenuManager.Update(menu);
|
||||
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("EditMenu"), Language == Domain.Language.CN ? menu.Name : menu.Name);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") }, "text/html");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("EditMenu"), ex.Message, false);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SaveFailedBecause") + ex.Message }, "text/html");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 酒店介绍
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAppHotel()
|
||||
{
|
||||
var result = new Dictionary<string, string>();
|
||||
foreach (var item in AppHotelManager.LoadAll())
|
||||
{
|
||||
result.Add(item.Code, item.Value);
|
||||
}
|
||||
|
||||
return Json(result, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult SaveAppHotel(string jsonData)
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = Newtonsoft.Json.JsonConvert.DeserializeObject<IDictionary<string, string>>(jsonData);
|
||||
|
||||
foreach (KeyValuePair<string, string> item in list)
|
||||
{
|
||||
var entity = AppHotelManager.Get(item.Key);
|
||||
if (entity != null)
|
||||
{
|
||||
entity.Value = item.Value;
|
||||
AppHotelManager.Update(entity);
|
||||
}
|
||||
}
|
||||
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("EditHotelIntroduce"), "");
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("EditHotelIntroduce"), ex.Message, false);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 服务
|
||||
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public ActionResult LoadServices()
|
||||
{
|
||||
var list = AlarmSettingManager.LoadAll('B').Where(r => r.HotelID == CurrentHotelID);
|
||||
|
||||
return Json(new { total = list.Count(), rows = list });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public ActionResult SaveService(char type, string code, bool appApply)
|
||||
{
|
||||
try
|
||||
{
|
||||
var serviceSetting = AlarmSettingManager.Get(CurrentHotelID, type, code);
|
||||
if (serviceSetting == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidService"));
|
||||
}
|
||||
|
||||
serviceSetting.AppApply = appApply;
|
||||
|
||||
AlarmSettingManager.Update(serviceSetting);
|
||||
|
||||
string logDetail = serviceSetting.AppApply ? HttpContext.InnerLanguage("Show") : HttpContext.InnerLanguage("Hide");
|
||||
|
||||
logDetail += "【" + (Language == Language.CN ? serviceSetting.Name : serviceSetting.EName) + "】";
|
||||
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("EditService"), logDetail);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SettingSuccess") });
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("EditService"), ex.Message, false);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SetFailedbecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 灯光
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadLightsByPage(int page, int rows, string order, string sort, int roomTypeId)
|
||||
{
|
||||
long total = 0;
|
||||
|
||||
var list = RoomTypeModalManager.LoadAllByPage(out total, page, rows, order, sort, roomTypeId);
|
||||
|
||||
var result = list.Select(r => new { r.ID, r.Outlet, r.Name, Type = HttpContext.InnerLanguage(r.Type.ToString()), r.AppApply, r.EnglishName });
|
||||
|
||||
return Json(new { total = total, rows = result });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public ActionResult SaveLight(int id, bool appApply)
|
||||
{
|
||||
try
|
||||
{
|
||||
var light = RoomTypeModalManager.Get(id);
|
||||
if (light == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidLight"));
|
||||
}
|
||||
|
||||
light.AppApply = appApply;
|
||||
|
||||
RoomTypeModalManager.Update(light);
|
||||
|
||||
string logDetail = light.AppApply ? HttpContext.InnerLanguage("Show") : HttpContext.InnerLanguage("Hide");
|
||||
|
||||
logDetail += "【" + light.RoomType.Name + "】";
|
||||
|
||||
logDetail += "【" + (Language == Language.CN ? light.Name : light.EnglishName) + "】";
|
||||
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("EditLight"), logDetail);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SettingSuccess") });
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("EditLight"), ex.Message, false);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SetFailedbecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 场景
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadScenesByPage(int page, int rows, string order, string sort, int roomTypeId)
|
||||
{
|
||||
long total = 0;
|
||||
|
||||
var list = RoomTypeSceneManager.LoadAllByPage(out total, page, rows, order, sort, CurrentHotelID, roomTypeId);
|
||||
|
||||
var result = list.Select(r => new { r.ID, r.Name, r.AppApply, r.EnglishName, r.Icon });
|
||||
|
||||
return Json(new { total = total, rows = result });
|
||||
}
|
||||
|
||||
public ActionResult SaveScene(int id, bool appApply)
|
||||
{
|
||||
try
|
||||
{
|
||||
var scene = RoomTypeSceneManager.Get(id);
|
||||
if (scene == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidScene"));
|
||||
}
|
||||
|
||||
scene.AppApply = appApply;
|
||||
|
||||
RoomTypeSceneManager.Update(scene);
|
||||
|
||||
string logDetail = scene.AppApply ? HttpContext.InnerLanguage("Show") : HttpContext.InnerLanguage("Hide");
|
||||
|
||||
logDetail += "【" + scene.RoomType.Name + "】";
|
||||
|
||||
logDetail += "【" + (Language == Language.CN ? scene.Name : scene.EnglishName) + "】";
|
||||
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("EditScene"), logDetail);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SettingSuccess") });
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("EditScene"), ex.Message, false);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SetFailedbecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ActionResult SaveEditScene(int id, string name, string engshilname, HttpPostedFileBase icon, bool appapply)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var scene = RoomTypeSceneManager.Get(id);
|
||||
|
||||
if (scene == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidScene"));
|
||||
}
|
||||
|
||||
if (icon != null)
|
||||
{
|
||||
if (icon.ContentLength == 0)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidSceneIcon"));
|
||||
}
|
||||
|
||||
if (icon.ContentType != "image/png" &&
|
||||
icon.ContentType != "image/jpeg" &&
|
||||
icon.ContentType != "image/gif")
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidSceneIconFormatSceneIconFormatCanOnlyBe") + "png、jpg/jpeg、gif。");
|
||||
}
|
||||
|
||||
string filePath = Server.MapPath("~/Uploads/AppIcons/");
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
string fileName = Path.GetFileName(icon.FileName);
|
||||
filePath += fileName;
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("IconFiles") + "【" + fileName + "】" + HttpContext.InnerLanguage("AlreadyExistsRenameAndThenUpload"));
|
||||
|
||||
}
|
||||
icon.SaveAs(filePath);
|
||||
scene.Icon = "Uploads/AppIcons/" + fileName;
|
||||
}
|
||||
|
||||
scene.AppApply = appapply;
|
||||
|
||||
RoomTypeSceneManager.Update(scene);
|
||||
|
||||
string logDetail = scene.AppApply ? HttpContext.InnerLanguage("Show") : HttpContext.InnerLanguage("Hide");
|
||||
|
||||
logDetail += "【" + scene.RoomType.Name + "】";
|
||||
|
||||
logDetail += "【" + (Language == Language.CN ? scene.Name : scene.EnglishName) + "】";
|
||||
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("EditScene"), logDetail);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SettingSuccess") }, "text/html");
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("EditScene"), ex.Message, false);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SetFailedbecause") + ex.Message }, "text/html");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PAD房号设置
|
||||
[Authorize]
|
||||
public ActionResult LoadAppRoomsByPage(int page, int rows, string order, string sort)
|
||||
{
|
||||
long total = 0;
|
||||
|
||||
var list = this.AppRoomManager.LoadAllByPage(out total, page, rows, order, sort);
|
||||
|
||||
return Json(new { total = total, rows = list });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult SaveAppRoom(int id, string mac, string roomNumber)
|
||||
{
|
||||
try
|
||||
{
|
||||
AppRoom existAppRoom = AppRoomManager.Get(id);
|
||||
AppRoom appRoom = null;
|
||||
|
||||
if (id == 0)
|
||||
{
|
||||
if (!AppRoomManager.isExistMac(mac))
|
||||
{
|
||||
//新增
|
||||
appRoom = new AppRoom();
|
||||
|
||||
appRoom.ID = id;
|
||||
appRoom.MAC = mac;
|
||||
appRoom.RoomNumber = roomNumber;
|
||||
|
||||
if (existAppRoom != null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = String.Format("【{0}】【{1}】" + HttpContext.InnerLanguage("PADRoomNumberSetupInformationAlreadyExists"), appRoom.MAC, appRoom.RoomNumber) });
|
||||
}
|
||||
|
||||
AppRoomManager.Save(appRoom);
|
||||
|
||||
string logDetail = HttpContext.InnerLanguage("New") + "【" + appRoom.MAC + "," + appRoom.RoomNumber + "】";
|
||||
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("PADRoomNumberSetting"), logDetail);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = String.Format("【{0}】" + HttpContext.InnerLanguage("AlreadyExist"), mac) });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//更新
|
||||
if (existAppRoom != null && existAppRoom.ID != id)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = String.Format("【{0}】【{1}】" + HttpContext.InnerLanguage("PADRoomNumberSetupInformationAlreadyExists"), appRoom.MAC, appRoom.RoomNumber) });
|
||||
}
|
||||
else
|
||||
{
|
||||
appRoom = existAppRoom;
|
||||
}
|
||||
|
||||
appRoom.MAC = mac;
|
||||
appRoom.RoomNumber = roomNumber;
|
||||
|
||||
AppRoomManager.Update(appRoom);
|
||||
|
||||
string logDetail = HttpContext.InnerLanguage("Edit") + "【" + appRoom.MAC + "," + appRoom.RoomNumber + "】";
|
||||
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("PADRoomNumberSetting"), logDetail);
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SaveFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult DeleteAppRoom(IList<int> idList)
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<string> appRoomList = new List<string>();
|
||||
|
||||
foreach (int id in idList)
|
||||
{
|
||||
var appRoom = AppRoomManager.Get(id);
|
||||
if (appRoom != null)
|
||||
{
|
||||
AppRoomManager.Delete(appRoom.ID);
|
||||
|
||||
appRoomList.Add("【" + appRoom.MAC + "," + appRoom.RoomNumber + "】");
|
||||
}
|
||||
}
|
||||
|
||||
string logDetail = HttpContext.InnerLanguage("Delete") + String.Join(",", appRoomList.ToArray());
|
||||
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("PADRoomNumberSetting"), logDetail);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveSystemLog(AUTHORITY_MobileApp, HttpContext.InnerLanguage("PADRoomNumberSetting"), ex.Message, false);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("DeleteFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
242
WebSite/Controllers/ModelController.cs
Normal file
242
WebSite/Controllers/ModelController.cs
Normal file
@@ -0,0 +1,242 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class ModelController : BaseController
|
||||
{
|
||||
private const int AuthorityID = 31;
|
||||
|
||||
public IModelManager ModelManager { get; set; }
|
||||
|
||||
public IHostManager HostManager { get; set; }
|
||||
|
||||
public IGroupManager GroupManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Index()
|
||||
{
|
||||
#if SIMON
|
||||
return View("SimonIndex");
|
||||
#else
|
||||
return View();
|
||||
#endif
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAllByPage(int page, int rows, string order, string sort)
|
||||
{
|
||||
long total = 0;
|
||||
var list = ModelManager.LoadAllByPage(out total, page, rows, order, sort);
|
||||
|
||||
IList<object> result = new List<object>();
|
||||
|
||||
foreach(var model in list)
|
||||
{
|
||||
result.Add(new
|
||||
{
|
||||
ID = model.ID,
|
||||
Name = model.Name,
|
||||
CorrectedTemp = model.CorrectedTemp,
|
||||
FanRunStatus = model.FanRunStatus,
|
||||
ExhaustFanStatus = model.ExhaustFanStatus,
|
||||
ExhausFanTime = model.ExhausFanTime,
|
||||
InfraredDelayPO = model.InfraredDelayPO,
|
||||
DoorDelayPO = model.DoorDelayPO,
|
||||
PullCardDelayPO = model.PullCardDelayPO,
|
||||
Remark = model.Remark,
|
||||
ModifiedDate = model.ModifiedDate,
|
||||
ApplyDate = model.ApplyDate,
|
||||
ApplyUser = model.ApplyUser
|
||||
});
|
||||
}
|
||||
|
||||
return Json(new { total = total, rows = result });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadModelDetail(int? modelId)
|
||||
{
|
||||
IList<object> details = new List<object>();
|
||||
|
||||
if (modelId.HasValue)
|
||||
{
|
||||
Model model = ModelManager.Get(modelId);
|
||||
if (model != null && model.Details != null)
|
||||
{
|
||||
foreach(ModelDetail detail in model.Details) {
|
||||
details.Add(new
|
||||
{
|
||||
ID = detail.ID,
|
||||
ModelStatus = detail.ModelStatus,
|
||||
OnOff = detail.OnOff,
|
||||
ModelType = detail.ModelType,
|
||||
Speed = detail.Speed,
|
||||
SummerTemp = detail.SummerTemp,
|
||||
WinterTemp = detail.WinterTemp,
|
||||
TimingControl = detail.TimingControl,
|
||||
Timer = detail.Timer,
|
||||
AllowElectric = detail.AllowElectric
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
details.Add(new { ID = 0, ModelStatus = "插卡时", OnOff = true });
|
||||
details.Add(new { ID = 0, ModelStatus = "拔卡时", OnOff = true });
|
||||
details.Add(new { ID = 0, ModelStatus = "待租时", OnOff = true });
|
||||
details.Add(new { ID = 0, ModelStatus = "停租时", OnOff = true });
|
||||
}
|
||||
|
||||
return Json(new { total = details.Count, rows = details });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Save(string jsonData)
|
||||
{
|
||||
try
|
||||
{
|
||||
Model entity = Newtonsoft.Json.JsonConvert.DeserializeObject<Model>(jsonData);
|
||||
|
||||
entity.ModifiedDate = DateTime.Now;
|
||||
entity.Remark = "";
|
||||
|
||||
Model existModel = ModelManager.GetByName(entity.Name);
|
||||
|
||||
if (entity.ID == 0)
|
||||
{
|
||||
if (existModel != null) {
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("ConfigurationName") + "【" + entity.Name + "】" + HttpContext.InnerLanguage("AlreadyExist"));
|
||||
}
|
||||
|
||||
if (entity.Details != null)
|
||||
{
|
||||
foreach (ModelDetail detail in entity.Details)
|
||||
{
|
||||
detail.Model = entity;
|
||||
}
|
||||
}
|
||||
|
||||
ModelManager.Save(entity);
|
||||
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("New"), entity.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existModel != null && existModel.ID != entity.ID)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("ConfigurationName") + "【" + entity.Name + "】"+ HttpContext.InnerLanguage("AlreadyExist"));
|
||||
}
|
||||
|
||||
var model = this.ModelManager.Get(entity.ID);
|
||||
|
||||
model.Name = entity.Name;
|
||||
model.CorrectedTemp = entity.CorrectedTemp;
|
||||
model.FanRunStatus = entity.FanRunStatus;
|
||||
model.ExhaustFanStatus = entity.ExhaustFanStatus;
|
||||
model.ExhausFanTime = entity.ExhausFanTime;
|
||||
model.InfraredDelayPO = entity.InfraredDelayPO;
|
||||
model.DoorDelayPO = entity.DoorDelayPO;
|
||||
model.PullCardDelayPO = entity.PullCardDelayPO;
|
||||
|
||||
CopyModelDetail(model.Details.FirstOrDefault(r => r.ModelStatus == "插卡时"), entity.Details.FirstOrDefault(r => r.ModelStatus == "插卡时"));
|
||||
CopyModelDetail(model.Details.FirstOrDefault(r => r.ModelStatus == "拔卡时"), entity.Details.FirstOrDefault(r => r.ModelStatus == "拔卡时"));
|
||||
CopyModelDetail(model.Details.FirstOrDefault(r => r.ModelStatus == "待租时"), entity.Details.FirstOrDefault(r => r.ModelStatus == "待租时"));
|
||||
CopyModelDetail(model.Details.FirstOrDefault(r => r.ModelStatus == "停租时"), entity.Details.FirstOrDefault(r => r.ModelStatus == "停租时"));
|
||||
|
||||
ModelManager.Update(model);
|
||||
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Edit"), entity.Name);
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
catch (ApplicationException ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Delete(IList<int> idList, IList<string> nameList)
|
||||
{
|
||||
ModelManager.Delete(idList.Cast<object>().ToList());
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Delete"), string.Join(",", nameList));
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Apply(int modelID, string hostIDs)
|
||||
{
|
||||
IList<int> ids = Newtonsoft.Json.JsonConvert.DeserializeObject<IList<int>>(hostIDs);
|
||||
|
||||
Model model = ModelManager.Get(modelID);
|
||||
if (model == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("InvalidAirConditioningEnergySavingSolutions") });
|
||||
}
|
||||
|
||||
IList<Host> hosts = new List<Host>();
|
||||
foreach (int id in ids)
|
||||
{
|
||||
Host host = HostManager.Get(id);
|
||||
if (host != null)
|
||||
{
|
||||
hosts.Add(host);
|
||||
}
|
||||
}
|
||||
|
||||
ModelManager.ApplyModel(model, hosts, User.Identity.Name);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("ApplicationOfSuccess") });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadGroupTreeWithRoom(int? modelID)
|
||||
{
|
||||
IList<Host> appliedHosts = new List<Host>();
|
||||
|
||||
if (modelID.HasValue)
|
||||
{
|
||||
Model model = ModelManager.Get(modelID);
|
||||
if (!String.IsNullOrEmpty(model.Hosts))
|
||||
{
|
||||
IList<int> hostIDs = model.Hosts.Split(',').Select(r => Convert.ToInt32(r)).ToList();
|
||||
foreach (int id in hostIDs)
|
||||
{
|
||||
appliedHosts.Add(HostManager.Get(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var groupTree = GroupManager.CreateGroupTreeWithRoom(null, appliedHosts, CurrentHotelID);
|
||||
return Json(groupTree, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
private void CopyModelDetail(ModelDetail modelDetail1, ModelDetail modelDetail2)
|
||||
{
|
||||
if (modelDetail1 != null && modelDetail2 != null)
|
||||
{
|
||||
modelDetail1.OnOff = modelDetail2.OnOff;
|
||||
modelDetail1.ModelType = modelDetail2.ModelType;
|
||||
modelDetail1.Speed = modelDetail2.Speed;
|
||||
modelDetail1.SummerTemp = modelDetail2.SummerTemp;
|
||||
modelDetail1.WinterTemp = modelDetail2.WinterTemp;
|
||||
modelDetail1.TimingControl = modelDetail2.TimingControl;
|
||||
modelDetail1.Timer = modelDetail2.Timer;
|
||||
modelDetail1.AllowElectric = modelDetail2.AllowElectric;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
252
WebSite/Controllers/Oauth2Controller.cs
Normal file
252
WebSite/Controllers/Oauth2Controller.cs
Normal file
@@ -0,0 +1,252 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Data;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Dynamic;
|
||||
using Common;
|
||||
using Service;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class Oauth2Controller : BaseController
|
||||
{
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(Oauth2Controller));
|
||||
private static string _clientID = System.Configuration.ConfigurationManager.AppSettings["rokid_client_id"];
|
||||
private static string _clientSecret = System.Configuration.ConfigurationManager.AppSettings["rokid_client_secret"];
|
||||
private static int _expiresIn = 180000;//50个小时
|
||||
|
||||
public ISysUserManager SysUserManager { get; set; }
|
||||
public ISysOauth2Manager SysOauth2Manager { get; set; }
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Authorize()
|
||||
{
|
||||
logger.Error("收到调用Authorize方法Url:" + Request.Url);
|
||||
try
|
||||
{
|
||||
if (Request.QueryString["response_type"] != "code")//固定code
|
||||
{
|
||||
return returnResult("response_type验证失败");
|
||||
}
|
||||
string client_id = Request.QueryString["client_id"];//若琪所使用的标识
|
||||
string redirect_uri = Request.QueryString["redirect_uri"];//回调地址
|
||||
string state = Request.QueryString["state"];//用来保持授权请求和授权回调状态的值,当授权完成后需要将这个参数附加在回调里。
|
||||
//string scope = Request.QueryString["scope"];//授权的范围
|
||||
if (client_id != _clientID)
|
||||
{
|
||||
logger.Error("client_id验证失败:" + client_id);
|
||||
return returnResult("client_id验证失败");
|
||||
}
|
||||
if (string.IsNullOrEmpty(redirect_uri))
|
||||
{
|
||||
logger.Error("redirect_uri无效:" + redirect_uri);
|
||||
return returnResult("redirect_uri无效");
|
||||
}
|
||||
if (redirect_uri.IndexOf("lzos.lunzn.com") > -1)//岚正播放盒免登录授权
|
||||
{
|
||||
string code = "1001BLW" + redirect_uri.Substring(redirect_uri.LastIndexOf("/") + 1);
|
||||
var sysOahth2 = SysOauth2Manager.Get(code);
|
||||
if (null == sysOahth2)
|
||||
{
|
||||
SysOauth2Manager.Save(new Domain.SysOauth2() { Code = code, RedirectUri = redirect_uri, ExpiresIn = _expiresIn, CreatedDate = DateTime.Now, Account = "system" });
|
||||
}
|
||||
return Redirect(redirect_uri + "?code=" + code + "&state=" + state);
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewData["client_id"] = client_id;
|
||||
ViewData["redirect_uri"] = redirect_uri;
|
||||
ViewData["state"] = state;
|
||||
return View();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex);
|
||||
return returnResult("授权失败:" + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult LoginOn(string jsonData)
|
||||
{
|
||||
try
|
||||
{
|
||||
JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData);
|
||||
string account = jData["account"].ToString();
|
||||
string password = jData["password"].ToString();
|
||||
string redirect_uri = jData["redirect_uri"].ToString();
|
||||
var entity = SysUserManager.Get(account, password);
|
||||
if (entity == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("UsernameOrPasswordWrong") });
|
||||
}
|
||||
if (!entity.ActiveIndicator)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("YourAccountHasBeenDisabledPleaseContactTheAdministrator") });
|
||||
}
|
||||
string code = entity.Hotels[0].Code + "BLW" + redirect_uri.Substring(redirect_uri.LastIndexOf("/") + 1);
|
||||
var sysOauth2 = SysOauth2Manager.Get(code);
|
||||
if (null == sysOauth2)
|
||||
{
|
||||
SysOauth2Manager.Save(new Domain.SysOauth2() { Code = code, RedirectUri = redirect_uri, ExpiresIn = _expiresIn, CreatedDate = DateTime.Now, Account = account });
|
||||
}
|
||||
redirect_uri = System.Web.HttpUtility.UrlDecode(redirect_uri, System.Text.Encoding.UTF8) + "?code=" + code + "&state=" + jData["state"].ToString();
|
||||
return Json(new { IsSuccess = true, Message = redirect_uri });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex);
|
||||
return returnResult("授权失败:" + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult Token()
|
||||
{
|
||||
Request.InputStream.Position = 0;
|
||||
byte[] reqBody = new byte[Request.InputStream.Length];
|
||||
Request.InputStream.Read(reqBody, 0, reqBody.Length);
|
||||
string reqData = System.Text.Encoding.UTF8.GetString(reqBody);
|
||||
//logger.Error("收到调用Token方法参数值:" + reqData);
|
||||
try
|
||||
{
|
||||
string grant_type = "";//Request.QueryString["grant_type"];//必须,值为 authorization_code,如果是刷新 Token 则为 refresh_token
|
||||
string code = "";//Request.QueryString["code"];//如果是通过 authorization_code 获取 access token 则为必须,授权过程中颁发的授权代码
|
||||
string client_id = "";//Request.QueryString["client_id"];//必须,若琪所使用的标识
|
||||
string client_secret = "";//Request.QueryString["client_secret"];//可选,如果使用 HTTP Basic Auth 则该参数会包含在 HTTP Authorization Header 中
|
||||
string refresh_token = "";
|
||||
string[] queryStrings = reqData.Split('&');
|
||||
foreach (string queryString in queryStrings)
|
||||
{
|
||||
string[] querys = queryString.Split('=');
|
||||
switch (querys[0])
|
||||
{
|
||||
case "client_id":
|
||||
client_id = querys[1];
|
||||
break;
|
||||
case "client_secret":
|
||||
client_secret = querys[1];
|
||||
break;
|
||||
case "grant_type":
|
||||
grant_type = querys[1];
|
||||
break;
|
||||
case "code":
|
||||
code = querys[1];
|
||||
break;
|
||||
case "refresh_token":
|
||||
refresh_token = querys[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(client_id))//获取岚正播放盒调用参数
|
||||
{
|
||||
JObject jData = (JObject)JsonConvert.DeserializeObject(reqData);
|
||||
client_id = jData["client_id"].ToString();
|
||||
client_secret = jData["client_secret"].ToString();
|
||||
grant_type = jData["grant_type"].ToString();
|
||||
code = jData["code"].ToString();
|
||||
refresh_token = jData["refresh_token"] == null ? "" : jData["refresh_token"].ToString();
|
||||
}
|
||||
if (client_id != _clientID)
|
||||
{
|
||||
logger.Error("client_id验证失败:" + client_id);
|
||||
return returnResult("client_id验证失败");
|
||||
}
|
||||
if (client_secret != _clientSecret)
|
||||
{
|
||||
logger.Error("client_secret验证失败:" + client_secret);
|
||||
return returnResult("client_secret验证失败");
|
||||
}
|
||||
Domain.SysOauth2 sysOauth2 = null;
|
||||
switch (grant_type)
|
||||
{
|
||||
case "client_credentials"://客户端凭证授权模式
|
||||
code = "1001BLWXiaoDu";//1001BLWXiaoMi
|
||||
sysOauth2 = SysOauth2Manager.Get(code);
|
||||
if (null == sysOauth2)
|
||||
{
|
||||
sysOauth2 = new Domain.SysOauth2()
|
||||
{
|
||||
Code = code,
|
||||
RedirectUri = "",
|
||||
ExpiresIn = _expiresIn,
|
||||
CreatedDate = DateTime.Now,
|
||||
Account = "system",
|
||||
AccessToken = code.Substring(0, code.IndexOf("BLW") + 3) + Guid.NewGuid(),
|
||||
RefreshToken = code.Substring(0, code.IndexOf("BLW") + 3) + Guid.NewGuid()
|
||||
};
|
||||
SysOauth2Manager.Save(sysOauth2);
|
||||
}
|
||||
else
|
||||
{
|
||||
sysOauth2.ExpiresIn = _expiresIn;
|
||||
sysOauth2.CreatedDate = DateTime.Now;
|
||||
SysOauth2Manager.Update(sysOauth2);//更新保存token
|
||||
}
|
||||
return Json(sysOauth2.AccessToken, JsonRequestBehavior.AllowGet);
|
||||
case "refresh_token":
|
||||
sysOauth2 = SysOauth2Manager.GetByRefreshToken(refresh_token);
|
||||
break;
|
||||
default:
|
||||
sysOauth2 = SysOauth2Manager.Get(code);
|
||||
sysOauth2.AccessToken = sysOauth2.Code.Substring(0, sysOauth2.Code.IndexOf("BLW") + 3) + Guid.NewGuid();//获取新的token
|
||||
sysOauth2.RefreshToken = sysOauth2.Code.Substring(0, sysOauth2.Code.IndexOf("BLW") + 3) + Guid.NewGuid();//获取新的token
|
||||
break;
|
||||
}
|
||||
if (null == sysOauth2)
|
||||
{
|
||||
logger.Error(string.Format("code或refresh_token验证失败,code:{0},refresh_token:{1}, 收到调用参数:{2}, 来自:{3}", code, refresh_token, reqData, Tools.GetClientIP()));
|
||||
return returnResult("code或refresh_token验证失败");
|
||||
}
|
||||
sysOauth2.ExpiresIn = _expiresIn;
|
||||
sysOauth2.CreatedDate = DateTime.Now;
|
||||
SysOauth2Manager.Update(sysOauth2);//更新保存token
|
||||
AuthorizeResult result = new AuthorizeResult
|
||||
{
|
||||
access_token = sysOauth2.AccessToken,
|
||||
expires_in = sysOauth2.ExpiresIn,
|
||||
refresh_token = sysOauth2.RefreshToken,
|
||||
example_parameter = "example_value"
|
||||
};
|
||||
return Json(result, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex);
|
||||
return returnResult("授权失败:" + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private ActionResult returnResult(string message)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = message }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
}
|
||||
|
||||
public class AuthorizeResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 必须,由授权服务颁发的 access token
|
||||
/// </summary>
|
||||
public string access_token { get; set; }
|
||||
/// <summary>
|
||||
/// 可选,AccessToken 的寿命,以秒为单位,如果 access_token 会过期则应该必须提供
|
||||
/// </summary>
|
||||
public int expires_in { get; set; }
|
||||
/// <summary>
|
||||
/// 可选,用来通过以 refresh_token 的 grant_type 请求 AccessToken 接口获取新的 AccessToken 的 token
|
||||
/// </summary>
|
||||
public string refresh_token { get; set; }
|
||||
/// <summary>
|
||||
/// example_value
|
||||
/// </summary>
|
||||
public string example_parameter { get; set; }
|
||||
}
|
||||
}
|
||||
249
WebSite/Controllers/OverviewController.cs
Normal file
249
WebSite/Controllers/OverviewController.cs
Normal file
@@ -0,0 +1,249 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Service;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class OverviewController : BaseController
|
||||
{
|
||||
public IHostManager HostManager { get; set; }
|
||||
public IOverviewManager OverviewManager { get; set; }
|
||||
public IHostFaultRecordsManager HostFaultRecordsManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
/// <summary>
|
||||
/// 回路状态记录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult HostModalRecords()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取回路状态记录
|
||||
///
|
||||
///
|
||||
/// 严重怀疑这里的调用有问题
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="rows"></param>
|
||||
/// <param name="order"></param>
|
||||
/// <param name="sort"></param>
|
||||
/// <param name="roomNumber"></param>
|
||||
/// <param name="startTime"></param>
|
||||
/// <param name="endTime"></param>
|
||||
/// <param name="modalIds"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult LoadHostModalRecords(int? page, int? rows, string order, string sort, string roomNumber, string startTime, string endTime, DeviceType? deviceType, string modalIds)
|
||||
{
|
||||
long total = 0;
|
||||
var list = OverviewManager.LoadHostModalRecords(out total, 1, 100, order, sort, roomNumber, startTime, endTime, deviceType, modalIds, CurrentHotelID);
|
||||
var result = new { total = total, rows = list };
|
||||
return Content(JsonConvert.SerializeObject(result, new DataTableConverter()));
|
||||
}
|
||||
/// <summary>
|
||||
/// 回路异常记录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult HostAbnormalRecords()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取异常类型
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ActionResult LoadAbnormalType()
|
||||
{
|
||||
IList<object> result = new List<object>();
|
||||
result.Add(new { Value = 1, Name = "门磁超过2天无开关记录(表示门磁已坏)" });
|
||||
result.Add(new { Value = 2, Name = "已取电,10小时内红外无打开记录(表示红外已坏)" });
|
||||
result.Add(new { Value = 3, Name = "已取电,10秒内门磁无开关记录(表示取电异常)" });
|
||||
|
||||
return Json(result, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取回路异常记录
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="rows"></param>
|
||||
/// <param name="order"></param>
|
||||
/// <param name="sort"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult LoadHostAbnormalRecords(int? page, int? rows, string order, string sort, int type)
|
||||
{
|
||||
//严重怀疑这里的代码有问题
|
||||
long total = 0;
|
||||
var list = OverviewManager.LoadHostAbnormalRecords(type, CurrentHotelID);
|
||||
var result = new { total = total, rows = list };
|
||||
return Content(JsonConvert.SerializeObject(result, new DataTableConverter()));
|
||||
}
|
||||
/// <summary>
|
||||
/// 外设异常记录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult HostFaultRecords()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取存在外设异常的房号
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ActionResult LoadRoomNumbers()
|
||||
{
|
||||
IList<object> result = new List<object>();
|
||||
IList<string> roomNumbers = HostFaultRecordsManager.LoadRoomNumbers(CurrentHotelID);
|
||||
foreach (string roomNumber in roomNumbers)
|
||||
{
|
||||
result.Add(new { Value = roomNumber, Name = roomNumber });
|
||||
}
|
||||
result.Insert(0, new { Value = "", Name = HttpContext.InnerLanguage("CheckAll") });
|
||||
|
||||
return Json(result, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取回路异常记录
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="rows"></param>
|
||||
/// <param name="order"></param>
|
||||
/// <param name="sort"></param>
|
||||
/// <param name="roomNumber"></param>
|
||||
/// <param name="startTime"></param>
|
||||
/// <param name="endTime"></param>
|
||||
/// <param name="deviceType"></param>
|
||||
/// <param name="modalIds"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult LoadHostFaultRecords(int? page, int? rows, string order, string sort, string roomNumber, string startTime, string endTime, DeviceType? deviceType, string modalIds)
|
||||
{
|
||||
long total = 0;
|
||||
var list = HostFaultRecordsManager.LoadHostFaultRecords(out total, 1, 100, order, sort, roomNumber, startTime, endTime, deviceType, modalIds, CurrentHotelID);
|
||||
var result = new { total = total, rows = list };
|
||||
return Content(JsonConvert.SerializeObject(result, new DataTableConverter()));
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View("SimonIndex");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载RCU联网通讯状况
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadRCUState()
|
||||
{
|
||||
var list = HostManager.LoadAll(CurrentHotelID);
|
||||
var state = new
|
||||
{
|
||||
Online = list.Count(r => r.Status == true),
|
||||
Offline = list.Count(r => r.Status == false),
|
||||
Total = list.Count()
|
||||
};
|
||||
return Json(state, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
/// <summary>
|
||||
/// 加载客房房门开关状况
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadDoorState()
|
||||
{
|
||||
return Json(OverviewManager.LoadDoorState(CurrentHotelID), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
/// <summary>
|
||||
/// 加载空调运行状况
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadAirConditionState()
|
||||
{
|
||||
return Json(OverviewManager.LoadAirConditionState(CurrentHotelID), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
/// <summary>
|
||||
/// 加载客房出租状况
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadRoomRentState()
|
||||
{
|
||||
return Json(OverviewManager.LoadRoomRentState(CurrentHotelID), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载正在请求的服务状况
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadRoomServiceState()
|
||||
{
|
||||
return Json(OverviewManager.LoadRoomServiceState(), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载保险箱状况
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadSafeBoxState()
|
||||
{
|
||||
return Json(OverviewManager.LoadSafeBoxState(), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载客房状况
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadRoomState()
|
||||
{
|
||||
return Json(OverviewManager.LoadRoomState(), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载客房窗门状况
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadWindowState()
|
||||
{
|
||||
var state = new
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
return Json(state, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载客房阳台门状况
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadBalconyDoorState()
|
||||
{
|
||||
var state = new
|
||||
{
|
||||
};
|
||||
|
||||
return Json(state, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
102
WebSite/Controllers/RoomCardController.cs
Normal file
102
WebSite/Controllers/RoomCardController.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Service;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class RoomCardController : BaseController
|
||||
{
|
||||
public IRoomCardManager RoomCardManager { get; set; }
|
||||
|
||||
public IRoomCardTypeManager RoomCardTypeManager { get; set; }
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
#if SIMON
|
||||
return View("SimonIndex");
|
||||
#else
|
||||
return View();
|
||||
#endif
|
||||
}
|
||||
|
||||
public ActionResult Edit(int? id)
|
||||
{
|
||||
if (id.HasValue)
|
||||
{
|
||||
return View(RoomCardManager.Get(id.Value));
|
||||
}
|
||||
|
||||
return View(new RoomCard { ID = 0, CardNumber = "", RoomCardType = null, UserNumber = "", UserName = "", Sort = 1 });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAllByPage(int page, int rows, string order, string sort)
|
||||
{
|
||||
long total = 0;
|
||||
|
||||
var list = RoomCardManager.LoadAllByPage(out total, page, rows, order, sort, CurrentHotelID);
|
||||
|
||||
var result = list.Select(r => new
|
||||
{
|
||||
r.ID,
|
||||
r.CardNumber,
|
||||
CardTypeID = r.RoomCardType.ID,
|
||||
CardType = r.RoomCardType.Name,
|
||||
r.UserNumber,
|
||||
r.UserName,
|
||||
r.Sort
|
||||
}).ToList();
|
||||
|
||||
return Json(new { total = result.Count, rows = result });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadRoomCardTypes()
|
||||
{
|
||||
var list = RoomCardTypeManager.LoadAll();
|
||||
return Json(list);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Save(string jsonData)
|
||||
{
|
||||
var entity = Newtonsoft.Json.JsonConvert.DeserializeObject<RoomCard>(jsonData);
|
||||
|
||||
var existRoomCard = RoomCardManager.GetByCarNumber(entity.CardNumber, CurrentHotelID);
|
||||
if (existRoomCard != null && (entity.ID == 0 || entity.ID != existRoomCard.ID))
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("CardNumber") + "【" + entity.CardNumber + "】" + HttpContext.InnerLanguage("AlreadyExist") });
|
||||
}
|
||||
|
||||
if (entity.ID == 0)
|
||||
{
|
||||
entity.HotelID = CurrentHotelID;
|
||||
RoomCardManager.Save(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
var roomCard = RoomCardManager.Get(entity.ID);
|
||||
roomCard.CardNumber = entity.CardNumber;
|
||||
roomCard.RoomCardType = entity.RoomCardType;
|
||||
roomCard.UserNumber = entity.UserNumber;
|
||||
roomCard.UserName = entity.UserName;
|
||||
roomCard.Sort = entity.Sort;
|
||||
roomCard.HotelID = CurrentHotelID;
|
||||
|
||||
RoomCardManager.Update(roomCard);
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Delete(IList<int> idList)
|
||||
{
|
||||
RoomCardManager.Delete(idList.Cast<object>().ToList());
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
}
|
||||
}
|
||||
}
|
||||
322
WebSite/Controllers/RoomControlController.cs
Normal file
322
WebSite/Controllers/RoomControlController.cs
Normal file
@@ -0,0 +1,322 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
using System.Data;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class RoomControlController : BaseController
|
||||
{
|
||||
private const int AUTHORITY_RoomControl = 11;
|
||||
|
||||
public IHostManager HostManager { get; set; }
|
||||
public IGroupManager GroupManager { get; set; }
|
||||
public IRoomStatusManager RoomStatusManager { get; set; }
|
||||
public IRoomTypeManager RoomTypeManager { get; set; }
|
||||
public IHostTimingControlManager HostTimingControlManager { get; set; }
|
||||
public IRoomTypeSceneManager RoomTypeSceneManager { get; set; }
|
||||
public ISysUserManager SysUserManager { get; set; }
|
||||
public IRoomCardTypeManager RoomCardTypeManager { get; set; }
|
||||
public ITestManager TestManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View("SimonIndex");
|
||||
}
|
||||
/// <summary>
|
||||
/// 加载定时记录
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="rows"></param>
|
||||
/// <param name="order"></param>
|
||||
/// <param name="sort"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadByRoomControl(int page, int rows, string order, string sort)
|
||||
{
|
||||
long total = 0;
|
||||
var list = HostTimingControlManager.LoadAllByPage(out total, page, rows, order, sort, CurrentHotelID);
|
||||
var restult = list.Select(r => new
|
||||
{
|
||||
r.ID,
|
||||
r.HotelID,
|
||||
r.HostIDs,
|
||||
RoomNumbers = GetRoomNumberByIDs(r.HostIDs),
|
||||
r.GroupID,
|
||||
GroupName = r.GroupID > 0 ? GroupManager.Get(r.GroupID).Name : "",
|
||||
r.RoomTypeID,
|
||||
RoomTypeName = r.RoomTypeID > 0 ? RoomTypeManager.Get(r.RoomTypeID).Name : "",
|
||||
r.RoomStatusID,
|
||||
RoomStatusName = r.RoomStatusID > 0 ? RoomStatusManager.Get(r.RoomStatusID).Name : "",
|
||||
r.RoomCardTypeID,
|
||||
RoomCardTypeName = r.RoomCardTypeID > -1 ? RoomCardTypeManager.Get(r.RoomCardTypeID).Name : "",
|
||||
r.RoomTypeSceneID,
|
||||
RoomTypeSceneName = RoomTypeSceneManager.Get(r.RoomTypeSceneID).Name,
|
||||
r.TimingType,
|
||||
r.TimingDay,
|
||||
r.Timing,
|
||||
r.ActiveIndicator,
|
||||
ExecStatus = r.ExecStatus ? true : false,
|
||||
ExecTime = r.ExecStatus ? Convert.ToDateTime(r.ExecTime).ToString("yyyy-MM-dd HH:mm:ss") : ""
|
||||
}).ToList();
|
||||
return Json(new { total = restult.Count, rows = restult });
|
||||
}
|
||||
|
||||
private string GetRoomNumberByIDs(string hostIDs)
|
||||
{
|
||||
string roomNumbers = "";
|
||||
foreach (string id in hostIDs.Split(','))
|
||||
{
|
||||
var item = HostManager.Get(Convert.ToInt32(id));
|
||||
if (item != null)
|
||||
{
|
||||
roomNumbers += item.RoomNumber + ",";
|
||||
}
|
||||
}
|
||||
if (roomNumbers.Length > 0 && roomNumbers.LastIndexOf(",") == roomNumbers.Length - 1)
|
||||
{
|
||||
roomNumbers = roomNumbers.Substring(0, roomNumbers.Length - 1);
|
||||
}
|
||||
return roomNumbers;
|
||||
}
|
||||
/// <summary>
|
||||
/// 编辑定时
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult Edit(int? id)
|
||||
{
|
||||
HostTimingControl model = new HostTimingControl { ID = 0 };
|
||||
model.RoomCardTypeID = -1;
|
||||
if (id.HasValue && id != 0)
|
||||
{
|
||||
model = HostTimingControlManager.Get(id);
|
||||
}
|
||||
return View(model);
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存新增、编辑定时
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult SaveRoomControrl(string jsonData)
|
||||
{
|
||||
var entity = Newtonsoft.Json.JsonConvert.DeserializeObject<HostTimingControl>(jsonData);
|
||||
|
||||
if (entity.ID == 0)
|
||||
{
|
||||
entity.HotelID = CurrentHotelID;
|
||||
entity.ActiveIndicator = false;
|
||||
entity.ExecStatus = false;
|
||||
entity.ExecTime = Convert.ToDateTime("1999-01-01");
|
||||
HostTimingControlManager.Save(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
var timingEntity = HostTimingControlManager.Get(entity.ID);
|
||||
timingEntity.HotelID = CurrentHotelID;
|
||||
timingEntity.GroupID = entity.GroupID;
|
||||
timingEntity.RoomTypeID = entity.RoomTypeID;
|
||||
timingEntity.HostIDs = entity.HostIDs;
|
||||
timingEntity.RoomStatusID = entity.RoomStatusID;
|
||||
timingEntity.RoomCardTypeID = entity.RoomCardTypeID;
|
||||
timingEntity.RoomTypeSceneID = entity.RoomTypeSceneID;
|
||||
timingEntity.TimingType = entity.TimingType;
|
||||
timingEntity.TimingDay = entity.TimingDay;
|
||||
timingEntity.Timing = entity.Timing;
|
||||
timingEntity.ActiveIndicator = false;
|
||||
|
||||
HostTimingControlManager.Update(timingEntity);
|
||||
}
|
||||
TestManager.Save(new Test() { MyName="nihao"});
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
/// <summary>
|
||||
/// 刪除定时记录
|
||||
/// </summary>
|
||||
/// <param name="idList"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult Delete(IList<int> idList)
|
||||
{
|
||||
HostTimingControlManager.Delete(idList.Cast<object>().ToList());
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="idList"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult SetActiveIndicator(IList<int> idList)
|
||||
{
|
||||
foreach (Int32 id in idList)
|
||||
{
|
||||
var item = HostTimingControlManager.Get(id);
|
||||
item.ActiveIndicator = !item.ActiveIndicator;
|
||||
HostTimingControlManager.Update(item);
|
||||
}
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 编辑框下拉选择
|
||||
/// <summary>
|
||||
/// 当酒店楼层改变时房号改变
|
||||
/// </summary>
|
||||
/// <param name="groupID"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult loadRoomNumber(int groupID)
|
||||
{
|
||||
var roomNumber = HostManager.LoadAll().Where(r => r.Group.ID == groupID && r.SysHotel.ID == CurrentHotelID).ToList();
|
||||
var result = roomNumber.Select(r => new {
|
||||
ID = r.ID,
|
||||
RoomNumber = r.RoomNumber
|
||||
}).ToList();
|
||||
return Json(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 房号
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadRoomNumberCombobox(int? roomTypeID)
|
||||
{
|
||||
var result = new List<object>();
|
||||
if (roomTypeID.HasValue && roomTypeID > 0)
|
||||
{
|
||||
//var currentUser = SysUserManager.Get(User.Identity.Name);//获取当前用户
|
||||
//var sysUserHotel = SysUserHotelManager.Get(currentUser.ID, CurrentHotelID);//获取当前用户所在酒店
|
||||
var currentGroup = GroupManager.LoadAll().FirstOrDefault(r => r.Parent == null && r.HotelID == CurrentHotelID); //Get(sysUserHotel != null ? sysUserHotel.GroupID : 0);//获取当前用户所在酒店的楼层
|
||||
|
||||
DataTable table = HostManager.LoadRoomNumbers(currentGroup != null ? currentGroup : null, CurrentHotelID);
|
||||
|
||||
foreach (DataRow row in table.Rows)
|
||||
{
|
||||
if (Convert.ToInt16(row["RoomTypeID"]) == roomTypeID)
|
||||
{
|
||||
result.Add(new { ID = row["ID"], RoomNumber = row["RoomNumber"], GroupName = row["GroupName"], RoomTypeName = row["RoomTypeName"] });
|
||||
}
|
||||
}
|
||||
}
|
||||
return Json(result);
|
||||
}
|
||||
/// <summary>
|
||||
/// 当前酒店场景
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadRoomTypeScene(int? roomTypeID)
|
||||
{
|
||||
var result = new List<object>();
|
||||
if (roomTypeID.HasValue && roomTypeID > 0)
|
||||
{
|
||||
var list = RoomTypeSceneManager.LoadAll().Where(r => r.HotelID == CurrentHotelID && r.RoomType.ID == roomTypeID).ToList();
|
||||
result = list.Select(r => new { r.ID, Name = ReturnNameByLanguage(r.Name, r.EnglishName, r.TWName) }).ToList<object>();
|
||||
}
|
||||
result.Insert(0, new { ID = 0, Name = HttpContext.InnerLanguage("Choice") });
|
||||
return Json(result);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取日期(星期几或几号)
|
||||
/// </summary>
|
||||
/// <param name="timeType"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult LoadTimeDay(int? timeType)
|
||||
{
|
||||
var result = new List<object>();
|
||||
switch (timeType)
|
||||
{
|
||||
case 1:
|
||||
result.Add(new { ID = 0, Name = "日" });
|
||||
result.Add(new { ID = 1, Name = "一" });
|
||||
result.Add(new { ID = 2, Name = "二" });
|
||||
result.Add(new { ID = 3, Name = "三" });
|
||||
result.Add(new { ID = 4, Name = "四" });
|
||||
result.Add(new { ID = 5, Name = "五" });
|
||||
result.Add(new { ID = 6, Name = "六" });
|
||||
break;
|
||||
case 2:
|
||||
for (int i = 1; i < 32; i++)
|
||||
{
|
||||
result.Add(new { ID = i, Name = i.ToString() });
|
||||
}
|
||||
break;
|
||||
default:
|
||||
result.Add(new { ID = 0, Name = HttpContext.InnerLanguage("EveryDay") });
|
||||
break;
|
||||
}
|
||||
return Json(result);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取时间(时:分)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ActionResult LoadTiming()
|
||||
{
|
||||
DateTime dt = Convert.ToDateTime("1999-01-01 00:00:00");
|
||||
var result = new List<object>();
|
||||
for (int i = 0; i < 96; i++)
|
||||
{
|
||||
result.Add(new { Value = dt.ToString("HH:mm") });
|
||||
dt = dt.AddMinutes(15);
|
||||
}
|
||||
|
||||
return Json(result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private IList<Host> FindHosts(int? hostID, int? groupID, int? roomStatusID, int? roomTypeID)
|
||||
{
|
||||
IList<Host> hosts = new List<Host>();
|
||||
|
||||
if (hostID.HasValue && hostID > 0)
|
||||
{
|
||||
var host = HostManager.Get(hostID.GetValueOrDefault());
|
||||
if (host != null)
|
||||
{
|
||||
hosts.Add(host);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IList<Group> groups = new List<Group>();
|
||||
if (groupID.HasValue)
|
||||
{
|
||||
groups = GroupManager.GetGroupList(GroupManager.Get(groupID));
|
||||
}
|
||||
|
||||
RoomStatus roomStatus = null;
|
||||
if (roomStatusID.HasValue)
|
||||
{
|
||||
roomStatus = RoomStatusManager.Get(roomStatusID);
|
||||
}
|
||||
|
||||
RoomType roomType = null;
|
||||
if (roomTypeID.HasValue)
|
||||
{
|
||||
roomType = RoomTypeManager.Get(roomTypeID);
|
||||
}
|
||||
|
||||
hosts = HostManager.LoadAll(groups, roomStatus, roomType);
|
||||
}
|
||||
|
||||
return hosts;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
83
WebSite/Controllers/RoomModalController.cs
Normal file
83
WebSite/Controllers/RoomModalController.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class RoomModalController : BaseController
|
||||
{
|
||||
private const int AuthorityID = 20;
|
||||
|
||||
public IRoomModalManager RoomModalManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Edit(string id)
|
||||
{
|
||||
return View(RoomModalManager.Get(id));
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAllByPage(int page, int rows, string order, string sort)
|
||||
{
|
||||
long total = 0;
|
||||
|
||||
var list = this.RoomModalManager.LoadAllByPage(out total, page, rows, order, sort);
|
||||
|
||||
//var result = list.Select(r => new { r.ID, r.Number, r.ModalName, r.Name, r.Type, r.Remark, @checked = true });
|
||||
|
||||
return Json(new { total = total, rows = list });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAll()
|
||||
{
|
||||
return Json(RoomModalManager.LoadAll().OrderBy(r => r.Sort).ToList());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 修改自定义名称
|
||||
/// </summary>
|
||||
/// <param name="ID"></param>
|
||||
/// <param name="Name"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult ChangeName(string ID, string Name)
|
||||
{
|
||||
RoomModal modal = RoomModalManager.Get(ID);
|
||||
|
||||
if (String.IsNullOrEmpty(ID) || modal == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("InvalidOperation") });
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(Name))
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("CustomNameCanNotBeEmpty") });
|
||||
}
|
||||
|
||||
modal.Name = Name;
|
||||
|
||||
RoomModalManager.Save(modal);
|
||||
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("EditingEquipment"), Name);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
343
WebSite/Controllers/RoomServiceController.cs
Normal file
343
WebSite/Controllers/RoomServiceController.cs
Normal file
@@ -0,0 +1,343 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Service;
|
||||
using System.IO;
|
||||
using CommonEntity;
|
||||
using Common;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class RoomServiceController : BaseController
|
||||
{
|
||||
private const int AuthorityID = 10;
|
||||
|
||||
public IRoomServiceManager RoomServiceManager { get; set; }
|
||||
|
||||
public IRoomServiceRecordManager RoomServiceRecordManager { get; set; }
|
||||
|
||||
public IAlarmSettingManager AlarmSettingManager { get; set; }
|
||||
|
||||
public IHostManager HostManager { get; set; }
|
||||
|
||||
public IHostModalManager HostModalManager { get; set; }
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
#region 服务记录
|
||||
|
||||
/// <summary>
|
||||
/// 服务记录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ActionResult ServiceRecords()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载服务记录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadServiceRecords(int page, int rows, string order, string sort, string roomNumber, string startTime, string endTime, string alarmCodes)
|
||||
{
|
||||
Models.QueryConditionModel model = new Models.QueryConditionModel();
|
||||
model.Order = order;
|
||||
model.Sort = sort;
|
||||
model.RoomNumber = roomNumber;
|
||||
model.StartTime = startTime;
|
||||
model.EndTime = endTime;
|
||||
model.AlarmCodes = alarmCodes;
|
||||
|
||||
Session["QueryConditionModel"] = model;
|
||||
|
||||
long total = 0;
|
||||
|
||||
string[] services = null;
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(alarmCodes))
|
||||
{
|
||||
services = alarmCodes.Split(',');
|
||||
}
|
||||
|
||||
var list = RoomServiceRecordManager.LoadAllByPage(out total, page, rows, order, sort, roomNumber, startTime, endTime, services);
|
||||
|
||||
//list = (IList<RoomServiceRecord>)list.Where(r => r.HostID == CurrentHotelID);
|
||||
|
||||
var result = list.Select(r => new
|
||||
{
|
||||
r.RoomNumber,
|
||||
r.Name,
|
||||
r.StartTime,
|
||||
r.EndTime,
|
||||
Time = r.EndTime.HasValue ? (r.EndTime.Value - r.StartTime).TotalMinutes : (DateTime.Now - r.StartTime).TotalMinutes,
|
||||
});
|
||||
|
||||
return Json(new { total = total, rows = result });
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前服务信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadCurrentMsg()
|
||||
{
|
||||
var result = new List<object>();
|
||||
|
||||
var table = RoomServiceManager.LoadCurrentRoomServicesCount(CurrentHotelID, this.User.Identity.Name);
|
||||
|
||||
if (table != null)
|
||||
{
|
||||
foreach (System.Data.DataRow row in table.Rows)
|
||||
{
|
||||
result.Add(new { Name = (bool)Session["isCN"] ? row["Name"] : row["EName"], Count = row["Number"] });
|
||||
}
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Data = result }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取当前设备故障信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadCurrentHostFault()
|
||||
{
|
||||
IList<object> faults = new List<object>();
|
||||
//外设离线
|
||||
IList<object[]> list = RoomServiceManager.LoadCurrentHostFaultStatistics(CurrentHotelID, this.User.Identity.Name, 1);
|
||||
foreach (object obj in list)
|
||||
{
|
||||
faults.Add(new { RoomNumber = Convert.ToString(((object[])(obj))[0]), Name = HttpContext.InnerLanguage("PeripheralOffline") });
|
||||
}
|
||||
//外设低电
|
||||
list = RoomServiceManager.LoadCurrentHostFaultStatistics(CurrentHotelID, this.User.Identity.Name, 2);
|
||||
foreach (object obj in list)
|
||||
{
|
||||
faults.Add(new { RoomNumber = Convert.ToString(((object[])(obj))[0]), Name = HttpContext.InnerLanguage("PeripheralLowPower") });
|
||||
}
|
||||
|
||||
return Json(new { total = faults.Count, rows = faults });
|
||||
}
|
||||
|
||||
//[Authorize]
|
||||
//public ActionResult LoadDeviceFault()
|
||||
//{
|
||||
// IList<object[]> list = RoomServiceManager.LoadCurrentHostFaultStatistics(CurrentHotelID, this.User.Identity.Name);
|
||||
// var result = list.Select(r => new
|
||||
// {
|
||||
// RoomNumber = r[0]
|
||||
// }).ToList();
|
||||
// return Json(new { total = result.Count, rows = result });
|
||||
//}
|
||||
/// <summary>
|
||||
/// 加载当前请求的服务
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadCurrentRoomServices()
|
||||
{
|
||||
IList<object[]> list = RoomServiceManager.LoadCurrentRoomServices(CurrentHotelID, this.User.Identity.Name);
|
||||
var result = list.Select(r => new TempLinShiClass()
|
||||
{
|
||||
HostID = r[0].ToString(),
|
||||
RoomTypeModalID = r[1].ToString(),
|
||||
RoomNumber = r[2].ToString(),
|
||||
Name = ReturnNameByLanguage(r[3].ToString(), r[4].ToString(), r[6].ToString()), //(bool)Session["isCN"] ? r[3] : r[4],
|
||||
Time = r[5],
|
||||
HostNumber = r[7].ToString(),
|
||||
ModalAddress = r[8].ToString()
|
||||
}).ToList();
|
||||
|
||||
foreach (var item in result)
|
||||
{
|
||||
if (item.Time == null)
|
||||
{
|
||||
string KKey = CacheKey.HostModalStatus_Prefix + "_" + item.HostID + "_" + item.ModalAddress;
|
||||
var hostModal = CSRedisCacheHelper.Get_Partition<HostModal_Cache>(KKey);
|
||||
if (hostModal != null)
|
||||
{
|
||||
HostModal_Cache hhh = hostModal = hostModal as HostModal_Cache;
|
||||
item.Time = hhh.UpdateTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Json(new { total = result.Count, rows = result });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载当前客房异常
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadCurrentRoomAbnormities()
|
||||
{
|
||||
IList<object[]> list = RoomServiceManager.LoadCurrentRoomAbnormities(CurrentHotelID, User.Identity.Name);
|
||||
|
||||
var result = list.Select(r => new { ID = r[0], Name = (bool)Session["isCN"] ? r[1] : r[4], RoomNumber = r[2], Time = r[3] }).ToList();
|
||||
|
||||
return Json(new { total = result.Count, rows = result });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadServicesForCombobox()
|
||||
{
|
||||
//var list = AlarmSettingManager.LoadAll()
|
||||
// .Where(r => r.HotelID == CurrentHotelID && r.Type == 'B')
|
||||
// .OrderBy(o => o.Sort)
|
||||
// .Select(s => new { Name = (Language == Language.CN) ? s.Name : s.EName, s.Code, s.Color })
|
||||
// .ToList();
|
||||
|
||||
IList<object> services = new List<object>();
|
||||
var table = RoomServiceManager.LoadCurrentRoomServicesCount(CurrentHotelID, this.User.Identity.Name);
|
||||
if (table != null)
|
||||
{
|
||||
foreach (System.Data.DataRow row in table.Rows)
|
||||
{
|
||||
services.Add(new
|
||||
{
|
||||
Code = row["Code"],
|
||||
Name = ReturnNameByLanguage(row["Name"].ToString(), row["EName"].ToString(), row["TWName"].ToString()),// (bool)Session["isCN"] ? row["Name"] : row["EName"],
|
||||
Color = row["Color"]
|
||||
});
|
||||
}
|
||||
}
|
||||
services.Insert(0, new { Name = HttpContext.InnerLanguage("Service"), Code = "", Color = "#FFFFFF" });
|
||||
return Json(services);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除服务
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult ClearRoomService(long id, string roomNumber, string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidRoom"));
|
||||
}
|
||||
|
||||
var service = RoomServiceManager.Get(id);
|
||||
if (service == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidService"));
|
||||
}
|
||||
|
||||
RoomServiceManager.ClearRoomService(host, service, User.Identity.Name);
|
||||
|
||||
// 清除相连通主机的服务
|
||||
//if (host.IsConnectingRoom)
|
||||
//{
|
||||
// var hostList = HostManager.GetConnectRoomHosts(host);
|
||||
|
||||
// foreach (var item in hostList)
|
||||
// {
|
||||
// var service1 = RoomServiceManager.Get(host.ID, service.AlarmCode);
|
||||
// RoomServiceManager.ClearRoomService(item, service1, User.Identity.Name);
|
||||
// }
|
||||
//}
|
||||
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("CleanupServices"), name);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("CleanupSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("CleanupFailedReason") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ActionResult ExportExcel()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
|
||||
|
||||
NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
|
||||
|
||||
sheet1.SetColumnWidth(0, 10 * 256);
|
||||
sheet1.SetColumnWidth(1, 20 * 256);
|
||||
sheet1.SetColumnWidth(2, 20 * 256);
|
||||
sheet1.SetColumnWidth(3, 20 * 256);
|
||||
|
||||
NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
|
||||
row1.CreateCell(0).SetCellValue(HttpContext.InnerLanguage("RoomNumber"));
|
||||
row1.CreateCell(1).SetCellValue(HttpContext.InnerLanguage("ServiceType"));
|
||||
row1.CreateCell(2).SetCellValue(HttpContext.InnerLanguage("StartDate"));
|
||||
row1.CreateCell(3).SetCellValue(HttpContext.InnerLanguage("Deadline"));
|
||||
row1.CreateCell(4).SetCellValue(HttpContext.InnerLanguage("TotalTime"));
|
||||
|
||||
Models.QueryConditionModel model = Session["QueryConditionModel"] as Models.QueryConditionModel;
|
||||
//var list = Session["ServiceList"] as IList<RoomServiceRecord>;
|
||||
|
||||
long total = 0;
|
||||
string[] services = null;
|
||||
if (!String.IsNullOrWhiteSpace(model.AlarmCodes))
|
||||
{
|
||||
services = model.AlarmCodes.Split(',');
|
||||
}
|
||||
|
||||
var list = RoomServiceRecordManager.LoadAllByPage(out total, 1, 10000, model.Order, model.Sort, model.RoomNumber,
|
||||
model.StartTime, model.EndTime, services);
|
||||
|
||||
list = (IList<RoomServiceRecord>)list.Where(r => r.HostID == CurrentHotelID);
|
||||
|
||||
if (list != null)
|
||||
{
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
NPOI.SS.UserModel.IRow row = sheet1.CreateRow(i + 1);
|
||||
row.CreateCell(0).SetCellValue(list[i].RoomNumber);
|
||||
row.CreateCell(1).SetCellValue(list[i].Name);
|
||||
row.CreateCell(2).SetCellValue(list[i].StartTime.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
row.CreateCell(3).SetCellValue(list[i].EndTime.HasValue ? list[i].EndTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : "");
|
||||
Double totalMinutes = list[i].EndTime.HasValue ? (list[i].EndTime.Value - list[i].StartTime).TotalMinutes : (DateTime.Now - list[i].StartTime).TotalMinutes;
|
||||
row.CreateCell(4).SetCellValue(Math.Floor(totalMinutes / 60) + HttpContext.InnerLanguage("Hour") + Math.Ceiling(totalMinutes % 60) + HttpContext.InnerLanguage("Minute"));
|
||||
}
|
||||
}
|
||||
|
||||
using (MemoryStream stream = new MemoryStream())
|
||||
{
|
||||
book.Write(stream);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
string filename = Common.Tools.ToUtf8String(HttpContext.InnerLanguage("ServiceQuery") + ".xls");
|
||||
|
||||
return File(stream, "application/vnd.ms-excel", filename);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("Export") + ex.Message }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
}
|
||||
}
|
||||
public class TempLinShiClass
|
||||
{
|
||||
public string HostID;
|
||||
public string RoomTypeModalID;
|
||||
public string RoomNumber;
|
||||
public string Name;
|
||||
public object Time;
|
||||
public string HostNumber { get; set; }
|
||||
public string ModalAddress { get; set; }
|
||||
}
|
||||
}
|
||||
1094
WebSite/Controllers/RoomStatusController.cs
Normal file
1094
WebSite/Controllers/RoomStatusController.cs
Normal file
File diff suppressed because it is too large
Load Diff
16
WebSite/Controllers/RoomTypeAirController.cs
Normal file
16
WebSite/Controllers/RoomTypeAirController.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class RoomTypeAirController : BaseController
|
||||
{
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
123
WebSite/Controllers/RoomTypeChannelsController.cs
Normal file
123
WebSite/Controllers/RoomTypeChannelsController.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Dynamic;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Xml;
|
||||
using Common;
|
||||
using Domain;
|
||||
using Service;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class RoomTypeChannelsController : BaseController
|
||||
{
|
||||
#region Properties
|
||||
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(RoomTypeChannelsController));
|
||||
private const int AUTHORITY_RoomType = 20;
|
||||
public IRoomTypeChannelsManager RoomTypeChannelsManager { get; set; }
|
||||
public IRoomTypeManager RoomTypeManager { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Index(int roomTypeID)
|
||||
{
|
||||
return View(roomTypeID);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取当前房型的电视频道
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="rows"></param>
|
||||
/// <param name="order"></param>
|
||||
/// <param name="sort"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadAllByPage(int page, int rows, string order, string sort, int roomTypeID)
|
||||
{
|
||||
long total = 0;
|
||||
var list = this.RoomTypeChannelsManager.LoadAllByPage(out total, page, rows, order, sort, roomTypeID);
|
||||
var result = list.Select(r => new
|
||||
{
|
||||
r.ID,
|
||||
RoomTypeID = r.RoomType.ID,
|
||||
RoomTypeName = r.RoomType.Name,
|
||||
r.Code,
|
||||
r.Name,
|
||||
r.Sort
|
||||
});
|
||||
return Json(new { total = total, rows = result });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAll(int roomTypeID)
|
||||
{
|
||||
var list = this.RoomTypeChannelsManager.LoadAll(roomTypeID);
|
||||
var result = list.Select(r => new
|
||||
{
|
||||
r.ID,
|
||||
r.Code,
|
||||
Name = r.Code + "-" + r.Name
|
||||
});
|
||||
return Json(new { rows = result });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Edit(int id, int roomTypeID)
|
||||
{
|
||||
if (id != 0)
|
||||
{
|
||||
return View(RoomTypeChannelsManager.Get(id));
|
||||
}
|
||||
RoomType roomType = RoomTypeManager.Get(roomTypeID);
|
||||
return View(new RoomTypeChannels { ID = 0, RoomType = roomType });//"~/Views/RoomTypeChannels/Edit.ascx",
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Save(string jsonData, int roomTypeID)
|
||||
{
|
||||
RoomTypeChannels entity = Newtonsoft.Json.JsonConvert.DeserializeObject<RoomTypeChannels>(jsonData);
|
||||
RoomType roomType = RoomTypeManager.Get(roomTypeID);
|
||||
entity.RoomType = roomType;
|
||||
if (entity.ID == 0)
|
||||
{
|
||||
RoomTypeChannelsManager.Save(entity);
|
||||
SaveSystemLog(AUTHORITY_RoomType, HttpContext.InnerLanguage("New"), entity.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
RoomTypeChannels roomTypeChannel = RoomTypeChannelsManager.Get(entity.ID);
|
||||
roomTypeChannel.Code = entity.Code;
|
||||
roomTypeChannel.Name = entity.Name;
|
||||
roomTypeChannel.Sort = entity.Sort;
|
||||
RoomTypeChannelsManager.Update(roomTypeChannel);
|
||||
SaveSystemLog(AUTHORITY_RoomType, HttpContext.InnerLanguage("Edit"), entity.Name);
|
||||
}
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Delete(IList<int> idList)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (idList != null && idList.Count > 0)
|
||||
{
|
||||
RoomTypeChannelsManager.Delete(idList.Cast<object>().ToList());
|
||||
string logDetail = String.Join(",", idList);
|
||||
SaveSystemLog(AUTHORITY_RoomType, HttpContext.InnerLanguage("Delete"), logDetail);
|
||||
}
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeletedSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex);
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("DeleteFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1284
WebSite/Controllers/RoomTypeController.cs
Normal file
1284
WebSite/Controllers/RoomTypeController.cs
Normal file
File diff suppressed because it is too large
Load Diff
388
WebSite/Controllers/RoomTypeSceneController.cs
Normal file
388
WebSite/Controllers/RoomTypeSceneController.cs
Normal file
@@ -0,0 +1,388 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Common;
|
||||
using Domain;
|
||||
using Service;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class RoomTypeSceneController : BaseController
|
||||
{
|
||||
private const int AUTHORITY_RoomTypeScene = 32;
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(RoomTypeSceneController));
|
||||
public IRoomTypeSceneManager RoomTypeSceneManager { get; set; }
|
||||
public IRoomTypeSceneModalManager RoomTypeSceneModalManager { get; set; }
|
||||
public IRoomTypeManager RoomTypeManager { get; set; }
|
||||
public IRoomTypeModalManager RoomTypeModalManager { get; set; }
|
||||
public IHostSceneManager HostSceneManager { get; set; }
|
||||
public IHostTimingControlManager HostTimingControlManager { get; set; }
|
||||
|
||||
#region Actions
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View("SimonIndex");
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Edit(int id, int roomTypeID)
|
||||
{
|
||||
if (id != 0)
|
||||
{
|
||||
return View(RoomTypeSceneManager.Get(id));
|
||||
}
|
||||
RoomType roomType = RoomTypeManager.Get(roomTypeID);
|
||||
return View("~/Views/RoomTypeScene/Edit.ascx", new RoomTypeScene { ID = 0, RoomType = roomType });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAll(int? roomTypeID, int? hostID)
|
||||
{
|
||||
IList<RoomTypeScene> list = new List<RoomTypeScene>();
|
||||
if (roomTypeID.HasValue && roomTypeID > 0)
|
||||
{
|
||||
list = RoomTypeSceneManager.LoadAll().Where(r => r.RoomType.ID == roomTypeID).ToList();
|
||||
if (hostID.HasValue && hostID > 0)
|
||||
{
|
||||
var hostSceneList = HostSceneManager.LoadByHostID((int)hostID);
|
||||
foreach (RoomTypeScene r in list)
|
||||
{
|
||||
int status = 2;
|
||||
foreach (HostScene h in hostSceneList)
|
||||
{
|
||||
if (r.ID == h.Scene.ID)
|
||||
{
|
||||
status = h.Status;
|
||||
break;
|
||||
}
|
||||
}
|
||||
r.Name = ReturnNameByLanguage(r.Name, r.EnglishName, r.TWName) + "(" + (status == 1 ? HttpContext.InnerLanguage("On") : HttpContext.InnerLanguage("Off")) + ")";
|
||||
}
|
||||
return Json(list.Select(r => new { r.ID, r.Name }));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(list.Select(r => new { r.ID, Name = ReturnNameByLanguage(r.Name, r.EnglishName, r.TWName) }));
|
||||
}
|
||||
}
|
||||
return Json(list);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAllByPage(int page, int rows, string order, string sort, int roomTypeID)
|
||||
{
|
||||
long total = 0;
|
||||
var list = RoomTypeSceneManager.LoadAllByPage(out total, page, rows, order, sort, CurrentHotelID, roomTypeID).ToList();
|
||||
var result = list.Select(r => new
|
||||
{
|
||||
r.ID,
|
||||
RoomTypeID = r.RoomType.ID,
|
||||
RoomTypeName = r.RoomType.Name,
|
||||
r.GroupAddress,
|
||||
r.EnglishName,
|
||||
Type = EnumDescription.GetDescription(r.Type),
|
||||
r.Name,
|
||||
r.TWName,
|
||||
r.ActiveIndicator,
|
||||
r.TakeInverse,
|
||||
r.Sort,
|
||||
r.AliasName
|
||||
});
|
||||
return Json(new { total = total, rows = result });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadRoomTypeSceneModals(int? roomTypeSceneID)//新增场景网格数据显示
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<RoomTypeSceneModal> list = new List<RoomTypeSceneModal>();
|
||||
var scene = RoomTypeSceneManager.Get(roomTypeSceneID);
|
||||
if (scene != null)
|
||||
{
|
||||
list = RoomTypeSceneModalManager.LoadAll(scene);
|
||||
}
|
||||
//查询数据库
|
||||
var result = list.Select(s =>
|
||||
{
|
||||
return new
|
||||
{
|
||||
s.Modal.ID,
|
||||
s.Modal.ModalAddress,
|
||||
Name = ReturnNameByLanguage(s.Modal.Name, s.Modal.EnglishName, s.Modal.TWName),
|
||||
Type = s.Modal.Type.ToString(),
|
||||
TypeName = HttpContext.InnerLanguage(s.Modal.Type.ToString()),
|
||||
s.Status,
|
||||
s.Brightness,
|
||||
s.CurrentTemp,
|
||||
s.Mode,
|
||||
s.FanSpeed,
|
||||
s.Valve
|
||||
};
|
||||
})
|
||||
.OrderBy(o => o.ID)
|
||||
.OrderByDescending(o => o.Status)
|
||||
.ToList();
|
||||
|
||||
return Json(new { total = result.Count(), rows = result });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("LoadDataFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载设备回路
|
||||
/// </summary>
|
||||
/// <param name="roomTypeId"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadDevices(int roomTypeId)
|
||||
{
|
||||
IList<RoomTypeModal> list = new List<RoomTypeModal>();
|
||||
var roomType = RoomTypeManager.Load(roomTypeId);
|
||||
if (roomType != null)
|
||||
{
|
||||
list = RoomTypeModalManager.LoadAll(roomType, 0).Where(r => r.ActiveIndicator).ToList();
|
||||
}
|
||||
var result = list.Select(r => new
|
||||
{
|
||||
r.ID,
|
||||
r.ModalAddress,
|
||||
r.Name,
|
||||
Type = r.Type.ToString(),
|
||||
TypeName = HttpContext.InnerLanguage(r.Type.ToString())
|
||||
});
|
||||
return Json(new { total = list.Count(), rows = result });
|
||||
}
|
||||
//保存场景
|
||||
[Authorize]
|
||||
public ActionResult Save(string jsonData)
|
||||
{
|
||||
try
|
||||
{
|
||||
IDictionary<string, object> json = Newtonsoft.Json.JsonConvert.DeserializeObject<IDictionary<string, object>>(jsonData);
|
||||
int roomTypeSceneID = 0;
|
||||
if (json.ContainsKey("ID"))
|
||||
{
|
||||
roomTypeSceneID = Convert.ToInt32(json["ID"]);
|
||||
}
|
||||
RoomType roomType = null;
|
||||
if (json.ContainsKey("RoomTypeID"))
|
||||
{
|
||||
roomType = RoomTypeManager.Get(Convert.ToInt32(json["RoomTypeID"]));
|
||||
}
|
||||
SceneType type = SceneType.Custom;
|
||||
if (json.ContainsKey("Type"))
|
||||
{
|
||||
type = (SceneType)Convert.ToInt32(json["Type"]);
|
||||
}
|
||||
string name = "";
|
||||
if (json.ContainsKey("Name"))
|
||||
{
|
||||
name = json["Name"].ToString();
|
||||
}
|
||||
string aliasName = "";
|
||||
if (json.ContainsKey("AliasName"))
|
||||
{
|
||||
aliasName = json["AliasName"].ToString();
|
||||
}
|
||||
string englishName = "";
|
||||
if (json.ContainsKey("EnglishName"))
|
||||
{
|
||||
englishName = json["EnglishName"].ToString();
|
||||
}
|
||||
string twName = "";
|
||||
if (json.ContainsKey("TWName"))
|
||||
{
|
||||
twName = json["TWName"].ToString();
|
||||
}
|
||||
string groupAddress = "";
|
||||
if (json.ContainsKey("GroupAddress"))
|
||||
{
|
||||
groupAddress = json["GroupAddress"].ToString();
|
||||
}
|
||||
int sort = 1;
|
||||
if (json.ContainsKey("Sort"))
|
||||
{
|
||||
sort = Convert.ToInt16(json["Sort"].ToString());
|
||||
}
|
||||
RoomTypeScene existRoomTypeScene = RoomTypeSceneManager.Get(roomType, name);
|
||||
RoomTypeScene roomTypeScene = null;
|
||||
if (roomTypeSceneID == 0)
|
||||
{
|
||||
//新增
|
||||
if (existRoomTypeScene != null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = String.Format("【{0}】【{1}】" + HttpContext.InnerLanguage("PatternAlreadyExists"), roomType.Name, name) });
|
||||
}
|
||||
roomTypeScene = new RoomTypeScene();
|
||||
roomTypeScene.ID = roomTypeSceneID;
|
||||
roomTypeScene.RoomType = roomType;
|
||||
roomTypeScene.Name = name;
|
||||
roomTypeScene.EnglishName = englishName;
|
||||
roomTypeScene.TWName = twName;
|
||||
roomTypeScene.Type = type;
|
||||
roomTypeScene.GroupAddress = groupAddress;
|
||||
roomTypeScene.HotelID = CurrentHotelID;
|
||||
roomTypeScene.Sort = sort;
|
||||
roomTypeScene.AliasName = aliasName;
|
||||
|
||||
RoomTypeSceneManager.Save(roomTypeScene);
|
||||
|
||||
string logDetail = HttpContext.InnerLanguage("SceneType" + roomTypeScene.Type.ToString()) + "【" + (Language == Language.CN ? roomTypeScene.Name : roomTypeScene.EnglishName) + "】";
|
||||
SaveSystemLog(AUTHORITY_RoomTypeScene, HttpContext.InnerLanguage("New"), logDetail);
|
||||
}
|
||||
else
|
||||
{
|
||||
//更新
|
||||
if (existRoomTypeScene != null && existRoomTypeScene.ID != roomTypeSceneID)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = String.Format("【{0}】【{1}】" + HttpContext.InnerLanguage("PatternAlreadyExists"), roomType.Name, name) });
|
||||
}
|
||||
else
|
||||
{
|
||||
roomTypeScene = existRoomTypeScene;
|
||||
}
|
||||
roomTypeScene = RoomTypeSceneManager.Get(roomTypeSceneID);
|
||||
roomTypeScene.RoomType = roomType;
|
||||
roomTypeScene.Type = type;
|
||||
roomTypeScene.Name = name;
|
||||
roomTypeScene.EnglishName = englishName;
|
||||
roomTypeScene.TWName = twName;
|
||||
roomTypeScene.GroupAddress = groupAddress;
|
||||
roomTypeScene.HotelID = CurrentHotelID;
|
||||
roomTypeScene.Sort = sort;
|
||||
roomTypeScene.AliasName = aliasName;
|
||||
|
||||
RoomTypeSceneManager.Update(roomTypeScene);
|
||||
|
||||
foreach (var modal in RoomTypeSceneModalManager.LoadAll(roomTypeScene))
|
||||
{
|
||||
RoomTypeSceneModalManager.Delete(modal.ID);
|
||||
}
|
||||
|
||||
string logDetail = HttpContext.InnerLanguage("SceneType" + roomTypeScene.Type.ToString()) + "【" + (Language == Language.CN ? roomTypeScene.Name : roomTypeScene.EnglishName) + "】";
|
||||
|
||||
SaveSystemLog(AUTHORITY_RoomTypeScene, HttpContext.InnerLanguage("Edit"), logDetail);
|
||||
}
|
||||
if (type == SceneType.Custom && json.ContainsKey("Modals"))
|
||||
{
|
||||
foreach (var modal in DeserializeRoomTypeSceneModal(roomTypeScene, json["Modals"].ToString()))
|
||||
{
|
||||
RoomTypeSceneModalManager.Save(modal);
|
||||
}
|
||||
}
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error("保存场景失败:" + ex);
|
||||
SaveSystemLog(AUTHORITY_RoomTypeScene, HttpContext.InnerLanguage("NewOrEdit"), ex.Message, false);
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SaveFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存取反信息
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="activeIndicator"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult SaveTakeInverseChange(int id, bool activeIndicator)
|
||||
{
|
||||
try
|
||||
{
|
||||
var modal = RoomTypeSceneManager.Get(id);
|
||||
if (modal == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidMenu"));
|
||||
}
|
||||
modal.TakeInverse = activeIndicator;
|
||||
RoomTypeSceneManager.Update(modal);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error("保存场景取反失败:" + ex);
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SaveFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
//删除场景
|
||||
[Authorize]
|
||||
public ActionResult Delete(IList<int> idList)
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<string> sceneList = new List<string>();
|
||||
foreach (int id in idList)
|
||||
{
|
||||
var scene = RoomTypeSceneManager.Get(id);
|
||||
if (scene != null)
|
||||
{
|
||||
sceneList.Add(HttpContext.InnerLanguage("SceneType" + scene.Type.ToString()) + "【" + (Language == Language.CN ? scene.Name : scene.EnglishName) + "】");
|
||||
|
||||
HostSceneManager.DeteleByRoomTypeScene(id);//删除主机执行场景记录
|
||||
var roomTypeSceneModalList = RoomTypeSceneModalManager.LoadAll(scene);
|
||||
foreach (var modal in roomTypeSceneModalList)
|
||||
{
|
||||
RoomTypeSceneModalManager.Delete(modal.ID);//删除场景关联回路
|
||||
}
|
||||
var hostTimingList = HostTimingControlManager.LoadAll().Where(r => r.RoomTypeSceneID == id).ToList();
|
||||
foreach (var timing in hostTimingList)
|
||||
{
|
||||
HostTimingControlManager.Delete(timing.ID);//删除场景关联定时任务
|
||||
}
|
||||
|
||||
RoomTypeSceneManager.Delete(id);//场景主表
|
||||
}
|
||||
}
|
||||
SaveSystemLog(AUTHORITY_RoomTypeScene, HttpContext.InnerLanguage("Delete"), String.Join(",", sceneList.ToArray()));
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error("删除场景失败:" + ex);
|
||||
SaveSystemLog(AUTHORITY_RoomTypeScene, HttpContext.InnerLanguage("Delete"), ex.Message, false);
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("DeleteFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region Private Methods
|
||||
/// <summary>
|
||||
/// 将json格式的数据反序列化为RoomTypeSceneModal
|
||||
/// </summary>
|
||||
/// <param name="roomTypeSceneID"></param>
|
||||
/// <param name="jsonData"></param>
|
||||
/// <returns></returns>
|
||||
private IList<RoomTypeSceneModal> DeserializeRoomTypeSceneModal(RoomTypeScene scene, string jsonData)
|
||||
{
|
||||
IList<RoomTypeSceneModal> roomTypeSceneModals = new List<RoomTypeSceneModal>();
|
||||
IList<IDictionary<string, object>> modals = Newtonsoft.Json.JsonConvert.DeserializeObject<IList<IDictionary<string, object>>>(jsonData);
|
||||
foreach (IDictionary<string, object> modal in modals)
|
||||
{
|
||||
roomTypeSceneModals.Add(new RoomTypeSceneModal
|
||||
{
|
||||
Scene = scene,
|
||||
Modal = RoomTypeModalManager.Get(Convert.ToInt32(modal["ID"])),
|
||||
Status = Convert.ToInt32(modal["Status"]),
|
||||
Brightness = Convert.ToInt32(modal["Brightness"]),
|
||||
CurrentTemp = Convert.ToInt32(modal["CurrentTemp"]),
|
||||
Mode = Convert.ToInt32(modal["Mode"]),
|
||||
FanSpeed = Convert.ToInt32(modal["FanSpeed"]),
|
||||
Valve = Convert.ToInt32(modal["Valve"])
|
||||
});
|
||||
}
|
||||
return roomTypeSceneModals;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
267
WebSite/Controllers/SearchHostController.cs
Normal file
267
WebSite/Controllers/SearchHostController.cs
Normal file
@@ -0,0 +1,267 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Dynamic;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class SearchHostController : BaseController
|
||||
{
|
||||
public ISearchHostManager SearchHostManager { get; set; }
|
||||
|
||||
public IHostManager HostManager { get; set; }
|
||||
|
||||
public IGroupManager GroupManager { get; set; }
|
||||
|
||||
public IRoomTypeManager RoomTypeManager { get; set; }
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult RegisterHost(string hostNumber, string ip, string subnetmask, string gateway, int port, string mac, string version, string configVersion)
|
||||
{
|
||||
var host = HostManager.GetByMAC(mac, CurrentHotelID);
|
||||
if (host != null)
|
||||
{
|
||||
host.HostNumber = hostNumber;
|
||||
host.IP = ip;
|
||||
host.SubnetMask = subnetmask;
|
||||
host.Gateway = gateway;
|
||||
host.Port = port;
|
||||
host.Version = version;
|
||||
host.ConfigVersion = configVersion;
|
||||
|
||||
return View(host);
|
||||
}
|
||||
|
||||
return View(new Host
|
||||
{
|
||||
ID = 0,
|
||||
HostNumber = hostNumber,
|
||||
Version = version,
|
||||
ConfigVersion = configVersion,
|
||||
RoomNumber = hostNumber,
|
||||
IP = ip,
|
||||
SubnetMask = subnetmask,
|
||||
Gateway = gateway,
|
||||
Port = port,
|
||||
MAC = mac,
|
||||
Group = null,
|
||||
Remark = ""
|
||||
});
|
||||
}
|
||||
|
||||
public ActionResult RegisterHosts(string hosts, int groupId, int roomTypeId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var group = GroupManager.Get(groupId);
|
||||
if (group == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidFloor"));
|
||||
}
|
||||
|
||||
var roomType = RoomTypeManager.Get(roomTypeId);
|
||||
if (roomType == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidRoomType"));
|
||||
}
|
||||
|
||||
var hostList = JsonConvert.DeserializeObject<List<SearchHost>>(hosts);
|
||||
if (hostList == null || hostList.Count == 0)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("PleaseSelectRegisteredHost"));
|
||||
}
|
||||
|
||||
foreach (var host in hostList)
|
||||
{
|
||||
if (host.Registered)
|
||||
{
|
||||
var entity = HostManager.GetByMAC(host.MAC, CurrentHotelID);
|
||||
|
||||
entity.Group = group;
|
||||
entity.RoomType = roomType;
|
||||
entity.IP = host.IP;
|
||||
entity.SubnetMask = host.SubnetMask;
|
||||
entity.Gateway = host.Gateway;
|
||||
entity.Port = host.Port;
|
||||
entity.HostNumber = host.HostNumber;
|
||||
entity.Version = host.Version;
|
||||
entity.ConfigVersion = host.ConfigVersion;
|
||||
|
||||
HostManager.Update(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = new Host();
|
||||
|
||||
entity.Group = group;
|
||||
entity.RoomType = roomType;
|
||||
entity.MAC = host.MAC;
|
||||
entity.IP = host.IP;
|
||||
entity.SubnetMask = host.SubnetMask;
|
||||
entity.Gateway = host.Gateway;
|
||||
entity.Port = host.Port;
|
||||
entity.HostNumber = host.HostNumber;
|
||||
entity.RoomNumber = host.HostNumber;
|
||||
entity.Version = host.Version;
|
||||
entity.ConfigVersion = host.ConfigVersion;
|
||||
|
||||
HostManager.Save(entity);
|
||||
}
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("RegisterSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("RegisterFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public ActionResult StartSearch(int registered)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!String.IsNullOrEmpty(SearchHostManager.User))
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("User") + "【" + SearchHostManager.User + "】" + HttpContext.InnerLanguage("SearchingForAHostTheSameTimeThereCanBeOnlyOneUserSearchHost"));
|
||||
}
|
||||
|
||||
IList<SearchHost> hostList = Session["HostList"] as IList<SearchHost>;
|
||||
if (hostList == null)
|
||||
{
|
||||
hostList = new List<SearchHost>();
|
||||
}
|
||||
SearchHostManager.Start(delegate(SearchHost host)
|
||||
{
|
||||
if (hostList == null)
|
||||
{
|
||||
SearchHostManager.Stop();
|
||||
}
|
||||
//如果存在缓存中,则不再添加
|
||||
SearchHost msg = hostList.FirstOrDefault(r => r.MAC == host.MAC);
|
||||
if (msg == null)
|
||||
{
|
||||
if (SearchHostManager.UpdateHost(host, CurrentHotelID))//如已注册,则更新子网掩码等信息
|
||||
{
|
||||
host.Registered = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
host.Registered = false;
|
||||
}
|
||||
if (registered == 0 ||
|
||||
(registered == 1 && host.Registered) ||
|
||||
(registered == 2 && !host.Registered))
|
||||
{
|
||||
hostList.Add(host);
|
||||
}
|
||||
}
|
||||
});
|
||||
Session["HostList"] = hostList;
|
||||
SearchHostManager.User = User.Identity.Name;
|
||||
|
||||
return Json(new { IsSuccess = true });
|
||||
}
|
||||
catch (ApplicationException ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public ActionResult ClearSearchResult()
|
||||
{
|
||||
IList<SearchHost> hostList = Session["HostList"] as IList<SearchHost>;
|
||||
if (hostList != null)
|
||||
{
|
||||
hostList.Clear();
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true });
|
||||
}
|
||||
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public ActionResult GetSearchResult(int page, int rows, string order, string sort)
|
||||
{
|
||||
SearchHostManager.Start();
|
||||
|
||||
var list = Session["HostList"] as IList<SearchHost>;
|
||||
//var list = MockHosts();
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
list = new List<SearchHost>();
|
||||
}
|
||||
var result = list.AsQueryable().OrderBy(sort + " " + order).Skip((page - 1) * rows).Take(rows);
|
||||
|
||||
return Json(new { IsSuccess = true, Data = new { total = list.Count(), rows = result } });
|
||||
//return Json(new { IsSuccess = false });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Searching()
|
||||
{
|
||||
if (SearchHostManager.User == this.User.Identity.Name)
|
||||
{
|
||||
return Json(new { IsSuccess = true, searching = SearchHostManager.Searching });
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, searching = false });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public ActionResult StopSearch()
|
||||
{
|
||||
SearchHostManager.Stop();
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("StoppedSearching") });
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
private IList<SearchHost> MockHosts()
|
||||
{
|
||||
var hosts = new List<SearchHost>();
|
||||
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.111", HostNumber = "101", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-51", Version = "1.0.1", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.112", HostNumber = "102", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-52", Version = "1.0.2", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.113", HostNumber = "103", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-53", Version = "1.0.3", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.114", HostNumber = "104", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-54", Version = "1.0.4", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.115", HostNumber = "105", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-55", Version = "1.0.5", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.116", HostNumber = "106", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-56", Version = "1.0.6", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.117", HostNumber = "107", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-57", Version = "1.0.7", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.118", HostNumber = "108", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-58", Version = "1.0.8", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.119", HostNumber = "109", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-59", Version = "1.0.9", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.120", HostNumber = "110", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-60", Version = "1.0.10", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.121", HostNumber = "111", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-61", Version = "1.0.1", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.122", HostNumber = "112", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-62", Version = "1.0.2", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.123", HostNumber = "113", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-63", Version = "1.0.3", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.124", HostNumber = "114", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-64", Version = "1.0.4", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.125", HostNumber = "115", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-65", Version = "1.0.5", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.126", HostNumber = "116", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-66", Version = "1.0.6", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.127", HostNumber = "117", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-67", Version = "1.0.7", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.128", HostNumber = "118", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-68", Version = "1.0.8", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.129", HostNumber = "119", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-69", Version = "1.0.9", ConfigVersion = "1.1.000" });
|
||||
hosts.Add(new SearchHost { Registered = true, IP = "192.168.1.130", HostNumber = "120", SubnetMask = "255.255.255.0", Gateway = "192.168.1.1", Port = 3341, MAC = "D0-50-99-56-51-70", Version = "1.0.10", ConfigVersion = "1.1.000" });
|
||||
|
||||
return hosts;
|
||||
}
|
||||
#endif //#if DEBUG
|
||||
}
|
||||
}
|
||||
19
WebSite/Controllers/SwaiotController.cs
Normal file
19
WebSite/Controllers/SwaiotController.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class SwaiotController : BaseController
|
||||
{
|
||||
|
||||
[HttpGet()]
|
||||
public ActionResult ZhuYe()
|
||||
{
|
||||
return Json(new { });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
35
WebSite/Controllers/SysAuthorityController.cs
Normal file
35
WebSite/Controllers/SysAuthorityController.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Service;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class SysAuthorityController : BaseController
|
||||
{
|
||||
public ISysAuthorityManager SysAuthorityManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult LoadAll()
|
||||
{
|
||||
var list = SysAuthorityManager.LoadAll().Where(r => r.ParentID != 0 && r.IsMenu && r.ActiveIndicator && r.IsLog).OrderBy(r => r.ID);
|
||||
|
||||
var result = list.Select(r => new { r.ID, Name = ReturnNameByLanguage(r.Name, r.EName, r.TWName) }).ToList();
|
||||
|
||||
result.Insert(0, new { ID = 0, Name = HttpContext.InnerLanguage("All") });
|
||||
|
||||
return Json(result);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
705
WebSite/Controllers/SysHotelController.cs
Normal file
705
WebSite/Controllers/SysHotelController.cs
Normal file
@@ -0,0 +1,705 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Service;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using CommonEntity;
|
||||
using Common;
|
||||
using WebSite.Models;
|
||||
using RestSharp;
|
||||
using System.Configuration;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class SysHotelController : BaseController
|
||||
{
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(SysHotelController));
|
||||
private const int AuthorityID = 54;
|
||||
/// <summary>
|
||||
/// 酒店编辑权限ID
|
||||
/// </summary>
|
||||
private const int AUTHORITY_EditHotel = 1005;
|
||||
|
||||
public ISysHotelManager SysHotelManager { get; set; }
|
||||
public IGroupManager GroupManager { get; set; }
|
||||
public IAlarmSettingManager AlarmSettingManager { get; set; }
|
||||
public IAppMenuManager AppMenuManager { get; set; }
|
||||
public IRoomTypeManager RoomTypeManager { get; set; }
|
||||
public ISysHotelGroupManager SysHotelGroupManager { get; set; }
|
||||
public ISysUserManager SysUserManager { get; set; }
|
||||
public ISysProvinceManager SysProvinceManager { get; set; }
|
||||
public IHostManager HostManager { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 空调ECO
|
||||
///
|
||||
/// 阿宝添加的
|
||||
/// </summary>
|
||||
public IECO_SettingMananger Air_ECO_SettingManager { get; set; }
|
||||
public IECO_RoomDetailManager RoomDetailManager { get; set; }
|
||||
public ILieECOMananger LieECOManager { get; set; }
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
ViewData["EditHotel"] = SysUserManager.HasAuthority(User.Identity.Name, AUTHORITY_EditHotel);
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Edit(int? id)
|
||||
{
|
||||
ViewData["IsApprove"] = false;
|
||||
switch (User.Identity.Name.ToLower())
|
||||
{
|
||||
case "admin":
|
||||
case "leo":
|
||||
case "blw":
|
||||
ViewData["IsApprove"] = true;
|
||||
break;
|
||||
}
|
||||
if (id.HasValue)
|
||||
{
|
||||
return View(SysHotelManager.Get(id.Value));
|
||||
}
|
||||
var lastHotel = SysHotelManager.LoadAll().OrderByDescending(r => r.Code).FirstOrDefault();
|
||||
int code = Convert.ToInt16(lastHotel.Code) + 1;
|
||||
return View(new SysHotel { ID = 0, Code = code.ToString(), Sort = code, Styles = "0", ValidateDate = DateTime.Now.AddYears(1).AddMonths(4), Status = 2, IsApprove = false });
|
||||
}
|
||||
|
||||
public ActionResult EditDockingInfo()
|
||||
{
|
||||
var q = SysHotelManager.Get(CurrentHotelID);
|
||||
return View(q);
|
||||
}
|
||||
|
||||
public ActionResult LoadAll()
|
||||
{
|
||||
var list = SysHotelManager.LoadAll().OrderBy(o => o.Sort).ToList();
|
||||
var result = list.Select(r => new { r.ID, Name = r.Code + "-" + ReturnNameByLanguage(r.Name, r.EName, r.TWName), r.Code }).ToList();
|
||||
//result.Insert(0, new { ID = 0, Name = HttpContext.InnerLanguage("All") });
|
||||
return Json(result);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAllByPage(int page, int rows, string order, string sort, string query, int? groupId)
|
||||
{
|
||||
if (groupId.HasValue)
|
||||
{
|
||||
long total = 0;
|
||||
IList<SysHotel> list = this.SysHotelManager.LoadAllByPage(out total, page, rows, order, sort, query, groupId);
|
||||
IList<SysProvince> province = SysProvinceManager.LoadAll();
|
||||
IList<SysCity> city = SysProvinceManager.LoadAllCity();
|
||||
IList<SysCounty> county = SysProvinceManager.LoadAllCounty();
|
||||
foreach (SysHotel hotel in list)
|
||||
{
|
||||
hotel.SysHotelGroupName = hotel.SysHotelGroup == null ? "" : hotel.SysHotelGroup.Name;
|
||||
if (!string.IsNullOrEmpty(hotel.ProvinceCode))
|
||||
{
|
||||
hotel.Address = province.Where(r => r.Code == hotel.ProvinceCode).FirstOrDefault().Name +
|
||||
city.Where(r => r.Code == hotel.CityCode).FirstOrDefault().Name +
|
||||
county.Where(r => r.Code == hotel.CountyCode).FirstOrDefault().Name + hotel.Address;
|
||||
}
|
||||
}
|
||||
return Json(new { total = total, rows = list });
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { total = 0, rows = new List<object>() });
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Save(string jsonData)
|
||||
{
|
||||
var entity = Newtonsoft.Json.JsonConvert.DeserializeObject<SysHotel>(jsonData);
|
||||
var existCode = SysHotelManager.GetByCode(entity.Code);
|
||||
if (entity.ID == 0 && existCode != null)//如果新增酒店,并且code已存在,则自动取最新的酒店code+1
|
||||
{
|
||||
var lastHotel = SysHotelManager.LoadAll().OrderByDescending(r => r.Code).FirstOrDefault();
|
||||
entity.Sort = Convert.ToInt16(lastHotel.Code) + 1;
|
||||
entity.Code = entity.Sort.ToString();
|
||||
}
|
||||
string action = HttpContext.InnerLanguage("New");
|
||||
if (entity.ID == 0)
|
||||
{
|
||||
entity.ParentID = 0;
|
||||
entity.ActiveIndicator = true;
|
||||
entity.CreatedBy = entity.ModifiedBy = this.User.Identity.Name;
|
||||
entity.CreatedDate = entity.ModifiedDate = DateTime.Now;
|
||||
entity.LogoPath = "../Uploads/logo/1001.png";
|
||||
SysHotelManager.Save(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
var sysHotel = SysHotelManager.Get(entity.ID);
|
||||
sysHotel.Code = entity.Code;
|
||||
sysHotel.Name = entity.Name;
|
||||
sysHotel.EName = entity.EName;
|
||||
sysHotel.TWName = entity.TWName;
|
||||
sysHotel.Contact = entity.Contact;
|
||||
sysHotel.Phone = entity.Phone;
|
||||
sysHotel.Address = entity.Address;
|
||||
//sysHotel.AssociatedAccount = entity.AssociatedAccount;
|
||||
//sysHotel.Styles = entity.Styles;
|
||||
sysHotel.Sort = entity.Sort;
|
||||
sysHotel.ModifiedBy = this.User.Identity.Name;
|
||||
sysHotel.ModifiedDate = DateTime.Now;
|
||||
//sysHotel.IsAutoGetKey = entity.IsAutoGetKey;
|
||||
//sysHotel.WelcomeSpeech = entity.WelcomeSpeech;
|
||||
//sysHotel.GoodbyeSpeech = entity.GoodbyeSpeech;
|
||||
//sysHotel.DomainUrl = entity.DomainUrl;
|
||||
sysHotel.ValidateDate = entity.ValidateDate;
|
||||
//sysHotel.TVControlToken = entity.TVControlToken;
|
||||
//sysHotel.TVControlUrl = entity.TVControlUrl;
|
||||
//sysHotel.IsSyncPMS = entity.IsSyncPMS;
|
||||
//sysHotel.DeviceStatusPushURL = entity.DeviceStatusPushURL;
|
||||
sysHotel.SysHotelGroup = entity.SysHotelGroup;
|
||||
sysHotel.ProvinceCode = entity.ProvinceCode;
|
||||
sysHotel.CityCode = entity.CityCode;
|
||||
sysHotel.CountyCode = entity.CountyCode;
|
||||
sysHotel.Remark = entity.Remark;
|
||||
sysHotel.Status = entity.Status;
|
||||
sysHotel.IsApprove = entity.IsApprove;
|
||||
|
||||
SysHotelManager.Update(sysHotel);
|
||||
action = HttpContext.InnerLanguage("Edit");
|
||||
}
|
||||
SaveSystemLog(AuthorityID, action, entity.Name);
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存第三方对接信息
|
||||
/// </summary>
|
||||
/// <param name="jsonData"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult SaveDockingInfo(string jsonData)
|
||||
{
|
||||
var entity = Newtonsoft.Json.JsonConvert.DeserializeObject<SysHotel>(jsonData);
|
||||
var sysHotel = SysHotelManager.Get(entity.ID);
|
||||
sysHotel.IsAutoGetKey = entity.IsAutoGetKey;
|
||||
sysHotel.WelcomeSpeech = entity.WelcomeSpeech;
|
||||
sysHotel.GoodbyeSpeech = entity.GoodbyeSpeech;
|
||||
sysHotel.TVControlToken = entity.TVControlToken;
|
||||
sysHotel.TVControlUrl = entity.TVControlUrl;
|
||||
sysHotel.DeviceStatusPushURL = entity.DeviceStatusPushURL;
|
||||
sysHotel.FaultPushURL = entity.FaultPushURL;
|
||||
sysHotel.IsVoincePowerOn = entity.IsVoincePowerOn;//语音取电控制
|
||||
sysHotel.IsPowerOffResetXiaoDu = entity.IsPowerOffResetXiaoDu;//断电重置小度
|
||||
sysHotel.FCSPushEnable = entity.FCSPushEnable;
|
||||
sysHotel.IsNewVersionProtocol = entity.IsNewVersionProtocol;
|
||||
|
||||
sysHotel.FCS_PropertyID = entity.FCS_PropertyID;
|
||||
sysHotel.FCSLoginUrl = entity.FCSLoginUrl;
|
||||
sysHotel.FCSLoginUserName = entity.FCSLoginUserName;
|
||||
sysHotel.FCSLoginPassWord = entity.FCSLoginPassWord;
|
||||
|
||||
sysHotel.FCS_Carbon_UUID = entity.FCS_Carbon_UUID;
|
||||
sysHotel.FCS_SOS_UUID = entity.FCS_SOS_UUID;
|
||||
sysHotel.FCS_TouSu_UUID = entity.FCS_TouSu_UUID;
|
||||
sysHotel.FCS_Clean_UUID = entity.FCS_Clean_UUID;
|
||||
sysHotel.FCS_TiSongWuPin = entity.FCS_TiSongWuPin;
|
||||
sysHotel.FCS_RCU_Device_Offline = entity.FCS_RCU_Device_Offline;
|
||||
sysHotel.FCS_RCU_Offline = entity.FCS_RCU_Offline;
|
||||
sysHotel.FCS_RCU_Online = entity.FCS_RCU_Online;
|
||||
sysHotel.FCS_MenCi_Close = entity.FCS_MenCi_Close;
|
||||
sysHotel.FCS_MenCi_Open = entity.FCS_MenCi_Open;
|
||||
|
||||
|
||||
sysHotel.IsUseSkyworthTV = entity.IsUseSkyworthTV;
|
||||
sysHotel.IsUseTCLTV = entity.IsUseTCLTV;
|
||||
sysHotel.SkyworthTVauthCode = entity.SkyworthTVauthCode;
|
||||
sysHotel.TouSuResponseData = entity.TouSuResponseData;
|
||||
sysHotel.IsUseQianLiMa = entity.IsUseQianLiMa;
|
||||
sysHotel.IsPushPMSData = entity.IsPushPMSData;
|
||||
sysHotel.HeTongNumber = entity.HeTongNumber;
|
||||
//sysHotel.TCLAppId = entity.TCLAppId;
|
||||
//sysHotel.TCLAppSecret = entity.TCLAppSecret;
|
||||
SysHotelManager.Update(sysHotel);
|
||||
|
||||
if (sysHotel.IsUseQianLiMa)
|
||||
{
|
||||
QianLiMa_PMS.QiYong(sysHotel.Code, "add");
|
||||
}
|
||||
else
|
||||
{
|
||||
QianLiMa_PMS.QiYong(sysHotel.Code, "remove");
|
||||
}
|
||||
|
||||
//推送数据到PMS
|
||||
if (sysHotel.IsPushPMSData)
|
||||
{
|
||||
ServiceReference1.blwwsSoapClient b = new ServiceReference1.blwwsSoapClient();
|
||||
b.PushBaoJing_IsEnable("7e533rU:#3721M7%", sysHotel.Code, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ServiceReference1.blwwsSoapClient b = new ServiceReference1.blwwsSoapClient();
|
||||
b.PushBaoJing_IsEnable("7e533rU:#3721M7%", sysHotel.Code, false);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string code = sysHotel.Code;
|
||||
var LLL = HostManager.LoadAll(code);
|
||||
foreach (Host item in LLL)
|
||||
{
|
||||
Host TakeOut = null;
|
||||
string HostNumberOnly = item.HostNumber;
|
||||
string Key = CacheKey.HostInfo_Key_HostNumber + "_" + HostNumberOnly;
|
||||
object obj = MemoryCacheHelper.Get(Key);
|
||||
if (obj != null)
|
||||
{
|
||||
TakeOut = obj as Host;
|
||||
TakeOut.SysHotel.WelcomeSpeech = entity.WelcomeSpeech;
|
||||
TakeOut.SysHotel.IsAutoGetKey = entity.IsAutoGetKey;
|
||||
TakeOut.SysHotel.WelcomeSpeech = entity.WelcomeSpeech;
|
||||
TakeOut.SysHotel.GoodbyeSpeech = entity.GoodbyeSpeech;
|
||||
TakeOut.SysHotel.TVControlToken = entity.TVControlToken;
|
||||
TakeOut.SysHotel.TVControlUrl = entity.TVControlUrl;
|
||||
TakeOut.SysHotel.DeviceStatusPushURL = entity.DeviceStatusPushURL;
|
||||
TakeOut.SysHotel.FaultPushURL = entity.FaultPushURL;
|
||||
TakeOut.SysHotel.IsVoincePowerOn = entity.IsVoincePowerOn;//语音取电控制
|
||||
TakeOut.SysHotel.IsPowerOffResetXiaoDu = entity.IsPowerOffResetXiaoDu;//断电重置小度
|
||||
TakeOut.SysHotel.FCSPushEnable = entity.FCSPushEnable;//断电重置小度
|
||||
TakeOut.SysHotel.IsNewVersionProtocol = entity.IsNewVersionProtocol;
|
||||
|
||||
|
||||
TakeOut.SysHotel.FCS_PropertyID = entity.FCS_PropertyID;
|
||||
TakeOut.SysHotel.FCSLoginUrl = entity.FCSLoginUrl;
|
||||
TakeOut.SysHotel.FCSLoginUserName = entity.FCSLoginUserName;
|
||||
TakeOut.SysHotel.FCSLoginPassWord = entity.FCSLoginPassWord;
|
||||
|
||||
TakeOut.SysHotel.FCS_Carbon_UUID = entity.FCS_Carbon_UUID;
|
||||
TakeOut.SysHotel.FCS_SOS_UUID = entity.FCS_SOS_UUID;
|
||||
TakeOut.SysHotel.FCS_TouSu_UUID = entity.FCS_TouSu_UUID;
|
||||
TakeOut.SysHotel.FCS_Clean_UUID = entity.FCS_Clean_UUID;
|
||||
TakeOut.SysHotel.FCS_TiSongWuPin = entity.FCS_TiSongWuPin;
|
||||
TakeOut.SysHotel.FCS_RCU_Device_Offline = entity.FCS_RCU_Device_Offline;
|
||||
TakeOut.SysHotel.FCS_RCU_Offline = entity.FCS_RCU_Offline;
|
||||
TakeOut.SysHotel.FCS_RCU_Online = entity.FCS_RCU_Online;
|
||||
TakeOut.SysHotel.FCS_MenCi_Close = entity.FCS_MenCi_Close;
|
||||
TakeOut.SysHotel.FCS_MenCi_Open = entity.FCS_MenCi_Open;
|
||||
|
||||
TakeOut.SysHotel.IsUseSkyworthTV = entity.IsUseSkyworthTV;//断电重置小度
|
||||
TakeOut.SysHotel.IsUseTCLTV = entity.IsUseTCLTV;//断电重置小度
|
||||
TakeOut.SysHotel.SkyworthTVauthCode = entity.SkyworthTVauthCode;//断电重置小度
|
||||
TakeOut.SysHotel.TouSuResponseData = entity.TouSuResponseData; //投诉反馈语音
|
||||
TakeOut.SysHotel.IsUseQianLiMa = entity.IsUseQianLiMa;//断电重置小度
|
||||
TakeOut.SysHotel.IsPushPMSData = entity.IsPushPMSData;
|
||||
TakeOut.SysHotel.HeTongNumber = entity.HeTongNumber;
|
||||
//TakeOut.SysHotel.TCLAppId = entity.TCLAppId;
|
||||
//TakeOut.SysHotel.TCLAppSecret = entity.TCLAppSecret;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Edit"), entity.Name + ":第三方对接信息");
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存上下午时间,并下发给本酒店下所有主机
|
||||
/// </summary>
|
||||
/// <param name="morningTime"></param>
|
||||
/// <param name="afternoonTime"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult SaveHotelTime(int morningTime, int afternoonTime)
|
||||
{
|
||||
var sysHotel = SysHotelManager.Get(CurrentHotelID);
|
||||
sysHotel.StartDayTime = morningTime;
|
||||
sysHotel.EndDayTime = afternoonTime;
|
||||
SysHotelManager.UpdateDayTime(sysHotel);
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Edit"), sysHotel.Name + ":白天时间信息");
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 空调节能模式
|
||||
/// </summary>
|
||||
/// <param name="morningTime"></param>
|
||||
/// <param name="afternoonTime"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult SaveAirConditionECO(int id, string StartTime, string EndTime, string Action, string TempVal, bool IsEnable)
|
||||
{
|
||||
var sysHotel = SysHotelManager.Get(CurrentHotelID);
|
||||
ECO_Setting se = new ECO_Setting();
|
||||
se.HotelID = CurrentHotelID;
|
||||
se.StartTime = StartTime;
|
||||
se.EndTime = EndTime;
|
||||
se.AddOrCutDown = Action;
|
||||
|
||||
int fg = 0;
|
||||
int.TryParse(TempVal, out fg);
|
||||
se.ActValue = fg;
|
||||
se.IsEnable = IsEnable;
|
||||
string ti = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
se.CreateTime = ti;
|
||||
|
||||
if (id == 0)
|
||||
{
|
||||
Air_ECO_SettingManager.Add(se);
|
||||
}
|
||||
else
|
||||
{
|
||||
se.ID = id;
|
||||
Air_ECO_SettingManager.Update(se);
|
||||
}
|
||||
|
||||
|
||||
//启动ECO任务
|
||||
string[] s_st = StartTime.Split(':');
|
||||
|
||||
//开始时间
|
||||
int sh = 0;
|
||||
int.TryParse(s_st[0], out sh);
|
||||
int sm = 0;
|
||||
int.TryParse(s_st[1], out sm);
|
||||
|
||||
|
||||
//任务管理系统 需要在结束后2分钟发送 重置 指令
|
||||
string[] str = EndTime.Split(':');
|
||||
|
||||
//结束时间
|
||||
int hh = 0;
|
||||
int.TryParse(str[0], out hh);
|
||||
int mm = 0;
|
||||
int.TryParse(str[1], out mm);
|
||||
|
||||
|
||||
int new_mm = mm + 2;
|
||||
//一般是结束时间小于开始时间
|
||||
|
||||
DateTime ct = DateTime.Now;
|
||||
DateTime d_st = new DateTime(ct.Year, ct.Month, ct.Day, sh, sm, 0);
|
||||
DateTime d_et = new DateTime(ct.Year, ct.Month, ct.Day, hh, mm, 0);
|
||||
|
||||
if (d_et > d_st)
|
||||
{
|
||||
Air_ECO_SettingManager.ECO_Start_Mission(CurrentHotelID.ToString(), sh, sm, hh, mm, IsEnable);
|
||||
}
|
||||
else if (d_et < d_st)
|
||||
{
|
||||
Air_ECO_SettingManager.ECO_Start_Mission(CurrentHotelID.ToString(), sh, sm, 00, 00, IsEnable);
|
||||
Air_ECO_SettingManager.ECO_Start_Mission(CurrentHotelID.ToString(), 0, 1, hh, mm, IsEnable);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
Air_ECO_SettingManager.ECO_Reset_Mission(CurrentHotelID.ToString(), hh, new_mm, IsEnable);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 欺骗式ECO
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="StartTime"></param>
|
||||
/// <param name="EndTime"></param>
|
||||
/// <param name="Action"></param>
|
||||
/// <param name="TempVal"></param>
|
||||
/// <param name="IsEnable"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult SaveConditionLieECO(string BiaoShiFlag, string StartTime, string EndTime, string AbsEnable, string AbsValue, string RelativeEnable, string RelativeValue, bool IsEnable, string Delay)
|
||||
{
|
||||
try
|
||||
{
|
||||
//启动ECO任务
|
||||
string[] s_st = StartTime.Split(':');
|
||||
|
||||
//开始时间
|
||||
int sh = 0;
|
||||
int.TryParse(s_st[0], out sh);
|
||||
int sm = 0;
|
||||
int.TryParse(s_st[1], out sm);
|
||||
|
||||
|
||||
//任务管理系统 需要在结束后2分钟发送 重置 指令
|
||||
string[] str = EndTime.Split(':');
|
||||
|
||||
//结束时间
|
||||
int hh = 0;
|
||||
int.TryParse(str[0], out hh);
|
||||
int mm = 0;
|
||||
int.TryParse(str[1], out mm);
|
||||
|
||||
DateTime ct = DateTime.Now;
|
||||
DateTime d_st = new DateTime(ct.Year, ct.Month, ct.Day, sh, sm, 0);
|
||||
DateTime d_et = new DateTime(ct.Year, ct.Month, ct.Day, hh, mm, 0);
|
||||
if (d_st > d_et)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = " \"结束时间\"须大于\"开始时间\"" });
|
||||
}
|
||||
|
||||
|
||||
var sysHotel = SysHotelManager.Get(CurrentHotelID);
|
||||
|
||||
|
||||
LieECO se = new LieECO();
|
||||
se.HotelID = CurrentHotelID;
|
||||
se.StartTime = StartTime;
|
||||
se.EndTime = EndTime;
|
||||
se.AbsEnable = bool.Parse(AbsEnable);
|
||||
se.AbsValue = int.Parse(AbsValue);
|
||||
se.RelativeEnable = bool.Parse(RelativeEnable);
|
||||
se.RelativeValue = int.Parse(RelativeValue);
|
||||
se.IsEnable = IsEnable;
|
||||
int ddd = 20;
|
||||
int.TryParse(Delay, out ddd);
|
||||
se.DelayTime = ddd;
|
||||
string ti = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
se.CreateTime = DateTime.Now;
|
||||
|
||||
if (BiaoShiFlag == "0")
|
||||
{
|
||||
LieECOManager.Add(se);
|
||||
}
|
||||
else
|
||||
{
|
||||
se.ID = int.Parse(BiaoShiFlag);
|
||||
LieECOManager.Update(se);
|
||||
}
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
public static string missionsys_address = ConfigurationManager.AppSettings["missionsys_address"];
|
||||
/// <summary>
|
||||
/// 凌晨ECO
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult SaveConditionTimerECO()
|
||||
{
|
||||
try
|
||||
{
|
||||
Request.InputStream.Position = 0;
|
||||
byte[] reqBody = new byte[Request.InputStream.Length];
|
||||
Request.InputStream.Read(reqBody, 0, reqBody.Length);
|
||||
string reqData = System.Text.Encoding.UTF8.GetString(reqBody);
|
||||
if (!string.IsNullOrEmpty(reqData))
|
||||
{
|
||||
var T = JsonConvert.DeserializeObject<List<LingChenECO>>(reqData);
|
||||
//T.ForEach(A => A.HotelCode = CurrentHotelCode);
|
||||
string GGG = CacheKey.KT_Timer_Controller + "_" + CurrentHotelCode;
|
||||
CSRedisCacheHelper.Set_PartitionWithForever<List<LingChenECO>>(GGG,T,5);
|
||||
var client1 = new RestClient(missionsys_address);
|
||||
foreach (var item in T)
|
||||
{
|
||||
string[] tt = item.StartTime.Split(':');
|
||||
string st_h = tt[0];
|
||||
string st_m = tt[1];
|
||||
if (item.IsEnable)
|
||||
{
|
||||
|
||||
//内存中 保存着 code 和 时间的
|
||||
CSRedisCacheHelper.HMSet(5, MvcApplication.LingChenECO_IntervalKey, item.HotelCode + "#" + item.StartTime, item.RelativeValue);
|
||||
//给任务管理系统发送数据
|
||||
var tq = new RedisTongJiData();
|
||||
tq.url = "api/LingChenECO";
|
||||
tq.cron_exp = string.Format("*{0} {1} * * *", st_h, st_m);
|
||||
tq.mission_key = MvcApplication.LingChenECO_IntervalKey + "_" + item.HotelCode + "_" + item.StartTime;
|
||||
|
||||
string ts = Newtonsoft.Json.JsonConvert.SerializeObject(tq);
|
||||
CSRedisCacheHelper.HMSet(1, MvcApplication.LingChenECO_MissionSysKey, item.HotelCode + "#" + item.StartTime, ts);
|
||||
|
||||
var request1 = new RestRequest("api/declare_mission", Method.POST);
|
||||
request1.AddParameter("url", tq.url);
|
||||
request1.AddParameter("mission_key", tq.mission_key);
|
||||
request1.AddParameter("mission_name", tq.mission_key);
|
||||
request1.AddParameter("cron_exp", tq.cron_exp);
|
||||
client1.ExecuteAsync(request1, (response) =>
|
||||
{
|
||||
string result = response.Content;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Delete(IList<int> idList)
|
||||
{
|
||||
try
|
||||
{
|
||||
SysHotelManager.Delete(idList.Cast<object>().ToList());
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex.ToString());
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("OperationFailed") });
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 上传logo
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult UploadLogo(HttpPostedFileBase file, int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (file == null || file.ContentLength <= 0)
|
||||
{
|
||||
throw new ApplicationException("请选择Logo");
|
||||
}
|
||||
string ext = System.IO.Path.GetExtension(file.FileName).ToLower();
|
||||
if (ext != ".png")
|
||||
{
|
||||
throw new ApplicationException("Logo格式必须是.png");
|
||||
}
|
||||
SysHotel entity = SysHotelManager.Get(id);
|
||||
if (entity == null)
|
||||
{
|
||||
throw new ApplicationException("未指定酒店");
|
||||
}
|
||||
entity.LogoPath = "../Uploads/logo/" + entity.Code + ".png";
|
||||
|
||||
string filePath = Server.MapPath("~/Uploads/logo/");
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
|
||||
filePath += entity.Code + ".png"; //file.FileName;
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
System.IO.File.Delete(filePath);
|
||||
//throw new ApplicationException(HttpContext.InnerLanguage("TheUpgradePackageHasBeenUploadedPleaseReSelect"));
|
||||
}
|
||||
|
||||
SysHotelManager.Update(entity);
|
||||
|
||||
file.SaveAs(filePath);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("UploadSuccessful") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpUtility.HtmlEncode(ex.Message) });
|
||||
}
|
||||
}
|
||||
[Authorize]
|
||||
public ActionResult LoadSysHotelGroupTree()
|
||||
{
|
||||
SysUsers user = SysUserManager.Get(User.Identity.Name);
|
||||
if (user.SysHotelGroup == null)
|
||||
{
|
||||
return Json(new List<object>(), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
//IList<SysHotelGroup> groups = SysHotelGroupManager.LoadAll();
|
||||
//return Json(BuildGroupTree(groups, null), JsonRequestBehavior.AllowGet);
|
||||
IList<object> result = new List<object>();
|
||||
result.Add(SysHotelGroupManager.CreateGroupTree2(user.SysHotelGroup));
|
||||
return Json(result, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadGroupTree2()
|
||||
{
|
||||
SysUsers user = SysUserManager.Get(User.Identity.Name);
|
||||
if (user.SysHotelGroup == null)
|
||||
{
|
||||
return Json(new List<object>(), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
return Json(SysHotelGroupManager.CreateGroupTree(user.SysHotelGroup), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
public ActionResult EditSysHotelGroup(int? id, int? parentId)
|
||||
{
|
||||
if (id.HasValue)
|
||||
{
|
||||
return View(SysHotelGroupManager.Get(id));
|
||||
}
|
||||
return View(new SysHotelGroup { ID = 0, Name = "", Parent = new SysHotelGroup { ID = parentId.GetValueOrDefault() }, Sort = 1 });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public ActionResult DeleteSysHotelGroup(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Delete"), SysHotelGroupManager.Get(id).Name);
|
||||
SysHotelGroupManager.Delete(id);
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex.ToString());
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("OperationFailed") });
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public ActionResult SaveSysHotelGroup(string jsonData)
|
||||
{
|
||||
try
|
||||
{
|
||||
SysHotelGroup entity = Newtonsoft.Json.JsonConvert.DeserializeObject<SysHotelGroup>(jsonData);
|
||||
if (entity.ID == 0)
|
||||
{
|
||||
SysHotelGroupManager.Save(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
SysHotelGroupManager.Update(entity);
|
||||
}
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Edit"), entity.Name);
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex.ToString());
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SaveFailedBecause") });
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult GetProvince()
|
||||
{
|
||||
IList<SysProvince> list = SysProvinceManager.LoadAll();
|
||||
return Json(list.Select(r => new { r.Code, Name = ReturnNameByLanguage(r.Name, r.EName, r.TWName) }).ToList(), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
public ActionResult GetCity(string provinceCode)
|
||||
{
|
||||
IList<SysCity> list = SysProvinceManager.GetCity(provinceCode);
|
||||
return Json(list.Select(r => new { r.Code, Name = ReturnNameByLanguage(r.Name, r.EName, r.TWName) }).ToList(), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
public ActionResult GetCounty(string cityCode)
|
||||
{
|
||||
IList<SysCounty> list = SysProvinceManager.GetCounty(cityCode);
|
||||
return Json(list.Select(r => new { r.Code, Name = ReturnNameByLanguage(r.Name, r.EName, r.TWName) }).ToList(), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
}
|
||||
}
|
||||
281
WebSite/Controllers/SysRoleController.cs
Normal file
281
WebSite/Controllers/SysRoleController.cs
Normal file
@@ -0,0 +1,281 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class SysRoleController : BaseController
|
||||
{
|
||||
private const int AuthorityID = 50;
|
||||
public ISysRoleManager SysRoleManager { get; set; }
|
||||
public ISysUserManager SysUserManager { get; set; }
|
||||
public ISysAuthorityManager SysAuthorityManager { get; set; }
|
||||
public ISysHotelGroupManager SysHotelGroupManager { get; set; }
|
||||
public ISysHotelManager SysHotelManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View("SimonIndex");
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Edit(int? id)
|
||||
{
|
||||
if (id.HasValue)
|
||||
{
|
||||
return View(SysRoleManager.Get(id));
|
||||
}
|
||||
|
||||
return View(new SysRole { ID = 0, Name = "", Sort = 1, Remark = "" });
|
||||
}
|
||||
|
||||
//[Authorize]
|
||||
//public ActionResult LoadAllByPage(int page, int rows, string order, string sort)
|
||||
//{
|
||||
// long total = 0;
|
||||
// var list = this.SysRoleManager.LoadAllByPage(out total, page, rows, order, sort);
|
||||
|
||||
// var result = new { total = total, rows = list };
|
||||
|
||||
// return Json(result);
|
||||
//}
|
||||
/// <summary>
|
||||
/// 装载到下拉框控件
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadAll()
|
||||
{
|
||||
SysUsers user = this.SysUserManager.Get(User.Identity.Name);//当前用户角色不装载出来
|
||||
IList<SysRole> roles = SysRoleManager.LoadAll().Where(r => r.ID != user.Role.ID && r.HotelID == CurrentHotelID).OrderBy(o => o.Sort).ToList();
|
||||
IList<object> result = new List<object>();
|
||||
foreach (SysRole role in roles)
|
||||
{
|
||||
result.Add(new { ID = role.ID, Name = role.Name });
|
||||
}
|
||||
return Json(result);
|
||||
}
|
||||
/// <summary>
|
||||
/// 角色管理主页面显示
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadAll2(int? groupId)
|
||||
{
|
||||
IList<object> result = new List<object>();
|
||||
try
|
||||
{
|
||||
|
||||
SysUsers user = this.SysUserManager.Get(User.Identity.Name);//当前用户角色不装载出来
|
||||
IList<SysRole> roles = SysRoleManager.LoadAll().Where(r => r.ID != user.Role.ID && r.HotelID == CurrentHotelID).OrderBy(o => o.HotelID).ThenBy(o => o.Sort).ToList();
|
||||
foreach (SysRole role in roles)
|
||||
{
|
||||
if (role.Authorities.Count > 0)
|
||||
{
|
||||
var nnn = role.Authorities.Select(r => ReturnNameByLanguage(r.Name, r.EName, r.TWName)).ToArray();
|
||||
string authorities = String.Join("、", nnn);
|
||||
if (!string.IsNullOrEmpty(authorities))
|
||||
{
|
||||
result.Add(new { ID = role.ID, Name = role.Name, Sort = role.Sort, Authorities = authorities });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
return Json(new { IsSuccess = true, data = result }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Save(int id, string name, int sort, IList<int> authorities)//,int sysHotelGroupID
|
||||
{
|
||||
SysRole existRole = this.SysRoleManager.Get(name);
|
||||
SysRole entity = new SysRole();
|
||||
var newAuthorities = GetAuthorities(authorities);
|
||||
|
||||
if (id == 0)
|
||||
{
|
||||
//新增
|
||||
if (null != existRole)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("RoleName") + "【" + name + "】" + HttpContext.InnerLanguage("AlreadyExist") });
|
||||
}
|
||||
|
||||
entity.ID = id;
|
||||
entity.Name = name;
|
||||
entity.Authorities = newAuthorities;
|
||||
entity.Sort = sort;
|
||||
entity.ActiveIndicator = true;
|
||||
entity.CreatedBy = entity.ModifiedBy = this.User.Identity.Name;
|
||||
entity.CreatedDate = entity.ModifiedDate = DateTime.Now;
|
||||
entity.HotelID = CurrentHotelID;
|
||||
entity.SysHotelGroup = new SysHotelGroup();// SysHotelGroupManager.Get(sysHotelGroupID);酒店角色无分组
|
||||
|
||||
SysRoleManager.Save(entity);
|
||||
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("New"), name);
|
||||
}
|
||||
else
|
||||
{
|
||||
//更新
|
||||
var role = this.SysRoleManager.Get(id);
|
||||
|
||||
if (existRole != null && existRole.ID != role.ID)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("RoleName") + "【" + name + "】" + HttpContext.InnerLanguage("AlreadyExist") });
|
||||
}
|
||||
|
||||
role.Name = name;
|
||||
role.Authorities.Clear();
|
||||
role.Authorities = newAuthorities;
|
||||
role.Sort = sort;
|
||||
role.ModifiedBy = this.User.Identity.Name;
|
||||
role.ModifiedDate = DateTime.Now;
|
||||
//role.HotelID = CurrentHotelID;//不修改所属酒店
|
||||
//role.SysHotelGroup = SysHotelGroupManager.Get(sysHotelGroupID);
|
||||
|
||||
SysRoleManager.Update(role);
|
||||
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Edit"), name);
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public ActionResult Delete(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
SysRole role = this.SysRoleManager.Get(id);
|
||||
|
||||
if (role.Name == HttpContext.InnerLanguage("SuperAdministrator"))
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("SuperAdministratorRoleCanNotBeDeleted"));
|
||||
}
|
||||
|
||||
this.SysRoleManager.Delete(id);
|
||||
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Delete"), role.Name);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
}
|
||||
catch (ApplicationException ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过角色获取对应的权限
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadRoleAuthorities(int? roleId)
|
||||
{
|
||||
IList<SysAuthority> allAuthorities = SysAuthorityManager.LoadAll().Where(r => r.ParentID == 0 || r.ParentID == 1000).ToList();//获取第一层功能权限和第一级别菜单权限
|
||||
SysRole userRole = SysUserManager.Get(User.Identity.Name).Role;//当前登录用户角色
|
||||
IList<SysAuthority> userAuthority = new List<SysAuthority>();//当前登录用户角色权限
|
||||
foreach (var authority in userRole.Authorities)
|
||||
{
|
||||
userAuthority.Add(authority);
|
||||
var parentNode = userRole.Authorities.Where(r => r.ID == authority.ParentID).FirstOrDefault();//判断其上级菜单是否存在,如果不存在,则添加进来
|
||||
if (parentNode == null && !userAuthority.Contains(parentNode))
|
||||
{
|
||||
userAuthority.Add(allAuthorities.Where(r => r.ID == authority.ParentID).FirstOrDefault());
|
||||
}
|
||||
}
|
||||
var first = allAuthorities.Where(r => r.ID == 1000).FirstOrDefault();//后台菜单权限:解决二级菜单全都没有打勾的问题
|
||||
if (!userAuthority.Contains(first))
|
||||
{
|
||||
userAuthority.Add(first);
|
||||
}
|
||||
SysRole editRole = null;//当前编辑的角色
|
||||
if (roleId.HasValue)
|
||||
{
|
||||
editRole = SysRoleManager.Get(roleId);
|
||||
}
|
||||
return Json(BuildAuthoritiesTree(userAuthority, editRole, 0), JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult SaveRoleAuthorities(int roleId, IList<int> authorityIdList)
|
||||
{
|
||||
try
|
||||
{
|
||||
SysRoleManager.SaveRoleAuthorities(roleId, authorityIdList);
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
catch (ApplicationException ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 构造权限树,用于设置角色权限
|
||||
/// </summary>
|
||||
/// <param name="role"></param>
|
||||
/// <param name="parentId"></param>
|
||||
/// <returns></returns>
|
||||
private IList<object> BuildAuthoritiesTree(IList<SysAuthority> userAuthority, SysRole editRole, int parentId)
|
||||
{
|
||||
IList<object> authoritiesTree = new List<object>();
|
||||
IList<SysAuthority> authorities = SysAuthorityManager.GetAuthorities(parentId);
|
||||
foreach (SysAuthority authority in authorities)
|
||||
{
|
||||
IList<object> children = BuildAuthoritiesTree(userAuthority, editRole, authority.ID);
|
||||
bool hasAuthority = false;
|
||||
if (editRole != null)
|
||||
{
|
||||
hasAuthority = editRole.Authorities.Contains(authority);
|
||||
}
|
||||
if (authority.ActiveIndicator)
|
||||
{
|
||||
if (User.Identity.Name.ToLower() == "admin" || (User.Identity.Name.ToLower() != "admin" && userAuthority.Contains(authority)))
|
||||
{
|
||||
if (children.Count != 0)
|
||||
{
|
||||
authoritiesTree.Add(new { id = authority.ID, text = ReturnNameByLanguage(authority.Name, authority.EName, authority.TWName), @checked = hasAuthority, children = children });
|
||||
}
|
||||
else
|
||||
{
|
||||
authoritiesTree.Add(new { id = authority.ID, text = ReturnNameByLanguage(authority.Name, authority.EName, authority.TWName), @checked = hasAuthority });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return authoritiesTree;
|
||||
}
|
||||
|
||||
private IList<SysAuthority> GetAuthorities(IList<int> authorityIDs)
|
||||
{
|
||||
IList<SysAuthority> authorities = new List<SysAuthority>();
|
||||
if (authorityIDs != null)
|
||||
{
|
||||
foreach (int authorityId in authorityIDs)
|
||||
{
|
||||
var authority = SysAuthorityManager.Get(authorityId);
|
||||
if (authority != null && !authorities.Contains(authority))
|
||||
{
|
||||
authorities.Add(authority);
|
||||
}
|
||||
}
|
||||
}
|
||||
return authorities;
|
||||
}
|
||||
}
|
||||
}
|
||||
285
WebSite/Controllers/SysRoleGroupController.cs
Normal file
285
WebSite/Controllers/SysRoleGroupController.cs
Normal file
@@ -0,0 +1,285 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class SysRoleGroupController : BaseController
|
||||
{
|
||||
private const int AuthorityID = 55;
|
||||
public ISysRoleManager SysRoleManager { get; set; }
|
||||
public ISysUserManager SysUserManager { get; set; }
|
||||
public ISysAuthorityManager SysAuthorityManager { get; set; }
|
||||
public ISysHotelGroupManager SysHotelGroupManager { get; set; }
|
||||
public ISysHotelManager SysHotelManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View("SimonIndex");
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Edit(int? id)
|
||||
{
|
||||
if (id.HasValue)
|
||||
{
|
||||
return View(SysRoleManager.Get(id));
|
||||
}
|
||||
|
||||
return View(new SysRole { ID = 0, Name = "", Sort = 1, Remark = "" });
|
||||
}
|
||||
|
||||
//[Authorize]
|
||||
//public ActionResult LoadAllByPage(int page, int rows, string order, string sort)
|
||||
//{
|
||||
// long total = 0;
|
||||
// var list = this.SysRoleManager.LoadAllByPage(out total, page, rows, order, sort);
|
||||
|
||||
// var result = new { total = total, rows = list };
|
||||
|
||||
// return Json(result);
|
||||
//}
|
||||
/// <summary>
|
||||
/// 装载到下拉框控件
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadAll(int? groupId)
|
||||
{
|
||||
//装载只有在该酒店分组下,且已授权访问酒店下的角色
|
||||
SysUsers user = this.SysUserManager.Get(User.Identity.Name);//当前用户角色不装载出来
|
||||
IList<SysRole> roles = SysRoleManager.LoadAll().Where(r => r.ID != 1 && r.ID != user.Role.ID && r.HotelID == 0 && r.SysHotelGroup.ID != user.SysHotelGroup.ID).OrderBy(o => o.Sort).ToList();
|
||||
if (groupId.HasValue && groupId != 1)
|
||||
{
|
||||
roles = roles.Where(r => r.SysHotelGroup.ID == groupId || (r.SysHotelGroup.Parent != null && r.SysHotelGroup.Parent.ID == groupId)
|
||||
|| (r.SysHotelGroup.Parent != null && r.SysHotelGroup.Parent.Parent != null && r.SysHotelGroup.Parent.Parent.ID == groupId)).ToList();
|
||||
}
|
||||
IList<object> result = new List<object>();
|
||||
foreach (SysRole role in roles)
|
||||
{
|
||||
result.Add(new { ID = role.ID, Name = role.Name });
|
||||
}
|
||||
return Json(result);
|
||||
}
|
||||
/// <summary>
|
||||
/// 角色管理主页面显示:只能装载自己所属分组的子分组的角色
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult LoadAll2(int? groupId)
|
||||
{
|
||||
IList<object> result = new List<object>();
|
||||
try
|
||||
{
|
||||
|
||||
SysUsers user = this.SysUserManager.Get(User.Identity.Name);//当前用户角色与同组的用户角色不装载出来
|
||||
if (user != null)
|
||||
{
|
||||
IList<SysRole> roles = SysRoleManager.LoadAll().Where(r =>
|
||||
{
|
||||
var NNV = r.SysHotelGroup;
|
||||
if (NNV != null)
|
||||
{
|
||||
bool bf = r.ID != 1 && r.ID != user.Role.ID && r.HotelID == 0 && r.SysHotelGroup.ID != user.SysHotelGroup.ID;
|
||||
return bf;
|
||||
}
|
||||
return false;
|
||||
}).OrderBy(o => o.Sort).ToList();
|
||||
|
||||
if (groupId.HasValue && groupId != 1)
|
||||
{
|
||||
roles = roles.Where(r => r.SysHotelGroup.ID == groupId || (r.SysHotelGroup.Parent != null && r.SysHotelGroup.Parent.ID == groupId)
|
||||
|| (r.SysHotelGroup.Parent != null && r.SysHotelGroup.Parent.Parent != null && r.SysHotelGroup.Parent.Parent.ID == groupId)).ToList();
|
||||
}
|
||||
foreach (SysRole role in roles)
|
||||
{
|
||||
string authorities = String.Join("、", role.Authorities.Select(r => ReturnNameByLanguage(r.Name, r.EName, r.TWName)).ToArray());
|
||||
result.Add(new { ID = role.ID, Name = role.Name, GroupName = role.SysHotelGroup.Name, Sort = role.Sort, Authorities = authorities });
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex.StackTrace);
|
||||
}
|
||||
return Json(new { IsSuccess = true, data = result }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Save(int id, string name, int sysHotelGroupID, int sort, IList<int> authorities)
|
||||
{
|
||||
var curUser = SysUserManager.Get(User.Identity.Name);
|
||||
if (sysHotelGroupID == curUser.SysHotelGroup.ID)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("Flag") });
|
||||
}
|
||||
SysRole existRole = this.SysRoleManager.Get(name);
|
||||
SysRole entity = new SysRole();
|
||||
var newAuthorities = GetAuthorities(authorities);
|
||||
|
||||
if (id == 0)
|
||||
{
|
||||
//新增
|
||||
if (null != existRole)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("RoleName") + "【" + name + "】" + HttpContext.InnerLanguage("AlreadyExist") });
|
||||
}
|
||||
|
||||
entity.ID = id;
|
||||
entity.Name = name;
|
||||
entity.Authorities = newAuthorities;
|
||||
entity.Sort = sort;
|
||||
entity.ActiveIndicator = true;
|
||||
entity.CreatedBy = entity.ModifiedBy = this.User.Identity.Name;
|
||||
entity.CreatedDate = entity.ModifiedDate = DateTime.Now;
|
||||
entity.HotelID = 0;//0表示组角色,跟酒店无关
|
||||
entity.SysHotelGroup = SysHotelGroupManager.Get(sysHotelGroupID);
|
||||
|
||||
SysRoleManager.Save(entity);
|
||||
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("New"), name);
|
||||
}
|
||||
else
|
||||
{
|
||||
//更新
|
||||
var role = this.SysRoleManager.Get(id);
|
||||
|
||||
if (existRole != null && existRole.ID != role.ID)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("RoleName") + "【" + name + "】" + HttpContext.InnerLanguage("AlreadyExist") });
|
||||
}
|
||||
|
||||
role.Name = name;
|
||||
role.Authorities.Clear();
|
||||
role.Authorities = newAuthorities;
|
||||
role.Sort = sort;
|
||||
role.ModifiedBy = this.User.Identity.Name;
|
||||
role.ModifiedDate = DateTime.Now;
|
||||
//role.HotelID = CurrentHotelID;//不修改所属酒店
|
||||
role.SysHotelGroup = SysHotelGroupManager.Get(sysHotelGroupID);
|
||||
|
||||
SysRoleManager.Update(role);
|
||||
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Edit"), name);
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public ActionResult Delete(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
SysRole role = this.SysRoleManager.Get(id);
|
||||
|
||||
if (role.Name == HttpContext.InnerLanguage("SuperAdministrator"))
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("SuperAdministratorRoleCanNotBeDeleted"));
|
||||
}
|
||||
|
||||
this.SysRoleManager.Delete(id);
|
||||
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Delete"), role.Name);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
}
|
||||
catch (ApplicationException ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
//[Authorize]
|
||||
//public ActionResult LoadRoleAuthorities(int? roleId)
|
||||
//{
|
||||
// SysRole role = null;
|
||||
|
||||
// if (roleId.HasValue)
|
||||
// {
|
||||
// role = SysRoleManager.Get(roleId);
|
||||
// }
|
||||
|
||||
// return Json(BuildAuthoritiesTree(role, 0), JsonRequestBehavior.AllowGet);
|
||||
//}
|
||||
|
||||
//[Authorize]
|
||||
//public ActionResult SaveRoleAuthorities(int roleId, IList<int> authorityIdList)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// SysRoleManager.SaveRoleAuthorities(roleId, authorityIdList);
|
||||
// return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
// }
|
||||
// catch (ApplicationException ex)
|
||||
// {
|
||||
// return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
// }
|
||||
//}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 构造权限树,用于设置角色权限
|
||||
/// </summary>
|
||||
/// <param name="role"></param>
|
||||
/// <param name="parentId"></param>
|
||||
/// <returns></returns>
|
||||
private IList<object> BuildAuthoritiesTree(SysRole role, int parentId)
|
||||
{
|
||||
IList<object> authoritiesTree = new List<object>();
|
||||
|
||||
IList<SysAuthority> authorities = SysAuthorityManager.GetAuthorities(parentId);
|
||||
|
||||
foreach (SysAuthority authority in authorities)
|
||||
{
|
||||
IList<object> children = BuildAuthoritiesTree(role, authority.ID);
|
||||
|
||||
bool hasAuthority = (role != null ? role.Authorities.Contains(authority) : false);
|
||||
|
||||
if (authority.ActiveIndicator)
|
||||
{
|
||||
if (children.Count != 0)
|
||||
{
|
||||
authoritiesTree.Add(new { id = authority.ID, text = ReturnNameByLanguage(authority.Name, authority.EName, authority.TWName), @checked = hasAuthority, children = children });
|
||||
}
|
||||
else
|
||||
{
|
||||
authoritiesTree.Add(new { id = authority.ID, text = ReturnNameByLanguage(authority.Name, authority.EName, authority.TWName), @checked = hasAuthority });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return authoritiesTree;
|
||||
}
|
||||
|
||||
private IList<SysAuthority> GetAuthorities(IList<int> authorityIDs)
|
||||
{
|
||||
IList<SysAuthority> authorities = new List<SysAuthority>();
|
||||
|
||||
if (authorityIDs != null)
|
||||
{
|
||||
foreach (int authorityId in authorityIDs)
|
||||
{
|
||||
var authority = SysAuthorityManager.Get(authorityId);
|
||||
if (authority != null && !authorities.Contains(authority))
|
||||
{
|
||||
authorities.Add(authority);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return authorities;
|
||||
}
|
||||
}
|
||||
}
|
||||
128
WebSite/Controllers/SysSettingController.cs
Normal file
128
WebSite/Controllers/SysSettingController.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Service;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class SysSettingController : BaseController
|
||||
{
|
||||
private const int AUTHORITY_SysSetting = 52;
|
||||
|
||||
public ISysSettingManager SysSettingManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View("SimonIndex");
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Save(string jsonData)
|
||||
{
|
||||
try
|
||||
{
|
||||
IDictionary<string, string> settings = Newtonsoft.Json.JsonConvert.DeserializeObject<IDictionary<string, string>>(jsonData);
|
||||
|
||||
foreach (var kv in settings)
|
||||
{
|
||||
SysSettingManager.SetValue(kv.Key, kv.Value);
|
||||
}
|
||||
|
||||
SaveSystemLog(AUTHORITY_SysSetting, HttpContext.InnerLanguage("EditSystemSetting"), "");
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveSystemLog(AUTHORITY_SysSetting, HttpContext.InnerLanguage("EditSystemSetting"), ex.Message);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveFailed") });
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAll()
|
||||
{
|
||||
var list = SysSettingManager.LoadAll().Where(r => r.AllowEdit);
|
||||
|
||||
IList<object> result = new List<object>();
|
||||
|
||||
foreach (var setting in list)
|
||||
{
|
||||
switch ((int)Session["isCN"])
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
if (setting.ERemark == "Address")
|
||||
{
|
||||
result.Add(new { id = setting.ID, name = setting.Name, remark = setting.ERemark, value = setting.Value, group = setting.EType, editor = new { type = "validatebox", options = new { required = true, validType = "ip" } } });
|
||||
}
|
||||
else if (setting.ERemark == "Port")
|
||||
{
|
||||
result.Add(new { id = setting.ID, name = setting.Name, remark = setting.ERemark, value = setting.Value, group = setting.EType, editor = new { type = "numberbox", options = new { required = true, min = 1, max = 65535 } } });
|
||||
}
|
||||
else if (setting.ERemark == "Synchronization Time")
|
||||
{
|
||||
result.Add(new { id = setting.ID, name = setting.Name, remark = setting.ERemark, value = setting.Value, group = setting.EType, editor = new { type = "timespinner", options = new { required = true } } });
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(new { id = setting.ID, name = setting.Name, remark = setting.ERemark, value = setting.Value, group = setting.EType, editor = "text" });
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
if (setting.Remark == "地址")
|
||||
{
|
||||
result.Add(new { id = setting.ID, name = setting.Name, remark = setting.Remark, value = setting.Value, group = setting.Type, editor = new { type = "validatebox", options = new { required = true, validType = "ip" } } });
|
||||
}
|
||||
else if (setting.Remark == "端口")
|
||||
{
|
||||
result.Add(new { id = setting.ID, name = setting.Name, remark = setting.Remark, value = setting.Value, group = setting.Type, editor = new { type = "numberbox", options = new { required = true, min = 1, max = 65535 } } });
|
||||
}
|
||||
else if (setting.Remark == "同步時間")
|
||||
{
|
||||
result.Add(new { id = setting.ID, name = setting.Name, remark = setting.Remark, value = setting.Value, group = setting.Type, editor = new { type = "timespinner", options = new { required = true } } });
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(new { id = setting.ID, name = setting.Name, remark = setting.Remark, value = setting.Value, group = setting.Type, editor = "text" });
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
if (setting.Remark == "地址")
|
||||
{
|
||||
result.Add(new { id = setting.ID, name = setting.Name, remark = setting.Remark, value = setting.Value, group = setting.Type, editor = new { type = "validatebox", options = new { required = true, validType = "ip" } } });
|
||||
}
|
||||
else if (setting.Remark == "端口")
|
||||
{
|
||||
result.Add(new { id = setting.ID, name = setting.Name, remark = setting.Remark, value = setting.Value, group = setting.Type, editor = new { type = "numberbox", options = new { required = true, min = 1, max = 65535 } } });
|
||||
}
|
||||
else if (setting.Remark == "同步时间")
|
||||
{
|
||||
result.Add(new { id = setting.ID, name = setting.Name, remark = setting.Remark, value = setting.Value, group = setting.Type, editor = new { type = "timespinner", options = new { required = true } } });
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(new { id = setting.ID, name = setting.Name, remark = setting.Remark, value = setting.Value, group = setting.Type, editor = "text" });
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Json(new { total = result.Count, rows = result });
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
73
WebSite/Controllers/SysSystemLogsController.cs
Normal file
73
WebSite/Controllers/SysSystemLogsController.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class SysSystemLogsController : BaseController
|
||||
{
|
||||
public ISysAuthorityManager SysAuthorityManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View("SimonIndex");
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAllByPage(int page, int rows, string order, string sort, int? authorityId, DateTime? startDate, DateTime? endDate, string keyword)
|
||||
{
|
||||
long total = 0;
|
||||
if (string.IsNullOrEmpty(keyword)) keyword = "";
|
||||
var list = this.SysSystemLogsManager.LoadAllByPage(out total, page, rows, order, sort, authorityId, startDate, endDate, keyword, CurrentHotelID);
|
||||
|
||||
var result = list.Select(r =>
|
||||
{
|
||||
var authority = SysAuthorityManager.Get(r.AuthorityID);
|
||||
|
||||
return new
|
||||
{
|
||||
r.ID,
|
||||
r.Account,
|
||||
Authority = authority != null ? ReturnNameByLanguage(authority.Name, authority.EName, authority.TWName) : "",
|
||||
r.Action,
|
||||
r.Detail,
|
||||
r.Result,
|
||||
r.IP,
|
||||
r.Time
|
||||
};
|
||||
});
|
||||
|
||||
return Json(new { total = total, rows = result });
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除多条数据
|
||||
/// </summary>
|
||||
/// <param name="idList"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult Delete(IList<long> idList)
|
||||
{
|
||||
SysSystemLogsManager.Delete(idList.Cast<object>().ToList());
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
}
|
||||
/// <summary>
|
||||
/// 批量删除
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult DeleteAll()
|
||||
{
|
||||
SysSystemLogsManager.DeleteAll(CurrentHotelID);
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("EmptySuccess") });
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
257
WebSite/Controllers/SysUserController.cs
Normal file
257
WebSite/Controllers/SysUserController.cs
Normal file
@@ -0,0 +1,257 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Service;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class SysUserController : BaseController
|
||||
{
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(SysUserController));
|
||||
private const int AuthorityID = 51;
|
||||
|
||||
public ISysUserManager SysUserManager { get; set; }
|
||||
public ISysRoleManager SysRoleManager { get; set; }
|
||||
public IGroupManager GroupManager { get; set; }
|
||||
public ISysHotelManager SysHotelManager { get; set; }
|
||||
public ISysHotelGroupManager SysHotelGroupManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Index()
|
||||
{
|
||||
switch (User.Identity.Name.ToLower())
|
||||
{
|
||||
case "admin":
|
||||
case "blw":
|
||||
ViewData["Account"] = true;
|
||||
break;
|
||||
default:
|
||||
ViewData["Account"] = false;
|
||||
break;
|
||||
}
|
||||
return View("SimonIndex");
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Edit(int? id)
|
||||
{
|
||||
if (id.HasValue)
|
||||
{
|
||||
return View(SysUserManager.Get(id));
|
||||
}
|
||||
var model = new SysUsers { ID = 0, Account = "", Role = null, Group = null, ActiveIndicator = true, Sort = 1, Remark = "" };
|
||||
return View(model);
|
||||
}
|
||||
|
||||
public ActionResult ChangePassword(int id)
|
||||
{
|
||||
ViewData["ID"] = id;
|
||||
return View();
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public ActionResult ChangePassword(int id, string password)
|
||||
{
|
||||
if (String.IsNullOrEmpty(password))
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("ThePasswordCanNotBeEmptyPleaseReEnter") });
|
||||
}
|
||||
SysUsers user = SysUserManager.Get(id);
|
||||
if (user != null)
|
||||
{
|
||||
SysUserManager.Update(user, password);
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("ResetPassword"), user.Account);
|
||||
}
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("PasswordResetSuccess") });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAllByPage(string order, string sort, int? groupId)//int page, int rows,
|
||||
{
|
||||
if (groupId.HasValue)
|
||||
{
|
||||
//long total = 0;
|
||||
//IList<SysUsers> list = this.SysUserManager.LoadAllByPage(out total, page, rows, order, sort, 1, groupId, CurrentHotelID);
|
||||
|
||||
IList<SysUsers> list = this.SysUserManager.LoadAll().Where(r => r.HotelID == CurrentHotelID && !r.IsDeleted
|
||||
&& (r.Group.ID == groupId || (r.Group.Parent != null && r.Group.Parent.ID == groupId)
|
||||
|| (r.Group.Parent != null && r.Group.Parent.Parent != null && r.Group.Parent.Parent.ID == groupId))).ToList();
|
||||
|
||||
IList<object> result = new List<object>();
|
||||
foreach (var user in list)
|
||||
{
|
||||
result.Add(new
|
||||
{
|
||||
ID = user.ID,
|
||||
Account = user.Account,
|
||||
RoleID = user.Role != null ? user.Role.ID.ToString() : "",
|
||||
RoleName = user.Role != null ? user.Role.Name : "",
|
||||
GroupID = user.Group != null ? user.Group.ID.ToString() : "",
|
||||
GroupName = GroupManager.BuildGroupName(user.Group),
|
||||
//SysHotelGroupName = SysHotelGroupManager.BuildGroupName(user.SysHotelGroup),
|
||||
ActiveIndicator = user.ActiveIndicator,
|
||||
Sort = user.Sort,
|
||||
Remark = user.Remark,
|
||||
CreatedBy = user.CreatedBy,
|
||||
CreatedDate = user.CreatedDate,
|
||||
ModifiedBy = user.ModifiedBy,
|
||||
ModifiedDate = user.ModifiedDate,
|
||||
HotelID = user.HotelID,
|
||||
Password2 = user.Password2
|
||||
//HotelName = ReturnNameByLanguage(hotel.Name, hotel.EName, hotel.TWName)
|
||||
});
|
||||
}
|
||||
return Json(new { total = result.Count, rows = result });
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { total = 0, rows = new List<object>() });
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult AuthorityHotel(int id)
|
||||
{
|
||||
return View(new SysUsers { ID = id });
|
||||
}
|
||||
|
||||
//[Authorize]
|
||||
//public ActionResult LoadAuthorityHotel(int userID)
|
||||
//{
|
||||
// IList<object> tree = new List<object>();
|
||||
// var hotelList = SysHotelManager.LoadAll().OrderBy(o => o.Sort).OrderBy(o => o.SysHotelGroup.Sort).ToList();
|
||||
// var userHotelList = SysUserManager.Get(userID).Hotels;
|
||||
// foreach (SysHotel hotel in hotelList)
|
||||
// {
|
||||
// bool check = false;
|
||||
// foreach (SysHotel userHoltel in userHotelList)
|
||||
// {
|
||||
// if (hotel.ID == userHoltel.ID)
|
||||
// {
|
||||
// check = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// tree.Add(new
|
||||
// {
|
||||
// id = hotel.ID,
|
||||
// text = hotel.Code + " -> " + SysHotelGroupManager.BuildGroupName(hotel.SysHotelGroup) + " -> " + ReturnNameByLanguage(hotel.Name, hotel.EName, hotel.TWName),
|
||||
// @checked = check
|
||||
// });
|
||||
// }
|
||||
// return Json(tree, JsonRequestBehavior.AllowGet);
|
||||
//}
|
||||
/// <summary>
|
||||
/// 保存授权酒店
|
||||
/// </summary>
|
||||
/// <param name="userID"></param>
|
||||
/// <param name="hotelID"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult SaveAuthorityHotel(int userID, IList<int> hotelIDs)
|
||||
{
|
||||
var user = SysUserManager.Get(userID);
|
||||
user.Hotels.Clear();
|
||||
foreach (int hotelID in hotelIDs)
|
||||
{
|
||||
user.Hotels.Add(SysHotelManager.Get(hotelID));
|
||||
}
|
||||
SysUserManager.SaveOrUpdate(user);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Save(string jsonData)
|
||||
{
|
||||
var user = Newtonsoft.Json.JsonConvert.DeserializeObject<SysUsers>(jsonData);
|
||||
try
|
||||
{
|
||||
var existUser = SysUserManager.Get(user.Account);
|
||||
IList<SysHotel> hotels = new List<SysHotel>();
|
||||
hotels.Add(SysHotelManager.Get(CurrentHotelID));
|
||||
if (user.ID == 0)
|
||||
{
|
||||
if (null != existUser)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("Account") + "【" + user.Account + "】" + HttpContext.InnerLanguage("AlreadyExist") });
|
||||
}
|
||||
user.Name = user.Account;
|
||||
user.CreatedBy = user.ModifiedBy = this.User.Identity.Name;
|
||||
user.CreatedDate = user.ModifiedDate = DateTime.Now;
|
||||
user.Hotels = hotels;
|
||||
user.HotelID = CurrentHotelID;
|
||||
|
||||
SysUserManager.Save(user);
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("New"), user.Account);
|
||||
}
|
||||
else
|
||||
{
|
||||
var currentUser = SysUserManager.Get(user.ID);
|
||||
if (existUser != null && existUser.ID != currentUser.ID)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("Account") + "【" + user.Account + "】" + HttpContext.InnerLanguage("AlreadyExist") });
|
||||
}
|
||||
currentUser.Account = user.Account;
|
||||
currentUser.Role = user.Role;
|
||||
currentUser.Group = user.Group;
|
||||
//currentUser.SysHotelGroup = user.SysHotelGroup;
|
||||
currentUser.ActiveIndicator = user.ActiveIndicator;
|
||||
currentUser.Sort = user.Sort;
|
||||
currentUser.Remark = user.Remark;
|
||||
currentUser.ModifiedBy = User.Identity.Name;
|
||||
currentUser.ModifiedDate = DateTime.Now;
|
||||
currentUser.HotelID = CurrentHotelID;
|
||||
|
||||
SysUserManager.Update(currentUser);
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Edit"), user.Account);
|
||||
}
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex);
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SaveFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Delete(IList<int> idList, IList<string> nameList)
|
||||
{
|
||||
//SysUserManager.Delete(idList.Cast<object>().ToList());
|
||||
foreach (int id in idList)
|
||||
{
|
||||
SysUsers user = SysUserManager.Get(id);
|
||||
user.IsDeleted = true;
|
||||
SysUserManager.Update(user);
|
||||
}
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Delete"), string.Join(",", nameList));
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
}
|
||||
|
||||
private IList<SysHotel> GetHotels(IList<int> hotelIDs)
|
||||
{
|
||||
IList<SysHotel> hotels = new List<SysHotel>();
|
||||
if (hotelIDs != null)
|
||||
{
|
||||
foreach (int hotelID in hotelIDs)
|
||||
{
|
||||
var hotel = SysHotelManager.Get(hotelID);
|
||||
if (hotel != null && !hotels.Contains(hotel))
|
||||
{
|
||||
hotels.Add(hotel);
|
||||
}
|
||||
}
|
||||
}
|
||||
return hotels;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
262
WebSite/Controllers/SysUserGroupController.cs
Normal file
262
WebSite/Controllers/SysUserGroupController.cs
Normal file
@@ -0,0 +1,262 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Domain;
|
||||
using Service;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class SysUserGroupController : BaseController
|
||||
{
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(SysUserGroupController));
|
||||
private const int AuthorityID = 56;
|
||||
|
||||
public ISysUserManager SysUserManager { get; set; }
|
||||
public ISysRoleManager SysRoleManager { get; set; }
|
||||
public IGroupManager GroupManager { get; set; }
|
||||
public ISysHotelManager SysHotelManager { get; set; }
|
||||
public ISysHotelGroupManager SysHotelGroupManager { get; set; }
|
||||
|
||||
#region Action
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Index()
|
||||
{
|
||||
//ViewData["Account"] = true;
|
||||
switch (User.Identity.Name.ToLower())
|
||||
{
|
||||
case "admin":
|
||||
case "blw":
|
||||
ViewData["Account"] = true;
|
||||
break;
|
||||
default:
|
||||
ViewData["Account"] = false;
|
||||
break;
|
||||
}
|
||||
return View("SimonIndex");
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Edit(int? id)
|
||||
{
|
||||
if (id.HasValue)
|
||||
{
|
||||
return View(SysUserManager.Get(id));
|
||||
}
|
||||
var model = new SysUsers { ID = 0, Account = "", Role = null, Group = null, ActiveIndicator = true, Sort = 1, Remark = "" };
|
||||
return View(model);
|
||||
}
|
||||
|
||||
public ActionResult ChangePassword(int id)
|
||||
{
|
||||
ViewData["ID"] = id;
|
||||
return View();
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public ActionResult ChangePassword(int id, string password)
|
||||
{
|
||||
if (String.IsNullOrEmpty(password))
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("ThePasswordCanNotBeEmptyPleaseReEnter") });
|
||||
}
|
||||
SysUsers user = SysUserManager.Get(id);
|
||||
if (user != null)
|
||||
{
|
||||
SysUserManager.Update(user, password);
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("ResetPassword"), user.Account);
|
||||
}
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("PasswordResetSuccess") });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAllByPage(string order, string sort, int? groupId)//int page, int rows,
|
||||
{
|
||||
if (groupId.HasValue)
|
||||
{
|
||||
//long total = 0;
|
||||
//IList<SysUsers> list = this.SysUserManager.LoadAllByPage(out total, page, rows, order, sort, 0, groupId, CurrentHotelID);
|
||||
SysUsers curUser = this.SysUserManager.Get(User.Identity.Name);
|
||||
IList<SysUsers> list = this.SysUserManager.LoadAll().Where(r => r.HotelID == 0 && !r.IsDeleted && r.SysHotelGroup.ID != curUser.SysHotelGroup.ID
|
||||
&& (r.SysHotelGroup.ID == groupId || (r.SysHotelGroup.Parent != null && r.SysHotelGroup.Parent.ID == groupId)
|
||||
|| (r.SysHotelGroup.Parent != null && r.SysHotelGroup.Parent.Parent != null && r.SysHotelGroup.Parent.Parent.ID == groupId))).ToList();
|
||||
|
||||
IList<object> result = new List<object>();
|
||||
foreach (var user in list)
|
||||
{
|
||||
result.Add(new
|
||||
{
|
||||
ID = user.ID,
|
||||
Account = user.Account,
|
||||
RoleID = user.Role != null ? user.Role.ID.ToString() : "",
|
||||
RoleName = user.Role != null ? user.Role.Name : "",
|
||||
GroupID = user.Group != null ? user.Group.ID.ToString() : "",
|
||||
GroupName = GroupManager.BuildGroupName(user.Group),
|
||||
SysHotelGroupName = SysHotelGroupManager.BuildGroupName(user.SysHotelGroup),
|
||||
ActiveIndicator = user.ActiveIndicator,
|
||||
Sort = user.Sort,
|
||||
Remark = user.Remark,
|
||||
CreatedBy = user.CreatedBy,
|
||||
CreatedDate = user.CreatedDate,
|
||||
ModifiedBy = user.ModifiedBy,
|
||||
ModifiedDate = user.ModifiedDate,
|
||||
HotelID = user.HotelID,
|
||||
Password2 = user.Password2
|
||||
});
|
||||
}
|
||||
return Json(new { total = result.Count, rows = result });
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { total = 0, rows = new List<object>() });
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult AuthorityHotel(int id)
|
||||
{
|
||||
return View(new SysUsers { ID = id });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult LoadAuthorityHotel(int userID)
|
||||
{
|
||||
var user = SysUserManager.Get(userID);
|
||||
switch (user.Account.ToLower())
|
||||
{
|
||||
case "admin":
|
||||
case "leo":
|
||||
case "blw":
|
||||
user.Hotels = SysHotelManager.LoadAll();
|
||||
break;
|
||||
}
|
||||
var groupTree = SysHotelGroupManager.CreateGroupTreeWithHotel(user.SysHotelGroup, user.Hotels);
|
||||
IList<object> result = new List<object>();
|
||||
result.Add(new { id = 1, text = HttpContext.InnerLanguage("Hotel"), iconCls = "tree-node-no-icon", children = groupTree, attributes = new { isHotel = false } });
|
||||
return Json(result, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存授权酒店
|
||||
/// </summary>
|
||||
/// <param name="userID"></param>
|
||||
/// <param name="hotelID"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public ActionResult SaveAuthorityHotel(int userID, string hotelIDs)
|
||||
{
|
||||
var user = SysUserManager.Get(userID);
|
||||
user.Hotels.Clear();
|
||||
IList<int> ids = Newtonsoft.Json.JsonConvert.DeserializeObject<IList<int>>(hotelIDs);
|
||||
foreach (int id in ids)
|
||||
{
|
||||
user.Hotels.Add(SysHotelManager.Get(id));
|
||||
}
|
||||
SysUserManager.SaveOrUpdate(user);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Save(string jsonData)
|
||||
{
|
||||
var user = Newtonsoft.Json.JsonConvert.DeserializeObject<SysUsers>(jsonData);
|
||||
try
|
||||
{
|
||||
//var curUser = SysUserManager.Get(User.Identity.Name);
|
||||
//if (user.SysHotelGroup.ID == curUser.SysHotelGroup.ID)
|
||||
//{
|
||||
// return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("Flag") });
|
||||
//}
|
||||
var existUser = SysUserManager.Get(user.Account);
|
||||
IList<SysHotel> hotels = new List<SysHotel>();
|
||||
var visitHotel = SysHotelManager.LoadAll().Where(r => r.SysHotelGroup.ID == user.SysHotelGroup.ID ||
|
||||
(r.SysHotelGroup.Parent != null && r.SysHotelGroup.Parent.ID == user.SysHotelGroup.ID) ||
|
||||
(r.SysHotelGroup.Parent != null && r.SysHotelGroup.Parent.Parent != null && r.SysHotelGroup.Parent.Parent.ID == user.SysHotelGroup.ID)).FirstOrDefault();
|
||||
if (visitHotel == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = "该用户默认访问酒店不能为空" });
|
||||
}
|
||||
hotels.Add(visitHotel);
|
||||
if (user.ID == 0)
|
||||
{
|
||||
if (null != existUser)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("Account") + "【" + user.Account + "】" + HttpContext.InnerLanguage("AlreadyExist") });
|
||||
}
|
||||
user.Name = user.Account;
|
||||
user.CreatedBy = user.ModifiedBy = this.User.Identity.Name;
|
||||
user.CreatedDate = user.ModifiedDate = DateTime.Now;
|
||||
user.Hotels = hotels;
|
||||
user.Group = GroupManager.LoadAll().Where(r => r.HotelID == visitHotel.ID).FirstOrDefault();
|
||||
user.HotelID = 0;//0表示组角色,跟酒店无关
|
||||
|
||||
SysUserManager.Save(user);
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("New"), user.Account);
|
||||
}
|
||||
else
|
||||
{
|
||||
var currentUser = SysUserManager.Get(user.ID);
|
||||
if (existUser != null && existUser.ID != currentUser.ID)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("Account") + "【" + user.Account + "】" + HttpContext.InnerLanguage("AlreadyExist") });
|
||||
}
|
||||
currentUser.Account = user.Account;
|
||||
currentUser.Role = user.Role;
|
||||
//currentUser.Group = user.Group;
|
||||
currentUser.SysHotelGroup = user.SysHotelGroup;
|
||||
currentUser.ActiveIndicator = user.ActiveIndicator;
|
||||
currentUser.Sort = user.Sort;
|
||||
currentUser.Remark = user.Remark;
|
||||
currentUser.ModifiedBy = User.Identity.Name;
|
||||
currentUser.ModifiedDate = DateTime.Now;
|
||||
//currentUser.HotelID = CurrentHotelID;
|
||||
|
||||
SysUserManager.Update(currentUser);
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Edit"), user.Account);
|
||||
}
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("SaveSuccess") });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex);
|
||||
return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("SaveFailedBecause") + ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult Delete(IList<int> idList, IList<string> nameList)
|
||||
{
|
||||
//SysUserManager.Delete(idList.Cast<object>().ToList());
|
||||
foreach (int id in idList)
|
||||
{
|
||||
SysUsers user = SysUserManager.Get(id);
|
||||
user.IsDeleted = true;
|
||||
SysUserManager.Update(user);
|
||||
}
|
||||
SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("Delete"), string.Join(",", nameList));
|
||||
return Json(new { IsSuccess = true, Message = HttpContext.InnerLanguage("DeleteSuccess") });
|
||||
}
|
||||
|
||||
private IList<SysHotel> GetHotels(IList<int> hotelIDs)
|
||||
{
|
||||
IList<SysHotel> hotels = new List<SysHotel>();
|
||||
if (hotelIDs != null)
|
||||
{
|
||||
foreach (int hotelID in hotelIDs)
|
||||
{
|
||||
var hotel = SysHotelManager.Get(hotelID);
|
||||
if (hotel != null && !hotels.Contains(hotel))
|
||||
{
|
||||
hotels.Add(hotel);
|
||||
}
|
||||
}
|
||||
}
|
||||
return hotels;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
21
WebSite/Controllers/TFTPController.cs
Normal file
21
WebSite/Controllers/TFTPController.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class TFTPController : BaseController
|
||||
{
|
||||
//
|
||||
// GET: /MachineRegisterLog/
|
||||
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(MachineRegisterLogController));
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
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; }
|
||||
}
|
||||
}
|
||||
992
WebSite/Controllers/WeiXinController.cs
Normal file
992
WebSite/Controllers/WeiXinController.cs
Normal file
@@ -0,0 +1,992 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Service;
|
||||
using Domain;
|
||||
using WebSite.Models;
|
||||
|
||||
namespace WebSite.Controllers
|
||||
{
|
||||
public class WeiXinController : BaseController
|
||||
{
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(WeiXinController));
|
||||
public IHostManager HostManager { get; set; }
|
||||
public IHostModalManager HostModalManager { get; set; }
|
||||
public IHostAirManager HostAirManager { get; set; }
|
||||
public IRoomTypeSceneManager RoomTypeSceneManager { get; set; }
|
||||
public ILightControlManager LightControlManager { 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 ISysHotelManager SysHotelManager { get; set; }
|
||||
public IUnlockControlManager UnlockControlManager { get; set; }
|
||||
public IMusicControlManager MusicControlManager { get; set; }
|
||||
public IAppMenuManager AppMenuManager { get; set; }
|
||||
public IRoomTypeWXMenusManager RoomTypeWXMenusManager { get; set; }
|
||||
|
||||
public IList<RoomTypeWXMenus> WXMenuList;
|
||||
|
||||
public ActionResult Index(string code, string creatDate)
|
||||
{
|
||||
SysHotel sysHotel = SysHotelManager.GetByCode(code, Convert.ToDateTime(creatDate));
|
||||
if (sysHotel == null)
|
||||
{
|
||||
ViewData["Error"] = "验证码有误,请联系管理员。";
|
||||
return View("Error");
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentHotelID = sysHotel.ID;//缓存当前酒店ID
|
||||
return Login();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult Login()
|
||||
{
|
||||
if (Request.Cookies["WXRoomNumber"] == null)
|
||||
{
|
||||
ViewData["RoomNumber"] = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewData["RoomNumber"] = Request.Cookies["WXRoomNumber"].Value;
|
||||
}
|
||||
return View("Login");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Login(string roomNumber, string identity)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = "无效房号或客房未出租。" });
|
||||
}
|
||||
else
|
||||
{
|
||||
//using (ServiceReference1.syncstatusSoapClient wsClient = new ServiceReference1.syncstatusSoapClient())
|
||||
//{
|
||||
// if (!wsClient.ValidateNumber(CurrentHotelID, roomNumber, identity))
|
||||
// {
|
||||
// return Json(new { IsSuccess = false, Message = "验证码有误。" });
|
||||
// }
|
||||
//}
|
||||
}
|
||||
//获取微信显示的菜单
|
||||
WXMenuList = new List<RoomTypeWXMenus>();
|
||||
IList<RoomTypeWXMenus> WXMenus = RoomTypeWXMenusManager.LoadAll(host.RoomType.ID).Where(r => r.ActiveIndicator == true).ToList();
|
||||
if (WXMenus.Count == 0)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = "登录失败,原因:未设置微信菜单" });
|
||||
}
|
||||
int width = 100 / WXMenus.Count;
|
||||
foreach (RoomTypeWXMenus menu in WXMenus)
|
||||
{
|
||||
WXMenuList.Add(new RoomTypeWXMenus { Code = menu.Code, Name = menu.Name, Class = menu.Class, Width = width });
|
||||
}
|
||||
Session["WXMenuList"] = WXMenuList;
|
||||
Response.Cookies["WXRoomNumber"].Value = roomNumber;
|
||||
Response.Cookies["WXRoomNumber"].Expires = DateTime.Now.AddYears(1);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = "登录成功。", Target = "/WeiXin/" + WXMenuList[0].Code + "?RoomNumber=" + roomNumber });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = "登录失败,原因:" + ex.Message });
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 微信开锁
|
||||
/// </summary>
|
||||
/// <param name="roomNumber"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult Unlock(string roomNumber, string code, string creatDate)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(code))
|
||||
{
|
||||
SysHotel sysHotel = SysHotelManager.GetByCode(code, Convert.ToDateTime(creatDate));
|
||||
if (sysHotel == null)
|
||||
{
|
||||
ViewData["Error"] = "验证码有误,请联系管理员。";
|
||||
return View("Error");
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentHotelID = sysHotel.ID;//缓存当前酒店ID
|
||||
}
|
||||
}
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = "无效房号或客房未出租。";
|
||||
return View("Error");
|
||||
}
|
||||
ViewData["RoomNumber"] = roomNumber;
|
||||
return View();
|
||||
}
|
||||
/// <summary>
|
||||
/// 开锁控制
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public ActionResult UnlockControl(string roomNumber)
|
||||
{
|
||||
try
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
return Json(new { IsSuccess = true, Message = "无效房号或客户未出租。" });
|
||||
}
|
||||
|
||||
UnlockControlManager.Send(host);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = "开锁成功。" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = true, Message = "操作失败,原因:" + ex.Message });
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 灯光
|
||||
/// </summary>
|
||||
/// <param name="roomNumber"></param>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="creatDate"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult Light(string roomNumber, string code, string creatDate)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(code))
|
||||
{
|
||||
SysHotel sysHotel = SysHotelManager.GetByCode(code, Convert.ToDateTime(creatDate));
|
||||
if (sysHotel == null)
|
||||
{
|
||||
ViewData["Error"] = "验证码有误,请联系管理员。";
|
||||
return View("Error");
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentHotelID = sysHotel.ID;//缓存当前酒店ID
|
||||
}
|
||||
}
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = "无效房号或客房未出租。";
|
||||
return View("Error");
|
||||
}
|
||||
ViewData["RoomNumber"] = roomNumber;
|
||||
|
||||
IList<HostModal> lightModals = HostModalManager.LoadAll().Where(r => r.HostID == host.ID && r.Modal.Name != null && r.Modal.Name != "" && r.Modal.ActiveIndicator == true).ToList();
|
||||
IList<Light> LightList = new List<Light>();
|
||||
IList<Light> DimmerList = new List<Light>();
|
||||
foreach (HostModal modal in lightModals)
|
||||
{
|
||||
switch (modal.Modal.Type)
|
||||
{
|
||||
case DeviceType.Relay:
|
||||
case DeviceType.Expand:
|
||||
Light light = new Light { Name = ((Boolean)Session["isCN"]) ? modal.Modal.Name : modal.Modal.EnglishName, ModalAddress = modal.Modal.ModalAddress, Status = modal.Brightness };
|
||||
LightList.Add(light);
|
||||
break;
|
||||
case DeviceType.Dimmer:
|
||||
case DeviceType.PWMDimmer:
|
||||
case DeviceType.PWMExpand:
|
||||
case DeviceType.LVout://弱电输出
|
||||
//case DeviceType.Strip:
|
||||
case DeviceType.Traic:
|
||||
case DeviceType.PB20:
|
||||
case DeviceType.PB20_LD:
|
||||
case DeviceType.PB20_LS:
|
||||
Light dimmer = new Light { Name = ((Boolean)Session["isCN"]) ? modal.Modal.Name : modal.Modal.EnglishName, ModalAddress = modal.Modal.ModalAddress, Status = modal.Brightness };
|
||||
DimmerList.Add(dimmer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ViewData["LightList"] = LightList;
|
||||
ViewData["DimmerList"] = DimmerList;
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
//public ActionResult LoadLightDimmer(string roomNumber)
|
||||
//{
|
||||
// Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
// IList<HostModal> DimmerModals = HostModalManager.Load(host.ID, DeviceType.Dimmer).Where(r => r.Modal.AppApply).ToList();
|
||||
|
||||
// IList<Light> DimmerLightList = new List<Light>();
|
||||
|
||||
// bool isCN = (Request.Cookies["isCN"].Value == "zh-cn");
|
||||
|
||||
// foreach (HostModal modal in DimmerModals)
|
||||
// {
|
||||
// Light light = new Light { Name = isCN ? modal.Modal.Name : modal.Modal.EnglishName, ModalAddress = modal.Modal.ModalAddress, Status = modal.Brightness };
|
||||
|
||||
// DimmerLightList.Add(light);
|
||||
// }
|
||||
|
||||
// return Json(DimmerLightList);
|
||||
//}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult LightControl(string roomNumber, string groupAddress, int status)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = "无效房号或客房未出租。";
|
||||
return View("Error");
|
||||
}
|
||||
if (!host.Status)
|
||||
{
|
||||
string message = String.Format(HttpContext.InnerLanguage("SendFailedHostOffline"), host.RoomNumber);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = "操作失败,原因:" + message });
|
||||
}
|
||||
ViewData["RoomNumber"] = roomNumber;
|
||||
|
||||
var hostModal = HostModalManager.GetByModalAddress(host.ID, groupAddress);
|
||||
if (hostModal == null)
|
||||
{
|
||||
ViewData["Error"] = "无效的灯光。";
|
||||
return View("Error");
|
||||
}
|
||||
|
||||
HostModalManager.SetDevice(host, hostModal, (status == 1 ? 1 : 2), status);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = "操作成功!" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = "操作失败,原因:" + ex.Message });
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 场景
|
||||
/// </summary>
|
||||
/// <param name="roomNumber"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult Scene(string roomNumber)
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = "无效房号或客房未出租。";
|
||||
return View("Error");
|
||||
}
|
||||
ViewData["RoomNumber"] = roomNumber;
|
||||
|
||||
IList<RoomTypeScene> modals = RoomTypeSceneManager.LoadAll().Where(r => r.RoomType.ID == host.RoomType.ID && r.ActiveIndicator == true).OrderBy(r => r.Sort).ToList(); ;
|
||||
List<SceneState> sceneList = new List<SceneState>();
|
||||
var lightState = new LightState();
|
||||
foreach (var modal in modals)
|
||||
{
|
||||
SceneState sceneState = new SceneState
|
||||
{
|
||||
SceneID = modal.ID,
|
||||
Name = modal.Name,
|
||||
Icon = modal.Icon
|
||||
};
|
||||
sceneList.Add(sceneState);
|
||||
}
|
||||
ViewData["SceneList"] = sceneList;
|
||||
return View();
|
||||
}
|
||||
/// <summary>
|
||||
/// 场景控制
|
||||
/// </summary>
|
||||
/// <param name="roomNumber"></param>
|
||||
/// <param name="sceneId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public ActionResult SceneControl(string roomNumber, int? sceneId)
|
||||
{
|
||||
try
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = "无效房号或客房未出租。";
|
||||
return View("Error");
|
||||
}
|
||||
|
||||
if (!host.Status)
|
||||
{
|
||||
string message = String.Format(HttpContext.InnerLanguage("SendFailedHostOffline"), host.RoomNumber);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = "操作失败,原因:" + message });
|
||||
}
|
||||
|
||||
|
||||
if (!sceneId.HasValue || sceneId == 0)
|
||||
{
|
||||
ViewData["Error"] = "无效的场景。";
|
||||
return View("Error");
|
||||
}
|
||||
|
||||
|
||||
var scene = RoomTypeSceneManager.Get(sceneId);
|
||||
if (scene == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = "无效的场景。" });
|
||||
}
|
||||
|
||||
LightControlManager.ApplyScene(host, scene);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = "设置场景成功!" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 风扇
|
||||
/// </summary>
|
||||
/// <param name="roomNumber"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult Fan(string roomNumber)
|
||||
{
|
||||
ViewData["RoomNumber"] = roomNumber;
|
||||
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = "无效房号或客房未出租。";
|
||||
return View("Error");
|
||||
}
|
||||
|
||||
IList<HostModal> DimmerModals = HostModalManager.Load(host.ID, DeviceType.Dimmer).Where(r => r.Modal.Name != "" && r.Modal.Name != null).ToList();
|
||||
|
||||
IList<Light> FanList = new List<Light>();
|
||||
|
||||
foreach (HostModal modal in DimmerModals)
|
||||
{
|
||||
Light light = new Light { Name = ((Boolean)Session["isCN"]) ? modal.Modal.Name : modal.Modal.EnglishName, ModalAddress = modal.Modal.ModalAddress, Status = modal.Brightness };
|
||||
|
||||
FanList.Add(light);
|
||||
}
|
||||
|
||||
ViewData["FanList"] = FanList;
|
||||
|
||||
return View();
|
||||
}
|
||||
/// <summary>
|
||||
/// 风扇控制
|
||||
/// </summary>
|
||||
/// <param name="roomNumber"></param>
|
||||
/// <param name="groupAddress"></param>
|
||||
/// <param name="status"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public ActionResult FanControl(string roomNumber, string groupAddress, int status)
|
||||
{
|
||||
try
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = "无效房号或客房未出租。";
|
||||
return View("Error");
|
||||
}
|
||||
|
||||
if (!host.Status)
|
||||
{
|
||||
string message = String.Format(HttpContext.InnerLanguage("SendFailedHostOffline"), host.RoomNumber);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = "操作失败,原因:" + message });
|
||||
}
|
||||
|
||||
|
||||
var hostModal = HostModalManager.GetByModalAddress(host.ID, groupAddress);
|
||||
if (hostModal == null)
|
||||
{
|
||||
ViewData["Error"] = "无效的灯光。";
|
||||
return View("Error");
|
||||
}
|
||||
|
||||
HostModalManager.SetDevice(host, hostModal, (status != 0 ? 1 : 0), status);
|
||||
|
||||
return Json(new { IsSuccess = true });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = true, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult LoadAirSetting(int hostId, int airId)
|
||||
{
|
||||
HostAir hostAir = HostAirManager.GetByModalTypeID(hostId, airId);
|
||||
|
||||
object air = new
|
||||
{
|
||||
Running = hostAir.OnOff,
|
||||
SettingTemp = hostAir.SettingTemp,
|
||||
Speed = hostAir.Speed,
|
||||
HightTemp = hostAir.HightTemp,
|
||||
LowerTemp = hostAir.LowerTemp,
|
||||
Mode = hostAir.Mode
|
||||
};
|
||||
|
||||
return Json(air);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult Air(string roomNumber)
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = "无效房号或客房未出租。";
|
||||
return View("Error");
|
||||
}
|
||||
|
||||
//var air = RoomTypeModalManager.Get(host.RoomType, "空调");
|
||||
//if (air == null)
|
||||
//{
|
||||
// ViewData["Error"] = "无效的空调。";
|
||||
// return View("Error");
|
||||
//}
|
||||
|
||||
ViewData["RoomNumber"] = roomNumber;
|
||||
//ViewData["AirModalId"] = air.ModalID;
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
public List<Air> ListAir(string roomNumber)
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
List<HostAir> hostAir = HostAirManager.LoadAll().Where(r => r.HostID == host.ID).ToList();
|
||||
|
||||
List<Air> list = new List<Air>();
|
||||
|
||||
foreach (HostAir item in hostAir)
|
||||
{
|
||||
Air air = new Air { HostID = item.HostID, Name = item.Modal.CustomerName, RoomTypeAirID = item.Modal.ModalType.ID };
|
||||
|
||||
list.Add(air);
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
public ActionResult LoadAir(string roomNumber)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = "无效房号或客房未出租。";
|
||||
return View("Error");
|
||||
}
|
||||
|
||||
List<Air> list = ListAir(roomNumber);
|
||||
|
||||
if (list.Count <= 0)
|
||||
{
|
||||
ViewData["Error"] = "该房号未配置空调。";
|
||||
return View("Error");
|
||||
}
|
||||
|
||||
return Json(list);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Air(string roomNumber, int airId, AirProperty property, int status)
|
||||
{
|
||||
try
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = "无效房号或客房未出租。";
|
||||
return View("Error");
|
||||
}
|
||||
|
||||
if (!host.Status)
|
||||
{
|
||||
string message = String.Format(HttpContext.InnerLanguage("SendFailedHostOffline"), host.RoomNumber);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = "操作失败,原因:" + message });
|
||||
}
|
||||
|
||||
//if (host != null)
|
||||
//{
|
||||
// HostAirManager.SetAirProperty(host, airId, property, status);
|
||||
//}
|
||||
|
||||
if (host != null)
|
||||
{
|
||||
HostAirManager.SetAirProperty(host, airId, property, status);
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = "操作成功!" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult Television(string roomNumber)
|
||||
{
|
||||
ViewData["RoomNumber"] = roomNumber;
|
||||
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
throw new ApplicationException("无效房号或客户未出租。");
|
||||
}
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Television(string roomNumber, TvKey key)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = "无效房号或客房未出租。";
|
||||
return View("Error");
|
||||
}
|
||||
|
||||
if (!host.Status)
|
||||
{
|
||||
string message = String.Format(HttpContext.InnerLanguage("SendFailedHostOffline"), host.RoomNumber);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = "操作失败,原因:" + message });
|
||||
}
|
||||
|
||||
TvControlManager.SendKey(host, key);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = "操作成功。" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Service(string roomNumber, string groupAddress, int status)
|
||||
{
|
||||
try
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
throw new ApplicationException("无效房号或客户未出租。");
|
||||
}
|
||||
|
||||
if (!host.Status)
|
||||
{
|
||||
string message = String.Format(HttpContext.InnerLanguage("SendFailedHostOffline"), host.RoomNumber);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = "操作失败,原因:" + message });
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(groupAddress))
|
||||
{
|
||||
throw new ApplicationException("无效的服务编号!");
|
||||
}
|
||||
if (groupAddress == "B09")//开锁
|
||||
{
|
||||
UnlockControlManager.Send(host);
|
||||
}
|
||||
else
|
||||
{
|
||||
RoomServiceManager.SetService(host, groupAddress, status);
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Message = "操作成功。" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ActionResult LoadAlarm(string roomNumber)
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
IList<AlarmSetting> AlarmList = AlarmSettingManager.LoadAll('B').Where(r => r.HotelID == CurrentHotelID).Where(r => r.AppApply).ToList();
|
||||
|
||||
IList<AlarmService> Service = new List<AlarmService>();
|
||||
|
||||
for (int i = 0; i < AlarmList.Count; i++)
|
||||
{
|
||||
AlarmService alarmService = new AlarmService();
|
||||
|
||||
alarmService.Status = RoomServiceManager.Get(host.ID, AlarmList[i].Code).Status;
|
||||
alarmService.Name = AlarmList[i].Name;
|
||||
alarmService.Code = AlarmList[i].Code;
|
||||
|
||||
Service.Add(alarmService);
|
||||
}
|
||||
|
||||
return Json(Service);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult Service(string roomNumber, string code, string creatDate)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(code))
|
||||
{
|
||||
SysHotel sysHotel = SysHotelManager.GetByCode(code, Convert.ToDateTime(creatDate));
|
||||
if (sysHotel == null)
|
||||
{
|
||||
ViewData["Error"] = "验证码有误,请联系管理员。";
|
||||
return View("Error");
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentHotelID = sysHotel.ID;//缓存当前酒店ID
|
||||
}
|
||||
}
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = "无效房号或客房未出租。";
|
||||
return View("Error");
|
||||
}
|
||||
ViewData["RoomNumber"] = roomNumber;
|
||||
|
||||
IList<HostModal> serviceModals = HostModalManager.Load(host.ID, DeviceType.ServiceInfo).Where(r => r.Modal.Name != null && r.Modal.Name != "" && r.Modal.ActiveIndicator == true).ToList();
|
||||
IList<Light> ServiceList = new List<Light>();
|
||||
foreach (HostModal modal in serviceModals)
|
||||
{
|
||||
Light light = new Light { Name = ((Boolean)Session["isCN"]) ? modal.Modal.Name : modal.Modal.EnglishName, ModalAddress = modal.Modal.ModalAddress, Status = modal.Brightness };
|
||||
ServiceList.Add(light);
|
||||
}
|
||||
ViewData["ServiceList"] = ServiceList;
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult LoadCurtain(string roomNumber, DeviceType deviceType)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
if (host == null)
|
||||
{
|
||||
throw new ApplicationException(HttpContext.InnerLanguage("InvalidRoomNumber"));
|
||||
}
|
||||
|
||||
//var hostModals = HostModalManager.Load(host.ID, deviceType).OrderBy(r => r.Modal.Sort).ToList();
|
||||
IList<HostModal> hostModals = HostModalManager.LoadAll().Where(r => r.HostID == host.ID && r.Modal.Type == DeviceType.Curtain
|
||||
&& r.Modal.Name != null && r.Modal.Name != "" && r.Modal.ActiveIndicator == true).ToList();
|
||||
|
||||
var curtainList = new List<CurtainModel>();
|
||||
|
||||
for (int i = 0; i < hostModals.Count; i++)
|
||||
{
|
||||
curtainList.Add(new CurtainModel() { Name = hostModals[i].Modal.Name, status = -1, curtainId = Convert.ToInt32(hostModals[i].Modal.ModalAddress) });
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = true, Data = curtainList });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
public class CurtainModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public int curtainId { get; set; }
|
||||
|
||||
public int status { get; set; }
|
||||
}
|
||||
|
||||
|
||||
//private CurtainModel CreateCurtainModel(IList<HostModal> hostModals)
|
||||
//{
|
||||
// var curtain = new CurtainModel();
|
||||
|
||||
// bool isCN = (Request.Cookies["isCN"].Value == "zh-cn");
|
||||
|
||||
// if (hostModals.Count >= 2)
|
||||
// {
|
||||
// var curtainOpenModal = hostModals.FirstOrDefault(r => r.Modal != null &&
|
||||
// r.Modal.Subtype.HasValue &&
|
||||
// (r.Modal.Subtype.Value == DeviceSubtype.CurtainOpen ||
|
||||
// r.Modal.Subtype.Value == DeviceSubtype.GauzeOpen));
|
||||
// if (curtainOpenModal != null)
|
||||
|
||||
// {
|
||||
// curtain.CurtainOpen = new CurtainOpenCloseModel
|
||||
// {
|
||||
// Address = curtainOpenModal.Modal.ModalAddress,
|
||||
// Name = isCN ? curtainOpenModal.Modal.Name : curtainOpenModal.Modal.EnglishName,
|
||||
// Subtype = curtainOpenModal.Modal.Subtype.Value,
|
||||
// Status = curtainOpenModal.Status
|
||||
// };
|
||||
// }
|
||||
|
||||
// var closeSubtype = curtain.CurtainOpen.Subtype == DeviceSubtype.CurtainOpen ? DeviceSubtype.CurtainClose : DeviceSubtype.GauzeClose;
|
||||
|
||||
// var curtainCloseModal = hostModals.FirstOrDefault(r => r.Modal != null && r.Modal.Subtype.HasValue && r.Modal.Subtype.Value == closeSubtype);
|
||||
// if (curtainCloseModal != null)
|
||||
// {
|
||||
// curtain.CurtainClose = new CurtainOpenCloseModel
|
||||
// {
|
||||
// Address = curtainCloseModal.Modal.ModalAddress,
|
||||
// Name = isCN ? curtainCloseModal.Modal.Name : curtainCloseModal.Modal.EnglishName,
|
||||
// Subtype = curtainCloseModal.Modal.Subtype.Value
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
|
||||
// return curtain;
|
||||
//}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult Curtain(string roomNumber)
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = "无效房号或客房未出租。";
|
||||
return View("Error");
|
||||
}
|
||||
|
||||
ViewData["RoomNumber"] = roomNumber;
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Curtain(string roomNumber, int CurtainId, CurtainCtrl ctrl)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
throw new ApplicationException("无效房号或客户未出租。");
|
||||
}
|
||||
|
||||
if (!host.Status)
|
||||
{
|
||||
string message = String.Format(HttpContext.InnerLanguage("SendFailedHostOffline"), host.RoomNumber);
|
||||
|
||||
return Json(new { IsSuccess = false, Message = "操作失败,原因:" + message });
|
||||
}
|
||||
|
||||
CurtainControlManager.SendCtrl(host, CurtainId, ctrl);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = "操作成功。" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult Music(string roomNumber)
|
||||
{
|
||||
ViewData["RoomNumber"] = roomNumber;
|
||||
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
throw new ApplicationException("无效房号或客户未出租。");
|
||||
}
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Music(string roomNumber, MusicKey key)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
if (host == null || host.RoomStatus.ID != 2)
|
||||
{
|
||||
ViewData["Error"] = "无效房号或客房未出租。";
|
||||
return View("Error");
|
||||
}
|
||||
|
||||
MusicControlManager.SendKey(host, key);
|
||||
|
||||
return Json(new { IsSuccess = true, Message = "操作成功。" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 小白调用
|
||||
/// </summary>
|
||||
/// <param name="roomNumber"></param>
|
||||
/// <param name="RobotAction"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult GetRobotAction(string roomNumber, string RobotAction)
|
||||
{
|
||||
Host host = HostManager.GetByRoomNumber(roomNumber, CurrentHotelID);
|
||||
|
||||
if (host == null)
|
||||
{
|
||||
return Json(new { IsSuccess = false, Result = "房号未知,请联系管理员。" }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
string[] item = RobotAction.Split('|');
|
||||
|
||||
if (item.Length > 0)
|
||||
{
|
||||
if (item[0] == "Light")
|
||||
{
|
||||
string groupAddress = item[1];
|
||||
|
||||
int status = Convert.ToInt32(item[2]);
|
||||
|
||||
LightControl(roomNumber, groupAddress, status);
|
||||
|
||||
return Json(new { IsSuccess = true, Result = "灯光下发成功" }, JsonRequestBehavior.AllowGet);
|
||||
|
||||
}
|
||||
else if (item[0] == "Scene")
|
||||
{
|
||||
int sceneId = Convert.ToInt32(item[1]);
|
||||
|
||||
SceneControl(roomNumber, sceneId);
|
||||
|
||||
return Json(new { IsSuccess = false, Result = "场景下发成功" }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
else if (item[0] == "Air")
|
||||
{
|
||||
List<Air> list = ListAir(roomNumber);
|
||||
|
||||
Air air = list[0];
|
||||
|
||||
AirProperty property = (AirProperty)Enum.Parse(typeof(AirProperty), item[1]);
|
||||
|
||||
Air(roomNumber, air.RoomTypeAirID, property, int.Parse(item[2]));
|
||||
|
||||
return Json(new { IsSuccess = true, Result = "空调下发成功" }, JsonRequestBehavior.AllowGet);
|
||||
|
||||
}
|
||||
else if (item[0] == "Television")
|
||||
{
|
||||
TvKey key = (TvKey)Enum.Parse(typeof(TvKey), item[1]);
|
||||
Television(roomNumber, key);
|
||||
|
||||
return Json(new { IsSuccess = true, Result = "电视下发成功" }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
else if (item[0] == "Curtain")
|
||||
{
|
||||
//Curtain(roomNumber, item[1], 0);
|
||||
//Curtain(roomNumber, item[2], 0);
|
||||
//Curtain(roomNumber, item[3], int.Parse(item[4]));
|
||||
CurtainCtrl key = (CurtainCtrl)Enum.Parse(typeof(CurtainCtrl), item[2]);
|
||||
Curtain(roomNumber, Convert.ToInt32(item[1]), key);
|
||||
return Json(new { IsSuccess = true, Result = "窗帘下发成功" }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
}
|
||||
|
||||
return Json(new { IsSuccess = false, Result = "未知,请联系管理员。" }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
//private void CreateWeiXinJsApiConfig()
|
||||
//{
|
||||
// var accessToken = Common.MemoryCacheHelper.Get("WeiXinAccessToken", "") as Common.WeiXinAccessToken;
|
||||
// if (accessToken == null)
|
||||
// {
|
||||
// accessToken = Common.WeiXinHelper.GetAccessToken();
|
||||
// if (accessToken.ErrorCode == 0)
|
||||
// {
|
||||
// Common.MemoryCacheHelper.Set("WeiXinAccessToken", accessToken, DateTimeOffset.Now.AddSeconds(accessToken.ExpiresIn));
|
||||
// }
|
||||
// }
|
||||
|
||||
// var jsApiTicket = Common.MemoryCacheHelper.Get("WeiXinJsApiTicket", "") as Common.WeiXinJsApiTicket;
|
||||
// if (jsApiTicket == null)
|
||||
// {
|
||||
// jsApiTicket = Common.WeiXinHelper.GetJsApiTicket(accessToken.AccessToken);
|
||||
// if (jsApiTicket.ErrorCode == 0)
|
||||
// {
|
||||
// Common.MemoryCacheHelper.Set("WeiXinJsApiTicket", jsApiTicket, DateTimeOffset.Now.AddSeconds(jsApiTicket.ExpiresIn));
|
||||
// }
|
||||
// }
|
||||
|
||||
// string noncestr = Common.WeiXinHelper.CreateNonceStr();
|
||||
|
||||
// int timestamp = Common.WeiXinHelper.GetCurrentTimeStamp();
|
||||
|
||||
// string signature = Common.WeiXinHelper.CreateJsApiSignature(jsApiTicket.Ticket, noncestr, timestamp, Request.Url.AbsoluteUri);
|
||||
|
||||
// ViewData["AppId"] = Common.WeiXinHelper.AppId;
|
||||
// ViewData["Timestamp"] = timestamp;
|
||||
// ViewData["NonceStr"] = noncestr;
|
||||
// ViewData["Signature"] = signature;
|
||||
// ViewData["JsApiTicket"] = jsApiTicket.Ticket;
|
||||
//}
|
||||
|
||||
public ActionResult Error(string msg)
|
||||
{
|
||||
ViewData["Error"] = msg;
|
||||
|
||||
return View();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 灯光状态类
|
||||
/// </summary>
|
||||
public class LightState
|
||||
{
|
||||
public string ModalID { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public int Status { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 场景类
|
||||
/// </summary>
|
||||
public class SceneState
|
||||
{
|
||||
public int SceneID { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Icon { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user