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.
394 lines
22 KiB
394 lines
22 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Quartz;
|
|
|
|
|
|
namespace ICSSoft.FromERP
|
|
{
|
|
/// <summary>
|
|
/// 采购到货(退货单)
|
|
/// </summary>
|
|
public class ICSDeliveryNotice
|
|
{
|
|
private static object key = new object();
|
|
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
private static string url = "";
|
|
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)
|
|
{
|
|
string dvURL = "";
|
|
string token = "";
|
|
string erpName = ICSHelper.GetConfigString()["ERPDB"];
|
|
string WorkPoint = dr["WorkPointCode"].ToString();
|
|
string Class = this.GetType().Name + WorkPoint;
|
|
erpName = string.Format(erpName, WorkPoint);
|
|
List<string> lsid = new List<string>();
|
|
#region 获取token
|
|
token= YSHepler.GetToken();
|
|
dvURL = YSHepler.GetSELECTURL();
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
//string SearchUrl = "https://api.diwork.com/open-auth/dataCenter/getGatewayAddress?tenantId=" + YSHepler.GetConfigString("ZH") + "";
|
|
//Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
|
|
//string Sresult = YSHepler.PostByTokenGet(SearchUrl, dic, "");
|
|
//JObject Sobj = new JObject();
|
|
//Sobj = JObject.Parse(Sresult);
|
|
|
|
//if (Sobj["code"].ToString() == "00000")
|
|
//{
|
|
// string timesp = YSHepler.ConvertDateTimeInt(DateTime.Now).ToString();
|
|
// string ZXSDS = YSHepler.Sign("appKey" + YSHepler.GetConfigString("AppKey") + "timestamp" + timesp + "", "" + YSHepler.GetConfigString("AppSecret") + "");
|
|
// string tokenurl = Sobj["data"]["tokenUrl"] + "/open-auth/selfAppAuth/getAccessToken?appKey=" + YSHepler.GetConfigString("AppKey") + "×tamp=" + timesp + "&signature=" + ZXSDS + "";
|
|
// dvURL = Sobj["data"]["gatewayUrl"].ToString() ;
|
|
// SearchUrl = tokenurl;
|
|
// dic = new Dictionary<string, string>();
|
|
|
|
// Sresult = YSHepler.PostByTokenGet(SearchUrl, dic, "");
|
|
// Sobj = JObject.Parse(Sresult);
|
|
// if (Sobj["code"].ToString() == "00000")
|
|
// token = Sobj["data"]["access_token"].ToString();
|
|
//}
|
|
#endregion
|
|
|
|
|
|
DataTable LastTime =ICSHelper.GetlastTime(conStr, Namespace, Class, WorkPoint, "", "#ICSDelive");
|
|
|
|
string Time = LastTime.Rows[0]["DateTime"].ToString();
|
|
|
|
DYS dys = new DYS();
|
|
List<DYSs> ls = new List<DYSs>();
|
|
List<DYSq> lq = new List<DYSq>();
|
|
|
|
dys.pageSize = 500;
|
|
dys.pageIndex = 1;
|
|
dys.isSum = true;
|
|
|
|
#region 添加条件
|
|
DYSs s = new DYSs();
|
|
s.field = "modifyTime";
|
|
s.op = "gt";
|
|
s.value1 = Time;
|
|
ls.Add(s);
|
|
#endregion
|
|
|
|
#region 添加排序
|
|
DYSq q = new DYSq();
|
|
q.field = "modifyTime";
|
|
q.order = "desc";
|
|
lq.Add(q);
|
|
#endregion
|
|
|
|
|
|
dys.simpleVOs = ls;
|
|
dys.queryOrders = lq;
|
|
|
|
string JsonData = JsonConvert.SerializeObject(dys);
|
|
#region 获取列表内ID
|
|
string results = YSHepler.HttpPost(dvURL + "/yonbip/scm/arrivalorder/list?access_token=" + token + "", JsonData, "", "POST");
|
|
JObject obj = JObject.Parse(results);
|
|
if (obj["code"].ToString() == "200")
|
|
{
|
|
foreach (JObject item in obj["data"]["recordList"])
|
|
{
|
|
lsid.Add(item["id"].ToString());
|
|
}
|
|
int end = Convert.ToInt32(obj["data"]["endPageIndex"].ToString());
|
|
if (end > 1)
|
|
{
|
|
for (int i = 2; i <= end; i++)
|
|
{
|
|
dys.pageIndex = 1;
|
|
JsonData = JsonConvert.SerializeObject(dys);
|
|
results = YSHepler.HttpPost(dvURL + "/yonbip/scm/arrivalorder/list?access_token=" + token + "", JsonData, "", "POST");
|
|
obj = JObject.Parse(results);
|
|
if (obj["code"].ToString() == "200")
|
|
{
|
|
foreach (JObject item in obj["data"]["recordList"])
|
|
{
|
|
lsid.Add(item["id"].ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
string sql = "";
|
|
int number = 0;
|
|
foreach (string item in lsid)
|
|
{
|
|
|
|
results = YSHepler.PostByTokenGet(dvURL + "/yonbip/scm/arrivalorder/detail?access_token=" + token + "&id=" + item + "", dic, "");
|
|
obj = JObject.Parse(results);
|
|
if (obj["code"].ToString() == "200")
|
|
{
|
|
#region 通过ID获取对应信息
|
|
string VenCoderesult = YSHepler.PostByTokenGet(dvURL + "/yonbip/digitalModel/vendor/detail?access_token=" + token + "&id=" + obj["data"]["vendor"].ToString() + "&orgId=" + obj["data"]["org"].ToString() + "", dic, "");
|
|
JObject result = JObject.Parse(VenCoderesult);
|
|
string VneCode = result["data"]["code"].ToString();
|
|
#endregion
|
|
foreach (JObject items in obj["data"]["arrivalOrders"])
|
|
{
|
|
number++;
|
|
if (number == 1)
|
|
{
|
|
sql += @"select '" + obj["data"]["code"].ToString() + "' DNCode,'" + items["lineno"].ToString() + "' Sequence," +
|
|
"'" + VneCode + "' VenCode,'' DepCode," + items["qty"].ToString() + " Quantity," + items["subQty"].ToString() + " Amount," +
|
|
"'" + (Convert.ToDecimal(items["qty"].ToString()) < 0 ? 2 : 1) + "' DNType,'" + items["product_cCode"].ToString() + "'InvCode, " +
|
|
"'" + obj["data"]["currency_name"].ToString() + "' Currency,'" + items["natUnitPrice"].ToString() + "' UnitPrice,'1' Status," +
|
|
"'" + obj["data"]["creator"].ToString() + "' CreatePerson,'" + obj["data"]["createTime"].ToString() + "' CreateDateTime," +
|
|
"'" + obj["data"]["createTime"].ToString() + "' MTIME,'" + obj["data"]["id"].ToString() + "' DNID,'" + items["id"].ToString() + "' DNDetailID," +
|
|
"'" + items["firstsourceid"].ToString() + "' POID,'" + items["firstsourceautoid"].ToString() + "' PODetailID," +
|
|
"'' ProjectCode,'' cBatch,'' version ,'' brand,'' as cFree1,'' as cFree2,'' as cFree3,'' as cFree4,'' as cFree5,'' as cFree6,'' as cFree7," +
|
|
"'' as cFree8,'' as cFree9,'' as cFree10,CAST('' AS NVARCHAR(500)) as Colspan,'' WHCode INTO #ICSDelive " ;
|
|
}
|
|
else
|
|
{
|
|
sql += @" union all select '" + obj["data"]["code"].ToString() + "' DNCode,'" + items["lineno"].ToString() + "' Sequence," +
|
|
"'" + VneCode + "' VenCode,'' DepCode," + items["qty"].ToString() + " Quantity," + items["subQty"].ToString() + " Amount," +
|
|
"'" + (Convert.ToDecimal(items["qty"].ToString()) < 0 ? 2 : 1) + "' DNType,'" + items["product_cCode"].ToString() + "'InvCode, " +
|
|
"'" + obj["data"]["currency_name"].ToString() + "' Currency,'" + items["natUnitPrice"].ToString() + "' UnitPrice,'1' Status," +
|
|
"'" + obj["data"]["creator"].ToString() + "' CreatePerson,'" + obj["data"]["createTime"].ToString() + "' CreateDateTime," +
|
|
"'" + obj["data"]["createTime"].ToString() + "' MTIME,'" + obj["data"]["id"].ToString() + "' DNID,'" + items["id"].ToString() + "' DNDetailID," +
|
|
"'" + items["firstsourceid"].ToString() + "' POID,'" + items["firstsourceautoid"].ToString() + "' PODetailID," +
|
|
"'' ProjectCode,'' cBatch,'' version ,'' brand,'' as cFree1,'' as cFree2,'' as cFree3,'' as cFree4,'' as cFree5,'' as cFree6,'' as cFree7," +
|
|
"'' as cFree8,'' as cFree9,'' as cFree10,CAST('' AS NVARCHAR(500)) as Colspan,'' WHCode ";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
#region 原临时表查询语句
|
|
// select a.cCode as DNCode,
|
|
// b.ivouchrowno as Sequence,
|
|
// a.cVenCode as VenCode ,
|
|
// cDepCode as DepCode ,
|
|
// CASE WHEN b.iQuantity >= 0 THEN '1' ELSE '2' END AS DNType,
|
|
// b.cInvCode as InvCode,
|
|
// b.iQuantity as Quantity ,
|
|
// isnull(b.iNum, 0) as Amount,
|
|
// a.cexch_name as Currency,
|
|
// b.iCost as UnitPrice,
|
|
// a.cMaker as CreatePerson,
|
|
// a.cMakeTime as CreateDateTime,
|
|
// a.iverifystateex as Status,
|
|
// a.cMakeTime as MTIME,
|
|
// a.ID as DNID,
|
|
// isnull(c.POID, '') as POID,
|
|
// isnull(b.iPOsID, '') as PODetailID,
|
|
// cast(b.AutoID as varchar(100)) as DNDetailID,
|
|
// isnull(b.cItemCode, '') ProjectCode,isnull(b.cbatch, '') cBatch,'' version ,'' brand,
|
|
// (case WHEN inv.bFree1 = 1 THEN isnull(b.cFree1,'') ELSE '' END) as cFree1,
|
|
// (case WHEN inv.bFree2 = 1 THEN isnull(b.cFree2,'') ELSE '' END) as cFree2,
|
|
// (case WHEN inv.bFree3 = 1 THEN isnull(b.cFree3,'') ELSE '' END) as cFree3,
|
|
// (case WHEN inv.bFree4 = 1 THEN isnull(b.cFree4,'') ELSE '' END) as cFree4,
|
|
// (case WHEN inv.bFree5 = 1 THEN isnull(b.cFree5,'') ELSE '' END) as cFree5,
|
|
// (case WHEN inv.bFree6 = 1 THEN isnull(b.cFree6,'') ELSE '' END) as cFree6,
|
|
// (case WHEN inv.bFree7 = 1 THEN isnull(b.cFree7,'') ELSE '' END) as cFree7,
|
|
// (case WHEN inv.bFree8 = 1 THEN isnull(b.cFree8,'') ELSE '' END) as cFree8,
|
|
// (case WHEN inv.bFree9 = 1 THEN isnull(b.cFree9,'') ELSE '' END) as cFree9,
|
|
// (case WHEN inv.bFree10 = 1 THEN isnull(b.cFree10,'') ELSE '' END) as cFree10,CAST('' AS NVARCHAR(500)) as Colspan,
|
|
// '{0}' as WorkPoint,
|
|
// b.cWhCode as WHCode
|
|
// INTO #ICSDelive
|
|
// from { 1}.DBO.PU_ArrivalVouch a
|
|
// inner join { 1}.DBO.PU_ArrivalVouchs b on a.ID = b.ID
|
|
// left join { 1}.DBO.PO_Podetails c on b.iPOsID = c.ID
|
|
// LEFT JOIN { 1}.dbo.Inventory inv ON b.cInvCode = inv.cInvCode
|
|
// where
|
|
//a.cBusType in('普通采购') and a.iBillType <> 2 and
|
|
// ISNULL(a.cverifier, '') <> ''and ISNULL(a.cAuditTime, ISNULL(a.cModifyTime, a.cmaketime))>= @LastTime
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region SQL
|
|
sql = @"
|
|
update #ICSDelive set Colspan=isNULL(ProjectCode,'')+'~'+isNULL(cBatch,'')+'~'+isNULL(Version,'')+'~'+isNULL(Brand,'')+'~'+isNULL(cFree1,'')+'~'+isnull(cFree2,'')+'~'+isnull(cFree3,'')+'~'+isnull(cFree4,'')+'~'+isnull(cFree5,'')+'~'+isnull(cFree6,'')+'~'+isnull(cFree7,'')+'~'+isnull(cFree8,'')+'~'+isnull(cFree9,'')+'~'+isnull(cFree10,'')
|
|
select distinct
|
|
Colspan,ProjectCode,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint,cBatch,version ,brand
|
|
INTO #TempExtension
|
|
from #ICSDelive
|
|
IF NOT EXISTS(SELECT * FROM #ICSDelive)
|
|
RETURN";
|
|
sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#ICSDelive");
|
|
Dictionary<string, string> value = new Dictionary<string, string>();
|
|
value.Add("ID", "NEWID()");
|
|
value.Add("BatchCode", "a.cBatch");
|
|
value.Add("version", "a.version");
|
|
value.Add("brand", "a.brand");
|
|
value.Add("ProjectCode", "a.ProjectCode");
|
|
value.Add("cFree1", "a.cFree1");
|
|
value.Add("cFree2", "a.cFree2");
|
|
value.Add("cFree3", "a.cFree3");
|
|
value.Add("cFree4", "a.cFree4");
|
|
value.Add("cFree5", "a.cFree5");
|
|
value.Add("cFree6", "a.cFree6");
|
|
value.Add("cFree7", "a.cFree7");
|
|
value.Add("cFree8", "a.cFree8");
|
|
value.Add("cFree9", "a.cFree9");
|
|
value.Add("cFree10", "a.cFree10");
|
|
value.Add("Colspan", "a.Colspan");
|
|
|
|
value.Add("MTIME", "GETDATE()");
|
|
value.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
|
|
value.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
|
|
value.Add("WorkPoint", "'" + WorkPoint + "'");
|
|
|
|
//插入新增数据->ICSExtension表
|
|
sql += ICSHelper.InsertSQL("ICSExtension", value)
|
|
+ @"#TempExtension a
|
|
LEFT JOIN ICSExtension b ON a.ProjectCode+'~'+a.cBatch+'~'+a.Version+'~'+a.Brand+'~'+a.cFree1+'~'+a.cFree2+'~'+a.cFree3+'~'+a.cFree4+'~'+a.cFree5+'~'+a.cFree6+'~'+a.cFree7+'~'+a.cFree8+'~'+a.cFree9+'~'+a.cFree10=b.Colspan and a.WorkPoint=b.WorkPoint
|
|
WHERE b.Colspan IS NULL";
|
|
// sql += @"--删除数据
|
|
// --DELETE ICSDeliveryNotice WHERE DNDetailID NOT IN ( SELECT AutoID FROM {1}.dbo.PU_ArrivalVouchs)and ICSDeliveryNotice.EATTRIBUTE1='1' and ASNCode is NULL
|
|
|
|
//SELECT a.DNDetailID INTO #tableICSDeliveryNotice
|
|
//FROM ICSDeliveryNotice a With(NoLock)
|
|
//LEFT JOIN {1}.dbo.[PU_ArrivalVouchs] b With(NoLock) ON a.DNDetailID=convert(varchar(50),b.AutoID)
|
|
// WHERE a.WorkPoint='{0}' and b.AutoID IS NULL --and a.EATTRIBUTE1='1' and a.ASNCode is NULL
|
|
|
|
// DELETE ICSDeliveryNotice
|
|
// WHERE WorkPoint='{0}' and DNDetailID IN ( SELECT DNDetailID from #tableICSDeliveryNotice)
|
|
|
|
|
|
// ";
|
|
Dictionary<string, string> values = new Dictionary<string, string>();
|
|
|
|
values.Add("DNCode", "a.DNCode");
|
|
values.Add("Sequence", "a.Sequence");
|
|
values.Add("VenCode", "a.VenCode");
|
|
values.Add("DepCode", "a.DepCode");
|
|
values.Add("DNType", "a.DNType");
|
|
values.Add("InvCode", "a.InvCode");
|
|
values.Add("Quantity", "abs(a.Quantity)");
|
|
values.Add("Amount", "a.Amount");
|
|
values.Add("UnitPrice", "a.UnitPrice");
|
|
values.Add("Currency", "a.Currency");
|
|
values.Add("Status", "a.Status");
|
|
values.Add("WHCode", "a.WHCode");
|
|
values.Add("CreatePerson", "a.CreatePerson");
|
|
values.Add("CreateDateTime", "a.CreateDateTime");
|
|
values.Add("POID", "a.POID");
|
|
values.Add("PODetailID", "a.PODetailID");
|
|
values.Add("DNDetailID", "a.DNDetailID");
|
|
values.Add("DNID", "a.DNID");
|
|
values.Add("ExtensionID", "c.ID");
|
|
values.Add("EATTRIBUTE1", "''");
|
|
//更新存在数据
|
|
sql += ICSHelper.UpdateSQL("ICSDeliveryNotice", values)
|
|
+ @" #ICSDelive a
|
|
INNER JOIN ICSDeliveryNotice b ON a.DNDetailID=b.DNDetailID and a.WorkPoint=b.WorkPoint
|
|
inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
|
|
WHERE a.WorkPoint='" + WorkPoint + "' and b.EATTRIBUTE2=0 ";
|
|
values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
|
|
values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
|
|
values.Add("WorkPoint", "'" + WorkPoint + "'");
|
|
values.Add("MTIME", "a.MTIME");
|
|
values.Add("ID", "NEWID()");
|
|
values.Add("RCVQuantity", "0");
|
|
values.Add("EATTRIBUTE2", "'0'");
|
|
//values.Add("ErpAutoID", "a.ErpAutoID");
|
|
//values.Add("ErpID", "a.ErpID");
|
|
//values.Add("iFQuantity", "a.iFQuantity");
|
|
|
|
//插入新增数据
|
|
sql += ICSHelper.InsertSQL("ICSDeliveryNotice", values)
|
|
+ @" #ICSDelive a
|
|
LEFT JOIN ICSDeliveryNotice b ON a.DNDetailID=b.DNDetailID and a.WorkPoint=b.WorkPoint
|
|
inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
|
|
WHERE b.DNDetailID IS NULL and a.WorkPoint='" + WorkPoint + "' ";
|
|
sql += "DROP TABLE #ICSDelive ";
|
|
sql += " DROP TABLE #TempExtension " +
|
|
" DROP TABLE #tableICSDeliveryNotice";
|
|
sql = string.Format(sql, WorkPoint, erpName);
|
|
ICSHelper.ExecuteDate(conStr, sql);
|
|
#endregion
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.ToString());
|
|
}
|
|
}
|
|
|
|
|
|
public class DYS
|
|
{
|
|
public int pageIndex;
|
|
public int pageSize;
|
|
public bool isSum;
|
|
public List<DYSs> simpleVOs;
|
|
public List<DYSq> queryOrders;
|
|
}
|
|
public class DYSs
|
|
{
|
|
public string field;
|
|
public string op;
|
|
public string value1;
|
|
}
|
|
public class DYSq
|
|
{
|
|
public string field;
|
|
public string order;
|
|
}
|
|
|
|
// {
|
|
// "pageIndex": 7,
|
|
// "pageSize": 500,
|
|
// "isSum": true,
|
|
// "simpleVOs": [
|
|
// {
|
|
// "field": "modifyTime",
|
|
// "op": "gt",
|
|
// "value1": "2025-03-30"
|
|
|
|
// }
|
|
// ],
|
|
// "queryOrders": [
|
|
// {
|
|
// "field": "modifyTime",
|
|
// "order": "desc"
|
|
|
|
// }
|
|
// ]
|
|
//}
|
|
}
|
|
}
|