IcsFromERPJob
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.

117 lines
5.6 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;
namespace ICSSoft.FromERP
{
/// <summary>
/// 委外采购订单子件
/// </summary>
public class ICSOMBOM : 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;
#region SQL
string sql = @"SELECT c.cCode AS OMCODE ,
b.cInvCode AS ITEMCODE,
b.iVouchRowNo AS OMSEQ,
a.cInvCode AS BOMITEMCODE,
CAST(a.MOMaterialsID AS NVARCHAR(50)) AS BOMITEMECN,
d.cInvName AS BOMITEMNAME,
d.cInvStd AS BOMITEMDESC,
'1' AS BOMITEMSTATUS,
GETDATE() AS BOMITEMEFFTIME,
GETDATE() AS BOMITEMINVTIME,
CASE WHEN d.bCutMantissa='1' AND d.bKCCutMantissa='1' THEN CEILING(a.iQuantity) ELSE a.iQuantity END AS BOMITEMQTY,
a.cWhCode AS BOMITEMLOCATION,
'' AS BOMITEMUOM,
ISNULL(a.irowno,0) AS BOMLINE,
ISNULL(c.dVerifyTime,ISNULL(c.dModifyTime, c.dCreateTime)) AS MTIME
INTO #TempBOM
FROM {0}.dbo.OM_MOMaterials a
INNER JOIN {0}.dbo.OM_MODetails b ON a.MoDetailsID = b.MoDetailsID
LEFT JOIN {0}.dbo.OM_MOMain c ON b.MOID = c.MOID
LEFT JOIN {0}.dbo.Inventory d ON a.cInvCode = d.cInvCode
LEFT JOIN {0}.dbo.ComputationUnit g ON d.cComUnitCode = g.cComunitCode
WHERE ISNULL(c.cverifier, '')<>'' AND ISNULL(c.dVerifyTime,ISNULL(c.dModifyTime, c.dCreateTime))>=@LastTime
IF NOT EXISTS(SELECT * FROM #TempBOM)
RETURN";
sql = ICSHelper.Time(Namespace, Class, ConstWorkPoint.WorkPoint, sql, "#TempBOM");
sql += "\r\n";
sql += @"--删除数据
DELETE ICSOMBOM WHERE BOMITEMECN NOT IN (SELECT MOMaterialsID FROM {0}.dbo.OM_MOMaterials) ";
Dictionary<string, string> values = new Dictionary<string, string>();
values.Add("OMCODE", "a.OMCODE");
values.Add("ITEMCODE", "a.ITEMCODE");
values.Add("OMSEQ", "a.OMSEQ");
values.Add("BOMITEMCODE", "a.BOMITEMCODE");
values.Add("BOMITEMNAME", "a.BOMITEMNAME");
values.Add("BOMITEMDESC", "a.BOMITEMDESC");
values.Add("BOMITEMSTATUS", "a.BOMITEMSTATUS");
values.Add("BOMITEMEFFTIME", "a.BOMITEMEFFTIME");
values.Add("BOMITEMINVTIME", "a.BOMITEMEFFTIME");
values.Add("BOMITEMQTY", "a.BOMITEMQTY");
values.Add("BOMITEMUOM", "a.BOMITEMUOM");
values.Add("BOMLINE", "a.BOMLINE");
values.Add("BOMITEMLOCATION", "a.BOMITEMLOCATION");
values.Add("MTIME", "a.MTIME");
//values.Add("WorkPoint", "a.WorkPoint");
//更新存在数据
sql += ICSHelper.UpdateSQL("b", values)
+ @" #TempBOM a
INNER JOIN ICSOMBOM b ON a.BOMITEMECN=b.BOMITEMECN
";
values.Add("HasQTY", "'0'");
values.Add("BOMITEMECN", "a.BOMITEMECN");
values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
values.Add("WorkPoint", "'" + ConstWorkPoint.WorkPoint + "'");
sql += "\r\n";
//插入新增数据
sql += ICSHelper.InsertSQL("ICSOMBOM", values)
+ @" #TempBOM a
LEFT JOIN ICSOMBOM b ON a.BOMITEMECN=b.BOMITEMECN
WHERE b.BOMITEMECN IS NULL
";
sql += "DROP TABLE #TempBOM";
sql = string.Format(sql, ICSHelper.GetConfigString()["ERPDB"]);
ICSHelper.ExecuteDate(conStr, sql);
#endregion
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
}
}