using ICSSoft.FromERP.Model;
using Newtonsoft.Json;
using Quartz;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ICSSoft.FromERP
{
///
/// 数采上传(金杨)
///
public class SyncCas_Jinyang : IJob
{
private static object key = new object();
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public void Execute(IJobExecutionContext context)
{
try
{
lock (key)
{
log.Info("开始……………………………………………………………………");
Execute();
log.Info("结束……………………………………………………………………");
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
public void Execute()
{
try
{
string conStr = ICSHelper.GetConnectString();
string Namespace = this.GetType().Namespace;
//string Class = this.GetType().Name;
DataTable dt = ICSHelper.GetERPDB(conStr);
foreach (DataRow dr in dt.Rows)
{
//var dtNowBegin = new DateTime(2000, 1, 1, 0, 0, 0);//默认开始时间
//var dtNow = DateTime.Now;
//string erpName = ICSHelper.GetConfigString()["ERPDB"];
//string TenantId = dr["TenantId"].ToString();//mes 组织
//string TenantCode = dr["TenantCode"].ToString();
//string ErpId = dr["ErpID"].ToString(); //erpID
//string Class = this.GetType().Name + TenantCode;
//erpName = string.Format(erpName, TenantId);
//string sql0 = " SELECT top 1 ModifyDate FROM ICSERPTime where ClassName='" + Class + "'";
//var lastDate = ICSHelper.ExecuteScalar(conStr, sql0).ToDateOrNull();
//if (!lastDate.HasValue)
//{
// lastDate = dtNowBegin;
//}
//string sql = @" select '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' as MTIME into #TempVendor ";
//sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempVendor");
//sql += "DROP TABLE #TempVendor";
//ICSHelper.ExecuteDate(conStr, sql);
List list = new List();
var input = new CapInputDto();
input.WorkshopID = "1";
input.EquipmentID = "1";
input.ProductNo = "1";
input.LotNo = "1";
input.CollectionTime = "1";
input.ParamValue_Resistance = 12;
input.ParamValue_Height = 12;
input.Msg = "";
list.Add(input);
var inputObj = JsonConvert.SerializeObject(list);
//string url = ICSHelper.GetConfigString()["JinyangCapUrl"]+ @"?deipaaskeyauth=a5P1RTL4380zd9jpb57qXx63rdynUHN2";
string url = ICSHelper.GetConfigString()["JinyangCapUrl"];
var result = HttpHelper.HttpClientPost(url, inputObj, new Dictionary() { { "deipaaskeyauth", "a5P1RTL4380zd9jpb57qXx63rdynUHN2" } }).Result;
// var result = HttpHelper.HttpClientPost(url, inputObj).Result;
if (result.Result == "OK")
{
}
else
{
throw new Exception(result.Result);
}
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
}
}