/// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        public ActionResult EditDevice(EDevice device)
        {
            if (device.Id == 0)
            {
                _deviceService.AddDevice(device);
                return JsonResult(device, "添加成功!");

            }
            else 
            {
                _deviceService.SaveDevice(device);
                return JsonResult(device, "保存成功!");
            }
        }
Exemple #2
0
        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;
                }
            }
        }
Exemple #3
0
        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;
                }
            }
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        public ActionResult EditDevice(EDevice device)
        {
            if (device.UserId == 0) 
            {
                device.UserId = Passport.User.Id;
            }
            if (device.Id == 0)
            {
                device.DeviceExpireTime = DateTime.Now.AddYears(1);
                _deviceService.AddDevice(device);
                return JsonResult(device, "添加成功!");

            }
            else
            {
                _deviceService.SaveDevice(device);
                return JsonResult(device, "保存成功!");
            }
        }
        public void AddDevice(EDevice device)
        {
            if (CheckDeviceGpsNoIsExist(device.DeviceGpsNo))
            {
                throw new BusinessException("已经存在Gps设备号!");
            }

            if (CheckDeviceGpsSimNoIsExist(device.DeviceGpsSimNo))
            {
                throw new BusinessException("已经存在Sim卡号!");
            }

            if (!device.DeviceGpsTypeId.HasValue)
            {
                throw new NullReferenceException("必须选择设备类型!");
            }
            if (device.UserId != 0) 
            {
                device.DeviceGroupId = _deviceGroupService.GetRootDeviceGroupByUserId(device.UserId).Id;
            }
            device.CreateTime = DateTime.Now;
            device.DeviceGpsInstallTime = DateTime.Now;
            device.NodeId = _nodeService.GetNodeIdByCreateTime(DateTime.Now);
            device.DeviceGpsCode = GetDeviceGpsCode(device.DeviceGpsTypeId.Value, device.DeviceGpsNo, device.DeviceGpsSimNo);

            using (var dmTrans = _rep.GetTransaction())
            {
                try
                {
                    var tran = dmTrans.BeginTransaction();
                    _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 = 200, 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();
                }
                catch
                {
                    dmTrans.Rollback();
                    throw;
                }
            }
        }
        public void SaveDevice(EDevice device)
        {
            var odevice = _rep.Get<EDevice>(p => p.Id == device.Id);
            if (odevice == null)
            {
                throw new NullReferenceException("不存在设备!");
            }

            if (device.DeviceGpsNo != odevice.DeviceGpsNo)
            {
                if (CheckDeviceGpsNoIsExist(device.DeviceGpsNo))
                {
                    throw new BusinessException("已经存在Gps设备号!");
                }
            }

            if (device.DeviceGpsSimNo != odevice.DeviceGpsSimNo)
            {
                if (CheckDeviceGpsSimNoIsExist(device.DeviceGpsSimNo))
                {
                    throw new BusinessException("已经存在Sim卡号!");
                }
            }

            if (device.UserId != odevice.UserId)
            {
                device.DeviceGroupId = _deviceGroupService.GetRootDeviceGroupByUserId(device.UserId).Id;
            }

            using (var dmTrans = _rep.GetTransaction())
            {
                try
                {
                    var tran = dmTrans.BeginTransaction();

                    var deviceLog = new EDeviceLog
                    {
                        DeviceId = device.Id,
                        CreateTime = DateTime.Now,
                        LogType = EnumDeviceLogType.EditDevice,
                        UserName = _stateService.GetPassport().User.UserName,
                        LogContent = new { old = odevice, last = device }.ToJson()
                    };
                    _rep.Add(deviceLog, tran);

                    device.DeviceGpsCode = GetDeviceGpsCode(device.DeviceGpsTypeId.Value, device.DeviceGpsNo, device.DeviceGpsSimNo);
                    _rep.Save(device, p => p.Id == device.Id, p => new Columns(p.DeviceName, p.DeviceTypeId, p.DeviceExpireTime, p.DeviceGpsNo, p.DeviceGpsCode, p.DeviceGpsTypeId, p.DeviceGpsSimNo, p.DeviceGpsInstallTime, p.UserId, p.DeviceGroupId), tran);
                    dmTrans.Commit();
                    _cacheService.UpdateCacheDependent(CacheKey.Gps_Device_By_DeviceGpsCode.GetFormat(odevice.DeviceGpsCode));
                    _cacheService.UpdateCacheDependent(CacheKey.Gps_Auto_Complete_Device);

                }
                catch
                {
                    dmTrans.Rollback();
                    throw;
                }
            }


        }