using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection.Metadata; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using WIDESEA_Common.LocationEnum; using WIDESEA_Common.StockEnum; using WIDESEA_Common.TaskEnum; using WIDESEA_Common.Warehouse; using WIDESEA_Core; using WIDESEA_Core.BaseRepository; using WIDESEA_Core.BaseServices; using WIDESEA_Core.Helper; using WIDESEA_Core.LogHelper; using WIDESEA_DTO.MES; using WIDESEA_DTO.Task; using WIDESEA_IBasicService; using WIDESEA_IStockService; using WIDESEA_Model.Models; using WIDESEA_Model.Models.Basic; using WIDESEA_Model.Models.Stock; using WIDESEAWCS_DTO.Stock; using WIDESEAWCS_ITaskInfoService; using WIDESEAWCS_Model.Models.TaskInfo; namespace WIDESEAWCS_TaskInfoService { public class TaskService : ServiceBase>, ITaskService { private readonly ILocationInfoService _LocationInfoService; private readonly IUnitOfWorkManage _unitOfWorkManage; private readonly IRepository _Task_HtyRepository; private readonly IRepository _LocationInfoRepository; private readonly IRepository _StockInfoRepository; private readonly IRepository _OutstockinfoRepository; private readonly IStockService _IStockService; private readonly ILocationInfoService _ILocationInfoService; private readonly IRepository _WarehouseRepository; private readonly IRepository _IOutstockinfoService; private readonly IRepository _IStockInfoDetailRepository; private readonly IRepository _IStockInfohtyRepository; private readonly IRepository _IStockInfoDetailHtyRepository; //WCS满桶出库信号 private static bool kk = false; public TaskService(IRepository BaseDal, ILocationInfoService ILocationInfoService, IRepository IStockInfoDetailRepository, IRepository IStockInfohtyRepository, IRepository IStockInfoDetailHtyRepository, IRepository IOutstockinfoService, IStockService IStockService, IRepository WarehouseService, IRepository OutstockinfoRepository, ILocationInfoService LocationInfoService, IRepository StockInfoRepository, IRepository LocationInfoRepository, IRepository Task_HtyRepository, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal) { _LocationInfoService = LocationInfoService; _unitOfWorkManage = unitOfWorkManage; _Task_HtyRepository = Task_HtyRepository; _LocationInfoRepository = LocationInfoRepository; _StockInfoRepository = StockInfoRepository; _OutstockinfoRepository = OutstockinfoRepository; _IStockService = IStockService; _ILocationInfoService = ILocationInfoService; _WarehouseRepository = WarehouseService; _IOutstockinfoService = IOutstockinfoService; _IStockInfoDetailRepository = IStockInfoDetailRepository; _IStockInfohtyRepository = IStockInfohtyRepository; _IStockInfoDetailHtyRepository = IStockInfoDetailHtyRepository; } public IRepository Repository => BaseDal; //测试 public WebResponseContent ceshi() { WebResponseContent content = new WebResponseContent(); string mes = AppSettings.Get("MSE"); if (!string.IsNullOrEmpty(mes)) { string k = ""; HttpHelper.Get($"{mes}+{k}"); } return content; } //空桶入库任务 public WebResponseContent addInTask(string location) { WebResponseContent content = new WebResponseContent(); Dt_Task task = new Dt_Task(); //入库分配货位 Dt_LocationInfo locations = _LocationInfoService.AllotLocationInfo(1); locations.LocationStatus = (int)LocationStatusEnum.Lock; task.SourceAddress = location; task.TargetAddress = locations.LocationCode; task.Roadway = "SC01"; task.Grade = 1; task.TaskType = (int)TaskTypeEnum.InEmpty; task.TaskState = (int)TaskStatusEnum.InNew; task.TaskNum = DateTime.Now.ToString("mmss").ObjToInt(); //开始数据库事务 _unitOfWorkManage.BeginTran(); _LocationInfoRepository.UpdateData(locations); BaseDal.AddData(task); //发送给WCS string address = AppSettings.Get("WCS"); if (!string.IsNullOrEmpty(address)) { HttpHelper.Post($"{address}/api/Task/WMSaddTask/", task.Serialize()); } //提交事务 _unitOfWorkManage.CommitTran(); return content; } //满桶入库任务 public WebResponseContent addOutTask(Stock stock) { WebResponseContent content = new WebResponseContent(); Dt_Task task = new Dt_Task(); List stockInfoDetail = new List(); List MESSocks = new List(); string materielDetailedid = stock.MaterialCode1 + DateTime.Now.ToString("mmss").ObjToInt(); //去MES查询物料编号详细信息 int h = 0; string mes = AppSettings.Get("MSE"); if (!string.IsNullOrEmpty(mes)) { if (stock.MaterialCode1 != null && !stock.MaterialCode1.Equals("")) { MESSocks[0] = JsonConvert.DeserializeObject(HttpHelper.Get($"{mes}+{stock.MaterialCode1}")); stockInfoDetail[0].MaterielCode = stock.MaterialCode1; } if (stock.MaterialCode2 != null && !stock.MaterialCode2.Equals("")) { MESSocks[1] = JsonConvert.DeserializeObject(HttpHelper.Get($"{mes}+{stock.MaterialCode2}")); h++; stockInfoDetail[1].MaterielCode = stock.MaterialCode2; } if (stock.MaterialCode3 != null && !stock.MaterialCode3.Equals("")) { MESSocks[2] = JsonConvert.DeserializeObject(HttpHelper.Get($"{mes}+{stock.MaterialCode3}")); h++; stockInfoDetail[2].MaterielCode = stock.MaterialCode3; } if (stock.MaterialCode4 != null && !stock.MaterialCode4.Equals("")) { MESSocks[3] = JsonConvert.DeserializeObject(HttpHelper.Get($"{mes}+{stock.MaterialCode4}")); h++; stockInfoDetail[3].MaterielCode = stock.MaterialCode4; } } //存储物料编号详细信息 for(int m = 0; m <= h; m++) { stockInfoDetail[m].MaterielDetailedid = materielDetailedid; stockInfoDetail[m].BarcodeType = MESSocks[m].BarcodeType; stockInfoDetail[m].AuxQty = MESSocks[m].AuxQty; stockInfoDetail[m].Quantity = MESSocks[m].Quantity; stockInfoDetail[m].MaxQty = MESSocks[m].MaxQty; stockInfoDetail[m].BarWeight = MESSocks[m].BarWeight; stockInfoDetail[m].PackageQty = MESSocks[m].PackageQty; stockInfoDetail[m].QuantityIn = MESSocks[m].QuantityIn; stockInfoDetail[m].QuantityOut = MESSocks[m].QuantityOut; stockInfoDetail[m].Status = MESSocks[m].Status; stockInfoDetail[m].Materialld = MESSocks[m].Materialld; stockInfoDetail[m].BatchNum = MESSocks[m].BatchNum; stockInfoDetail[m].CreateEmpld = MESSocks[m].CreateEmpld; stockInfoDetail[m].Taskld = MESSocks[m].Taskld; stockInfoDetail[m].TaskSubld = MESSocks[m].TaskSubld; } //区分货区 int k = 1; Dt_Warehouse warehouse = _WarehouseRepository.QueryFirst(x => x.MaterialName == ""); if (warehouse.MaterialType == (int)WarehouseTypeEnum.Food) { k = 2; } else if (warehouse.MaterialType == (int)WarehouseTypeEnum.Industry) { k = 3; } //入库分配货位 Dt_LocationInfo locations = _LocationInfoService.AllotLocationInfo(k); locations.LocationStatus = (int)LocationStatusEnum.Lock; //创建物料组盘 Dt_StockInfo stockInfo = new Dt_StockInfo(); stockInfo.LocationCode = locations.LocationCode; stockInfo.StockStatus = (int)StockStatusEmun.组盘暂存; stockInfo.MaterielCode1 = stock.MaterialCode1; stockInfo.MaterielCode2 = stock.MaterialCode2; stockInfo.MaterielCode3 = stock.MaterialCode3; stockInfo.MaterielCode4 = stock.MaterialCode4; stockInfo.MaterielDetailedid = materielDetailedid; stockInfo.StockType = (int)StockTypeEmun.水; //创建物料详细信息 //判定入库模式 Dt_Outstockinfo outstockinfo = _IOutstockinfoService.QueryFirst(x => x.Id == 1); //正常入库 if (outstockinfo.OutMode == 1) { task.SourceAddress = stock.location; task.TargetAddress = locations.LocationCode; task.Roadway = "SC01"; task.Grade = 1; task.TaskType = (int)TaskTypeEnum.Infull; task.TaskState = (int)TaskStatusEnum.InNew; task.TaskNum = DateTime.Now.ToString("mmss").ObjToInt(); } //直接出库 else { task.SourceAddress = "1-52-1"; task.TargetAddress = locations.LocationCode; task.Roadway = "SC01"; task.Grade = 1; task.TaskType = (int)TaskTypeEnum.OutDirect; task.TaskState = (int)TaskStatusEnum.InNew; task.TaskNum = DateTime.Now.ToString("mmss").ObjToInt(); } //开始数据库事务 _unitOfWorkManage.BeginTran(); _LocationInfoRepository.UpdateData(locations); BaseDal.AddData(task); _StockInfoRepository.AddData(stockInfo); _IStockInfoDetailRepository.AddData(stockInfoDetail); //发送给WCS string address = AppSettings.Get("WCS"); if (!string.IsNullOrEmpty(address)) { HttpHelper.Post($"{address}/api/Task/WMSaddTask/", task.Serialize()); } //提交事务 _unitOfWorkManage.CommitTran(); return content; } //WCS入库任务完成 public Stock WCSAccomplishIn(int TaskNum) { Stock content = new Stock(); //查询任务 Dt_Task task = SeletcTaskNum(TaskNum); if (task == null) { return content; } //空桶入库 if (task.TaskType == (int)TaskTypeEnum.InEmpty) { //生成库存信息 //Dt_StockInfo stockInfo = new Dt_StockInfo(); //修改货位状态 Dt_LocationInfo locationInfo = _LocationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); locationInfo.LocationStatus = (int)LocationStatusEnum.EmptyBarrel; //生成历史任务 Dt_Task_Hty taskhty = new Dt_Task_Hty(); taskhty.TaskNum = task.TaskNum; taskhty.WMSId = task.WMSId; taskhty.PalletCode = task.PalletCode; taskhty.Roadway = task.Roadway; taskhty.SourceAddress = task.SourceAddress; taskhty.TargetAddress = task.TargetAddress; taskhty.CurrentAddress = task.CurrentAddress; taskhty.NextAddress = task.NextAddress; taskhty.ExceptionMessage = task.ExceptionMessage; taskhty.Grade = task.Grade; taskhty.Remark = task.Remark; taskhty.TaskType = task.TaskType; taskhty.TaskState = (int)TaskStatusEnum.Task_Finish; //开始数据库事务 _unitOfWorkManage.BeginTran(); //_StockInfoRepository.AddData(stockInfo); _LocationInfoRepository.UpdateData(locationInfo); _Task_HtyRepository.AddData(taskhty); BaseDal.DeleteData(task); //提交事务 _unitOfWorkManage.CommitTran(); } //满桶入库 else if (task.TaskType == (int)TaskTypeEnum.Infull) { //修改库存信息 Dt_StockInfo stockInfo = _StockInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); stockInfo.StockStatus = (int)StockStatusEmun.空闲; //修改货位状态 Dt_LocationInfo locationInfo = _LocationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); locationInfo.LocationStatus = (int)LocationStatusEnum.InStock; //生成历史任务 Dt_Task_Hty taskhty = new Dt_Task_Hty(); taskhty.TaskNum = task.TaskNum; taskhty.WMSId = task.WMSId; taskhty.PalletCode = task.PalletCode; taskhty.Roadway = task.Roadway; taskhty.SourceAddress = task.SourceAddress; taskhty.TargetAddress = task.TargetAddress; taskhty.CurrentAddress = task.CurrentAddress; taskhty.NextAddress = task.NextAddress; taskhty.ExceptionMessage = task.ExceptionMessage; taskhty.Grade = task.Grade; taskhty.Remark = task.Remark; taskhty.TaskType = task.TaskType; taskhty.TaskState = task.TaskState; //开始数据库事务 _unitOfWorkManage.BeginTran(); _StockInfoRepository.UpdateData(stockInfo); _LocationInfoRepository.UpdateData(locationInfo); _Task_HtyRepository.AddData(taskhty); BaseDal.DeleteData(task); //提交事务 _unitOfWorkManage.CommitTran(); } //空桶出 else if (task.TaskType == (int)TaskTypeEnum.OutEmpty) { //删除库存信息 //Dt_StockInfo stockInfo = new Dt_StockInfo(); //修改货位状态 Dt_LocationInfo locationInfo = _LocationInfoRepository.QueryFirst(x => x.LocationCode == task.SourceAddress); locationInfo.LocationStatus = (int)LocationStatusEnum.Free; //生成历史任务 Dt_Task_Hty taskhty = new Dt_Task_Hty(); taskhty.TaskNum = task.TaskNum; taskhty.WMSId = task.WMSId; taskhty.PalletCode = task.PalletCode; taskhty.Roadway = task.Roadway; taskhty.SourceAddress = task.SourceAddress; taskhty.TargetAddress = task.TargetAddress; taskhty.CurrentAddress = task.CurrentAddress; taskhty.NextAddress = task.NextAddress; taskhty.ExceptionMessage = task.ExceptionMessage; taskhty.Grade = task.Grade; taskhty.Remark = task.Remark; taskhty.TaskType = task.TaskType; taskhty.TaskState = (int)TaskStatusEnum.Task_Finish; //开始数据库事务 _unitOfWorkManage.BeginTran(); _LocationInfoRepository.UpdateData(locationInfo); _Task_HtyRepository.AddData(taskhty); BaseDal.DeleteData(task); //提交事务 _unitOfWorkManage.CommitTran(); } //满桶出 else if (task.TaskType == (int)TaskTypeEnum.Outfull) { //删除库存信息 Dt_StockInfo stockInfo = _StockInfoRepository.QueryFirst(x => x.LocationCode == task.SourceAddress); List stockInfoDetail = _IStockInfoDetailRepository.QueryData(x => x.MaterielDetailedid == stockInfo.MaterielDetailedid); //生成历史库存信息 Dt_StockInfo_hty stockInfo_Hty = new Dt_StockInfo_hty(); stockInfo_Hty.PalletCode = stockInfo.PalletCode; stockInfo_Hty.LocationCode = stockInfo.LocationCode; stockInfo_Hty.StockStatus = (int)StockStatusEmun.已出库; stockInfo_Hty.MaterielCode1 = stockInfo.MaterielCode1; stockInfo_Hty.MaterielName = stockInfo.MaterielName; stockInfo_Hty.Remark = stockInfo.Remark; stockInfo_Hty.MaterielCode2 = stockInfo.MaterielCode2; stockInfo_Hty.MaterielCode3 = stockInfo.MaterielCode3; stockInfo_Hty.MaterielCode4 = stockInfo.MaterielCode4; stockInfo_Hty.StockType = stockInfo.StockType; stockInfo_Hty.MaterielDetailedid = stockInfo.MaterielDetailedid; List stockInfoDetail_Hty = new List(); int k = stockInfoDetail.Count() - 1; for(int i = 0; i <= k; i++) { stockInfoDetail_Hty[i].MaterielCode = stockInfoDetail[i].MaterielCode; stockInfoDetail_Hty[i].MaterielDetailedid = stockInfoDetail[i].MaterielDetailedid; } //修改货位状态 Dt_LocationInfo locationInfo = _LocationInfoRepository.QueryFirst(x => x.LocationCode == task.SourceAddress); locationInfo.LocationStatus = (int)LocationStatusEnum.Free; //生成历史任务 Dt_Task_Hty taskhty = new Dt_Task_Hty(); taskhty.TaskNum = task.TaskNum; taskhty.WMSId = task.WMSId; taskhty.PalletCode = task.PalletCode; taskhty.Roadway = task.Roadway; taskhty.SourceAddress = task.SourceAddress; taskhty.TargetAddress = task.TargetAddress; taskhty.CurrentAddress = task.CurrentAddress; taskhty.NextAddress = task.NextAddress; taskhty.ExceptionMessage = task.ExceptionMessage; taskhty.Grade = task.Grade; taskhty.Remark = task.Remark; taskhty.TaskType = task.TaskType; taskhty.TaskState = (int)TaskStatusEnum.Task_Finish; //返回货物编号 content.MaterialCode1 = stockInfo.MaterielCode1; content.MaterialCode2 = stockInfo.MaterielCode2; content.MaterialCode3 = stockInfo.MaterielCode3; content.MaterialCode4 = stockInfo.MaterielCode4; //开始数据库事务 _unitOfWorkManage.BeginTran(); _StockInfoRepository.DeleteData(stockInfo); _IStockInfoDetailRepository.DeleteData(stockInfoDetail); _IStockInfohtyRepository.AddData(stockInfo_Hty); _IStockInfoDetailHtyRepository.AddData(stockInfoDetail_Hty); _LocationInfoRepository.UpdateData(locationInfo); _Task_HtyRepository.AddData(taskhty); BaseDal.DeleteData(task); //提交事务 _unitOfWorkManage.CommitTran(); } //直接出库 else if(task.TaskType == (int)TaskTypeEnum.OutDirect) { //删除库存信息 Dt_StockInfo stockInfo = _StockInfoRepository.QueryFirst(x => x.LocationCode == task.SourceAddress); List stockInfoDetail = _IStockInfoDetailRepository.QueryData(x => x.MaterielDetailedid == stockInfo.MaterielDetailedid); //生成历史库存信息 Dt_StockInfo_hty stockInfo_Hty = new Dt_StockInfo_hty(); stockInfo_Hty.PalletCode = stockInfo.PalletCode; stockInfo_Hty.LocationCode = stockInfo.LocationCode; stockInfo_Hty.StockStatus = (int)StockStatusEmun.直接出库; stockInfo_Hty.MaterielCode1 = stockInfo.MaterielCode1; stockInfo_Hty.MaterielName = stockInfo.MaterielName; stockInfo_Hty.Remark = stockInfo.Remark; stockInfo_Hty.MaterielCode2 = stockInfo.MaterielCode2; stockInfo_Hty.MaterielCode3 = stockInfo.MaterielCode3; stockInfo_Hty.MaterielCode4 = stockInfo.MaterielCode4; stockInfo_Hty.StockType = stockInfo.StockType; stockInfo_Hty.MaterielDetailedid = stockInfo.MaterielDetailedid; List stockInfoDetail_Hty = new List(); int k = stockInfoDetail.Count() - 1; for (int i = 0; i <= k; i++) { stockInfoDetail_Hty[i].MaterielCode = stockInfoDetail[i].MaterielCode; stockInfoDetail_Hty[i].MaterielDetailedid = stockInfoDetail[i].MaterielDetailedid; stockInfoDetail_Hty[i].BarcodeType = stockInfoDetail[i].BarcodeType; stockInfoDetail_Hty[i].AuxQty = stockInfoDetail[i].AuxQty; stockInfoDetail_Hty[i].Quantity = stockInfoDetail[i].Quantity; stockInfoDetail_Hty[i].MaxQty = stockInfoDetail[i].MaxQty; stockInfoDetail_Hty[i].BarWeight = stockInfoDetail[i].BarWeight; stockInfoDetail_Hty[i].PackageQty = stockInfoDetail[i].PackageQty; stockInfoDetail_Hty[i].QuantityIn = stockInfoDetail[i].QuantityIn; stockInfoDetail_Hty[i].QuantityOut = stockInfoDetail[i].QuantityOut; stockInfoDetail_Hty[i].Status = stockInfoDetail[i].Status; stockInfoDetail_Hty[i].Materialld = stockInfoDetail[i].Materialld; stockInfoDetail_Hty[i].BatchNum = stockInfoDetail[i].BatchNum; stockInfoDetail_Hty[i].CreateEmpld = stockInfoDetail[i].CreateEmpld; stockInfoDetail_Hty[i].Taskld = stockInfoDetail[i].Taskld; stockInfoDetail_Hty[i].TaskSubld = stockInfoDetail[i].TaskSubld; } //生成历史任务 Dt_Task_Hty taskhty = new Dt_Task_Hty(); taskhty.TaskNum = task.TaskNum; taskhty.WMSId = task.WMSId; taskhty.PalletCode = task.PalletCode; taskhty.Roadway = task.Roadway; taskhty.SourceAddress = task.SourceAddress; taskhty.TargetAddress = task.TargetAddress; taskhty.CurrentAddress = task.CurrentAddress; taskhty.NextAddress = task.NextAddress; taskhty.ExceptionMessage = task.ExceptionMessage; taskhty.Grade = task.Grade; taskhty.Remark = task.Remark; taskhty.TaskType = task.TaskType; taskhty.TaskState = (int)TaskStatusEnum.Task_Finish; //返回货物编号 content.MaterialCode1 = stockInfo.MaterielCode1; content.MaterialCode2 = stockInfo.MaterielCode2; content.MaterialCode3 = stockInfo.MaterielCode3; content.MaterialCode4 = stockInfo.MaterielCode4; //开始数据库事务 _unitOfWorkManage.BeginTran(); _StockInfoRepository.DeleteData(stockInfo); _IStockInfoDetailRepository.DeleteData(stockInfoDetail); _IStockInfohtyRepository.AddData(stockInfo_Hty); _IStockInfoDetailHtyRepository.AddData(stockInfoDetail_Hty); _Task_HtyRepository.AddData(taskhty); BaseDal.DeleteData(task); //提交事务 _unitOfWorkManage.CommitTran(); } return content; } //根据任务号查询任务 public Dt_Task SeletcTaskNum(int TaskNum) { Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == TaskNum); return task; } //WCS同步任务状态 public WebResponseContent WCSTaskState(Dt_Task task) { WebResponseContent content = new WebResponseContent(); Dt_Task tasks = SeletcTaskNum(task.TaskNum); tasks.WMSId = task.WMSId; tasks.PalletCode = task.PalletCode; tasks.Roadway = task.Roadway; tasks.SourceAddress = task.SourceAddress; tasks.TargetAddress = task.TargetAddress; tasks.CurrentAddress = task.CurrentAddress; tasks.NextAddress = task.NextAddress; tasks.ExceptionMessage = task.ExceptionMessage; tasks.Grade = task.Grade; tasks.Remark = task.Remark; tasks.TaskType = task.TaskType; tasks.TaskState = task.TaskState; BaseDal.UpdateData(tasks); return content; } //空桶出库任务 public WebResponseContent addOutEmptyTask(string location) { WebResponseContent content = new WebResponseContent(); Dt_Task task = new Dt_Task(); //出库分配物料 Dt_LocationInfo locations = _LocationInfoService.AllotStock(1); locations.LocationStatus = (int)LocationStatusEnum.Lock; task.SourceAddress = locations.LocationCode; task.TargetAddress = location; task.Roadway = "SC01"; task.Grade = 1; task.TaskType = (int)TaskTypeEnum.OutEmpty; task.TaskState = (int)TaskStatusEnum.OutNew; task.TaskNum = DateTime.Now.ToString("mmss").ObjToInt(); //开始数据库事务 _unitOfWorkManage.BeginTran(); _LocationInfoRepository.UpdateData(locations); BaseDal.AddData(task); //发送给WCS string address = AppSettings.Get("WCS"); if (!string.IsNullOrEmpty(address)) { HttpHelper.Post($"{address}/api/Task/WMSaddTask/", task.Serialize()); } //提交事务 _unitOfWorkManage.CommitTran(); return content; } //根据数量和种类下发满桶出库任务 public WebResponseContent ArtificialTask(int Num, int Type) { WebResponseContent content = new WebResponseContent(); List tasks = new List(); List LocationInfo = new List(); List StockInfo = new List(); if (Num > 0 && Type > 0 && kk == true) { Dt_Outstockinfo outstockinfo = _OutstockinfoRepository.QueryFirst(x => x.Id == 1); //满 if (outstockinfo.BigOrLittle == 1) { //获取并锁定物料 StockInfo = _IStockService.PriorityBig(Num, Type); } //残 else { //获取并锁定物料 StockInfo = _IStockService.PriorityLittle(Num, Type); } //创建任务 if (StockInfo != null) { //获取并锁定货位 LocationInfo = _ILocationInfoService.StockLockLocation(StockInfo); //创建任务 tasks = StocksAddTasks(StockInfo); } else { return WebResponseContent.Instance.Error($"物料不足"); } //开始数据库事务 _unitOfWorkManage.BeginTran(); _LocationInfoRepository.UpdateData(LocationInfo); _StockInfoRepository.UpdateData(StockInfo); BaseDal.AddData(tasks); //发送给WCS string address = AppSettings.Get("WCS"); if (!string.IsNullOrEmpty(address)) { HttpHelper.Post($"{address}/api/Task/WMSaddListTask/", tasks.Serialize()); } //提交事务 _unitOfWorkManage.CommitTran(); } else { LogLock.OutLogAOP("接口日志", new string[] { "下发数量、种类或信号异常"}); } return content; } //根据多条物料创建多条出库任务 public List StocksAddTasks(List StockInfo) { List tasks = new List(); int k = StockInfo.Count() - 1; string StationName = "满桶出"; string StationNames = SelectStationManger(StationName); for (int i = 0; i <= k; i++) { Dt_Task task = new Dt_Task(); task.SourceAddress = StockInfo[i].LocationCode; task.TargetAddress = StationNames; task.Roadway = "SC01"; task.Grade = 1; task.TaskType = (int)TaskTypeEnum.Outfull; task.TaskState = (int)TaskStatusEnum.OutNew; task.TaskNum = DateTime.Now.ToString("mmss").ObjToInt() + i; tasks.Add(task); } return tasks; } //根据站台名称查询站台地址 public string SelectStationManger(string StationName) { string address = AppSettings.Get("WCS"); string StationNames = ""; if (!string.IsNullOrEmpty(address)) { StationNames = HttpHelper.Post($"{address}/api/StationManger/SelectStationManger/?StationName={StationName}", ""); } return StationNames; } //手动立即完成任务 public WebResponseContent Complete(int taskid) { WebResponseContent content = new WebResponseContent(); Dt_Task task = BaseDal.QueryFirst(x => x.Id == taskid); //生成历史任务 Dt_Task_Hty taskhty = new Dt_Task_Hty(); taskhty.TaskNum = task.TaskNum; taskhty.WMSId = task.WMSId; taskhty.PalletCode = task.PalletCode; taskhty.Roadway = task.Roadway; taskhty.SourceAddress = task.SourceAddress; taskhty.TargetAddress = task.TargetAddress; taskhty.CurrentAddress = task.CurrentAddress; taskhty.NextAddress = task.NextAddress; taskhty.ExceptionMessage = task.ExceptionMessage; taskhty.Grade = task.Grade; taskhty.Remark = task.Remark; taskhty.TaskType = task.TaskType; taskhty.TaskState = (int)TaskStatusEnum.Task_Finish; //空桶入 if (task.TaskType == (int)TaskTypeEnum.InEmpty) { Dt_LocationInfo locationInfo = _LocationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); locationInfo.LocationStatus = (int)LocationStatusEnum.EmptyBarrel; //开始数据库事务 _unitOfWorkManage.BeginTran(); _LocationInfoRepository.UpdateData(locationInfo); BaseDal.DeleteData(task); WCSTaskDelete(task.TaskNum); _Task_HtyRepository.AddData(taskhty); //提交事务 _unitOfWorkManage.CommitTran(); } //空桶出 else if (task.TaskType == (int)TaskTypeEnum.OutEmpty) { Dt_LocationInfo locationInfo = _LocationInfoRepository.QueryFirst(x => x.LocationCode == task.SourceAddress); locationInfo.LocationStatus = (int)LocationStatusEnum.Free; //开始数据库事务 _unitOfWorkManage.BeginTran(); _LocationInfoRepository.UpdateData(locationInfo); BaseDal.DeleteData(task); WCSTaskDelete(task.TaskNum); _Task_HtyRepository.AddData(taskhty); //提交事务 _unitOfWorkManage.CommitTran(); } //满桶入 else if (task.TaskType == (int)TaskTypeEnum.Infull) { Dt_LocationInfo locationInfo = _LocationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); locationInfo.LocationStatus = (int)LocationStatusEnum.InStock; Dt_StockInfo stockInfo = _StockInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); stockInfo.StockStatus = (int)StockStatusEmun.空闲; //开始数据库事务 _unitOfWorkManage.BeginTran(); _LocationInfoRepository.UpdateData(locationInfo); _StockInfoRepository.UpdateData(stockInfo); BaseDal.DeleteData(task); WCSTaskDelete(task.TaskNum); _Task_HtyRepository.AddData(taskhty); //提交事务 _unitOfWorkManage.CommitTran(); } //满桶出 else if (task.TaskType == (int)TaskTypeEnum.Outfull) { Dt_LocationInfo locationInfo = _LocationInfoRepository.QueryFirst(x => x.LocationCode == task.SourceAddress); locationInfo.LocationStatus = (int)LocationStatusEnum.Free; Dt_StockInfo stockInfo = _StockInfoRepository.QueryFirst(x => x.LocationCode == task.SourceAddress); //开始数据库事务 _unitOfWorkManage.BeginTran(); _LocationInfoRepository.UpdateData(locationInfo); _StockInfoRepository.DeleteData(stockInfo); BaseDal.DeleteData(task); WCSTaskDelete(task.TaskNum); _Task_HtyRepository.AddData(taskhty); //提交事务 _unitOfWorkManage.CommitTran(); } return content; } //WCS任务删除 public WebResponseContent WCSTaskDelete(int tasknum) { WebResponseContent content = new WebResponseContent(); if (tasknum == 0) { WebResponseContent.Instance.Error($"任务号不存在"); } string address = AppSettings.Get("WCS"); if (!string.IsNullOrEmpty(address)) { HttpHelper.Post($"{address}/api/Task/WCSTaskDelete/?tasknum={tasknum}", ""); } return content; } //大屏电视查询任务 public List selectTask() { List task = new List(); task = _Task_HtyRepository.QueryData().OrderByDescending(t => t.CreateDate).ToList(); return task; } //WCS满桶出库信号 public WebResponseContent WCSSignal(int k) { WebResponseContent content=new WebResponseContent(); //可以出 if (k == 1) { kk = true; } //不可以出 else { kk = false; } return content; } } }