diff --git a/ICSSoft.FromERP/App.config b/ICSSoft.FromERP/App.config index 7b62e13..0c5585a 100644 --- a/ICSSoft.FromERP/App.config +++ b/ICSSoft.FromERP/App.config @@ -3,7 +3,7 @@ - + @@ -15,12 +15,16 @@ - + + + + + - + diff --git a/ICSSoft.FromERP/ICSInventory_PaiNaWeiS.cs b/ICSSoft.FromERP/ICSInventory_PaiNaWeiS.cs new file mode 100644 index 0000000..2110d6d --- /dev/null +++ b/ICSSoft.FromERP/ICSInventory_PaiNaWeiS.cs @@ -0,0 +1,289 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Quartz; + +using System.Data; + +namespace ICSSoft.FromERP +{ + /// + /// 物料档案(凯尔克) + /// + public class ICSInventory_PaiNaWeiS : 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; + bool isAutoBindOp = Convert.ToBoolean(ICSHelper.GetConfigString()["IsAutoBindItemOP"]); + //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 values = new Dictionary(); + 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", "a.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 + "' 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); + log.Info(sql); + // return; + ICSHelper.ExecuteDate(conStr, sql); + // return; + if (isAutoBindOp) //物料是否直接关联工艺路线 + { + #region 创建默认工艺路线,工序 + string route = ICSHelper.GetConfigString()["DefaultRoute"].ToString(); + string op = ICSHelper.GetConfigString()["DefaultOp"].ToString(); + string routeDesc = ICSHelper.GetConfigString()["DefaultRouteDesc"].ToString(); + string opDesc = ICSHelper.GetConfigString()["DefaultOpDesc"].ToString(); + var bindSql = ""; + bindSql += $"\r\n select '{op}' as OpCode,'{opDesc}' as OpDesc into #TempOp "; + Dictionary opDic = new Dictionary(); + opDic.Add("Opcode", "A.OPCODE"); + opDic.Add("Opdesc", "A.OPDESC"); + opDic.Add("OPNAME", "A.OPDESC"); + opDic.Add("OPSEQ", "10"); + 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("TenantId", "'" + TenantId + "'"); + opDic.Add("CreationTime", "GETDATE()");//操作时间 + opDic.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人 + opDic.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称 + bindSql += ICSHelper.InsertSQL("ICSOP", opDic) + +$@" #TempOp a + LEFT JOIN ICSOP b on a.OPCODE=b.OPCODE and b.TenantId='{TenantId}' + WHERE 1=1 and b.OPCODE is null"; + + bindSql+=$"\r\n select '{route}' as RouteCode,'{routeDesc}' as RouteName Into #TempRoute "; + Dictionary routeDic = new Dictionary(); + routeDic.Add("RouteCode", "A.RouteCode"); + routeDic.Add("RouteName", "A.RouteName"); + routeDic.Add("RouteDesc", "A.RouteName"); + routeDic.Add("RouteType", "'Normal'"); + routeDic.Add("EffDate", "getdate()"); + routeDic.Add("IvlDate", "'2999-12-30 00:00:00.0000000'"); + routeDic.Add("Enabled", "'Y'"); + routeDic.Add("TenantId", "'" + TenantId + "'"); + routeDic.Add("CreationTime", "GETDATE()");//操作时间 + routeDic.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人 + routeDic.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称 + bindSql+=ICSHelper.InsertSQL("ICSROUTE", routeDic) + + $@"#TempRoute a + LEFT JOIN ICSROUTE b on a.ROUTECODE=b.ROUTECODE and b.TenantId='{TenantId}' + WHERE 1=1 and b.ID is null "; + + Dictionary routeOpDic = new Dictionary(); + routeOpDic.Add("RouteCode", "A.RouteCode"); + routeOpDic.Add("OPCODE", "A.OPCODE"); + routeOpDic.Add("ROUTEID", "A.ROUTEID"); + routeOpDic.Add("OPID", "A.OPID"); + routeOpDic.Add("OPSEQ", "10"); + routeOpDic.Add("IsMaterial", "'N'"); + routeOpDic.Add("IsMerge", "'N'"); + routeOpDic.Add("OpLevel", "'A'"); + routeOpDic.Add("OpControlSeq", "10"); + routeOpDic.Add("OPControl", "'10000000'"); + routeOpDic.Add("ParallelOp", "'N'"); + routeOpDic.Add("TenantId", "'" + TenantId + "'"); + routeOpDic.Add("CreationTime", "GETDATE()");//操作时间 + routeOpDic.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人 + routeOpDic.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称 + bindSql += ICSHelper.InsertSQL("ICSROUTE2OP", routeOpDic) + + $@"(SELECT RouteCode,ROUTE.ID ROUTEID,OPCODE,OP.ID OPID FROM ICSROUTE route Inner JOIN ICSOP op on op.opcode='{op}' and route.TenantId=op.TenantId and route.RouteCode='{route}' and route.TenantId='{TenantId}') a + LEFT JOIN ICSROUTE2OP b on a.ROUTECODE=b.ROUTECODE and A.OPCODE=B.OPCODE AND b.TenantId='{TenantId}' + WHERE 1=1 and b.OPCODE is null "; + #endregion + + #region 物料绑定默认工艺路线,工序 + Dictionary ItemRouteDic = new Dictionary(); + 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("TenantId", "'" + TenantId + "'"); + ItemRouteDic.Add("CreationTime", "GETDATE()");//操作时间 + ItemRouteDic.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人 + ItemRouteDic.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称 + bindSql += ICSHelper.InsertSQL("ICSITEM2ROUTE",ItemRouteDic) + + $@"(select a.ItemCode,a.Id as ItemId,c.id as ROUTEID,c.routeCode from IcsInventory a + --left join IcsItem2Route b on a.ItemCode=b.ItemCode and a.TenantId=b.TenantId + left join IcsRoute c on c.routeCode='{route}' and c.TenantId=a.TenantId + where a.TenantId='{TenantId}') a + LEFT JOIN ICSITEM2ROUTE b on a.ROUTECODE=b.ROUTECODE and A.ITEMCODE=B.ITEMCODE AND b.TenantId='{TenantId}' + WHERE 1=1 and b.ID is null + + Update ICSITEM2ROUTE SET IsRef='N' where routeCode<>'{route}' and TenantId='{TenantId}' "; + + + Dictionary ItemOpDic = new Dictionary(); + 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("ParallelOp", "'N'"); + ItemOpDic.Add("TenantId", "'" + TenantId + "'"); + ItemOpDic.Add("CreationTime", "GETDATE()");//操作时间 + ItemOpDic.Add("CreatorUserId", "'" + ConstWorkPoint.Muser + "'");//操作人 + ItemOpDic.Add("CreatorUserName", "'" + ConstWorkPoint.Musername + "'");//操作人名称 + + bindSql+=ICSHelper.InsertSQL("ICSITEMROUTE2OP", ItemOpDic) + + $@"(select a.ItemCode,a.Id as ItemId,c.id as RouteId,c.RouteCode,d.OpCode,d.OpId,d.OpSeq from IcsInventory a + left join IcsRoute c on c.routeCode='{route}' and c.TenantId=a.TenantId + left join IcsRoute2Op d on d.RouteCode=c.RouteCode and d.TenantId=a.TenantId + where a.TenantId='{TenantId}') 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"; + log.Info(bindSql); + ICSHelper.ExecuteDate(conStr, bindSql); + #endregion + } + #endregion + } + } + catch (Exception ex) + { + log.Error(ex.ToString()); + } + } + } +} diff --git a/ICSSoft.FromERP/ICSMo.cs b/ICSSoft.FromERP/ICSMo.cs index f0b1eae..de0d79a 100644 --- a/ICSSoft.FromERP/ICSMo.cs +++ b/ICSSoft.FromERP/ICSMo.cs @@ -86,7 +86,8 @@ namespace ICSSoft.FromERP '' as cFree10,CAST('' AS NVARCHAR(500)) as Colspan ,A12.Code as TenantId ,A12.id as Org - ,a.DescFlexField_PrivateDescSeg1 AS EATTRIBUTE1 + ,a.DescFlexField_PrivateDescSeg1 AS EATTRIBUTE1, + a.DescFlexField_PubDescSeg5 as EATTRIBUTE5 ,( select b1.code from {1}.dbo.UBF_Sys_ExtEnumType a1 left join {1}.dbo.UBF_Sys_ExtEnumValue b1 on a1.ID=b1.ExtEnumType @@ -163,7 +164,7 @@ else Convert(varchar(10),a.ActualCompleteDate,120 ) end as ActualCompleteDate values.Add("WHCode", "a.WHCode");//仓库 values.Add("MoPlanStartDate", "a.StartDate");//开工日 values.Add("MoPlanEndDate", "a.DueDate");//完工日 - + values.Add("Default5", "a.Eattribute5");//项目名称 values.Add("MOMemo", "a.MOMemo");//生产订单状态 values.Add("MoUser", "a.CreatePerson");//生产订单状态 values.Add("MODOWNDATE", "a.CreateDateTime");//生产订单状态 diff --git a/ICSSoft.FromERP/ICSSoft.FromERP.csproj b/ICSSoft.FromERP/ICSSoft.FromERP.csproj index 770c2cf..4abd8e4 100644 --- a/ICSSoft.FromERP/ICSSoft.FromERP.csproj +++ b/ICSSoft.FromERP/ICSSoft.FromERP.csproj @@ -98,6 +98,7 @@ +