diff --git a/langguanApi.xml b/langguanApi.xml index 72a4586..0d7dcb0 100644 --- a/langguanApi.xml +++ b/langguanApi.xml @@ -125,6 +125,16 @@ + + + 按设备类型取设备列表 //1 voc,2 cems,3,tsp,4 video + + key + + + + + 获取指定设备的历史数据 @@ -195,6 +205,52 @@ + + + 角色 权限 + + + + + 获取角色详情 + + + + + + + 添加角色 + + + + + + + update角色 + + + + + + + 删除角色 + + + + + + + 获取角色列表 + + + + + + + 获取所有角色 + + + 清洁运输 @@ -326,6 +382,21 @@ + + + linq extension + + + + + 合并表达式以及参数 + + + + + + + 日志 @@ -555,6 +626,11 @@ 设备类型,1 voc,2 cems,3,tsp,4 video + + + 视频流地址 + + HJ212_2017 @@ -684,6 +760,91 @@ 国几排放量 + + + 菜单实体类 + + + + + 菜单名称 + + + + + 菜单URL + + + + + 排序 + + + + + 父菜单ID,一级菜单为null + + + + + 菜单名称 + + + + + 菜单URL + + + + + 排序 + + + + + 父菜单ID,一级菜单为null + + + + + 角色名称 + + + + + 角色描述 + + + + + 角色名称 + + + + + 角色描述 + + + + + 更新角色DTO + + + + + 角色ID + + + + + DTO for adding role menu + + + + + DTO for updating role menu + + 用户实体 @@ -709,6 +870,46 @@ 邮箱 + + + 手机号 + + + + + 添加用户DTO + + + + + 用户名 + + + + + 密码 md5加密 + + + + + 角色id + + + + + 邮箱 + + + + + 更新用户DTO + + + + + 用户id + + 污染物因子编码 @@ -1253,6 +1454,20 @@ + + + 批量删除 + + + + + + + 批量删除 + + + + 表达式取数据 @@ -1344,6 +1559,16 @@ + + + 分页取设备 + + + + + + + 分页取数据 @@ -1574,6 +1799,62 @@ + + + 根据角色ID获取角色菜单 + + + + + + + 表中添加角色菜单 + + + + + + + 更新角色菜单 + + + + + + + 新增角色 + + + + + + + 获取角色及菜单 + + + + + + + 删除角色 + + + + + + + 更新角色 + + + + + + + 分页取数据 + + + + TransportService 运输服务 diff --git a/langguanApi/Controllers/DeviceController.cs b/langguanApi/Controllers/DeviceController.cs index 93f385b..166c2c9 100644 --- a/langguanApi/Controllers/DeviceController.cs +++ b/langguanApi/Controllers/DeviceController.cs @@ -1,4 +1,5 @@ -using langguanApi.Model; +using Amazon.Runtime.Internal.Auth; +using langguanApi.Model; using langguanApi.Model.Dto; using langguanApi.Service; using Microsoft.AspNetCore.Mvc; @@ -80,8 +81,22 @@ namespace langguanApi.Controllers [HttpGet] public async Task GetDeviceTypes() { - var result=await _deviceService.GetDeviceTypes(); + var result = await _deviceService.GetDeviceTypes(); return Ok(new ApiResult() { code = 0, data = result }); } + /// + /// 按设备类型取设备列表 //1 voc,2 cems,3,tsp,4 video + /// + /// key + /// + /// + /// + /// + [HttpGet] + public async Task GetListByDeviceType(string key="", int pageSize = 10, int current = 1, int deviceType = 1) + { + var result = await _deviceService.GetDeviceListByTypes(key, pageSize, current, deviceType); + return Ok(result); + } } } diff --git a/langguanApi/Controllers/RoleController.cs b/langguanApi/Controllers/RoleController.cs new file mode 100644 index 0000000..199181c --- /dev/null +++ b/langguanApi/Controllers/RoleController.cs @@ -0,0 +1,92 @@ +using langguanApi.Model; +using langguanApi.Model.Entity; +using langguanApi.Service; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace langguanApi.Controllers +{ + /// + /// 角色 权限 + /// + [Route("api/[controller]")] + [ApiController] + public class RoleController : ControllerBase + { + public readonly RoleService _roleService; + public RoleController(RoleService roleService) + { + _roleService = roleService; + } + /// + /// 获取角色详情 + /// + /// + /// + [HttpGet("get")] + public async Task Get(string id) + { + var role = await _roleService.GetRoleAndMenu(id); + return Ok(role); + } + /// + /// 添加角色 + /// + /// + /// + [HttpPost("add")] + public async Task Add([FromBody] AddRoleDto role) + { + var result = await _roleService.Add(role); + return Ok(result); + } + /// + /// update角色 + /// + /// + /// + [HttpPut("update")] + public async Task Update([FromBody] UpdateRoleDto role) + { + var result = await _roleService.update(role); + return Ok(result); + } + /// + /// 删除角色 + /// + /// + /// + [HttpDelete("remove")] + public async Task Remove(IEnumerable ids) + { + var result = await _roleService.Remove(ids); + return Ok(result); + } + /// + /// 获取角色列表 + /// + /// + /// + [HttpGet("list")] + public async Task List([FromQuery] reqpage input) + { + var roles = await _roleService.GetPager(input); + return Ok(roles); + } + /// + /// 获取所有角色 + /// + /// + [HttpGet("all")] + public async Task GetAllrole() + { + var roles = await _roleService.GetAsync(); + return Ok(new ApiResult() + { + code = 0, + data = roles. + Select(s => new { s.Id, s.RoleName }) + }); + } + } +} diff --git a/langguanApi/Extensions/WhereIfExtension.cs b/langguanApi/Extensions/WhereIfExtension.cs new file mode 100644 index 0000000..fc79baf --- /dev/null +++ b/langguanApi/Extensions/WhereIfExtension.cs @@ -0,0 +1,72 @@ +using System.Linq.Expressions; + +namespace langguanApi.Extensions +{ + /// + /// linq extension + /// + public static class WhereIfExtension + { + public static IQueryable WhereIf(this IQueryable source, bool condition, Expression> predicate) + { + return condition ? source.Where(predicate) : source; + } + public static IQueryable WhereIf(this IQueryable source, Expression> predicate, bool condition) + { + return condition ? source.Where(predicate) : source; + } + public static IEnumerable WhereIf(this IEnumerable source, bool condition, Func predicate) + { + return condition ? source.Where(predicate) : source; + } + public static Expression> And( + this Expression> first, + Expression> second) + { + return first.AndAlso(second, Expression.AndAlso); + } + /// + /// 合并表达式以及参数 + /// + /// + /// + /// + /// + /// + private static Expression> AndAlso( + this Expression> expr1, + Expression> expr2, + Func func) + { + var parameter = Expression.Parameter(typeof(T)); + + var leftVisitor = new ReplaceExpressionVisitor(expr1.Parameters[0], parameter); + var left = leftVisitor.Visit(expr1.Body); + + var rightVisitor = new ReplaceExpressionVisitor(expr2.Parameters[0], parameter); + var right = rightVisitor.Visit(expr2.Body); + + return Expression.Lambda>( + func(left, right), parameter); + + } + private class ReplaceExpressionVisitor +: ExpressionVisitor + { + private readonly Expression _oldValue; + private readonly Expression _newValue; + + public ReplaceExpressionVisitor(Expression oldValue, Expression newValue) + { + _oldValue = oldValue; + _newValue = newValue; + } + public override Expression Visit(Expression node) + { + if (node == _oldValue) + return _newValue; + return base.Visit(node); + } + } + } +} diff --git a/langguanApi/Model/Device.cs b/langguanApi/Model/Device.cs index 8e8eccd..1c1e3c8 100644 --- a/langguanApi/Model/Device.cs +++ b/langguanApi/Model/Device.cs @@ -21,15 +21,20 @@ /// 设备类型,1 voc,2 cems,3,tsp,4 video /// public int DeviceType { get; set; } + /// + /// 视频流地址 + /// + public string VideoUrl { get; set; } } public class DeviceAddDto { - public string deviceMN { get; set; } public string Ip { get; set; } public double lng { get; set; } public double lat { get; set; } public string NickName { get; set; } + public int DeviceType { get; set; } + public string VideoUrl { get; set; } } public class DeviceUpdateDto { @@ -37,5 +42,6 @@ public string NickName { get; set; } public string OrgId { get; set; } public int DeviceType { get; set; } + public string VideoUrl { get; set; } } } diff --git a/langguanApi/Model/Dto/UserLogin.cs b/langguanApi/Model/Dto/UserLogin.cs index bde8309..4bef7fd 100644 --- a/langguanApi/Model/Dto/UserLogin.cs +++ b/langguanApi/Model/Dto/UserLogin.cs @@ -18,11 +18,12 @@ /// /// 角色id /// - public int roleId { get; set; } + public string roleId { get; set; } /// /// 邮箱 /// public string Email { get; set; } + public string Phone { get; set; } } /// /// 用户更新 diff --git a/langguanApi/Model/Entity/Menu.cs b/langguanApi/Model/Entity/Menu.cs new file mode 100644 index 0000000..02ccc82 --- /dev/null +++ b/langguanApi/Model/Entity/Menu.cs @@ -0,0 +1,48 @@ +namespace langguanApi.Model.Entity +{ + /// + /// 菜单实体类 + /// + public class Menu : BaseModel + { + /// + /// 菜单名称 + /// + public string Name { get; set; } + /// + /// 菜单URL + /// + public string Url { get; set; } + /// + /// 排序 + /// + public int Sort { get; set; } + /// + /// 父菜单ID,一级菜单为null + /// + public string ParentId { get; set; } + } + public class AddMenuDto + { + /// + /// 菜单名称 + /// + public string Name { get; set; } + /// + /// 菜单URL + /// + public string Url { get; set; } + /// + /// 排序 + /// + public int Sort { get; set; } + /// + /// 父菜单ID,一级菜单为null + /// + public string ParentId { get; set; } + } + public class UpdateMenuDto : AddMenuDto + { + public string Id { get; set; } + } +} diff --git a/langguanApi/Model/Entity/Role.cs b/langguanApi/Model/Entity/Role.cs new file mode 100644 index 0000000..2b446ba --- /dev/null +++ b/langguanApi/Model/Entity/Role.cs @@ -0,0 +1,35 @@ +namespace langguanApi.Model.Entity +{ + public class Role : BaseModel + { + /// + /// 角色名称 + /// + public string RoleName { get; set; } + /// + /// 角色描述 + /// + public string RoleDescription { get; set; } + } + public class AddRoleDto + { + /// + /// 角色名称 + /// + public string RoleName { get; set; } + /// + /// 角色描述 + /// + public string RoleDescription { get; set; } + } + /// + /// 更新角色DTO + /// + public class UpdateRoleDto: AddRoleDto + { + /// + /// 角色ID + /// + public int RoleId { get; set; } + } +} diff --git a/langguanApi/Model/Entity/RoleMenu.cs b/langguanApi/Model/Entity/RoleMenu.cs new file mode 100644 index 0000000..bfed213 --- /dev/null +++ b/langguanApi/Model/Entity/RoleMenu.cs @@ -0,0 +1,24 @@ +namespace langguanApi.Model.Entity +{ + public class RoleMenu : BaseModel + { + public string RoleId { get; set; } + public string MenuId { get; set; } + } + /// + /// DTO for adding role menu + /// + public class AddRoleMenuDTO + { + public string RoleId { get; set; } + public List MenuIds { get; set; } + } + /// + /// DTO for updating role menu + /// + public class UpdateRoleMenuDTO + { + public string RoleId { get; set; } + public List MenuIds { get; set; } + } +} diff --git a/langguanApi/Model/Entity/UserEntity.cs b/langguanApi/Model/Entity/UserEntity.cs index 350b96a..21fa5fd 100644 --- a/langguanApi/Model/Entity/UserEntity.cs +++ b/langguanApi/Model/Entity/UserEntity.cs @@ -16,10 +16,47 @@ /// /// 角色id /// - public int roleId { get; set; } + public string roleId { get; set; } + /// + /// 邮箱 + /// + public string Email { get; set; } + /// + /// 手机号 + /// + public string Phone { get; set; } + } + /// + /// 添加用户DTO + /// + public class AddDto + { + /// + /// 用户名 + /// + public string Username { get; set; } + /// + /// 密码 md5加密 + /// + public string Password { get; set; } + /// + /// 角色id + /// + public string roleId { get; set; } /// /// 邮箱 /// public string Email { get; set; } } + /// + /// 更新用户DTO + /// + public class UpdateDto:AddDto + { + /// + /// 用户id + /// + public string Id { get; set; } + } + } diff --git a/langguanApi/Service/BaseService.cs b/langguanApi/Service/BaseService.cs index 4e5f677..a502ab3 100644 --- a/langguanApi/Service/BaseService.cs +++ b/langguanApi/Service/BaseService.cs @@ -136,7 +136,25 @@ namespace langguanApi.Service { await _collection.DeleteOneAsync(T => T.Id == id); } - + /// + /// 批量删除 + /// + /// + /// + public async Task BatchRemoveAsync(IEnumerable ids) + { + var filter = Builders.Filter.In(s => s.Id, ids); + await _collection.DeleteManyAsync(filter); + } + /// + /// 批量删除 + /// + /// + /// + public async Task BatchRemoveAsync(Expression> expression) + { + await _collection.DeleteManyAsync(expression); + } #endregion /// /// 表达式取数据 diff --git a/langguanApi/Service/DeviceService.cs b/langguanApi/Service/DeviceService.cs index 5bc931d..fa61936 100644 --- a/langguanApi/Service/DeviceService.cs +++ b/langguanApi/Service/DeviceService.cs @@ -1,4 +1,5 @@ -using langguanApi.Extensions.AutoDI; +using langguanApi.Extensions; +using langguanApi.Extensions.AutoDI; using langguanApi.Model; using langguanApi.Model.Dto; using Mapster; @@ -25,12 +26,8 @@ namespace langguanApi.Service return new ApiResult { code = 1, msg = $"已经存在名称为:{input.NickName}" }; } var entity = input.Adapt(); - if (entity != null) - { - await base.CreateAsync(entity); - return new ApiResult { code = 0, msg = "" }; - } - return new ApiResult { code = -1, msg = "" }; ; + await base.CreateAsync(entity); + return new ApiResult { code = 0, msg = "" }; } /// /// 是否存在 @@ -103,7 +100,7 @@ namespace langguanApi.Service /// 获取设备类型 /// /// - public Task> GetDeviceTypes() + public Task> GetDeviceTypes() { //1 voc,2 cems,3,tsp,4 video Dictionary dic = new Dictionary @@ -115,19 +112,40 @@ namespace langguanApi.Service }; return Task.FromResult(dic); } - /// - /// 分页取数据 - /// - /// - /// - public async Task GetPage(reqpage input) - { - Expression> exp = filter => filter.NickName.Contains(input.key) && filter.IsDelete == false; - return await base.GetPager(new ReqPaing() + /// + /// 分页取设备 + /// + /// + /// + /// + /// + /// + public async Task GetDeviceListByTypes(string key, int pageSize = 10, int current = 1, int deviceType = 1) { - pageSize = input.pageSize, - current = input.current - }, exp); + Expression> exp = filter => filter.IsDelete == false && filter.DeviceType == deviceType; + if (!string.IsNullOrEmpty(key)) + { + exp = exp.And(filter => filter.NickName.Contains(key)); + } + return await base.GetPager(new ReqPaing() + { + pageSize = pageSize, + current = current + }, exp); + } + /// + /// 分页取数据 + /// + /// + /// + public async Task GetPage(reqpage input) + { + Expression> exp = filter => filter.NickName.Contains(input.key) && filter.IsDelete == false; + return await base.GetPager(new ReqPaing() + { + pageSize = input.pageSize, + current = input.current + }, exp); + } } } -} diff --git a/langguanApi/Service/MenuService.cs b/langguanApi/Service/MenuService.cs new file mode 100644 index 0000000..ac02656 --- /dev/null +++ b/langguanApi/Service/MenuService.cs @@ -0,0 +1,34 @@ +using langguanApi.Extensions.AutoDI; +using langguanApi.Model; +using langguanApi.Model.Entity; +using Mapster; +using Microsoft.AspNetCore.Mvc.ApiExplorer; +using System.Linq.Expressions; + +namespace langguanApi.Service +{ + [ServiceInjection(InjectionType.Transient)] + public class MenuService : BaseService + { + public MenuService(IConfiguration config) : base(config, nameof(Menu)) + { + } + public async Task> GetMenusByParentId(string parentId) + { + Expression> exp = filter => filter.IsDelete == false && filter.ParentId == parentId; + return (await base.GetListWithExp(exp)).OrderBy(x => x.Sort).ToList(); + } + public async Task AddMenu(AddMenuDto menu) + { + var entity = menu.Adapt(); + await base.CreateAsync(entity); + return new ApiResult(); + } + public async Task UpdateMenu(UpdateMenuDto menu) + { + var entity = menu.Adapt(); + await base.UpdateAsync(entity.Id, entity); + return new ApiResult(); + } + } +} diff --git a/langguanApi/Service/RoleMenuServie.cs b/langguanApi/Service/RoleMenuServie.cs new file mode 100644 index 0000000..c7829e9 --- /dev/null +++ b/langguanApi/Service/RoleMenuServie.cs @@ -0,0 +1,64 @@ +using langguanApi.Extensions.AutoDI; +using langguanApi.Model; +using langguanApi.Model.Entity; +using System.Linq.Expressions; + +namespace langguanApi.Service +{ + [ServiceInjection(InjectionType.Transient)] + public class RoleMenuServie : BaseService + { + public RoleMenuServie(IConfiguration config) : base(config, nameof(RoleMenu)) + { + } + /// + /// 根据角色ID获取角色菜单 + /// + /// + /// + public async Task> GetByRoleId(string roleId) + { + Expression> exp = filter => filter.IsDelete == false && filter.RoleId == roleId; + return (await base.GetListWithExp(exp)).ToList(); + } + /// + /// 表中添加角色菜单 + /// + /// + /// + public async Task AddRoleMenu(AddRoleMenuDTO input) + { + foreach (var item in input.MenuIds) + { + await base.CreateAsync(new RoleMenu() + { + RoleId = input.RoleId, + MenuId = item + }); + } + return new ApiResult() { code = 0 }; + } + public async Task DeleteRoleMenu(string roleId) + { + return null; + } + /// + /// 更新角色菜单 + /// + /// + /// + public async Task UpdateRoleMenu(UpdateRoleMenuDTO input) + { + await base.BatchRemoveAsync(filter => filter.RoleId == input.RoleId); + foreach (var item in input.MenuIds) + { + await base.CreateAsync(new RoleMenu() + { + RoleId = input.RoleId, + MenuId = item + }); + } + return new ApiResult() { code = 0 }; + } + } +} diff --git a/langguanApi/Service/RoleService.cs b/langguanApi/Service/RoleService.cs new file mode 100644 index 0000000..99d906c --- /dev/null +++ b/langguanApi/Service/RoleService.cs @@ -0,0 +1,95 @@ +using langguanApi.Extensions; +using langguanApi.Extensions.AutoDI; +using langguanApi.Model; +using langguanApi.Model.Entity; +using Mapster; +using NPOI.SS.Formula.Functions; +using System.Linq.Expressions; + +namespace langguanApi.Service +{ + [ServiceInjection(InjectionType.Transient)] + public class RoleService : BaseService + { + private readonly RoleMenuServie _roleMenuServie; + public RoleService(IConfiguration config, RoleMenuServie roleMenuServie) : base(config, nameof(Role)) + { + _roleMenuServie = roleMenuServie; + } + /// + /// 新增角色 + /// + /// + /// + public async Task Add(AddRoleDto role) + { + if (await base.Exist(filter => filter.RoleName == role.RoleName)) + { + return new ApiResult() { code = 1, msg = "角色名称已存在" }; + } + var entity = role.Adapt(); + await base.CreateAsync(entity); + return new ApiResult() { code = 0 }; + } + /// + /// 获取角色及菜单 + /// + /// + /// + public async Task GetRoleAndMenu(string roleId) + { + var role = await base.GetAsync(roleId); + if (role != null) + { + var menus = await _roleMenuServie.GetByRoleId(roleId); + return new ApiResult() { code = 0, data = new { role, menus } }; + } + return new ApiResult() { code = 0 }; + } + /// + /// 删除角色 + /// + /// + /// + public async Task Remove(IEnumerable ids) + { + if (ids.Any()) + { + foreach (var item in ids) + { + await base.RemoveAsync(item); + } + } + return new ApiResult() { code = 0 }; + } + /// + /// 更新角色 + /// + /// + /// + public async Task update(UpdateRoleDto role) + { + var entity = role.Adapt(); + await base.UpdateAsync(entity.Id, entity); + return new ApiResult() { code = 0 }; + } + /// + /// 分页取数据 + /// + /// + /// + public async Task GetPage(reqpage input) + { + Expression> exp = filter => filter.IsDelete == false; + if (!string.IsNullOrEmpty(input.key)) + { + exp = exp.And(filter => filter.RoleName.Contains(input.key)); + } + return await base.GetPager(new ReqPaing() + { + pageSize = input.pageSize, + current = input.current + }, exp); + } + } +} diff --git a/langguanApi/langguanApi.csproj b/langguanApi/langguanApi.csproj index ec7e81a..17fbefa 100644 --- a/langguanApi/langguanApi.csproj +++ b/langguanApi/langguanApi.csproj @@ -2,7 +2,7 @@ net6.0 - enable + disable enable Linux