You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb.Service.Output/DoReadApply.cs

152 lines
4.7 KiB
C#

using DSWeb.Common;
using DSWeb.Common.DB;
using DSWeb.Common.Helper;
using log4net;
using log4net.Repository.Hierarchy;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Quartz;
using RabbitMQ.Client;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Linq;
using System.Runtime.Caching;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading.Tasks;
namespace DSWeb.Service.Output
{
//
public class DoReadApply : IJob
{
//private const string ExchangeName = "output";
//private const string QueuePrefix = "djy.output.cangdan.ds7.";
private ILog log = LogManager.GetLogger(typeof(DoReadApply));
//private string rabbitUri = ConfigurationManager.AppSettings["OutputDS7MQUri"];
//string OAconnStr = ConfigurationManager.AppSettings["OAconnStr"];
string DS7connStr = ConfigurationManager.AppSettings["DS7connStr"];
string DS7URL = ConfigurationManager.AppSettings["DS7URL"];
string USERID = ConfigurationManager.AppSettings["USERID"];
string USERNAME = ConfigurationManager.AppSettings["USERNAME"];
1 year ago
List<string> NoReadMessage = new List<string> {
"获取报关数据查询数据列表为空"
};
public class ReadRtn
{
//{"message":"正在查询中","status":"0"}
public bool? status { get; set; } = true;
//ds7当中 如果读取未返回则在返回消息中包含 status=false;
1 year ago
public string message { get; set; }
}
public void Execute(IJobExecutionContext context)
{
//int reqTimeout = Convert.ToInt32(context.JobDetail.JobDataMap.GetString("RequestTimeout"));
try
{
log.Debug("读取列表 start");
var cdc = new CommonDataContext(DS7connStr);
//待读取的任务为OP_LOGICINFO当中 数值为NAME = "定时读取单一窗口"的, BSNO = DecHead.BSNO
//执行读取服务每次读取一条并删除一条
var needread = new OP_LOGICINFO_md();
var needReadList = cdc.OP_LOGICINFO.Where(x => x.PROPNAME == "定时读取单一窗口").ToList();
if (needReadList != null && needReadList.Count > 0) {
needread = needReadList[0];
DoRead(needread,cdc);
}
log.Debug("读取列表 end");
}
catch (Exception ex)
{
log.Debug($"catch{ex.Message}");
log.Error(ex.Message);
log.Error(ex.StackTrace);
}
}
private void DoRead(OP_LOGICINFO_md readrec , CommonDataContext cdc)
{
try
{
//根据oa系统的userid查找ds7系统的userid
//log.Debug("audit start");
//var cdc = new CommonDataContext(DS7connStr);
//var ds7user = cdc.VW_user.Where(x => x.SHOWNAME.Replace(" ","") == OAUser.lastname).ToList();
//var ds7user = cdc.VW_user.Where(x => x.SHOWNAME == "系统管理员").ToList();
var dic = new Dictionary<string, string> {
{ "bsno",readrec.BSNO},
{ "userid",USERID},
1 year ago
{ "username",USERNAME},
{ "withdoc","true"}
};
log.Debug("url=" + DS7URL+";dic="+JsonConvert.SerializeObject(dic));
cdc.OP_LOGICINFO.Remove(readrec);
cdc.SaveChanges();
string rtn = WebRequestHelper.DoPost(DS7URL, dic, 120000);
log.Debug("rtn=" + rtn);
var _rtn = JsonConvert.DeserializeObject<ReadRtn>(rtn);
if (_rtn.status == false)
{
log.Debug("错误rtn=" + rtn);
1 year ago
if (NoReadMessage.Exists(x=>x == _rtn.message))
{
}
else
{
//错误 重新读取
cdc.OP_LOGICINFO.Add(readrec);
cdc.SaveChanges();
}
}
else {
//删除这条
if (readrec.PROPVALUE == "结关") {
readrec.PROPNAME = "结关已读取";
cdc.OP_LOGICINFO.Add(readrec);
cdc.SaveChanges();
}
}
//log.Debug("audit end");
}
catch (Exception e) {
log.Error(e.Message);
}
}
}
}