using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm;
using WIDESEA_Common;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.FreeDB;
using WIDESEA_Entity.DomainModels;
using WIDESEA_WMS.IRepositories;
using WIDESEA_WMS.Repositories;
namespace WIDESEA_WMS.Common
{
public class HandleTask
{
public static FreeDB freeDB = new FreeDB();
///
/// 添加历史任务
///
/// 任务
/// 操作类型
public static void AddHtyTask(dt_agvtask task, string operatetype = "Complete", string compeletor = "AGV")
{
VOLContext context = new VOLContext();
Idt_agvtask_htyRepository htyRepository = new dt_agvtask_htyRepository(context);
Idt_agvtaskRepository repository = new dt_agvtaskRepository(context);
dt_agvtask_hty agvtask_Hty = new dt_agvtask_hty()
{
hty_pkid = Guid.NewGuid(),
agv_id = Guid.Empty,
agv_tasknum = task.agv_tasknum,
agv_materielid = task.agv_materielid,
agv_qty = task.agv_qty,
agv_createtime = task.agv_createtime,
agv_realesstime = task.agv_realesstime,
agv_executingBeginTime = task.agv_executingBeginTime,
agv_executingEndTime = task.agv_executingEndTime,
agv_completeBeginTime = task.agv_completeBeginTime,
agv_finishedtime = DateTime.Now,
agv_taskstate = task.agv_taskstate,
agv_tasktype = task.agv_tasktype,
agv_fromaddress = task.agv_fromaddress,
agv_toaddress = task.agv_toaddress,
agv_operatetype = operatetype,
agv_compeletor = compeletor,
agv_completedate = DateTime.Now,
agv_grade = task.agv_grade,
agv_userid = task.agv_userid,
agv_barcode = task.agv_barcode,
agv_code = task.agv_code,
agv_worktype = task.agv_worktype,
agv_remark = task.agv_remark
};
htyRepository.Add(agvtask_Hty, true);
repository.Delete(task, true);
}
///
/// 库存处理
///
///
public static void Updateinventory(dt_agvtask task)
{
string[] bindSNs = task.bindSN.Split(",");
if (bindSNs.Length > 0)
{
var Materiel = QueryData.QueryMateriel(task.agv_materielid);
List inventorys = new List();
foreach (string bindSN in bindSNs)
{
dt_inventory inventory = new dt_inventory()
{
SN = bindSN,//待完善
};
inventorys.Add(inventory);
}
if (task.agv_tasktype == AGVTaskTypeEnum.TaskType_Inbound.ToString() || task.agv_tasktype == AGVTaskTypeEnum.TaskType_OutsourceInbound.ToString())
freeDB.AddRange(inventorys);
else if (task.agv_tasktype == AGVTaskTypeEnum.TaskType_Outbound.ToString() || task.agv_tasktype == AGVTaskTypeEnum.TaskType_OutsourceOutbound.ToString())
freeDB.Remove(inventorys);
}
}
///
/// 自动更新缓存架状态
///
///
public static void AutoUpdateHCJState(dt_agvtask task)
{
VOLContext context = new VOLContext();
Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
var station1 = stationinfoRepository.FindFirst(t => t.stationCode == task.agv_fromaddress);
var station2 = stationinfoRepository.FindFirst(t => t.stationCode == task.agv_toaddress);
station2.quantity = station1.quantity;
station2.bindSN = station1.bindSN;
station2.location_state = LocationStateEnum.Stroge.ToString();
station2.tray_status = station1.tray_status;
stationinfoRepository.Update(station2, true);
station1.quantity = 0;
station1.bindSN = string.Empty;
station1.location_state = LocationStateEnum.Empty.ToString();
station1.tray_status = string.Empty;
stationinfoRepository.Update(station1, true);
}
}
}