Forráskód Böngészése

公司日常绩效 CURD、建表、本地测试

Lyyyi 4 nap óta
szülő
commit
76ab6b2781

+ 17 - 9
OASystem/OASystem.Api/Controllers/PersonnelModuleController.cs

@@ -5092,7 +5092,6 @@ ORDER BY MonthNumber, CollectionDays";
 
         #region 公司部门日常绩效
 
-
         /// <summary>
         /// 绩效数据
         /// </summary>
@@ -5110,31 +5109,40 @@ ORDER BY MonthNumber, CollectionDays";
         }
 
 
-        #region 财务部
+        #region 公司日常绩效
 
         /// <summary>
-        /// 财务部 日常绩效 初始化数据
+        /// 公司日常绩效 初始化数据
         /// </summary>
         /// <returns></returns>
         [HttpGet]
-        public async Task<IActionResult> FinanceKpiInit()
+        public async Task<IActionResult> CompanyDailyKpiInit()
         {
-            return Ok(await _companyDailyKyiRep.FinanceInit());
+            return Ok(await _companyDailyKyiRep.InitAsync());
         }
 
-
         /// <summary>
-        /// 财务部 日常绩效 详情
+        /// 公司日常绩效 详情
         /// </summary>
         /// <param name="month">月份(2025-12)</param>
         /// <param name="evaluator">考核人</param>
         /// <returns></returns>
         [HttpGet]
-        public async Task<IActionResult> FinanceKpiInfos(string month, int evaluator)
+        public async Task<IActionResult> CompanyDailyInfos(string month, int evaluator)
         {
-            return Ok(await _companyDailyKyiRep.FinanceInfo(month, evaluator));
+            return Ok(await _companyDailyKyiRep.InfoAsync(month, evaluator));
         }
 
+        /// <summary>
+        /// 公司日常绩效 保存
+        /// </summary>
+        /// <param name="dto">请求类</param>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<IActionResult> CompanyDailyKpiSave(CompanyDailyKpiSaveDto dto)
+        {
+            return Ok(await _companyDailyKyiRep.SaveAsync(dto));
+        }
 
         #endregion
 

+ 5 - 0
OASystem/OASystem.Domain/AutoMappers/_baseMappingProfile.cs

@@ -410,6 +410,11 @@ namespace OASystem.Domain.AutoMappers
             CreateMap<ConferenceAffairsCostView, Grp_ConferenceAffairsCost>();
             CreateMap<ConferenceAffairsCostChildView, Grp_ConferenceAffairsCostChild>();
             #endregion
+
+            #region 公司日常 KPI
+            CreateMap<CompanyDailyKpiView, Pm_CompanyDailyKpi>();
+
+            #endregion
         }
     }
 

+ 26 - 0
OASystem/OASystem.Domain/Dtos/PersonnelModule/DailyKpiDtos.cs

@@ -0,0 +1,26 @@
+using OASystem.Domain.ViewModels.PersonnelModule;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.PersonnelModule
+{
+    public class DailyKpiDtos
+    {
+        public int CurrUserId { get; set; }
+    }
+
+    #region 财务 日常考勤 dto
+
+    public class CompanyDailyKpiSaveDto : DailyKpiDtos
+    {
+        public List<CompanyDailyKpiView> Infos { get; set; }
+    }
+
+
+    #endregion
+
+
+}

+ 8 - 2
OASystem/OASystem.Domain/Entities/PersonnelModule/Pm_CompanyDailyKpi.cs

@@ -24,11 +24,17 @@ namespace OASystem.Domain.Entities.PersonnelModule
         [SugarColumn(ColumnName = "Evaluator", ColumnDescription = "考核人", IsNullable = true, ColumnDataType = "int")]
         public int Evaluator { get; set; }
 
+        /// <summary>
+        /// 考核内容 Order
+        /// </summary>
+        [SugarColumn(ColumnName = "EvalContentOrder", ColumnDescription = "考核内容 Order", IsNullable = true, ColumnDataType = "int")]
+        public int EvalContentOrder { get; set; }
+
         /// <summary>
         /// 考核内容
         /// </summary>
