From 3d5d69f5bfc1b7b25c1c0367d2cd39b923f5dbc6 Mon Sep 17 00:00:00 2001 From: "qianhao.xu" Date: Wed, 7 Aug 2024 15:56:01 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8F=AD=E7=BB=84=E7=AE=A1=E7=90=86=E5=B2=97?= =?UTF-8?q?=E4=BD=8D=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MES/dev/DeviceAccountController.cs | 5 + .../MES/group/GroupPostController.cs | 109 ++++++++++++++ .../appsettings.Development.json | 2 +- DOAN.Common/TreeHelper.cs | 48 +++++++ DOAN.Model/MES/group/Dto/GroupPostDto.cs | 41 ++++++ DOAN.Model/MES/group/GroupPost.cs | 63 ++++++++ DOAN.Service/MES/group/GroupPostService.cs | 135 ++++++++++++++++++ .../MES/group/IService/IGroupPostService.cs | 26 ++++ 8 files changed, 428 insertions(+), 1 deletion(-) create mode 100644 DOAN.Admin.WebApi/Controllers/MES/group/GroupPostController.cs create mode 100644 DOAN.Common/TreeHelper.cs create mode 100644 DOAN.Model/MES/group/Dto/GroupPostDto.cs create mode 100644 DOAN.Model/MES/group/GroupPost.cs create mode 100644 DOAN.Service/MES/group/GroupPostService.cs create mode 100644 DOAN.Service/MES/group/IService/IGroupPostService.cs diff --git a/DOAN.Admin.WebApi/Controllers/MES/dev/DeviceAccountController.cs b/DOAN.Admin.WebApi/Controllers/MES/dev/DeviceAccountController.cs index 24f0dd7..82b8e20 100644 --- a/DOAN.Admin.WebApi/Controllers/MES/dev/DeviceAccountController.cs +++ b/DOAN.Admin.WebApi/Controllers/MES/dev/DeviceAccountController.cs @@ -38,6 +38,11 @@ namespace DOAN.Admin.WebApi.Controllers var response = _DeviceAccountService.GetList(parm); return SUCCESS(response); } + + + + + /// /// 查询绑定或者未绑定巡检任务的设备台账 /// diff --git a/DOAN.Admin.WebApi/Controllers/MES/group/GroupPostController.cs b/DOAN.Admin.WebApi/Controllers/MES/group/GroupPostController.cs new file mode 100644 index 0000000..8e1741a --- /dev/null +++ b/DOAN.Admin.WebApi/Controllers/MES/group/GroupPostController.cs @@ -0,0 +1,109 @@ +using Microsoft.AspNetCore.Mvc; +using DOAN.Model.Dto; +using DOAN.Model.MES.group; +using DOAN.Model.MES.group.Dto; +using DOAN.Service.group.IService; +using DOAN.Admin.WebApi.Filters; + +//创建时间:2024-08-07 +namespace DOAN.Admin.WebApi.Controllers +{ + /// + /// 岗位 + /// + [Verify] + [Route("mes/groupManagement/GroupPost")] + public class GroupPostController : BaseController + { + /// + /// 岗位接口 + /// + private readonly IGroupPostService _GroupPostService; + + public GroupPostController(IGroupPostService GroupPostService) + { + _GroupPostService = GroupPostService; + } + + /// + /// 查询岗位列表 + /// + /// + /// + [HttpGet("list")] + [ActionPermissionFilter(Permission = "groupManagement:grouppost:list")] + public IActionResult QueryGroupPost([FromQuery] GroupPostQueryDto parm) + { + var response = _GroupPostService.GetList(parm); + return SUCCESS(response); + } + + + /// + /// 查询岗位详情 + /// + /// + /// + [HttpGet("{Id}")] + [ActionPermissionFilter(Permission = "groupManagement:grouppost:query")] + public IActionResult GetGroupPost(string Id) + { + var response = _GroupPostService.GetInfo(Id); + + var info = response.Adapt(); + return SUCCESS(info); + } + + /// + /// 添加岗位 + /// + /// + [HttpPost] + [ActionPermissionFilter(Permission = "groupManagement:grouppost:add")] + [Log(Title = "岗位", BusinessType = BusinessType.INSERT)] + public IActionResult AddGroupPost([FromBody] GroupPostDto parm) + { + var modal = parm.Adapt().ToCreate(HttpContext); + + var response = _GroupPostService.AddGroupPost(modal); + + return SUCCESS(response); + } + + /// + /// 更新岗位 + /// + /// + [HttpPut] + [ActionPermissionFilter(Permission = "groupManagement:grouppost:edit")] + [Log(Title = "岗位", BusinessType = BusinessType.UPDATE)] + public IActionResult UpdateGroupPost([FromBody] GroupPostDto parm) + { + var modal = parm.Adapt().ToUpdate(HttpContext); + var response = _GroupPostService.UpdateGroupPost(modal); + + return ToResponse(response); + } + + /// + /// 删除岗位 + /// + /// + [HttpDelete("{ids}")] + [ActionPermissionFilter(Permission = "groupManagement:grouppost:delete")] + [Log(Title = "岗位", BusinessType = BusinessType.DELETE)] + public IActionResult DeleteGroupPost(string ids) + { + string[] idsArr = Tools.SpitStrArrary(ids); + if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } + + var response = _GroupPostService.RemoveGroupPost(idsArr); + + return ToResponse(response); + } + + + + + } +} \ No newline at end of file diff --git a/DOAN.Admin.WebApi/appsettings.Development.json b/DOAN.Admin.WebApi/appsettings.Development.json index 659c612..5e1b142 100644 --- a/DOAN.Admin.WebApi/appsettings.Development.json +++ b/DOAN.Admin.WebApi/appsettings.Development.json @@ -28,7 +28,7 @@ //代码生成数据库配置 "CodeGenDbConfig": { //代码生成连接字符串,注意{dbName}为固定格式,不要填写数据库名 - "Conn": "Data Source=192.168.50.163;User ID=root;Password=123456;Initial Catalog={dbName};", + "Conn": "Data Source=192.168.0.58;User ID=root;Password=123456;Initial Catalog={dbName};", "DbType": 0, "IsAutoCloseConnection": true, "DbName": "GXAssembly" //代码生成默认连接数据库,Oracle库是实例的名称 diff --git a/DOAN.Common/TreeHelper.cs b/DOAN.Common/TreeHelper.cs new file mode 100644 index 0000000..88d56f3 --- /dev/null +++ b/DOAN.Common/TreeHelper.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DOAN.Common +{ + + + public class Node + { + public int Id { get; set; } + public int? ParentId { get; set; } + } + + public static class TreeNodeHelper + { + /// + /// 获取指定节点的所有后代节点。 + /// + /// 所有节点的集合。 + /// 根节点的 ID。 + /// 所有后代节点的列表。 + public static List GetDescendants(List nodes, int rootId) + { + var descendants = new List(); + + void FindChildren(Node node) + { + var children = nodes.Where(n => n.ParentId == node.Id).ToList(); + foreach (var child in children) + { + descendants.Add(child); + FindChildren(child); + } + } + + var rootNode = nodes.FirstOrDefault(n => n.Id == rootId); + if (rootNode != null) + { + FindChildren(rootNode); + } + + return descendants; + } + } +} diff --git a/DOAN.Model/MES/group/Dto/GroupPostDto.cs b/DOAN.Model/MES/group/Dto/GroupPostDto.cs new file mode 100644 index 0000000..282f8f6 --- /dev/null +++ b/DOAN.Model/MES/group/Dto/GroupPostDto.cs @@ -0,0 +1,41 @@ +using System.ComponentModel.DataAnnotations; + +namespace DOAN.Model.MES.group.Dto +{ + /// + /// 岗位查询对象 + /// + public class GroupPostQueryDto : PagerInfo + { + public string PostName { get; set; } + } + + /// + /// 岗位输入输出对象 + /// + public class GroupPostDto + { + [Required(ErrorMessage = "雪花不能为空")] + public string Id { get; set; } + + [Required(ErrorMessage = "父id不能为空")] + public string ParentId { get; set; } + + public string PostName { get; set; } + + public int? Status { get; set; } + + public string Remark { get; set; } + + public string CreatedBy { get; set; } + + public DateTime? CreatedTime { get; set; } + + public string UpdatedBy { get; set; } + + public DateTime? UpdatedTime { get; set; } + + + + } +} \ No newline at end of file diff --git a/DOAN.Model/MES/group/GroupPost.cs b/DOAN.Model/MES/group/GroupPost.cs new file mode 100644 index 0000000..c65b5c9 --- /dev/null +++ b/DOAN.Model/MES/group/GroupPost.cs @@ -0,0 +1,63 @@ + +namespace DOAN.Model.MES.group +{ + /// + /// 岗位 + /// + [SugarTable("group_post")] + public class GroupPost + { + /// + /// 雪花 + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = false)] + public string Id { get; set; } + + /// + /// 父id + /// + [SugarColumn(ColumnName = "parent_id")] + public string ParentId { get; set; } + + /// + /// 岗位名称 + /// + [SugarColumn(ColumnName = "post_name")] + public string PostName { get; set; } + + /// + /// 1:启用 0:停用 + /// + public int? Status { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } + + /// + /// 创建人 + /// + [SugarColumn(ColumnName = "cREATED_BY")] + public string CreatedBy { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "cREATED_TIME")] + public DateTime? CreatedTime { get; set; } + + /// + /// 更新人 + /// + [SugarColumn(ColumnName = "uPDATED_BY")] + public string UpdatedBy { get; set; } + + /// + /// 更新时间 + /// + [SugarColumn(ColumnName = "uPDATED_TIME")] + public DateTime? UpdatedTime { get; set; } + + } +} \ No newline at end of file diff --git a/DOAN.Service/MES/group/GroupPostService.cs b/DOAN.Service/MES/group/GroupPostService.cs new file mode 100644 index 0000000..9c55b4e --- /dev/null +++ b/DOAN.Service/MES/group/GroupPostService.cs @@ -0,0 +1,135 @@ +using System; +using SqlSugar; +using Infrastructure.Attribute; +using Infrastructure.Extensions; +using DOAN.Model; +using DOAN.Model.Dto; +using DOAN.Model.MES.group; +using DOAN.Model.MES.group.Dto; +using DOAN.Repository; +using DOAN.Service.group.IService; +using System.Linq; +using DOAN.Common; + +namespace DOAN.Service.group +{ + /// + /// 岗位Service业务层处理 + /// + [AppService(ServiceType = typeof(IGroupPostService), ServiceLifetime = LifeTime.Transient)] + public class GroupPostService : BaseService, IGroupPostService + { + /// + /// 查询岗位列表 + /// + /// + /// + public PagedInfo GetList(GroupPostQueryDto parm) + { + var predicate = Expressionable.Create() + .AndIF(!string.IsNullOrEmpty(parm.PostName), it => it.PostName.Contains(parm.PostName)); + + ; + + var response = Queryable() + .Where(predicate.ToExpression()) + .ToPage(parm); + + return response; + } + + + /// + /// 获取详情 + /// + /// + /// + public GroupPost GetInfo(string Id) + { + var response = Queryable() + .Where(x => x.Id == Id) + .First(); + + return response; + } + + /// + /// 添加岗位 + /// + /// + /// + public GroupPost AddGroupPost(GroupPost model) + { + model.Id = XueHua; + if (string.IsNullOrEmpty(model.ParentId)) + { + model.ParentId = "0"; + } + + return Context.Insertable(model).ExecuteReturnEntity(); + } + + /// + /// 修改岗位 + /// + /// + /// + public int UpdateGroupPost(GroupPost model) + { + //var response = Update(w => w.Id == model.Id, it => new GroupPost() + //{ + // PostName = model.PostName, + // Status = model.Status, + // Remark = model.Remark, + // CreatedBy = model.CreatedBy, + // CreatedTime = model.CreatedTime, + // UpdatedBy = model.UpdatedBy, + // UpdatedTime = model.UpdatedTime, + //}); + //return response; + return Update(model, true); + } + + /// + /// 删除岗位包括子 + /// + /// + /// + public int RemoveGroupPost(string[] ids) + { + List all_nodes = Context.Queryable().ToList(); + + + List Descendants = GetDescendants(all_nodes, ids[0]); + + + List children = Descendants.Select(it => it.Id).ToList(); + children.Add(ids[0]); + + return Delete(children.ToArray()); + } + public List GetDescendants(List nodes, string rootId) + { + var descendants = new List(); + + + void FindChildren(GroupPost node) + { + var children = nodes.Where(n => n.ParentId == node.Id).ToList(); + foreach (var child in children) + { + descendants.Add(child); + FindChildren(child); + } + } + + var rootNode = nodes.FirstOrDefault(n => n.Id == rootId); + if (rootNode != null) + { + FindChildren(rootNode); + } + + return descendants; + } + } +} \ No newline at end of file diff --git a/DOAN.Service/MES/group/IService/IGroupPostService.cs b/DOAN.Service/MES/group/IService/IGroupPostService.cs new file mode 100644 index 0000000..014ef89 --- /dev/null +++ b/DOAN.Service/MES/group/IService/IGroupPostService.cs @@ -0,0 +1,26 @@ +using System; +using DOAN.Model; +using DOAN.Model.Dto; +using DOAN.Model.MES.group; +using DOAN.Model.MES.group.Dto; +using System.Collections.Generic; + +namespace DOAN.Service.group.IService +{ + /// + /// 岗位service接口 + /// + public interface IGroupPostService : IBaseService + { + PagedInfo GetList(GroupPostQueryDto parm); + + GroupPost GetInfo(string Id); + + GroupPost AddGroupPost(GroupPost parm); + + int UpdateGroupPost(GroupPost parm); + + int RemoveGroupPost(string[] ids); + + } +}