|
|
|
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 WsJob : IJob
|
|
|
|
{
|
|
|
|
private readonly SqlSugarClient _db;//数据库
|
|
|
|
DateTime unixStartTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
|
|
|
public WsJob(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)
|
|
|
|
{
|
|
|
|
Console.WriteLine("定时任务执行中...");
|
|
|
|
Console.WriteLine("定时任务执行中...");
|
|
|
|
JobDataMap datas = context.JobDetail.JobDataMap;
|
|
|
|
// 定时任务执行的代码
|
|
|
|
Console.WriteLine("定时任务执行中...");
|
|
|
|
//获取文书最新跟新时间
|
|
|
|
var Document = _db.Queryable<App_DocumentModel>().OrderByDescending(q => long.Parse(q.zhxgsj)).Select(q=>new { q.zhxgsj}).ToList().FirstOrDefault();
|
|
|
|
var start = DateTime.Parse(unixStartTime.AddMilliseconds(long.Parse(Document.zhxgsj)).AddDays(-1).ToString("yyyy-MM-dd"));
|
|
|
|
var end = DateTime.Parse(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"));
|
|
|
|
var daa = new { data = "{\"token\":\"www.archives.net.cn\",\"dwbm\":\"\",\"zt\":\"02\",\"zjhm\":\"\",\"zrrxm\":\"\",\"zrrlshm\":\"\",\"account\":\"\",\"dhhm\":\"\",\"start\":\"" + start + "\",\"end\":\"" + end + "\"}" };
|
|
|
|
var msg = "";
|
|
|
|
var data = HttpHelper.Post("http://jhg.ahjiguang.cn:80/agyw/api/user/command/wssdapi/getwssdlist", daa, out msg);
|
|
|
|
var Results = JsonConvert.DeserializeObject<RequestResults>(data);
|
|
|
|
var Documentlist = JsonConvert.DeserializeObject<List<App_DocumentModel>>(Results.data);
|
|
|
|
if (Documentlist.Count() > 0)
|
|
|
|
{
|
|
|
|
await AddDocument(Documentlist);
|
|
|
|
_db.Dispose();
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(msg))
|
|
|
|
Console.WriteLine($"文书签收错误...{msg}");
|
|
|
|
//LogService.WriteLog(msg, "文书签收");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 添加文书签收
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="info"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public async Task AddDocument(List<App_DocumentModel> Documentdata)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
//获取app平台所有用户身份证
|
|
|
|
var usercardIds = _db.Queryable<App_Sys_UserModel>().Where(q => q.IsDeleted == 0 && q.usertype == 1).Select(q => q.cardId).ToList();
|
|
|
|
//获取文书最新跟新时间戳
|
|
|
|
var Document = _db.Queryable<App_DocumentModel>().OrderByDescending(q => long.Parse(q.zhxgsj)).ToList().FirstOrDefault();
|
|
|
|
//获取文书编号
|
|
|
|
var Documentwsslbh = _db.Queryable<App_DocumentModel>().Select(q => q.wsslbh).ToList();
|
|
|
|
//获取文书Id,文书编号
|
|
|
|
var Documentlist = _db.Queryable<App_DocumentModel>().Select(q => new { q.wsslbh,q.Id }).ToList();
|
|
|
|
//根据数据库最新时间戳筛选文书数据
|
|
|
|
Documentdata.Where(q => long.Parse(q.zhxgsj) >= long.Parse(Document.zhxgsj));
|
|
|
|
//获取系统存在的用户文书数据
|
|
|
|
Documentdata = Documentdata.Where(q => usercardIds.Contains(q.zjhm)).ToList();
|
|
|
|
//筛选数据库包含文书
|
|
|
|
var bhwslist = Documentdata.Where(q => Documentwsslbh.Contains(q.wsslbh)).ToList();
|
|
|
|
//筛选数据库不包含文书
|
|
|
|
var nobhwslist = Documentdata.Where(q => !Documentwsslbh.Contains(q.wsslbh)).ToList();
|
|
|
|
//循环赋值Id
|
|
|
|
bhwslist.ForEach(q =>
|
|
|
|
{
|
|
|
|
var data = Documentlist.Where(x => x.wsslbh == q.wsslbh).FirstOrDefault();
|
|
|
|
q.Id = data.Id;
|
|
|
|
q.reservationId = "0e231845-0439-11ee-ab29-0242ac110004";
|
|
|
|
});
|
|
|
|
//循环生成唯一Id
|
|
|
|
nobhwslist.ForEach(q =>
|
|
|
|
{
|
|
|
|
q.Id = Guid.NewGuid().ToString();
|
|
|
|
q.reservationId = "0e231845-0439-11ee-ab29-0242ac110004";
|
|
|
|
});
|
|
|
|
_db.BeginTran();
|
|
|
|
await _db.Insertable(nobhwslist).ExecuteCommandAsync();
|
|
|
|
await _db.Updateable(bhwslist).UpdateColumns(it => new { it.zt, it.zhxgsj, it.qmsj,it.sdsj }).ExecuteCommandAsync();
|
|
|
|
_db.CommitTran();
|
|
|
|
}
|
|
|
|
catch (System.Exception ex)
|
|
|
|
{
|
|
|
|
_db.RollbackTran();
|
|
|
|
LogService.WriteLog(ex, "添加文书签收");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|