public void RegisterMember(string userName, int? deviceGpsTypeId, string deviceGpsNo, string deviceGpsSimNo, string password, int? roleId) { using (var dmTrans = _rep.GetTransaction()) { try { var tran = dmTrans.BeginTransaction(); var user = new EUser() { UserName = userName, NickName = userName, Password = password.GetMD5By32(), UserAvatar = "/Content/Images/noPic.jpg", LastLoginTime = DateTime.Now }; if (_rep.Get<EUser>(p => p.UserName == user.UserName) != null) { throw new ArgumentException("存在相同用户名!"); }; //添加用户 _rep.Add(user, tran); if (roleId.HasValue) { //添加角色 _rep.Add(new EUserRole() { UserId = user.Id, RoleId = roleId.Value }, null, tran); } //添加车辆分组 var deviceGroup = new EDeviceGroup() { DeviceGroupName = "默认分组", DeviceGroupOrderId = 0, IsRoot = true, UserId = user.Id }; _rep.Add(deviceGroup, tran); if (deviceGpsNo.HasValue() && deviceGpsSimNo.HasValue()) { //添加设备 if (_deviceService.CheckDeviceGpsNoIsExist(deviceGpsNo)) { throw new BusinessException("已经存在Gps设备号!"); } if (_deviceService.CheckDeviceGpsSimNoIsExist(deviceGpsSimNo)) { throw new BusinessException("已经存在Sim卡号!"); } var device = new EDevice { UserId = user.Id, DeviceName = deviceGpsNo, DeviceGpsNo = deviceGpsNo, DeviceGpsSimNo = deviceGpsSimNo, DeviceGpsTypeId = deviceGpsTypeId, DeviceTypeId = 1, DeviceGroupId = deviceGroup.Id, CreateTime = DateTime.Now, NodeId = _nodeService.GetNodeIdByCreateTime(DateTime.Now), DeviceGpsInstallTime = DateTime.Now, DeviceExpireTime = DateTime.Now.AddYears(5) }; device.DeviceGpsCode = _deviceService.GetDeviceGpsCode(device.DeviceGpsTypeId.Value, device.DeviceGpsNo, device.DeviceGpsSimNo); _rep.Add(device, tran); _rep.Add(new EAlarmSettingOverspeed() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); _rep.Add(new EAlarmSettingInOutArea() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); _rep.Add(new EAlarmSettingParkingNotStalled() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); _rep.Add(new EAlarmSettingTired() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); _rep.Add(new EAlarmSettingAutoFortify() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59), Radius = 50, ActivationTime = 10 }, tran); _rep.Add(new EAlarmSettingMainPowerBreak() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); } dmTrans.Commit(); //更新车辆分组缓存 _cacheService.RemoveByKey(Cdev.Core.Gps.CacheKey.Gps_DeviceGroups_All); } catch { dmTrans.Rollback(); throw; } } }
private EUser RegisterMemberByOpenLogin(EUser user, int? deviceGpsTypeId, string deviceGpsNo, string deviceGpsSimNo, int? roleId) { using (var dmTrans = _rep.GetTransaction()) { try { var tran = dmTrans.BeginTransaction(); //添加用户 _rep.Add(user, tran); if (roleId.HasValue) { //添加角色 _rep.Add(new EUserRole() { UserId = user.Id, RoleId = roleId.Value }, null, tran); } //添加车辆分组 var deviceGroup = new EDeviceGroup() { DeviceGroupName = "默认分组", DeviceGroupOrderId = 0, IsRoot = true, UserId = user.Id }; _rep.Add(deviceGroup, tran); if (deviceGpsNo.HasValue() && deviceGpsSimNo.HasValue()) { //添加设备 if (_deviceService.CheckDeviceGpsNoIsExist(deviceGpsNo)) { throw new BusinessException("已经存在Gps设备号!"); } if (_deviceService.CheckDeviceGpsSimNoIsExist(deviceGpsSimNo)) { throw new BusinessException("已经存在Sim卡号!"); } var device = new EDevice { UserId = user.Id, DeviceName = deviceGpsNo, DeviceGpsNo = deviceGpsNo, DeviceGpsSimNo = deviceGpsSimNo, DeviceGpsTypeId = deviceGpsTypeId, DeviceTypeId = 1, DeviceGroupId = deviceGroup.Id, CreateTime = DateTime.Now, NodeId = _nodeService.GetNodeIdByCreateTime(DateTime.Now), DeviceGpsInstallTime = DateTime.Now, DeviceExpireTime = DateTime.Now.AddYears(1) }; device.DeviceGpsCode = _deviceService.GetDeviceGpsCode(device.DeviceGpsTypeId.Value, device.DeviceGpsNo, device.DeviceGpsSimNo); _rep.Add(device, tran); _rep.Add(new EAlarmSettingOverspeed() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); _rep.Add(new EAlarmSettingInOutArea() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); _rep.Add(new EAlarmSettingParkingNotStalled() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); _rep.Add(new EAlarmSettingTired() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); _rep.Add(new EAlarmSettingAutoFortify() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59), Radius = 50, ActivationTime = 10 }, tran); _rep.Add(new EAlarmSettingMainPowerBreak() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); } dmTrans.Commit(); //更新车辆分组缓存 _cacheService.RemoveByKey(Cdev.Core.Gps.CacheKey.Gps_DeviceGroups_All); return user; } catch { dmTrans.Rollback(); throw; } } }
/// <summary> /// 递归获取车辆分组集合结构 /// </summary> /// <param name="root"></param> private void GetSubDeviceGroupListByRecursion(EDeviceGroup root, List<EDeviceGroup> list) { //获取下一级菜单 var children = GetAllDeviceGroupsFromCache().Where(p => p.DeviceGroupParentId == root.Id).OrderByDescending(p => p.DeviceGroupOrderId).ToList(); if (children.Count > 0) { list.AddRange(children); foreach (var sub in children) { GetSubDeviceGroupListByRecursion(sub, list); } } }
/// <summary> /// 递归获取车辆分组集合结构 /// </summary> /// <param name="root"></param> /// <param name="allDeviceGroupList"></param> private void GetSubDeviceGroupListByRecursion(EDeviceGroup root, List<EDeviceGroup> list, List<EDeviceGroup> allDeviceGroupList) { //获取下一级菜单 var children = allDeviceGroupList.Where(p => p.DeviceGroupParentId == root.Id).ToList(); if (children.Count > 0) { list.AddRange(children); foreach (var sub in children) { GetSubDeviceGroupListByRecursion(sub, list, allDeviceGroupList); } } }
/// <summary> /// 递归获取车辆分组树结构 /// </summary> /// <param name="root"></param> /// <param name="allDeviceGroupCategorys"></param> private void GetDeviceGroupTreeByRecursion(EDeviceGroup root) { //获取下一级菜单 var children = GetAllDeviceGroupsFromCache().Where(p => p.DeviceGroupParentId == root.Id).OrderByDescending(p => p.DeviceGroupOrderId).ToList(); if (children.Count > 0) { root.Children = children; foreach (var sub in root.Children) { GetDeviceGroupTreeByRecursion(sub); } } }
/// <summary> /// 递归获取车辆分组树结构 /// </summary> /// <param name="root"></param> /// <param name="allDeviceGroupList"></param> private void GetDeviceGroupTreeByRecursion(EDeviceGroup root, IList<EDeviceGroup> allDeviceGroupList) { //获取下一级菜单 var children = allDeviceGroupList.Where(p => p.DeviceGroupParentId == root.Id).OrderBy(p => p.DeviceGroupOrderId).ToList(); if (children.Count > 0) { root.Children = children; foreach (var sub in root.Children) { GetDeviceGroupTreeByRecursion(sub, allDeviceGroupList); } } }
/// <summary> /// 保存车辆分组 /// </summary> /// <param name="deviceGroup"></param> public void SaveDeviceGroup(EDeviceGroup deviceGroup) { _rep.Save(deviceGroup, p => p.Id == deviceGroup.Id); _cacheService.RemoveByKey(CacheKey.Gps_DeviceGroups_All); }
/// <summary> /// 递归获取车辆分组集合结构 /// </summary> /// <param name="deviceGroupId"></param> public IList<EDeviceGroup> GetSubDeviceGroups(int? deviceGroupId) { List<EDeviceGroup> list = new List<EDeviceGroup>(); if (deviceGroupId.HasValue) { EDeviceGroup root = GetDeviceGroupByIdFromCache(deviceGroupId.Value); GetSubDeviceGroupListByRecursion(root, list); return list; } else { EDeviceGroup root = new EDeviceGroup() { Id = deviceGroupId ?? 0, DeviceGroupName = "车辆分组" }; IList<EDeviceGroup> allDeviceGroupList = _rep.GetAll<EDeviceGroup>(p => p.DeviceGroupOrderId.Desc()); GetSubDeviceGroupListByRecursion(root, allDeviceGroupList.ToList()); return list; } }
/// <summary> /// 获取车辆分组树结构 /// </summary> /// <returns></returns> public EDeviceGroup GetDeviceGroupTreeById(int? deviceGroupId) { if (deviceGroupId.HasValue) { EDeviceGroup root = GetDeviceGroupByIdFromCache(deviceGroupId.Value); GetDeviceGroupTreeByRecursion(root); return root; } else { EDeviceGroup root = new EDeviceGroup() { Id = deviceGroupId ?? 0, DeviceGroupName = "车辆分组" }; IList<EDeviceGroup> allDeviceGroupList = GetAllDeviceGroupsFromCache(); GetDeviceGroupTreeByRecursion(root, allDeviceGroupList); return root; } }
/// <summary> /// 添加车辆分组 /// </summary> /// <param name="deviceGroup"></param> public void AddDeviceGroup(EDeviceGroup deviceGroup) { _rep.Add(deviceGroup); _cacheService.RemoveByKey(CacheKey.Gps_DeviceGroups_All); }
/// <summary> /// 编辑 /// </summary> /// <returns></returns> public ActionResult EditDeviceGroup(EDeviceGroup deviceGroup) { if (deviceGroup.Id == 0) { deviceGroup.IsRoot = false; deviceGroup.UserId = Passport.User.Id; _deviceGroupService.AddDeviceGroup(deviceGroup); return JsonResult(deviceGroup, "添加成功!"); } else { deviceGroup.UserId = Passport.User.Id; _deviceGroupService.SaveDeviceGroup(deviceGroup); return JsonResult(deviceGroup, "保存成功!"); } }