xusc
3 weeks ago
4 changed files with 394 additions and 0 deletions
-
BIN.vs/ICSSoft.FromERP/v14/.suo
-
179ICSSoft.FromERP/ICSInventoryFromU8_XinHJ.cs
-
213ICSSoft.FromERP/ICSMoFromU8_XinHJ.cs
-
2ICSSoft.FromERP/ICSSoft.FromERP.csproj
Binary file not shown.
@ -0,0 +1,179 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using Quartz; |
|||
|
|||
using System.Data; |
|||
using System.Net.NetworkInformation; |
|||
|
|||
namespace ICSSoft.FromERP |
|||
{ |
|||
/// <summary>
|
|||
/// 物料档案(来源U8)
|
|||
/// </summary>
|
|||
public class ICSInventoryFromU8_XinHJ : 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;
|
|||
string erpNames = ICSHelper.GetConfigString()["Workpoint_ERPDB"]; |
|||
List<string> DBS = erpNames.Split(',').ToList(); |
|||
List<WorkpointERPDBLink> ListDB = new List<WorkpointERPDBLink>(); |
|||
foreach (string DB in DBS) |
|||
{ |
|||
if (DB.Split('|') != null && DB.Split('|').Count() > 1) |
|||
{ |
|||
WorkpointERPDBLink wd = new WorkpointERPDBLink(); |
|||
wd.Workpoint = DB.Split('|')[0]; |
|||
wd.ERPDB = DB.Split('|')[1]; |
|||
ListDB.Add(wd); |
|||
} |
|||
} |
|||
DataTable dt = ICSHelper.GetERPDB(conStr); |
|||
foreach (DataRow dr in dt.Rows) |
|||
{ |
|||
|
|||
string TenantId = dr["TenantId"].ToString(); |
|||
string TenantCode = dr["TenantCode"].ToString(); |
|||
string ErpId = dr["ErpID"].ToString(); //erpID
|
|||
string Class = this.GetType().Name + TenantCode; |
|||
|
|||
WorkpointERPDBLink dblink= ListDB.FindLast(a => a.Workpoint == TenantCode); |
|||
if (dblink == null) |
|||
{ |
|||
return; |
|||
} |
|||
string erpName = dblink.ERPDB; |
|||
//erpName = string.Format(erpName, TenantId);
|
|||
|
|||
#region SQL
|
|||
string sql = @"
|
|||
|
|||
select NEWID() AS ID, |
|||
a.cInvCode AS ItemCode, |
|||
CASE WHEN A.bSelf ='1' THEN '1' WHEN A.bPurchase='1' THEN '1' when a.bProxyForeign='1' THEN '2' |
|||
else '' end ItemFormAttribute, |
|||
dbo.GetReplaceStr(cInvName) AS ItemName, |
|||
a.cEngineerFigNo ItemDrawingNo, |
|||
'' ItemDesc, |
|||
dbo.GetReplaceStr(isnull(cInvAddCode,'')+'|'+isnull(cInvStd,'')) AS ItemStd, |
|||
a.cInvAddCode INVPARSETYPE, |
|||
c.cComUnitName AS ItemUnit, |
|||
a.cInvCCode ItemMainCategoryCode, |
|||
b.cInvCName ClassName, |
|||
ISNULL(c.iChangRate,0) as ItemRate, |
|||
ISNULL(a.iMassDate,'') as EffectiveDays, |
|||
ISNULL(CONVERT(NVARCHAR(50),a.dModifyDate,21),'') MTime, |
|||
(case when isnull(a.fOutExcess,0)=0 then 0 else (case when isnull(a.fOutExcess,0)>5 then 3 else 2 end) end) 备料超额类型, |
|||
isnull(a.fOutExcess,0) 备料超额值 |
|||
|
|||
INTO #TempINV |
|||
FROM {1}.dbo.Inventory a with(nolock) |
|||
LEFT JOIN {1}.dbo.InventoryClass b with(nolock) ON a.cInvCCode = b.cInvCCode |
|||
LEFT JOIN {1}.dbo.ComputationUnit c with(nolock) ON a.cComUnitCode = c.cComunitCode |
|||
WHERE a.dEDate IS NULL AND a.dModifyDate>=@LastTime |
|||
ORDER BY cInvCode |
|||
|
|||
|
|||
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.[Inventory] b With(NoLock) ON a.ItemCode=b.cInvCode |
|||
WHERE b.cInvCode is null |
|||
and a.TenantId='{0}' |
|||
|
|||
|
|||
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");//产品属性(0:采购,1:自制,2:委外,3虚拟)
|
|||
values.Add("ItemAddCode", "a.INVPARSETYPE"); //产品代码(U8存货代码 )
|
|||
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");//是否IQC检验
|
|||
values.Add("InvFQC", "0");//是否FQC检验
|
|||
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.备料超额类型");//超领类型(1:比例,2:数量,3:不管控)
|
|||
values.Add("OverValue", "a.备料超额值"); |
|||
values.Add("LastModificationTime", "a.Mtime");//操作时间
|
|||
values.Add("ItemType", "'itemtype_finishedproduct'"); |
|||
values.Add("ItemContype", "'item_control_lot'"); |
|||
values.Add("ItemControlType", "'item_control_lot'"); |
|||
values.Add("ItemDrawingNo", "b.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 + "' ";
|
|||
|
|||
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 |
|||
";
|
|||
sql += " DROP TABLE #TempINV " + |
|||
" DROP TABLE #tableICSINVENTORY "; |
|||
sql = string.Format(sql, TenantId, erpName, ErpId); |
|||
|
|||
ICSHelper.ExecuteDate(conStr, sql); |
|||
#endregion
|
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
log.Error(ex.ToString()); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,213 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using Quartz; |
|||
|
|||
|
|||
namespace ICSSoft.FromERP |
|||
{ |
|||
/// <summary>
|
|||
/// 工单(来源U8) -新鸿基
|
|||
/// </summary>
|
|||
public class ICSMoFromU8_XinHJ : 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); |
|||
|
|||
string erpNames = ICSHelper.GetConfigString()["Workpoint_ERPDB"]; |
|||
List<string> DBS = erpNames.Split(',').ToList(); |
|||
List<WorkpointERPDBLink> ListDB = new List<WorkpointERPDBLink>(); |
|||
foreach (string DB in DBS) |
|||
{ |
|||
if (DB.Split('|') != null && DB.Split('|').Count() > 1) |
|||
{ |
|||
WorkpointERPDBLink wd = new WorkpointERPDBLink(); |
|||
wd.Workpoint = DB.Split('|')[0]; |
|||
wd.ERPDB = DB.Split('|')[1]; |
|||
ListDB.Add(wd); |
|||
} |
|||
} |
|||
|
|||
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; |
|||
|
|||
WorkpointERPDBLink dblink = ListDB.FindLast(a => a.Workpoint == TenantCode); |
|||
if (dblink == null) |
|||
{ |
|||
return; |
|||
} |
|||
string erpName = dblink.ERPDB; |
|||
|
|||
//erpName = string.Format(erpName, TenantId);
|
|||
#region SQL
|
|||
string sql = @"
|
|||
|
|||
|
|||
select CAST(b.MoDId as VARCHAR(50)) as ID, |
|||
a.MoCode as MOCODE, |
|||
b.SortSeq as Sequence, |
|||
b.InvCode as InvCode, |
|||
b.Qty as Quantity, |
|||
a.CreateUser as CreatePerson, |
|||
a.CreateTime as CreateDateTime, |
|||
isnull(b.AuxQty,0) as Amount, |
|||
isnull(b.QualifiedInQty,0) as RCVQuantity, |
|||
b.MDeptCode as DepCode, |
|||
b.WhCode as WHCode, |
|||
case when b.CloseUser is not null then 'mostatus_initial' else 'mostatus_close' end as MOStatus, |
|||
b.Remark as MOMemo, |
|||
case when b.CloseUser is not null then '3' else '2' end as ERPStatus, |
|||
c.StartDate as StartDate, |
|||
c.DueDate as DueDate, |
|||
a.MoId as MOID, |
|||
b.MoDId as MODetailID, |
|||
|
|||
CASE WHEN ISNULL(a.ModifyTime, a.CreateTime)> |
|||
ISNULL(b.CloseTime,ISNULL(b.RelsTime,ISNULL(a.ModifyTime, a.CreateTime))) |
|||
THEN ISNULL(a.ModifyTime, a.CreateTime) |
|||
ELSE ISNULL(b.CloseTime,ISNULL(b.RelsTime,ISNULL(a.ModifyTime, a.CreateTime))) END as MTIME, |
|||
isnull(b.CostItemCode,'') ProjectCode,isnull(b.MoLotCode,'') cBatch,'' version ,'' brand, |
|||
(case WHEN inv.bFree1=1 THEN isnull(b.Free1,'') ELSE '' END) as cFree1, |
|||
(case WHEN inv.bFree2=1 THEN isnull(b.Free2,'') ELSE '' END) as cFree2, |
|||
(case WHEN inv.bFree3=1 THEN isnull(b.Free3,'') ELSE '' END) as cFree3, |
|||
(case WHEN inv.bFree4=1 THEN isnull(b.Free4,'') ELSE '' END) as cFree4, |
|||
(case WHEN inv.bFree5=1 THEN isnull(b.Free5,'') ELSE '' END) as cFree5, |
|||
(case WHEN inv.bFree6=1 THEN isnull(b.Free6,'') ELSE '' END) as cFree6, |
|||
(case WHEN inv.bFree7=1 THEN isnull(b.Free7,'') ELSE '' END) as cFree7, |
|||
(case WHEN inv.bFree8=1 THEN isnull(b.Free8,'') ELSE '' END) as cFree8, |
|||
(case WHEN inv.bFree9=1 THEN isnull(b.Free9,'') ELSE '' END) as cFree9, |
|||
(case WHEN inv.bFree10=1 THEN isnull(b.Free10,'') ELSE '' END) as cFree10, |
|||
CAST('' AS NVARCHAR(500)) as Colspan, |
|||
b.MoLotCode 生产批号,b.Free1 零件版本,b.Free2 图纸版本 |
|||
|
|||
INTO #TempMO |
|||
FROM {1}.dbo.mom_order a |
|||
INNER JOIN {1}.dbo.mom_orderdetail b ON a.MoId = b.MoId |
|||
INNER JOIN {1}.dbo.mom_morder c ON b.MoDId = c.MoDId |
|||
LEFT JOIN {1}.dbo.Inventory inv ON b.InvCode = inv.cInvCode |
|||
LEFT JOIN {1}.dbo.Customer cus ON b.CustCode = cus.cCusCode |
|||
LEFT JOIN {1}.dbo.SO_SODetails so ON b.OrderDId = so.iSOsID |
|||
|
|||
where ISNULL (b.RelsUser,'') <> '' |
|||
and CASE WHEN ISNULL(a.ModifyTime, a.CreateTime)>ISNULL(b.CloseTime,ISNULL(b.RelsTime,ISNULL(a.ModifyTime, a.CreateTime))) THEN ISNULL(a.ModifyTime, a.CreateTime) ELSE ISNULL(b.CloseTime,ISNULL(b.RelsTime,ISNULL(a.ModifyTime, a.CreateTime))) END>=@LastTime |
|||
|
|||
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 += @"--删除数据
|
|||
|
|||
SELECT a.ID INTO #tableICSMO |
|||
FROM ICSMO a With(NoLock) |
|||
LEFT JOIN {1}.dbo.[mom_order] b With(NoLock) ON a.Mocode=b.MoCode |
|||
left JOIN {1}.dbo.mom_orderdetail b2 ON b.MoId = b2.MoId AND A.MoSeq=B2.SortSeq |
|||
WHERE a.TenantId='{0}' and B2.SortSeq IS NULL |
|||
|
|||
DELETE FROM ICSMO |
|||
WHERE TenantId='{0}' and ID IN ( SELECT ID 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.生产批号");//完工日
|
|||
values.Add("Default2", "a.零件版本");//完工日
|
|||
values.Add("Default3", "a.图纸版本");//完工日
|
|||
|
|||
//更新存在数据
|
|||
sql += ICSHelper.UpdateSQL("b", values) |
|||
+ @" #TempMO a
|
|||
INNER JOIN ICSMO b ON a.Mocode=b.Mocode AND A.Sequence=B.MoSeq |
|||
WHERE b.TenantId='{0}' ";
|
|||
|
|||
// 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 A.Sequence=B.MoSeq and b.TenantId='{0}' |
|||
WHERE 1=1 and b.MoCode is null ";
|
|||
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()); |
|||
} |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue