|
@@ -16,7 +16,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 聚合Api 服务
|
|
/// 聚合Api 服务
|
|
/// </summary>
|
|
/// </summary>
|
|
- public class QiYeWeChatApiService: IQiYeWeChatApiService
|
|
|
|
|
|
+ public class QiYeWeChatApiService : IQiYeWeChatApiService
|
|
{
|
|
{
|
|
private readonly HttpClient _httpClient;
|
|
private readonly HttpClient _httpClient;
|
|
private readonly string CorpId = "wwe978bef5495a0728"; //企业Id
|
|
private readonly string CorpId = "wwe978bef5495a0728"; //企业Id
|
|
@@ -38,7 +38,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="clientFactory"></param>
|
|
/// <param name="clientFactory"></param>
|
|
/// <param name="jobPostRep"></param>
|
|
/// <param name="jobPostRep"></param>
|
|
- public QiYeWeChatApiService(IHttpClientFactory clientFactory, JobPostRepository jobPostRep)
|
|
|
|
|
|
+ public QiYeWeChatApiService(IHttpClientFactory clientFactory, JobPostRepository jobPostRep)
|
|
{
|
|
{
|
|
_httpClient = clientFactory.CreateClient("PublicQiYeWeChatApi"); ;
|
|
_httpClient = clientFactory.CreateClient("PublicQiYeWeChatApi"); ;
|
|
_jobPostRep = jobPostRep;
|
|
_jobPostRep = jobPostRep;
|
|
@@ -78,7 +78,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
}
|
|
}
|
|
else if (applicationType == 4) //通讯录同步
|
|
else if (applicationType == 4) //通讯录同步
|
|
{
|
|
{
|
|
- access_Token.corpsecret = AddressBook_Corpsecret;
|
|
|
|
|
|
+ access_Token.corpsecret = AddressBook_Corpsecret;
|
|
cacheName = "AddressBook_Access_Token";
|
|
cacheName = "AddressBook_Access_Token";
|
|
}
|
|
}
|
|
else if (applicationType == 5) //审批
|
|
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);
|
|
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);
|
|
var access_tokenReq = await _httpClient.GetAsync(access_token_url);
|
|
- if (access_tokenReq.IsSuccessStatusCode)
|
|
|
|
|
|
+ if (access_tokenReq.IsSuccessStatusCode)
|
|
{
|
|
{
|
|
var stringResponse = await access_tokenReq.Content.ReadAsStringAsync();
|
|
var stringResponse = await access_tokenReq.Content.ReadAsStringAsync();
|
|
|
|
|
|
@@ -330,7 +330,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
/// <param name="startDt"></param>
|
|
/// <param name="startDt"></param>
|
|
/// <param name="endDt"></param>
|
|
/// <param name="endDt"></param>
|
|
/// <returns></returns>
|
|
/// <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();
|
|
CheckInView checkInView = new CheckInView();
|
|
|
|
|
|
@@ -339,7 +339,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
if (userIdListView.errcode != 0)
|
|
if (userIdListView.errcode != 0)
|
|
{
|
|
{
|
|
checkInView.errcode = userIdListView.errcode;
|
|
checkInView.errcode = userIdListView.errcode;
|
|
- checkInView.errmsg = string.Format("【企业微信】【获取员工IdList】【Msg】{0}",userIdListView.errmsg);
|
|
|
|
|
|
+ checkInView.errmsg = string.Format("【企业微信】【获取员工IdList】【Msg】{0}", userIdListView.errmsg);
|
|
return checkInView;
|
|
return checkInView;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -362,7 +362,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
|
|
|
|
Checkin_MonthData_Request checkInReq = new Checkin_MonthData_Request();
|
|
Checkin_MonthData_Request checkInReq = new Checkin_MonthData_Request();
|
|
checkInReq.access_token = access_Token.access_token;
|
|
checkInReq.access_token = access_Token.access_token;
|
|
-
|
|
|
|
|
|
+
|
|
checkInReq.starttime = (uint)(startDt - _1970).TotalSeconds;
|
|
checkInReq.starttime = (uint)(startDt - _1970).TotalSeconds;
|
|
checkInReq.endtime = (uint)(endDt - _1970).TotalSeconds;
|
|
checkInReq.endtime = (uint)(endDt - _1970).TotalSeconds;
|
|
checkInReq.useridlist = userIdListView.dept_user.Select(it => it.userid).ToList();
|
|
checkInReq.useridlist = userIdListView.dept_user.Select(it => it.userid).ToList();
|
|
@@ -425,7 +425,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
uint starttimeOne, endtimeOne, starttimeTwo, endtimeTwo;
|
|
uint starttimeOne, endtimeOne, starttimeTwo, endtimeTwo;
|
|
int days = (int)(endDt - startDt).TotalDays;
|
|
int days = (int)(endDt - startDt).TotalDays;
|
|
|
|
|
|
- if (days > 32)
|
|
|
|
|
|
+ if (days > 32)
|
|
{
|
|
{
|
|
starttimeOne = (uint)((startDt.ToUniversalTime().Ticks - 621355968000000000) / 10000000);
|
|
starttimeOne = (uint)((startDt.ToUniversalTime().Ticks - 621355968000000000) / 10000000);
|
|
endtimeOne = (uint)((startDt.AddDays(31).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 startTs = (startDt.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
|
|
long endTs = (endDt.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,
|
|
access_token = access_Token.access_token,
|
|
useridlist = useridlist,
|
|
useridlist = useridlist,
|
|
@@ -840,7 +840,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
checkInDayDataView = System.Text.Json.JsonSerializer.Deserialize<CheckInDayDataView>(stringResponse,
|
|
checkInDayDataView = System.Text.Json.JsonSerializer.Deserialize<CheckInDayDataView>(stringResponse,
|
|
new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
|
|
new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
return checkInDayDataView;
|
|
return checkInDayDataView;
|
|
}
|
|
}
|
|
@@ -888,7 +888,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
|
|
|
|
int index = 0;
|
|
int index = 0;
|
|
//多次访问审批接口
|
|
//多次访问审批接口
|
|
- if (approvalDataView.total>=100)
|
|
|
|
|
|
+ if (approvalDataView.total >= 100)
|
|
{
|
|
{
|
|
approvalDataView.total -= 100;
|
|
approvalDataView.total -= 100;
|
|
int forTotal = approvalDataView.total % 100 == 0 ? approvalDataView.total / 100 : approvalDataView.total / 100 + 1;
|
|
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;
|
|
long? next_spnum = approvalDataView.next_spnum;
|
|
approvalDataReq.next_spnum = next_spnum;
|
|
approvalDataReq.next_spnum = next_spnum;
|
|
|
|
|
|
-
|
|
|
|
|
|
+
|
|
for (int i = 0; i < forTotal; i++)
|
|
for (int i = 0; i < forTotal; i++)
|
|
{
|
|
{
|
|
index++;
|
|
index++;
|
|
@@ -988,14 +988,14 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
ApprovalDataView approvalData_2 = await GetApprovalDataAsync(sp_centerDt, sp_endDt); //时间段内所有 审批数据
|
|
ApprovalDataView approvalData_2 = await GetApprovalDataAsync(sp_centerDt, sp_endDt); //时间段内所有 审批数据
|
|
if (approvalData_1.errcode != 0)
|
|
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;
|
|
return sp_Infos;
|
|
}
|
|
}
|
|
sp_Infos.AddRange(approvalData_1.data);
|
|
sp_Infos.AddRange(approvalData_1.data);
|
|
if (approvalData_2.errcode != 0)
|
|
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;
|
|
return sp_Infos;
|
|
}
|
|
}
|
|
@@ -1033,7 +1033,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
/// record_type - 审批单类型属性,1-请假;2-打卡补卡;3-出差;4-外出;5-加班; 6- 调班;7-会议室预定;8-退款审批;9-红包报销审批
|
|
/// record_type - 审批单类型属性,1-请假;2-打卡补卡;3-出差;4-外出;5-加班; 6- 调班;7-会议室预定;8-退款审批;9-红包报销审批
|
|
/// </param>
|
|
/// </param>
|
|
/// <returns></returns>
|
|
/// <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();
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
sw.Start();
|
|
@@ -1043,7 +1043,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
//获取所有打卡补卡,审批 数据 向前增加30天 向后范围增加15天
|
|
//获取所有打卡补卡,审批 数据 向前增加30天 向后范围增加15天
|
|
DateTime sp_startDt = startDt.AddDays(-30);
|
|
DateTime sp_startDt = startDt.AddDays(-30);
|
|
DateTime sp_endDt = endDt.AddDays(15);
|
|
DateTime sp_endDt = endDt.AddDays(15);
|
|
-
|
|
|
|
|
|
+
|
|
//获取审批数据 token
|
|
//获取审批数据 token
|
|
Access_TokenView access_Token = await GetTokenAsync(5);
|
|
Access_TokenView access_Token = await GetTokenAsync(5);
|
|
if (access_Token.errcode != 0)
|
|
if (access_Token.errcode != 0)
|
|
@@ -1068,7 +1068,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
int days = (sp_endDt - sp_startDt).Days;
|
|
int days = (sp_endDt - sp_startDt).Days;
|
|
decimal runCount = days % 30;
|
|
decimal runCount = days % 30;
|
|
int runCount1 = 0;
|
|
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);
|
|
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);
|
|
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,
|
|
access_token = access_Token.access_token,
|
|
sp_no = sp_no,
|
|
sp_no = sp_no,
|
|
};
|
|
};
|
|
@@ -1217,7 +1218,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
}
|
|
}
|
|
|
|
|
|
ApprovalInfoView approvalInfoView = new ApprovalInfoView();
|
|
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)
|
|
if (approvalInfoView.errcode != 0)
|
|
{
|
|
{
|
|
return details;
|
|
return details;
|
|
@@ -1232,7 +1233,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
Log.Error("【GetApprovalDetailsAsync】 record_type:" + record_type + " ErrorMsg:" + approvalDetailView.errmsg);
|
|
Log.Error("【GetApprovalDetailsAsync】 record_type:" + record_type + " ErrorMsg:" + approvalDetailView.errmsg);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
details.Add(approvalDetailView.info);
|
|
details.Add(approvalDetailView.info);
|
|
}
|
|
}
|
|
sw.Stop();
|
|
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);
|
|
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,
|
|
access_token = access_Token.access_token,
|
|
template_id = template_id,
|
|
template_id = template_id,
|
|
@@ -1284,8 +1285,38 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
public long ConvertToTimeSpan(DateTime dt)
|
|
public long ConvertToTimeSpan(DateTime dt)
|
|
- {
|
|
|
|
|
|
+ {
|
|
return (dt.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
|
|
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;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|