luocaiyang 3 лет назад
Родитель
Сommit
c0817461e4

+ 162 - 0
wispro.sp.api/Controllers/OrganizationController.cs

@@ -0,0 +1,162 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using wispro.sp.entity;
+
+namespace wispro.sp.api.Controllers
+{
+    [Route("api/[controller]/[action]")]
+    [ApiController]
+    public class OrganizationController : ControllerBase
+    {
+        spDbContext Context;
+
+        public OrganizationController(spDbContext context)
+        {
+            Context = context;
+        }
+        #region 部门API
+        [HttpPost]
+        public Department SaveDept(Department dept)
+        {
+            if(dept.Id > 0)
+            {
+                var inDbObj = Context.Departments.FirstOrDefault<Department>(d=>d.Id == dept.Id);
+
+                inDbObj.Name = dept.Name;
+                inDbObj.Memo = dept.Memo;
+
+                if(dept.order_num != inDbObj.order_num)
+                {
+                    inDbObj.order_num = dept.order_num;
+                }
+
+                if(dept.parentId != inDbObj.parentId)
+                {
+                    inDbObj.parentId = dept.parentId;
+                    Department parentDept = null;
+                    if (dept.parentId != null)
+                    {
+                        parentDept = Context.Departments.FirstOrDefault<Department>(d => d.Id == dept.parentId);
+                    }
+                    
+                    if (parentDept != null || !string.IsNullOrEmpty(parentDept.ancestors))
+                    {
+
+                        inDbObj.ancestors = $"{parentDept.ancestors},{parentDept.Id}";
+                    }
+                    else
+                    {
+                        inDbObj.ancestors = parentDept.Id.ToString();
+                    }
+
+                    if (dept.order_num == null)
+                    {
+                        var temOrderNum = Context.Departments.Where<Department>(d => d.parentId == parentDept.parentId).Max(d => d.order_num);
+                        if (temOrderNum == null)
+                        {
+                            inDbObj.order_num = temOrderNum + 1;
+                        }
+                        else
+                        {
+                            inDbObj.order_num = 1;
+                        }
+                    }
+                    else
+                    {
+                        inDbObj.order_num = dept.order_num;
+                    }
+                }
+
+
+                Context.SaveChanges();
+
+                return inDbObj;
+                
+            }
+            else
+            {
+                Department parentDept = null;
+                if (dept.parentId != null)
+                {
+                    parentDept = Context.Departments.FirstOrDefault<Department>(d => d.Id == dept.parentId);
+                }
+                
+
+                if (dept.order_num == null)
+                {
+                    if(parentDept == null)
+                    {
+                        var temOrderNum = Context.Departments.Where<Department>(d => d.parentId == null).Max(d => d.order_num);
+                        if (temOrderNum != null)
+                        {
+                            dept.order_num = temOrderNum + 1;
+                        }
+                        else
+                        {
+                            dept.order_num = 1;
+                        }
+                    }
+                    else
+                    {
+                        var temOrderNum = Context.Departments.Where<Department>(d => d.parentId == parentDept.Id ).Max(d => d.order_num);
+                        if (temOrderNum != null)
+                        {
+                            dept.order_num = temOrderNum + 1;
+                        }
+                        else
+                        {
+                            dept.order_num = 1;
+                        }
+                    }
+                    
+                    
+                }
+
+                if(parentDept != null && !string.IsNullOrEmpty(parentDept.ancestors ))
+                {
+
+                    dept.ancestors = $"{parentDept.ancestors},{parentDept.Id}";
+                }
+                else
+                {
+                    if (parentDept != null)
+                    {
+                        dept.ancestors = parentDept.Id.ToString();
+                    }
+                }
+
+                Context.Departments.Add(dept);
+                Context.SaveChanges();
+                return dept;
+
+
+            }
+        }
+
+        public List<Department> GetDepartments()
+        {
+            return Context.Departments.ToList();
+        }
+
+        public bool DeleteDept(int Id)
+        {
+            try
+            {
+                var delObj = Context.Departments.FirstOrDefault<Department>(d => d.Id == Id);
+                Context.Departments.Remove(delObj);
+                Context.SaveChanges();
+                return true;
+            }
+            catch(Exception ex)
+            {
+                return false;
+            }
+
+        }
+        #endregion
+    }
+}

