徐莉
4 months ago
5 changed files with 447 additions and 0 deletions
-
BIN.vs/ICSSoft.FromERP/v14/.suo
-
159ICSSoft.FromERP/ICSInventoryFromU8.cs
-
3ICSSoft.FromERP/ICSSoft.FromERP.csproj
-
128ICSSoft.FromERP/IcsMainCategoryCodeFromU8.cs
-
157ICSSoft.FromERP/IcsSBomFromU8.cs
Binary file not shown.
@ -0,0 +1,159 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using Quartz; |
|||
|
|||
using System.Data; |
|||
|
|||
namespace ICSSoft.FromERP |
|||
{ |
|||
/// <summary>
|
|||
/// 物料档案(凯尔克)
|
|||
/// </summary>
|
|||
public class ICSInventoryFromU8 : 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 conERPStr = ICSHelper.GetERPConnectString();
|
|||
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 TenantId = dr["TenantId"].ToString(); |
|||
string TenantCode = dr["TenantCode"].ToString(); |
|||
string ErpId = dr["ErpID"].ToString(); //erpID
|
|||
string Class = this.GetType().Name + TenantCode; |
|||
erpName = string.Format(erpName, TenantId); |
|||
|
|||
#region SQL
|
|||
string sql = @"
|
|||
|
|||
select NEWID() AS ID, |
|||
a.cInvCode AS ItemCode, |
|||
CASE WHEN A.bSelf ='1' THEN '1' WHEN A.bPurchase='1' THEN '1' when a.bProxyForeign='1' THEN '2' |
|||
else '' end ItemFormAttribute, |
|||
dbo.GetReplaceStr(cInvName) AS ItemName, |
|||
a.cEngineerFigNo ItemDrawingNo, |
|||
'' ItemDesc, |
|||
dbo.GetReplaceStr(isnull(cInvAddCode,'')+'|'+isnull(cInvStd,'')) AS ItemStd, |
|||
|
|||
c.cComUnitName AS ItemUnit, |
|||
a.cInvCCode ItemMainCategoryCode, |
|||
b.cInvCName ClassName, |
|||
ISNULL(c.iChangRate,0) as ItemRate, |
|||
ISNULL(a.iMassDate,'') as EffectiveDays, |
|||
ISNULL(CONVERT(NVARCHAR(50),a.dModifyDate,21),'') MTime, |
|||
(case when isnull(a.fOutExcess,0)=0 then 0 else (case when isnull(a.fOutExcess,0)>5 then 3 else 2 end) end) 备料超额类型, |
|||
isnull(a.fOutExcess,0) 备料超额值 |
|||
|
|||
INTO #TempINV |
|||
FROM {1}.dbo.Inventory a with(nolock) |
|||
LEFT JOIN {1}.dbo.InventoryClass b with(nolock) ON a.cInvCCode = b.cInvCCode |
|||
LEFT JOIN {1}.dbo.ComputationUnit c with(nolock) ON a.cComUnitCode = c.cComunitCode |
|||
WHERE a.dEDate IS NULL AND a.dModifyDate>=@LastTime |
|||
ORDER BY cInvCode |
|||
|
|||
|
|||
IF NOT EXISTS(SELECT * FROM #TempINV) |
|||
RETURN";
|
|||
sql = string.Format(sql, ErpId, erpName); |
|||
sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempINV"); |
|||
|
|||
sql += @"--删除数据
|
|||
|
|||
SELECT a.ItemCode INTO #tableICSINVENTORY |
|||
FROM ICSINVENTORY a With(NoLock) |
|||
LEFT JOIN {1}.dbo.[Inventory] b With(NoLock) ON a.ItemCode=b.cInvCode |
|||
WHERE b.cInvCode is null |
|||
and a.TenantId='{0}' |
|||
|
|||
|
|||
DELETE ICSINVENTORY |
|||
WHERE TenantId='{0}' and ItemCode IN ( SELECT ItemCode from #tableICSINVENTORY) ";
|
|||
Dictionary<string, string> values = new Dictionary<string, string>(); |
|||
values.Add("ItemCode", "a.ItemCode");//物料编号
|
|||
values.Add("ItemName", "a.ItemName");//物料名称
|
|||
values.Add("ItemDesc", "a.ItemDesc");//物料描述
|
|||
values.Add("ItemStd", "a.ItemStd");//规格型号
|
|||
values.Add("ItemAttribute", "a.ItemFormAttribute");//产品属性(0:采购,1:自制,2:委外,3虚拟)
|
|||
values.Add("ItemAddCode", "a.INVPARSETYPE"); //产品代码(U8存货代码 )
|
|||
values.Add("ItemUnit", "a.ItemUnit");//主计量单位
|
|||
values.Add("ItemMainCategoryCode", "a.ItemMainCategoryCode");//大类编码
|
|||
values.Add("ItemRate", "a.ItemRate"); |
|||
values.Add("InvVersion", "''"); |
|||
values.Add("InvBrand", "''"); |
|||
values.Add("InvIQC", "0");//是否IQC检验
|
|||
values.Add("InvFQC", "0");//是否FQC检验
|
|||
values.Add("EffectiveEnable", "0");//
|
|||
values.Add("EffectiveDays", "a.EffectiveDays");//
|
|||
values.Add("BatchEnable", "1");//
|
|||
values.Add("LotEnable", "0");//
|
|||
values.Add("PrintEnable", "0");//
|
|||
values.Add("OverType", "a.备料超额类型");//超领类型(1:比例,2:数量,3:不管控)
|
|||
values.Add("OverValue", "a.备料超额值"); |
|||
values.Add("LastModificationTime", "a.Mtime");//操作时间
|
|||
values.Add("ItemType", "d.ItemType");//操作时间
|
|||
values.Add("ItemContype", "d.ItemContype");//操作时间
|
|||
values.Add("ItemControlType", "d.ItemControlType");//操作时间
|
|||
values.Add("ItemDrawingNo", "b.ItemDrawingNo");//产品图号
|
|||
|
|||
|
|||
//更新存在数据
|
|||
sql += ICSHelper.UpdateSQL("b", values) |
|||
+ @" #TempINV a
|
|||
INNER JOIN ICSINVENTORY b ON a.ItemCode=b.ItemCode |
|||
left join IcsMainCategoryCode d on b.ItemMainCategoryCode=d.ItemMainCategoryCode and b.TenantId=d.TenantId |
|||
WHERE b.TenantId='" + TenantId + "' ";
|
|||
|
|||
values.Add("CreationTime", "a.MTime");//操作人
|
|||
values.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
|
|||
values.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
|
|||
values.Add("TenantId", "'" + TenantId + "'");//站点
|
|||
//插入新增数据
|
|||
sql += ICSHelper.InsertSQL("ICSINVENTORY", values) |
|||
+ @" #TempINV a
|
|||
LEFT JOIN ICSINVENTORY b ON a.ItemCode=b.ItemCode and b.TenantId='{0}' |
|||
left join IcsMainCategoryCode d on b.ItemMainCategoryCode=d.ItemMainCategoryCode and b.TenantId=d.TenantId |
|||
WHERE 1=1 and b.ItemCode is null |
|||
";
|
|||
sql += " DROP TABLE #TempINV " + |
|||
" DROP TABLE #tableICSINVENTORY "; |
|||
sql = string.Format(sql, TenantId, erpName, ErpId); |
|||
|
|||
ICSHelper.ExecuteDate(conStr, sql); |
|||
#endregion
|
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
log.Error(ex.ToString()); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,128 @@ |
|||
using Quartz; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
namespace ICSSoft.FromERP |
|||
{ |
|||
/// <summary>
|
|||
/// 物料主分类(凯尔克)
|
|||
/// </summary>
|
|||
public class IcsMainCategoryCodeFromU8 : 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 conERPStr = ICSHelper.GetERPConnectString();
|
|||
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 TenantId = dr["TenantId"].ToString();//mes 组织
|
|||
string TenantCode = dr["TenantCode"].ToString(); |
|||
string ErpId = dr["ErpID"].ToString(); //erpID
|
|||
string Class = this.GetType().Name + TenantCode; |
|||
erpName = string.Format(erpName, TenantId); |
|||
|
|||
#region SQL
|
|||
string sql = @" select a.cInvCCode as ItemMainCategoryCode
|
|||
,b.cInvCCode as ItemMainCategoryName |
|||
,'' as ItemMainCategoryDesc |
|||
,getdate() MTime |
|||
,p.parentCode |
|||
INTO #TempItemCategory |
|||
from {1}.dbo.[InventoryClass] a with(nolock) |
|||
left join |
|||
( |
|||
select cc.cInvCCode,cc_p.cInvCCode parentCode |
|||
from {1}.dbo.InventoryClass cc with(nolock) |
|||
left join {1}.dbo.InventoryClass cc_p with(nolock) on cc.cInvCCode like cc_p.cInvCCode+'%' |
|||
and cc.iInvCGrade=cc_p.iInvCGrade+1 |
|||
) p ON a.cInvCCode=p.cInvCCode |
|||
where 1=1 |
|||
and A.ModifiedOn>=@LastTime |
|||
ORDER BY A.cInvCCode |
|||
|
|||
IF NOT EXISTS(SELECT * FROM #TempItemCategory) |
|||
RETURN";
|
|||
sql = string.Format(sql, ErpId, erpName); |
|||
sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempItemCategory"); |
|||
|
|||
|
|||
sql += @"--删除数据
|
|||
|
|||
SELECT a.ItemMainCategoryCode INTO #tableItemCategory |
|||
FROM IcsMainCategoryCode a With(NoLock) |
|||
LEFT JOIN {1}.dbo.[InventoryClass] b With(NoLock) ON a.ItemMainCategoryCode=b.cInvCCode |
|||
WHERE b.cInvCCode is null |
|||
and a.TenantId='{0}' |
|||
|
|||
DELETE IcsMainCategoryCode |
|||
WHERE TenantId='{0}' and ItemMainCategoryCode IN ( SELECT ItemMainCategoryCode from #tableItemCategory) ";
|
|||
Dictionary<string, string> values = new Dictionary<string, string>(); |
|||
values.Add("ItemMainCategoryCode", "a.ItemMainCategoryCode");//物料编号
|
|||
values.Add("ItemMainCategoryName", "a.ItemMainCategoryNAME");//物料名称
|
|||
values.Add("ItemMainCategoryDesc", "a.ItemMainCategoryDesc");//物料描述
|
|||
values.Add("LastModificationTime", "a.MTime");//操作时间
|
|||
values.Add("PCode", "a.parentCode");//操作人
|
|||
|
|||
//更新存在数据
|
|||
sql += ICSHelper.UpdateSQL("b", values) |
|||
+ @" #TempItemCategory a
|
|||
INNER JOIN IcsMainCategoryCode b ON a.ItemMainCategoryCode=b.ItemMainCategoryCode |
|||
WHERE b.TenantId='" + TenantId + "' ";
|
|||
|
|||
|
|||
|
|||
values.Add("CreationTime", "a.MTime");//操作人
|
|||
values.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
|
|||
values.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
|
|||
values.Add("TenantId", "'" + TenantId + "'");//站点
|
|||
//插入新增数据
|
|||
sql += ICSHelper.InsertSQL("IcsMainCategoryCode", values) |
|||
+ @" #TempItemCategory a
|
|||
LEFT JOIN IcsMainCategoryCode b ON a.ItemMainCategoryCode=b.ItemMainCategoryCode and b.TenantId='{0}' |
|||
WHERE 1=1 and b.ItemMainCategoryCode is null |
|||
|
|||
";
|
|||
sql += " DROP TABLE #TempItemCategory " + |
|||
" DROP TABLE #tableItemCategory "; |
|||
sql = string.Format(sql, TenantId, erpName,ErpId); |
|||
// return;
|
|||
ICSHelper.ExecuteDate(conStr, sql); |
|||
#endregion
|
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
log.Error(ex.ToString()); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,157 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using Quartz; |
|||
|
|||
namespace ICSSoft.FromERP |
|||
{ |
|||
/// <summary>
|
|||
/// 产品Bom(凯尔克)
|
|||
/// </summary>
|
|||
public class IcsSBomFromU8 : 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 TenantId = dr["TenantId"].ToString(); |
|||
string TenantCode = dr["TenantCode"].ToString(); |
|||
string ErpId = dr["ErpID"].ToString(); //erpID
|
|||
string Class = this.GetType().Name + TenantCode; |
|||
erpName = string.Format(erpName, TenantId); |
|||
#region SQL
|
|||
string sql = @"
|
|||
|
|||
SELECT DISTINCT |
|||
c.InvCode as 料品编码, |
|||
f.InvCode as 子阶料编码, |
|||
g2.cInvName as 子阶料名称, |
|||
'' 子阶料描述, |
|||
'' 项目号, |
|||
'' 工程变更号, |
|||
d.BaseQtyD 子阶料计量数量, |
|||
'' 子阶料物料版本, |
|||
d.EffBegDate 生效日期, |
|||
d.EffEndDate 失效日期, |
|||
d.SortSeq 次序, |
|||
d.OpSeq 工序号, |
|||
a.Version 母料版本号 , |
|||
ISNULL(a.ModifyDate, a.CreateDate) as MTime |
|||
,d.OpComponentId as ErpDetailID |
|||
into #TempBOM |
|||
FROM {1}.dbo.bom_bom a With(NoLock) -- BOM资料 |
|||
INNER JOIN {1}.dbo.bom_parent b With(NoLock) on a.BomId = b.BomId --BOM母件资料 |
|||
INNER JOIN {1}.dbo.bas_part c With(NoLock) on b.ParentId = c.PartId --物料表 |
|||
INNER JOIN {1}.dbo.bom_opcomponent d With(NoLock) on a.BomId=d.BomId --BOM子件资料 |
|||
INNER JOIN {1}.dbo.bas_part f With(NoLock) on d.ComponentId = f.PartId |
|||
left join {1}.dbo.inventory g With(NoLock) on c.InvCode=g.cInvCode --存货档案 |
|||
left join {1}.dbo.inventory g2 With(NoLock) on f.InvCode=g2.cInvCode --存货档案 |
|||
|
|||
WHERE ISNULL(a.ModifyDate, a.CreateDate)>=@LastTime |
|||
|
|||
IF NOT EXISTS(SELECT * FROM #TempBOM) |
|||
RETURN";
|
|||
|
|||
sql = string.Format(sql, ErpId, erpName); |
|||
sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempBOM"); |
|||
sql += "\r\n"; |
|||
sql += @"--删除数据
|
|||
|
|||
|
|||
|
|||
SELECT a.ErpId INTO #tableICSSBOM |
|||
FROM ICSSBOM a With(NoLock) |
|||
left join {1}.dbo.bom_opcomponent d With(NoLock) on a.ErpId=d.OpComponentId |
|||
WHERE d.id is null |
|||
and a.TenantId='{0}' |
|||
|
|||
|
|||
DELETE ICSSBOM |
|||
WHERE TenantId='{0}' and ErpId IN ( SELECT ErpId from #tableICSSBOM) |
|||
";
|
|||
Dictionary<string, string> values = new Dictionary<string, string>(); |
|||
values.Add("SBOMVER", "a.母料版本号"); |
|||
values.Add("ITEMCODE", "a.料品编码"); |
|||
values.Add("SBITEMCODE", "a.子阶料编码"); |
|||
values.Add("SBItemName", "a.子阶料名称"); |
|||
values.Add("SBSITEMCODE", "a.子阶料编码"); |
|||
values.Add("SBITEMQTY", "a.子阶料计量数量"); |
|||
values.Add("SEQ", "1"); |
|||
values.Add("SBItemECN", "a.工程变更号"); |
|||
values.Add("SBItemStatus", "'Y'"); |
|||
values.Add("SBItemEfftime", "a.生效日期"); |
|||
values.Add("SBItemInvtime", "a.失效日期"); |
|||
values.Add("SBItemProject", "a.项目号"); |
|||
values.Add("SBItemSeq", "a.次序"); |
|||
values.Add("Location", "a.工序号"); |
|||
values.Add("LastModificationTime", "a.Mtime");//操作时间
|
|||
values.Add("LastModifierUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
|
|||
values.Add("LastModifierUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
|
|||
values.Add("SBItemContype", "c.ItemContype"); |
|||
//更新存在数据
|
|||
sql += ICSHelper.UpdateSQL("b", values) |
|||
+ @" #TempBOM a
|
|||
INNER JOIN ICSSBOM b ON a.ErpDetailID=b.ErpId |
|||
left join IcsInventory c on b.SBItemCode=c.ItemCode and b.TenantId=c.TenantId |
|||
left join IcsMainCategoryCode d on c.ItemMainCategoryCode=d.ItemMainCategoryCode and c.TenantId=d.TenantId |
|||
WHERE b.TenantId='{0}' ";
|
|||
|
|||
values.Add("ErpId", "convert(nvarchar(100), a.ErpDetailID)"); |
|||
values.Add("CreationTime", "a.MTime");//操作人
|
|||
values.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
|
|||
values.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
|
|||
values.Add("TenantId", "'" + TenantId + "'");//站点
|
|||
sql += "\r\n"; |
|||
//插入新增数据
|
|||
sql += ICSHelper.InsertSQL("ICSSBOM", values) |
|||
+ @" #TempBOM a
|
|||
LEFT JOIN ICSSBOM b ON a.ErpDetailID=b.ErpId and b.TenantId='{0}' |
|||
left join IcsInventory c on a.子阶料编码=c.ItemCode and c.TenantId='{0}' |
|||
left join IcsMainCategoryCode d on c.ItemMainCategoryCode=d.ItemMainCategoryCode and d.TenantId='{0}' |
|||
WHERE 1=1 and b.id is null |
|||
";
|
|||
sql += " DROP TABLE #TempBOM " + |
|||
"DROP TABLE #tableICSSBOM"; |
|||
sql = string.Format(sql, TenantId, erpName, ErpId); |
|||
// return;
|
|||
ICSHelper.ExecuteDate(conStr, sql); |
|||
#endregion
|
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
log.Error(ex.ToString()); |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue