yuanrf hai 4 meses
pai
achega
7b4bbb5703

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

@@ -2301,6 +2301,26 @@ OPTION (MAXRECURSION 0); -- 允许无限递归      ";
             return Ok(jw);
         }
 
+
+        [HttpPost]
+        public IActionResult QueryAssessmentByUser(QueryAssessmentByUser Dto)
+        {
+            var jw = JsonView(false);
+            var user_entity = _sqlSugar.Queryable<Sys_Users>()
+                              .First(e => e.Id == Dto.UserId && e.IsDel == 0);
+
+            jw.Msg = "用户企业微信Id未绑定!";
+            if (user_entity != null && !string.IsNullOrEmpty(user_entity.QiyeChatUserId))
+            {
+                var data = _qiYeWeChatApiService.QueryAssessmentByUser(Dto.Start, Dto.End, new List<string> { user_entity.QiyeChatUserId });
+                jw.Data = data;
+                jw.Msg = "查询成功!";
+                jw.Code = 200;
+            }
+
+            return Ok(jw);
+        }
+
         #endregion
     }
 }

+ 10 - 0
OASystem/OASystem.Api/OAMethodLib/QiYeWeChatAPI/IQiYeWeChatApiService.cs

@@ -62,6 +62,16 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
         /// <returns></returns>
         Task<CheckInView> GetCheckin_MonthDataAsync1(DateTime startDt, DateTime endDt);
 
+        /// <summary>
+        /// 获取用户考核打卡记录
+        /// </summary>
+        /// <param name="startDt"></param>
+        /// <param name="endDt"></param>
+        /// <param name="qiyeUid"></param>
+        /// <returns></returns>
+
+        Task<object> QueryAssessmentByUser(DateTime startDt, DateTime endDt, List<string> qiyeUidList);
+
         /// <summary>
         /// 获取月打卡数据 Redis
         /// </summary>

+ 122 - 2
OASystem/OASystem.Api/OAMethodLib/QiYeWeChatAPI/QiYeWeChatApiService.cs

@@ -1,4 +1,5 @@
-using OASystem.Domain.Dtos.QiYeWeChat;
+using EyeSoft.Extensions;
+using OASystem.Domain.Dtos.QiYeWeChat;
 using OASystem.Domain.ViewModels.QiYeWeChat;
 using System.Diagnostics;
 using System.Text.Json;
@@ -669,6 +670,125 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
             return checkInView;
         }
 