-        [SugarColumn(ColumnName = "EvalContent", ColumnDescription = "考核内容", IsNullable = true, ColumnDataType = "int")]
-        public int EvalContent { get; set; }
+        [SugarColumn(ColumnName = "EvalContent", ColumnDescription = "考核内容", IsNullable = true, ColumnDataType = "varchar(500)")]
+        public string EvalContent { get; set; }
 
         /// <summary>
         /// 是否失误

+ 34 - 7
OASystem/OASystem.Domain/ViewModels/PersonnelModule/CompanyDailyKpiView.cs

@@ -15,22 +15,22 @@
         /// <summary>
         /// 序号
         /// </summary>
-        public string No { get; set; }
+        public int EvalContentOrder { get; set; }
 
         /// <summary>
         /// 考核人 Id
         /// </summary>
-        public int EvaluatorId { get; set; }
+        public int Evaluator { get; set; }
 
         /// <summary>
         /// 考核人
         /// </summary>
-        public string Evaluator { get; set; }
+        public string EvaluatorName { get; set; }
 
-        /// <summary>
-        /// 考核内容 Id
-        /// </summary>
-        public int EvalContentId { get; set; }
+        ///// <summary>
+        ///// 考核内容 Id
+        ///// </summary>
+        //public int EvalContentId { get; set; }
 
         /// <summary>
         /// 考核内容 
@@ -75,4 +75,31 @@
         }
 
     }
+
+    public class KpiTempDepNameInfo
+    {
+        public string DepName { get; set; }
+    }
+
+    public class KpiTempDepartmentInfo : KpiTempDepNameInfo
+    {
+        public List<string> JobNames { get; set; }
+    }
+
+    public class KpiTempDepartmentInfoView : KpiTempDepartmentInfo
+    {
+        public List<KpiTempUserInfo> Users { get; set; }
+    }
+
+    public class KpiTempUserInfo
+    {
+        public int   Id { get; set; }
+        public string DepName { get; set; }
+        public string JobName { get; set; }
+        public string Name { get; set; }
+    }
+    public class KpiTempDepartmentInitView : KpiTempDepNameInfo
+    {
+        public List<KpiTempUserInfo> Users { get; set; }
+    }
 }

+ 117 - 125
OASystem/OASystem.Infrastructure/Repositories/PersonnelModule/CompanyDailyKpiRepository.cs

@@ -1,6 +1,10 @@
 using AutoMapper;
+using EyeSoft.Messanging;
+using MathNet.Numerics;
+using OASystem.Domain.Dtos.PersonnelModule;
 using OASystem.Domain.Entities.PersonnelModule;
 using OASystem.Domain.ViewModels.PersonnelModule;
+using OASystem.Domain.ViewModels.QiYeWeChat;
 using OASystem.Infrastructure.Repositories.System;
 
 namespace OASystem.Infrastructure.Repositories.PersonnelModule
@@ -90,17 +94,22 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
         /// <summary>
         /// 获取部门和岗位
         /// </summary>
-        public async Task<object> KpiDepartmentsAndJobs()
+        /// <param name="depName">部门名称 空查询全部</param>
+        /// <returns></returns>
+        public async Task<(bool Success, string Message, List<string> Departments, List<KpiTempDepartmentInfo> DepartmentsWithJobs)>
+            KpiDepartmentsAndJobs(string depName = "")
         {
+            var departments = new List<string>();
+            var departmentsWithJobs = new List<KpiTempDepartmentInfo>();
             var config = await _sqlSugar.Queryable<Sys_SetDataType>()
                 .Where(x => x.IsDel == 0 && x.Id == 132)
                 .FirstAsync();
 
-            if (config == null) return new { Success = false, Message = "配置为空" };
+            if (config == null) return (false, "配置为空", departments, departmentsWithJobs);
 
             var typeIds = JsonSerializer.Deserialize<List<int>>(config.Remark ?? "[]");
             if (typeIds == null || typeIds.Count < 1)
-                return new { Success = false, Message = "类型ID为空" };
+                return (false, "类型ID为空", departments, departmentsWithJobs);
 
             var names = await _sqlSugar.Queryable<Sys_SetData>()
                 .LeftJoin<Sys_SetDataType>((sd, sdt) => sd.STid == sdt.Id)
@@ -137,31 +146,33 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                     return new { Department = dept, Job = job };
                 })
                 .Where(x => x.Department != "未分类")
