using ConsoleApp1.Controller.CY_API;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1.Controller.DDing_API
{
public class InTheMiddle
{
private DingdingAPI Ding = new DingdingAPI();
private CY_NC_Api _cy = new CY_NC_Api();
private string employee = "";
///
/// 更新智能人事花名册信息
///
///
public string smartworks(Dictionary dic)
{
string token = Ding.dttoken();
//string agentid = Ding.get_auth_info();
string smartwork = Ding.smartwork(token);
if (dic.LongCount() == 4)
{
employee = Ding.employee(dic);
}
else if (dic.LongCount() == 5)
{
employee = Ding.The_Contract(dic);
}
return employee;
}
///
/// 获取员工信息并更新至氚云
///
///
public string Update_smartwork()
{
try
{
string access_token = Ding.dttoken();
//if (string.IsNullOrEmpty(access_token))
//{
access_token = Ding.dttoken();
//}
int offset = 0, size = 50; string userid_list; int next_cursor;
//string field_filter_list = "sys00-name, sys00-mainDeptId, sys00-mainDept,sys05-nowContractStartTime, sys05-nowContractEndTime, sys00-position, sys00-confirmJoinTime, sys01-positionLevel,sys05-contractPeriodType, sys05-contractRenewCount, userid";
do
{
string queryonjob = Ding.smartwork_smartwork(access_token, "2,3,5,-1", offset, size);
JObject json = JsonConvert.DeserializeObject(queryonjob.ToString());
next_cursor = json["result"]["data_list"].Count();
//next_cursor = json["result"]["next_cursor"].ToString()!= null || json["result"]["next_cursor"].ToString() != "" ? Convert.ToInt32(json["result"]["next_cursor"]) : 0;
userid_list = json["result"]["data_list"].ToString().Replace("[", "").Replace("\"", "").Replace("]", "").Trim();
//string value1 = Ding.listemployee(userid_list);
string value = Ding.smartwork_list(access_token, userid_list, null);
JObject json1 = JsonConvert.DeserializeObject(value);
foreach (var item in json1["result"])
{
JObject json2 = JsonConvert.DeserializeObject(item.ToString());
_cy.employee(json2);
_cy.Basic(json2);
}
offset = offset + size;
} while (next_cursor >= 50);
return "OK";
}
catch (Exception ex)
{
throw ex;
}
}
}
}