纽威
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.
 
 
 
 
 

280 lines
17 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Quartz;
namespace ICSSoft.FromERP
{
public class ICSBOM : 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 DISTINCT g.cInvDefine1,--存货自定义项1
c.partID ITEMID,
f.partID SBITEMID,
K.partID SBSITEMID,
c.InvCode as ITEMCODE,--存货编码
f.InvCode as SBITEMCODE,--存货编码
K.InvCode as SBSITEMCODE,--替代料编码
d.BaseQtyD SBITEMQTY, --BaseQtyD 基本用量- --单机用量
d.BaseQtyN, --AuxBaseQtyN 辅助基本用量
a.VersionEffDate SBITEMEFFTIME,--VersionEffDate 版本生效日
a.VersionEndDate SBITEMINVTIME,--VersionEndDate 版本失效日
d.SortSeq SEQ, --SortSeq 序号 SEQ
d.SortSeq SBITEMSEQ, --SortSeq 序号 SEQ
e.WIPType SBITEMCONTYPE, --WIPType WIP属性(1入库/2工序/3领料/4虚拟) ,
a.Version SBOMVER ,--Version 母料版本号
a.AuditStatus,--Version BOM状态
a.CreateDate,a.CreateUser,a.ModifyDate,a.ModifyUser,a.cCurrentAuditor,--当前审批人
d.CompScrap, --CompScrap 子件损耗率
d.ByproductFlag, --ByproductFlag 是否联副产品
d.ProductType, --ProductType 产出类型(1:空/2:联产品/3:副产品)
i.Factor ReplaceFactor,--替代比例
i.EffBegDate ReplaceEffBegDate,--生效日期
i.EffEndDate ReplaceEffEndDate,--失效日期
ISNULL(a.ModifyDate, a.CreateDate) AS MTIME ,
a.RelsTime as cAuditDate, --审核时间
i.ReplaceFlag,--是否替换料
i.OpComponentId,-- 子件Id
i.Sequence ReplaceSequence,--替代序号
a.VersionDesc --VersionDesc 版本说明
,moall.OpComponentId as moOpComponentId --工单中使用的BOM子件
, '{0}' as WorkPoint
into #TempBOM
FROM {1}.dbo.bom_bom a -- BOM资料
INNER JOIN {1}.dbo.bom_parent b on a.BomId = b.BomId --BOM母件资料
INNER JOIN {1}.dbo.bas_part c on b.ParentId = c.PartId --物料表
INNER JOIN {1}.dbo.bom_opcomponent d on a.BomId=d.BomId --BOM子件资料
INNER JOIN {1}.dbo.bas_part f on d.ComponentId = f.PartId
INNER JOIN {1}.dbo.bom_opcomponentopt e ON d.OptionsId=e.OptionsId -- 子件选项资料
left JOIN {1}.dbo.bom_opcomponentsub i ON d.OpComponentId =i.OpComponentId --子件替代料
left join {1}.dbo.inventory g on c.InvCode=g.cInvCode --存货档案
LEFT JOIN {1}.dbo.bas_part K ON K.PartId=i.PartId
LEFT JOIN {1}.dbo.mom_moallocate moall ON moall.OpComponentId=d.OpComponentId
WHERE ISNULL(a.ModifyDate, a.CreateDate)>=@LastTime
IF NOT EXISTS(SELECT * FROM #TempBOM)
RETURN";
sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempBOM");
sql += "\r\n";
sql += @"--删除数据
-- DELETE ICSSBOM WHERE moOpComponentId NOT IN (SELECT OpComponentId FROM {1}.dbo.bom_opcomponent)
SELECT a.moOpComponentId INTO #tableICSSBOM
FROM ICSSBOM a With(NoLock)
LEFT JOIN {1}.dbo.[bom_opcomponent] b With(NoLock) ON a.moOpComponentId=b.OpComponentId
WHERE a.WorkPoint='{0}' and b.OpComponentId IS NULL
DELETE ICSSBOM
WHERE WorkPoint='{0}' and moOpComponentId IN ( SELECT moOpComponentId from #tableICSSBOM)
";
Dictionary<string, string> values = new Dictionary<string, string>();
values.Add("SBOMVER", "a.SBOMVER");
values.Add("ITEMID", "a.ITEMID");
values.Add("SBITEMID", "a.SBITEMID");
values.Add("SBSITEMID", "a.SBSITEMID");
values.Add("ITEMCODE", "a.ITEMCODE");
values.Add("SBITEMCODE", "a.SBITEMCODE");
values.Add("SBSITEMCODE", "a.SBSITEMCODE");
values.Add("SBITEMQTY", "a.SBITEMQTY");
values.Add("BaseQtyN", "a.BaseQtyN");
values.Add("SBITEMEFFTIME", "a.SBITEMEFFTIME");
values.Add("SBITEMINVTIME", "a.SBITEMINVTIME");
values.Add("SEQ", "a.SEQ");
values.Add("SBITEMCONTYPE", "a.SBITEMCONTYPE");
values.Add("CreateDate", "a.CreateDate");
values.Add("CreateUser", "a.CreateUser");
values.Add("ModifyDate", "a.ModifyDate");
values.Add("ModifyUser", "a.ModifyUser");
values.Add("cCurrentAuditor", "a.cCurrentAuditor");
values.Add("CompScrap", "a.CompScrap");
values.Add("ByproductFlag", "a.ByproductFlag");
values.Add("ProductType", "a.ProductType");
values.Add("ReplaceFactor", "a.ReplaceFactor");
values.Add("ReplaceEffBegDate", "a.ReplaceEffBegDate");
values.Add("ReplaceEffEndDate", "a.ReplaceEffEndDate");
values.Add("VersionDesc", "a.VersionDesc");
values.Add("SBITEMSEQ", "a.SBITEMSEQ");
values.Add("MTIME", "a.MTIME");
values.Add("moOpComponentId", "a.moOpComponentId");
values.Add("AuditStatus", "a.AuditStatus");
//更新存在数据
sql += ICSHelper.UpdateSQL("b", values)
+ @" #TempBOM a
INNER JOIN ICSSBOM b ON a.ITEMID=b.ITEMID AND a.SBITEMID=b.SBITEMID and a.WorkPoint=b.WorkPoint
WHERE a.WorkPoint='" + WorkPoint + "' ";
values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
values.Add("WorkPoint", "'" + WorkPoint + "'");
sql += "\r\n";
//插入新增数据
sql += ICSHelper.InsertSQL("ICSSBOM", values)
+ @" #TempBOM a
LEFT JOIN ICSSBOM b ON a.ITEMID=b.ITEMID AND a.SBITEMID=b.SBITEMID and a.WorkPoint=b.WorkPoint
WHERE b.ITEMCODE IS NULL and a.WorkPoint='" + WorkPoint + "' ";
sql += " DROP TABLE #TempBOM " +
"DROP TABLE #tableICSSBOM";
sql = string.Format(sql, WorkPoint, erpName);
ICSHelper.ExecuteDate(conStr, sql);
#endregion
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
// public void Execute_bak20201201()
// {
// try
// {
// string conStr = ICSHelper.GetConnectString();
// string Namespace = this.GetType().Namespace;
// string Class = this.GetType().Name;
// #region SQL
// string sql = @" SELECT g.cInvDefine1,--存货自定义项1
// a.Version,--Version 版本号
// a.VersionDesc,--VersionDesc 版本说明
// a.VersionEffDate,--VersionEffDate 版本生效日
// a.VersionEndDate,--VersionEndDate 版本失效日
// c.InvCode as cInvCode ,--存货编码
// f.InvCode as SubcInvCode ,--存货编码
// e.WIPType, --WIPType WIP属性(1入库/2工序/3领料/4虚拟)
// d.SortSeq, --SortSeq 序号
// d.BaseQtyN, --AuxBaseQtyN 辅助基本用量
// d.BaseQtyD, --BaseQtyD 基本用量-分母
// d.ByproductFlag, --ByproductFlag 是否联副产品
// d.ProductType, --ProductType 产出类型(1:空/2:联产品/3:副产品)
// d.CompScrap, --CompScrap 子件损耗率
// a.CreateDate,a.CreateUser,a.ModifyDate,a.ModifyUser,a.cCurrentAuditor,--当前审批人
// a.RelsTime as cAuditDate, --审核时间
// i.ReplaceFlag,--是否替换料
// i.OpComponentId,-- 子件Id
// i.Sequence ReplaceSequence,--替代序号
// K.InvCode as ReplaceInvCode ,--替代料编码
// i.Factor ReplaceFactor,--替代比例
// i.EffBegDate ReplaceEffBegDate,--生效日期
// i.EffEndDate ReplaceEffEndDate,--失效日期
// ISNULL(a.ModifyDate, a.CreateDate) AS MTIME
// into #TempBOM
// FROM {1}.dbo.bom_bom a -- BOM资料
// INNER JOIN {1}.dbo.bom_parent b on a.BomId = b.BomId --BOM母件资料
// INNER JOIN {1}.dbo.bas_part c on b.ParentId = c.PartId --物料表
// INNER JOIN {1}.dbo.bom_opcomponent d on a.BomId=d.BomId --BOM子件资料
// INNER JOIN {1}.dbo.bas_part f on d.ComponentId = f.PartId
// INNER JOIN {1}.dbo.bom_opcomponentopt e ON d.OptionsId=e.OptionsId -- 子件选项资料
// left JOIN {1}.dbo.bom_opcomponentsub i ON d.OpComponentId =i.OpComponentId --子件替代料
// left join {1}.dbo.inventory g on c.InvCode=g.cInvCode --存货档案
// LEFT JOIN {1}.dbo.bas_part K ON K.PartId=i.PartId
//
// WHERE ISNULL(a.ModifyDate, a.CreateDate)>=@LastTime
// IF NOT EXISTS(SELECT * FROM #TempBOM)
// RETURN";
// sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempBOM");
// sql += "\r\n";
// sql += @"--删除数据
// DELETE ICSBOM WHERE cInvCode NOT IN (SELECT InvCode FROM {1}.dbo.bas_part) ";
// Dictionary<string, string> values = new Dictionary<string, string>();
// values.Add("Version", "a.Version");
// values.Add("VersionDesc", "a.VersionDesc");
// values.Add("VersionEffDate", "a.VersionEffDate");
// values.Add("VersionEndDate", "a.VersionEndDate");
// values.Add("cInvCode", "a.cInvCode");
// values.Add("SubcInvCode", "a.SubcInvCode");
// values.Add("WIPType", "a.WIPType");
// values.Add("SortSeq", "a.SortSeq");
// values.Add("BaseQtyN", "a.BaseQtyN");
// values.Add("BaseQtyD", "a.BaseQtyD");
// values.Add("ByproductFlag", "a.ByproductFlag");
// values.Add("ProductType", "a.ProductType");
// values.Add("CompScrap", "a.CompScrap");
// values.Add("CreateDate", "a.CreateDate");
// values.Add("CreateUser", "a.CreateUser");
// values.Add("ModifyDate", "a.ModifyDate");
// values.Add("ModifyUser", "a.ModifyUser");
// values.Add("cCurrentAuditor", "a.cCurrentAuditor");
// values.Add("cAuditDate", "a.cAuditDate");
// values.Add("ReplaceFlag", "a.ReplaceFlag");
// values.Add("OpComponentId", "a.OpComponentId");
// values.Add("ReplaceSequence", "a.ReplaceSequence");
// values.Add("ReplaceInvCode", "a.ReplaceInvCode");
// values.Add("ReplaceFactor", "a.ReplaceFactor");
// values.Add("ReplaceEffBegDate", "a.ReplaceEffBegDate");
// values.Add("ReplaceEffEndDate", "a.ReplaceEffEndDate");
// values.Add("MTIME", "a.MTIME");
// //更新存在数据
// sql += ICSHelper.UpdateSQL("b", values)
// + @" #TempBOM a
// INNER JOIN ICSBOM b ON a.cInvCode=b.cInvCode ";
// values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
// values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
// values.Add("WorkPoint", "'" + WorkPoint + "'");
// sql += "\r\n";
// //插入新增数据
// sql += ICSHelper.InsertSQL("ICSBOM", values)
// + @" #TempBOM a
// LEFT JOIN ICSBOM b ON a.cInvCode=b.cInvCode
// WHERE b.cInvCode 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());
// }
// }
}
}