/// <summary> /// 添加路口 /// </summary> /// <param name="roadCrossing">路口</param> /// <param name="userName">用户名</param> /// <returns>添加结果</returns> public ObjectResult Add([FromBody] RoadCrossing roadCrossing, string userName = null) { _context.RoadCrossings.Add(roadCrossing); _context.SaveChanges(); _logger.LogInformation(new EventId((int)LogEvent.编辑路口, userName), $"添加路口 {roadCrossing}"); return(new OkObjectResult(roadCrossing)); }
/// <summary> /// 添加路段 /// </summary> /// <param name="roadSection">路段</param> /// <param name="userName">用户名</param> /// <returns>添加结果</returns> public ObjectResult Add([FromBody] RoadSection roadSection, string userName = null) { _context.RoadSections.Add(roadSection); _context.SaveChanges(); _logger.LogInformation(new EventId((int)LogEvent.编辑路段, userName), $"添加路段 {roadSection}"); return(new OkObjectResult(roadSection)); }
public ActionResult Create([Bind(Include = "ID,Descricao,Preco,UltimaCompra,Estoque")] Teste teste) { if (ModelState.IsValid) { db.Testes.Add(teste); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(teste)); }
public ActionResult Create([Bind(Include = "ContaId,Nome")] Conta conta) { if (ModelState.IsValid) { db.Contas.Add(conta); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(conta)); }
public ActionResult Create([Bind(Include = "PerfilId,Nome,ContaId")] Perfil perfil) { if (ModelState.IsValid) { db.Perfils.Add(perfil); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ContaId = new SelectList(db.Contas, "ContaId", "Nome", perfil.ContaId); return(View(perfil)); }
public ActionResult Create([Bind(Include = "SetorId,Nome,PerfilId")] Setor setor) { if (ModelState.IsValid) { db.Setors.Add(setor); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PerfilId = new SelectList(db.Perfils, "PerfilId", "Nome", setor.PerfilId); return(View(setor)); }
/// <summary> /// 添加设备 /// </summary> /// <param name="deviceInsert">设备信息</param> /// <param name="userName">用户名</param> /// <returns>添加结果</returns> public ObjectResult Add(FlowDeviceInsert deviceInsert, string userName = null) { FlowDevice device = new FlowDevice { DeviceId = 0, DeviceName = deviceInsert.DeviceName, DeviceModel = deviceInsert.DeviceModel, DeviceStatus = (int)DeviceStatus.异常, Ip = deviceInsert.Ip, Port = deviceInsert.Port }; try { UpdateChannels(device, deviceInsert.Channels); _context.Devices.Add(device); _context.SaveChanges(); _logger.LogInformation(new EventId((int)LogEvent.编辑设备, userName), $"添加设备 {device}"); return(new OkObjectResult(device)); } catch (Exception) { ModelStateDictionary modelState = CheckError(device, deviceInsert.Channels); if (modelState.IsValid) { throw; } else { return(new BadRequestObjectResult(modelState)); } } }
/// <summary> /// 添加通道 /// </summary> /// <param name="channel">通道</param> /// <param name="userName">用户名</param> /// <returns>添加结果</returns> public ObjectResult Add(FlowChannel channel, string userName = null) { try { AddChannel(_context, channel); _context.SaveChanges(); _logger.LogInformation(new EventId((int)LogEvent.编辑通道, userName), $"添加通道 {channel}"); return(new OkObjectResult(channel)); } catch (Exception) { ModelStateDictionary modelState = CheckInsertError(_context, channel); if (modelState.IsValid) { throw; } else { return(new BadRequestObjectResult(modelState)); } } }
/// <summary> /// 初始化数据库 /// </summary> private async void InitDb() { _logger.LogInformation((int)LogEvent.系统, "初始化数据库"); DateTime minTime = TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel); using (IServiceScope serviceScope = _serviceProvider.CreateScope()) { using (FlowContext context = serviceScope.ServiceProvider.GetRequiredService <FlowContext>()) { if (context.Database.EnsureCreated()) { #region 用户 _logger.LogInformation((int)LogEvent.系统, "创建管理员用户"); UserManager <IdentityUser> userManager = serviceScope.ServiceProvider.GetRequiredService <UserManager <IdentityUser> >(); await userManager.CreateAsync(new IdentityUser("admin"), "123456"); #endregion #region 权限 _logger.LogInformation((int)LogEvent.系统, "创建权限"); IdentityUser adminUser = await userManager.FindByNameAsync("admin"); List <YumekoJabami.Models.Claim> claims = new List <YumekoJabami.Models.Claim> { new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02000000", Descirption = "智慧交通视频检测系统" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02010000", Descirption = "设备管理" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02010100", Descirption = "设备信息维护" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02010200", Descirption = "设备位置维护" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02010300", Descirption = "国标网关设置" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02010400", Descirption = "校时配置" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02010500", Descirption = "设备操作" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02010600", Descirption = "设备运行状态" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02010700", Descirption = "视频信息维护" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02010800", Descirption = "视频位置维护" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02020000", Descirption = "数据分析" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02020100", Descirption = "通行信息查询" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02020200", Descirption = "流量数据分析" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02020300", Descirption = "IO数据监测" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02020400", Descirption = "流量分布查询" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02020500", Descirption = "拥堵趋势分析" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02020600", Descirption = "状态时间统计" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02020700", Descirption = "交通状态分析" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02030000", Descirption = "系统设置" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02030100", Descirption = "路口维护" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02030200", Descirption = "路段维护" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02030300", Descirption = "用户管理" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02030400", Descirption = "角色管理" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02030600", Descirption = "字典管理" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02030700", Descirption = "参数管理" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02030800", Descirption = "日志查询" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02030900", Descirption = "系统监控" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02040000", Descirption = "状况监测" }, new YumekoJabami.Models.Claim { Type = ClaimTypes.Webpage, Value = "02040100", Descirption = "应用检测" }, }; context.TrafficClaims.AddRange(claims); foreach (YumekoJabami.Models.Claim claim in claims) { await userManager.AddClaimAsync(adminUser, new System.Security.Claims.Claim(claim.Type, claim.Value)); } #endregion #region 字典 _logger.LogInformation((int)LogEvent.系统, "创建字典"); List <Code> flowCodes = new List <Code>(); flowCodes.AddRange(Enum.GetValues(typeof(LogEvent)) .Cast <LogEvent>() .Select(e => new Code { Key = typeof(LogEvent).Name, Value = (int)e, Description = e.ToString() })); flowCodes.Add(new Code { Key = "LogLevel", Value = (int)LogLevel.Debug, Description = "调试" }); flowCodes.Add(new Code { Key = "LogLevel", Value = (int)LogLevel.Information, Description = "消息" }); flowCodes.Add(new Code { Key = "LogLevel", Value = (int)LogLevel.Warning, Description = "警告" }); flowCodes.Add(new Code { Key = "LogLevel", Value = (int)LogLevel.Error, Description = "错误" }); flowCodes.AddRange(Enum.GetValues(typeof(ChannelType)) .Cast <ChannelType>() .Select(e => new Code { Key = typeof(ChannelType).Name, Value = (int)e, Description = e.ToString() })); flowCodes.AddRange(Enum.GetValues(typeof(DeviceModel)) .Cast <DeviceModel>() .Select(e => new Code { Key = typeof(DeviceModel).Name, Value = (int)e, Description = e.ToString() })); flowCodes.AddRange(Enum.GetValues(typeof(DeviceStatus)) .Cast <DeviceStatus>() .Select(e => new Code { Key = typeof(DeviceStatus).Name, Value = (int)e, Description = e.ToString() })); flowCodes.AddRange(Enum.GetValues(typeof(RtspProtocol)) .Cast <RtspProtocol>() .Select(e => new Code { Key = typeof(RtspProtocol).Name, Value = (int)e, Description = e.ToString() })); flowCodes.AddRange(Enum.GetValues(typeof(SectionDirection)) .Cast <SectionDirection>() .Select(e => new Code { Key = typeof(SectionDirection).Name, Value = (int)e, Description = e.ToString() })); flowCodes.AddRange(Enum.GetValues(typeof(SectionType)) .Cast <SectionType>() .Select(e => new Code { Key = typeof(SectionType).Name, Value = (int)e, Description = e.ToString() })); flowCodes.AddRange(Enum.GetValues(typeof(Age)) .Cast <Age>() .Select(e => new Code { Key = typeof(Age).Name, Value = (int)e, Description = e.ToString() })); flowCodes.AddRange(Enum.GetValues(typeof(NonVehicle)) .Cast <NonVehicle>() .Select(e => new Code { Key = typeof(NonVehicle).Name, Value = (int)e, Description = e.ToString() })); flowCodes.AddRange(Enum.GetValues(typeof(CarColor)) .Cast <CarColor>() .Select(e => new Code { Key = typeof(CarColor).Name, Value = (int)e, Description = e.ToString() })); flowCodes.AddRange(Enum.GetValues(typeof(CarType)) .Cast <CarType>() .Select(e => new Code { Key = typeof(CarType).Name, Value = (int)e, Description = e.ToString() })); flowCodes.AddRange(Enum.GetValues(typeof(FlowDirection)) .Cast <FlowDirection>() .Select(e => new Code { Key = typeof(FlowDirection).Name, Value = (int)e, Description = e.ToString() })); flowCodes.Add(new Code { Key = "VehicleType", Value = (int)FlowType.轮车, Description = FlowType.轮车.ToString() }); flowCodes.Add(new Code { Key = "VehicleType", Value = (int)FlowType.卡车, Description = FlowType.卡车.ToString() }); flowCodes.Add(new Code { Key = "VehicleType", Value = (int)FlowType.客车, Description = FlowType.客车.ToString() }); flowCodes.Add(new Code { Key = "VehicleType", Value = (int)FlowType.轿车, Description = FlowType.轿车.ToString() }); flowCodes.Add(new Code { Key = "VehicleType", Value = (int)FlowType.面包车, Description = FlowType.面包车.ToString() }); flowCodes.Add(new Code { Key = "BikeType", Value = (int)FlowType.自行车, Description = FlowType.自行车.ToString() }); flowCodes.Add(new Code { Key = "BikeType", Value = (int)FlowType.摩托车, Description = FlowType.摩托车.ToString() }); flowCodes.Add(new Code { Key = "PedestrainType", Value = (int)FlowType.行人, Description = FlowType.行人.ToString() }); flowCodes.Add(new Code { Key = "FlowType", Value = (int)FlowType.平均速度, Description = FlowType.平均速度.ToString() }); flowCodes.Add(new Code { Key = "FlowType", Value = (int)FlowType.车头时距, Description = FlowType.车头时距.ToString() }); flowCodes.Add(new Code { Key = "FlowType", Value = (int)FlowType.车头间距, Description = FlowType.车头间距.ToString() }); flowCodes.Add(new Code { Key = "FlowType", Value = (int)FlowType.时间占有率, Description = FlowType.时间占有率.ToString() }); flowCodes.Add(new Code { Key = "FlowType", Value = (int)FlowType.空间占有率, Description = FlowType.空间占有率.ToString() }); flowCodes.AddRange(Enum.GetValues(typeof(LaneDirection)) .Cast <LaneDirection>() .Select(e => new Code { Key = typeof(LaneDirection).Name, Value = (int)e, Description = e.ToString() })); flowCodes.AddRange(Enum.GetValues(typeof(LaneType)) .Cast <LaneType>() .Select(e => new Code { Key = typeof(LaneType).Name, Value = (int)e, Description = e.ToString() })); flowCodes.AddRange(Enum.GetValues(typeof(PlateType)) .Cast <PlateType>() .Select(e => new Code { Key = typeof(PlateType).Name, Value = (int)e, Description = e.ToString() })); flowCodes.AddRange(Enum.GetValues(typeof(Sex)) .Cast <Sex>() .Select(e => new Code { Key = typeof(Sex).Name, Value = (int)e, Description = e.ToString() })); flowCodes.AddRange(Enum.GetValues(typeof(TrafficStatus)) .Cast <TrafficStatus>() .Select(e => new Code { Key = typeof(TrafficStatus).Name, Value = (int)e, Description = e.ToString() })); flowCodes.AddRange(Enum.GetValues(typeof(UpperColor)) .Cast <UpperColor>() .Select(e => new Code { Key = typeof(UpperColor).Name, Value = (int)e, Description = e.ToString() })); flowCodes.AddRange(Enum.GetValues(typeof(VideoStructType)) .Cast <VideoStructType>() .Select(e => new Code { Key = typeof(VideoStructType).Name, Value = (int)e, Description = e.ToString() })); flowCodes.Add(new Code { Key = "FlowDateLevel", Value = (int)DateTimeLevel.Minute, Description = "一分钟" }); flowCodes.Add(new Code { Key = "FlowDateLevel", Value = (int)DateTimeLevel.FiveMinutes, Description = "五分钟" }); flowCodes.Add(new Code { Key = "FlowDateLevel", Value = (int)DateTimeLevel.FifteenMinutes, Description = "十五分钟" }); flowCodes.Add(new Code { Key = "FlowDateLevel", Value = (int)DateTimeLevel.Hour, Description = "小时" }); flowCodes.Add(new Code { Key = "FlowDateLevel", Value = (int)DateTimeLevel.Day, Description = "天" }); flowCodes.Add(new Code { Key = "FlowDateLevel", Value = (int)DateTimeLevel.Month, Description = "月" }); flowCodes.Add(new Code { Key = "CongestionDateLevel", Value = (int)DateTimeLevel.Hour, Description = "小时" }); flowCodes.Add(new Code { Key = "CongestionDateLevel", Value = (int)DateTimeLevel.Day, Description = "天" }); flowCodes.Add(new Code { Key = "CongestionDateLevel", Value = (int)DateTimeLevel.Month, Description = "月" }); flowCodes.Add(new Code { Key = "StatusTimeDateLevel", Value = (int)DateTimeLevel.Hour, Description = "小时" }); flowCodes.Add(new Code { Key = "StatusTimeDateLevel", Value = (int)DateTimeLevel.Day, Description = "天" }); flowCodes.Add(new Code { Key = "StatusTimeDateLevel", Value = (int)DateTimeLevel.Month, Description = "月" }); context.Codes.AddRange(flowCodes); #endregion context.Version.Add(new TrafficVersion { Version = Assembly.GetExecutingAssembly().GetName().Version.ToString() }); context.SaveChanges(); } else { try { LaneFlow laneFlow = context.LaneFlows_One.OrderByDescending(f => f.Id).FirstOrDefault(); if (laneFlow != null && TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, laneFlow.DateTime) != minTime) { context.ChangeDatabase(BranchDbConvert.GetTableName(laneFlow.DateTime)); } VideoVehicle vehicle = context.Vehicles.OrderByDescending(v => v.Id).FirstOrDefault(); if (vehicle != null && TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, vehicle.DateTime) != minTime) { context.ChangeVehicleTable(BranchDbConvert.GetTableName(vehicle.DateTime)); } VideoBike bike = context.Bikes.OrderByDescending(v => v.Id).FirstOrDefault(); if (bike != null && TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, bike.DateTime) != minTime) { context.ChangeBikeTable(BranchDbConvert.GetTableName(bike.DateTime)); } VideoPedestrain pedestrain = context.Pedestrains.OrderByDescending(v => v.Id).FirstOrDefault(); if (pedestrain != null && TimePointConvert.CurrentTimePoint(BranchDbConvert.DateLevel, pedestrain.DateTime) != minTime) { context.ChangePedestrainTable(BranchDbConvert.GetTableName(pedestrain.DateTime)); } } catch (MySqlException) { } } } } }
public static List <FlowDevice> CreateFlowDevice(IServiceProvider serviceProvider, int deviceCount, int channelCount, int laneCount, bool initDatabase = false, string ip1 = "127.0.0.", int ip2 = 1, int id = 100) { List <FlowDevice> devices = new List <FlowDevice>(); using (FlowContext context = serviceProvider.CreateScope().ServiceProvider.GetRequiredService <FlowContext>()) { if (initDatabase) { ResetDatabase(serviceProvider); } for (int i = 0; i < deviceCount; ++i) { FlowDevice device = new FlowDevice { DeviceId = id, DeviceName = $"流量测试设备_{id}", DeviceModel = (int)DeviceModel.MO_AF_A11_04_4X, Ip = $"{ip1}{ip2++}", Port = 17000, FlowDevice_FlowChannels = new List <FlowDevice_FlowChannel>() }; for (int j = 0; j < channelCount; ++j) { RoadCrossing roadCrossing = new RoadCrossing { CrossingId = id, CrossingName = $"流量测试路口_{id}" }; RoadSection roadSection = new RoadSection { SectionId = id, SectionName = $"流量测试通路段_{id}", SectionType = (int)SectionType.主干路, SpeedLimit = 10, Length = 10, Direction = (int)LaneDirection.由东向西 }; FlowChannel channel = new FlowChannel { ChannelId = $"channel_{id}", ChannelName = $"流量测试通道_{id}", ChannelIndex = j + 1, CrossingId = id, SectionId = id, ChannelType = (int)ChannelType.GB28181, Lanes = new List <Lane>(), RoadCrossing = roadCrossing, RoadSection = roadSection }; FlowDevice_FlowChannel relation = new FlowDevice_FlowChannel { DeviceId = id, ChannelId = channel.ChannelId, Channel = channel }; id++; device.FlowDevice_FlowChannels.Add(relation); for (int k = 0; k < laneCount; ++k) { LaneDirection direction; if (k >= 0 && k < 3) { direction = LaneDirection.由南向北; } else if (k >= 3 && k < 6) { direction = LaneDirection.由北向南; } else if (k >= 6 && k < 9) { direction = LaneDirection.由东向西; } else { direction = LaneDirection.由西向东; } FlowDirection flowDirection; if (k % 3 == 0) { flowDirection = FlowDirection.直行; } else if (k % 3 == 1) { flowDirection = FlowDirection.左转; } else { flowDirection = FlowDirection.右转; } channel.Lanes.Add(new Lane { ChannelId = channel.ChannelId, LaneId = $"{k + 1:D2}", LaneName = $"流量测试车道_{k + 1:D2}", Channel = channel, Direction = (int)direction, FlowDirection = (int)flowDirection, LaneIndex = k + 1, Region = "[]", Length = 10 }); } } context.Devices.Add(device); devices.Add(device); context.SaveChanges(); } } return(devices); }