Pārlūkot izejas kodu

团组操作- Jietuanoperator 实际值改为CreateUserId

jiangjc 10 mēneši atpakaļ
vecāks
revīzija
8480bf0ad4

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

@@ -138,5 +138,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
         /// <param name="spNo">审批No</param>
         /// <returns></returns>
         Task<ApprovalDetailView> GetApprovalDetailAsync(string spNo);
+
+        Task<ResponseBase> RobotSendMsg_GroupInfo(string msg);
     }
 }

+ 53 - 22
OASystem/OASystem.Api/OAMethodLib/QiYeWeChatAPI/QiYeWeChatApiService.cs

@@ -16,7 +16,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
     /// <summary>
     /// 聚合Api 服务
     /// </summary>
-    public class QiYeWeChatApiService: IQiYeWeChatApiService
+    public class QiYeWeChatApiService : IQiYeWeChatApiService
     {
         private readonly HttpClient _httpClient;
         private readonly string CorpId = "wwe978bef5495a0728";   //企业Id
@@ -38,7 +38,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
         /// </summary>
         /// <param name="clientFactory"></param>
         /// <param name="jobPostRep"></param>
-        public QiYeWeChatApiService(IHttpClientFactory clientFactory, JobPostRepository jobPostRep) 
+        public QiYeWeChatApiService(IHttpClientFactory clientFactory, JobPostRepository jobPostRep)
         {
             _httpClient = clientFactory.CreateClient("PublicQiYeWeChatApi"); ;
             _jobPostRep = jobPostRep;
@@ -78,7 +78,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
             }
             else if (applicationType == 4)       //通讯录同步
             {
-                access_Token.corpsecret = AddressBook_Corpsecret; 
+                access_Token.corpsecret = AddressBook_Corpsecret;
                 cacheName = "AddressBook_Access_Token";
             }
             else if (applicationType == 5) //审批
@@ -102,7 +102,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
                 string access_token_url = string.Format(@"/cgi-bin/gettoken?corpid={0}&corpsecret={1}", access_Token.corpid, access_Token.corpsecret);
 
                 var access_tokenReq = await _httpClient.GetAsync(access_token_url);
-                if (access_tokenReq.IsSuccessStatusCode) 
+                if (access_tokenReq.IsSuccessStatusCode)
                 {
                     var stringResponse = await access_tokenReq.Content.ReadAsStringAsync();
 
@@ -330,7 +330,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
         /// <param name="startDt"></param>
         /// <param name="endDt"></param>
         /// <returns></returns>
-        public async Task<CheckInView> GetCheckin_MonthDataAsync1(DateTime startDt,DateTime endDt)
+        public async Task<CheckInView> GetCheckin_MonthDataAsync1(DateTime startDt, DateTime endDt)
         {
             CheckInView checkInView = new CheckInView();
 
@@ -339,7 +339,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
             if (userIdListView.errcode != 0)
             {
                 checkInView.errcode = userIdListView.errcode;
-                checkInView.errmsg = string.Format("【企业微信】【获取员工IdList】【Msg】{0}",userIdListView.errmsg);
+                checkInView.errmsg = string.Format("【企业微信】【获取员工IdList】【Msg】{0}", userIdListView.errmsg);
                 return checkInView;
             }
 
@@ -362,7 +362,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
 
             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 = userIdListView.dept_user.Select(it => it.userid).ToList();
@@ -425,7 +425,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
             uint starttimeOne, endtimeOne, starttimeTwo, endtimeTwo;
             int days = (int)(endDt - startDt).TotalDays;
 
-            if (days > 32) 
+            if (days > 32)
             {
                 starttimeOne = (uint)((startDt.ToUniversalTime().Ticks - 621355968000000000) / 10000000);
                 endtimeOne = (uint)((startDt.AddDays(31).ToUniversalTime().Ticks - 621355968000000000) / 10000000);
@@ -718,7 +718,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
             long startTs = (startDt.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
             long endTs = (endDt.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
 
-            var checkInData_Req = new 
+            var checkInData_Req = new
             {
                 access_token = access_Token.access_token,
                 useridlist = useridlist,
@@ -840,7 +840,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
                 checkInDayDataView = System.Text.Json.JsonSerializer.Deserialize<CheckInDayDataView>(stringResponse,
                     new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
             }
-            
+
 
             return checkInDayDataView;
         }
@@ -888,7 +888,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
 
             int index = 0;
             //多次访问审批接口
-            if (approvalDataView.total>=100)
+            if (approvalDataView.total >= 100)
             {
                 approvalDataView.total -= 100;
                 int forTotal = approvalDataView.total % 100 == 0 ? approvalDataView.total / 100 : approvalDataView.total / 100 + 1;
@@ -896,7 +896,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
                 long? next_spnum = approvalDataView.next_spnum;
                 approvalDataReq.next_spnum = next_spnum;
 
-                
+
                 for (int i = 0; i < forTotal; i++)
                 {
                     index++;
@@ -988,14 +988,14 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
                 ApprovalDataView approvalData_2 = await GetApprovalDataAsync(sp_centerDt, sp_endDt);    //时间段内所有 审批数据
                 if (approvalData_1.errcode != 0)
                 {
-                    Log.Error("企业微信 获取 "+ sp_startDt + " - "+ sp_centerDt + " 内审批 Msg:" + approvalData_1.errmsg);
+                    Log.Error("企业微信 获取 " + sp_startDt + " - " + sp_centerDt + " 内审批 Msg:" + approvalData_1.errmsg);
 
                     return sp_Infos;
                 }
                 sp_Infos.AddRange(approvalData_1.data);
                 if (approvalData_2.errcode != 0)
                 {
-                    Log.Error("企业微信 获取 "+ sp_centerDt + " - "+ sp_endDt + " 内审批 Msg:" + approvalData_2.errmsg);
+                    Log.Error("企业微信 获取 " + sp_centerDt + " - " + sp_endDt + " 内审批 Msg:" + approvalData_2.errmsg);
 
                     return sp_Infos;
                 }
@@ -1033,7 +1033,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
         /// record_type - 审批单类型属性,1-请假;2-打卡补卡;3-出差;4-外出;5-加班; 6- 调班;7-会议室预定;8-退款审批;9-红包报销审批
         /// </param>
         /// <returns></returns>
-        private async Task<ApprovalInfoView> GetApprovalInfoAsync(DateTime startDt,DateTime endDt,string creator, int sp_status, int record_type)
+        private async Task<ApprovalInfoView> GetApprovalInfoAsync(DateTime startDt, DateTime endDt, string creator, int sp_status, int record_type)
         {
             Stopwatch sw = new Stopwatch();
             sw.Start();
@@ -1043,7 +1043,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
             //获取所有打卡补卡,审批 数据 向前增加30天 向后范围增加15天
             DateTime sp_startDt = startDt.AddDays(-30);
             DateTime sp_endDt = endDt.AddDays(15);
-            
+
             //获取审批数据 token
             Access_TokenView access_Token = await GetTokenAsync(5);
             if (access_Token.errcode != 0)
@@ -1068,7 +1068,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
             int days = (sp_endDt - sp_startDt).Days;
             decimal runCount = days % 30;
             int runCount1 = 0;
-            if (runCount == 0) runCount1 =(int)(days % 30.00M);
+            if (runCount == 0) runCount1 = (int)(days % 30.00M);
             else runCount1 = (int)Math.Ceiling(days / 30.00M);
 
 
@@ -1173,7 +1173,8 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
 
             string url = string.Format("/cgi-bin/oa/getapprovaldetail?access_token={0}", access_Token.access_token);
 
-            ApprovalDetail_Request approvalDetail_Req = new ApprovalDetail_Request() {
+            ApprovalDetail_Request approvalDetail_Req = new ApprovalDetail_Request()
+            {
                 access_token = access_Token.access_token,
                 sp_no = sp_no,
             };
@@ -1217,7 +1218,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
             }
 
             ApprovalInfoView approvalInfoView = new ApprovalInfoView();
-            approvalInfoView = await GetApprovalInfoAsync(startDt,endDt, creator,sp_status, record_type);
+            approvalInfoView = await GetApprovalInfoAsync(startDt, endDt, creator, sp_status, record_type);
             if (approvalInfoView.errcode != 0)
             {
                 return details;
@@ -1232,7 +1233,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
                     Log.Error("【GetApprovalDetailsAsync】 record_type:" + record_type + " ErrorMsg:" + approvalDetailView.errmsg);
                     break;
                 }
-                
+
                 details.Add(approvalDetailView.info);
             }
             sw.Stop();
@@ -1265,7 +1266,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
 
             string url = string.Format("/cgi-bin/oa/gettemplatedetail?access_token={0}", access_Token.access_token);
 
-            var approvalDetail_Req = new 
+            var approvalDetail_Req = new
             {
                 access_token = access_Token.access_token,
                 template_id = template_id,
@@ -1284,8 +1285,38 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
         #endregion
 
         public long ConvertToTimeSpan(DateTime dt)
-        { 
+        {
             return (dt.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
         }
+
+        /// <summary>
+        /// 发送团组信息给财务群
+        /// </summary>
+        /// <param name="msg"></param>
+        /// <returns></returns>
+        /// <exception cref="NotImplementedException"></exception>
+        public async Task<ResponseBase> RobotSendMsg_GroupInfo(string msg)
+        {
+            string key = "b4fe152f-a97a-48b1-830f-ab447f6d2f5f";
+            string url = string.Format("/webhook/send?key={0}", key);
+
+            RobotSendMsg_GroupInfo_Content contentStr = new RobotSendMsg_GroupInfo_Content() { content = msg };
+
+            RobotSendMsg_GroupInfo reqJson = new RobotSendMsg_GroupInfo()
+            {
+                msgtype = "markdown",
+                markdown = contentStr
+            };
+
+            var json = System.Text.Json.JsonSerializer.Serialize(RobotSendMsg_GroupInfo);
+            var content = new StringContent(json, Encoding.UTF8, "application/json");
+            var create_Req = await _httpClient.PostAsync(url, content);
+            var stringResponse = await create_Req.Content.ReadAsStringAsync();
+
+            ResponseBase sendMsgView = System.Text.Json.JsonSerializer.Deserialize<ResponseBase>(stringResponse,
+                new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
+
+            return sendMsgView;
+        }
     }
 }

+ 36 - 0
OASystem/OASystem.Api/OAMethodLib/Quartz/Business/DeleReminderMessage.cs

@@ -83,6 +83,42 @@ namespace OASystem.API.OAMethodLib.Quartz.Business
             }
         }
 
+        /// <summary>
+        /// 企业微信发送消息
+        /// </summary>
+        public static async void PostMessageByWebhook()
+        {
+            DateTime dtNow = DateTime.Now;
+            string add2day = dtNow.AddDays(3).ToString("yyyy-MM-dd"); //结束出访前3天
+            string add7day = dtNow.AddDays(7).ToString("yyyy-MM-dd"); //开始出访前1周
+
+            string sql = string.Format(@" Select * From Grp_DelegationInfo With(Nolock) Where IsDel=0 And VisitEndDate ='{0}' Or VisitStartDate='{1}' ", add2day, add7day);
+            List<Grp_DelegationInfo> list_source = _grpDeleRep._sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
+
+            if (list_source.Count > 0)
+            {
+                List<Grp_DelegationInfo> listAdd7day = list_source.Where(s => s.VisitStartDate.Equals(add7day)).ToList();
+                List<Grp_DelegationInfo> listAdd2day = list_source.Where(s => s.VisitEndDate.Equals(add2day)).ToList();
+                string dayStr = dtNow.ToString("yyyy年MM月dd日");
+                string content = string.Format(@" 今天是{0},\n ");
+
+                if (listAdd7day.Count > 0)
+                {
+                    
+                    string tempStr1 = string.Format(@" 检查到7天后开始的团组数量: <font color='warning'>{1}</font>\n ", dayStr,listAdd7day.Count);
+                    listAdd7day.ForEach(s => tempStr1 += string.Format(@"> {0}", s.TeamName));
+                    content += tempStr1;
+                }
 
+                if (listAdd2day.Count > 0)
+                {
+                    string tempStr2 = string.Format(@" 检查到3天后结束的团组数量: <font color='warning'>{1}</font>\n ", dayStr, listAdd2day.Count);
+                    listAdd7day.ForEach(s => tempStr2 += string.Format(@"> {0}", s.TeamName));
+                    content += tempStr2;
+                }
+
+                content += string.Format(@"");
+            }
+        }
     }
 }

+ 16 - 0
OASystem/OASystem.Domain/Dtos/QiYeWeChat/ApprovalData_Request.cs

@@ -107,4 +107,20 @@ namespace OASystem.Domain.Dtos.QiYeWeChat
         public string sp_no { get; set; }
 
     }
+
+    public class RobotSendMsg_GroupInfo
+    {
+        public string msgtype { get; set; } = "markdown";
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public RobotSendMsg_GroupInfo_Content markdown { get; set; }
+
+    }
+
+    public class RobotSendMsg_GroupInfo_Content
+    {
+        public string content { get; set; }
+    }
 }

+ 4 - 4
OASystem/OASystem.Infrastructure/Repositories/Groups/DelegationInfoRepository.cs

@@ -248,14 +248,14 @@ namespace OASystem.Infrastructure.Repositories.Groups
 	                                        From  Grp_DelegationInfo gdi
 	                                        Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id 
 	                                        Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
-	                                        Left Join Sys_Users su On gdi.JietuanOperator = su.Id
+	                                        Left Join Sys_Users su On gdi.CreateUserId = su.Id
 	                                        Where gdi.IsDel = 0 
                                         )temp Where RowNumber Between {0} and {1}", startIndex, endIndex);
 
                 string sqlCount = string.Format(@"Select Count(1) as Count From  Grp_DelegationInfo gdi
 	                                        Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id 
 	                                        Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
-	                                        Left Join Sys_Users su On gdi.JietuanOperator = su.Id
+	                                        Left Join Sys_Users su On gdi.CreateUserId = su.Id
 	                                        Where gdi.IsDel = 0  ");
 
                 List<DelegationPageListView> _DeleInfoList = await _sqlSugar.SqlQueryable<DelegationPageListView>(sql).ToListAsync();
@@ -298,7 +298,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
 				  From  Grp_DelegationInfo gdi
                   Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id 
                   Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
-                  Left Join Sys_Users su On gdi.JietuanOperator = su.Id
+                  Left Join Sys_Users su On gdi.CreateUserId = su.Id
 				  left Join Grp_Schedule gs On gdi.Id = gs.DiId
                   Where gdi.IsDel = 0 
                   Order By gdi.CreateTime Desc");
@@ -322,7 +322,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
                   From  Grp_DelegationInfo gdi
                   Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id 
                   Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
-                  Left Join Sys_Users su On gdi.JietuanOperator = su.Id
+                  Left Join Sys_Users su On gdi.CreateUserId = su.Id
                   Where gdi.IsDel = 0 
                   Order By gdi.CreateTime Desc");