+ 1 - 1
wispro.sp.api/Controllers/StaffController.cs

@@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Authorization;
 
 namespace wispro.sp.api.Controllers
 {
-    [Authorize]
+    //[Authorize]
     [Route("api/[controller]/[action]")]
     [ApiController]
     public class StaffController : ControllerBase

+ 1 - 1
wispro.sp.api/Properties/launchSettings.json

@@ -4,7 +4,7 @@
     "anonymousAuthentication": true,
     "iisExpress": {
       "applicationUrl": "http://localhost:39476",
-      "sslPort": 44359
+      "sslPort": 0
     }
   },
   "$schema": "http://json.schemastore.org/launchsettings.json",

+ 0 - 14
wispro.sp.api/Startup.cs

@@ -61,11 +61,6 @@ namespace wispro.sp.api
                 o.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
                 
             });
-            //services.AddControllers().AddJsonOptions(options =>
-            //{
-            //    options.JsonSerializerOptions.IgnoreNullValues = true;
-            //    options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve;
-            //});
 
             services.AddDbContext<spDbContext>(optionsAction =>
                 optionsAction.UseSqlServer(Configuration.GetConnectionString("DefaultConnect"))
@@ -98,15 +93,6 @@ namespace wispro.sp.api
             });
 
             
-
-            //JobKey jobKey = new JobKey("ImportReportData");
-            //var trigger = TriggerBuilder.Create()
-            //    .WithDescription("µ¼ÈëÿÔ±¨±í")
-            //    .WithSchedule(CronScheduleBuilder.CronSchedule("0 0/2 * * * ? *").WithMisfireHandlingInstructionDoNothing())
-            //    .Build();
-
-
-            //QuartzUtil.Add(typeof(ImportReportJob), jobKey, trigger);
         }
     }
 }

+ 2 - 1
wispro.sp.api/appsettings.json

@@ -27,7 +27,8 @@
     "Account": "caiyangl",
     "Password": "j)wx*lier*@3",
     "ChormeDriverPath": "D:\\source\\repos\\ConsoleApp2\\ConsoleApp2\\bin\\Debug",
-    "ScheduleSetting": "00 16 01 1 * ? *"
+    "ScheduleSetting": "00 16 01 1 * ? *",
+    "IPEasyWeb": "http://47.106.221.167/Login.aspx"
   },
 
   "MailSetting": {

+ 31 - 0
wispro.sp.api/spDbContext.cs

@@ -49,6 +49,12 @@ namespace wispro.sp.api
 
         public virtual DbSet<CaseCeoffcient> CaseCeoffcients { get; set; }
 
+        public virtual DbSet<Department> Departments { get; set; }
+
+        public virtual DbSet<Position> Positions { get; set; }
+
+        public virtual DbSet<DepartmentPosition> DepartmentPositions { get; set; }
+
         protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
         {
             if (!optionsBuilder.IsConfigured)
@@ -418,6 +424,31 @@ namespace wispro.sp.api
 
             });
 
