Files
DeMiWebApi_yuyubo/MyCode.Project.Services/Implementation/StaffData/StaffDataEnterpriseWechatService.cs

150 lines
6.2 KiB
C#
Raw Normal View History

2025-07-01 20:09:17 +08:00
using MyCode.Project.Domain.Message.Request.User;
using MyCode.Project.Domain.Message.Response.EnterpriseWechat;
using MyCode.Project.Domain.Message.Response.Wechat;
2025-06-30 19:22:02 +08:00
using MyCode.Project.Domain.Model;
using MyCode.Project.Domain.Repositories;
using MyCode.Project.Infrastructure.Common;
2025-07-01 20:09:17 +08:00
using MyCode.Project.Infrastructure.WebPost;
2025-06-30 19:22:02 +08:00
using MyCode.Project.OutSideService;
using MyCode.Project.Repositories;
using Senparc.CO2NET.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
2025-07-01 20:09:17 +08:00
using System.Net;
using System.Security.Policy;
using System.Threading;
2025-06-30 19:22:02 +08:00
using System.Xml.Linq;
namespace MyCode.Project.Services.Implementation
{
/// <summary>
/// 员工档案与企业微信资料 相关服务
/// </summary>
public class StaffDataEnterpriseWechatService : ServiceBase , IStaffDataEnterpriseWechatService
{
private IWorkProcessService _workProcessService;
2025-07-01 20:09:17 +08:00
2025-06-30 19:22:02 +08:00
private ITBDStaffDataLRepository _tBDStaffDataLRepository;
private ITBDStaffDataRepository _tBDStaffDataRepository;
2025-07-01 20:09:17 +08:00
private ITUserLoginParameterRepository _tUserLoginParameterRepository;
2025-06-30 19:22:02 +08:00
private static object locker = new object(); //创建锁
public StaffDataEnterpriseWechatService(IWorkProcessService workProcessService
2025-07-01 20:09:17 +08:00
2025-06-30 19:22:02 +08:00
, ITBDStaffDataLRepository tBDStaffDataLRepository
, ITBDStaffDataRepository tBDStaffDataRepository
2025-07-01 20:09:17 +08:00
, ITUserLoginParameterRepository tUserLoginParameterRepository
2025-06-30 19:22:02 +08:00
, IEnterpriseWechatService enterpriseWechatService)
{
_workProcessService = workProcessService;
2025-07-01 20:09:17 +08:00
_tUserLoginParameterRepository = tUserLoginParameterRepository;
_tBDStaffDataLRepository = tBDStaffDataLRepository;
2025-06-30 19:22:02 +08:00
_tBDStaffDataRepository = tBDStaffDataRepository;
}
DateTime now = DateTime.Now;
2025-07-01 20:09:17 +08:00
2025-06-30 19:22:02 +08:00
/// <summary>
2025-07-01 20:09:17 +08:00
/// 定时获取用户登录参数
2025-06-30 19:22:02 +08:00
/// </summary>
2025-07-01 20:09:17 +08:00
public void TaskGetPasswordData()
2025-06-30 19:22:02 +08:00
{
2025-07-01 20:09:17 +08:00
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);
2025-06-30 19:22:02 +08:00
2025-07-01 20:09:17 +08:00
LogHelper.Info(re);
var result = JsonHelper.ToObject<DeMiResp>(re);
if (result.Result.IsSuccess == "true")
2025-06-30 19:22:02 +08:00
{
2025-07-01 20:09:17 +08:00
var list = result.Result.Data.Item;
var oldList = _tUserLoginParameterRepository.Queryable().Where(t => 1 == 1).ToList();
list.ForEach(t =>
2025-06-30 19:22:02 +08:00
{
2025-07-01 20:09:17 +08:00
int add = 0;
var one = oldList.Where(h => h.FPHONE == t.FPHONE).FirstOrDefault();
if (one == null)
2025-06-30 19:22:02 +08:00
{
2025-07-01 20:09:17 +08:00
add = 1;
one = new T_UserLogin_Parameter();
one.FPHONE = t.FPHONE;
2025-06-30 19:22:02 +08:00
}
2025-07-01 20:09:17 +08:00
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);
2025-06-30 19:22:02 +08:00
});
}
2025-07-01 20:09:17 +08:00
//_workProcessService.Add<IStaffDataEnterpriseWechatService>(this.MerchantId, "InitDepartment", "刷企业微信数据", "", 2);
2025-06-30 19:22:02 +08:00
}
/// <summary>
2025-07-01 20:09:17 +08:00
/// 调度定时登录账号信息
2025-06-30 19:22:02 +08:00
/// </summary>
2025-07-01 20:09:17 +08:00
public void TaskGetUserByAccount()
2025-06-30 19:22:02 +08:00
{
2025-07-01 20:09:17 +08:00
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();
2025-06-30 19:22:02 +08:00
list.ForEach(t =>
{
2025-07-01 20:09:17 +08:00
var JsonString = new
2025-06-30 19:22:02 +08:00
{
2025-07-01 20:09:17 +08:00
Data = new
2025-06-30 19:22:02 +08:00
{
2025-07-01 20:09:17 +08:00
DBID = postModel1.DBID,
userName = t.FPHONE,
HashPassword = t.FPASSWORD,
IFTaskLogin=1
2025-06-30 19:22:02 +08:00
}
2025-07-01 20:09:17 +08:00
};
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")
2025-06-30 19:22:02 +08:00
{
2025-07-01 20:09:17 +08:00
t.LoginStatus = 1;
2025-06-30 19:22:02 +08:00
}
2025-07-01 20:09:17 +08:00
else
{
t.LoginStatus = 0;
}
t.LoginEditTime = DateTime.Now;
_tUserLoginParameterRepository.Update(t);
Thread.Sleep(300);
});
//_workProcessService.Add<IStaffDataEnterpriseWechatService>(this.MerchantId, "InitDepartment", "刷企业微信数据", "", 2);
2025-06-30 19:22:02 +08:00
}
2025-07-02 19:31:43 +08:00
public void AddTask()
{
_workProcessService.Add<IStaffDataEnterpriseWechatService>(this.MerchantId, "TaskGetPasswordData", "定时获取用户登录参数", "", 2);
_workProcessService.Add<IStaffDataEnterpriseWechatService>(this.MerchantId, "TaskGetUserByAccount", "调度定时登录账号信息", "", 2);
}
2025-06-30 19:22:02 +08:00
}
}