Browse Source

Merge branch 'master' of http://119.3.29.177:3000/xusc/IcsFromERPJob

Branch_PaiNaWeiSJob
shiqian.wang 4 weeks ago
parent
commit
3cb0692cc9
  1. BIN
      .vs/ICSSoft.FromERP/v16/.suo
  2. 4
      ICSSoft.FromERP/App.config
  3. 2
      ICSSoft.FromERP/ICSInventory.cs
  4. 16
      ICSSoft.FromERP/ICSInventory_Rhtyon.cs
  5. 9
      ICSSoft.FromERP/ICSSoft.FromERP.csproj
  6. 104
      ICSSoft.FromERP/IcsAutoSyncMoRoute_Rhtyon.cs
  7. 47
      ICSSoft.FromERP/IcsOp.cs
  8. 2
      ICSSoft.Test/ICSSoft.Test.csproj
  9. 2
      ICSSoft.Test/Program.cs

BIN
.vs/ICSSoft.FromERP/v16/.suo

Binary file not shown.

4
ICSSoft.FromERP/App.config

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="ERPDB" value="[U9Ctest]"/>
<!--<add key="ERPDB" value="[192.168.93.132].[U9TEST0628]"/>-->
<!--<add key="ERPDB" value="[U9Ctest]"/>-->
<add key="ERPDB" value="[192.168.93.132].[U9TEST0628]"/>
<add key="Workpoint_ERPDB" value="zhc|[MESTOU8].[UFDATA_001_2017]"/>
</appSettings>
<connectionStrings>

2
ICSSoft.FromERP/ICSInventory.cs

@ -127,7 +127,7 @@ a.DescFlexField_PrivateDescSeg2 ItemDrawingNo
values.Add("ItemType", "d.ItemType");//操作时间
values.Add("ItemContype", "d.ItemContype");//操作时间
values.Add("ItemControlType", "d.ItemControlType");//操作时间
values.Add("ItemDrawingNo", "b.ItemDrawingNo");//操作时间
values.Add("ItemDrawingNo", "a.ItemDrawingNo");//操作时间
//更新存在数据

16
ICSSoft.FromERP/ICSInventory_Rhtyon.cs

@ -54,7 +54,11 @@ namespace ICSSoft.FromERP
A.Code AS ItemCode
,a.ItemFormAttribute
,dbo.GetReplaceStr(A.Name) AS ItemName,
a.DescFlexField_PrivateDescSeg2 ItemDrawingNo
a.DescFlexField_PrivateDescSeg1 ItemDrawingNo
,a.DescFlexField_PrivateDescSeg2 as Default2
,a.DescFlexField_PrivateDescSeg8 as Default1
,a.DescFlexField_PrivateDescSeg9 Default3
,a.DescFlexField_PrivateDescSeg11 Default4
,b.Description ItemDesc,
dbo.GetReplaceStr(A.SPECS) AS ItemStd,
D.Name AS ItemUnit,
@ -90,6 +94,7 @@ a.DescFlexField_PrivateDescSeg2 ItemDrawingNo
sql = string.Format(sql, ErpId, erpName);
sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempINV");
sql += @"--删除数据
SELECT a.ItemCode INTO #tableICSINVENTORY
@ -125,8 +130,13 @@ a.DescFlexField_PrivateDescSeg2 ItemDrawingNo
//values.Add("ItemType", "d.ItemType");//操作时间
values.Add("ItemContype", "d.ItemContype");//操作时间
values.Add("ItemControlType", "d.ItemControlType");//操作时间
values.Add("ItemDrawingNo", "b.ItemDrawingNo");//操作时间
values.Add("ItemDrawingNo", "a.ItemDrawingNo");//操作时间
values.Add("ItemType", "'itemtype_finishedproduct'");
values.Add("Default1", "a.Default1");
values.Add("Default2", "a.Default2");
values.Add("Default3", "a.Default3");
values.Add("Default4", "a.Default4");
// values.Add("Default5", "b.Default4");
//更新存在数据
sql += ICSHelper.UpdateSQL("b", values)
@ -149,7 +159,7 @@ a.DescFlexField_PrivateDescSeg2 ItemDrawingNo
sql += " DROP TABLE #TempINV " +
" DROP TABLE #tableICSINVENTORY ";
sql = string.Format(sql, TenantId, erpName, ErpId);
// return;
//return;
ICSHelper.ExecuteDate(conStr, sql);
#endregion
}

