xusc
1 month ago
10 changed files with 1148 additions and 2 deletions
-
BIN.vs/ICSSoft.FromERP/v16/.suo
-
5ICSSoft.FromERP/ConvertExt.cs
-
100ICSSoft.FromERP/ICSHelper.cs
-
163ICSSoft.FromERP/ICSInventory_Rhtyon.cs
-
7ICSSoft.FromERP/ICSSoft.FromERP.csproj
-
219ICSSoft.FromERP/IcsMo_Rhtyon.cs
-
485ICSSoft.FromERP/IcsOp.cs
-
6ICSSoft.FromERP/IcsSBom.cs
-
165ICSSoft.FromERP/IcsSBom_Rhtyon.cs
-
BINRoot/NPinyin.dll
Binary file not shown.
@ -0,0 +1,163 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using Quartz; |
|||
using System.Data; |
|||
namespace ICSSoft.FromERP |
|||
{ |
|||
/// <summary>
|
|||
/// 物料档案(锐腾)
|
|||
/// </summary>
|
|||
public class ICSInventory_Rhtyon : 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 A.ID AS ID,
|
|||
A.Code AS ItemCode |
|||
,a.ItemFormAttribute |
|||
,dbo.GetReplaceStr(A.Name) AS ItemName, |
|||
a.DescFlexField_PrivateDescSeg2 ItemDrawingNo |
|||
,b.Description ItemDesc, |
|||
dbo.GetReplaceStr(A.SPECS) AS ItemStd, |
|||
D.Name AS ItemUnit, |
|||
G.Code as ItemMainCategoryCode, |
|||
H.Name as ClassName, |
|||
1 as ItemRate, |
|||
1 as EffectiveDays, |
|||
A.ModifiedOn as MTime |
|||
,I.id as Org |
|||
,Case When Q.IsSueOverType=0 THEN 1 WHEN Q.IsSueOverType=1 THEN 2 WHEN Q.IsSueOverType=2 THEN 3 ELSE 0 END AS 备料超额类型 |
|||
,Case When Q.IsSueOverType=0 Then Q.StandardMaterialScale When Q.IsSueOverType=1 Then Q.StandardMaterialQty |
|||
ELSE 0 END AS 备料超额值 |
|||
INTO #TempINV |
|||
from {1}.dbo.[CBO_ItemMaster] AS A |
|||
LEFT JOIN {1}.dbo.[CBO_ItemMaster_Trl] AS B ON ( A.[ID] = B.[ID] AND B.SysMLFlag='zh-CN') |
|||
LEFT JOIN {1}.dbo.[Base_UOM] AS C ON ( A.[CostUOM] = C.[ID] ) |
|||
LEFT JOIN {1}.dbo.[Base_UOM_Trl] AS D ON ( C.[ID] = D.[ID] AND D.SysMLFlag='zh-CN') |
|||
LEFT JOIN {1}.dbo.[Base_UOM] AS E ON ( A.[InventoryUOM] = E.[ID] ) |
|||
LEFT JOIN {1}.dbo.[Base_UOM_Trl] AS F ON ( E.[ID] = F.[ID] AND F.SysMLFlag='zh-CN') |
|||
LEFT JOIN {1}.dbo.[CBO_Category] AS G ON ( A.[MainItemCategory] = G.[ID] ) |
|||
LEFT JOIN {1}.dbo.[CBO_Category_Trl] AS H ON ( G.[ID] = H.[ID] AND H.SysMLFlag='zh-CN') |
|||
LEFT JOIN {1}.dbo.[Base_Organization] AS I ON ( A.[Org] = I.[ID] ) |
|||
LEFT JOIN {1}.dbo.[Base_Organization_Trl] AS J ON ( I.[ID] = J.[ID] AND J.SysMLFlag='zh-CN') |
|||
LEFT JOIN {1}.dbo.CBO_InventoryInfo L on A.id=L.ItemMaster |
|||
LEFT JOIN {1}.dbo.CBO_Wh M on L.warehouse=M.id and A.org=M.org |
|||
LEFT JOIN {1}.dbo.CBO_Category_Trl P ON P.ID=A.MainItemCategory |
|||
LEFT JOIN {1}.dbo.CBO_MfgInfo Q ON Q.ItemMaster=A.ID |
|||
where A.ModifiedOn>=@LastTime AND I.id={0} |
|||
ORDER BY A.Code |
|||
|
|||
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.[CBO_ItemMaster] b With(NoLock) ON a.ItemCode=b.code |
|||
WHERE b.code is null |
|||
and a.TenantId='{0}' |
|||
AND b.Org={2} |
|||
|
|||
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");//规格型号
|
|||
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");//大类编码
|
|||
values.Add("InvFQC", "0");//大类编码
|
|||
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.备料超额类型"); |
|||
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");//操作时间
|
|||
values.Add("ItemType", "'itemtype_finishedproduct'"); |
|||
|
|||
//更新存在数据
|
|||
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 + "' and a.Org={2} ";
|
|||
|
|||
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 |
|||
and a.Org={2} ";
|
|||
sql += " DROP TABLE #TempINV " + |
|||
" DROP TABLE #tableICSINVENTORY "; |
|||
sql = string.Format(sql, TenantId, erpName, ErpId); |
|||
// return;
|
|||
ICSHelper.ExecuteDate(conStr, sql); |
|||
#endregion
|
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
log.Error(ex.ToString()); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,219 @@ |
|||
using Quartz; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace ICSSoft.FromERP |
|||
{ |
|||
/// <summary>
|
|||
/// 工单(锐腾)
|
|||
/// </summary>
|
|||
public class IcsMo_Rhtyon : 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();//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.ID as ID, |
|||
A.DocNO as MOCODE, |
|||
1 as Sequence, |
|||
A7.Code as InvCode, |
|||
CASE WHEN A.IsStartMO != 1 THEN |
|||
(SELECT TOP 1 TotalStartQty FROM {1}.dbo.MO_MOStartInfo WHERE MO=A.ID ORDER BY StartDatetime DESC) |
|||
ELSE (SELECT TOP 1 ActualStartQty FROM {1}.dbo.MO_MOStartInfo WHERE MO=A.ID ORDER BY StartDatetime DESC) END as Quantity, |
|||
A.CreatedBy as CreatePerson, |
|||
A.CreatedOn as CreateDateTime, |
|||
0 as Amount, |
|||
0 as RCVQuantity, |
|||
A13.Code as DepCode, |
|||
A22.Code as WHCode, |
|||
'mostatus_initial' as MOStatus, |
|||
A2.Description as MOMemo, |
|||
'2' as ERPStatus, |
|||
A.StartDate as StartDate, |
|||
A.CompleteDate as DueDate, |
|||
A.ID as MOID, |
|||
A.ID as MODetailID, |
|||
ISNULL(A.ModifiedOn,A.BusinessCreatedOn) as MTIME, |
|||
isnull(A11.Code,'') ProjectCode,isnull(A19.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 |
|||
,A12.Code as TenantId |
|||
,A12.id as Org |
|||
,a.DescFlexField_PrivateDescSeg1 AS EATTRIBUTE1 |
|||
,( |
|||
select b1.code from {1}.dbo.UBF_Sys_ExtEnumType a1 |
|||
left join {1}.dbo.UBF_Sys_ExtEnumValue b1 on a1.ID=b1.ExtEnumType |
|||
left join {1}.dbo.UBF_Sys_ExtEnumValue_Trl c1 on b1.id=c1.ID |
|||
WHERE a1.Code like 'UFIDA.U9.CBO.Enums.DemandCodeEnum' |
|||
and b1.evalue=a.DemandCode |
|||
and b1.code not like 'K10%' |
|||
) as NeedType |
|||
,A4.Name as MoDocType |
|||
,case when a.ActualCompleteDate is null then '' |
|||
else Convert(varchar(10),a.ActualCompleteDate,120 ) end as ActualCompleteDate |
|||
INTO #TempMO |
|||
from {1}.dbo.MO_MO as A With(NoLock) |
|||
left join {1}.dbo.[MO_MOMemo] as A1 With(NoLock) on (A.[ID] = A1.[MO]) |
|||
left join {1}.dbo.[MO_MOMemo_Trl] as A2 With(NoLock) on (A2.SysMlFlag = 'zh-CN') and (A1.[ID] = A2.[ID]) |
|||
left join {1}.dbo.[MO_MODocType] as A3 With(NoLock) on (A.[MODocType] = A3.[ID]) |
|||
left join {1}.dbo.[MO_MODocType_Trl] as A4 With(NoLock) on (A4.SysMlFlag = 'zh-CN') and (A3.[ID] = A4.[ID]) |
|||
left join {1}.dbo.[MO_MOTaskPlan] as A5 With(NoLock) on (A.[ID] = A5.[MO]) |
|||
left join {1}.dbo.[Base_User] as A6 With(NoLock) on (A.ModifiedBy = A6.Code) |
|||
left join {1}.dbo.[CBO_ItemMaster] as A7 With(NoLock) on (A.[ItemMaster] = A7.[ID]) |
|||
left join {1}.dbo.[MO_MO_Trl] as A8 With(NoLock) on (A8.SysMlFlag = 'zh-CN') and (A.[ID] = A8.[ID]) |
|||
left join {1}.dbo.[CBO_BOMVersion] as A9 With(NoLock) on (A.[BOMVersion] = A9.[ID]) |
|||
left join {1}.dbo.[CBO_ItemMaster_Trl] as A10 With(NoLock) on (A10.SysMlFlag = 'zh-CN') and (A7.[ID] = A10.[ID]) |
|||
left join {1}.dbo.[CBO_Project] as A11 With(NoLock) on (A.[Project] = A11.[ID]) |
|||
left join {1}.dbo.[Base_Organization] as A12 With(NoLock) on (A.[Org] = A12.[ID]) |
|||
left join {1}.dbo.[CBO_Department] as A13 With(NoLock) on (A.[Department] = A13.[ID]) |
|||
left join {1}.dbo.[CBO_Department_Trl] as A14 With(NoLock) on (A14.SysMlFlag = 'zh-CN') and (A13.[ID] = A14.[ID]) |
|||
left join {1}.dbo. MO_MO As A16 With(NoLock) on A16.[MODocType]=1001603110990023 and A.[Project]=A16.Project and A.ItemMaster=A16.ItemMaster |
|||
left join {1}.dbo.[CBO_ItemMaster] as A17 With(NoLock) on (A16.[ItemMaster] = A17.[ID]) |
|||
left join {1}.dbo.[CBO_ItemMaster_Trl] as A18 With(NoLock) on (A18.SysMlFlag = 'zh-CN') and (A17.[ID] = A16.[ID]) |
|||
left join {1}.dbo.[MO_MOLot] as A19 With(NoLock) on (A16.[ID] = A19.[MO]) |
|||
left join (select * from (select ROW_NUMBER() over( partition by dept order by code desc ) row,* from {1}.dbo.CBO_Operators with(nolock) ) bb |
|||
where bb.row='1' )as A20 on A20.dept=A.Department and a20.Org=a.Org |
|||
--left join {1}.dbo.[MO_IssueDoc] as A21 With(NoLock) on A21.[SourceDoc_SrcDocNo]=A.DocNo |
|||
LEFT JOIN {1}.dbo.[CBO_Wh] AS A22 With(NoLock) ON A22.ID=A.CompleteWh |
|||
where (A.DocState=2 OR A.DocState=3) and A.[BusinessType] != 50 and (A.[BusinessType] != 52) |
|||
and (A.[BusinessType] != 2417) and (A.[IsMultiRouting] != 1) and A.[ItemMaster] is not null --and (A.[IsStartMO] != 1) |
|||
and ISNULL(A.ModifiedOn,A.BusinessCreatedOn)>=@LastTime AND A12.id='{0}' |
|||
|
|||
--update #TempMO 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,TenantId,cBatch,version ,brand |
|||
-- INTO #TempExtensionMO |
|||
-- from #TempMO |
|||
|
|||
IF NOT EXISTS(SELECT * FROM #TempMO) |
|||
begin |
|||
DROP TABLE #TempMO |
|||
RETURN |
|||
|
|||
end";
|
|||
sql = string.Format(sql, ErpId, erpName); |
|||
sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempMO"); |
|||
Dictionary<string, string> value = new Dictionary<string, string>(); |
|||
|
|||
sql += @"--删除数据
|
|||
-- DELETE ICSMO WHERE MODetailID NOT IN (SELECT CAST(MoDId AS VARCHAR) FROM {1}.dbo.[mom_orderdetail]) |
|||
SELECT a.MoCode INTO #tableICSMO |
|||
FROM ICSMO a With(NoLock) |
|||
LEFT JOIN {1}.dbo.[MO_MO] b With(NoLock) ON a.Mocode=b.DocNO |
|||
WHERE a.TenantId='{0}' and b.DocNO IS NULL AND b.Org={2} |
|||
|
|||
DELETE ICSMO |
|||
WHERE TenantId='{0}' and mocode IN ( SELECT MoCode from #tableICSMO) |
|||
";
|
|||
Dictionary<string, string> values = new Dictionary<string, string>(); |
|||
values.Add("MoCode", "a.MOCODE");//工单号
|
|||
values.Add("MoSeq", "a.Sequence");//工单行号
|
|||
values.Add("ItemCode", "a.InvCode");//物料代码
|
|||
values.Add("MoPlanQty", "a.Quantity");//数量
|
|||
values.Add("Amount", "a.Amount");//辅机数量
|
|||
values.Add("DepCode", "a.DepCode");//辅机数量
|
|||
values.Add("SegCode", "a.DepCode");//辅机数量
|
|||
values.Add("WHCode", "a.WHCode");//仓库
|
|||
values.Add("MoPlanStartDate", "a.StartDate");//开工日
|
|||
values.Add("MoPlanEndDate", "a.DueDate");//完工日
|
|||
|
|||
values.Add("MOMemo", "a.MOMemo");//生产订单状态
|
|||
values.Add("MoUser", "a.CreatePerson");//生产订单状态
|
|||
values.Add("MODOWNDATE", "a.CreateDateTime");//生产订单状态
|
|||
values.Add("MOID", "a.MoId");//生产订单状态
|
|||
values.Add("MODetailID", "a.MODetailID");//生产订单状态
|
|||
values.Add("LastModifierUserId", "'" + ConstWorkPoint.Muser + "'"); |
|||
values.Add("LastModifierUserName", "'" + ConstWorkPoint.Musername + "'"); |
|||
values.Add("LastModificationTime", "a.Mtime");//操作时间
|
|||
//values.Add("Default1", "a.EATTRIBUTE1");
|
|||
//values.Add("Default2", "a.NeedType");
|
|||
values.Add("DocType", "a.MoDocType"); |
|||
// values.Add("Default3", "a.ActualCompleteDate");
|
|||
|
|||
//更新存在数据
|
|||
sql += ICSHelper.UpdateSQL("b", values) |
|||
+ @" #TempMO a
|
|||
INNER JOIN ICSMO b ON a.Mocode=b.Mocode |
|||
WHERE b.TenantId='{0}' and a.Org={2} ";
|
|||
|
|||
// values.Add("ID", "NEWID()");
|
|||
values.Add("MoType", "'normal'");//辅机数量
|
|||
values.Add("MOVER", "'1'");//辅机数量
|
|||
values.Add("ProjectCode", "a.ProjectCode");//辅机数量
|
|||
|
|||
values.Add("MOINPUTQTY", "0");//辅机数量
|
|||
values.Add("MOSCRAPQTY", "0");//辅机数量
|
|||
values.Add("MOACTQTY", "0");//辅机数量
|
|||
values.Add("CollectModel", "'SS'");//辅机数量
|
|||
values.Add("CollectType", "'collecttype_one'");//辅机数量
|
|||
values.Add("MoBom", "'1'");//辅机数量
|
|||
values.Add("CreationTime", "a.MTime");//操作人
|
|||
values.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
|
|||
values.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
|
|||
values.Add("TenantId", "'" + TenantId + "'");//站点
|
|||
values.Add("MOSTATUS", "a.MOStatus");//生产订单状态
|
|||
//插入新增数据
|
|||
sql += ICSHelper.InsertSQL("ICSMO", values) |
|||
+ @" #TempMO a
|
|||
LEFT JOIN ICSMO b on a.Mocode=b.Mocode and b.TenantId='{0}' |
|||
WHERE 1=1 and b.MoCode is null and a.Org={2} ";
|
|||
sql += "DROP TABLE #TempMO"; |
|||
sql += " DROP TABLE #tableICSMO "; |
|||
sql = string.Format(sql, TenantId, erpName, ErpId); |
|||
//return;
|
|||
ICSHelper.ExecuteDate(conStr, sql); |
|||
#endregion
|
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
log.Error(ex.ToString()); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,485 @@ |
|||
using NPinyin; |
|||
using Quartz; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
namespace ICSSoft.FromERP |
|||
{ |
|||
/// <summary>
|
|||
/// 工序/工艺路线(锐腾)
|
|||
/// </summary>
|
|||
public class IcsOp : 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; |
|||
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);
|
|||
string time = ICSHelper.GetTime(conStr, Namespace, Class, TenantId).ToStringBz(); |
|||
string sql = @"select DISTINCT EffectiveDate,DisableDate,ITEM.Code+'_'+RoutingVersionCode+'_'+cast(AlternateType as nvarchar) AS ROUTECODE,
|
|||
ITEM.Code+'_'+RoutingVersionCode+'_'+(case AlternateType when '0' then '主制造' when '1' then '委外' when '2001' then '试制' end ) AS RouteDesc,RoutingVersionCode,RoutingVersion, |
|||
u9route.CreatedOn as RouteCreateTime,u9route.ModifiedOn as RouteModifiedTime,opu9.Sequence as opseq, |
|||
opu9trl.Description+'_'+OPU9.Sequence as U9Opcode,opu9.CreatedOn as opCreateTime,opu9.ModifiedOn as OpModifiedTime,opu9trl.Description as OpDesc, |
|||
u9route.ID as routeID,opu9.ID as OPID,work.Code AS SegCode,u9Group.Code as CrewCode,u9route.Lot,u9Line.Code as LineCode,'' as MesOpcode, |
|||
case when timeuom.Name='小时' then cast (opu9.RunTime as decimal(18,3)) |
|||
when timeuom.Name='秒' then cast (opu9.RunTime/3600 as decimal(18,3)) |
|||
when timeuom.Name='分钟' then cast (opu9.RunTime/60 as decimal(18,3)) |
|||
when timeuom.Name='天' then cast (opu9.RunTime/24 as decimal(18,3)) |
|||
end as Rtime, |
|||
case when timeuom.Name='小时' then cast (opu9.SetupTime as decimal(18,3)) |
|||
when timeuom.Name='秒' then cast (opu9.SetupTime/3600 as decimal(18,3)) |
|||
when timeuom.Name='分钟' then cast (opu9.SetupTime/60 as decimal(18,3)) |
|||
when timeuom.Name='天' then cast (opu9.SetupTime/24 as decimal(18,3)) |
|||
end as Stime,u9Res.Code AS resCode,u9Restrl.Name as resName,PerResUsage,PerResOutput, |
|||
case when IsSubcOperation='0' THEN 'N' |
|||
else 'Y' end as IsSubcOperation,ITEM.Code as ItemCode,u9Group.Name AS CREWName,u9Linetrl.Name as LineName,worktrl.Name as SegNAME |
|||
from |
|||
{2}.DBO.CBO_Routing u9route |
|||
LEFT JOIN {2}.DBO.CBO_Routing_Trl u9routetrl on u9routetrl.ID=u9route.ID |
|||
LEFT JOIN {2}.DBO.CBO_ItemMaster ITEM ON ITEM.ID=ItemMaster |
|||
LEFT JOIN {2}.DBO.CBO_Operation opu9 on opu9.Routing=u9route.ID |
|||
LEFT JOIN {2}.DBO.CBO_Operation_Trl opu9trl on opu9.ID=opu9trl.ID |
|||
LEFT JOIN {2}.DBO.CBO_StdOperation opstdu9 on opstdu9.id=opu9.StdOperation |
|||
LEFT JOIN {2}.DBO.CBO_ShiftGroup u9Group on u9Group.ID=opu9.ShiftGroup |
|||
LEFT JOIN {2}.DBO.CBO_WorkCenter work on work.ID=opu9.WorkCenter |
|||
LEFT JOIN {2}.DBO.CBO_WorkCenter_Trl worktrl on work.ID=worktrl.ID |
|||
LEFT JOIN {2}.DBO.Base_UOM_Trl timeuom on timeuom.ID=opu9.TimeUOM |
|||
LEFT JOIN {2}.DBO.CBO_ProductionLine u9Line on u9Line.ID=ProductionLine |
|||
LEFT JOIN {2}.DBO.CBO_ProductionLine_Trl u9Linetrl on u9Linetrl.ID=ProductionLine |
|||
LEFT JOIN {2}.DBO.CBO_OpResource opRes ON opRes.Operation=opu9.id |
|||
LEFT JOIN {2}.DBO.CBO_Resource u9Res on u9Res.ID=opRes.Resource |
|||
LEFT JOIN {2}.DBO.CBO_Resource_Trl u9Restrl on u9Restrl.ID=u9Res.ID |
|||
WHERE u9route.org='{0}' And u9route.ModifiedOn>='{1}' and u9route.ApproveDate is not null |
|||
";
|
|||
sql = string.Format(sql, ErpId, time, erpName); |
|||
var table = ICSHelper.ExecuteTable(conStr, sql); |
|||
if (table.Rows.Count <= 0) |
|||
{ |
|||
log.Info("未查询到工艺路线数据,同步结束"); |
|||
return; |
|||
} |
|||
table.AsEnumerable().ToList().ForEach(row => |
|||
{ |
|||
row["MesOpcode"] = Pinyin.GetPinyin(row["U9Opcode"].ToString()).Replace(" ", ""); |
|||
}); |
|||
table.AcceptChanges(); |
|||
|
|||
#region 工序
|
|||
string opsql = ""; |
|||
int count = 0; |
|||
var opObj = table.AsEnumerable().Select(a => new { opcode = a["MesOpcode"].ToString(), opdesc = a["OpDesc"].ToString(), Opseq = a["opseq"].ToString(), u9Opcode = a["U9Opcode"].ToString() }). |
|||
Distinct().ToList(); |
|||
opObj.ForEach(b => { |
|||
count++; |
|||
|
|||
if (count != opObj.Count) |
|||
opsql += $" SELECT '{b.opcode}' as Opcode,'{b.opdesc}' as Opdesc,'{b.Opseq}' as opseq,'{b.u9Opcode}' as u9Opcode union all "; |
|||
else |
|||
opsql += $" SELECT '{b.opcode}' as Opcode,'{b.opdesc}' as Opdesc,'{b.Opseq}' as opseq,'{b.u9Opcode}' as u9Opcode"; |
|||
|
|||
}); |
|||
|
|||
opsql = "select * into #TempOp from (" + opsql + ") a"; |
|||
|
|||
Dictionary<string, string> opDic = new Dictionary<string, string>(); |
|||
opDic.Add("Opcode", "A.OPCODE"); |
|||
opDic.Add("Opdesc", "A.OPDESC"); |
|||
opDic.Add("OPNAME", "A.OPDESC"); |
|||
opDic.Add("OPSEQ", "A.OPSEQ"); |
|||
opDic.Add("OPCOLLECTION", "'MANUAl'"); |
|||
opDic.Add("OPCONTROL", "'10000000'"); |
|||
opDic.Add("ISMaterial", "'N'"); |
|||
opDic.Add("ISMerge", "'N'"); |
|||
opDic.Add("OPLevel", "'A'"); |
|||
opDic.Add("STIME", "0.00"); |
|||
opDic.Add("RTIME", "0.00"); |
|||
opDic.Add("Default1", "A.u9Opcode"); |
|||
opDic.Add("TenantId", "'" + TenantId + "'"); |
|||
opDic.Add("CreationTime", "GETDATE()");//操作时间
|
|||
opDic.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
|
|||
opDic.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
|
|||
|
|||
opsql += @"
|
|||
DELETE OP |
|||
FROM ICSOP OP |
|||
LEFT JOIN |
|||
(SELECT opu9trl.Description+'_'+Sequence as Opcode FROM {1}.DBO.CBO_Operation opu9 |
|||
LEFT JOIN {1}.DBO.CBO_Operation_Trl opu9trl on opu9.ID=opu9trl.ID |
|||
WHERE opu9.org='{2}' |
|||
) u9op on u9op.Opcode=OP.Default1 |
|||
WHERE TenantId='{0}' and u9op.Opcode is null ";
|
|||
|
|||
opsql += ICSHelper.InsertSQL("ICSOP", opDic) |
|||
+ @" #TempOp a
|
|||
LEFT JOIN ICSOP b on a.OPCODE=b.OPCODE and b.TenantId='{0}' |
|||
WHERE 1=1 and b.OPCODE is null";
|
|||
opsql += " DROP TABLE #TempOp"; |
|||
opsql = string.Format(opsql, TenantId, erpName, ErpId); |
|||
#endregion
|
|||
|
|||
#region 途程
|
|||
String routeSql = ""; |
|||
string itemRouteSql = ""; |
|||
count = 0; |
|||
var RouteObj = table.AsEnumerable().Select(a => new { RouteCode = a["ROUTECODE"].ToString(), RouteName = a["RouteDesc"].ToString(), EffDate = ((DateTime)a["EffectiveDate"]).ToStringBz(), IvlDate = ((DateTime)a["DisableDate"]).ToStringBz(), ProductLine = a["LineCode"].ToString(), ProductLineName = a["LineName"].ToString(), ItemCode = a["ItemCode"].ToString(), RouteVersion = a["RoutingVersion"].ToString(), Lot = a["Lot"].ToString() }). |
|||
Distinct().ToList(); |
|||
RouteObj.ForEach(b => { |
|||
count++; |
|||
|
|||
if (count != RouteObj.Count) |
|||
routeSql += $" SELECT '{b.RouteCode}' as RouteCode,'{b.RouteName}' as RouteName,'{b.EffDate}' as EffDate,'{b.IvlDate}' as IvlDate,'{b.ItemCode}' as ItemCode,'{b.Lot}' AS Lot,'{b.ProductLine}' as ProductLine,'{b.ProductLineName}' as ProductLineName,'{b.RouteVersion}' as RouteVersion union all "; |
|||
else |
|||
routeSql += $" SELECT '{b.RouteCode}' as RouteCode,'{b.RouteName}' as RouteName,'{b.EffDate}' as EffDate,'{b.IvlDate}' as IvlDate,'{b.ItemCode}' as ItemCode,'{b.Lot}' AS Lot,'{b.ProductLine}' as ProductLine,'{b.ProductLineName}' as ProductLineName,'{b.RouteVersion}' as RouteVersion"; |
|||
|
|||
}); |
|||
itemRouteSql = routeSql; |
|||
routeSql = " select * into #TempRoute from (" + routeSql + ") a"; |
|||
Dictionary<string, string> routeDic = new Dictionary<string, string>(); |
|||
routeDic.Add("RouteCode", "A.RouteCode"); |
|||
routeDic.Add("RouteName", "A.RouteName"); |
|||
routeDic.Add("RouteDesc", "A.RouteName"); |
|||
routeDic.Add("RouteType", "'Normal'"); |
|||
routeDic.Add("EffDate", "a.EffDate"); |
|||
routeDic.Add("IvlDate", "a.IvlDate"); |
|||
routeDic.Add("Enabled", "'Y'"); |
|||
routeDic.Add("TenantId", "'" + TenantId + "'"); |
|||
routeDic.Add("CreationTime", "GETDATE()");//操作时间
|
|||
routeDic.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
|
|||
routeDic.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
|
|||
|
|||
|
|||
|
|||
routeSql += @"
|
|||
DELETE ROUTE |
|||
FROM ICSROUTE ROUTE |
|||
LEFT JOIN |
|||
(SELECT item.Code+'_'+route.RoutingVersionCode+'_'+cast(AlternateType as nvarchar) as RouteCode FROM {1}.DBO.CBO_Routing route |
|||
LEFT JOIN {1}.DBO.CBO_ItemMaster item on route.ItemMaster=item.ID |
|||
WHERE route.org='{2}' |
|||
) u9route on u9route.RouteCode=ROUTE.ROUTECODE |
|||
WHERE TenantId='{0}' and u9route.RouteCode is null ";
|
|||
|
|||
routeSql += ICSHelper.InsertSQL("ICSROUTE", routeDic) |
|||
+ @"#TempRoute a
|
|||
LEFT JOIN ICSROUTE b on a.ROUTECODE=b.ROUTECODE and b.TenantId='{0}' |
|||
WHERE 1=1 and b.ID is null";
|
|||
routeSql += " DROP TABLE #TempRoute "; |
|||
routeSql = string.Format(routeSql, TenantId, erpName, ErpId); |
|||
#endregion
|
|||
|
|||
|
|||
#region 途程关联工序
|
|||
string routeOpSql = ""; |
|||
count = 0; |
|||
var RouteOpObj = table.AsEnumerable().Select(a => new { RouteCode = a["ROUTECODE"].ToString(), Opcode = a["MesOpcode"].ToString(), Opseq = a["opseq"].ToString(), ParallelOp = a["IsSubcOperation"].ToString(), ItemCode = a["ItemCode"].ToString(), RouteVersion = a["RoutingVersion"].ToString(), Stime = a["Stime"].ToString(), Rtime = a["Rtime"].ToString(), SEGCODE = a["SegCode"].ToString(), SegName = a["SegNAME"].ToString(), CrewCode = a["CrewCode"].ToString(), CREWName = a["CREWName"].ToString() }). |
|||
Distinct().ToList(); |
|||
RouteOpObj.ForEach(b => { |
|||
count++; |
|||
|
|||
if (count != RouteOpObj.Count) |
|||
routeOpSql += $" SELECT '{b.RouteCode}' as RouteCode,'{b.Opcode}' as Opcode,'{b.Opseq}' as Opseq,'{b.ParallelOp}' as ParallelOp,'{b.ItemCode}' as ItemCode,{b.Rtime} as Rtime,{b.Stime} as Stime,'{b.SEGCODE}' as SEGCODE,'{b.SegName}' as SegName,'{b.CrewCode}' as CrewCode,'{b.CREWName}' as CREWName union all"; |
|||
else |
|||
routeOpSql += $" SELECT '{b.RouteCode}' as RouteCode,'{b.Opcode}' as Opcode,'{b.Opseq}' as Opseq,'{b.ParallelOp}' as ParallelOp,'{b.ItemCode}' as ItemCode,{b.Rtime} as Rtime,{b.Stime} as Stime,'{b.SEGCODE}' as SEGCODE,'{b.SegName}' as SegName,'{b.CrewCode}' as CrewCode,'{b.CREWName}' as CREWName "; |
|||
|
|||
}); |
|||
var itemOpSql = routeOpSql; |
|||
routeOpSql = $@"SELECT a.*,B.ID AS ROUTEID,C.ID AS OPID INTO #TempRoute2op FROM ({routeOpSql}) a
|
|||
LEFT JOIN ICSROUTE b on b.RouteCode=a.RouteCode and b.TenantId='{TenantId}' |
|||
LEFT JOIN ICSOP C ON C.OPCODE=A.OPCODE AND C.TenantId='{TenantId}' |
|||
";
|
|||
Dictionary<string, string> routeOpDic = new Dictionary<string, string>(); |
|||
routeOpDic.Add("RouteCode", "A.RouteCode"); |
|||
routeOpDic.Add("OPCODE", "A.OPCODE"); |
|||
routeOpDic.Add("ROUTEID", "A.ROUTEID"); |
|||
routeOpDic.Add("OPID", "A.OPID"); |
|||
routeOpDic.Add("OPSEQ", "a.OPSEQ"); |
|||
routeOpDic.Add("IsMaterial", "'N'"); |
|||
routeOpDic.Add("IsMerge", "'N'"); |
|||
routeOpDic.Add("OpLevel", "'A'"); |
|||
routeOpDic.Add("OpControlSeq", "a.OPSEQ"); |
|||
routeOpDic.Add("OPControl", "'10000000'"); |
|||
routeOpDic.Add("ParallelOp", "a.ParallelOp"); |
|||
routeOpDic.Add("TenantId", "'" + TenantId + "'"); |
|||
routeOpDic.Add("CreationTime", "GETDATE()");//操作时间
|
|||
routeOpDic.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
|
|||
routeOpDic.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
|
|||
|
|||
routeOpSql += @"
|
|||
DELETE ROUTEOP |
|||
FROM ICSROUTE2OP ROUTEOP |
|||
LEFT JOIN ICSOP OP ON ROUTEOP.OPID=OP.ID |
|||
LEFT JOIN |
|||
(SELECT item.Code+'_'+u9route.RoutingVersionCode+'_'+cast(u9route.AlternateType as nvarchar) as U9RouteCode,opu9trl.Description+'_'+OPU9.Sequence as u9Opcode |
|||
FROM {1}.DBO.CBO_Routing u9route |
|||
LEFT JOIN {1}.DBO.CBO_ItemMaster item on u9route.ItemMaster=item.ID |
|||
LEFT JOIN {1}.DBO.CBO_Operation opu9 on opu9.Routing=u9route.ID |
|||
LEFT JOIN {1}.DBO.CBO_Operation_Trl opu9trl on opu9.ID=opu9trl.ID |
|||
WHERE u9route.org='{2}' |
|||
) u9routeOp on u9routeOp.U9RouteCode=ROUTEOP.ROUTECODE AND u9routeOp.u9Opcode=OP.DEFAULT1 |
|||
WHERE ROUTEOP.TenantId='{0}' and u9routeOp.U9RouteCode is null ";
|
|||
|
|||
routeOpSql += ICSHelper.InsertSQL("ICSROUTE2OP", routeOpDic) |
|||
+ @"#TempRoute2op a
|
|||
LEFT JOIN ICSROUTE2OP b on a.ROUTECODE=b.ROUTECODE and A.OPCODE=B.OPCODE AND b.TenantId='{0}' |
|||
WHERE 1=1 and b.OPCODE is null";
|
|||
routeOpSql += " DROP TABLE #TempRoute2op"; |
|||
routeOpSql = string.Format(routeOpSql, TenantId, erpName, ErpId); |
|||
|
|||
#endregion
|
|||
|
|||
|
|||
#region 物料关联途程
|
|||
itemRouteSql = $@"SELECT A.*,B.ID AS ITEMID,C.ID AS ROUTEID INTO #TempItemRoute
|
|||
FROM ({itemRouteSql}) A |
|||
LEFT JOIN IcsInventory B ON A.ItemCode=B.ItemCode AND B.TenantId='{TenantId}' |
|||
LEFT JOIN ICSROUTE C ON C.ROUTECODE=A.ROUTECODE AND C.TenantId='{TenantId}' |
|||
";
|
|||
|
|||
itemRouteSql += @"
|
|||
DELETE ITEMROUTE |
|||
FROM IcsItem2Route ITEMROUTE |
|||
LEFT JOIN |
|||
(SELECT item.Code+'_'+u9route.RoutingVersionCode+ '_'+cast(u9route.AlternateType as nvarchar) as U9RouteCode, |
|||
item.Code as itemcode |
|||
FROM {1}.DBO.CBO_Routing u9route |
|||
LEFT JOIN {1}.DBO.CBO_ItemMaster item on u9route.ItemMaster=item.ID |
|||
WHERE u9route.org='{2}' |
|||
) u9routeOp on u9routeOp.U9RouteCode=ITEMROUTE.ROUTECODE AND u9routeOp.ITEMCODE=ITEMROUTE.itemcode |
|||
WHERE TenantId='{0}' and u9routeOp.itemcode is null ";
|
|||
|
|||
Dictionary<string, string> ItemRouteDic = new Dictionary<string, string>(); |
|||
ItemRouteDic.Add("RouteCode", "A.RouteCode"); |
|||
ItemRouteDic.Add("ItemCode", "A.ItemCode"); |
|||
ItemRouteDic.Add("ROUTEID", "A.ROUTEID"); |
|||
ItemRouteDic.Add("ITEMID", "A.ITEMID"); |
|||
ItemRouteDic.Add("IsRef", "'Y'"); |
|||
ItemRouteDic.Add("Default1", "A.ProductLine"); |
|||
ItemRouteDic.Add("Default2", "A.ProductLineName"); |
|||
ItemRouteDic.Add("Default3", "A.LOT"); |
|||
ItemRouteDic.Add("TenantId", "'" + TenantId + "'"); |
|||
ItemRouteDic.Add("CreationTime", "GETDATE()");//操作时间
|
|||
ItemRouteDic.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
|
|||
ItemRouteDic.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
|
|||
|
|||
itemRouteSql += ICSHelper.InsertSQL("ICSITEM2ROUTE", ItemRouteDic) |
|||
+ @" #TempItemRoute a
|
|||
LEFT JOIN ICSITEM2ROUTE b on a.ROUTECODE=b.ROUTECODE and A.ITEMCODE=B.ITEMCODE AND b.TenantId='{0}' |
|||
WHERE 1=1 and b.ID is null ";
|
|||
|
|||
|
|||
|
|||
itemRouteSql += @" Update A SET IsRef='N' FROM ICSITEM2ROUTE A INNER JOIN
|
|||
(SELECT A.ROUTECODE,A.ITEMCODE FROM #TempItemRoute A LEFT JOIN ICSITEM2ROUTE B ON a.ROUTECODE=b.ROUTECODE and A.ITEMCODE=B.ITEMCODE AND b.TenantId='{0}' Where b.ID is null)B |
|||
ON B.ITEMCODE=A.ITEMCODE AND B.ROUTECODE<>A.ROUTECODE |
|||
";
|
|||
itemRouteSql += " DROP TABLE #TempItemRoute"; |
|||
|
|||
itemRouteSql = string.Format(itemRouteSql, TenantId, erpName, ErpId); |
|||
#endregion
|
|||
|
|||
#region 物料关联途程与工序
|
|||
itemOpSql = $@"Select a.*,B.ID AS RouteId,c.id as OpId,d.id as ItemId,C.DEFAULT1 AS U9OPCODE INTO #TEMPITEMOP from ({itemOpSql})a
|
|||
LEFT JOIN ICSROUTE b on b.RouteCode=a.RouteCode and b.TenantId='{TenantId}' |
|||
LEFT JOIN ICSOP C ON C.OPCODE=A.OPCODE AND C.TenantId='{TenantId}' |
|||
LEFT JOIN IcsInventory D ON D.ItemCode=A.ItemCode AND D.TenantId='{TenantId}' |
|||
";
|
|||
|
|||
Dictionary<string, string> ItemOpDic = new Dictionary<string, string>(); |
|||
ItemOpDic.Add("STIME", "A.STIME"); |
|||
ItemOpDic.Add("RTIME", "A.RTIME"); |
|||
ItemOpDic.Add("Default1", "A.SEGCODE"); |
|||
ItemOpDic.Add("Default2", "A.SEGNAME"); |
|||
ItemOpDic.Add("Default3", "A.CREWCODE"); |
|||
ItemOpDic.Add("Default4", "A.CREWNAME"); |
|||
ItemOpDic.Add("LastModificationTime", "GETDATE()");//操作时间
|
|||
ItemOpDic.Add("LastModifierUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
|
|||
ItemOpDic.Add("LastModifierUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
|
|||
itemOpSql += ICSHelper.UpdateSQL("b", ItemOpDic) |
|||
+ "#TEMPITEMOP a" |
|||
+ " INNER JOIN ICSITEMROUTE2OP b on a.ROUTECODE = b.ROUTECODE and A.ITEMCODE = B.ITEMCODE AND A.OPCODE = B.OPCODE AND b.TenantId = '{0}'"; |
|||
|
|||
ItemOpDic.Add("RouteCode", "A.RouteCode"); |
|||
ItemOpDic.Add("ItemCode", "A.ItemCode"); |
|||
ItemOpDic.Add("OpCode", "A.OpCode"); |
|||
ItemOpDic.Add("OpSeq", "A.OpSeq"); |
|||
ItemOpDic.Add("ITEMID", "A.ITEMID"); |
|||
ItemOpDic.Add("RouteId", "A.RouteId"); |
|||
ItemOpDic.Add("OpId", "A.OpId"); |
|||
ItemOpDic.Add("OPCONTROL", "'10000000'"); |
|||
ItemOpDic.Add("IdMergeRule", "'0'"); |
|||
ItemOpDic.Add("OpLevel", "'A'"); |
|||
ItemOpDic.Add("OpControlSeq", "A.OpSeq"); |
|||
ItemOpDic.Add("TenantId", "'" + TenantId + "'"); |
|||
ItemOpDic.Add("CreationTime", "GETDATE()");//操作时间
|
|||
ItemOpDic.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
|
|||
ItemOpDic.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
|
|||
|
|||
|
|||
itemOpSql += @"
|
|||
DELETE ITEMOP |
|||
FROM ICSITEMROUTE2OP ITEMOP |
|||
LEFT JOIN ICSOP OP ON ITEMOP.OPID=OP.ID |
|||
LEFT JOIN |
|||
(SELECT item.Code+'_'+u9route.RoutingVersionCode+ '_'+cast(u9route.AlternateType as nvarchar) as U9RouteCode, |
|||
item.Code as itemcode, |
|||
opu9trl.Description+'_'+OPU9.Sequence as U9Opcode |
|||
FROM {1}.DBO.CBO_Routing u9route |
|||
LEFT JOIN {1}.DBO.CBO_Operation opu9 on opu9.Routing=u9route.ID |
|||
LEFT JOIN {1}.DBO.CBO_Operation_TRL opu9trl on opu9trl.ID=opu9.ID |
|||
LEFT JOIN {1}.DBO.CBO_ItemMaster item on u9route.ItemMaster=item.ID |
|||
WHERE u9route.org='{2}' |
|||
) u9ItemOp on u9ItemOp.U9RouteCode=ITEMOP.ROUTECODE AND u9ItemOp.ITEMCODE=ITEMOP.itemcode AND u9ItemOp.U9Opcode=OP.DEFAULT1 |
|||
WHERE ITEMOP.TenantId='{0}' and u9ItemOp.U9RouteCode is null ";
|
|||
|
|||
itemOpSql += ICSHelper.InsertSQL("ICSITEMROUTE2OP", ItemOpDic) |
|||
+ @" #TEMPITEMOP a
|
|||
LEFT JOIN ICSITEMROUTE2OP b on a.ROUTECODE=b.ROUTECODE and A.ITEMCODE=B.ITEMCODE AND A.OPCODE=B.OPCODE AND b.TenantId='{0}' |
|||
WHERE 1=1 and b.ID is null";
|
|||
|
|||
itemOpSql = string.Format(itemOpSql, TenantId, erpName, ErpId); |
|||
|
|||
itemOpSql += " DROP TABLE #TEMPITEMOP"; |
|||
|
|||
#endregion
|
|||
|
|||
#region 工序资源
|
|||
string opResSql = ""; |
|||
count = 0; |
|||
var opResObj = table.AsEnumerable().Where(a => a["resCode"].ToString() != "").Select(a => new { RouteCode = a["ROUTECODE"].ToString(), Opcode = a["MesOpcode"].ToString(), Opseq = a["opseq"].ToString(), ItemCode = a["ItemCode"].ToString(), resCode = a["resCode"].ToString(), resName = a["resName"].ToString(), PerResUsage = a["PerResUsage"].ToString(), PerResOutput = a["PerResOutput"].ToString() }). |
|||
Distinct().ToList(); |
|||
opResObj.ForEach(b => { |
|||
count++; |
|||
|
|||
if (count != opResObj.Count) |
|||
opResSql += $" SELECT '{b.RouteCode}' as RouteCode,'{b.Opcode}' as Opcode,'{b.Opseq}' as Opseq,'{b.resCode}' as resCode,'{b.ItemCode}' as ItemCode,'{b.resName}' as resName,'{b.PerResUsage}' as PerResUsage,'{b.PerResOutput}' as PerResOutput union all"; |
|||
else |
|||
opResSql += $" SELECT '{b.RouteCode}' as RouteCode,'{b.Opcode}' as Opcode,'{b.Opseq}' as Opseq,'{b.resCode}' as resCode,'{b.ItemCode}' as ItemCode,'{b.resName}' as resName,'{b.PerResUsage}' as PerResUsage,'{b.PerResOutput}' as PerResOutput "; |
|||
|
|||
}); |
|||
|
|||
opResSql = $@"SELECT a.*,B.ID AS RouteId,c.id as OpId,d.id as ItemId,C.DEFAULT1 AS U9OPCODE INTO #TempOPRes FROM ({opResSql}) a
|
|||
LEFT JOIN ICSROUTE b on b.RouteCODE=a.RouteCode and b.TenantId='{TenantId}' |
|||
LEFT JOIN ICSOP C ON C.OPCODE=A.OPCODE AND C.TenantId='{TenantId}' |
|||
LEFT JOIN IcsInventory D ON D.ItemCode=A.ItemCode AND D.TenantId='{TenantId}' |
|||
";
|
|||
Dictionary<string, string> opResDic = new Dictionary<string, string>(); |
|||
opResDic.Add("PerResUsage", "CAST(A.PerResUsage AS DECIMAL)"); |
|||
opResDic.Add("PerResOutput", "CAST(A.PerResOutput AS DECIMAL)"); |
|||
opResDic.Add("LastModificationTime", "GETDATE()");//操作时间
|
|||
opResDic.Add("LastModifierUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
|
|||
opResDic.Add("LastModifierUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
|
|||
opResSql += ICSHelper.UpdateSQL("b", opResDic) |
|||
+ " #TempOPRes a" |
|||
+ " INNER JOIN IcsOpResU9 b on a.ROUTECODE = b.ROUTECODE and A.ITEMCODE = B.ITEMCODE AND A.OPCODE = B.OPCODE AND A.ResCode=B.U9ResCode AND b.TenantId = '{0}'"; |
|||
|
|||
opResSql += @"
|
|||
DELETE OPRES |
|||
FROM IcsOpResU9 OPRES |
|||
LEFT JOIN ICSOP OP ON OPRES.OPID=OP.ID |
|||
LEFT JOIN |
|||
(SELECT item.Code+'_'+u9route.RoutingVersionCode+ '_'+cast(u9route.AlternateType as nvarchar) as U9RouteCode, |
|||
item.Code as itemcode, |
|||
opu9trl.Description+'_'+OPU9.Sequence as U9Opcode, |
|||
u9Res.code as resCode |
|||
FROM {1}.DBO.CBO_Routing u9route |
|||
LEFT JOIN {1}.DBO.CBO_Operation opu9 on opu9.Routing=u9route.ID |
|||
LEFT JOIN {1}.DBO.CBO_ItemMaster item on u9route.ItemMaster=item.ID |
|||
LEFT JOIN {1}.DBO.CBO_OpResource opRes ON opRes.Operation=opu9.id |
|||
LEFT JOIN {1}.DBO.CBO_Operation_TRL opu9trl on opu9trl.ID=opu9.ID |
|||
LEFT JOIN {1}.DBO.CBO_Resource u9Res on u9Res.ID=opRes.Resource |
|||
WHERE u9route.org='{2}' |
|||
) u9opres on u9opres.U9RouteCode=OPRES.ROUTECODE AND u9opres.ITEMCODE=OPRES.itemcode AND u9opres.U9Opcode=OP.DEFAULT1 and u9opres.rescode=OPRES.U9ResCode |
|||
WHERE OPRES.TenantId='{0}' and u9opres.U9Opcode is null ";
|
|||
|
|||
opResDic.Add("RouteCode", "A.RouteCode"); |
|||
opResDic.Add("ItemCode", "A.ItemCode"); |
|||
opResDic.Add("u9Rescode", "A.Rescode"); |
|||
opResDic.Add("u9ResName", "A.ResName"); |
|||
opResDic.Add("OpCode", "A.OpCode"); |
|||
opResDic.Add("OpSeq", "A.OpSeq"); |
|||
opResDic.Add("ITEMID", "A.ITEMID"); |
|||
opResDic.Add("RouteId", "A.RouteId"); |
|||
opResDic.Add("OpId", "A.OpId"); |
|||
opResDic.Add("TenantId", "'" + TenantId + "'"); |
|||
opResDic.Add("CreationTime", "GETDATE()");//操作时间
|
|||
opResDic.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
|
|||
opResDic.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
|
|||
opResSql += ICSHelper.InsertSQL("IcsOpResU9", opResDic) |
|||
+ " #TempOPRes a" |
|||
+ " LEFT JOIN IcsOpResU9 b on a.ROUTECODE = b.ROUTECODE and A.ITEMCODE = B.ITEMCODE AND A.OPCODE = B.OPCODE AND A.ResCode=B.U9ResCode AND b.TenantId = '{0}' WHERE B.ID IS NULL "; |
|||
|
|||
opResSql = string.Format(opResSql, TenantId, erpName, ErpId); |
|||
|
|||
opResSql += " DROP TABLE #TempOPRes"; |
|||
#endregion
|
|||
|
|||
log.Info("开始同步工序"); |
|||
ICSHelper.ExecuteDateNew(conStr, opsql); |
|||
log.Info("结束同步工序"); |
|||
|
|||
log.Info("开始同步途程"); |
|||
ICSHelper.ExecuteDateNew(conStr, routeSql); |
|||
log.Info("结束同步途程"); |
|||
|
|||
log.Info("开始同步途程关联工序"); |
|||
ICSHelper.ExecuteDateNew(conStr, routeOpSql); |
|||
log.Info("结束同步途程关联工序"); |
|||
|
|||
log.Info("开始同步物料关联途程"); |
|||
ICSHelper.ExecuteDateNew(conStr, itemRouteSql); |
|||
log.Info("结束同步物料关联途程"); |
|||
|
|||
log.Info("开始同步物料关联途程与工序"); |
|||
ICSHelper.ExecuteDateNew(conStr, itemOpSql); |
|||
log.Info("结束同步物料关联途程与工序"); |
|||
|
|||
log.Info("开始同步工序关联资源信息"); |
|||
ICSHelper.ExecuteDateNew(conStr, opResSql); |
|||
log.Info("结束同步工序关联资源信息"); |
|||
|
|||
var maxTime = table.AsEnumerable().Max(a => Convert.ToDateTime(a["RouteModifiedTime"])); |
|||
ICSHelper.UpdateTime(conStr, Namespace, Class, TenantId, maxTime); |
|||
|
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
|
|||
throw ex; |
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
@ -0,0 +1,165 @@ |
|||
using Quartz; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace ICSSoft.FromERP |
|||
{ |
|||
/// <summary>
|
|||
/// 产品Bom(锐腾)
|
|||
/// </summary>
|
|||
public class IcsSBom_Rhtyon : 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 A2.[ID] as 料品ID,
|
|||
A2.[Code] as 料品编码, |
|||
A2.Name as 料品名称, |
|||
A4.Description as 料品描述, |
|||
A3.ID as 子阶料ID, |
|||
A3.[Code] as 子阶料编码, |
|||
A3.[Name] as 子阶料名称, |
|||
A5.Description as 子阶料描述, |
|||
A.FixedScrap as 固定损耗, |
|||
isnull( A6.[Code],'') as 项目号, |
|||
isnull( A.[ECNCode],'') as 工程变更号, |
|||
A.[UsageQty], |
|||
a.ParentQty, |
|||
cast(isnull( A.[UsageQty],0)/isnull( a.ParentQty,1) as decimal(18,6)) 子阶料计量数量, |
|||
A.[ItemVersionCode] as 子阶料物料版本, |
|||
A.[EffectiveDate] as 生效日期, |
|||
isnull( A.IsSpecialUseItem,'') as 管控类型, |
|||
A.[DisableDate] as 失效日期, |
|||
A.[Sequence] as 次序, |
|||
A.[IsEffective] as 有效, |
|||
A1.[BOMVersionCode] as 母料版本号, |
|||
A.[OperationNum] as 工序号 |
|||
,I.id as Org |
|||
,A.ModifiedOn as MTime |
|||
,A.ID as ErpDetailID |
|||
INTO #TempBOM |
|||
from {1}.dbo.CBO_BOMComponent as A |
|||
left join {1}.dbo.[CBO_BOMMaster] as A1 on (A.[BOMMaster] = A1.[ID]) |
|||
left join {1}.dbo.[CBO_ItemMaster] as A2 on (A1.[ItemMaster] = A2.[ID]) |
|||
left join {1}.dbo.[CBO_ItemMaster_Trl] as A4 on (A4.SysMlFlag = 'zh-CN') and (A2.[ID] = A4.[ID]) |
|||
left join {1}.dbo.[CBO_ItemMaster] as A3 on (A.[ItemMaster] = A3.[ID]) |
|||
left join {1}.dbo.[CBO_ItemMaster_Trl] as A5 on (A5.SysMlFlag = 'zh-CN') and (A3.[ID] = A5.[ID]) |
|||
left join {1}.dbo.[CBO_Project] as A6 on (A.[CompProject] = A6.[ID]) |
|||
LEFT JOIN {1}.dbo.[Base_Organization] AS I ON ( A1.[Org] = I.[ID] ) |
|||
LEFT JOIN {1}.dbo.[Base_Organization_Trl] AS J ON ( I.[ID] = J.[ID] AND J.SysMLFlag='zh-CN') |
|||
where 1=1 and IsEffective=1 and A.ModifiedOn>=@LastTime AND I.id={0} and A.ComponentType=0 and A1.AlternateType=0 |
|||
|
|||
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 += @"--删除数据
|
|||
-- DELETE ICSSBOM WHERE moOpComponentId NOT IN (SELECT OpComponentId FROM {1}.dbo.bom_opcomponent) |
|||
SELECT a.ErpId INTO #tableICSSBOM |
|||
FROM ICSSBOM a With(NoLock) |
|||
LEFT JOIN {1}.dbo.[CBO_BOMComponent] b With(NoLock) ON a.ErpId=b.Id |
|||
LEFT JOIN {1}.dbo.CBO_BOMMaster c With(NoLock) ON b.BOMMaster=c.Id |
|||
WHERE b.id is null |
|||
and a.TenantId='{0}' |
|||
AND c.Org={2} |
|||
|
|||
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("SBItemDesc", "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}' and a.Org={2} ";
|
|||
|
|||
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 |
|||
and a.Org={2} ";
|
|||
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()); |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
Binary file not shown.
Write
Preview
Loading…
Cancel
Save
Reference in new issue