107 lines
4.3 KiB
C#
107 lines
4.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using HHWMS.Web.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Newtonsoft.Json;
|
|
using Quartz;
|
|
using WalkingTec.Mvvm.Core;
|
|
using WalkingTec.Mvvm.Core.Support.Quartz;
|
|
|
|
namespace HHWMS.Web
|
|
{
|
|
//[QuartzRepeat(10,10, true, 30)]
|
|
//定时回传入库完成物料信息
|
|
[PersistJobDataAfterExecution]
|
|
[DisallowConcurrentExecution]
|
|
public class InvBackJob : WtmJob
|
|
{
|
|
public override Task Execute(IJobExecutionContext context)
|
|
{
|
|
try
|
|
{
|
|
var _unitwork = new UnitWork(Wtm);
|
|
List<Inventory> inventories = _unitwork.Find<Inventory>(x => x.Status == "0").ToList();
|
|
var Invs = inventories.Take(5).ToList();
|
|
|
|
var bizData = new InStore
|
|
{
|
|
INWMS = new INWMS
|
|
{
|
|
INITEMS = new INITEMS
|
|
{
|
|
INITEM = new List<INITEMItem>()
|
|
{
|
|
}
|
|
}
|
|
}
|
|
};
|
|
if (Invs.Count > 0)
|
|
{
|
|
foreach (var inv in Invs)
|
|
{
|
|
//var inv = _unitwork.FindById<Inventory>(int.Parse(id));
|
|
var qr = _unitwork.FindSingle<MaterialQr>(x => x.UniqueCode.Equals(inv.UniqueCode))?.QRCode;
|
|
bizData.INWMS.INITEMS.INITEM.Add(
|
|
new INITEMItem()
|
|
{
|
|
ERPSN = qr,
|
|
WMSSN = inv?.UniqueCode,
|
|
QTY = ((int?)inv?.Qty).ToString(),
|
|
TYPE = "2"
|
|
});
|
|
}
|
|
var str = JsonConvert.SerializeObject(bizData);
|
|
var request = new ServiceReference1.bizOperationV1Request
|
|
{
|
|
fromUnit = "8357S",
|
|
toUnit = "8357S",
|
|
fromSys = "WMSTEST",
|
|
toSys = "MES",
|
|
bizOperation = "InStore",
|
|
bizData = str
|
|
};
|
|
var client = new ServiceReference1.portTypeClient();
|
|
var result = client.bizOperationV1Async(request).Result;
|
|
if (result.Status == "Y")
|
|
{
|
|
_unitwork.BatchUpdate<Inventory>(x => Invs.Select(y => y.ID).Contains(x.ID), x => new Inventory
|
|
{
|
|
Status = "1",
|
|
UpdateBy = "invjob",
|
|
UpdateTime = DateTime.Now
|
|
});
|
|
Wtm.DoLog("", ActionLogTypesEnum.Normal, "mes", request: JsonConvert.SerializeObject(request), result: "success");
|
|
//return FFResult().Message("库存回传成功").RefreshGrid();
|
|
}
|
|
else
|
|
{
|
|
Wtm.DoLog("", ActionLogTypesEnum.Normal, "mes", request: JsonConvert.SerializeObject(request), result: "error");
|
|
//return FFResult().Message($"{result.Message}").RefreshGrid();
|
|
}
|
|
}
|
|
#region 更新时间
|
|
|
|
var job = _unitwork.FindSingle<SysJob>(x => x.JobName == context.JobDetail.Key.Name);
|
|
if (job != null)
|
|
{
|
|
job.LastFireTime = TimeZoneInfo.ConvertTimeFromUtc(context.FireTimeUtc.DateTime, TimeZoneInfo.Local);
|
|
// 只执行一次 没有下次执行时间
|
|
if (context.NextFireTimeUtc != null)
|
|
{
|
|
job.NextFireTime = TimeZoneInfo.ConvertTimeFromUtc(context.NextFireTimeUtc.Value.DateTime, TimeZoneInfo.Local);
|
|
}
|
|
_unitwork.Update<SysJob>(job);
|
|
}
|
|
Wtm.DoLog("任务下发", ActionLogTypesEnum.Job, "SendWcsJob");
|
|
#endregion 更新时间
|
|
}
|
|
catch { }
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|