yuanrf 4 nap óta
szülő
commit
8675919361

+ 97 - 0
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -32856,6 +32856,103 @@ ORDER BY
 
         #region 团组会务成本
 
+        ///读取excel数据
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> MaterialCostsReadExcel(MaterialCostsReadExcelDto dto)
+        {
+            var file = dto.File;
+            var rowIndex = dto.RowIndex;
+            var userId = dto.UserId;
+            var groupId = dto.GroupId;
+            var conferenceAffairsCostId = dto.ConferenceAffairsCostId;
+
+            if (file == null || file.Length == 0)
+            {
+                return Ok(JsonView(false, "请选择文件"));
+            }
+
+
+            var conferenceAffairsCost = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
+                           .First(x => x.Id == conferenceAffairsCostId && x.IsDel == 0);
+            if (conferenceAffairsCost == null)
+            {
+                return Ok(JsonView(false, "ConferenceAffairsCostId 参数有误!"));
+            }
+
+
+            var workbook = new Workbook(file.OpenReadStream());
+            var worksheet = workbook.Worksheets[0];
+            var rowCount = worksheet.Cells.MaxDataRow + 1;
+            var colCount = worksheet.Cells.MaxDataColumn + 1;
+
+            var setDatas = await _sqlSugar.Queryable<Sys_SetData>()
+            .Where(x => x.IsDel == 0 && (x.STid == 21 || x.STid == 119))
+            .Select(x => new { x.Id, x.Name, x.STid })
+            .ToListAsync();
+
+            var typeItems = setDatas.Where(x => x.STid == 21).ToList();
+            var unitItems = setDatas.Where(x => x.STid == 119).ToList();
+            // 预处理为字典,提高查找效率
+            var typeDict = typeItems.GroupBy(x => x.Name).ToDictionary(g => g.Key, g => g.First().Id);
+            var unitDict = unitItems.GroupBy(x => x.Name).ToDictionary(g => g.Key, g => g.First().Id);
+
+            List<Grp_ConferenceAffairsCostChild> data = new List<Grp_ConferenceAffairsCostChild>();
+
+            for (int i = rowIndex; i < rowCount; i++)
+            {
+                var sotr = int.TryParse(worksheet.Cells[i, 0].Value.toString(), out int index) ? index : 0;
+                var typeName = worksheet.Cells[i, 1].Value.toString();
+                var itemName = worksheet.Cells[i, 2].Value.toString();
+                var count = int.TryParse(worksheet.Cells[i, 3].Value.toString(), out int countInt) ? countInt : 0;
+                var unitName = worksheet.Cells[i, 4].Value.toString();
+                var baoJiaPrice = decimal.TryParse(worksheet.Cells[i, 5].Value.toString(), out decimal priceDecimal) ? priceDecimal : 0;
+                var baoJiaAllPrice = decimal.TryParse(worksheet.Cells[i, 6].Value.toString(), out decimal allPriceDecimal) ? allPriceDecimal : 0;
+                var costPriceAll = decimal.TryParse(worksheet.Cells[i, 7].Value.toString(), out decimal costPriceAllDecimal) ? costPriceAllDecimal : 0; //成本总价
+
+                var rowNo = i + 1;
+                if (count == 0) return Ok(JsonView(false, $"第{rowNo}行第4列单元格数据有误"));
+                if (baoJiaPrice == 0) return Ok(JsonView(false, $"第{rowNo}行第6列单元格数据有误"));
+                if (baoJiaAllPrice == 0) return Ok(JsonView(false, $"第{rowNo}行第7列单元格数据有误"));
+                if (costPriceAll == 0) return Ok(JsonView(false, $"第{rowNo}行第8列单元格数据有误"));
+
+                //计算系数
+                var costSinglePrice = costPriceAll / count; //单项成本
+                var costSinglePriceRate = baoJiaPrice / costSinglePrice; //系数
+
+                data.Add(new Grp_ConferenceAffairsCostChild
+                {
+                    Index = index,
+                    PriceType = typeDict.GetValueOrDefault(typeName, 0),
+                    PriceName = itemName,
+                    Count = count,
+                    Unit = unitDict.GetValueOrDefault(unitName, 0),
+                    CostPrice = costSinglePrice,
+                    Currency = 836, // 建议定义为常量或从配置读取
+                    Rate = costSinglePriceRate,
+                    AddedValue = 0,
+                    Details = "",
+                    ReviewStatus = 0,
+                    Imgs = "",
+                    Diid = groupId,
+                    ConferenceAffairsCostId = conferenceAffairsCostId,
+                    CreateTime = DateTime.Now,
+                    CreateUserId = userId,
+                    IsDel = 0,
+                    BaoJiaPrice = baoJiaPrice,
+                    Coefficient = costSinglePriceRate,
+                    Remark = string.Empty
+                });
+            }
+
+            var result = await _sqlSugar.Insertable(data).ExecuteCommandAsync();
+            if (result < 1) return Ok(JsonView(false, "数据插入失败!"));
+            return Ok(JsonView(true, "数据插入成功!", new { count = result }));
+        }
+
+
         /// <summary>
         /// 团组会务成本数据初始化
         /// </summary>

