You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
219 lines
12 KiB
219 lines
12 KiB
using Quartz;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ICSSoft.FromERP
|
|
{
|
|
/// <summary>
|
|
/// 工单(锐腾)
|
|
/// </summary>
|
|
public class IcsMo_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 conStr = ICSHelper.GetConnectString();
|
|
string Namespace = this.GetType().Namespace;
|
|
//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();//mes 组织
|
|
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.DocNO as MOCODE,
|
|
1 as Sequence,
|
|
A7.Code as InvCode,
|
|
CASE WHEN A.IsStartMO != 1 THEN
|
|
(SELECT TOP 1 TotalStartQty FROM {1}.dbo.MO_MOStartInfo WHERE MO=A.ID ORDER BY StartDatetime DESC)
|
|
ELSE (SELECT TOP 1 ActualStartQty FROM {1}.dbo.MO_MOStartInfo WHERE MO=A.ID ORDER BY StartDatetime DESC) END as Quantity,
|
|
A.CreatedBy as CreatePerson,
|
|
A.CreatedOn as CreateDateTime,
|
|
0 as Amount,
|
|
0 as RCVQuantity,
|
|
A13.Code as DepCode,
|
|
A22.Code as WHCode,
|
|
case when A.DocState=2 then 'mostatus_initial'
|
|
when A.DocState=3 then 'mostatus_close'
|
|
else 'mostatus_initial' end as MOStatus,
|
|
case when A.DocState=2 then '开工' when A.DocState=3 then '关闭' else '开工' end as DocState,
|
|
A2.Description as MOMemo,
|
|
'2' as ERPStatus,
|
|
A.StartDate as StartDate,
|
|
A.CompleteDate as DueDate,
|
|
A.ID as MOID,
|
|
A.ID as MODetailID,
|
|
ISNULL(A.ModifiedOn,A.BusinessCreatedOn) as MTIME
|
|
, isnull(A11.Code,'') ProjectCode
|
|
,'' version ,'' brand,
|
|
'' as cFree1,
|
|
'' as cFree2,
|
|
'' as cFree3,
|
|
'' as cFree4,
|
|
'' as cFree5,
|
|
'' as cFree6,
|
|
'' as cFree7,
|
|
'' as cFree8,
|
|
'' as cFree9,
|
|
'' as cFree10,CAST('' AS NVARCHAR(500)) as Colspan
|
|
,A12.Code as TenantId
|
|
,A12.id as Org
|
|
,a.DescFlexField_PrivateDescSeg1 AS EATTRIBUTE1
|
|
,a.DescFlexField_PrivateDescSeg2 AS EATTRIBUTE2
|
|
,a.DescFlexField_PrivateDescSeg3 AS EATTRIBUTE3
|
|
,(
|
|
select b1.code from {1}.dbo.UBF_Sys_ExtEnumType a1
|
|
left join {1}.dbo.UBF_Sys_ExtEnumValue b1 on a1.ID=b1.ExtEnumType
|
|
left join {1}.dbo.UBF_Sys_ExtEnumValue_Trl c1 on b1.id=c1.ID
|
|
WHERE a1.Code like 'UFIDA.U9.CBO.Enums.DemandCodeEnum'
|
|
and b1.evalue=a.DemandCode
|
|
and b1.code not like 'K10%'
|
|
) as NeedType
|
|
,A4.Name as MoDocType
|
|
,case when a.ActualCompleteDate is null then ''
|
|
else Convert(varchar(10),a.ActualCompleteDate,120 ) end as ActualCompleteDate
|
|
,a.IsFIClose
|
|
INTO #TempMO
|
|
from {1}.dbo.MO_MO as A With(NoLock)
|
|
left join {1}.dbo.[MO_MOMemo] as A1 With(NoLock) on (A.[ID] = A1.[MO])
|
|
left join {1}.dbo.[MO_MOMemo_Trl] as A2 With(NoLock) on (A2.SysMlFlag = 'zh-CN') and (A1.[ID] = A2.[ID])
|
|
left join {1}.dbo.[MO_MODocType] as A3 With(NoLock) on (A.[MODocType] = A3.[ID])
|
|
left join {1}.dbo.[MO_MODocType_Trl] as A4 With(NoLock) on (A4.SysMlFlag = 'zh-CN') and (A3.[ID] = A4.[ID])
|
|
left join {1}.dbo.[Base_User] as A6 With(NoLock) on (A.ModifiedBy = A6.Code)
|
|
left join {1}.dbo.[CBO_ItemMaster] as A7 With(NoLock) on (A.[ItemMaster] = A7.[ID])
|
|
left join {1}.dbo.[CBO_Project] as A11 With(NoLock) on (A.[Project] = A11.[ID])
|
|
left join {1}.dbo.[Base_Organization] as A12 With(NoLock) on (A.[Org] = A12.[ID])
|
|
left join {1}.dbo.[CBO_Department] as A13 With(NoLock) on (A.[Department] = A13.[ID])
|
|
left join {1}.dbo.[CBO_Department_Trl] as A14 With(NoLock) on (A14.SysMlFlag = 'zh-CN') and (A13.[ID] = A14.[ID])
|
|
LEFT JOIN {1}.dbo.[CBO_Wh] AS A22 With(NoLock) ON A22.ID=A.CompleteWh
|
|
where (A.DocState=2 OR A.DocState=3) and A.[BusinessType] != 50 and (A.[BusinessType] != 52)
|
|
and (A.[BusinessType] != 2417) and (A.[IsMultiRouting] != 1) and A.[ItemMaster] is not null --and (A.[IsStartMO] != 1)
|
|
and ISNULL(A.ModifiedOn,A.BusinessCreatedOn)>=@LastTime AND A12.id='{0}'
|
|
|
|
--update #TempMO set Colspan=isNULL(ProjectCode,'')+'~'+isNULL(cBatch,'')+'~'+isNULL(Version,'')+'~'+isNULL(Brand,'')+'~'+isNULL(cFree1,'')+'~'+isnull(cFree2,'')+'~'+isnull(cFree3,'')+'~'+isnull(cFree4,'')+'~'+isnull(cFree5,'')+'~'+isnull(cFree6,'')+'~'+isnull(cFree7,'')+'~'+isnull(cFree8,'')+'~'+isnull(cFree9,'')+'~'+isnull(cFree10,'')
|
|
-- select distinct
|
|
-- Colspan,ProjectCode,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,TenantId,cBatch,version ,brand
|
|
-- INTO #TempExtensionMO
|
|
-- from #TempMO
|
|
|
|
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 += @"--删除数据
|
|
-- DELETE ICSMO WHERE MODetailID NOT IN (SELECT CAST(MoDId AS VARCHAR) FROM {1}.dbo.[mom_orderdetail])
|
|
SELECT a.MoCode INTO #tableICSMO
|
|
FROM ICSMO a With(NoLock)
|
|
LEFT JOIN {1}.dbo.[MO_MO] b With(NoLock) ON a.Mocode=b.DocNO
|
|
WHERE a.TenantId='{0}' and b.DocNO IS NULL AND b.Org={2}
|
|
|
|
DELETE ICSMO
|
|
WHERE TenantId='{0}' and mocode IN ( SELECT MoCode 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.EATTRIBUTE1");
|
|
values.Add("CusItemCode", "a.EATTRIBUTE2");
|
|
values.Add("CusName", "a.EATTRIBUTE3");
|
|
values.Add("DocType", "a.MoDocType");
|
|
values.Add("Default3", "a.ActualCompleteDate");
|
|
values.Add("Default5", "a.DocState");
|
|
values.Add("Default6", "a.IsFIClose");
|
|
|
|
//更新存在数据
|
|
sql += ICSHelper.UpdateSQL("b", values)
|
|
+ @" #TempMO a
|
|
INNER JOIN ICSMO b ON a.Mocode=b.Mocode
|
|
WHERE b.TenantId='{0}' and a.Org={2} ";
|
|
|
|
// 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 b.TenantId='{0}'
|
|
WHERE 1=1 and b.MoCode is null and a.Org={2} ";
|
|
sql += "DROP TABLE #TempMO";
|
|
sql += " DROP TABLE #tableICSMO ";
|
|
sql = string.Format(sql, TenantId, erpName, ErpId);
|
|
//return;
|
|
//log.Info(sql);
|
|
ICSHelper.ExecuteDate(conStr, sql);
|
|
#endregion
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|