+            modelBuilder.Entity<Department>(entity => {
+                entity.ToTable("Department");
+                
+            });
+
+            modelBuilder.Entity<Position>(entity => {
+                entity.ToTable("Position");
+            });
+
+            modelBuilder.Entity<DepartmentPosition>(entity=> {
+                entity.ToTable("DepartmentPosition");
+
+                entity.HasOne(d => d.department)
+                    .WithMany()
+                    .HasForeignKey(d => d.departmentId);
+
+                entity.HasOne(d => d.Position)
+                    .WithMany()
+                    .HasForeignKey(d=>d.PositionId);
+
+                entity.HasOne(d => d.Staff)
+                    .WithMany()
+                    .HasForeignKey(d => d.StaffId);
+            });
+
             modelBuilder.Entity<StaffGrade>().HasData(
                 new StaffGrade[]
                 {

+ 9 - 0
wispro.sp.web/Components/RightMenuTreeNode.razor

@@ -0,0 +1,9 @@
+<ContextMenu Id="@($"righMenu-{Department.Id}")" Context="pp">
+    <Item OnClick="() => _OnCreate(Department)">添加</Item>
+    <Item OnClick="() => _OnEdit(Department)">修改</Item>
+    <Item OnClick="() => _OnDelete(Department)">删除</Item>
+</ContextMenu>
+
+<ContextMenuTrigger MenuId="@($"righMenu-{Department.Id}")">
+    <div>@Department.Name</div>
+</ContextMenuTrigger>

+ 51 - 0
wispro.sp.web/Components/RightMenuTreeNode.razor.cs

@@ -0,0 +1,51 @@
+using Microsoft.AspNetCore.Components;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using wispro.sp.entity;
+
+namespace wispro.sp.web.Components
+{
+    public partial class RightMenuTreeNode
+    {
+        [Parameter]
+        public Department Department { get; set; }
+
+        [Parameter]
+        public EventCallback<Department> OnCreate { get; set; }
+
+        [Parameter]
+        public EventCallback<Department> OnEdit { get; set; }
+
+        [Parameter]
+        public EventCallback<Department> OnDelete { get; set; }
+
+        private void _OnCreate(Department dept)
+        {
+            if (OnCreate.HasDelegate)
+            {
+                OnCreate.InvokeAsync(dept);
+            }
+            
+        }
+
+        private void _OnEdit(Department dept)
+        {
+            if (OnEdit.HasDelegate)
+            {
+                OnEdit.InvokeAsync(dept);
+            }
+
+        }
+
+        private void _OnDelete(Department dept)
+        {
+            if (OnDelete.HasDelegate)
+            {
+                OnDelete.InvokeAsync(dept);
+            }
+
+        }
+    }
+}

+ 80 - 0
wispro.sp.web/Pages/Organization/Department.razor

@@ -0,0 +1,80 @@
+@page "/Department"
+
+<PageContainer>
+    <Breadcrumb>
+        <Breadcrumb>
+            <BreadcrumbItem>
+                <a href="/Home"><Icon Type="home"></Icon></a>
+            </BreadcrumbItem>
+            <BreadcrumbItem>
+                <Icon Type="setting"></Icon><span>基本信息管理</span>
+            </BreadcrumbItem>
+            <BreadcrumbItem>
+                <Icon Type="user"></Icon><span>部门管理</span>
+            </BreadcrumbItem>
+        </Breadcrumb>
+    </Breadcrumb>
+    <Content>
+        <Button Type="primary" Icon="plus" OnClick="()=>AddNew(null)" Style="float:right">添加</Button>
+    </Content>
+    <ChildContent>
+        <AntDesign.Layout>
+            <Sider Style="background-color:white" Width="260">
+                <div style="width:fit-content">
+                    @if (departments != null)
+                    {
+                    <Tree @ref="tree" DefaultExpandAll Draggable BlockNode ShowLine="true" ShowLeafIcon="true"
+                          ShowIcon DataSource="GetChildren(null)"
+                          TitleExpression="x => x.DataItem.Name"
+                          ChildrenExpression="x => GetChildren(x.DataItem)"
+                          IsLeafExpression="x => GetChildren(x.DataItem)?.Count == 0"
+                          KeyExpression="x => x.DataItem.Id.ToString()"
+                          TItem="wispro.sp.entity.Department" OnDragEnd="e => { }"
+                          OnClick="OnSelect"
+                          Style="width:250px;">
+                        <TitleTemplate>
+                            <wispro.sp.web.Components.RightMenuTreeNode Department="@context.DataItem"/>
+
+                            @*<Menu Mode=MenuMode.Horizontal Style="float:right;font-size: small;">
+                            <SubMenu>
+                                <TitleTemplate>
+                                    <Icon Type="plus" />
+                                </TitleTemplate>
+                                <ChildContent>
+                                    <MenuItem Icon="folder-add" OnClick="() => AddNew(context.DataItem)">添加</MenuItem>
+                                    <MenuItem Icon="edit" OnClick="() => EditDept(context.DataItem)">编辑</MenuItem>
+                                    <MenuItem Icon="delete" OnClick="() => DeleteDept(context.DataItem)">删除</MenuItem>
+                                </ChildContent>
+                            </SubMenu>
+                        </Menu>*@
+                        </TitleTemplate>
+                    </Tree>
+                    }
+                        else
+                        {
+                            <Spin/>
+                        }
+                </div>
+            </Sider>
+            <Content>
+
+            </Content>
+        </AntDesign.Layout>
+    </ChildContent>
+</PageContainer>
+
+<Modal Title="新建"
+       Visible="@newModal"
+       OnOk="@NewOk"
+       OnCancel="@NewCancel">
+
+    <Form Model="_editDepartment" LabelColSpan="6"
+          WrapperColSpan="16">
+        <FormItem Label="名称">
+            <Input @bind-Value="@context.Name" />
+        </FormItem>
+        <FormItem Label="备注">
+            <TextArea @bind-Value="@context.Memo" MinRows="4" />
+        </FormItem>
+    </Form>
+</Modal>

+ 116 - 0
wispro.sp.web/Pages/Organization/Department.razor.cs

@@ -0,0 +1,116 @@
+using AntDesign;
+using Microsoft.AspNetCore.Components;
+using Microsoft.AspNetCore.Components.Web;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.Json;
+using System.Threading.Tasks;
+using wispro.sp.web.Services;
+
+namespace wispro.sp.web.Pages.Organization
+{
+    public partial class Department
+    {
+        private List<wispro.sp.entity.Department> departments;
+        Tree<wispro.sp.entity.Department> tree;
+        string searchKey;
+        bool _loading = false;
+
+        entity.Department _editDepartment;
+       [Inject] OrganizationService orgService { get; set; }
+
+        protected override async System.Threading.Tasks.Task OnInitializedAsync()
+        {
+
+            _loading = true;
+
+            departments =await orgService.GetDepartments(); 
+                
+            _loading = false;
+        }
+
+        #region 部门操作
+        bool newModal = false;
+        private void AddNew(entity.Department parentDept)
+        {
+            _editDepartment = new entity.Department();
+
+            if (parentDept != null)
+            {
+                _editDepartment.parentId = parentDept.Id;
+                //if(!string.IsNullOrEmpty(parentDept.ancestors))
+                //{
+                //    _editDepartment.ancestors = $"{parentDept.ancestors},{parentDept.Id}";
+                //}
+                //else
+                //{
+                //    _editDepartment.ancestors  = parentDept.Id.ToString();
+                //}
+                
+                //_editDepartment.order_num = GetChildren(parentDept).Count + 1;
+            }
+            
+            newModal = true; 
+        }
+        
+
+        private void EditDept(entity.Department department)
+        {
+            _editDepartment = department;
+            newModal = true;
+        }
+
+        private async Task DeleteDept(entity.Department department)
+        {
+            var result = await orgService.DeleteDept(department.Id);
+            departments = await orgService.GetDepartments();
+            StateHasChanged();
+        }
+
+        private async System.Threading.Tasks.Task NewOk(MouseEventArgs e)
+        {
+            newModal = false;
+            Console.WriteLine(JsonSerializer.Serialize(_editDepartment)); 
+            var retObj = await orgService.SaveDept(_editDepartment);
+            Console.WriteLine(JsonSerializer.Serialize(retObj)); 
+            departments = await orgService.GetDepartments();
+            StateHasChanged();
+        }
+
+        private void NewCancel(MouseEventArgs e)
+        {
+            newModal = false;
+        }
+        #endregion
+
+        void OnSelect(TreeEventArgs<entity.Department> e)
+        {
+            _editDepartment = e.Node.DataItem;
+            //Console.WriteLine(JsonSerializer.Serialize(e));
+        }
+
+        private List<wispro.sp.entity.Department> GetChildren(wispro.sp.entity.Department dept)
+        {
+            if(dept == null)
+            {
+                var retList = departments.Where<wispro.sp.entity.Department>(x => x.parentId == null).OrderBy(x=>x.order_num).ToList();
+                Console.WriteLine(JsonSerializer.Serialize(retList));
+                return retList;
+            }
+            else
+            {
+                var retList = departments.Where<wispro.sp.entity.Department>(x => x.parentId == dept.Id).OrderBy(x => x.order_num).ToList();
+                Console.WriteLine(JsonSerializer.Serialize(retList));
+                return retList;
+            }
+            
+        }
+
+        void HandleRightClick(MouseEventArgs args)
+        {
+            if (args.Button == 2)
+                Console.WriteLine("This is a right click");
+        }
+    }
+}

+ 3 - 0
wispro.sp.web/Program.cs

@@ -40,6 +40,9 @@ namespace wispro.sp.web
             builder.Services.AddScoped<IAgentFeedBackMemoItemsService, AgentFeedbackMemoItemsServices>();
             builder.Services.AddScoped<AppealTypeService, AppealTypeService>();
             builder.Services.AddScoped<IHttpService, HttpService>();
+            builder.Services.AddScoped<OrganizationService, OrganizationService>();
+
+            builder.Services.AddBlazorContextMenu();
 
             await builder.Build().RunAsync();
         }

+ 38 - 0
wispro.sp.web/Services/OrganizationService.cs

@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using wispro.sp.entity;
+
+namespace wispro.sp.web.Services
+{
+    public class OrganizationService
+    {
+        private readonly IHttpService _httpClient;
+        
+
+        public OrganizationService(IHttpService httpClient)
+        {
+            _httpClient = httpClient;
+           
+        }
+        public async Task<Department> SaveDept(Department dept)
+        {
+            var data = await _httpClient.Post<Department>($"Organization/SaveDept",dept);
+            return data;
+        }
+
+        public async Task<List<Department>> GetDepartments()
+        {
+            var data = await _httpClient.Get<List<Department>>($"Organization/GetDepartments");
+            return data;
+        }
+
+        public async  Task<bool> DeleteDept(int deptId)
+        {
+            var ret =  await _httpClient.Get<bool>($"Organization/DeleteDept?Id={deptId}");
+            return ret;
+           
+        }
+    }
+}

+ 1 - 0
wispro.sp.web/_Imports.razor

@@ -14,3 +14,4 @@
 @using wispro.sp.web.Services
 @using Microsoft.AspNetCore.Components.Authorization
 @using Microsoft.AspNetCore.Authorization
+@using BlazorContextMenu

+ 1 - 0
wispro.sp.web/wispro.sp.web.csproj

@@ -27,6 +27,7 @@
   <ItemGroup>
     <PackageReference Include="AntDesign.Charts" Version="0.2.1" />
     <PackageReference Include="AntDesign.ProLayout" Version="0.1.8" />
+    <PackageReference Include="Blazor.ContextMenu" Version="1.10.1" />
     <PackageReference Include="Blazored.LocalStorage" Version="4.1.5" />
     <PackageReference Include="DynamicExpresso.Core" Version="2.9.3" />
     <PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.0" />

+ 2 - 2
wospro.sp.entity/Organization/Department.cs

@@ -30,7 +30,7 @@ namespace wispro.sp.entity
         /// <summary>
         /// 同层排序字段
         /// </summary>
-        public int order_num { get; set; }
+        public int? order_num { get; set; }
 
         /// <summary>
         /// 部门备注
@@ -41,6 +41,6 @@ namespace wispro.sp.entity
         /// <summary>
         /// 上级部门Id
         /// </summary>
-        public int parentId { get; set; }
+        public int? parentId { get; set; }
     }
 }

+ 3 - 1
wospro.sp.entity/Organization/DepartmentPosition.cs

@@ -32,6 +32,8 @@ namespace wispro.sp.entity
         public int PositionId { get; set; }
 
         
-        public virtual List<Staff> Staffs { get; set; }
+        public virtual Staff Staff { get; set; }
+
+        public int StaffId { get; set; }
     }
 }

+ 5 - 0
wospro.sp.entity/Organization/Position.cs

@@ -20,5 +20,10 @@ namespace wispro.sp.entity
         /// 职位名称
         /// </summary>
         public string Name { get; set; }
+
+        /// <summary>
+        /// 说明
+        /// </summary>
+        public string Memo { get; set; }
     }
 }

+ 5 - 0
wospro.sp.entity/Organization/Staff.cs

@@ -117,5 +117,10 @@ namespace wispro.sp.entity
         /// </summary>
         public virtual ICollection<PerformanceItem> ReviewerItems { get; set; }
 
+        /// <summary>
+        /// 职位
+        /// </summary>
+        public virtual ICollection<DepartmentPosition> Positions { get; set; }
+
     }
 }