+        public async Task<object> QueryAssessmentByUser(DateTime startDt, DateTime endDt, List<string> qiyeUidList)
+        {
+            AssessmentByUserListView assessmentByUserListView = new AssessmentByUserListView();
+            List<AssessmentByUserView> AssessmentByUserView = new  List<AssessmentByUserView>();
+            assessmentByUserListView.Data = AssessmentByUserView;
+            assessmentByUserListView.errcode = 0;  
+            assessmentByUserListView.errmsg = "成功";
+
+            CheckInView? checkInView = new CheckInView();
+
+            //获取打卡数据 token
+            Access_TokenView access_Token = await GetTokenAsync(2);
+            if (access_Token.errcode != 0)
+            {
+                assessmentByUserListView.errcode = access_Token.errcode;
+                assessmentByUserListView.errmsg = string.Format("【企业微信】【获取月打卡数据】【Token】【Msg】{0}", access_Token.errmsg);
+                return assessmentByUserListView;
+            }
+
+            string url = string.Format("/cgi-bin/checkin/getcheckin_monthdata?access_token={0}", access_Token.access_token);
+
+            Checkin_MonthData_Request checkInReq = new Checkin_MonthData_Request();
+            checkInReq.access_token = access_Token.access_token;
+
+            checkInReq.starttime = (uint)(startDt - _1970).TotalSeconds;
+            checkInReq.endtime = (uint)(endDt - _1970).TotalSeconds;
+            checkInReq.useridlist = qiyeUidList;
+
+            var json = System.Text.Json.JsonSerializer.Serialize(checkInReq);
+            var content = new StringContent(json, Encoding.UTF8, "application/json");
+            var create_Req = await _httpClient.PostAsync(url, content);
+            var stringResponse = await create_Req.Content.ReadAsStringAsync();
+
+            checkInView = System.Text.Json.JsonSerializer.Deserialize<CheckInView>(stringResponse,
+                new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
+
+            if (checkInView == null)
+            {
+                assessmentByUserListView.errcode = -1;
+                assessmentByUserListView.errmsg = "checkInView Deserialize Error";
+                return assessmentByUserListView;
+            }
+
+            if (checkInView.errcode != 0)
+            {
+                assessmentByUserListView.errcode = checkInView.errcode;
+                assessmentByUserListView.errmsg = checkInView.errmsg;
+                return assessmentByUserListView;
+            }
+
+            var errorUserList = new List<string>();
+
+            //遍历用户数据
+            foreach (var item in checkInView.datas)
+            {
+
+                //有异常状态的情况下获取具体异常信息
+                if (item.summary_info.except_days > 0)
+                {
+                    errorUserList.Add(item.base_info.acctid);
+                }
+
+                assessmentByUserListView.Data.Add(new Domain.ViewModels.QiYeWeChat.AssessmentByUserView
+                {
+                    Accid = item.base_info.acctid,
+                    Except_days = item.summary_info.except_days,
+                    Name = item.base_info.name,
+                    Regular_days = item.summary_info.regular_days,
+                    Exception_info_List = new List<Exception_info>(),
+                });
+            }
+
+            if (errorUserList.Count > 0) {
+
+                var dayInfo = await GetCheckinDataAsync(errorUserList, 3, startDt, endDt);
+
+                if (dayInfo.errcode != 0)
+                {
+                    assessmentByUserListView.errcode = dayInfo.errcode;
+                    assessmentByUserListView.errmsg = dayInfo.errmsg;
+                    assessmentByUserListView.Data = new List<AssessmentByUserView>();
+                    return assessmentByUserListView;
+                }
+
+                var dic = new Dictionary<ErrorType, List<string>>()
+                {
+                    { ErrorType.迟到 , new List<string>{ "时间异常" } },
+                    { ErrorType.缺卡 , new List<string>{ "未打卡" } },
+                };
+
+                foreach (var item in dayInfo.checkindata)
+                {
+                    foreach (var user in assessmentByUserListView.Data)
+                    {
+                        if (user.Accid == item.userid)
+                        {
+                            //遍历异常信息
+                            if (!item.exception_type.IsNullOrWhiteSpace())
+                            {
+                                var linqFind = dic.First(x => x.Value.Contains(item.exception_type));
+
+                                var errinfo =  new Exception_info
+                                {
+                                    Date = item.checkin_time_dt,
+                                    Type = linqFind.Key,
+                                    Info = item.exception_type
+                                };
+
+                                user.Exception_info_List.Add(errinfo);
+                            }
+                        }
+                    }
+                }
+
+            }
+
+            return assessmentByUserListView;
+        }
+
         /// <summary>
         /// 获取打卡记录数据
         /// </summary>
@@ -1561,6 +1681,6 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
             return (dt.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
         }
 
-
+       
     }
 }

+ 8 - 0
OASystem/OASystem.Domain/Dtos/PersonnelModule/TreeNode.cs

@@ -169,4 +169,12 @@ namespace OASystem.Domain.Dtos.PersonnelModule
 
         public string SearchValue { get; set; }
     }
+
+    public class QueryAssessmentByUser
+    {
+        public int UserId { get; set; }
+
+        public DateTime Start { get; set; }
+        public DateTime End { get; set; }
+    }
 }

+ 38 - 0
OASystem/OASystem.Domain/ViewModels/QiYeWeChat/CheckInView.cs

@@ -296,4 +296,42 @@ namespace OASystem.Domain.ViewModels.QiYeWeChat
         /// </summary>
         public int? restdays_over_sec { get; set; }
     }
+
+    public class AssessmentByUserListView : ResponseBase
+    {
+        public List<AssessmentByUserView> Data { get; set; }
+    }
+
+    public class AssessmentByUserView
+    {
+        public string Name { get; set; }
+
+        public string Accid { get; set; }
+
+        public int Regular_days { get; set; }
+
+        public int Except_days { get; set; }
+
+        public List<Exception_info> Exception_info_List { get; set; }
+
+    }
+
+    public class Exception_info
+    {
+        public ErrorType Type { get; set; }
+
+        public DateTime Date { get; set; }
+
+        public string Info { get; set; }
+    }
+
+    public enum ErrorType
+    {
+        迟到 = 1, // 迟到
+        早退 = 2, // 早退
+        缺卡 = 3, // 缺卡
+        旷工 = 4, // 旷工
+        地点异常 = 5, // 地点异常
+        设备异常 = 6 // 设备异常
+    }
 }