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.
236 lines
14 KiB
236 lines
14 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 ICSPO : 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
|
|
CAST (A1.ID AS VARCHAR(50)) AS PODetailID,
|
|
A.ID AS POID,
|
|
A.DocNO AS POCode,
|
|
isnull(A1.SrcDocInfo_SrcDoc_EntityID ,'')as PRDetailID,
|
|
isnull(A1.SrcDocInfo_SrcDocLine_EntityID,'') as PRID,
|
|
CAST (A1.DocLineNo AS VARCHAR(50)) AS PORow,
|
|
A.BusinessDate AS PODate,
|
|
A2.Code AS VenCode,
|
|
A3.Name AS VenName,
|
|
A6.Code AS PersonCode,
|
|
A7.Name AS PersonName,
|
|
A8.Code AS GroupCode,
|
|
A9.Name AS GroupName,
|
|
A5.Name AS CurrencyName,
|
|
'' AS SubjectCode,
|
|
'' AS ProjectType,
|
|
A1.ItemInfo_ItemCode AS InvCode,
|
|
A1.ReqQtyTU AS Quantity,
|
|
A.CreatedBy AS CreatePerson,
|
|
A.CreatedOn as CreateDateTime,
|
|
A20.PlanArriveDate AS PreArriveDate,
|
|
'2' AS Status,
|
|
0 AS Amount,
|
|
'1' AS POType,
|
|
'BS' AS ServerModel,
|
|
A1.NetFinallyPriceTC AS Price,
|
|
ISNULL(A28.Code,'') AS ORDERNO,
|
|
ISNULL(A1.ModifiedOn ,A1.CreatedOn) AS MTIME,
|
|
A16.Description AS MEMO,
|
|
'' AS WHCode,
|
|
A1.DescFlexSegments_PubDescSeg4 AS ReMark,
|
|
A.CreatedBy AS DateTime1User,
|
|
A.BusinessDate AS DateTime1,
|
|
A.ApprovedBy AS DateTime2User,
|
|
A.ApprovedOn AS DateTime2,
|
|
A.POPriority AS ISUrgent,
|
|
--(CASE WHEN inv.bCheckBatch=1 THEN isnull(b.cBatch,'') ELSE '' END) as cBatch,
|
|
isnull(A28.Code,'') 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
|
|
,A30.Code as WorkPoint
|
|
INTO #TempPO
|
|
FROM {1}.dbo.PM_PurchaseOrder A
|
|
inner join {1}.dbo.PM_POLine A1 on A.ID=A1.PurchaseOrder
|
|
left join {1}.dbo.CBO_Supplier A2 on A.Supplier_Supplier=A2.ID
|
|
left join {1}.dbo.CBO_Supplier_Trl A3 on (A3.SysMLFlag='zh-CN') and (A2.ID=A3.ID)
|
|
left join {1}.dbo.Base_Currency A4 on (A.TC = A4.[ID])
|
|
left join {1}.dbo.[Base_Currency_Trl] A5 on (A5.SysMlFlag = 'zh-CN') and (A4.[ID] = A5.[ID])
|
|
left join {1}.dbo.[CBO_Operators] as A6 on (A.PurOper = A6.[ID])
|
|
left join {1}.dbo.[CBO_Operators_Trl] as A7 on (A7.SysMlFlag = 'zh-CN') and (A6.[ID] = A7.[ID])
|
|
left join {1}.dbo.CBO_Department as A8 on (A.PurDept = A8.[ID])
|
|
left join {1}.dbo.[CBO_Department_Trl] as A9 on (A9.SysMlFlag = 'zh-CN') and (A8.[ID] = A9.[ID])
|
|
left join {1}.dbo.PM_PODocType A12 on A.DocumentType=A12.ID
|
|
left join {1}.dbo.PM_PODocType_Trl A13 on A12.ID=A13.ID and A13.SysMLFlag='zh-CN'
|
|
left join {1}.dbo.Base_User A14 on A14.Name=A.CreatedBy
|
|
LEFT JOIN {1}.dbo.PM_POMemo A15 ON A15.PurchaseOrder=A.ID
|
|
LEFT JOIN {1}.dbo.PM_POMemo_Trl A16 ON A15.ID=A16.ID AND A16.SysMLFlag='zh-CN'
|
|
|
|
left join {1}.dbo.[CBO_ItemMaster] as A22 on (A1.[ItemInfo_ItemID] = A22.[ID])
|
|
left join {1}.dbo.[Base_UOM] as A24 on (A1.TradeUOM = A24.[ID])
|
|
left join {1}.dbo.[Base_UOM_Trl] as A25 on (A25.SysMlFlag = 'zh-CN') and (A24.[ID] = A25.[ID])
|
|
left join {1}.dbo.[Base_UOM] as A26 on (A1.PriceUOM = A26.[ID])
|
|
left join {1}.dbo.[Base_UOM_Trl] as A27 on (A27.SysMlFlag = 'zh-CN') and (A26.[ID] = A27.[ID])
|
|
left join {1}.dbo.CBO_Project as A28 on A1.Project =A28.ID
|
|
left join {1}.dbo.CBO_Project_Trl as A29 on (A29.SysMLFlag='zh-CN') and (A28.ID=A29.ID)
|
|
LEFT JOIN (SELECT POLine,MAX(PlanArriveDate) AS PlanArriveDate FROM {1}.dbo.PM_POShipLine GROUP BY POLine) A20 ON A1.ID=A20.POLine
|
|
LEFT JOIN {1}.dbo.Base_Organization A30 ON A.Org=A30.ID
|
|
where A.Status='2' AND A30.Code='{0}' and ISNULL(A1.ModifiedOn ,A1.CreatedOn)>=@LastTime
|
|
|
|
update #TempPO 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 #TempExtensionPO
|
|
from #TempPO
|
|
|
|
IF NOT EXISTS(SELECT * FROM #TempPO)
|
|
RETURN";
|
|
sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempPO");
|
|
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)
|
|
+ @"#TempExtensionPO 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 ICSPurchaseOrder WHERE PODetailID NOT IN (SELECT CAST(ID AS VARCHAR) FROM {1}.dbo.[PO_Podetails])
|
|
SELECT a.PODetailID INTO #tableICSPurchaseOrder
|
|
FROM ICSPurchaseOrder a With(NoLock)
|
|
LEFT JOIN {1}.dbo.[PM_POLine] b With(NoLock) ON a.PODetailID=CAST(b.ID AS VARCHAR)
|
|
WHERE a.WorkPoint='{0}' and b.ID IS NULL
|
|
|
|
DELETE ICSPurchaseOrder
|
|
WHERE WorkPoint='{0}' and PODetailID IN ( SELECT PODetailID from #tableICSPurchaseOrder)
|
|
|
|
";
|
|
Dictionary<string, string> values = new Dictionary<string, string>();
|
|
values.Add("POID", "a.POID");
|
|
values.Add("POCode", "a.POCode");//采购订单号
|
|
values.Add("Sequence", "a.PORow");//采购订单行号
|
|
values.Add("VenCode", "a.VenCode");//供应商代码
|
|
values.Add("DepCode", "a.GroupCode");//部门代码
|
|
values.Add("PersonCode", "a.PersonCode");//业务员代码
|
|
values.Add("InvCode", "a.InvCode");//物料代码
|
|
values.Add("Quantity", "a.Quantity");//数量
|
|
values.Add("Amount", "a.Amount");//辅计量
|
|
values.Add("UnitPrice", "a.Price");//价格
|
|
values.Add("Currency", "a.CurrencyName");//币种
|
|
values.Add("Status", "a.Status");
|
|
values.Add("CreatePerson", "a.CreatePerson");//创建人
|
|
values.Add("PlanArriveDate", "a.PreArriveDate");//预计到货日期
|
|
values.Add("CreateDateTime", "a.CreateDateTime");//业务员名称
|
|
values.Add("PRDetailID", "a.PRDetailID");
|
|
values.Add("PRID", "a.PRID");
|
|
values.Add("ExtensionID", "c.ID");
|
|
values.Add("PODetailID", "a.PODetailID");
|
|
//values.Add("POID", "a.POID");
|
|
values.Add("MTIME", "a.MTIME");
|
|
//更新存在数据
|
|
sql += ICSHelper.UpdateSQL("b", values)
|
|
+ @" #TempPO a
|
|
INNER JOIN ICSPurchaseOrder b ON a.PODetailID+a.POType=b.PODetailID+b.POType 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("PODetailID", "a.Free2");
|
|
//values.Add("POType", "a.POType");
|
|
//values.Add("ServerModel", "a.ServerModel");
|
|
|
|
values.Add("ID", "NEWID()");//ID
|
|
values.Add("POType", "a.POType");//采购类型
|
|
values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");//操作人
|
|
values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");//操作人姓名
|
|
values.Add("WorkPoint", "'" + WorkPoint + "'");//站点
|
|
values.Add("EATTRIBUTE1", "''");//站点
|
|
values.Add("ReleaseState", "'0'");//发布状态
|
|
//插入新增数据
|
|
sql += ICSHelper.InsertSQL("ICSPurchaseOrder", values)
|
|
+ @" #TempPO a
|
|
LEFT JOIN ICSPurchaseOrder b ON a.PODetailID=b.PODetailID and a.WorkPoint=b.WorkPoint
|
|
inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
|
|
WHERE b.PODetailID IS NULL and a.WorkPoint='" + WorkPoint + @"' ";
|
|
sql += " DROP TABLE #TempPO";
|
|
sql += " DROP TABLE #TempExtensionPO " +
|
|
" DROP TABLE #tableICSPurchaseOrder ";
|
|
sql = string.Format(sql, WorkPoint, erpName);
|
|
ICSHelper.ExecuteDate(conStr, sql);
|
|
#endregion
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|