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.
256 lines
15 KiB
256 lines
15 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Quartz;
|
|
|
|
|
|
namespace ICSSoft.FromERP
|
|
{
|
|
/// <summary>
|
|
/// 销售发货退货单
|
|
/// </summary>
|
|
public class ICSSoDispatch : 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)
|
|
{
|
|
string erpName = ICSHelper.GetConfigString()["ERPDB"];
|
|
string WorkPoint = dr["WorkPointCode"].ToString();
|
|
string Class = this.GetType().Name + WorkPoint;
|
|
erpName = string.Format(erpName, WorkPoint);
|
|
|
|
|
|
#region SQL
|
|
string sql = @"SELECT * into #TempSO FROM (
|
|
SELECT A1.DocNo AS SDNCode,
|
|
CAST(A2.DocLineNo AS NVARCHAR(50)) AS Sequence,
|
|
ISNULL(A2.SONo,'') AS SOCode,
|
|
CAST(A2.SrcDocLineNo AS NVARCHAR(50)) AS SOSequence,
|
|
A3.Code AS CusCode,
|
|
A4.Name AS CusName,
|
|
'1' AS Type,
|
|
A5.Code AS InvCode,
|
|
A7.Code AS WHCode,
|
|
A2.ShipQtyInvAmount AS Quantity,
|
|
0 as Amount,
|
|
A1.CreatedBy AS CreatePerson,
|
|
A1.CreatedOn as CreateDateTime,
|
|
'1' AS Status,
|
|
CAST(A1.ID AS NVARCHAR(50)) AS SDNID,
|
|
CAST(A2.ID AS NVARCHAR(50)) AS SDNDetailID,
|
|
ISNULL(A2.ModifiedOn ,A2.CreatedOn) AS MTIME,
|
|
isnull(A1.ShipConfirmDate,getdate()) AS ArriveDate,
|
|
isnull(A13.Code,'') ProjectCode,isnull(A2.LotInfo_LotCode,'') 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,
|
|
'' as EATTRIBUTE1
|
|
,A11.Code as WorkPoint
|
|
FROM {1}.dbo.SM_Ship A1
|
|
LEFT JOIN {1}.dbo.SM_ShipLine A2 ON A2.Ship=A1.ID
|
|
LEFT JOIN {1}.dbo.CBO_Customer A3 ON A1.OrderBy_Customer=A3.ID
|
|
LEFT JOIN {1}.dbo.CBO_Customer_Trl A4 ON A4.ID = A3.ID AND A4.SysMLFlag='zh-CN'
|
|
LEFT JOIN {1}.dbo.CBO_ItemMaster A5 ON A2.ItemInfo_ItemID=A5.ID
|
|
LEFT JOIN {1}.dbo.CBO_ItemMaster_Trl A6 ON A6.ID = A5.ID AND A6.SysMLFlag='zh-CN'
|
|
LEFT JOIN {1}.dbo.CBO_Wh A7 ON A2.WH=A7.ID
|
|
LEFT JOIN {1}.dbo.CBO_Wh_Trl A8 ON A8.ID = A7.ID AND A8.SysMLFlag='zh-CN'
|
|
LEFT JOIN {1}.dbo.Base_UOM A9 ON A2.InvUom=A9.ID
|
|
LEFT JOIN {1}.dbo.Base_UOM_Trl A10 ON A10.ID = A9.ID AND A10.SysMLFlag='zh-CN'
|
|
LEFT JOIN {1}.dbo.Base_Organization A11 ON A1.Org=A11.ID
|
|
LEFT JOIN {1}.dbo.Base_Organization_Trl A12 ON A12.ID = A11.ID AND A12.SysMLFlag='zh-CN'
|
|
LEFT JOIN {1}.dbo.CBO_Project A13 ON A2.Project=A13.ID
|
|
WHERE A1.Status=2
|
|
UNION ALL
|
|
SELECT A1.DocNo AS SDNCode,
|
|
CAST(A2.DocLineNo AS NVARCHAR(10)) AS Sequence,
|
|
A2.SrcDoc_SrcDocNo AS SOCode,
|
|
CAST(A2.SrcDoc_SrcDocLineNo AS NVARCHAR(50)) AS SOSequence,
|
|
A1.RtnCustomer_Code AS CusCode,
|
|
A1.RtnCustomer_ShortName AS CusName,
|
|
'2' AS Type,
|
|
A2.ItemInfo_ItemCode AS InvCode,
|
|
A6.Code AS WHCode,
|
|
A2.ArriveQtyPU AS Quantity,
|
|
0 as Amount,
|
|
A1.CreatedBy AS CreatePerson,
|
|
A1.CreatedOn as CreateDateTime,
|
|
'1' AS Status,
|
|
CAST(A1.ID AS NVARCHAR(50)) AS SDNID,
|
|
CAST(A2.ID AS NVARCHAR(50)) AS SDNDetailID,
|
|
ISNULL(A2.ModifiedOn ,A2.CreatedOn) AS MTIME,
|
|
A2.ArrivedTime AS ArriveDate,
|
|
isnull(A12.Code,'') ProjectCode,isnull(A13.LotCode,'') 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,
|
|
'' as EATTRIBUTE1
|
|
,A10.Code as WorkPoint
|
|
FROM {1}.dbo.PM_Receivement A1
|
|
LEFT JOIN {1}.dbo.PM_RcvLine A2 ON A2.Receivement=A1.ID
|
|
LEFT JOIN {1}.dbo.PM_RcvLine_Trl A3 ON A2.ID=A3.ID AND A3.SysMLFlag='zh-CN'
|
|
LEFT JOIN {1}.dbo.PM_RcvDocType A4 ON A1.RcvDocType=A4.ID
|
|
LEFT JOIN {1}.dbo.PM_RcvDocType_Trl A5 ON A5.ID = A4.ID AND A5.SysMLFlag='zh-CN'
|
|
LEFT JOIN {1}.dbo.CBO_Wh A6 ON A2.Wh=A6.ID
|
|
LEFT JOIN {1}.dbo.CBO_Wh_Trl A7 ON A7.ID = A6.ID AND A7.SysMLFlag='zh-CN'
|
|
LEFT JOIN {1}.dbo.Base_UOM A8 ON A2.PriceUOM=A8.ID
|
|
LEFT JOIN {1}.dbo.Base_UOM_Trl A9 ON A9.ID = A8.ID AND A9.SysMLFlag='zh-CN'
|
|
LEFT JOIN {1}.dbo.Base_Organization A10 ON A1.Org=A10.ID
|
|
LEFT JOIN {1}.dbo.Base_Organization_Trl A11 ON A11.ID = A10.ID AND A11.SysMLFlag='zh-CN'
|
|
LEFT JOIN {1}.dbo.CBO_Project A12 ON A2.Project=A12.ID
|
|
LEFT JOIN {1}.dbo.Lot_LotMaster A13 ON A2.InvLot=A13.ID
|
|
WHERE A1.ReceivementType=2 AND A1.Status=3
|
|
) t
|
|
where t.MTIME>=@LastTime
|
|
|
|
update #TempSO 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 #TempSO
|
|
|
|
IF NOT EXISTS(SELECT * FROM #TempSO)
|
|
RETURN";
|
|
sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempSO");
|
|
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 ICSSDN WHERE SDNDetailID NOT IN (SELECT CAST(AutoID as VARCHAR) FROM {1}.dbo.DispatchLists)
|
|
|
|
SELECT * INTO #tableICSSDN FROM(
|
|
SELECT a.SDNDetailID FROM ICSSDN a With(NoLock)
|
|
LEFT JOIN {1}.dbo.[SM_ShipLine] b With(NoLock) ON a.SDNDetailID=CAST(b.ID as VARCHAR)
|
|
WHERE a.WorkPoint='{0}' and b.ID IS NULL
|
|
UNION ALL
|
|
SELECT a.SDNDetailID FROM ICSSDN a With(NoLock)
|
|
LEFT JOIN {1}.dbo.[PM_RcvLine] b With(NoLock) ON a.SDNDetailID=CAST(b.ID as VARCHAR)
|
|
WHERE a.WorkPoint='{0}' and b.ID IS NULL
|
|
)
|
|
|
|
DELETE ICSSDN
|
|
WHERE WorkPoint='{0}' and SDNDetailID IN ( SELECT SDNDetailID from #tableICSSDN)
|
|
|
|
";
|
|
Dictionary<string, string> values = new Dictionary<string, string>();
|
|
|
|
values.Add("SDNCode", "a.SDNCode");
|
|
values.Add("Sequence", "a.Sequence");
|
|
values.Add("SOCode", "a.SOCode");
|
|
values.Add("SOSequence", "a.SOSequence");
|
|
values.Add("CusCode", "a.CusCode");
|
|
values.Add("CusName", "a.CusName");
|
|
values.Add("Type", "a.Type");
|
|
values.Add("InvCode", "a.InvCode");
|
|
values.Add("WHCode", "a.WHCode");
|
|
values.Add("ArriveDate", "a.ArriveDate");
|
|
values.Add("Quantity", "a.Quantity");
|
|
values.Add("EATTRIBUTE1", "a.EATTRIBUTE1");
|
|
values.Add("Amount", "a.Amount");
|
|
values.Add("CreatePerson", "a.CreatePerson");
|
|
values.Add("CreateDateTime", "a.CreateDateTime");
|
|
values.Add("Status", "a.Status");
|
|
values.Add("SDNID", "a.SDNID");
|
|
values.Add("ExtensionID", "c.ID");
|
|
values.Add("SDNDetailID", "a.SDNDetailID");
|
|
//更新存在数据
|
|
sql += ICSHelper.UpdateSQL("ICSSDN", values)
|
|
+ @" #TempSO a
|
|
INNER JOIN ICSSDN b ON a.SDNDetailID=b.SDNDetailID and a.WorkPoint=b.WorkPoint
|
|
inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
|
|
WHERE a.WorkPoint='" + WorkPoint + "' ";
|
|
values.Add("MTIME", "a.MTIME");
|
|
values.Add("ID", "NEWID()");
|
|
values.Add("SDNQuantity", "0");
|
|
values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
|
|
values.Add("MUSERNAME", "'" + ConstWorkPoint.Musername + "'");
|
|
values.Add("WorkPoint", "'" + WorkPoint + "'");
|
|
//插入新增数据
|
|
sql += ICSHelper.InsertSQL("ICSSDN", values)
|
|
+ @" #TempSO a
|
|
LEFT JOIN ICSSDN b ON a.SDNDetailID=b.SDNDetailID and a.WorkPoint=b.WorkPoint
|
|
inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
|
|
WHERE b.SDNDetailID IS NULL and a.WorkPoint='" + WorkPoint + @"'
|
|
";
|
|
sql += " DROP TABLE #TempSO";
|
|
sql += " DROP TABLE #TempExtension" +
|
|
" DROP TABLE #tableICSSDN";
|
|
sql = string.Format(sql, WorkPoint, erpName);
|
|
ICSHelper.ExecuteDate(conStr, sql);
|
|
#endregion
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|