Browse Source

工艺路线更新

Branch_PaiNaWeiSJob
DESKTOP-QD1SU79\Xfu 3 months ago
parent
commit
6a5a225ebe
  1. 8
      ICSSoft.FromERP/ICSSoft.FromERP.csproj
  2. 47
      ICSSoft.FromERP/IcsOp.cs

8
ICSSoft.FromERP/ICSSoft.FromERP.csproj

@ -26,7 +26,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>..\ICSSoft.Test\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
@ -54,9 +54,8 @@
<Reference Include="NPinyin">
<HintPath>..\Root\NPinyin.dll</HintPath>
</Reference>
<Reference Include="Quartz, Version=2.6.1.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\Debug\Quartz.dll</HintPath>
<Reference Include="Quartz">
<HintPath>..\Root\Quartz.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
@ -160,6 +159,7 @@
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>

47
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);

Loading…
Cancel
Save