SGGL_SHJ/SGGL/BLL/ZHGL/RealName/SedinRealName.Service.cs

1011 lines
37 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace BLL
{
/// <summary>
/// 赛鼎实名制接口同步服务。
/// </summary>
public static class SedinRealNameService
{
private const string DataSourceName = "赛鼎宁波实名制";
private const string DefaultBaseUrl = "http://gd.17hr.net:8016";
private const string DefaultApiKey = "07c1cead689244be98809b80ec54d80c";
private const string DefaultApiSecret = "5fec0405962e4e66ac03840dc1cfe49d";
/// <summary>
/// 根据项目和同步配置构造赛鼎实名制请求参数。
/// 约定ApiUrl 存基础地址ClientId 存 api_keyPassword 存 api_secret。
/// xmjc 优先取实名制项目简称,其次取项目简称。
/// xmcode 优先取实名制项目编码,其次取合同号。
/// </summary>
/// <param name="projectId">本系统项目ID</param>
/// <param name="unitId">同步配置单位ID可为空</param>
/// <returns>接口请求参数</returns>
public static SedinRealNameOptions BuildOptionsByProject(string projectId, string unitId = null)
{
if (string.IsNullOrEmpty(projectId))
{
throw new ArgumentException("项目ID不能为空", nameof(projectId));
}
var project = Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId == projectId);
if (project == null)
{
throw new InvalidOperationException("未找到对应的项目配置");
}
string proCode = project.ContractNo;
var realNameProject = !string.IsNullOrEmpty(proCode)
? Funs.DB.RealName_Project.FirstOrDefault(x => x.ProCode == proCode)
: null;
string xmcode = realNameProject != null && !string.IsNullOrEmpty(realNameProject.JTproCode)
? realNameProject.JTproCode
: (realNameProject != null && !string.IsNullOrEmpty(realNameProject.ProCode) ? realNameProject.ProCode : proCode);
string xmjc = realNameProject != null && !string.IsNullOrEmpty(realNameProject.ProShortName)
? realNameProject.ProShortName
: (project.ShortName ?? project.ProjectName);
return new SedinRealNameOptions
{
ProjectId = projectId,
UnitId = unitId,
BaseUrl = DefaultBaseUrl,
Xmjc = xmjc,
Xmcode = xmcode,
ApiKey = DefaultApiKey,
ApiSecret = DefaultApiSecret,
};
}
/// <summary>
/// 按顺序同步参建单位、班组、人员、打卡记录。
/// </summary>
/// <param name="options">赛鼎实名制请求参数</param>
/// <param name="start">开始时间,传空则不限制</param>
/// <param name="end">结束时间,传空则不限制</param>
/// <returns>同步结果</returns>
public static SedinRealNameSyncResult SyncAll(SedinRealNameOptions options, string start = "", string end = "")
{
ValidateOptions(options);
var result = new SedinRealNameSyncResult
{
ProjectId = options.ProjectId,
};
var units = GetSubContractors(options, start, end);
var unitMap = SyncSubContractors(options.ProjectId, units);
result.SubContractorCount = unitMap.Count;
var teams = GetTeams(options, start, end);
var teamMap = SyncTeams(options.ProjectId, unitMap, teams);
result.TeamCount = teamMap.Count;
var persons = GetPersons(options, start, end);
result.PersonCount = SyncPersons(options.ProjectId, unitMap, teamMap, persons);
var checkIns = GetCheckIns(options, start, end);
result.CheckInCount = SyncCheckIns(options.ProjectId, checkIns);
result.LastStart = checkIns.LastStart;
result.Message = $"同步完成:参建单位 {result.SubContractorCount} 条,班组 {result.TeamCount} 条,人员 {result.PersonCount} 条,打卡记录 {result.CheckInCount} 条。";
return result;
}
/// <summary>
/// 获取参建单位。
/// </summary>
public static SedinApiListResult<SedinSubContractorDto> GetSubContractors(SedinRealNameOptions options, string start = "", string end = "")
{
return PostList<SedinSubContractorDto>(options, "/ApiService/SubContractorInfo.ashx", "获取参建单位", start, end);
}
/// <summary>
/// 获取班组信息。
/// </summary>
public static SedinApiListResult<SedinTeamDto> GetTeams(SedinRealNameOptions options, string start = "", string end = "")
{
return PostList<SedinTeamDto>(options, "/ApiService/TeamInfo.ashx", "获取班组信息", start, end);
}
/// <summary>
/// 获取人员信息。
/// </summary>
public static SedinApiListResult<SedinPersonDto> GetPersons(SedinRealNameOptions options, string start = "", string end = "")
{
return PostList<SedinPersonDto>(options, "/ApiService/GetUser.ashx", "获取人员信息", start, end);
}
/// <summary>
/// 获取打卡记录。
/// </summary>
public static SedinApiListResult<SedinCheckInDto> GetCheckIns(SedinRealNameOptions options, string start = "", string end = "")
{
return PostList<SedinCheckInDto>(options, "/ApiService/GetCockIn.ashx", "获取打卡记录", start, end);
}
/// <summary>
/// 同步参建单位到 Base_Unit / Project_ProjectUnit。
/// 返回值外部单位ID -> 本系统单位ID。
/// </summary>
public static Dictionary<string, string> SyncSubContractors(string projectId, SedinApiListResult<SedinSubContractorDto> result)
{
var unitMap = new Dictionary<string, string>();
if (result == null || result.Items == null || result.Items.Count == 0)
{
return unitMap;
}
foreach (var item in result.Items)
{
if (string.IsNullOrEmpty(item.FBDataID) || string.IsNullOrEmpty(item.Name))
{
continue;
}
var unit = Funs.DB.Base_Unit.FirstOrDefault(x => x.FromUnitId == item.FBDataID)
?? (!string.IsNullOrEmpty(item.OrgCode_XY) ? Funs.DB.Base_Unit.FirstOrDefault(x => x.CollCropCode == item.OrgCode_XY) : null)
?? Funs.DB.Base_Unit.FirstOrDefault(x => x.UnitName == item.Name);
if (unit == null)
{
unit = new Model.Base_Unit
{
UnitId = SQLHelper.GetNewID(typeof(Model.Base_Unit)),
UnitCode = !string.IsNullOrEmpty(item.OrgCode_XY) ? item.OrgCode_XY : item.FBDataID,
UnitName = item.Name,
ShortUnitName = item.ShortName,
Corporate = item.OrgOwner,
Address = FirstNotEmpty(item.Address, item.OrgAddress),
Telephone = item.FuZeRenPhone,
EMail = item.Email,
DataSources = DataSourceName,
FromUnitId = item.FBDataID,
CollCropCode = item.OrgCode_XY,
LinkName = item.FuZeRen,
IdcardNumber = item.OrgOwnerCode,
LinkMobile = item.FuZeRenPhone,
CollCropStatus = item.Status,
};
UnitService.AddUnit(unit);
unit = Funs.DB.Base_Unit.FirstOrDefault(x => x.UnitId == unit.UnitId);
}
else
{
unit.UnitCode = !string.IsNullOrEmpty(item.OrgCode_XY) ? item.OrgCode_XY : unit.UnitCode;
unit.UnitName = item.Name;
unit.ShortUnitName = item.ShortName;
unit.Corporate = item.OrgOwner;
unit.Address = FirstNotEmpty(item.Address, item.OrgAddress);
unit.Telephone = item.FuZeRenPhone;
unit.EMail = item.Email;
unit.DataSources = DataSourceName;
unit.FromUnitId = item.FBDataID;
unit.CollCropCode = item.OrgCode_XY;
unit.LinkName = item.FuZeRen;
unit.IdcardNumber = item.OrgOwnerCode;
unit.LinkMobile = item.FuZeRenPhone;
unit.CollCropStatus = item.Status;
Funs.DB.SubmitChanges();
}
if (unit == null)
{
continue;
}
unitMap[item.FBDataID] = unit.UnitId;
var projectUnit = ProjectUnitService.GetProjectUnitByUnitIdProjectId(projectId, unit.UnitId);
if (projectUnit == null)
{
ProjectUnitService.AddProjectUnit(new Model.Project_ProjectUnit
{
ProjectId = projectId,
UnitId = unit.UnitId,
UnitType = MapUnitType(item.FenBaoType),
InTime = ParseDateTime(item.RCDate),
OutTime = ParseDateTime(item.LCDate),
IsSynchro = true,
IsOutSideUnit = true,
});
}
else
{
projectUnit.UnitType = MapUnitType(item.FenBaoType);
projectUnit.InTime = ParseDateTime(item.RCDate);
projectUnit.OutTime = ParseDateTime(item.LCDate);
projectUnit.IsSynchro = true;
projectUnit.IsOutSideUnit = true;
ProjectUnitService.UpdateProjectUnit(projectUnit);
}
}
return unitMap;
}
/// <summary>
/// 同步班组到 ProjectData_TeamGroup。
/// 返回值外部班组ID -> 本系统班组ID。
/// </summary>
public static Dictionary<string, string> SyncTeams(string projectId, IDictionary<string, string> unitMap, SedinApiListResult<SedinTeamDto> result)
{
var teamMap = new Dictionary<string, string>();
if (result == null || result.Items == null || result.Items.Count == 0)
{
return teamMap;
}
foreach (var item in result.Items)
{
if (string.IsNullOrEmpty(item.BZDataID) || string.IsNullOrEmpty(item.Name))
{
continue;
}
string unitId = GetMappedValue(unitMap, item.FBDataID);
if (string.IsNullOrEmpty(unitId))
{
continue;
}
var team = Funs.DB.ProjectData_TeamGroup.FirstOrDefault(x => x.ProjectId == projectId && x.ThirdTeamCode == item.BZDataID)
?? Funs.DB.ProjectData_TeamGroup.FirstOrDefault(x => x.ProjectId == projectId && x.UnitId == unitId && x.TeamGroupName == item.Name);
if (team == null)
{
team = new Model.ProjectData_TeamGroup
{
TeamGroupId = SQLHelper.GetNewID(typeof(Model.ProjectData_TeamGroup)),
ProjectId = projectId,
UnitId = unitId,
TeamGroupCode = item.BZDataID,
TeamGroupName = item.Name,
ThirdTeamCode = item.BZDataID,
EntryTime = ParseDateTime(item.RCDate),
ExitTime = ParseDateTime(item.LCDate),
Remark = item.Remark,
};
TeamGroupService.AddTeamGroup(team);
team = Funs.DB.ProjectData_TeamGroup.FirstOrDefault(x => x.TeamGroupId == team.TeamGroupId);
}
else
{
team.UnitId = unitId;
team.TeamGroupCode = item.BZDataID;
team.TeamGroupName = item.Name;
team.ThirdTeamCode = item.BZDataID;
team.EntryTime = ParseDateTime(item.RCDate);
team.ExitTime = ParseDateTime(item.LCDate);
team.Remark = item.Remark;
Funs.DB.SubmitChanges();
}
if (team != null)
{
teamMap[item.BZDataID] = team.TeamGroupId;
}
}
return teamMap;
}
/// <summary>
/// 同步人员到 Person_Persons / SitePerson_Person。
/// </summary>
public static int SyncPersons(string projectId, IDictionary<string, string> unitMap, IDictionary<string, string> teamMap, SedinApiListResult<SedinPersonDto> result)
{
int count = 0;
if (result == null || result.Items == null || result.Items.Count == 0)
{
return count;
}
foreach (var item in result.Items)
{
if (string.IsNullOrEmpty(item.Shenfenzheng) || string.IsNullOrEmpty(item.Name))
{
continue;
}
string unitId = GetMappedValue(unitMap, item.FBDataID);
string teamGroupId = GetMappedValue(teamMap, item.BZDataID);
if (string.IsNullOrEmpty(unitId))
{
continue;
}
string workPostId = EnsureWorkPost(item.Zhicheng);
string personId = EnsurePerson(item, unitId, workPostId);
EnsureSitePerson(projectId, personId, unitId, teamGroupId, workPostId, item);
UpdateTeamLeaderByPerson(teamGroupId, personId, item.TeamWorkerType);
count++;
}
return count;
}
/// <summary>
/// 同步打卡记录到 SitePerson_PersonInOut。
/// </summary>
public static int SyncCheckIns(string projectId, SedinApiListResult<SedinCheckInDto> result)
{
int count = 0;
if (result == null || result.Items == null || result.Items.Count == 0)
{
return count;
}
foreach (var item in result.Items)
{
if (string.IsNullOrEmpty(item.Shenfenzheng))
{
continue;
}
DateTime? checkTime = ParseDateTime(item.CheckTime);
if (!checkTime.HasValue)
{
continue;
}
bool isIn = ParseIsIn(item.inout);
var sitePerson = SitePerson_PersonService.GetSitePersonByProjectIdIdentityCard(projectId, item.Shenfenzheng);
if (sitePerson == null || string.IsNullOrEmpty(sitePerson.PersonId))
{
continue;
}
var exists = PersonInOutService.GetPersonInOutByTimePersonId(sitePerson.PersonId, checkTime.Value, isIn);
if (exists != null)
{
continue;
}
PersonInOutService.AddPersonInOut(new Model.SitePerson_PersonInOut
{
ProjectId = projectId,
PersonId = sitePerson.PersonId,
IdentityCard = item.Shenfenzheng,
IsIn = isIn,
ChangeTime = checkTime,
InOutWay = Const.InOutWay_1,
OldID = item.machine_sn,
Address = item.MachineAlias,
Remark = "赛鼎实名制同步",
});
count++;
}
return count;
}
private static SedinApiListResult<T> PostList<T>(SedinRealNameOptions options, string path, string operationName, string start, string end)
{
ValidateOptions(options);
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
string token = BuildToken(options, timestamp);
string url = BuildRequestUrl(options.BaseUrl, path, token);
string body = JsonConvert.SerializeObject(new
{
xmjc = options.Xmjc,
xmcode = options.Xmcode,
start = start ?? string.Empty,
end = end ?? string.Empty,
});
string responseText = APIGetHttpService.OutsideHttp(url, "POST", "application/json;charset=utf-8", null, body);
var response = ParseResponse<T>(responseText);
SynchroSetService.InsertRealNamePushLog(options.ProjectId, options.Xmcode, operationName, response.Success ? "True" : "False", response.Code, response.Message, response.DataRaw, body);
if (!response.Success)
{
throw new InvalidOperationException($"{operationName}失败:{response.Message}");
}
return response;
}
private static SedinApiListResult<T> ParseResponse<T>(string responseText)
{
var result = new SedinApiListResult<T>
{
Raw = responseText,
};
if (string.IsNullOrWhiteSpace(responseText))
{
result.Success = false;
result.Message = "接口未返回任何内容";
return result;
}
JObject obj = JObject.Parse(responseText);
result.Code = FirstNotEmpty(obj["code"]?.ToString(), obj["success"]?.ToString());
result.Message = FirstNotEmpty(obj["msg"]?.ToString(), obj["message"]?.ToString());
result.LastStart = obj["laststart"]?.ToString();
result.Success = IsSuccess(obj["success"]);
result.DataRaw = obj["data"]?.ToString();
if (string.IsNullOrWhiteSpace(result.DataRaw))
{
result.Items = new List<T>();
return result;
}
JToken dataToken = obj["data"];
if (dataToken == null)
{
result.Items = new List<T>();
return result;
}
if (dataToken.Type == JTokenType.String)
{
string dataString = dataToken.ToString();
if (string.IsNullOrWhiteSpace(dataString))
{
result.Items = new List<T>();
}
else
{
result.Items = JsonConvert.DeserializeObject<List<T>>(dataString);
}
}
else if (dataToken.Type == JTokenType.Array)
{
result.Items = dataToken.ToObject<List<T>>();
}
else
{
result.Items = new List<T>();
}
if (result.Items == null)
{
result.Items = new List<T>();
}
return result;
}
private static string EnsurePerson(SedinPersonDto item, string unitId, string workPostId)
{
var person = Person_PersonsService.GetPerson_PersonsByIdCard(item.Shenfenzheng);
if (person == null)
{
person = new Model.Person_Persons
{
PersonId = SQLHelper.GetNewID(typeof(Model.Person_Persons)),
UnitId = unitId,
WorkPostId = workPostId,
PersonName = item.Name,
IdentityCard = item.Shenfenzheng,
IdcardType = "身份证",
Telephone = FirstNotEmpty(item.ShoujiHaoma, item.LianxiDianHua),
Sex = MapSex(item.Xingbie),
Birthday = ParseDateTime(item.ChushengRq),
Address = item.JiatingDz,
PhotoUrl = item.EmpPhoto,
PersonType = "3",
Email = item.Email,
IsPost = item.Status != "0",
IntoDate = ParseDateTime(item.RuzhiRq),
WorkDate = ParseDateTime(item.RuzhiRq),
DataFrom = DataSourceName,
OldDataId = FirstNotEmpty(item.Kaoqinhao, item.Shenfenzheng),
Major = item.Zhicheng,
};
Person_PersonsService.AddPerson(person);
return person.PersonId;
}
bool changed = false;
changed |= SetStringProperty(person.UnitId, unitId, v => person.UnitId = v);
changed |= SetStringProperty(person.WorkPostId, workPostId, v => person.WorkPostId = v);
changed |= SetStringProperty(person.PersonName, item.Name, v => person.PersonName = v);
changed |= SetStringProperty(person.IdentityCard, item.Shenfenzheng, v => person.IdentityCard = v);
changed |= SetStringProperty(person.Telephone, FirstNotEmpty(item.ShoujiHaoma, item.LianxiDianHua), v => person.Telephone = v);
changed |= SetStringProperty(person.Sex, MapSex(item.Xingbie), v => person.Sex = v);
changed |= SetStringProperty(person.Address, item.JiatingDz, v => person.Address = v);
changed |= SetStringProperty(person.PhotoUrl, item.EmpPhoto, v => person.PhotoUrl = v);
changed |= SetStringProperty(person.PersonType, "3", v => person.PersonType = v);
changed |= SetStringProperty(person.Email, item.Email, v => person.Email = v);
changed |= SetStringProperty(person.DataFrom, DataSourceName, v => person.DataFrom = v);
changed |= SetStringProperty(person.OldDataId, FirstNotEmpty(item.Kaoqinhao, item.Shenfenzheng), v => person.OldDataId = v);
changed |= SetStringProperty(person.Major, item.Zhicheng, v => person.Major = v);
changed |= SetDateProperty(person.Birthday, ParseDateTime(item.ChushengRq), v => person.Birthday = v);
changed |= SetDateProperty(person.IntoDate, ParseDateTime(item.RuzhiRq), v => person.IntoDate = v);
changed |= SetDateProperty(person.WorkDate, ParseDateTime(item.RuzhiRq), v => person.WorkDate = v);
bool isPost = item.Status != "0";
if (person.IsPost != isPost)
{
person.IsPost = isPost;
changed = true;
}
if (changed)
{
Person_PersonsService.UpdatePerson(person);
}
return person.PersonId;
}
private static void EnsureSitePerson(string projectId, string personId, string unitId, string teamGroupId, string workPostId, SedinPersonDto item)
{
var sitePerson = SitePerson_PersonService.GetSitePersonByProjectIdPersonId(projectId, personId)
?? SitePerson_PersonService.GetSitePersonByProjectIdIdentityCard(projectId, item.Shenfenzheng);
DateTime? inTime = ParseDateTime(item.RuzhiRq);
DateTime? outTime = ParseDateTime(item.LiZhiRq);
string states = item.Status == "0" ? Const.ProjectPersonStates_2 : Const.ProjectPersonStates_1;
if (sitePerson == null)
{
SitePerson_PersonService.AddSitePerson(new Model.SitePerson_Person
{
SitePersonId = SQLHelper.GetNewID(typeof(Model.SitePerson_Person)),
PersonId = personId,
CardNo = item.Kaoqinhao,
PersonName = item.Name,
UnitId = unitId,
IdentityCard = item.Shenfenzheng,
ProjectId = projectId,
TeamGroupId = teamGroupId,
WorkPostId = workPostId,
InTime = inTime ?? DateTime.Now,
OutTime = outTime,
States = states,
Remark = FirstNotEmpty(item.Memo, item.Zhicheng),
AuditorDate = DateTime.Now,
});
sitePerson = SitePerson_PersonService.GetSitePersonByProjectIdPersonId(projectId, personId);
}
else
{
sitePerson.PersonId = personId;
sitePerson.CardNo = item.Kaoqinhao;
sitePerson.PersonName = item.Name;
sitePerson.UnitId = unitId;
sitePerson.IdentityCard = item.Shenfenzheng;
sitePerson.ProjectId = projectId;
sitePerson.TeamGroupId = teamGroupId;
sitePerson.WorkPostId = workPostId;
sitePerson.InTime = inTime ?? sitePerson.InTime;
sitePerson.OutTime = outTime;
sitePerson.States = states;
sitePerson.Remark = FirstNotEmpty(item.Memo, item.Zhicheng);
if (!sitePerson.AuditorDate.HasValue)
{
sitePerson.AuditorDate = DateTime.Now;
}
SitePerson_PersonService.UpdateSitePerson(sitePerson, null);
}
if (sitePerson != null)
{
sitePerson.RealNameAddTime = sitePerson.RealNameAddTime ?? DateTime.Now;
sitePerson.RealNameUpdateTime = DateTime.Now;
Funs.DB.SubmitChanges();
}
}
private static void UpdateTeamLeaderByPerson(string teamGroupId, string personId, string teamWorkerType)
{
if (string.IsNullOrEmpty(teamGroupId) || teamWorkerType != "1")
{
return;
}
var team = TeamGroupService.GetTeamGroupById(teamGroupId);
if (team != null && team.GroupLeaderId != personId)
{
team.GroupLeaderId = personId;
TeamGroupService.UpdateTeamGroup(team);
}
}
private static string EnsureWorkPost(string workPostName)
{
if (string.IsNullOrWhiteSpace(workPostName))
{
workPostName = "其他";
}
var workPost = Funs.DB.Base_WorkPost.FirstOrDefault(x => x.WorkPostName == workPostName);
if (workPost != null)
{
return workPost.WorkPostId;
}
var newWorkPost = new Model.Base_WorkPost
{
WorkPostId = SQLHelper.GetNewID(typeof(Model.Base_WorkPost)),
WorkPostCode = workPostName,
WorkPostName = workPostName,
PostType = "3",
Remark = "赛鼎实名制同步",
};
WorkPostService.AddWorkPost(newWorkPost);
return newWorkPost.WorkPostId;
}
private static string MapUnitType(string unitTypeName)
{
if (string.IsNullOrWhiteSpace(unitTypeName))
{
return Const.ProjectUnitType_0;
}
if (unitTypeName.Contains("总承包"))
{
return Const.ProjectUnitType_1;
}
if (unitTypeName.Contains("劳务") || unitTypeName.Contains("专业分包") || unitTypeName.Contains("分包"))
{
return Const.ProjectUnitType_2;
}
if (unitTypeName.Contains("监理"))
{
return Const.ProjectUnitType_3;
}
if (unitTypeName.Contains("建设"))
{
return Const.ProjectUnitType_4;
}
if (unitTypeName.Contains("检测") || unitTypeName.Contains("监测"))
{
return Const.ProjectUnitType_5;
}
if (unitTypeName.Contains("供应"))
{
return Const.ProjectUnitType_6;
}
return Const.ProjectUnitType_0;
}
private static string MapSex(string sex)
{
return sex == "女" ? "2" : "1";
}
private static bool ParseIsIn(string inout)
{
return inout != "2";
}
private static string BuildRequestUrl(string baseUrl, string path, string token)
{
string url = NormalizeUrl(baseUrl) + path;
return $"{url}?token={Uri.EscapeDataString(token)}";
}
private static string NormalizeUrl(string baseUrl)
{
string url = (baseUrl ?? string.Empty).Trim().TrimEnd('/');
if (!url.StartsWith("http://", StringComparison.OrdinalIgnoreCase)
&& !url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
{
url = "http://" + url;
}
return url;
}
private static string BuildToken(SedinRealNameOptions options, string timestamp)
{
string raw = $"xmcode={options.Xmcode}&xmjc={options.Xmjc}&api_key_szzjt={options.ApiKey}&api_secret_szzjt={options.ApiSecret}&timestamp={timestamp}";
using (var md5 = MD5.Create())
{
byte[] bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(raw));
StringBuilder sb = new StringBuilder(bytes.Length * 2);
foreach (byte item in bytes)
{
sb.Append(item.ToString("x2"));
}
return sb.ToString();
}
}
private static bool IsSuccess(JToken token)
{
if (token == null)
{
return false;
}
string value = token.ToString().Trim();
return value == "0" || value.Equals("true", StringComparison.OrdinalIgnoreCase);
}
private static DateTime? ParseDateTime(string value)
{
if (string.IsNullOrWhiteSpace(value))
{
return null;
}
DateTime dateTime;
if (DateTime.TryParse(value, out dateTime))
{
return dateTime;
}
double oaValue;
if (double.TryParse(value, out oaValue) && oaValue > 0 && oaValue < 600000)
{
try
{
return DateTime.FromOADate(oaValue);
}
catch
{
return null;
}
}
return null;
}
private static void ValidateOptions(SedinRealNameOptions options)
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
if (string.IsNullOrWhiteSpace(options.ProjectId))
{
throw new InvalidOperationException("ProjectId 未配置");
}
if (string.IsNullOrWhiteSpace(options.BaseUrl))
{
throw new InvalidOperationException("赛鼎实名制接口地址未配置");
}
if (string.IsNullOrWhiteSpace(options.Xmjc))
{
throw new InvalidOperationException("项目简称 xmjc 未配置");
}
if (string.IsNullOrWhiteSpace(options.Xmcode))
{
throw new InvalidOperationException("项目编号 xmcode 未配置");
}
if (string.IsNullOrWhiteSpace(options.ApiKey))
{
throw new InvalidOperationException("api_key 未配置");
}
if (string.IsNullOrWhiteSpace(options.ApiSecret))
{
throw new InvalidOperationException("api_secret 未配置");
}
}
private static string GetMappedValue(IDictionary<string, string> map, string key)
{
if (map == null || string.IsNullOrEmpty(key))
{
return null;
}
string value;
return map.TryGetValue(key, out value) ? value : null;
}
private static string FirstNotEmpty(params string[] values)
{
return values.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x));
}
private static bool SetStringProperty(string currentValue, string newValue, Action<string> setter)
{
if (currentValue == newValue)
{
return false;
}
setter(newValue);
return true;
}
private static bool SetDateProperty(DateTime? currentValue, DateTime? newValue, Action<DateTime?> setter)
{
if (currentValue == newValue)
{
return false;
}
setter(newValue);
return true;
}
}
/// <summary>
/// 赛鼎实名制接口请求参数。
/// </summary>
public class SedinRealNameOptions
{
public string ProjectId { get; set; }
public string UnitId { get; set; }
public string BaseUrl { get; set; }
public string Xmjc { get; set; }
public string Xmcode { get; set; }
public string ApiKey { get; set; }
public string ApiSecret { get; set; }
}
/// <summary>
/// 赛鼎实名制同步结果。
/// </summary>
public class SedinRealNameSyncResult
{
public string ProjectId { get; set; }
public int SubContractorCount { get; set; }
public int TeamCount { get; set; }
public int PersonCount { get; set; }
public int CheckInCount { get; set; }
public string LastStart { get; set; }
public string Message { get; set; }
}
/// <summary>
/// 赛鼎实名制列表接口返回结果。
/// </summary>
public class SedinApiListResult<T>
{
public bool Success { get; set; }
public string Code { get; set; }
public string Message { get; set; }
public string LastStart { get; set; }
public string DataRaw { get; set; }
public string Raw { get; set; }
public List<T> Items { get; set; }
}
public class SedinSubContractorDto
{
public string XMDataID { get; set; }
public string FBDataID { get; set; }
public string Name { get; set; }
public string FuZeRen { get; set; }
public string FuZeRenPhone { get; set; }
public string Remark { get; set; }
public string OrgCode_XY { get; set; }
public string OrgAddress { get; set; }
public string OrgOwner { get; set; }
public string OrgOwnerCode { get; set; }
public string ModifyTime { get; set; }
public string Address { get; set; }
public string Email { get; set; }
public string FenBaoType { get; set; }
public string ShortName { get; set; }
public string RCDate { get; set; }
public string LCDate { get; set; }
public string Status { get; set; }
}
public class SedinTeamDto
{
public string XMDataID { get; set; }
public string FBDataID { get; set; }
public string BZDataID { get; set; }
public string Name { get; set; }
public string Remark { get; set; }
public string ModifyTime { get; set; }
public string RCDate { get; set; }
public string LCDate { get; set; }
public string Status { get; set; }
}
public class SedinPersonDto
{
public string XMDataID { get; set; }
public string FBDataID { get; set; }
public string BZDataID { get; set; }
public string Kaoqinhao { get; set; }
public string Name { get; set; }
public string Zhicheng { get; set; }
public string Shenfenzheng { get; set; }
public string ChushengRq { get; set; }
public string Xingbie { get; set; }
public string Jiguan { get; set; }
public string Mingzu { get; set; }
public string Xueli { get; set; }
public string RuzhiRq { get; set; }
public string LiZhiRq { get; set; }
public string Email { get; set; }
public string LianxiDianHua { get; set; }
public string ShoujiHaoma { get; set; }
public string JiatingDz { get; set; }
public string IsBlack { get; set; }
public string Status { get; set; }
public string Memo { get; set; }
public string TeamWorkerType { get; set; }
public string EmpPhoto { get; set; }
}
public class SedinCheckInDto
{
public string Shenfenzheng { get; set; }
public string Name { get; set; }
public string MachineAlias { get; set; }
public string machine_sn { get; set; }
public string CheckTime { get; set; }
public string inout { get; set; }
public string AddTime { get; set; }
}
}