9
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" />
@ -94,6 +93,7 @@
<Compile Include="IcsAutoMo2Lot4JWX.cs" />
<Compile Include="IcsAutoSyncItemRoute.cs" />
<Compile Include="IcsAutoSyncMoRoute.cs" />
<Compile Include="IcsAutoSyncMoRoute_Rhtyon.cs" />
<Compile Include="ICSDeliveryNotice.cs" />
<Compile Include="ICSDisassemblyDoc.cs" />
<Compile Include="ICSICSMOIssue.cs" />
@ -170,6 +170,7 @@
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>

104
ICSSoft.FromERP/IcsAutoSyncMoRoute_Rhtyon.cs

@ -0,0 +1,104 @@
using Quartz;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
namespace ICSSoft.FromERP
{
/// <summary>
/// 工单工艺自动生成(锐腾)
/// </summary>
public class IcsAutoSyncMoRoute_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;
// List<string> itemCodeList = new List<string>() { "A2001", "A2002", "KA10", "A2003" };
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 sql1 = @"
select a.MoCode,a.MoSeq, a.Id,a.ItemCode ,b.RouteCode
from IcsMo a with(nolock)
left join IcsItem2Route b with(nolock) on a.ItemCode=b.ItemCode and b.IsRef='Y' and a.TenantId=b.TenantId
where a.MoStatus='mostatus_initial'
and not exists (select MoCode from IcsMo2Route with(nolock) where MoCode=a.MoCode) and a.TenantId='" + TenantId + "' " +
" and b.RouteCode is not null ";
var itemDt = ICSHelper.ExecuteTable(conStr, sql1);
if (itemDt != null && itemDt.Rows.Count > 0)
{
//循环工单
string sql2 = "";
for (int i = 0; i < itemDt.Rows.Count; i++)
{
var item = itemDt.Rows[i];
//工艺路线表头
sql2 += @"
insert into IcsMo2Route (MoId,RouteId,MoCode,MoSeq, RouteCode,IsMRoute, TenantId,CreationTime,CreatorUserId,CreatorUserName)
select top 1 " + item["Id"].ToInt64() + ",Id,'" + item["MoCode"].ToString() + "'," + item["MoSeq"].ToInt64() + ",RouteCode,'Y','" + TenantId + "',GETDATE(),'c65321b94c804dc26eb93a0ba67c8a2a','xusc' from IcsItem2Route a " +
" where ItemCode='" + item["ItemCode"].ToString() + "' " +
"and a.IsRef='Y' and TenantId='" + TenantId + "' ";
//工艺路线明细
sql2 += @"
insert into IcsMoRoute2Op (MoId,RouteId,OpId,MoCode,MoSeq, RouteCode,OpCode,OpSeq,OpControl ,OpLevel ,OpControlSeq,ParallelOp
,TenantId,CreationTime,CreatorUserId,CreatorUserName)
select " + item["Id"].ToInt64() + ",RouteId,OpId,'" + item["MoCode"].ToString() + "'," + item["MoSeq"].ToInt64() + ",RouteCode,OpCode,OpSeq,OPControl,'A',OpControlSeq,'N','" + TenantId + "',GETDATE(),'c65321b94c804dc26eb93a0ba67c8a2a','xusc' from IcsItemRoute2Op a " +
"where ItemCode='" + item["ItemCode"].ToString() +
"' and a.RouteCode='"+ item["RouteCode"].ToString() + "' and TenantId='" + TenantId + "' ";
sql2 += @" update icsmo set MoRoute='" + item["RouteCode"].ToString() + "' where Id=" + item["Id"].ToInt64() + " and TenantId='" + TenantId + "' ";
}
ICSHelper.ExecuteDate(conStr, sql2);
}
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
}
}

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

2
ICSSoft.Test/ICSSoft.Test.csproj

@ -94,7 +94,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ICSSoft.FromERP\ICSSoft.FromERP.csproj">
<Project>{71BE770C-F5BE-46C8-A81C-1897E28DB761}</Project>
<Project>{71be770c-f5be-46c8-a81c-1897e28db761}</Project>
<Name>ICSSoft.FromERP</Name>
</ProjectReference>
</ItemGroup>

2
ICSSoft.Test/Program.cs

@ -13,7 +13,7 @@ namespace ICSSoft.Test
//ICSVendor test = new ICSVendor();
//test.Execute();
IcsSBom_Rhtyon test = new IcsSBom_Rhtyon();
ICSInventory_Rhtyon test = new ICSInventory_Rhtyon();
test.Execute();

Loading…
Cancel
Save