diff --git a/ICSSoft.FromERP/ICSSoft.FromERP.csproj b/ICSSoft.FromERP/ICSSoft.FromERP.csproj
index 640371f..ba6965c 100644
--- a/ICSSoft.FromERP/ICSSoft.FromERP.csproj
+++ b/ICSSoft.FromERP/ICSSoft.FromERP.csproj
@@ -26,7 +26,7 @@
true
full
false
- bin\Debug\
+ ..\ICSSoft.Test\bin\Debug\
DEBUG;TRACE
prompt
4
@@ -54,9 +54,8 @@
..\Root\NPinyin.dll
-
- False
- bin\Debug\Quartz.dll
+
+ ..\Root\Quartz.dll
@@ -160,6 +159,7 @@
Designer
+ PreserveNewest
diff --git a/ICSSoft.FromERP/IcsOp.cs b/ICSSoft.FromERP/IcsOp.cs
index c7b9169..585cb0a 100644
--- a/ICSSoft.FromERP/IcsOp.cs
+++ b/ICSSoft.FromERP/IcsOp.cs
@@ -49,6 +49,7 @@ namespace ICSSoft.FromERP
//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,
+case AlternateType when '0' then '主制造' when '1' then '委外' when '2001' then '试制' end as AlternateType,
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,
@@ -153,15 +154,15 @@ WHERE u9route.org='{0}' And u9route.ModifiedOn>='{1}' and u9route.ApproveDate i
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() }).
+ 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["RoutingVersionCode"].ToString(), Lot = a["Lot"].ToString(), AlternateType = a["AlternateType"].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 ";
+ 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,'{b.AlternateType}' as AlternateType 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";
+ 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,'{b.AlternateType}' as AlternateType";
});
itemRouteSql = routeSql;
@@ -173,6 +174,8 @@ WHERE u9route.org='{0}' And u9route.ModifiedOn>='{1}' and u9route.ApproveDate i
routeDic.Add("RouteType", "'Normal'");
routeDic.Add("EffDate", "a.EffDate");
routeDic.Add("IvlDate", "a.IvlDate");
+ routeDic.Add("Default4", "a.RouteVersion");
+ routeDic.Add("Default5", "a.AlternateType");
routeDic.Add("Enabled", "'Y'");
routeDic.Add("TenantId", "'" + TenantId + "'");
routeDic.Add("CreationTime", "GETDATE()");//操作时间
@@ -288,22 +291,25 @@ WHERE u9route.org='{0}' And u9route.ModifiedOn>='{1}' and u9route.ApproveDate i
ItemRouteDic.Add("Default1", "A.ProductLine");
ItemRouteDic.Add("Default2", "A.ProductLineName");
ItemRouteDic.Add("Default3", "A.LOT");
+ ItemRouteDic.Add("Default4", "a.RouteVersion");
ItemRouteDic.Add("TenantId", "'" + TenantId + "'");
ItemRouteDic.Add("CreationTime", "GETDATE()");//操作时间
ItemRouteDic.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人
ItemRouteDic.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称
+
+
+ //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 += 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);
@@ -445,6 +451,25 @@ WHERE u9route.org='{0}' And u9route.ModifiedOn>='{1}' and u9route.ApproveDate i
opResSql += " DROP TABLE #TempOPRes";
#endregion
+ string updateRef =@"
+UPDATE
+A
+SET IsRef = 'N'
+FROM IcsItem2Route A
+LEFT JOIN IcsRoute C ON A.RouteId = C.Id
+LEFT JOIN
+(
+select MAX(SUBSTRING(A.default4, 2, len(A.default4) - 1)) AS[VerSion], ItemCode, B.Default5, A.TenantId
+from IcsItem2Route A
+LEFT JOIN IcsRoute B ON A.RouteId = B.Id
+GROUP BY ItemCode, B.Default5, A.TenantId
+HAVING(NOT EXISTS(SELECT IcsItem2Route.ID FROM IcsItem2Route
+LEFT JOIN IcsRoute ON IcsItem2Route.RouteId = IcsRoute.Id
+ WHERE IcsItem2Route.ItemCode = A.ItemCode AND B.Default5 <> IcsRoute.Default5) OR B.Default5 = '主制造'))B
+ on B.Default5 = C.Default5 AND b.ItemCode = a.ItemCode and b.VerSion = SUBSTRING(A.default4, 2, len(A.default4) - 1) AND B.TenantId = A.TenantId
+WHERE B.ItemCode IS NULL";
+
+
log.Info("开始同步工序");
ICSHelper.ExecuteDateNew(conStr, opsql);
log.Info("结束同步工序");
@@ -469,6 +494,10 @@ WHERE u9route.org='{0}' And u9route.ModifiedOn>='{1}' and u9route.ApproveDate i
ICSHelper.ExecuteDateNew(conStr, opResSql);
log.Info("结束同步工序关联资源信息");
+ log.Info("开始更新默认途程");
+ ICSHelper.ExecuteDateNew(conStr, updateRef);
+ log.Info("结束更新默认途程");
+
var maxTime = table.AsEnumerable().Max(a => Convert.ToDateTime(a["RouteModifiedTime"]));
ICSHelper.UpdateTime(conStr, Namespace, Class, TenantId, maxTime);