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.
104 lines
4.3 KiB
104 lines
4.3 KiB
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());
|
|
}
|
|
}
|
|
}
|
|
}
|