You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
5.7 KiB
125 lines
5.7 KiB
using Elight.Utility.logs; |
|
using Elight.Utility; |
|
using Newtonsoft.Json; |
|
using Quartz; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using System.Text; |
|
using System.Threading.Tasks; |
|
using Elight.Entity; |
|
using Microsoft.Extensions.Logging; |
|
using SqlSugar; |
|
using Microsoft.AspNetCore.Mvc; |
|
using Microsoft.Extensions.DependencyInjection; |
|
using java.sql; |
|
using org.omg.PortableServer; |
|
using System.Runtime.Intrinsics.X86; |
|
using Microsoft.OpenApi.Validations; |
|
using static com.sun.tools.@internal.xjc.reader.xmlschema.bindinfo.BIConversion; |
|
using Microsoft.Extensions.Configuration; |
|
|
|
namespace Elight.Logic.Job |
|
{ |
|
[DisallowConcurrentExecution] |
|
public class YgJob : IJob |
|
{ |
|
private readonly SqlSugarClient _db;//数据库 |
|
DateTime unixStartTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); |
|
public YgJob(IConfiguration configuration) |
|
{ |
|
var connectionString = configuration.GetSection("ConnectionStrings:MySQLConnString").Value; |
|
_db = new SqlSugarClient(new ConnectionConfig |
|
{ |
|
ConnectionString = connectionString, |
|
DbType = SqlSugar.DbType.MySql, |
|
IsAutoCloseConnection = true, |
|
InitKeyType = InitKeyType.Attribute |
|
}); |
|
} |
|
public async Task Execute(IJobExecutionContext context) |
|
{ |
|
JobDataMap datas = context.JobDetail.JobDataMap; |
|
// 定时任务执行的代码 |
|
Console.WriteLine("云柜同步定时任务执行中..."); |
|
var daa = new { data = "{\"token\":\"www.archives.net.cn\",\"dwbm\":\"\",\"zt\":\"\",\"sfzh\":\"\",\"xm\":\"\",\"lxhm\":\"\",\"account\":\"\",\"gjlxhm\":\"\"}" }; |
|
var msg = ""; |
|
try |
|
{ |
|
var data = HttpHelper.Post("http://jhg.ahjiguang.cn:80/jhg/api/user/command/jhgwbsclapi/getjhgywlist", daa, out msg); |
|
var Results = JsonConvert.DeserializeObject<RequestResults>(data); |
|
if (Results != null && Results.code == "200") |
|
{ |
|
var CloudCabinetlist = JsonConvert.DeserializeObject<List<App_CloudCabinetModel>>(Results.data); |
|
if (CloudCabinetlist != null && CloudCabinetlist.Count() > 0) |
|
{ |
|
await AddDocument(CloudCabinetlist); |
|
_db.Dispose(); |
|
} |
|
Console.WriteLine($"云柜同步成功..{DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")}"); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
Console.WriteLine($"云柜错误...{ex.Message + ex.InnerException}"); |
|
} |
|
Console.WriteLine("云柜同步定时任务完成..."); |
|
} |
|
|
|
|
|
/// <summary> |
|
/// 添加云柜 |
|
/// </summary> |
|
/// <param name="info"></param> |
|
/// <returns></returns> |
|
public async Task AddDocument(List<App_CloudCabinetModel> CloudCabinetdata) |
|
{ |
|
try |
|
{ |
|
//获取app平台所有用户身份证 |
|
var usercardIds = _db.Queryable<App_Sys_UserModel>().Where(q => q.IsDeleted == 0 && q.usertype == 1).Select(q => q.cardId).ToList(); |
|
//获取app平台所有用户电话号码 |
|
var userphone = _db.Queryable<App_Sys_UserModel>().Where(q => q.IsDeleted == 0 && q.usertype == 1).Select(q => q.phone).ToList(); |
|
//获取云柜最新创建时间 |
|
var Document = _db.Queryable<App_CloudCabinetModel>().OrderByDescending(q => long.Parse(q.cjsj)).ToList().FirstOrDefault(); |
|
//获取云柜编号 |
|
var Documentwsslbh = _db.Queryable<App_CloudCabinetModel>().Select(q => q.bh).ToList(); |
|
//获取云柜Id,云柜编号 |
|
var CloudCabinetdatalist = _db.Queryable<App_CloudCabinetModel>().Select(q => new { q.bh, q.Id }).ToList(); |
|
//根据数据库最新时间戳筛选文书数据 |
|
CloudCabinetdata.WhereIF(Document != null, q => long.Parse(q.cjsj) >= long.Parse(Document.cjsj)); |
|
//获取系统存在的用户云柜数据 |
|
CloudCabinetdata = CloudCabinetdata.Where(q => usercardIds.Contains(q.sfzh) || userphone.Contains(q.lxhm)).ToList(); |
|
//筛选数据库包含云柜 |
|
var bhyglist = CloudCabinetdata.Where(q => Documentwsslbh.Contains(q.bh)).ToList(); |
|
//筛选数据库不包含云柜 |
|
var nobhyglist = CloudCabinetdata.Where(q => !Documentwsslbh.Contains(q.bh)).ToList(); |
|
//循环赋值Id |
|
bhyglist.ForEach(q => |
|
{ |
|
var data = CloudCabinetdatalist.Where(x => x.bh == q.bh).FirstOrDefault(); |
|
q.Id = data.Id; |
|
q.reservationId = "0e23db19-0439-11ee-ab29-0242ac110004"; |
|
//q.cjsj=unixStartTime.AddMilliseconds(long.Parse(q.cjsj)) |
|
// q.cjsj=DateTime.Now; |
|
}); |
|
//循环生成唯一Id |
|
nobhyglist.ForEach(q => |
|
{ |
|
q.Id = Guid.NewGuid().ToString(); |
|
q.reservationId = "0e23db19-0439-11ee-ab29-0242ac110004"; |
|
// q.cjsj=DateTime.Now; |
|
}); |
|
_db.BeginTran(); |
|
await _db.Insertable(nobhyglist).ExecuteCommandAsync(); |
|
await _db.Updateable(bhyglist).UpdateColumns(it => new { it.zt, it.qjsj ,it.cjsj}).ExecuteCommandAsync(); |
|
_db.CommitTran(); |
|
} |
|
catch (System.Exception ex) |
|
{ |
|
_db.RollbackTran(); |
|
//LogService.WriteLog(ex, "添加文书签收"); |
|
} |
|
} |
|
} |
|
}
|
|
|