|
|
|
|
|
using Khd.Core.Domain.Models;
|
|
|
|
|
|
using Khd.Core.EntityFramework;
|
|
|
|
|
|
using Khd.Core.Library.Mapper;
|
|
|
|
|
|
using Khd.Core.Wcs.Global;
|
|
|
|
|
|
using Masuit.Tools;
|
|
|
|
|
|
using Masuit.Tools.Logging;
|
|
|
|
|
|
using Microsoft.CodeAnalysis;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
using SixLabors.ImageSharp;
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
using Z.EntityFramework.Plus;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Khd.Core.Wcs.Wcs
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据出入库记录创建出入库任务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class CreateTaskByRecord
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IHost _host;
|
|
|
|
|
|
public CreateTaskByRecord(IHost host)
|
|
|
|
|
|
{
|
|
|
|
|
|
this._host = host;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 启动上件扫描监听
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void StartPoint()
|
|
|
|
|
|
{
|
|
|
|
|
|
var createBearAgvReturnThread = new Thread(CreateBearAgvReturnLogic);
|
|
|
|
|
|
createBearAgvReturnThread.Start();
|
|
|
|
|
|
|
|
|
|
|
|
var createFiveProductInTaskThread = new Thread(CreateFiveProductInTaskLogic);
|
|
|
|
|
|
createFiveProductInTaskThread.Start();
|
|
|
|
|
|
|
|
|
|
|
|
var createFiveProductTaskThread = new Thread(CreateFiveProductTaskLogic);
|
|
|
|
|
|
createFiveProductTaskThread.Start();
|
|
|
|
|
|
|
|
|
|
|
|
var createRawTaskThread = new Thread(CreateRawTaskLogic);
|
|
|
|
|
|
createRawTaskThread.Start();
|
|
|
|
|
|
|
|
|
|
|
|
var createThirdOutTaskThread = new Thread(CreateThirdOutTaskLogic);
|
|
|
|
|
|
createThirdOutTaskThread.Start();
|
|
|
|
|
|
|
|
|
|
|
|
var CreateSecondProductTaskThread = new Thread(CreateSecondProductTaskLogic);
|
|
|
|
|
|
CreateSecondProductTaskThread.Start();
|
|
|
|
|
|
|
|
|
|
|
|
var createEmptyTrayThread = new Thread(CreateEmptyTrayLogic);
|
|
|
|
|
|
createEmptyTrayThread.Start();
|
|
|
|
|
|
|
|
|
|
|
|
var createThirdWasterTaskThread = new Thread(CreateThirdWasterTaskLogic);
|
|
|
|
|
|
createThirdWasterTaskThread.Start();
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":出库任务监听启动成功");
|
|
|
|
|
|
LogManager.Info("出库任务监听启动成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据人工任务生成可执行任务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
|
|
private void CreateThirdWasterTaskLogic()
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
|
|
|
|
|
|
bool hasTask = dbContext.WcsTask.Where(t => t.nextPointId == 9).Any();
|
|
|
|
|
|
if (!hasTask)
|
|
|
|
|
|
{
|
|
|
|
|
|
WcsTaskManual? wcsTaskManual = dbContext.WcsTaskManual.Where(t => t.nextPointId == 9).OrderBy(t => t.createBy).FirstOrDefault();
|
|
|
|
|
|
if (wcsTaskManual != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
WcsTask wcsTask = CoreMapper.Map<WcsTask>(wcsTaskManual);
|
|
|
|
|
|
wcsTask.createTime = DateTime.Now;
|
|
|
|
|
|
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(wcsTask);
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
dbContext.Add(wcsTaskLog);
|
|
|
|
|
|
dbContext.Remove(wcsTaskManual);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 3楼托盘库
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
|
|
private void CreateEmptyTrayLogic()
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
BaseEquip agvEquip = StaticData.BaseEquip.First(t => t.objid == 9);
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
|
|
|
|
|
|
bool canCreate = dbContext.WcsTask.Where(t => t.nextPointId == 9).Any();
|
|
|
|
|
|
if (!canCreate)
|
|
|
|
|
|
{
|
|
|
|
|
|
BaseEquip baseEquip = dbContext.BaseEquip.First(t => t.objid == 35);
|
|
|
|
|
|
if (baseEquip.emptyCount == (SystemData.maxTray / 2))
|
|
|
|
|
|
{
|
|
|
|
|
|
var endEquip = dbContext.BaseEquip.FirstOrDefault(t => t.equipType == 15 && t.equipStatus == 1 && t.emptyCount == 5);
|
|
|
|
|
|
if (endEquip != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var wcsTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
serialNo = SystemData.GetSerialNo(dbContext),
|
|
|
|
|
|
taskType = 40,
|
|
|
|
|
|
nextPointId = agvEquip.objid,
|
|
|
|
|
|
nextPointNo = agvEquip.equipNo,
|
|
|
|
|
|
endPointId = baseEquip.objid,
|
|
|
|
|
|
endPointNo = baseEquip.equipNo,
|
|
|
|
|
|
currPointId = endEquip.objid,
|
|
|
|
|
|
currPointNo = endEquip.equipNo,
|
|
|
|
|
|
equipmentNo = agvEquip.equipNo,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
qty = 5,
|
|
|
|
|
|
isEmpty = "1",
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
floorNo = 3,
|
|
|
|
|
|
fromFloorNo = 3,
|
|
|
|
|
|
masterId = 0,
|
|
|
|
|
|
orderId = 0,
|
|
|
|
|
|
materialId = 0,
|
|
|
|
|
|
};
|
|
|
|
|
|
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(wcsTask);
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
dbContext.Add(wcsTaskLog);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
endEquip = dbContext.BaseEquip.FirstOrDefault(t => t.equipType == 15 && t.equipStatus == 0 && t.emptyCount == 0);
|
|
|
|
|
|
if (endEquip != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var wcsTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
serialNo = SystemData.GetSerialNo(dbContext),
|
|
|
|
|
|
taskType = 43,
|
|
|
|
|
|
nextPointId = agvEquip.objid,
|
|
|
|
|
|
nextPointNo = agvEquip.equipNo,
|
|
|
|
|
|
endPointId = endEquip.objid,
|
|
|
|
|
|
endPointNo = endEquip.equipNo,
|
|
|
|
|
|
currPointId = baseEquip.objid,
|
|
|
|
|
|
currPointNo = baseEquip.equipNo,
|
|
|
|
|
|
equipmentNo = agvEquip.equipNo,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
qty = 5,
|
|
|
|
|
|
isEmpty = "1",
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
floorNo = 3,
|
|
|
|
|
|
fromFloorNo = 3,
|
|
|
|
|
|
masterId = 0,
|
|
|
|
|
|
orderId = 0,
|
|
|
|
|
|
materialId = 0,
|
|
|
|
|
|
};
|
|
|
|
|
|
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(wcsTask);
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
dbContext.Add(wcsTaskLog);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (baseEquip.emptyCount == SystemData.maxTray)
|
|
|
|
|
|
{
|
|
|
|
|
|
var endEquip = dbContext.BaseEquip.FirstOrDefault(t => t.equipType == 15 && t.equipStatus == 0 && t.emptyCount == 0);
|
|
|
|
|
|
if (endEquip != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var wcsTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
serialNo = SystemData.GetSerialNo(dbContext),
|
|
|
|
|
|
taskType = 43,
|
|
|
|
|
|
nextPointId = agvEquip.objid,
|
|
|
|
|
|
nextPointNo = agvEquip.equipNo,
|
|
|
|
|
|
endPointId = endEquip.objid,
|
|
|
|
|
|
endPointNo = endEquip.equipNo,
|
|
|
|
|
|
currPointId = baseEquip.objid,
|
|
|
|
|
|
currPointNo = baseEquip.equipNo,
|
|
|
|
|
|
equipmentNo = agvEquip.equipNo,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
qty = 10,
|
|
|
|
|
|
isEmpty = "1",
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
floorNo = 3,
|
|
|
|
|
|
fromFloorNo = 3,
|
|
|
|
|
|
masterId = 0,
|
|
|
|
|
|
orderId = 0,
|
|
|
|
|
|
materialId = 0,
|
|
|
|
|
|
};
|
|
|
|
|
|
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(wcsTask);
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
dbContext.Add(wcsTaskLog);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 半成品入库
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
|
|
private void CreateFiveProductInTaskLogic()
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
BaseEquip agvEquip = StaticData.BaseEquip.First(t => t.objid == 28);
|
|
|
|
|
|
BaseEquip endEquip = StaticData.BaseEquip.First(t => t.objid == 30);
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
|
|
|
|
|
|
bool task = dbContext.WcsTask.Where(t => t.nextPointId == 28 && t.taskStatus <= 5).Any();
|
|
|
|
|
|
if (!task)
|
|
|
|
|
|
{
|
|
|
|
|
|
var wmsProductInstock = dbContext.WmsProductInstock
|
|
|
|
|
|
.Where(t => t.productType == "2")
|
|
|
|
|
|
.Where(t => t.auditStatus == "1")
|
|
|
|
|
|
.Where(t => t.warehouseId == 521)
|
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
if (wmsProductInstock != null && wmsProductInstock.executeStatus == "0")
|
|
|
|
|
|
{
|
|
|
|
|
|
var wmsBaseLocation = dbContext.WmsBaseLocation
|
|
|
|
|
|
.Where(t => t.warehouseId == 521)
|
|
|
|
|
|
.Where(t => t.activeFlag == "1")
|
|
|
|
|
|
.Where(t => t.instockFlag == "0")
|
|
|
|
|
|
.Where(t => t.outstockFlag == "0")
|
|
|
|
|
|
.Where(t => t.locationStatus == "1")
|
|
|
|
|
|
.Where(t => t.containerCode == null || t.containerCode == "").FirstOrDefault();
|
|
|
|
|
|
if (wmsBaseLocation != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var wcsTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
serialNo = SystemData.GetSerialNo(dbContext),
|
|
|
|
|
|
taskType = 34,
|
|
|
|
|
|
endPointId = endEquip.objid,
|
|
|
|
|
|
endPointNo = endEquip.equipNo,
|
|
|
|
|
|
currPointId = wmsBaseLocation.locationId,
|
|
|
|
|
|
currPointNo = wmsBaseLocation.locationCode,
|
|
|
|
|
|
equipmentNo = agvEquip.equipNo,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
qty = 1,
|
|
|
|
|
|
containerNo = wmsProductInstock.palletInfoCode,
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
floorNo = 5,
|
|
|
|
|
|
fromFloorNo = 5,
|
|
|
|
|
|
isEmpty = "0",
|
|
|
|
|
|
masterId = wmsProductInstock.productId,
|
|
|
|
|
|
orderId = wmsProductInstock.productInstockId,
|
|
|
|
|
|
materialId = wmsProductInstock.productId,
|
|
|
|
|
|
nextPointId = agvEquip.objid,
|
|
|
|
|
|
nextPointNo = agvEquip.equipNo,
|
|
|
|
|
|
materialBarcode = wmsProductInstock.productBatch,
|
|
|
|
|
|
};
|
|
|
|
|
|
WmsProductInstockDetail wmsProductInstockDetail = new WmsProductInstockDetail()
|
|
|
|
|
|
{
|
|
|
|
|
|
erpAmount = 0,
|
|
|
|
|
|
productId = wmsProductInstock.productId,
|
|
|
|
|
|
executeStatus = "1",
|
|
|
|
|
|
productInstockDetailId = StaticData.SnowId.NextId(),
|
|
|
|
|
|
instockAmount = 1,
|
|
|
|
|
|
instockBy = "WCS",
|
|
|
|
|
|
instockDate = DateTime.Now,
|
|
|
|
|
|
instockWay = "2",
|
|
|
|
|
|
locationCode = wmsBaseLocation.locationCode,
|
|
|
|
|
|
planAmount = 1,
|
|
|
|
|
|
productBarcode = wmsProductInstock.productBatch,
|
|
|
|
|
|
productBatch = wmsProductInstock.productBatch,
|
|
|
|
|
|
productInstockId = wmsProductInstock.productInstockId,
|
|
|
|
|
|
};
|
|
|
|
|
|
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(wcsTask);
|
|
|
|
|
|
wmsProductInstock.executeStatus = "1";
|
|
|
|
|
|
wmsBaseLocation.instockFlag = "1";
|
|
|
|
|
|
wmsBaseLocation.locationStatus = "4";
|
|
|
|
|
|
dbContext.Add(wmsProductInstock);
|
|
|
|
|
|
dbContext.Update(wmsProductInstock);
|
|
|
|
|
|
dbContext.Update(wmsBaseLocation);
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
dbContext.Add(wcsTaskLog);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建去翻转机的任务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
|
private void CreateThirdOutTaskLogic()
|
|
|
|
|
|
{
|
|
|
|
|
|
BaseEquip endEquip = StaticData.BaseEquip.First(t => t.objid == 31);
|
|
|
|
|
|
BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.objid == 9);
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
|
|
|
|
|
|
bool task = dbContext.WcsTask.Where(t => t.nextPointId == 9 && t.taskStatus <= 5).Any();
|
|
|
|
|
|
if (!task)
|
|
|
|
|
|
{
|
|
|
|
|
|
WcsTask? wcsTask = dbContext.WcsTask.FirstOrDefault(t => t.endPointId == endEquip.objid);
|
|
|
|
|
|
if (wcsTask == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
WcsTaskManual? wcsTaskManual = dbContext.WcsTaskManual.Where(t => t.taskType == 999).FirstOrDefault();
|
|
|
|
|
|
if (wcsTaskManual != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var wmsRawOutstock = dbContext.WmsRawOutstock.FirstOrDefault(t => t.rawOutstockId == wcsTaskManual.orderId);
|
|
|
|
|
|
if (wmsRawOutstock != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var wmsRawStocks = dbContext.WmsRawStock
|
|
|
|
|
|
.Where(t => t.materialId == wmsRawOutstock.materialId)
|
|
|
|
|
|
.Where(t => t.warehouseId == 311)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
var wmsBaseLocations = dbContext.WmsBaseLocation
|
|
|
|
|
|
.Where(t => t.activeFlag == "1")
|
|
|
|
|
|
.Where(t => t.delFlag == "0")
|
|
|
|
|
|
.Where(t => t.locationScrapType == "1")
|
|
|
|
|
|
.Where(t => t.instockFlag == "0")
|
|
|
|
|
|
.Where(t => t.outstockFlag == "0")
|
|
|
|
|
|
.Where(t => t.ContainerStatus == "1")
|
|
|
|
|
|
.Where(t => t.warehouseId == 311).ToList();
|
|
|
|
|
|
var bill = from a in wmsBaseLocations
|
|
|
|
|
|
from b in wmsRawStocks
|
|
|
|
|
|
where a.locationCode == b.locationCode
|
|
|
|
|
|
select new { a, b };
|
|
|
|
|
|
WmsBaseLocation? wmsBaseLocation = null;
|
|
|
|
|
|
bill = bill.OrderBy(t => t.b.instockDate);
|
|
|
|
|
|
var fistbill = bill.FirstOrDefault();
|
|
|
|
|
|
if (fistbill != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
int? locRow = 0;
|
|
|
|
|
|
if (fistbill.a.locRow % 2 == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
locRow = fistbill.a.locRow + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
locRow = fistbill.a.locRow - 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
var lastbill = bill.Where(t => t.a.locRow == locRow)
|
|
|
|
|
|
.Where(t => t.a.locColumn == fistbill.a.locColumn)
|
|
|
|
|
|
.Where(t => t.a.locDeep == 2)
|
|
|
|
|
|
.Where(t => t.b.materialId == wmsRawOutstock.materialId)
|
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
if (lastbill != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (lastbill.b.instockDate != null && fistbill.b.instockDate != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
wmsBaseLocation = fistbill.a;
|
|
|
|
|
|
if (lastbill.b.instockDate.Value.Date == fistbill.b.instockDate.Value.Date)
|
|
|
|
|
|
{
|
|
|
|
|
|
wmsBaseLocation = lastbill.a;
|
|
|
|
|
|
}
|
|
|
|
|
|
else//移库
|
|
|
|
|
|
{
|
|
|
|
|
|
var formWmsBaseLocation = lastbill.a;
|
|
|
|
|
|
//先找深库位
|
|
|
|
|
|
List<string> list = wmsRawStocks.Select(t => t.locationCode).ToList();
|
|
|
|
|
|
var deepLocation = wmsBaseLocations
|
|
|
|
|
|
.Where(t => t.locDeep == 1)
|
|
|
|
|
|
.Where(t => !list.Contains(t.locationCode))
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
if (deepLocation.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var toWmsBaseLocation = deepLocation.First();
|
|
|
|
|
|
var EKWcsTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
orderId = wmsRawOutstock.rawOutstockId,
|
|
|
|
|
|
taskType = 49,
|
|
|
|
|
|
containerNo = wmsBaseLocation.containerCode,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now.AddSeconds(-10),
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
materialId = wmsRawOutstock.materialId,
|
|
|
|
|
|
currPointId = formWmsBaseLocation.locationId,
|
|
|
|
|
|
currPointNo = formWmsBaseLocation.locationCode,
|
|
|
|
|
|
nextPointId = baseEquip.objid,
|
|
|
|
|
|
nextPointNo = baseEquip.equipNo,
|
|
|
|
|
|
endPointId = toWmsBaseLocation.locationId,
|
|
|
|
|
|
endPointNo = toWmsBaseLocation.locationCode,
|
|
|
|
|
|
equipmentNo = baseEquip.equipNo,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
qty = 1
|
|
|
|
|
|
};
|
|
|
|
|
|
formWmsBaseLocation.outstockFlag = "1";
|
|
|
|
|
|
formWmsBaseLocation.locationStatus = "4";
|
|
|
|
|
|
toWmsBaseLocation.instockFlag = "1";
|
|
|
|
|
|
toWmsBaseLocation.locationStatus = "4";
|
|
|
|
|
|
dbContext.Add(EKWcsTask);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (wmsBaseLocation != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
MesBasePalletInfo? mesBasePalletInfo = dbContext.MesBasePalletInfo.FirstOrDefault(t => t.palletInfoCode == wmsBaseLocation.containerCode);
|
|
|
|
|
|
if (mesBasePalletInfo != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
MesBaseBarcodeInfo? mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == mesBasePalletInfo.materialBarcode);
|
|
|
|
|
|
if (mesBaseBarcodeInfo != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
WmsRawOutstockDetail wmsRawOutstockDetail = new WmsRawOutstockDetail()
|
|
|
|
|
|
{
|
|
|
|
|
|
rawOutstockDetailId = StaticData.SnowId.NextId(),
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createDate = DateTime.Now,
|
|
|
|
|
|
executeStatus = "0",
|
|
|
|
|
|
erpAmount = 0,
|
|
|
|
|
|
erpStatus = "0",
|
|
|
|
|
|
instockBatch = mesBaseBarcodeInfo.batchCode,
|
|
|
|
|
|
stackAmount = 1,
|
|
|
|
|
|
locationCode = wmsBaseLocation.locationCode,
|
|
|
|
|
|
rawOutstockId = wmsRawOutstock.rawOutstockId,
|
|
|
|
|
|
planAmount = 1,
|
|
|
|
|
|
outstockWay = "2",
|
|
|
|
|
|
outstockPerson = "WCS",
|
|
|
|
|
|
outstockTime = DateTime.Now,
|
|
|
|
|
|
materialProductionDate = mesBaseBarcodeInfo.productionDate,
|
|
|
|
|
|
materialBarcode = mesBasePalletInfo.materialBarcode,
|
|
|
|
|
|
materialId = wmsRawOutstock.materialId,
|
|
|
|
|
|
machineName = mesBaseBarcodeInfo.machineName,
|
|
|
|
|
|
outstockAmount = 1,
|
|
|
|
|
|
taskCode = wmsRawOutstock.taskCode
|
|
|
|
|
|
};
|
|
|
|
|
|
wcsTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
orderId = wmsRawOutstock.rawOutstockId,
|
|
|
|
|
|
taskType = 41,
|
|
|
|
|
|
containerNo = wmsBaseLocation.containerCode,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
materialId = wmsRawOutstock.materialId,
|
|
|
|
|
|
currPointId = wmsBaseLocation.locationId,
|
|
|
|
|
|
currPointNo = wmsBaseLocation.locationCode,
|
|
|
|
|
|
nextPointId = baseEquip.objid,
|
|
|
|
|
|
nextPointNo = baseEquip.equipNo,
|
|
|
|
|
|
endPointId = endEquip.objid,
|
|
|
|
|
|
endPointNo = endEquip.equipNo,
|
|
|
|
|
|
equipmentNo = endEquip.equipNo,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
qty = 1
|
|
|
|
|
|
};
|
|
|
|
|
|
dbContext.Add(wmsRawOutstockDetail);
|
|
|
|
|
|
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(wcsTask);
|
|
|
|
|
|
dbContext.Remove(wcsTaskManual);
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
dbContext.Add(wcsTaskLog);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建返库任务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
|
|
private void CreateBearAgvReturnLogic()
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
BaseEquip endEquip = StaticData.BaseEquip.First(t => t.objid == 21);
|
|
|
|
|
|
BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.objid == 10);
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
|
|
|
|
|
|
var wmsRawReturn = dbContext.WmsRawReturn
|
|
|
|
|
|
.Where(t => t.auditStatus == "1")
|
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
if (wmsRawReturn != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (wmsRawReturn.executeStatus == "0")
|
|
|
|
|
|
{
|
|
|
|
|
|
//任务未开始Status=0
|
|
|
|
|
|
BaseEquip startEquip = StaticData.BaseEquip.First(t => t.equipNo == wmsRawReturn.endStationCode);
|
|
|
|
|
|
WcsTask wcsTask = new()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
orderId = wmsRawReturn.rawReturnId,
|
|
|
|
|
|
taskType = 48,
|
|
|
|
|
|
containerNo = "",
|
|
|
|
|
|
currPointId = startEquip.objid,
|
|
|
|
|
|
currPointNo = startEquip.equipNo,
|
|
|
|
|
|
nextPointId = baseEquip.objid,
|
|
|
|
|
|
nextPointNo = baseEquip.equipNo,
|
|
|
|
|
|
endPointId = endEquip.objid,
|
|
|
|
|
|
endPointNo = endEquip.equipNo,
|
|
|
|
|
|
serialNo = SystemData.GetSerialNo(dbContext),
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
materialId = wmsRawReturn.materialId,
|
|
|
|
|
|
qty = 1,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
equipmentNo = startEquip.equipNo,
|
|
|
|
|
|
remark = "装配区返库",
|
|
|
|
|
|
floorNo = 5,
|
|
|
|
|
|
masterId = wmsRawReturn.materialId,
|
|
|
|
|
|
fromFloorNo = 5,
|
|
|
|
|
|
//materialNo = wmsRawReturn.materialBatch,
|
|
|
|
|
|
};
|
|
|
|
|
|
wmsRawReturn.executeStatus = "1";
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(wcsTask);
|
|
|
|
|
|
dbContext.Add(wcsTaskLog);
|
|
|
|
|
|
dbContext.Update(wmsRawReturn);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 成品出库
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void CreateFiveProductTaskLogic()
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
|
|
|
|
|
|
bool task = dbContext.WcsTask.Where(t => t.nextPointId == 28 && t.taskStatus <= 5).Any();
|
|
|
|
|
|
if (!task)
|
|
|
|
|
|
{
|
|
|
|
|
|
var proStock = dbContext.WmsProductStock
|
|
|
|
|
|
.Where(t => t.warehouseId == 531)
|
|
|
|
|
|
.Where(t => t.activeFlag == "0").ToList();
|
|
|
|
|
|
var proOutStock = dbContext.WmsProductOutstock
|
|
|
|
|
|
.Where(t => t.outstockQty < t.applyQty)
|
|
|
|
|
|
.Where(t => t.auditStatus == "1")
|
|
|
|
|
|
.Where(t => t.warehouseId == 531)
|
|
|
|
|
|
.Where(t => t.productType == "3")
|
|
|
|
|
|
.Where(t => t.executeStatus == "0" || t.executeStatus == "1").ToList();
|
|
|
|
|
|
//获取最早入库时间
|
|
|
|
|
|
foreach (var item in proOutStock)
|
|
|
|
|
|
{
|
|
|
|
|
|
task = dbContext.WcsTask.Where(t => t.nextPointId == 28 && t.taskStatus <= 5).Any();
|
|
|
|
|
|
if (!task)
|
|
|
|
|
|
{
|
|
|
|
|
|
BaseEquip endEquip = dbContext.BaseEquip.First(t => t.floorNo == 5 && t.equipType == 1);
|
|
|
|
|
|
|
|
|
|
|
|
var wmsproStocks = proStock
|
|
|
|
|
|
.Where(t => t.productId == item.productId && t.warehouseId == item.warehouseId)
|
|
|
|
|
|
.Select(t => t.palletInfoCode)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var wmsBaseLocations = dbContext.WmsBaseLocation
|
|
|
|
|
|
.Where(t => t.activeFlag == "1")
|
|
|
|
|
|
.Where(t => t.delFlag == "0")
|
|
|
|
|
|
.Where(t => t.locationScrapType == "1")
|
|
|
|
|
|
.Where(t => t.instockFlag == "0")
|
|
|
|
|
|
.Where(t => t.outstockFlag == "0")
|
|
|
|
|
|
.Where(t => t.warehouseId == item.warehouseId)
|
|
|
|
|
|
.Where(t => wmsproStocks.Contains(t.containerCode))
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
decimal needNumber = Convert.ToDecimal(item.applyQty - item.outstockQty);
|
|
|
|
|
|
if (needNumber <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.executeStatus = "2";
|
|
|
|
|
|
dbContext.Update(item);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var bill = from a in wmsBaseLocations
|
|
|
|
|
|
from b in proStock
|
|
|
|
|
|
where a.containerCode == b.palletInfoCode
|
|
|
|
|
|
select new { a, b };
|
|
|
|
|
|
//如果第一列满足需求,则按第一列排序,否则按最后一列排序
|
|
|
|
|
|
if (bill.Where(t => t.a.locColumn == 1).Select(t => t.b.totalAmount - t.b.frozenAmount).Sum() > needNumber)
|
|
|
|
|
|
{
|
|
|
|
|
|
bill = bill.OrderBy(t => t.a.locColumn).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
bill = bill.OrderByDescending(t => t.a.locColumn).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
//做数量限制
|
|
|
|
|
|
|
|
|
|
|
|
BaseEquip agvEquip = StaticData.BaseEquip.First(t => t.objid == 28);
|
|
|
|
|
|
BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.objid == 5);
|
|
|
|
|
|
foreach (var b in bill)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.executeStatus = "1";
|
|
|
|
|
|
WmsBaseLocation location = b.a;
|
|
|
|
|
|
WmsProductStock stock = b.b;
|
|
|
|
|
|
WcsTask wcsTask;
|
|
|
|
|
|
int qty = 0;
|
|
|
|
|
|
if (stock.totalAmount - stock.frozenAmount <= needNumber)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.outstockQty += stock.totalAmount - stock.frozenAmount;
|
|
|
|
|
|
qty = Convert.ToInt32(stock.totalAmount - stock.frozenAmount);
|
|
|
|
|
|
stock.updateDate = DateTime.Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
item.outstockQty += needNumber;
|
|
|
|
|
|
qty = Convert.ToInt32(needNumber);
|
|
|
|
|
|
stock.updateDate = DateTime.Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
MesBasePalletInfo? mesBasePalletInfo = dbContext.MesBasePalletInfo.FirstOrDefault(t => t.palletInfoCode == location.containerCode);
|
|
|
|
|
|
if (mesBasePalletInfo != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
WmsProductOutstockDetail detail = new()
|
|
|
|
|
|
{
|
|
|
|
|
|
productId = item.productId,
|
|
|
|
|
|
productOutstockId = item.productOutstockId,
|
|
|
|
|
|
locationCode = location.locationCode,
|
|
|
|
|
|
executeStatus = "1",
|
|
|
|
|
|
beginTime = DateTime.Now,
|
|
|
|
|
|
warehouseId = item.warehouseId,
|
|
|
|
|
|
erpAmount = 0,
|
|
|
|
|
|
confirmAmount = 0,
|
|
|
|
|
|
outstockAmount = 1,
|
|
|
|
|
|
planAmount = 1,
|
|
|
|
|
|
productBatch = item.productBatch,
|
|
|
|
|
|
productOutstockDetailId = StaticData.SnowId.NextId(),
|
|
|
|
|
|
productBarcode = mesBasePalletInfo.materialBarcode
|
|
|
|
|
|
};
|
|
|
|
|
|
if (location.locDeep == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
int? column = 0;
|
|
|
|
|
|
if (location.locColumn % 2 == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
column = location.locColumn + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
column = location.locColumn - 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
WmsBaseLocation? wmsBaseLocation = dbContext.WmsBaseLocation.Where(t => t.locColumn == column)
|
|
|
|
|
|
.Where(t => t.locRow == location.locRow)
|
|
|
|
|
|
.Where(t => t.warehouseId == location.warehouseId).FirstOrDefault();
|
|
|
|
|
|
if (wmsBaseLocation != null && !string.IsNullOrEmpty(wmsBaseLocation.containerCode))
|
|
|
|
|
|
{
|
|
|
|
|
|
WmsBaseLocation? toLocation = dbContext.WmsBaseLocation.Where(t => t.warehouseId == location.warehouseId)
|
|
|
|
|
|
.Where(t => t.locDeep == 1)
|
|
|
|
|
|
.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault();
|
|
|
|
|
|
toLocation ??= dbContext.WmsBaseLocation.Where(t => t.warehouseId == location.warehouseId)
|
|
|
|
|
|
.Where(t => t.warehouseId != location.locationId)
|
|
|
|
|
|
.Where(t => string.IsNullOrEmpty(t.containerCode))
|
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
if (toLocation != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var RemoveTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
orderId = item.productOutstockId,
|
|
|
|
|
|
taskType = 38,
|
|
|
|
|
|
containerNo = wmsBaseLocation.containerCode,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now.AddSeconds(-10),
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
materialId = item.productId,
|
|
|
|
|
|
currPointId = wmsBaseLocation.locationId,
|
|
|
|
|
|
currPointNo = wmsBaseLocation.locationCode,
|
|
|
|
|
|
nextPointId = agvEquip.objid,
|
|
|
|
|
|
nextPointNo = agvEquip.equipNo,
|
|
|
|
|
|
endPointId = toLocation.locationId,
|
|
|
|
|
|
endPointNo = toLocation.locationCode,
|
|
|
|
|
|
equipmentNo = agvEquip.equipNo,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
qty = qty
|
|
|
|
|
|
};
|
|
|
|
|
|
toLocation.locationStatus = "4";
|
|
|
|
|
|
toLocation.instockFlag = "1";
|
|
|
|
|
|
toLocation.updateBy = "WCS";
|
|
|
|
|
|
toLocation.updateTime = DateTime.Now;
|
|
|
|
|
|
wmsBaseLocation.updateBy = "WCS";
|
|
|
|
|
|
wmsBaseLocation.updateTime = DateTime.Now;
|
|
|
|
|
|
wmsBaseLocation.outstockFlag = "1";
|
|
|
|
|
|
wmsBaseLocation.locationStatus = "4";
|
|
|
|
|
|
dbContext.Update(toLocation);
|
|
|
|
|
|
dbContext.Update(wmsBaseLocation);
|
|
|
|
|
|
dbContext.Add(RemoveTask);
|
|
|
|
|
|
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(RemoveTask);
|
|
|
|
|
|
dbContext.Add(wcsTaskLog);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
wcsTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
orderId = item.productOutstockId,
|
|
|
|
|
|
taskType = 38,
|
|
|
|
|
|
containerNo = location.containerCode,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
materialId = item.productId,
|
|
|
|
|
|
currPointId = location.locationId,
|
|
|
|
|
|
currPointNo = location.locationCode,
|
|
|
|
|
|
nextPointId = agvEquip.objid,
|
|
|
|
|
|
nextPointNo = agvEquip.equipNo,
|
|
|
|
|
|
endPointId = lineEquip.objid,
|
|
|
|
|
|
endPointNo = lineEquip.equipNo,
|
|
|
|
|
|
equipmentNo = agvEquip.equipNo,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
qty = qty
|
|
|
|
|
|
};
|
|
|
|
|
|
location.outstockFlag = "1";
|
|
|
|
|
|
location.locationStatus = "6";
|
|
|
|
|
|
location.updateBy = "WCS";
|
|
|
|
|
|
location.updateTime = DateTime.Now;
|
|
|
|
|
|
dbContext.Add(detail);
|
|
|
|
|
|
dbContext.Update(location);
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
dbContext.Update(stock);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
if (qty >= needNumber)
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (item.beginTime == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.beginTime = DateTime.Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
dbContext.Update(item);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(ex.Message + ex.StackTrace);
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 成品出库
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void CreateSecondProductTaskLogic()
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
|
|
|
|
|
|
bool task = dbContext.WcsTask.Where(t => t.nextPointId == 8 && t.taskStatus <= 7).Any();
|
|
|
|
|
|
if (!task)
|
|
|
|
|
|
{
|
|
|
|
|
|
var proStock = dbContext.WmsProductStock
|
|
|
|
|
|
.Where(t => t.warehouseId == 231)
|
|
|
|
|
|
.Where(t => t.activeFlag == "0").ToList();
|
|
|
|
|
|
var proOutStock = dbContext.WmsProductOutstock
|
|
|
|
|
|
.Where(t => t.outstockQty < t.applyQty)
|
|
|
|
|
|
.Where(t => t.auditStatus == "1")
|
|
|
|
|
|
.Where(t => t.warehouseId == 231)
|
|
|
|
|
|
.Where(t => t.productType == "3")
|
|
|
|
|
|
.Where(t => t.executeStatus == "0" || t.executeStatus == "1").ToList();
|
|
|
|
|
|
//获取最早入库时间
|
|
|
|
|
|
foreach (var item in proOutStock)
|
|
|
|
|
|
{
|
|
|
|
|
|
task = dbContext.WcsTask.Where(t => t.nextPointId == 8 && t.taskStatus <= 7).Any();
|
|
|
|
|
|
if (!task)
|
|
|
|
|
|
{
|
|
|
|
|
|
BaseEquip endEquip = dbContext.BaseEquip.First(t => t.floorNo == 2 && t.equipType == 1);
|
|
|
|
|
|
var wmsproStocks = proStock
|
|
|
|
|
|
.Where(t => t.productId == item.productId && t.warehouseId == item.warehouseId)
|
|
|
|
|
|
.Select(t => t.palletInfoCode)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var wmsBaseLocations = dbContext.WmsBaseLocation
|
|
|
|
|
|
.Where(t => t.activeFlag == "1")
|
|
|
|
|
|
.Where(t => t.delFlag == "0")
|
|
|
|
|
|
.Where(t => t.locationScrapType == "1")
|
|
|
|
|
|
.Where(t => t.instockFlag == "0")
|
|
|
|
|
|
.Where(t => t.outstockFlag == "0")
|
|
|
|
|
|
.Where(t => t.warehouseId == item.warehouseId)
|
|
|
|
|
|
.Where(t => wmsproStocks.Contains(t.containerCode))
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
decimal needNumber = Convert.ToDecimal(item.applyQty - item.outstockQty);
|
|
|
|
|
|
if (needNumber <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.executeStatus = "2";
|
|
|
|
|
|
dbContext.Update(item);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var bill = from a in wmsBaseLocations
|
|
|
|
|
|
from b in proStock
|
|
|
|
|
|
where a.containerCode == b.palletInfoCode
|
|
|
|
|
|
select new { a, b };
|
|
|
|
|
|
//如果第一列满足需求,则按第一列排序,否则按最后一列排序
|
|
|
|
|
|
if (bill.Where(t => t.a.locColumn == 1).Select(t => t.b.totalAmount - t.b.frozenAmount).Sum() > needNumber)
|
|
|
|
|
|
{
|
|
|
|
|
|
bill = bill.OrderBy(t => t.a.locColumn).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
bill = bill.OrderByDescending(t => t.a.locColumn).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
//做数量限制
|
|
|
|
|
|
|
|
|
|
|
|
BaseEquip agvEquip = StaticData.BaseEquip.First(t => t.objid == 8);
|
|
|
|
|
|
BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.objid == 2);
|
|
|
|
|
|
foreach (var b in bill)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.executeStatus = "1";
|
|
|
|
|
|
WmsBaseLocation location = b.a;
|
|
|
|
|
|
WmsProductStock stock = b.b;
|
|
|
|
|
|
WcsTask wcsTask;
|
|
|
|
|
|
int qty = 0;
|
|
|
|
|
|
if (stock.totalAmount - stock.frozenAmount <= needNumber)//该料箱全部出
|
|
|
|
|
|
{
|
|
|
|
|
|
item.outstockQty += stock.totalAmount - stock.frozenAmount;
|
|
|
|
|
|
qty = Convert.ToInt32(stock.totalAmount - stock.frozenAmount);
|
|
|
|
|
|
stock.updateDate = DateTime.Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
item.outstockQty += needNumber;
|
|
|
|
|
|
qty = Convert.ToInt32(needNumber);
|
|
|
|
|
|
stock.updateDate = DateTime.Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
MesBasePalletInfo? mesBasePalletInfo = dbContext.MesBasePalletInfo.FirstOrDefault(t => t.palletInfoCode == location.containerCode);
|
|
|
|
|
|
if (mesBasePalletInfo != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
WmsProductOutstockDetail detail = new()
|
|
|
|
|
|
{
|
|
|
|
|
|
productId = item.productId,
|
|
|
|
|
|
productOutstockId = item.productOutstockId,
|
|
|
|
|
|
locationCode = location.locationCode,
|
|
|
|
|
|
executeStatus = "1",
|
|
|
|
|
|
beginTime = DateTime.Now,
|
|
|
|
|
|
warehouseId = item.warehouseId,
|
|
|
|
|
|
erpAmount = 0,
|
|
|
|
|
|
confirmAmount = 0,
|
|
|
|
|
|
outstockAmount = 1,
|
|
|
|
|
|
planAmount = 1,
|
|
|
|
|
|
productBatch = item.productBatch,
|
|
|
|
|
|
productOutstockDetailId = StaticData.SnowId.NextId(),
|
|
|
|
|
|
productBarcode = mesBasePalletInfo.materialBarcode
|
|
|
|
|
|
};
|
|
|
|
|
|
if (location.locDeep == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
int? column = 0;
|
|
|
|
|
|
if (location.locColumn % 2 == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
column = location.locColumn + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
column = location.locColumn - 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
WmsBaseLocation? wmsBaseLocation = dbContext.WmsBaseLocation.Where(t => t.locColumn == column)
|
|
|
|
|
|
.Where(t => t.locRow == location.locRow)
|
|
|
|
|
|
.Where(t => t.warehouseId == location.warehouseId).FirstOrDefault();
|
|
|
|
|
|
if (wmsBaseLocation != null && !string.IsNullOrEmpty(wmsBaseLocation.containerCode))
|
|
|
|
|
|
{
|
|
|
|
|
|
WmsBaseLocation? toLocation = dbContext.WmsBaseLocation.Where(t => t.warehouseId == location.warehouseId)
|
|
|
|
|
|
.Where(t => t.locDeep == 1)
|
|
|
|
|
|
.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault();
|
|
|
|
|
|
toLocation ??= dbContext.WmsBaseLocation.Where(t => t.warehouseId == location.warehouseId)
|
|
|
|
|
|
.Where(t => t.warehouseId != location.locationId)
|
|
|
|
|
|
.Where(t => string.IsNullOrEmpty(t.containerCode))
|
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
if (toLocation != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var RemoveTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
orderId = item.productOutstockId,
|
|
|
|
|
|
taskType = 38,
|
|
|
|
|
|
containerNo = wmsBaseLocation.containerCode,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now.AddSeconds(-10),
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
materialId = item.productId,
|
|
|
|
|
|
currPointId = wmsBaseLocation.locationId,
|
|
|
|
|
|
currPointNo = wmsBaseLocation.locationCode,
|
|
|
|
|
|
nextPointId = agvEquip.objid,
|
|
|
|
|
|
nextPointNo = agvEquip.equipNo,
|
|
|
|
|
|
endPointId = toLocation.locationId,
|
|
|
|
|
|
endPointNo = toLocation.locationCode,
|
|
|
|
|
|
equipmentNo = agvEquip.equipNo,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
qty = qty
|
|
|
|
|
|
};
|
|
|
|
|
|
toLocation.locationStatus = "4";
|
|
|
|
|
|
toLocation.instockFlag = "1";
|
|
|
|
|
|
toLocation.updateBy = "WCS";
|
|
|
|
|
|
toLocation.updateTime = DateTime.Now;
|
|
|
|
|
|
wmsBaseLocation.updateBy = "WCS";
|
|
|
|
|
|
wmsBaseLocation.updateTime = DateTime.Now;
|
|
|
|
|
|
wmsBaseLocation.outstockFlag = "1";
|
|
|
|
|
|
wmsBaseLocation.locationStatus = "4";
|
|
|
|
|
|
dbContext.Update(toLocation);
|
|
|
|
|
|
dbContext.Update(wmsBaseLocation);
|
|
|
|
|
|
dbContext.Add(RemoveTask);
|
|
|
|
|
|
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(RemoveTask);
|
|
|
|
|
|
dbContext.Add(wcsTaskLog);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
wcsTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
orderId = item.productOutstockId,
|
|
|
|
|
|
taskType = 38,
|
|
|
|
|
|
containerNo = location.containerCode,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
materialId = item.productId,
|
|
|
|
|
|
currPointId = location.locationId,
|
|
|
|
|
|
currPointNo = location.locationCode,
|
|
|
|
|
|
nextPointId = agvEquip.objid,
|
|
|
|
|
|
nextPointNo = agvEquip.equipNo,
|
|
|
|
|
|
endPointId = lineEquip.objid,
|
|
|
|
|
|
endPointNo = lineEquip.equipNo,
|
|
|
|
|
|
equipmentNo = agvEquip.equipNo,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
qty = qty
|
|
|
|
|
|
};
|
|
|
|
|
|
location.outstockFlag = "1";
|
|
|
|
|
|
location.locationStatus = "6";
|
|
|
|
|
|
location.updateBy = "WCS";
|
|
|
|
|
|
location.updateTime = DateTime.Now;
|
|
|
|
|
|
dbContext.Add(detail);
|
|
|
|
|
|
dbContext.Update(location);
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
dbContext.Update(stock);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
if (qty >= needNumber)
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (item.beginTime == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.beginTime = DateTime.Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
dbContext.Update(item);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(ex.Message + ex.StackTrace);
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 原材料出库
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void CreateRawTaskLogic()
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
|
|
|
|
|
|
//原材料库存
|
|
|
|
|
|
var rawStock = dbContext.WmsRawStock.Where(t => t.activeFlag == "1").ToList();
|
|
|
|
|
|
//原材料出库记录
|
|
|
|
|
|
var rawOutStock = dbContext.WmsRawOutstock
|
|
|
|
|
|
.Where(t => t.executeStatus == "0" || t.executeStatus == "1")
|
|
|
|
|
|
.Where(t => t.outstockAmount > t.realOutstockAmount)
|
|
|
|
|
|
.Where(t => t.auditStatus == "1")
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
List<WcsTaskManual> wcsTaskManuals = dbContext.WcsTaskManual.Where(t => t.nextPointId == 11).OrderBy(t => t.createBy).ToList();
|
|
|
|
|
|
if (wcsTaskManuals.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
WcsOutstockLock wcsOutstockLock = dbContext.WcsOutstockLock.Where(t => t.warehouseId == 512).First();
|
|
|
|
|
|
int taskCount = dbContext.WcsTask.Where(t => t.nextPointId == 11).Count();
|
|
|
|
|
|
if (taskCount == 0 && wcsOutstockLock.qty == 0 && wcsOutstockLock.boxStatus == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var wcs in wcsTaskManuals.Take(6))
|
|
|
|
|
|
{
|
|
|
|
|
|
WcsTask wcsTask = CoreMapper.Map<WcsTask>(wcs);
|
|
|
|
|
|
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(wcsTask);
|
|
|
|
|
|
wcsOutstockLock.qty += 1;
|
|
|
|
|
|
wcsOutstockLock.boxStatus = 1;
|
|
|
|
|
|
dbContext.Update(wcsOutstockLock);
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
dbContext.Add(wcsTaskLog);
|
|
|
|
|
|
dbContext.WcsTaskManual.Where(t => t.objid == wcs.objid).Delete();
|
|
|
|
|
|
}
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in rawOutStock)
|
|
|
|
|
|
{
|
|
|
|
|
|
decimal? RealOutNumber = item.realOutstockAmount;
|
|
|
|
|
|
var endEquip = StaticData.BaseEquip.FirstOrDefault(t => t.equipNo == item.endStationCode);
|
|
|
|
|
|
if (endEquip != null && endEquip.floorNo == 5)
|
|
|
|
|
|
{
|
|
|
|
|
|
lock (SystemData.outStockLock)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (endEquip.equipType == 8)//CTU出库
|
|
|
|
|
|
{
|
|
|
|
|
|
var wcsOutstockLock = dbContext.WcsOutstockLock.Where(t => t.warehouseId == 512).First();
|
|
|
|
|
|
if (wcsOutstockLock.qty == 0 && wcsOutstockLock.boxStatus == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var wmsRawStocks = rawStock
|
|
|
|
|
|
.Where(t => t.materialId == item.materialId)
|
|
|
|
|
|
.Where(t => t.warehouseId == item.warehouseId)
|
|
|
|
|
|
.Select(t => t.locationCode)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var wmsBaseLocations = dbContext.WmsBaseLocation
|
|
|
|
|
|
.Where(t => t.activeFlag == "1")
|
|
|
|
|
|
.Where(t => t.delFlag == "0")
|
|
|
|
|
|
.Where(t => t.locationScrapType == "1")
|
|
|
|
|
|
.Where(t => t.instockFlag == "0")
|
|
|
|
|
|
.Where(t => t.outstockFlag == "0")
|
|
|
|
|
|
.Where(t => t.ContainerStatus == "1")
|
|
|
|
|
|
.Where(t => t.warehouseId == item.warehouseId)
|
|
|
|
|
|
.Where(t => wmsRawStocks.Contains(t.locationCode))
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
decimal? needNumber = item.outstockAmount - RealOutNumber;
|
|
|
|
|
|
|
|
|
|
|
|
var bill = from a in wmsBaseLocations
|
|
|
|
|
|
from b in rawStock
|
|
|
|
|
|
where a.locationCode == b.locationCode
|
|
|
|
|
|
select new { a, b };
|
|
|
|
|
|
//如果第一列满足需求,则按第一列排序,否则按最后一列排序
|
|
|
|
|
|
if (bill.Where(t => t.a.locColumn == 1).Select(t => t.b.totalAmount - t.b.frozenAmount).Sum() > needNumber)
|
|
|
|
|
|
{
|
|
|
|
|
|
bill = bill.OrderBy(t => t.a.locColumn).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
bill = bill.OrderByDescending(t => t.a.locColumn).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
//做数量限制
|
|
|
|
|
|
|
|
|
|
|
|
//bill = bill.Take(5 - dbContext.WcsCmd.Where(t => t.cmdStatus < 3 && t.nextPointId == 20).Count());
|
|
|
|
|
|
bill = bill.Take(6);
|
|
|
|
|
|
BaseEquip ctuEquip = StaticData.BaseEquip.First(t => t.objid == 11);
|
|
|
|
|
|
BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.objid == 20);
|
|
|
|
|
|
foreach (var b in bill)
|
|
|
|
|
|
{
|
|
|
|
|
|
needNumber = item.outstockAmount - RealOutNumber;
|
|
|
|
|
|
item.executeStatus = "1";
|
|
|
|
|
|
WmsBaseLocation location = b.a;
|
|
|
|
|
|
WmsRawStock stock = b.b;
|
|
|
|
|
|
WcsTask wcsTask;
|
|
|
|
|
|
int qty = 0;
|
|
|
|
|
|
int outNumber = 0;
|
|
|
|
|
|
if (stock.totalAmount - stock.frozenAmount <= needNumber)//该料箱全部出
|
|
|
|
|
|
{
|
|
|
|
|
|
RealOutNumber += stock.totalAmount - stock.frozenAmount;
|
|
|
|
|
|
qty = Convert.ToInt32(stock.totalAmount - stock.frozenAmount);
|
|
|
|
|
|
stock.updateDate = DateTime.Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
RealOutNumber += needNumber;
|
|
|
|
|
|
qty = Convert.ToInt32(needNumber);
|
|
|
|
|
|
stock.updateDate = DateTime.Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
wcsTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
orderId = item.rawOutstockId,
|
|
|
|
|
|
taskType = 38,
|
|
|
|
|
|
containerNo = location.containerCode,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
taskStatus = -1,
|
|
|
|
|
|
materialId = item.materialId,
|
|
|
|
|
|
currPointId = location.locationId,
|
|
|
|
|
|
currPointNo = location.locationCode,
|
|
|
|
|
|
nextPointId = ctuEquip.objid,
|
|
|
|
|
|
nextPointNo = ctuEquip.equipNo,
|
|
|
|
|
|
endPointId = lineEquip.objid,
|
|
|
|
|
|
endPointNo = lineEquip.equipNo,
|
|
|
|
|
|
equipmentNo = ctuEquip.equipNo,
|
|
|
|
|
|
ud1 = location.locColumn,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
qty = qty
|
|
|
|
|
|
};
|
|
|
|
|
|
MesBaseBarcodeInfo? mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.Where(t => t.barcodeInfo == stock.instockBatch).FirstOrDefault();
|
|
|
|
|
|
if (mesBaseBarcodeInfo != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
WmsRawOutstockDetail wmsProductOutstockDetail = new WmsRawOutstockDetail()
|
|
|
|
|
|
{
|
|
|
|
|
|
rawOutstockDetailId = StaticData.SnowId.NextId(),
|
|
|
|
|
|
rawOutstockId = item.rawOutstockId,
|
|
|
|
|
|
materialId = item.materialId,
|
|
|
|
|
|
createDate = DateTime.Now,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
taskCode = wcsTask.objid.ToString(),
|
|
|
|
|
|
executeStatus = "1",
|
|
|
|
|
|
locationCode = location.locationCode,
|
|
|
|
|
|
outstockAmount = qty,
|
|
|
|
|
|
planAmount = item.outstockAmount,
|
|
|
|
|
|
warehouseId = item.warehouseId,
|
|
|
|
|
|
materialBarcode = mesBaseBarcodeInfo.barcodeInfo,
|
|
|
|
|
|
instockBatch = mesBaseBarcodeInfo.batchCode,
|
|
|
|
|
|
stackAmount = qty,
|
|
|
|
|
|
outstockPerson = "WCS",
|
|
|
|
|
|
outstockTime = DateTime.Now,
|
|
|
|
|
|
outstockWay = "2",
|
|
|
|
|
|
materialProductionDate = mesBaseBarcodeInfo.productionDate
|
|
|
|
|
|
};
|
|
|
|
|
|
location.outstockFlag = "1";
|
|
|
|
|
|
location.locationStatus = "6";
|
|
|
|
|
|
location.updateBy = "WCS";
|
|
|
|
|
|
location.updateTime = DateTime.Now;
|
|
|
|
|
|
wcsOutstockLock.boxStatus = 1;
|
|
|
|
|
|
dbContext.Add(wmsProductOutstockDetail);
|
|
|
|
|
|
dbContext.Update(location);
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
dbContext.Update(stock);
|
|
|
|
|
|
if (qty >= needNumber)
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (item.beginTime == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.beginTime = DateTime.Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
dbContext.Update(wcsOutstockLock);
|
|
|
|
|
|
dbContext.Update(item);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}//CTU出库
|
|
|
|
|
|
if (endEquip.equipType == 10)//CTU出库到装配区
|
|
|
|
|
|
{
|
|
|
|
|
|
bool CreateSuccess = false;
|
|
|
|
|
|
var wcsOutstockLock = dbContext.WcsOutstockLock
|
|
|
|
|
|
.Where(t => t.warehouseId == 512)
|
|
|
|
|
|
.First();
|
|
|
|
|
|
if (wcsOutstockLock.qty == 0 && wcsOutstockLock.boxStatus == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var orderList = rawOutStock.Where(t => t.endStationCode == item.endStationCode).ToList();
|
|
|
|
|
|
foreach (var order in orderList)
|
|
|
|
|
|
{
|
|
|
|
|
|
WcsTask? task = dbContext.WcsTask.FirstOrDefault(t => t.taskType == 32);
|
|
|
|
|
|
if (task == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var wmsRawStocks = rawStock
|
|
|
|
|
|
.Where(t => t.materialId == order.materialId && t.warehouseId == order.warehouseId)
|
|
|
|
|
|
.Select(t => t.palletInfoCode)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var wmsBaseLocations = dbContext.WmsBaseLocation
|
|
|
|
|
|
.Where(t => t.activeFlag == "1")
|
|
|
|
|
|
.Where(t => t.delFlag == "0")
|
|
|
|
|
|
.Where(t => t.locationScrapType == "1")
|
|
|
|
|
|
.Where(t => t.instockFlag == "0")
|
|
|
|
|
|
.Where(t => t.outstockFlag == "0")
|
|
|
|
|
|
.Where(t => t.warehouseId == order.warehouseId)
|
|
|
|
|
|
.Where(t => wmsRawStocks.Contains(t.containerCode))
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
decimal? needNumber = order.outstockAmount - RealOutNumber;
|
|
|
|
|
|
|
|
|
|
|
|
var bill = from a in wmsBaseLocations
|
|
|
|
|
|
from b in rawStock
|
|
|
|
|
|
where a.containerCode == b.palletInfoCode
|
|
|
|
|
|
select new { a, b };
|
|
|
|
|
|
//如果第一列满足需求,则按第一列排序,否则按最后一列排序
|
|
|
|
|
|
if (bill.Where(t => t.a.locColumn == 1).Select(t => t.b.totalAmount - t.b.frozenAmount).Sum() > needNumber)
|
|
|
|
|
|
{
|
|
|
|
|
|
bill = bill.OrderBy(t => t.a.locColumn).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
bill = bill.OrderByDescending(t => t.a.locColumn).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
//做数量限制
|
|
|
|
|
|
|
|
|
|
|
|
bill = bill.Take(5 - dbContext.WcsCmd.Where(t => t.cmdStatus < 3 && t.nextPointId == 20).Count());
|
|
|
|
|
|
BaseEquip ctuEquip = StaticData.BaseEquip.First(t => t.objid == 11);
|
|
|
|
|
|
BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.objid == 20);
|
|
|
|
|
|
foreach (var b in bill)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.executeStatus = "1";
|
|
|
|
|
|
WmsBaseLocation location = b.a;
|
|
|
|
|
|
WmsRawStock stock = b.b;
|
|
|
|
|
|
WcsTask wcsTask;
|
|
|
|
|
|
int qty = 0;
|
|
|
|
|
|
if (stock.totalAmount - stock.frozenAmount <= needNumber)//该料箱全部出
|
|
|
|
|
|
{
|
|
|
|
|
|
RealOutNumber += stock.totalAmount - stock.frozenAmount;
|
|
|
|
|
|
qty = Convert.ToInt32(stock.totalAmount - stock.frozenAmount);
|
|
|
|
|
|
stock.updateDate = DateTime.Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
RealOutNumber += needNumber;
|
|
|
|
|
|
qty = Convert.ToInt32(needNumber);
|
|
|
|
|
|
stock.updateDate = DateTime.Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
wcsTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
orderId = item.rawOutstockId,
|
|
|
|
|
|
taskType = 30,
|
|
|
|
|
|
containerNo = location.containerCode,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
materialId = item.materialId,
|
|
|
|
|
|
currPointId = location.locationId,
|
|
|
|
|
|
currPointNo = location.locationCode,
|
|
|
|
|
|
nextPointId = ctuEquip.objid,
|
|
|
|
|
|
nextPointNo = ctuEquip.equipNo,
|
|
|
|
|
|
endPointId = lineEquip.objid,
|
|
|
|
|
|
endPointNo = lineEquip.equipNo,
|
|
|
|
|
|
equipmentNo = ctuEquip.equipNo,
|
|
|
|
|
|
ud1 = location.locColumn,
|
|
|
|
|
|
useFlag = 0,
|
|
|
|
|
|
qty = qty
|
|
|
|
|
|
};
|
|
|
|
|
|
MesBaseBarcodeInfo? mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.Where(t => t.barcodeInfo == stock.instockBatch).FirstOrDefault();
|
|
|
|
|
|
if (mesBaseBarcodeInfo != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
WmsRawOutstockDetail wmsProductOutstockDetail = new WmsRawOutstockDetail()
|
|
|
|
|
|
{
|
|
|
|
|
|
rawOutstockDetailId = StaticData.SnowId.NextId(),
|
|
|
|
|
|
rawOutstockId = item.rawOutstockId,
|
|
|
|
|
|
materialId = item.materialId,
|
|
|
|
|
|
createDate = DateTime.Now,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
taskCode = wcsTask.objid.ToString(),
|
|
|
|
|
|
executeStatus = "1",
|
|
|
|
|
|
locationCode = location.locationCode,
|
|
|
|
|
|
outstockAmount = qty,
|
|
|
|
|
|
planAmount = item.outstockAmount,
|
|
|
|
|
|
warehouseId = item.warehouseId,
|
|
|
|
|
|
materialBarcode = mesBaseBarcodeInfo.barcodeInfo,
|
|
|
|
|
|
instockBatch = mesBaseBarcodeInfo.batchCode,
|
|
|
|
|
|
stackAmount = qty,
|
|
|
|
|
|
outstockPerson = "WCS",
|
|
|
|
|
|
outstockTime = DateTime.Now,
|
|
|
|
|
|
outstockWay = "2",
|
|
|
|
|
|
materialProductionDate = mesBaseBarcodeInfo.productionDate
|
|
|
|
|
|
};
|
|
|
|
|
|
dbContext.Add(wmsProductOutstockDetail);
|
|
|
|
|
|
location.outstockFlag = "1";
|
|
|
|
|
|
location.locationStatus = "6";
|
|
|
|
|
|
location.updateBy = "WCS";
|
|
|
|
|
|
location.updateTime = DateTime.Now;
|
|
|
|
|
|
wcsOutstockLock.qty += 1;
|
|
|
|
|
|
wcsOutstockLock.boxStatus = 1;
|
|
|
|
|
|
dbContext.Update(wcsOutstockLock);
|
|
|
|
|
|
dbContext.Update(location);
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
dbContext.Update(stock);
|
|
|
|
|
|
CreateSuccess = true;
|
|
|
|
|
|
if (qty >= needNumber)
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (CreateSuccess)
|
|
|
|
|
|
{
|
|
|
|
|
|
BaseEquip startStationEquip = StaticData.BaseEquip.First(t => t.objid == 21);
|
|
|
|
|
|
BaseEquip bearAgvEquip = StaticData.BaseEquip.First(t => t.objid == 10);
|
|
|
|
|
|
BaseEquip endStationEquip = StaticData.BaseEquip.First(t => t.equipNo == item.endStationCode);
|
|
|
|
|
|
WcsTask bearAgvTask = new()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
orderId = item.orderId,
|
|
|
|
|
|
taskType = 32,
|
|
|
|
|
|
containerNo = "",
|
|
|
|
|
|
currPointId = startStationEquip.objid,
|
|
|
|
|
|
currPointNo = startStationEquip.equipNo,
|
|
|
|
|
|
nextPointId = bearAgvEquip.objid,
|
|
|
|
|
|
nextPointNo = bearAgvEquip.equipNo,
|
|
|
|
|
|
endPointId = endStationEquip.objid,
|
|
|
|
|
|
endPointNo = endStationEquip.equipNo,
|
|
|
|
|
|
serialNo = SystemData.GetSerialNo(dbContext),
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
materialId = item.materialId,
|
|
|
|
|
|
qty = 1,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
equipmentNo = startStationEquip.equipNo,
|
|
|
|
|
|
remark = "组装出库",
|
|
|
|
|
|
floorNo = 5,
|
|
|
|
|
|
masterId = item.materialId,
|
|
|
|
|
|
fromFloorNo = 5,
|
|
|
|
|
|
};
|
|
|
|
|
|
if (item.beginTime == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.beginTime = DateTime.Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
dbContext.Add(bearAgvTask);
|
|
|
|
|
|
dbContext.Update(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (endEquip.equipType == 12 || endEquip.equipType == 13)//原材料到柜体验收区
|
|
|
|
|
|
{
|
|
|
|
|
|
bool hasTask = dbContext.WcsTask.Where(t => t.nextPointId == 28 && t.taskStatus <= 5).Any();
|
|
|
|
|
|
if (hasTask)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (endEquip.emptyCount == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var wmsRawStocks = rawStock
|
|
|
|
|
|
.Where(t => t.materialId == item.materialId && t.warehouseId == item.warehouseId)
|
|
|
|
|
|
.WhereIf(endEquip.equipType == 13, t => t.completeFlag == "0")
|
|
|
|
|
|
.WhereIf(endEquip.equipType == 12, t => t.completeFlag == "1")
|
|
|
|
|
|
.Where(t => t.totalAmount > t.frozenAmount)
|
|
|
|
|
|
.Select(t => t.palletInfoCode)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var wmsBaseLocations = dbContext.WmsBaseLocation
|
|
|
|
|
|
.Where(t => t.activeFlag == "1")
|
|
|
|
|
|
.Where(t => t.delFlag == "0")
|
|
|
|
|
|
.Where(t => t.locationScrapType == "1")
|
|
|
|
|
|
.Where(t => t.instockFlag == "0")
|
|
|
|
|
|
.Where(t => t.outstockFlag == "0")
|
|
|
|
|
|
.Where(t => t.warehouseId == item.warehouseId)
|
|
|
|
|
|
.Where(t => wmsRawStocks.Contains(t.containerCode))
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
decimal? needNumber = item.outstockAmount - item.realOutstockAmount;
|
|
|
|
|
|
if (needNumber <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.executeStatus = "2";
|
|
|
|
|
|
dbContext.Update(item);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var bill = from a in wmsBaseLocations
|
|
|
|
|
|
from b in rawStock
|
|
|
|
|
|
where a.containerCode == b.palletInfoCode
|
|
|
|
|
|
select new { a, b };
|
|
|
|
|
|
//如果第一列满足需求,则按第一列排序,否则按最后一列排序
|
|
|
|
|
|
if (bill.Where(t => t.a.locColumn == 1).Select(t => t.b.totalAmount - t.b.frozenAmount).Sum() > needNumber)
|
|
|
|
|
|
{
|
|
|
|
|
|
bill = bill.OrderBy(t => t.a.locColumn).Take(1).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
bill = bill.OrderByDescending(t => t.a.locColumn).Take(1).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BaseEquip agvEquip = StaticData.BaseEquip.First(t => t.objid == 28);
|
|
|
|
|
|
BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.equipNo == item.endStationCode);
|
|
|
|
|
|
foreach (var b in bill)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.executeStatus = "1";
|
|
|
|
|
|
WmsBaseLocation location = b.a;
|
|
|
|
|
|
WmsRawStock stock = b.b;
|
|
|
|
|
|
WcsTask wcsTask;
|
|
|
|
|
|
int qty = 0;
|
|
|
|
|
|
if (stock.totalAmount - stock.frozenAmount <= needNumber)//该料箱全部出
|
|
|
|
|
|
{
|
|
|
|
|
|
item.realOutstockAmount += stock.totalAmount - stock.frozenAmount;
|
|
|
|
|
|
qty = Convert.ToInt32(stock.totalAmount - stock.frozenAmount);
|
|
|
|
|
|
stock.updateDate = DateTime.Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
item.realOutstockAmount += needNumber;
|
|
|
|
|
|
qty = Convert.ToInt32(needNumber);
|
|
|
|
|
|
stock.updateDate = DateTime.Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
MesBaseBarcodeInfo? mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.Where(t => t.barcodeInfo == stock.instockBatch).FirstOrDefault();
|
|
|
|
|
|
if (mesBaseBarcodeInfo != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (location.locDeep == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
int? column = 0;
|
|
|
|
|
|
if (location.locColumn % 2 == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
column = location.locColumn + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
column = location.locColumn - 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
WmsBaseLocation? wmsBaseLocation = dbContext.WmsBaseLocation.Where(t => t.locColumn == column)
|
|
|
|
|
|
.Where(t => t.locRow == location.locRow)
|
|
|
|
|
|
.Where(t => t.warehouseId == location.warehouseId).FirstOrDefault();
|
|
|
|
|
|
if (wmsBaseLocation != null && !string.IsNullOrEmpty(wmsBaseLocation.containerCode))
|
|
|
|
|
|
{
|
|
|
|
|
|
WmsBaseLocation? toLocation = dbContext.WmsBaseLocation.Where(t => t.warehouseId == location.warehouseId)
|
|
|
|
|
|
.Where(t => t.locDeep == 1)
|
|
|
|
|
|
.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault();
|
|
|
|
|
|
toLocation ??= dbContext.WmsBaseLocation.Where(t => t.warehouseId == location.warehouseId)
|
|
|
|
|
|
.Where(t => t.warehouseId != location.locationId)
|
|
|
|
|
|
.Where(t => string.IsNullOrEmpty(t.containerCode))
|
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
if (toLocation != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var RemoveTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
orderId = item.rawOutstockId,
|
|
|
|
|
|
taskType = 38,
|
|
|
|
|
|
containerNo = wmsBaseLocation.containerCode,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now.AddSeconds(-10),
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
materialId = item.materialId,
|
|
|
|
|
|
currPointId = wmsBaseLocation.locationId,
|
|
|
|
|
|
currPointNo = wmsBaseLocation.locationCode,
|
|
|
|
|
|
nextPointId = agvEquip.objid,
|
|
|
|
|
|
nextPointNo = agvEquip.equipNo,
|
|
|
|
|
|
endPointId = toLocation.locationId,
|
|
|
|
|
|
endPointNo = toLocation.locationCode,
|
|
|
|
|
|
equipmentNo = agvEquip.equipNo,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
qty = qty
|
|
|
|
|
|
};
|
|
|
|
|
|
toLocation.locationStatus = "4";
|
|
|
|
|
|
toLocation.instockFlag = "1";
|
|
|
|
|
|
toLocation.updateBy = "WCS";
|
|
|
|
|
|
toLocation.updateTime = DateTime.Now;
|
|
|
|
|
|
wmsBaseLocation.updateBy = "WCS";
|
|
|
|
|
|
wmsBaseLocation.updateTime = DateTime.Now;
|
|
|
|
|
|
wmsBaseLocation.outstockFlag = "1";
|
|
|
|
|
|
wmsBaseLocation.locationStatus = "4";
|
|
|
|
|
|
dbContext.Update(toLocation);
|
|
|
|
|
|
dbContext.Update(wmsBaseLocation);
|
|
|
|
|
|
dbContext.Add(RemoveTask);
|
|
|
|
|
|
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(RemoveTask);
|
|
|
|
|
|
dbContext.Add(wcsTaskLog);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
wcsTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
orderId = item.rawOutstockId,
|
|
|
|
|
|
taskType = endEquip.equipType == 12 ? 46 : 33,//如果是12那么就是原材料到柜体验收区,如果是13那么就是原材料到背板安装区
|
|
|
|
|
|
containerNo = location.containerCode,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
materialId = item.materialId,
|
|
|
|
|
|
currPointId = location.locationId,
|
|
|
|
|
|
currPointNo = location.locationCode,
|
|
|
|
|
|
nextPointId = agvEquip.objid,
|
|
|
|
|
|
nextPointNo = agvEquip.equipNo,
|
|
|
|
|
|
endPointId = lineEquip.objid,
|
|
|
|
|
|
endPointNo = lineEquip.equipNo,
|
|
|
|
|
|
equipmentNo = agvEquip.equipNo,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
qty = qty
|
|
|
|
|
|
};
|
|
|
|
|
|
WmsRawOutstockDetail wmsProductOutstockDetail = new WmsRawOutstockDetail()
|
|
|
|
|
|
{
|
|
|
|
|
|
rawOutstockDetailId = StaticData.SnowId.NextId(),
|
|
|
|
|
|
rawOutstockId = item.rawOutstockId,
|
|
|
|
|
|
materialId = item.materialId,
|
|
|
|
|
|
createDate = DateTime.Now,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
taskCode = wcsTask.objid.ToString(),
|
|
|
|
|
|
executeStatus = "1",
|
|
|
|
|
|
locationCode = location.locationCode,
|
|
|
|
|
|
outstockAmount = qty,
|
|
|
|
|
|
planAmount = item.outstockAmount,
|
|
|
|
|
|
warehouseId = item.warehouseId,
|
|
|
|
|
|
materialBarcode = mesBaseBarcodeInfo.barcodeInfo,
|
|
|
|
|
|
instockBatch = mesBaseBarcodeInfo.batchCode,
|
|
|
|
|
|
stackAmount = qty,
|
|
|
|
|
|
outstockPerson = "WCS",
|
|
|
|
|
|
outstockTime = DateTime.Now,
|
|
|
|
|
|
outstockWay = "2",
|
|
|
|
|
|
materialProductionDate = mesBaseBarcodeInfo.productionDate
|
|
|
|
|
|
};
|
|
|
|
|
|
dbContext.Add(wmsProductOutstockDetail);
|
|
|
|
|
|
location.outstockFlag = "1";
|
|
|
|
|
|
location.locationStatus = "6";
|
|
|
|
|
|
location.updateBy = "WCS";
|
|
|
|
|
|
location.updateTime = DateTime.Now;
|
|
|
|
|
|
endEquip.emptyCount = 1;
|
|
|
|
|
|
dbContext.Update(endEquip);
|
|
|
|
|
|
dbContext.Update(location);
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
dbContext.Update(stock);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
if (qty >= needNumber)
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (item.beginTime == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.beginTime = DateTime.Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
dbContext.Update(item);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|