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.
233 lines
9.2 KiB
233 lines
9.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Quartz;
|
|
|
|
|
|
namespace ICSSoft.FromERP
|
|
{
|
|
/// <summary>
|
|
/// 完工报告
|
|
/// </summary>
|
|
public class ICSManufactureReceiveList : 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;
|
|
DataTable dt = ICSHelper.GetERPDB(conStr);
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
string erpName = ICSHelper.GetConfigString()["ERPDB"];
|
|
string WorkPoint = dr["WorkPointCode"].ToString();
|
|
string Class = this.GetType().Name + WorkPoint;
|
|
erpName = string.Format(erpName, WorkPoint);
|
|
string dvURL = "";
|
|
string token = "";
|
|
List<string> lsid = new List<string>();
|
|
//获取token
|
|
token = YSHepler.GetToken();
|
|
dvURL = YSHepler.GetSELECTURL();
|
|
|
|
DataTable LastTime = ICSHelper.GetlastTime(conStr, Namespace, Class, WorkPoint, "", "#TempMFR");
|
|
string Time = LastTime.Rows[0]["DateTime"].ToString();
|
|
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
DYS dys = new DYS();
|
|
|
|
dys.pageSize = 500;
|
|
dys.pageIndex = 1;
|
|
string ORG = "";
|
|
if (WorkPoint == "DE_Clean")
|
|
ORG = "1697012463846817795";
|
|
else if (WorkPoint == "DE_Clean-1")
|
|
ORG = "2143118501979095046";
|
|
else if (WorkPoint == "DE_Clean-2")
|
|
ORG = "2143119326616485897";
|
|
else if (WorkPoint == "DE_Clean-3")
|
|
ORG = "2201817055513018374";
|
|
|
|
dys.status = "1";
|
|
dys.orgId = ORG;
|
|
#region 添加条件
|
|
simple s = new simple();
|
|
s.open_pubts_begin = Convert.ToDateTime(Time).ToString("yyyy-MM-dd HH:mm:ss");
|
|
s.open_pubts_end = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
#endregion
|
|
|
|
dys.simple = s;
|
|
|
|
string JsonData = JsonConvert.SerializeObject(dys);
|
|
#region 获取列表内ID
|
|
string results = YSHepler.HttpPost(dvURL + "/yonbip/mfg/finishedreport/list?access_token=" + token + "", JsonData, "", "POST");
|
|
JObject obj = JObject.Parse(results);
|
|
if (obj["code"].ToString() == "200")
|
|
{
|
|
List<InvLists> infos = new List<InvLists>();
|
|
infos = JsonConvert.DeserializeObject<List<InvLists>>(obj["data"]["recordList"].ToString());
|
|
infos = infos.GroupBy(p => p.id).Select(g => g.First()).ToList();
|
|
BulkInsertUsers(infos, WorkPoint);
|
|
string sqldelete = " delete ICSWMS_YS_DYSList.DBO.ICSManufactureReceiveLists ";
|
|
ICSHelper.ExecuteDate(conStr, sqldelete);
|
|
int end = Convert.ToInt32(obj["data"]["endPageIndex"].ToString());
|
|
if (end > 1)
|
|
{
|
|
for (int i = 2; i <= end; i++)
|
|
{
|
|
dys.pageIndex = i;
|
|
JsonData = JsonConvert.SerializeObject(dys);
|
|
results = YSHepler.HttpPost(dvURL + "/yonbip/mfg/finishedreport/list?access_token=" + token + "", JsonData, "", "POST");
|
|
obj = JObject.Parse(results);
|
|
if (obj["code"].ToString() == "200")
|
|
{
|
|
infos = new List<InvLists>();
|
|
infos = JsonConvert.DeserializeObject<List<InvLists>>(obj["data"]["recordList"].ToString());
|
|
infos = infos.GroupBy(p => p.id).Select(g => g.First()).ToList();
|
|
BulkInsertUsers(infos, WorkPoint);
|
|
sqldelete = " delete ICSWMS_YS_DYSList.DBO.ICSManufactureReceiveLists ";
|
|
ICSHelper.ExecuteDate(conStr, sqldelete);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
string sql = "select '" + s.open_pubts_end + "' MTIME into #TempMFR delete ICSWMS_YS_DYSList.DBO.ICSManufactureReceiveLists ";
|
|
|
|
sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempMFR");
|
|
sql += " DROP TABLE #TempMFR ";
|
|
sql = string.Format(sql, WorkPoint, erpName);
|
|
ICSHelper.ExecuteDate(conStr, sql);
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.ToString());
|
|
}
|
|
}
|
|
|
|
|
|
public class DYS
|
|
{
|
|
public int pageIndex;
|
|
public int pageSize;
|
|
public string status;
|
|
public string orgId;
|
|
public simple simple;
|
|
}
|
|
public class simple
|
|
{
|
|
public string open_pubts_begin;
|
|
public string open_pubts_end;
|
|
}
|
|
|
|
|
|
public class InvLists
|
|
{
|
|
public string id;
|
|
public string code;
|
|
}
|
|
|
|
|
|
|
|
static void BulkInsertUsers(List<InvLists> users, string WorkPoint)
|
|
{
|
|
try
|
|
{
|
|
string conStr = ICSHelper.GetYSString();
|
|
|
|
DataTable dataTable = new DataTable();
|
|
dataTable.Columns.Add("YSID", typeof(string));
|
|
dataTable.Columns.Add("Org", typeof(string));
|
|
dataTable.Columns.Add("OrgCode", typeof(string));
|
|
dataTable.Columns.Add("CODE", typeof(string));
|
|
dataTable.Columns.Add("ISIN", typeof(int));
|
|
string ORG = "";
|
|
if (WorkPoint == "DE_Clean")
|
|
ORG = "1697012463846817795";
|
|
else if (WorkPoint == "DE_Clean-1")
|
|
ORG = "2143118501979095046";
|
|
else if (WorkPoint == "DE_Clean-2")
|
|
ORG = "2143119326616485897";
|
|
else if (WorkPoint == "DE_Clean-3")
|
|
ORG = "2201817055513018374";
|
|
|
|
foreach (var user in users)
|
|
dataTable.Rows.Add(user.id, ORG, WorkPoint, user.code, 0);
|
|
|
|
using (SqlConnection connection = new SqlConnection(conStr))
|
|
{
|
|
connection.Open();
|
|
|
|
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection))
|
|
{
|
|
bulkCopy.DestinationTableName = "ICSManufactureReceiveLists";
|
|
bulkCopy.ColumnMappings.Add("YSID", "YSID");
|
|
bulkCopy.ColumnMappings.Add("Org", "Org");
|
|
bulkCopy.ColumnMappings.Add("OrgCode", "OrgCode");
|
|
bulkCopy.ColumnMappings.Add("CODE", "CODE");
|
|
bulkCopy.ColumnMappings.Add("ISIN", "ISIN");
|
|
bulkCopy.WriteToServer(dataTable);
|
|
}
|
|
|
|
// 执行 MERGE 操作
|
|
string mergeQuery = @"
|
|
MERGE INTO ICSManufactureReceiveList AS Target
|
|
USING ICSManufactureReceiveLists AS Source
|
|
ON Target.YSID = Source.YSID and Target.Org = Source.Org
|
|
WHEN MATCHED THEN
|
|
UPDATE SET Target.ISIN = 0
|
|
WHEN NOT MATCHED BY TARGET THEN
|
|
INSERT (YSID, Org, ISIN,OrgCode,CODE)
|
|
VALUES (Source.YSID, Source.Org,0, Source.OrgCode,Source.CODE);";
|
|
|
|
using (SqlCommand command = new SqlCommand(mergeQuery, connection))
|
|
{
|
|
command.ExecuteNonQuery();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.ToString());
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|