using System; using System.Collections.Generic; using System.Linq; using System.Text; using Quartz; namespace ICSSoft.FromERP { /// /// 备料表(工单BOM) /// public class ICSMOBOM : 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; #region SQL string sql = @"SELECT a.MoCode AS MOCODE , b.InvCode AS ITEMCODE, b.SortSeq AS SEQ, c.InvCode AS MOBITEMCODE, CAST(c.AllocateId AS NVARCHAR(50)) AS MOBITEMECN, d.cInvName AS MOBITEMNAME, d.cInvStd AS MOBITEMDESC, '1' AS MOBITEMSTATUS, GETDATE() AS MOBITEMEFFTIME, GETDATE() AS MOBITEMINVTIME, CASE WHEN d.bCutMantissa='1' AND d.bKCCutMantissa='1' THEN CEILING(c.Qty) ELSE c.Qty END AS MOBITEMQTY, c.WhCode AS MOBITEMLOCATION, CASE WHEN c.WIPType='1' THEN '1' ELSE '0' END AS MOBOMITEMUOM, '' AS MOFAC, c.SortSeq AS MOBOMLINE, 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 into #TempBOM FROM {0}.dbo.mom_order a INNER JOIN {0}.dbo.mom_orderdetail b ON a.MoId = b.MoId INNER JOIN {0}.dbo.mom_moallocate c ON b.MoDId = c.MoDId INNER JOIN {0}.dbo.Inventory d ON c.InvCode = d.cInvCode LEFT JOIN {0}.dbo.bom_parent e ON b.BomId = e.BomId LEFT JOIN {0}.dbo.bom_bom f ON e.BomId = f.BomId LEFT JOIN {0}.dbo.ComputationUnit unit ON d.cComUnitCode = unit.cComunitCode 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 #TempBOM) RETURN"; sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempBOM"); sql += "\r\n"; sql += @"--删除数据 DELETE ICSMOBOM WHERE MOBITEMECN NOT IN (SELECT AllocateId FROM {0}.dbo.mom_moallocate) "; Dictionary values = new Dictionary(); values.Add("MOCODE", "a.MOCODE"); values.Add("ITEMCODE", "a.ITEMCODE"); values.Add("SEQ", "a.SEQ"); values.Add("MOBITEMCODE", "a.MOBITEMCODE"); values.Add("MOBITEMNAME", "a.MOBITEMNAME"); values.Add("MOBITEMDESC", "a.MOBITEMDESC"); values.Add("MOBITEMSTATUS", "a.MOBITEMSTATUS"); values.Add("MOBITEMEFFTIME", "a.MOBITEMEFFTIME"); values.Add("MOBITEMINVTIME", "a.MOBITEMEFFTIME"); values.Add("MOBITEMQTY", "a.MOBITEMQTY"); values.Add("MOBOMITEMUOM", "a.MOBOMITEMUOM");//供应类型:1:入库到冲 values.Add("MOBOMLINE", "a.MOBOMLINE"); values.Add("MOBITEMLOCATION", "a.MOBITEMLOCATION"); values.Add("MTIME", "a.MTIME"); values.Add("MOFAC", "a.MOFAC"); //values.Add("WorkPoint", "a.WorkPoint"); //更新存在数据 sql += ICSHelper.UpdateSQL("b", values) + @" #TempBOM a INNER JOIN ICSMOBOM b ON a.MOBITEMECN=b.MOBITEMECN "; values.Add("MOBITEMECN", "a.MOBITEMECN"); values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'"); values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'"); values.Add("WorkPoint", "'" + WorkPoint + "'"); sql += "\r\n"; //插入新增数据 sql += ICSHelper.InsertSQL("ICSMOBOM", values) + @" #TempBOM a LEFT JOIN ICSMOBOM b ON a.MOBITEMECN=b.MOBITEMECN WHERE b.MOBITEMECN IS NULL "; sql += "DROP TABLE #TempBOM"; sql = string.Format(sql, WorkPoint); ICSHelper.ExecuteDate(conStr, sql); #endregion } catch (Exception ex) { log.Error(ex.ToString()); } } } }