+                .WhereIF(!string.IsNullOrEmpty(depName),x=> x.Department.Equals(depName))
                 .GroupBy(x => x.Department)
-                .Select(g => new
+                .Select(g => new KpiTempDepartmentInfo()
                 {
-                    Department = g.Key,
-                    Jobs = g.Select(x => x.Job).Distinct().Where(j => j != "通用").OrderBy(j => j).ToList()
+                    DepName = g.Key,
+                    JobNames = g.Select(x => x.Job).Distinct().Where(j => j != "通用").OrderBy(j => j).ToList()
                 })
-                .OrderBy(g => g.Department)
+                .OrderBy(g => g.DepName)
                 .ToList();
-
-            return new
-            {
-                Success = true,
-                Departments = deptJobList.Select(g => g.Department).ToList(),
-                DepartmentsWithJobs = deptJobList
-            };
+            departmentsWithJobs = deptJobList;
+            departments = deptJobList.Select(g => g.DepName).ToList();
+            return (true, "操作成功", departments, departmentsWithJobs);
         }
 
-
-        #region 财务部日常绩效
         /// <summary>
         /// 基础数据
         /// </summary>
         /// <returns></returns>
-        public async Task<JsonView> FinanceInit()
+        public async Task<JsonView> InitAsync()
         {
+            var result = await KpiDepartmentsAndJobs("财务部");
+            if (!result.Success)
+            {
+                _jv.Msg = result.Message;
+                return _jv;
+            }
+
             var userInfos = await _sqlSugar.Queryable<Sys_Users>()
                 .LeftJoin<Sys_JobPost>((u, jp) => u.JobPostId == jp.Id)
                 .LeftJoin<Sys_Department>((u, jp, d) => u.DepId == d.Id)
@@ -181,112 +192,26 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                 .OrderBy(u => u.CompanyId)
                 .ToListAsync();
 
-            if (userInfos?.Any() != true)
-            {
-                _jv.Code = StatusCodes.Status200OK;
-                _jv.Msg = $"暂无人员数据";
-                return _jv;
-            }
-
-            //转换为层级结构
-            #region 层级转换 公司 -> 部门 -> 岗位 -> 人员
-            //var result = userInfos
-            //    .GroupBy(u => new { u.CompanyId, u.CompanyName })
-            //    .Select(companyGroup => new
-            //    {
-            //        CompanyId = companyGroup.Key.CompanyId,
-            //        CompanyName = companyGroup.Key.CompanyName,
-            //        Departments = companyGroup
-            //            .GroupBy(u => new { u.DepId, u.DepName })
-            //            .Select(departmentGroup => new
-            //            {
-            //                DepId = departmentGroup.Key.DepId,
-            //                DepartmentName = departmentGroup.Key.DepName,
-            //                JobPosts = departmentGroup
-            //                    .GroupBy(u => new { u.JobPostId, u.JobName })
-            //                    .Select(jobGroup => new
-            //                    {
-            //                        JobPostId = jobGroup.Key.JobPostId,
-            //                        JobName = jobGroup.Key.JobName,
-            //                        Employees = jobGroup
-            //                            .Select(u => new
-            //                            {
-            //                                Id = u.UserId,
-            //                                UserName = u.UserName,
-            //                            })
-            //                            .OrderBy(e => e.UserName)
-            //                            .ToList()
-            //                    })
-            //                    .OrderBy(j => j.JobName)
-            //                    .ToList()
-            //            })
-            //            .OrderBy(d => d.DepartmentName)
-            //            .ToList()
-            //    })
-            //    .OrderBy(c => c.CompanyName)
-            //    .ToList();
-            #endregion
-
-            //转换为层级结构
-            #region 层级转换 公司 -> 部门 -> 人员
-            // 构建树形结构
-            var result = userInfos
-                .GroupBy(u => new { u.CompanyId, u.CompanyName })
-                .Select(companyGroup => new
-                {
-                    CompanyId = companyGroup.Key.CompanyId,
-                    CompanyName = companyGroup.Key.CompanyName,
-                    Departments = companyGroup
-                        .GroupBy(u => new { u.DepId, u.DepName })
-                        .Where(deptGroup => deptGroup.Key.DepId > 0) // 过滤掉无部门的人员
-                        .Select(deptGroup => new
-                        {
-                            DepartmentId = deptGroup.Key.DepId,
-                            DepartmentName = deptGroup.Key.DepName,
-                            Users = deptGroup
-                                .Select(u => new
-                                {
-                                    u.UserId,
-                                    u.UserName,
-                                    u.JobPostId,
-                                    u.JobName
-                                })
-                                .OrderBy(u => u.UserName)
-                                .ToList()
-                        })
-                        .Where(dept => dept.Users.Any())
-                        .OrderBy(dept => dept.DepartmentName)
-                        .ToList(),
-                    // 无部门的人员(直接挂载到公司下)
-                    NoDepartmentUsers = companyGroup
-                        .Where(u => u.DepId <= 0)
-                        .Select(u => new
-                        {
-                            u.UserId,
-                            u.UserName,
-                            u.JobPostId,
-                            u.JobName
-                        })
-                        .OrderBy(u => u.UserName)
-                        .ToList()
-                })
-                .OrderBy(c => c.CompanyName)
+            var jobNames = result.DepartmentsWithJobs
+                .SelectMany(x => x.JobNames)
                 .ToList();
-            #endregion
 
+            var view = userInfos.Where(x => jobNames.Contains(x.JobName))
+                .Select(x => new KpiTempUserInfo() { Id = x.UserId, DepName = x.DepName, JobName = x.JobName, Name = x.UserName })
+                .ToList();
             _jv.Code = StatusCodes.Status200OK;
-            _jv.Data = result;
+            _jv.Data = view;
             _jv.Msg = $"操作成功";
             return _jv;
         }
 
         /// <summary>