+ 124 - 0
OASystem/OASystem.Api/Controllers/PersonnelModuleController.cs

@@ -2998,6 +2998,130 @@ OPTION (MAXRECURSION 0); -- 允许无限递归      ";
             public string KaoqinAnswer { get; set; }
         }
 
+        /// <summary>
+        /// 查询时间范围内国交同事完成任务情况
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <param name="start"></param>
+        /// <param name="end"></param>
+        /// <param name="createUserId"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<IActionResult> AiPerformanceAnalysis_GuoJiaoAsync(int userId, DateTime start, DateTime end, int createUserId)
+        {
+            var jw = JsonView(false);
+
+            var user_entity = _sqlSugar.Queryable<Sys_Users>()
+            .First(e => e.Id == userId && e.IsDel == 0);
+
+            if (user_entity == null)
+            {
+                jw.Msg = "用户不存在!";
+                return Ok(jw);
+            }
+
+            if (user_entity.DepId != 7)
+            {
+                jw.Msg = "用户不属于国交部门!";
+                return Ok(jw);
+            }
+
+            var successList = await _sqlSugar.Queryable<Grp_ProcessNode>()
+            .LeftJoin<Grp_ProcessOverview>((x, y) => x.ProcessId == y.Id && y.IsDel == 0)
+            .LeftJoin<Grp_DelegationInfo>((x, y, z) => y.GroupId == z.Id && z.IsDel == 0)
+            .LeftJoin<Sys_Users>((x, y, z, u) => u.Id == x.Operator && u.IsDel == 0)
+            .Where(x => x.IsDel == 0 && x.OverallStatus == ProcessStatus.Completed)
+            .Where(x => x.OperationTime >= start && x.OperationTime <= end)
+            .Where(x => x.Operator == userId)
+            .Select((x, y, z, u) => new
+            {
+                x.NodeName,
+                x.NodeDescTips,
+                z.TeamName,
+                z.VisitDate,
+                z.SureTime,
+                u.CnName
+            })
+            .ToListAsync();
+
+            var setdataId = 1537;
+            var question = string.Empty;
+
+            try
+            {
+                var str = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == setdataId && x.IsDel == 0);
+                if (str != null && !string.IsNullOrEmpty(str.Remark))
+                {
+                    var stringFormatResp = await GeneralMethod.StringFormatAsync(new StringFormatDto
+                    {
+                        FormatTemplate = str.Remark,
+                        Parameters = new List<string> {
+                            JsonConvert.SerializeObject(successList),
+                            user_entity.CnName
+                        }
+                    });
+
+                    if (stringFormatResp.Success)
+                    {
+                        //日志
+                        _logger.LogInformation($"模板格式化成功,模板ID:{setdataId}, 时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
+                        question = stringFormatResp.FormattedResult;
+                    }
+                    else
+                    {
+                        _logger.LogError($"模板格式化失败,模板ID:{setdataId}, 时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, 错误:{stringFormatResp.Message}");
+                        jw.Msg = "模板格式化失败!" + stringFormatResp.Message;
+                        return Ok(jw);
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                jw.Msg = "模板格式化失败!" + ex.Message;
+                return Ok(jw);
+            }
+
+            var resp = await _deepSeekService.ChatAsync(question);
+            if (!resp.Success)
+            {
+                jw.Msg = "Ai分析用户绩效失败!" + resp.Message;
+                return Ok(jw);
+            }
+
+            var kaoqinResp = await GetKaoqinAnalysisAsync(user_entity, start, end, jw, "Ai分析用户考勤");
+            if (string.IsNullOrEmpty(kaoqinResp))
+            {
+                return Ok(jw);
+            }
+
+            jw.Data = new AiResponse()
+            {
+                Answer = resp.Answer,
+                KaoqinAnswer = kaoqinResp
+            };
+
+            //保存至数据库中
+            Pm_PerformanceAnalysis insertData = new Pm_PerformanceAnalysis
+            {
+                CreateTime = DateTime.Now,
+                CreateUserId = createUserId,
+                IsDel = 0,
+                Year = start.Year,
+                Month = start.Month,
+                JsonResult = JsonConvert.SerializeObject(jw.Data),
+                UserId = userId,
+                StartDate = start,
+                EndDate = end,
+            };
+
+            await _sqlSugar.Insertable(insertData).ExecuteCommandAsync();
+
+            jw.Code = 200;
+            jw.Msg = "操作成功!";
+
+            return Ok(jw);
+        }
+
         /// <summary>
         /// 全部门生成通用方法
         /// </summary>

+ 10 - 0
OASystem/OASystem.Domain/Dtos/Groups/ConferenceAffairsInIt.cs

@@ -8,6 +8,16 @@ using System.Threading.Tasks;
 
 namespace OASystem.Domain.Dtos.Groups
 {
+
+    public class MaterialCostsReadExcelDto
+    {
+        public IFormFile File { get; set; }
+        public int RowIndex { get; set; } = 1;
+        public int UserId { get; set; }
+        public int GroupId { get; set; }
+        public int ConferenceAffairsCostId { get; set; }
+
+    }
     public class ConferenceAffairsInItDto
     {
         public int UserId { get; set; }

+ 23 - 1
OASystem/OASystem.Infrastructure/Repositories/Resource/MaterialCostRepository.cs

@@ -100,13 +100,35 @@ namespace OASystem.Infrastructure.Repositories.Resource
             .FirstAsync();
         }
 
+
         /// <summary>
         /// 物料成本基础数据初始化
         /// </summary>
         /// <returns></returns>
         /// <exception cref="NotImplementedException"></exception>
-        public async Task<List<MaterialCostView>> MaterialCostsInSetDataIds()
+        public async Task<object> MaterialCostsInSetDataIds()
         {
+            var scaleItems = _sqlSugar.Queryable<Sys_SetData>()
+            .Where(it => it.IsDel == 0)
+            .Select(it => new { it.Id, it.Name }).ToList();
+
+            var cityItems = _sqlSugar.Queryable<Dis_City>()
+            .Where(it => it.IsDel == 0)
+            .Select(it => new { it.Id, it.CnName }).ToList();
+
+            var unitItems = _sqlSugar.Queryable<Sys_SetData>()
+            .Where(it => it.IsDel == 0)
+            .Select(it => new { it.Id, it.Name }).ToList();
+
+            var typeItems = _sqlSugar.Queryable<Sys_SetData>()
+            .Where(it => it.IsDel == 0)
+            .Select(it => new { it.Id, it.Name }).ToList();
+
+            var data = new
+            {
+
+            };
+
             throw new NotImplementedException();
         }
     }