198 lines
7.9 KiB
C#
198 lines
7.9 KiB
C#
using MyCode.Project.Domain.Message.Request.User;
|
|
using MyCode.Project.Domain.Message.Response.EnterpriseWechat;
|
|
using MyCode.Project.Domain.Message.Response.Wechat;
|
|
using MyCode.Project.Domain.Model;
|
|
using MyCode.Project.Domain.Repositories;
|
|
using MyCode.Project.Infrastructure.Common;
|
|
using MyCode.Project.Infrastructure.WebPost;
|
|
using MyCode.Project.OutSideService;
|
|
using MyCode.Project.Repositories;
|
|
using Senparc.CO2NET.Exceptions;
|
|
using Senparc.Weixin.MP.Entities.Request;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Security.Policy;
|
|
using System.Threading;
|
|
using System.Web.Helpers;
|
|
using System.Xml.Linq;
|
|
|
|
namespace MyCode.Project.Services.Implementation
|
|
{
|
|
/// <summary>
|
|
/// 员工档案与企业微信资料 相关服务
|
|
/// </summary>
|
|
public class StaffDataEnterpriseWechatService : ServiceBase, IStaffDataEnterpriseWechatService
|
|
{
|
|
private IWorkProcessService _workProcessService;
|
|
|
|
private ITBDStaffDataLRepository _tBDStaffDataLRepository;
|
|
private ITBDStaffDataRepository _tBDStaffDataRepository;
|
|
private ITAttendanceRequestRepository _tAttendanceRequestRepository;
|
|
private ITUserLoginParameterRepository _tUserLoginParameterRepository;
|
|
|
|
private static object locker = new object(); //创建锁
|
|
public StaffDataEnterpriseWechatService(IWorkProcessService workProcessService
|
|
|
|
, ITBDStaffDataLRepository tBDStaffDataLRepository
|
|
, ITBDStaffDataRepository tBDStaffDataRepository
|
|
, ITUserLoginParameterRepository tUserLoginParameterRepository
|
|
, ITAttendanceRequestRepository tAttendanceRequestRepository
|
|
, IEnterpriseWechatService enterpriseWechatService)
|
|
{
|
|
_workProcessService = workProcessService;
|
|
_tUserLoginParameterRepository = tUserLoginParameterRepository;
|
|
_tBDStaffDataLRepository = tBDStaffDataLRepository;
|
|
_tBDStaffDataRepository = tBDStaffDataRepository;
|
|
_tAttendanceRequestRepository = tAttendanceRequestRepository;
|
|
}
|
|
|
|
DateTime now = DateTime.Now;
|
|
/// <summary>
|
|
/// 打卡
|
|
/// </summary>
|
|
public static string _UpdateAttendanceDataUrl = "http://14.21.32.187:9090/K3Cloud/G_HRApi.Attendance.UpdateAttendanceData.ExecuteService,G-HRApi.common.kdsvc";
|
|
/// <summary>
|
|
/// 定时获取用户登录参数
|
|
/// </summary>
|
|
public void TaskGetPasswordData()
|
|
{
|
|
string url = $@"http://14.21.32.187:9090/K3Cloud/G_HRApi.Staff.StaffData.GetPasswordData.ExecuteService,G-HRApi.common.kdsvc";
|
|
PostModel1 postModel1 = new PostModel1();
|
|
postModel1.DBID = "5dc0f25110f625";
|
|
postModel1.KEY = "95F80245-F905-4472-A319-008682087E02";
|
|
WebUtils webUtility = new WebUtils();
|
|
string json = JsonHelper.ToJson(postModel1);
|
|
Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
|
|
keyValuePairs.Add("Data", json);
|
|
json = JsonHelper.ToJson(keyValuePairs);
|
|
LogHelper.Info(json);
|
|
var re = webUtility.DoPostJson(url, json);
|
|
|
|
LogHelper.Info(re);
|
|
var result = JsonHelper.ToObject<DeMiResp>(re);
|
|
if (result.Result.IsSuccess == "true")
|
|
{
|
|
var list = result.Result.Data.Item;
|
|
var oldList = _tUserLoginParameterRepository.Queryable().Where(t => 1 == 1).ToList();
|
|
list.ForEach(t =>
|
|
{
|
|
int add = 0;
|
|
var one = oldList.Where(h => h.FPHONE == t.FPHONE).FirstOrDefault();
|
|
if (one == null)
|
|
{
|
|
add = 1;
|
|
one = new T_UserLogin_Parameter();
|
|
one.FPHONE = t.FPHONE;
|
|
}
|
|
one.DBID = postModel1.DBID;
|
|
one.FPASSWORD = t.FPASSWORD;
|
|
one.Status = 1;
|
|
one.EditTime = DateTime.Now;
|
|
one.KEY1 = "95F80245-F905-4472-A319-008682087E02";
|
|
if (add == 0)
|
|
_tUserLoginParameterRepository.Update(one);
|
|
else
|
|
_tUserLoginParameterRepository.Add(one);
|
|
});
|
|
}
|
|
//_workProcessService.Add<IStaffDataEnterpriseWechatService>(this.MerchantId, "InitDepartment", "刷企业微信数据", "", 2);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 调度定时登录账号信息
|
|
/// </summary>
|
|
public void TaskGetUserByAccount()
|
|
{
|
|
string url = $@"http://14.21.32.187:9090/K3Cloud/G_HRApi.GetUserByAccount.ExecuteService,G-HRApi.common.kdsvc";
|
|
PostModel1 postModel1 = new PostModel1();
|
|
postModel1.DBID = "5dc0f25110f625";
|
|
postModel1.KEY = "95F80245-F905-4472-A319-008682087E02";
|
|
|
|
WebUtils webUtility = new WebUtils();
|
|
string json = JsonHelper.ToJson(postModel1);
|
|
var list = _tUserLoginParameterRepository.Queryable().Where(t => t.FPHONE != "").ToList();
|
|
list.ForEach(t =>
|
|
{
|
|
var JsonString = new
|
|
{
|
|
Data = new
|
|
{
|
|
DBID = postModel1.DBID,
|
|
userName = t.FPHONE,
|
|
HashPassword = t.FPASSWORD,
|
|
IFTaskLogin = 1
|
|
}
|
|
};
|
|
json = JsonHelper.ToJson(JsonString);
|
|
LogHelper.Info(json);
|
|
var re = webUtility.DoPostJson(url, json);
|
|
LogHelper.Info(re);
|
|
var result = JsonHelper.ToObject<DeMiResp>(re);
|
|
t.Response = re;
|
|
if (result.Result.IsSuccess == "true")
|
|
{
|
|
t.LoginStatus = 1;
|
|
}
|
|
else
|
|
{
|
|
t.LoginStatus = 0;
|
|
}
|
|
t.LoginEditTime = DateTime.Now;
|
|
_tUserLoginParameterRepository.Update(t);
|
|
Thread.Sleep(300);
|
|
});
|
|
_workProcessService.Add<IStaffDataEnterpriseWechatService>(this.MerchantId, "TaskGetUserByAccount", "调度定时登录账号信息", "", 2);
|
|
|
|
}
|
|
|
|
|
|
public void AddTask()
|
|
{
|
|
_workProcessService.Add<IStaffDataEnterpriseWechatService>(this.MerchantId, "TaskGetPasswordData", "定时获取用户登录参数", "", 2);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 定时打卡任务
|
|
/// </summary>
|
|
public void TaskAttendanceRequest()
|
|
{
|
|
WebUtils webUtility = new WebUtils();
|
|
var list = _tAttendanceRequestRepository.Queryable().Where(t => t.Status == 0).OrderBy(y => y.Id).Take(50).ToList();
|
|
list.ForEach(t =>
|
|
{
|
|
t.Status = 1;
|
|
t.EditTime = DateTime.Now;
|
|
t.ExceptionInfo = "";
|
|
|
|
});
|
|
_tAttendanceRequestRepository.Update(list);
|
|
list.ForEach(t =>
|
|
{
|
|
LogHelper.Info(t.Request);
|
|
var re = webUtility.DoPostJson(_UpdateAttendanceDataUrl, t.Request);
|
|
LogHelper.Info(re);
|
|
var result = JsonHelper.ToObject<DeMiResp>(re);
|
|
if (result.Result.IsSuccess == "true")
|
|
{
|
|
t.Status = 2;
|
|
t.EditTime = DateTime.Now;
|
|
t.ExceptionInfo = "";
|
|
_tAttendanceRequestRepository.Update(t);
|
|
}
|
|
else
|
|
{
|
|
t.Status = 3;
|
|
t.EditTime = DateTime.Now;
|
|
t.ExceptionInfo = result.Result.ErrorMessage;
|
|
_tAttendanceRequestRepository.Update(t);
|
|
}
|
|
Thread.Sleep(500);
|
|
|
|
});
|
|
}
|
|
}
|
|
}
|