-        /// 日常考勤详情
+        /// 考勤详情
         /// </summary>
         /// <param name="month">月份 2025-12</param>
         /// <param name="evaluator">考核人</param>
         /// <returns></returns>
-        public async Task<JsonView> FinanceInfo(string month, int evaluator)
+        public async Task<JsonView> InfoAsync(string month, int evaluator)
         {
             if (string.IsNullOrEmpty(month))
             {
@@ -326,17 +251,16 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
 
             var info = await _sqlSugar
                 .Queryable<Pm_CompanyDailyKpi>()
-                .LeftJoin<Sys_SetData>((cdk, sd) => cdk.EvalContent == sd.Id)
-                .LeftJoin<Sys_Users>((cdk, sd, u) => cdk.Evaluator == u.Id)
-                .Where((cdk, sd, u) => cdk.IsDel == 0 && cdk.Evaluator == evaluator && cdk.Month.Equals(month))
-                .Select((cdk, sd, u) => new CompanyDailyKpiView()
+                .LeftJoin<Sys_Users>((cdk,  u) => cdk.Evaluator == u.Id)
+                .Where((cdk,  u) => cdk.IsDel == 0 && cdk.Evaluator == evaluator && cdk.Month.Equals(month))
+                .Select((cdk,  u) => new CompanyDailyKpiView()
                 {
                     Id = cdk.Id,
                     Month = cdk.Month,
-                    EvaluatorId = cdk.Evaluator,
-                    Evaluator = u.CnName,
-                    EvalContentId = cdk.EvalContent,
-                    EvalContent = sd.Remark,
+                    EvalContentOrder = cdk.EvalContentOrder,
+                    Evaluator = cdk.Evaluator,
+                    EvaluatorName = u.CnName,
+                    EvalContent = cdk.EvalContent,
                     IsMistake = cdk.IsMistake,
                     MistakeReason = cdk.MistakeReason
                 })
@@ -347,7 +271,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                 var tempInfo = await KpiTemplateDataAsync(evaluatorInfo.DepName, evaluatorInfo.JobName);
                 if (!tempInfo.isSuccess)
                 {
-                    _jv.Msg = $"{evaluatorInfo.DepName} - {evaluatorInfo.JobName},未配置日常绩效考核。";
+                    _jv.Msg = $"{evaluatorInfo.DepName}-{evaluatorInfo.JobName},未配置日常绩效考核。";
                     return _jv;
                 }
 
@@ -355,13 +279,13 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                 {
                     t.Contents.ForEach(c =>
                     {
+                        _ = int.TryParse(c.KpiSort, out int no);
                         info.Add(new CompanyDailyKpiView()
                         {
                             Month = month,
-                            No = c.KpiSort,
-                            EvaluatorId = evaluatorInfo.UserId,
-                            Evaluator = evaluatorInfo.UserName,
-                            EvalContentId = c.KpiId,
+                            EvalContentOrder = no,
+                            Evaluator = evaluatorInfo.UserId,
+                            EvaluatorName = evaluatorInfo.UserName,
                             EvalContent = c.KpiContent,
                             IsMistake = false,
                             MistakeReason = string.Empty
@@ -376,7 +300,75 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
             return _jv;
         }
 
-        #endregion
+        /// <summary>
+        /// kpi Save
+        /// </summary>
+        /// <param name="dto">请求类</param>
+        /// <returns></returns>
+        public async Task<JsonView> SaveAsync(CompanyDailyKpiSaveDto dto)
+        {
+            if (dto.Infos == null || !dto.Infos.Any())
+            {
+                _jv.Msg = $"请选择需要新增或者编辑的数据!";
+                return _jv;
+            }
+
+            var evaluatorInfo = await _sqlSugar.Queryable<Sys_Users>()
+                 .LeftJoin<Sys_Company>((u, c) => u.CompanyId == c.Id)
+                 .LeftJoin<Sys_Department>((u, c, d) => u.DepId == d.Id)
+                 .LeftJoin<Sys_JobPost>((u, c, d, jp) => u.JobPostId == jp.Id)
+                 .Where((u, c, d, jp) => u.IsDel == 0 && u.Id == dto.CurrUserId)
+                 .Select((u, c, d, jp) => new
+                 {
+                     UserId = u.Id,
+                     u.CompanyId,
+                     c.CompanyName,
+                     u.DepId,
+                     d.DepName,
+                     u.JobPostId,
+                     jp.JobName,
+                     UserName = u.CnName
+                 })
+                 .FirstAsync();
+            if (evaluatorInfo == null)
+            {
+                _jv.Msg = $"请选择有效的考核人!";
+                return _jv;
+            }
+            _ = dto.Infos.OrderBy(x => x.EvalContentOrder);
+            var infos = _mapper.Map<List<Pm_CompanyDailyKpi>>(dto.Infos);
+            
+            infos.ForEach(x => {
+                if (x.Id <= 0)
+                {
+                    x.CreateUserId = dto.CurrUserId;
+                }
+                x.LastUpdateUserId = dto.CurrUserId;
+                x.LastUpdateTime = DateTime.Now;
+            });
+
+            try
+            {
+                var storage = _sqlSugar.Storageable(infos)
+                       .WhereColumns(x => x.Id) // 根据Id判断
+                       .ToStorage();
+
+                await storage.AsInsertable.ExecuteCommandAsync();
+                await storage.AsUpdateable.ExecuteCommandAsync();
+                _jv.Code = StatusCodes.Status200OK;
+                //_jv.Data = infos;
+                _jv.Msg = $"操作成功";
+                return _jv;
+            }
+            catch (Exception ex)
+            {
+
+                _jv.Msg = $"操作失败!Ex:{ex.Message}";
+                return _jv;
+            }
+        }
+
+
 
     }
 }