diff --git a/src/Khd.Core.Api/Controllers/RecieveRcsController.cs b/src/Khd.Core.Api/Controllers/RecieveRcsController.cs index e9f4ffb..3d2ead5 100644 --- a/src/Khd.Core.Api/Controllers/RecieveRcsController.cs +++ b/src/Khd.Core.Api/Controllers/RecieveRcsController.cs @@ -3,6 +3,7 @@ using Khd.Core.Domain.Dto.webapi; using Masuit.Tools; using Masuit.Tools.Logging; using Microsoft.AspNetCore.Mvc; +using System.Threading; namespace Khd.Core.Api.Controllers { @@ -25,15 +26,49 @@ namespace Khd.Core.Api.Controllers public ReponseagvCallbackDto agvCallback(agvCallbackDto agvCallbackDto) { LogManager.Info($"RecieveRcsController接口信息:{agvCallbackDto.ToJsonString()}"); + if (agvCallbackDto.method == "start") + { + Thread.Sleep(1000); + } return _application.AgvCallback(agvCallbackDto); } - [HttpPost("MesToAgvComplete")] + /// + /// 背负式Agv通知任务完成 + /// + /// + /// + [HttpPost("agvComplete")] public AgvCompeletedResponse MesToAgvComplete(AgvCompeleted agvCompeletedRequest) { LogManager.Info($"RecieveRcsController接口信息:{agvCompeletedRequest.ToJsonString()}"); return _application.MesToAgvComplete(agvCompeletedRequest); } + + /// + /// 原材料入口任务继续通知 + /// + /// + /// + [HttpPost("taskContinue")] + public AgvCompeletedResponse TaskContinue(TaskContinue taskContinue) + { + LogManager.Info($"TaskContinue 接口收到消息: {taskContinue}"); + return _application.TaskContinue(taskContinue); + } + + /// + /// 柜体拆分验收区通知返库接口 + /// + /// + /// + [HttpPost("taskReturn")] + public AgvCompeletedResponse TaskReturn(TaskReturn taskReturn) + { + LogManager.Info($"TaskReturn 接口收到消息: {taskReturn}"); + return _application.TaskReturn(taskReturn); + } + } } \ No newline at end of file diff --git a/src/Khd.Core.Application/Interface/IWcsTaskApplication.cs b/src/Khd.Core.Application/Interface/IWcsTaskApplication.cs index f4e1c93..506e674 100644 --- a/src/Khd.Core.Application/Interface/IWcsTaskApplication.cs +++ b/src/Khd.Core.Application/Interface/IWcsTaskApplication.cs @@ -24,5 +24,10 @@ namespace Khd.Core.Application.Interface AgvCompeletedResponse MesToAgvComplete(AgvCompeleted agvCompeletedRequest); + + + AgvCompeletedResponse TaskContinue(TaskContinue taskContinue); + + AgvCompeletedResponse TaskReturn(TaskReturn taskReturn); } } \ No newline at end of file diff --git a/src/Khd.Core.Application/WcsTaskApplication.cs b/src/Khd.Core.Application/WcsTaskApplication.cs index bf9c2b6..50473e8 100644 --- a/src/Khd.Core.Application/WcsTaskApplication.cs +++ b/src/Khd.Core.Application/WcsTaskApplication.cs @@ -2,6 +2,7 @@ using Khd.Core.Domain.Dto.webapi; using Khd.Core.Domain.Models; using Khd.Core.EntityFramework; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using System; using System.Linq; @@ -47,18 +48,19 @@ namespace Khd.Core.Application ReponseagvCallbackDto reponseagvCallbackDto = new ReponseagvCallbackDto(); try { + _dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); var wcscmd = _dbContext.WcsCmd - .Where(t=>t.taskCode==agvCallbackDto.taskCode) + .Where(t => t.taskCode == agvCallbackDto.taskCode) .FirstOrDefault(); if (wcscmd != null) { WcsTask wcsTask = _dbContext.WcsTask.FirstOrDefault(t => t.objid == wcscmd.taskId); - if(wcsTask != null) + if (wcsTask != null) { //start 开始 end结束 continue继续 //待取货 if (agvCallbackDto.method.ToLower() == "start") - { + { wcscmd.cmdStatus = 2; wcscmd.sendFlag = 1; wcsTask.taskStatus = 2; @@ -87,7 +89,7 @@ namespace Khd.Core.Application { wcscmd.cmdStatus = 5; wcscmd.sendFlag = 1; - wcsTask.taskStatus= 5; + wcsTask.taskStatus = 5; _dbContext.WcsCmd.Update(wcscmd); _dbContext.Update(wcsTask); _dbContext.SaveChanges(); @@ -129,13 +131,19 @@ namespace Khd.Core.Application return ""; } + /// + /// 背负式Agv通知完成 + /// + /// + /// public AgvCompeletedResponse MesToAgvComplete(AgvCompeleted agvCompeletedRequest) { AgvCompeletedResponse agvCompeletedResponse = new AgvCompeletedResponse(); try { - string stationId = agvCompeletedRequest.stationId; - BaseEquip baseEquip = _dbContext.BaseEquip.FirstOrDefault(t=>t.equipNo==stationId); + _dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); + string stationId = agvCompeletedRequest.stationNo; + BaseEquip baseEquip = _dbContext.BaseEquip.FirstOrDefault(t => t.equipNo == stationId); if (baseEquip != null) { var wcsCmd = _dbContext.WcsCmd.Where(t => t.nextPointId == baseEquip.objid).FirstOrDefault(); @@ -172,5 +180,78 @@ namespace Khd.Core.Application } return agvCompeletedResponse; } + + /// + /// 4楼到5楼原材料入口继续 + /// + /// + /// + public AgvCompeletedResponse TaskContinue(TaskContinue taskContinue) + { + AgvCompeletedResponse compeletedResponse = new AgvCompeletedResponse(); + try + { + _dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); + WcsTask wcsTask = _dbContext.WcsTask + .Where(t => t.materialId == taskContinue.materialId) + .Where(t => t.taskType == 47) + .FirstOrDefault(); + if (wcsTask != null) + { + wcsTask.useFlag = 1; + _dbContext.WcsTask.Update(wcsTask); + _dbContext.SaveChanges(); + compeletedResponse.code = "0"; + compeletedResponse.message = "成功"; + } + else + { + compeletedResponse.code = "1"; + compeletedResponse.message = "未找到当前任务"; + } + } + catch (Exception ex) + { + compeletedResponse.code = "1"; + compeletedResponse.message = ex.Message; + } + return compeletedResponse; + } + /// + /// 柜体拆分区通知返库 + /// + /// + /// + public AgvCompeletedResponse TaskReturn(TaskReturn taskReturn) + { + AgvCompeletedResponse compeletedResponse = new AgvCompeletedResponse(); + try + { + _dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); + WcsTask wcsTask = _dbContext.WcsTask + .Where(t => t.taskType == 28) + .Where(t => t.materialId == taskReturn.materialId) + .FirstOrDefault(); + if (wcsTask != null) + { + wcsTask.useFlag = 1; + _dbContext.WcsTask.Update(wcsTask); + _dbContext.SaveChanges(); + compeletedResponse.code = "0"; + compeletedResponse.message = "成功"; + } + else + { + compeletedResponse.code = "1"; + compeletedResponse.message = "未找到当前任务"; + } + } + catch (Exception ex) + { + compeletedResponse.code = "1"; + compeletedResponse.message = ex.Message; + } + return compeletedResponse; + } } } \ No newline at end of file diff --git a/src/Khd.Core.Domain/Dto/webapi/AgvCompeleted.cs b/src/Khd.Core.Domain/Dto/webapi/AgvCompeleted.cs index e964d3f..20309c1 100644 --- a/src/Khd.Core.Domain/Dto/webapi/AgvCompeleted.cs +++ b/src/Khd.Core.Domain/Dto/webapi/AgvCompeleted.cs @@ -9,10 +9,21 @@ namespace Khd.Core.Domain.Dto.webapi public class AgvCompeleted { public string stationId { get; set; } + public string stationNo { get; set; } public string stationState { get; set; } public string method { get; set; } } + public class TaskContinue + { + public long? materialId { get; set; } + } + + public class TaskReturn + { + public long? materialId { get; set; } + } + public class AgvCompeletedResponse { public string code { get; set; } diff --git a/src/Khd.Core.Domain/Dto/webapi/AgvStatusDto.cs b/src/Khd.Core.Domain/Dto/webapi/AgvStatusDto.cs new file mode 100644 index 0000000..b328bb2 --- /dev/null +++ b/src/Khd.Core.Domain/Dto/webapi/AgvStatusDto.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Khd.Core.Domain.Dto.webapi +{ + public class AgvStatusDto + { + public string code { get; set; } + public List data { get; set; } + } + + public class cardStatus + { + public string battery { get; set; } + public string exclType { get; set; } + public string mapCode { get; set; } + public string online { get; set; } + public string[] path { get; set; } + public string podCode { get; set; } + public string podDir { get; set; } + public string posX { get; set; } + public string posY { get; set; } + public string robotCode { get; set; } + public string robotDir { get; set; } + public string robotIp { get; set; } + public string speed { get; set; } + public string status { get; set; } + public string stop { get; set; } + public string timestamp { get; set; } + } +} \ No newline at end of file diff --git a/src/Khd.Core.Domain/Models/BaseDictionary.cs b/src/Khd.Core.Domain/Models/BaseDictionary.cs index edd6e11..6ce9a9a 100644 --- a/src/Khd.Core.Domain/Models/BaseDictionary.cs +++ b/src/Khd.Core.Domain/Models/BaseDictionary.cs @@ -91,20 +91,20 @@ namespace Khd.Core.Domain.Models /// /// 备用字段1 /// - [Column("ud1")] - public string ud1 { get; set; } + [Column("agv_type")] + public string agvType { get; set; } /// /// 备用字段2 /// - [Column("ud2")] - public string ud2 { get; set; } + [Column("agv_task_type")] + public string agvTaskType { get; set; } /// /// 备用字段3 /// - [Column("ud3")] - public string ud3 { get; set; } + [Column("to_plc")] + public string ToPlc { get; set; } /// /// 备注 diff --git a/src/Khd.Core.Domain/Models/BaseEquip.cs b/src/Khd.Core.Domain/Models/BaseEquip.cs index 0445bdb..1d9f397 100644 --- a/src/Khd.Core.Domain/Models/BaseEquip.cs +++ b/src/Khd.Core.Domain/Models/BaseEquip.cs @@ -17,6 +17,9 @@ namespace Khd.Core.Domain.Models [Table("wcs_base_equip")] public class BaseEquip { + [Column("empty_count")] + public int? emptyCount; + [Column("agv_position_code")] public string agvPositionCode { get; set; } @@ -125,6 +128,7 @@ namespace Khd.Core.Domain.Models /// [Column("remark")] public string remark { get; set; } + } } diff --git a/src/Khd.Core.Domain/Models/BasePlc.cs b/src/Khd.Core.Domain/Models/BasePlc.cs new file mode 100644 index 0000000..f149b20 --- /dev/null +++ b/src/Khd.Core.Domain/Models/BasePlc.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace Khd.Core.Domain.Models +{ + [Table("base_plcpoint")] + public class BasePlc + { + [Column("id")] + public int Id { get; set; } + + [Column("name")] + public string Name { get; set; } + + [Column("station")] + public string Station { get; set; } + + [Column("address")] + public string Address { get; set; } + + [Column("value")] + public string Value { get; set; } + + [Column("type")] + public string type { get; set; } + } +} diff --git a/src/Khd.Core.Domain/Models/WcsTask.cs b/src/Khd.Core.Domain/Models/WcsTask.cs index 57c6997..a18b735 100644 --- a/src/Khd.Core.Domain/Models/WcsTask.cs +++ b/src/Khd.Core.Domain/Models/WcsTask.cs @@ -56,6 +56,21 @@ namespace Khd.Core.Domain.Models /// /// 任务类型,字典表 + /// 27提升机输送线对接位-验收拆分区 + /// 28验收拆分区-原材料周转区 + /// 29回转输送线回库口-辅料库货架 + /// 30辅料库货架-回转输送线出库口 + /// 31回转输送线回库口-辅料库货架 + /// 32物料分拣位-装配区领料工位 + /// 33原材料周转区-背板安装区 + /// 34背板安装区-半成品周转区 + /// 35半成品周转区-检测台 + /// 37检验台-成品区 + /// 38成品区-提升机输送线对接点 + /// 46原材料-柜体拆分区 + /// 47接驳位-原材料周转区 + /// + /// /// [Column("task_type")] public int? taskType { get; set; } diff --git a/src/Khd.Core.Domain/Models/WcsTaskLog.cs b/src/Khd.Core.Domain/Models/WcsTaskLog.cs index ded2cc4..ed6c08f 100644 --- a/src/Khd.Core.Domain/Models/WcsTaskLog.cs +++ b/src/Khd.Core.Domain/Models/WcsTaskLog.cs @@ -17,17 +17,13 @@ namespace Khd.Core.Domain.Models [Table("wcs_task_log")] public class WcsTaskLog { + [Column("from_floor_no")] + public int? fromFloorNo { get; set; } [Key] [Column("objid")] public long objid { get; set; } - /// - /// 任务ID - /// - [Column("taskid")] - public long? taskid { get; set; } - /// /// wcs_warehouse_order 主键id /// @@ -60,6 +56,21 @@ namespace Khd.Core.Domain.Models /// /// 任务类型,字典表 + /// 27提升机输送线对接位-验收拆分区 + /// 28验收拆分区-原材料周转区 + /// 29回转输送线回库口-辅料库货架 + /// 30辅料库货架-回转输送线出库口 + /// 31回转输送线回库口-辅料库货架 + /// 32物料分拣位-装配区领料工位 + /// 33原材料周转区-背板安装区 + /// 34背板安装区-半成品周转区 + /// 35半成品周转区-检测台 + /// 37检验台-成品区 + /// 38成品区-提升机输送线对接点 + /// 46原材料-柜体拆分区 + /// 47接驳位-原材料周转区 + /// + /// /// [Column("task_type")] public int? taskType { get; set; } @@ -80,7 +91,7 @@ namespace Khd.Core.Domain.Models /// 物料号 /// [Column("material_no")] - public int? materialNo { get; set; } + public string? materialNo { get; set; } /// /// 数量 @@ -112,11 +123,14 @@ namespace Khd.Core.Domain.Models [Column("curr_point_id")] public long? currPointId { get; set; } + /// + /// 下一点位id + /// [Column("next_point_id")] public long? nextPointId { get; set; } /// - /// 结束点编号 + /// 下一点位编号 /// [Column("next_point_no")] public string nextPointNo { get; set; } @@ -131,7 +145,7 @@ namespace Khd.Core.Domain.Models /// 结束点id /// [Column("end_point_id")] - public Guid endPointId { get; set; } + public long? endPointId { get; set; } /// /// 所属楼层 @@ -192,6 +206,9 @@ namespace Khd.Core.Domain.Models /// [Column("remark")] public string remark { get; set; } + + [Column("is_delete")] + public int? IsDelete { get; set; } } } diff --git a/src/Khd.Core.Domain/Models/WmsBaseLocation.cs b/src/Khd.Core.Domain/Models/WmsBaseLocation.cs index d4261a2..5f8587c 100644 --- a/src/Khd.Core.Domain/Models/WmsBaseLocation.cs +++ b/src/Khd.Core.Domain/Models/WmsBaseLocation.cs @@ -40,7 +40,7 @@ namespace Khd.Core.Domain.Models public string agvPositionCode { get; set; } [Column("warehouse_floor")] - public int warehouseFloor { get; set; } + public int? warehouseFloor { get; set; } /// /// 库位编码 @@ -221,6 +221,9 @@ namespace Khd.Core.Domain.Models /// [Column("height")] public decimal? height { get; set; } + + [Column("container_status")] + public string ContainerStatus { get; set; } } } diff --git a/src/Khd.Core.Domain/Models/WmsBaseWarehouse.cs b/src/Khd.Core.Domain/Models/WmsBaseWarehouse.cs index ddc5d27..cbab7bb 100644 --- a/src/Khd.Core.Domain/Models/WmsBaseWarehouse.cs +++ b/src/Khd.Core.Domain/Models/WmsBaseWarehouse.cs @@ -106,11 +106,11 @@ namespace Khd.Core.Domain.Models [Column("active_flag")] public string activeFlag { get; set; } - /// - /// 审核标识 (1是,0否) - /// - [Column("audit_flag")] - public string auditFlag { get; set; } + ///// + ///// 审核标识 (1是,0否) + ///// + //[Column("audit_flag")] + //public string auditFlag { get; set; } /// /// 返库标识(1是,0否) diff --git a/src/Khd.Core.Domain/Models/WmsProductInstock.cs b/src/Khd.Core.Domain/Models/WmsProductInstock.cs index d8f4c93..9ef5158 100644 --- a/src/Khd.Core.Domain/Models/WmsProductInstock.cs +++ b/src/Khd.Core.Domain/Models/WmsProductInstock.cs @@ -22,6 +22,11 @@ namespace Khd.Core.Domain.Models [Column("product_instock_id")] public long productInstockId { get; set; } + [Column("sale_order_id")] + public long? SaleOrderId { get; set; } + + [Column("saleorder_code")] + public string saleorderCode { get; set; } /// /// 任务编号 /// @@ -33,7 +38,11 @@ namespace Khd.Core.Domain.Models /// [Column("warehouse_id")] public long warehouseId { get; set; } - + /// + /// 仓库ID + /// + [Column("warehouse_floor")] + public int? warehouseFloor { get; set; } /// /// 库位编码 /// diff --git a/src/Khd.Core.Domain/Models/WmsProductOutstock.cs b/src/Khd.Core.Domain/Models/WmsProductOutstock.cs index 655a63c..079221b 100644 --- a/src/Khd.Core.Domain/Models/WmsProductOutstock.cs +++ b/src/Khd.Core.Domain/Models/WmsProductOutstock.cs @@ -110,7 +110,7 @@ namespace Khd.Core.Domain.Models /// 出库目的地 /// [Column("end_station_code")] - public long? endStationCode { get; set; } + public string endStationCode { get; set; } /// /// 申请数量 diff --git a/src/Khd.Core.Domain/Models/WmsProductStock.cs b/src/Khd.Core.Domain/Models/WmsProductStock.cs index f23840a..379a055 100644 --- a/src/Khd.Core.Domain/Models/WmsProductStock.cs +++ b/src/Khd.Core.Domain/Models/WmsProductStock.cs @@ -68,7 +68,7 @@ namespace Khd.Core.Domain.Models /// 产品ID,关联物料信息的物料ID /// [Column("product_id")] - public long productId { get; set; } + public long? productId { get; set; } /// /// 计划编号,关联pd_base_plan_info的plan_code diff --git a/src/Khd.Core.Domain/Models/WmsRawOutstock.cs b/src/Khd.Core.Domain/Models/WmsRawOutstock.cs index cc0873c..57648f3 100644 --- a/src/Khd.Core.Domain/Models/WmsRawOutstock.cs +++ b/src/Khd.Core.Domain/Models/WmsRawOutstock.cs @@ -90,7 +90,7 @@ namespace Khd.Core.Domain.Models /// 已出库数量 /// [Column("real_outstock_amount")] - public decimal realOutstockAmount { get; set; } + public decimal? realOutstockAmount { get; set; } /// /// 出库目的地 diff --git a/src/Khd.Core.Domain/Models/WmsRawReturn.cs b/src/Khd.Core.Domain/Models/WmsRawReturn.cs new file mode 100644 index 0000000..5fcbd4b --- /dev/null +++ b/src/Khd.Core.Domain/Models/WmsRawReturn.cs @@ -0,0 +1,168 @@ + +//----------------------------------------------------------------------- +// +// * Copyright (C) 2021 KEHAIDASOFT All Rights Reserved +// * version : 4.0.30319.42000 +// * author : khd by t4-2 +// +//----------------------------------------------------------------------- + +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Khd.Core.Domain.Models +{ + + [Table("wms_raw_return")] + public class WmsRawReturn + { + + [Key] + [Column("raw_return_id")] + public long rawReturnId { get; set; } + + /// + /// 任务编号 + /// + [Column("task_code")] + public string taskCode { get; set; } + + /// + /// 仓库ID;领料时需要保存 + /// + [Column("warehouse_id")] + public long? warehouseId { get; set; } + + /// + /// 库位编码 + /// + [Column("location_code")] + public string locationCode { get; set; } + + /// + /// 计划编号,关联mes_product_plan_info的plan_code + /// + [Column("plan_code")] + public string planCode { get; set; } + + /// + /// 计划明细编号,关联mes_product_plan_detail的plan_detail_code + /// + [Column("plan_detail_code")] + public string planDetailCode { get; set; } + + + [Column("material_id")] + public long? materialId { get; set; } + + /// + /// 物料批次 + /// + [Column("material_batch")] + public string materialBatch { get; set; } + + /// + /// 计划出库数量 + /// + [Column("plan_amount")] + public decimal planAmount { get; set; } + + /// + /// 已出库数量 + /// + [Column("return_amount")] + public decimal returnAmount { get; set; } + + /// + /// 出库目的地 + /// + [Column("end_station_code")] + public string endStationCode { get; set; } + + /// + /// 操作类型(0自动,1人工,2强制,3调度) + /// + [Column("operation_type")] + public string operationType { get; set; } + + /// + /// 任务类型(1生产领料,2拆分出库,3组装出库,9其他) + /// + [Column("task_type")] + public string taskType { get; set; } + + /// + /// 申请原因 + /// + [Column("apply_reason")] + public string applyReason { get; set; } + + /// + /// 审核原因 + /// + [Column("audit_reason")] + public string auditReason { get; set; } + + /// + /// 审核状态(0待审核,1审核通过,2审核未通过) + /// + [Column("audit_status")] + public string auditStatus { get; set; } + + /// + /// 执行状态(0待执行,1执行中,2执行完成) + /// + [Column("execute_status")] + public string executeStatus { get; set; } + + /// + /// 申请人 + /// + [Column("apply_by")] + public string applyBy { get; set; } + + /// + /// 申请时间 + /// + [Column("apply_date")] + public DateTime? applyDate { get; set; } + + /// + /// 审核人 + /// + [Column("audit_by")] + public string auditBy { get; set; } + + /// + /// 审核时间 + /// + [Column("audit_date")] + public DateTime? auditDate { get; set; } + + /// + /// 最后更新人 + /// + [Column("update_by")] + public string updateBy { get; set; } + + /// + /// 最后更新时间 + /// + [Column("update_date")] + public DateTime? updateDate { get; set; } + + /// + /// 执行开始时间 + /// + [Column("begin_time")] + public DateTime? beginTime { get; set; } + + /// + /// 执行结束时间 + /// + [Column("end_time")] + public DateTime? endTime { get; set; } + } +} + diff --git a/src/Khd.Core.Domain/Models/WmsRawStock.cs b/src/Khd.Core.Domain/Models/WmsRawStock.cs index 684d925..5ea7b32 100644 --- a/src/Khd.Core.Domain/Models/WmsRawStock.cs +++ b/src/Khd.Core.Domain/Models/WmsRawStock.cs @@ -50,7 +50,7 @@ namespace Khd.Core.Domain.Models /// 物料ID /// [Column("material_id")] - public long materialId { get; set; } + public long? materialId { get; set; } /// /// 入库批次号 @@ -92,19 +92,19 @@ namespace Khd.Core.Domain.Models /// 总数量;库位存放的总数量 /// [Column("total_amount")] - public decimal totalAmount { get; set; } + public decimal? totalAmount { get; set; } /// /// 冻结数量;手动冻结的,暂时可不用 /// [Column("frozen_amount")] - public decimal frozenAmount { get; set; } + public decimal? frozenAmount { get; set; } /// /// 占用数量;申请时占用的数量,在出库时要减去出库数量,并且总数量要同步更新; /// [Column("occupy_amount")] - public decimal occupyAmount { get; set; } + public decimal? occupyAmount { get; set; } /// /// 供应商ID diff --git a/src/Khd.Core.EntityFramework/DefaultDbContext.cs b/src/Khd.Core.EntityFramework/DefaultDbContext.cs index 15e754d..735daca 100644 --- a/src/Khd.Core.EntityFramework/DefaultDbContext.cs +++ b/src/Khd.Core.EntityFramework/DefaultDbContext.cs @@ -1,4 +1,5 @@ -using Khd.Core.Domain.Models; +using Khd.Core.Domain.Dto.wcs; +using Khd.Core.Domain.Models; using Microsoft.EntityFrameworkCore; namespace Khd.Core.EntityFramework @@ -8,12 +9,16 @@ namespace Khd.Core.EntityFramework public DefaultDbContext(DbContextOptions options) : base(options) { } + public DbSet WmsRawReturn { get; set; } + public DbSet BaseDictionary { get; set; } public DbSet BaseEquip { get; set; } public DbSet BasePlcpoint { get; set; } + public DbSet BasePlc { get; set; } + public DbSet MesBasePalletInfo { get; set; } public DbSet WcsCmd { get; set; } diff --git a/src/Khd.Core.Library/Khd.Core.Library.csproj b/src/Khd.Core.Library/Khd.Core.Library.csproj index 46987b6..118e91b 100644 --- a/src/Khd.Core.Library/Khd.Core.Library.csproj +++ b/src/Khd.Core.Library/Khd.Core.Library.csproj @@ -5,6 +5,7 @@ + diff --git a/src/Khd.Core.Library/Mapper/CoreMapper.cs b/src/Khd.Core.Library/Mapper/CoreMapper.cs new file mode 100644 index 0000000..ec36e1f --- /dev/null +++ b/src/Khd.Core.Library/Mapper/CoreMapper.cs @@ -0,0 +1,42 @@ +using Mapster; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Khd.Core.Library.Mapper +{ + public class CoreMapper + { + /// + /// Map source object to destination object + /// + /// The type of the destination. + /// The source object. + /// The destination object. + /// Thrown when source is null. + public static TDestination Map(object source) + { + if(source == null) + throw new ArgumentNullException("Map Error : source is null"); + TypeAdapterConfig config = new TypeAdapterConfig(); + + config.NewConfig().MapWith(dest => string.IsNullOrEmpty(dest.Trim()) ? Guid.Empty : new Guid(dest)); + config.NewConfig().MapWith(dest => string.IsNullOrEmpty(dest.Trim()) ? null : new Guid(dest)); + config.NewConfig().MapWith(dest => dest.ToString()); + + config.NewConfig().MapWith(dest => string.IsNullOrEmpty(dest) ? DateTime.Now : Convert.ToDateTime(dest)); + config.NewConfig().MapWith(dest => string.IsNullOrEmpty(dest) ? null : Convert.ToDateTime(dest)); + config.NewConfig().MapWith(dest => dest.ToString()); + // var c = source.Adapt(destination, config2); + config.NewConfig().MapWith(dest => dest.Trim()); + // config.ForType().Map(member: guid => guid, source: @string => string.IsNullOrEmpty(@string) ? Guid.Empty : new Guid(@string)); + // config.ForType().Map(member: @string => @string, source: guid => ("wode")); + config.Default.IgnoreNullValues(true);//忽略null + config.Default.NameMatchingStrategy(NameMatchingStrategy.IgnoreCase);//忽略大小写 + var destination = source.Adapt(config); + return destination; + } + } +} diff --git a/src/Khd.Core.Plc/S7/PLCHelpers.cs b/src/Khd.Core.Plc/S7/PLCHelpers.cs index 906161b..0b224b8 100644 --- a/src/Khd.Core.Plc/S7/PLCHelpers.cs +++ b/src/Khd.Core.Plc/S7/PLCHelpers.cs @@ -260,5 +260,6 @@ namespace Khd.Core.Plc.S7 return package.ToArray(); } + } } diff --git a/src/Khd.Core.Plc/S7/PlcSynchronous.cs b/src/Khd.Core.Plc/S7/PlcSynchronous.cs index 774dbcf..949850d 100644 --- a/src/Khd.Core.Plc/S7/PlcSynchronous.cs +++ b/src/Khd.Core.Plc/S7/PlcSynchronous.cs @@ -79,7 +79,7 @@ namespace Khd.Core.Plc.S7 return Read(adr.DataType, adr.DbNumber, adr.StartByte, adr.VarType, 1, (byte)adr.BitNumber); } - public object? Read(string variable,VarType varType) + public object? Read(string variable, VarType varType) { var adr = new PLCAddress(variable); return Read(adr.DataType, adr.DbNumber, adr.StartByte, varType, 1, (byte)adr.BitNumber); @@ -316,7 +316,7 @@ namespace Khd.Core.Plc.S7 } catch (Exception exc) { - throw new PlcException(ErrorCode.ReadData, exc); + throw new PlcException(ErrorCode.ReadData, this.IP, exc); } } @@ -348,7 +348,7 @@ namespace Khd.Core.Plc.S7 } catch (Exception exc) { - throw new PlcException(ErrorCode.WriteData, exc); + throw new PlcException(ErrorCode.WriteData, this.IP, exc); } } diff --git a/src/Khd.Core.Plc/StaticPlcHelper.cs b/src/Khd.Core.Plc/StaticPlcHelper.cs index f65e10c..eb75c16 100644 --- a/src/Khd.Core.Plc/StaticPlcHelper.cs +++ b/src/Khd.Core.Plc/StaticPlcHelper.cs @@ -72,6 +72,10 @@ namespace Khd.Core.Plc { return Convert.ToByte(value); } + if (len == "8") + { + return Convert.ToString(value); + } return 0; } } diff --git a/src/Khd.Core.Wcs/Global/HttpHelper.cs b/src/Khd.Core.Wcs/Global/HttpHelper.cs index a137e1f..7a1bfd8 100644 --- a/src/Khd.Core.Wcs/Global/HttpHelper.cs +++ b/src/Khd.Core.Wcs/Global/HttpHelper.cs @@ -5,9 +5,8 @@ namespace Khd.Core.Wcs public class HttpHelper { - public static string SendPostMessage(string ip, int port, string url, string message) + public static string SendPostMessage(string ip, int port, string url, string message,string contentType="application/Text") { - var contentType = "application/Text"; string retsult = HttpPost("http://" + ip + ":" + port + "/" + url, message, contentType, 30, null); return retsult; } diff --git a/src/Khd.Core.Wcs/Global/StaticData.cs b/src/Khd.Core.Wcs/Global/StaticData.cs index 0280b03..0beeb16 100644 --- a/src/Khd.Core.Wcs/Global/StaticData.cs +++ b/src/Khd.Core.Wcs/Global/StaticData.cs @@ -36,13 +36,32 @@ namespace Khd.Core.Wcs.Global public static List WmsWarehouseMaterial = new List(); public static List MesBasePalletInfo = new List(); public static List BaseDictionary = new List(); - public static List BaseEquip = new List(); + + private static object baseEquipLock = new object(); + private static List _baseEquip= new List(); + public static List BaseEquip + { + get + { + lock (baseEquipLock) + { + return _baseEquip; + } + } + set + { + lock (baseEquipLock) + { + _baseEquip = value; + } + } + } public static List WcsCmd = new List(); public static List WcsCmdLog = new List(); public static List WcsStock = new List(); public static List WcsInWareOrder = new List(); public static List WcsOutWareOrder = new List(); - + public static List basePlcs = new List(); public static List PlcConfigs { get; set; } public static Dictionary> PlcPoints = new Dictionary>(); public static Dictionary PlcDic = new Dictionary(); diff --git a/src/Khd.Core.Wcs/MainCentralControl.cs b/src/Khd.Core.Wcs/MainCentralControl.cs index ef0d880..760adc4 100644 --- a/src/Khd.Core.Wcs/MainCentralControl.cs +++ b/src/Khd.Core.Wcs/MainCentralControl.cs @@ -1,4 +1,5 @@ -using Khd.Core.EntityFramework; +using Khd.Core.Domain.Models; +using Khd.Core.EntityFramework; using Khd.Core.Plc; using Khd.Core.Plc.S7; using Khd.Core.Wcs.Global; @@ -9,6 +10,7 @@ using Microsoft.Extensions.Hosting; using System.Data; using System.Net.Http.Headers; using System.Text; +using Z.EntityFramework.Plus; namespace Khd.Core.Wcs { @@ -46,19 +48,31 @@ namespace Khd.Core.Wcs //设置默认去向=>1为 Int16位 WcsMoRenQuXiang = StaticPlcHelper.GetValue("2", "1"); dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); + StaticData.BasePlcpointList = dbContext.BasePlcpoint.Where(t => t.isDelete == 0).ToList(); StaticData.BaseEquip = dbContext.BaseEquip.ToList(); + StaticData.basePlcs = dbContext.BasePlc.ToList(); + StaticData.BaseDictionary = dbContext.BaseDictionary.ToList(); foreach (var plcConfig in StaticData.PlcConfigs) { if (!StaticData.PlcDic.Any(t => t.Key == plcConfig.Code)) { Plc.S7.Plc plc; plc = new Plc.S7.Plc(plcConfig.CpuType, plcConfig.IP, plcConfig.Port, plcConfig.Rack, plcConfig.Slot); - plc.Open(); + try + { + plc.Open(); + Console.WriteLine(DateTime.Now + ":连接到PLC:" + plcConfig.IP); + } + catch + { + Console.WriteLine(DateTime.Now + ":连接Plc" + plcConfig.IP + "失败~~~~~~~"); + } StaticData.PlcDic.TryAdd(plcConfig.Code, plc); } } - ////创建任务 + + //////创建任务 //CreateTaskByRecord createTaskByRecord = new(_host, StaticData.PlcDic[0], ""); //createTaskByRecord.StartPoint(); @@ -101,10 +115,10 @@ namespace Khd.Core.Wcs //FiveFloorLine fiveFloorLine = new(_host, StaticData.PlcDic[0], FiveFloorLineEquip.floorNo.Value, FiveFloorLineEquip.equipNo); //fiveFloorLine.StartPoint(); - //五层CTU - var FiveFloorCTUEquip = StaticData.BaseEquip.Where(t => t.floorNo == 5 && t.equipType == 6).First(); - FiveFloorCTU fiveFloorCTU = new(_host, StaticData.PlcDic[0], FiveFloorCTUEquip.floorNo.Value, FiveFloorCTUEquip.equipNo); - fiveFloorCTU.StartPoint(); + ////五层CTU + //var FiveFloorCTUEquip = StaticData.BaseEquip.Where(t => t.floorNo == 5 && t.equipType == 6).First(); + //FiveFloorCTU fiveFloorCTU = new(_host, StaticData.PlcDic[1], FiveFloorCTUEquip.floorNo.Value, FiveFloorCTUEquip.equipNo); + //fiveFloorCTU.StartPoint(); ////五层AGV //var FifthFloorAgvEquip = StaticData.BaseEquip.Where(t => t.floorNo == 5 && t.equipType == 5).First(); diff --git a/src/Khd.Core.Wcs/Wcs/CreateTaskByRecord.cs b/src/Khd.Core.Wcs/Wcs/CreateTaskByRecord.cs index 6ea5e45..4e18058 100644 --- a/src/Khd.Core.Wcs/Wcs/CreateTaskByRecord.cs +++ b/src/Khd.Core.Wcs/Wcs/CreateTaskByRecord.cs @@ -1,13 +1,17 @@ using Khd.Core.Domain.Dto.wcs; 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 System.Security.Cryptography; +using System.Threading.Tasks.Dataflow; using Z.EntityFramework.Plus; namespace Khd.Core.Wcs.Wcs @@ -60,19 +64,252 @@ namespace Khd.Core.Wcs.Wcs /// public void StartPoint() { + var createBearAgvReturnThread = new Thread(CreateBearAgvReturnLogic); + createBearAgvReturnThread.Start(); var createRawInWareTaskThread = new Thread(CreateRawInWareTaskLogic); createRawInWareTaskThread.Start(); - var createProductTaskThread=new Thread(CreateProductTaskLogic); + var createProductTaskThread = new Thread(CreateProductTaskLogic); createProductTaskThread.Start(); - var createRawTaskThread=new Thread(CreateRawTaskLogic); + var createRawTaskThread = new Thread(CreateRawTaskLogic); createRawTaskThread.Start(); + + var createThirdOutTaskThread = new Thread(CreateThirdOutTaskLogic); + createThirdOutTaskThread.Start(); + Console.WriteLine(DateTime.Now + ":出库任务监听启动成功"); LogManager.Info("出库任务监听启动成功"); } + /// + /// 创建去翻转机的任务 + /// + /// + /// + private void CreateThirdOutTaskLogic(object? obj) + { + 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(); + while (true) + { + try + { + dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); + WcsTask? wcsTask = dbContext.WcsTask.FirstOrDefault(t => t.endPointId == endEquip.objid); + if (wcsTask == null) + { + var wmsRawOutstock = dbContext.WmsRawOutstock + .Where(t => t.endStationCode == endEquip.equipNo) + .Where(t => t.executeStatus == "0") + .OrderBy(t => t.auditStatus == "1") + .FirstOrDefault(); + if (wmsRawOutstock != null) + { + var wmsRawStocks = dbContext.WmsRawStock + .Where(t => t.materialId == wmsRawOutstock.materialId) + .Where(t => t.instockBatch == wmsRawOutstock.materialBatch) + .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) + .Where(t => t.b.instockBatch == wmsRawOutstock.materialBatch) + .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 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.orderId, + taskType = 49, + containerNo = wmsBaseLocation.containerCode, + createBy = "WCS", + createTime = DateTime.Now, + taskStatus = 0, + materialId = wmsRawOutstock.materialId, + currPointId = formWmsBaseLocation.locationId, + currPointNo = formWmsBaseLocation.locationCode, + startPointId = formWmsBaseLocation.locationId, + startPointNo = 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); + dbContext.SaveChanges(); + Thread.Sleep(2000); + } + } + if (wmsBaseLocation != null) + { + wcsTask = new WcsTask() + { + objid = StaticData.SnowId.NextId(), + orderId = wmsRawOutstock.orderId, + taskType = 41, + containerNo = wmsBaseLocation.containerCode, + createBy = "WCS", + createTime = DateTime.Now, + taskStatus = 0, + materialId = wmsRawOutstock.materialId, + currPointId = wmsBaseLocation.locationId, + currPointNo = wmsBaseLocation.locationCode, + startPointId = wmsBaseLocation.locationId, + startPointNo = wmsBaseLocation.locationCode, + nextPointId = baseEquip.objid, + nextPointNo = baseEquip.equipNo, + endPointId = endEquip.objid, + endPointNo = endEquip.equipNo, + equipmentNo = endEquip.equipNo, + useFlag = 1, + qty = 1 + }; + WcsTaskLog wcsTaskLog = CoreMapper.Map(wcsTask); + dbContext.Add(wcsTask); + dbContext.Add(wcsTaskLog); + dbContext.SaveChanges(); + } + } + } + } + + } + } + } + catch (Exception ex) + { + LogManager.Error(ex); + } + } + } + + /// + /// 创建返库任务 + /// + /// + private void CreateBearAgvReturnLogic() + { + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + 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 wmsRawReturns = dbContext.WmsRawReturn.Where(t => t.executeStatus == "0") + .Where(t => t.auditStatus == "1") + .ToList(); + if (wmsRawReturns != null && wmsRawReturns.Count > 0) + { + WmsRawReturn wmsRawReturn = wmsRawReturns.First(); + if (wmsRawReturn.executeStatus == "0") + { + //任务未开始Status=0 + string startStation = wmsRawReturn.endStationCode; + BaseEquip startEquip = StaticData.BaseEquip.First(t => t.equipNo == startStation); + WcsTask wcsTask = new() + { + objid = StaticData.SnowId.NextId(), + orderId = wmsRawReturn.rawReturnId, + taskType = 48, + containerNo = "", + startPointId = startEquip.objid, + startPointNo = startEquip.equipNo, + 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); + dbContext.Update(wmsRawReturn); + dbContext.SaveChanges(); + } + } + } + catch (Exception ex) + { + LogManager.Error(ex); + } + Thread.Sleep(1000); + } + } + /// /// 背板安装区到半成品入库 /// @@ -92,6 +329,7 @@ namespace Khd.Core.Wcs.Wcs Console.WriteLine(ex.Message + ex.StackTrace); LogManager.Error(ex); } + Thread.Sleep(5000); } } @@ -109,7 +347,10 @@ namespace Khd.Core.Wcs.Wcs { dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); var proStock = dbContext.WmsProductStock.Where(t => t.activeFlag == "0").ToList(); - var proOutStock = dbContext.WmsProductOutstock.Where(t => t.operationType == "3").Where(t => t.executeStatus == "0").ToList(); + var proOutStock = dbContext.WmsProductOutstock + .Where(t => t.outstockQty < t.applyQty) + .Where(t => t.auditStatus == "1") + .Where(t => t.executeStatus == "0" || t.executeStatus == "1").ToList(); //获取最早入库时间 foreach (var item in proOutStock) { @@ -201,26 +442,8 @@ namespace Khd.Core.Wcs.Wcs }; location.outstockFlag = "1"; location.locationStatus = "6"; - location.updateBy = "SYS"; + location.updateBy = "WCS"; location.updateTime = DateTime.Now; - WcsOutstockLock stockLock = new() - { - objid = StaticData.SnowId.NextId(), - boxNo = stock.palletInfoCode, - boxStatus = 0, - createTime = DateTime.Now, - createBy = "SYS", - floorNum = 5, - materialId = item.productId, - qty = qty, - warehouseId = item.warehouseId, - wmsOrderId = item.saleOrderId, - wmsOrderDetailId = item.productOutstockId, - orderType = 2, - taskId = wcsTask.objid, - useFlag = 1, - }; - dbContext.Add(stockLock); dbContext.Update(location); dbContext.Add(wcsTask); dbContext.Update(stock); @@ -230,55 +453,13 @@ namespace Khd.Core.Wcs.Wcs break; } } + if (item.beginTime == null) + { + item.beginTime = DateTime.Now; + } dbContext.Update(item); dbContext.SaveChanges(); } - ////自动获取id - - //var objid = StaticData.SnowId.NextId(); - ////锁定库存 - //WcsOutstockLock stockLock = new() - //{ - // objid = objid, - // materialId = item.productId, - // qty = item.applyQty, - // warehouseId = item.warehouseId, - // wmsOrderId = item.productOutstockId, - // wmsOrderDetailId = item.productOutstockId, - // createBy = "sys", - // createTime = DateTime.Now - //}; - - //var dic = StaticData.BaseDictionary.Where(t => t.dicKey == "TaskType" && t.ud1 == "O" && t.dicField == item.productType).FirstOrDefault(); - ////获取最早入库时间 - //var firstDate = proStock.Where(t => t.productId == item.productId && t.warehouseId == item.warehouseId).OrderBy(t => t.createDate).FirstOrDefault(); - //if (firstDate != null && dic != null) - //{ - // //创建出库任务 - // WcsTask newTask = new() - // { - // objid = objid, - // taskType = Convert.ToInt32(dic.dicValue), - // containerNo = "", - // taskStatus = 0, - // materialId = item.warehouseId, - // qty = 1, - // startPointId = item.warehouseId, - // startPointNo = "", - // currPointId = item.warehouseId, - // currPointNo = "", - // endPointId = item.warehouseId, - // endPointNo = "", - // }; - // dbContext.Add(newTask); - // dbContext.SaveChanges(); - // //回写wms记录表 - // dbContext.WmsProductOutstock.Where(t => t.productOutstockId == item.productOutstockId).Update(t => new WmsProductOutstock() - // { - // executeStatus = "1", - // updateDate = DateTime.Now - // }); - //} } catch (Exception ex) { @@ -288,7 +469,6 @@ namespace Khd.Core.Wcs.Wcs } } - /// /// 原材料出库 /// @@ -305,294 +485,285 @@ namespace Khd.Core.Wcs.Wcs var rawStock = dbContext.WmsRawStock.Where(t => t.activeFlag == "1").ToList(); //原材料出库记录 var rawOutStock = dbContext.WmsRawOutstock - .Where(t => t.operationType == "3") - .Where(t => t.executeStatus != "2") + .Where(t => t.executeStatus == "0" || t.executeStatus == "1") + .Where(t => t.outstockAmount > t.realOutstockAmount) .Where(t => t.auditStatus == "1") .ToList(); 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) { if (endEquip.equipType == 8)//CTU出库 { - var wmsRawStocks = rawStock - .Where(t => t.materialId == item.materialId && 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 => wmsRawStocks.Contains(t.containerCode)) - .ToList(); - - decimal needNumber = item.outstockAmount - item.realOutstockAmount; - if (needNumber <= 0) + WcsOutstockLock wcsOutstockLock = dbContext.WcsOutstockLock.Where(t => t.warehouseId == 512).First(); + if (wcsOutstockLock.qty == 0 && wcsOutstockLock.boxStatus == 0) { - item.executeStatus = "2"; - dbContext.Update(item); - dbContext.SaveChanges(); - continue; - } + var wmsRawStocks = rawStock + .Where(t => t.materialId == item.materialId) + .Where(t => t.warehouseId == item.warehouseId) + .Select(t => t.locationCode) + .ToList(); - 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.occupyAmount - t.b.frozenAmount).Sum() > needNumber) - { - bill = bill.OrderBy(t => t.a.locColumn).ToList(); - } - else - { - bill = bill.OrderByDescending(t => t.a.locColumn).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(); - 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.occupyAmount - stock.frozenAmount <= needNumber)//该料箱全部出 + 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.occupyAmount - t.b.frozenAmount).Sum() > needNumber) { - item.realOutstockAmount += stock.totalAmount - stock.occupyAmount - stock.frozenAmount; - qty = Convert.ToInt32(stock.totalAmount - stock.frozenAmount); - stock.occupyAmount += qty; - stock.updateDate = DateTime.Now; + bill = bill.OrderBy(t => t.a.locColumn).ToList(); } else { - item.realOutstockAmount += needNumber; - stock.occupyAmount += needNumber; - qty = Convert.ToInt32(needNumber); - stock.updateDate = DateTime.Now; + bill = bill.OrderByDescending(t => t.a.locColumn).ToList(); } - wcsTask = new WcsTask() + //做数量限制 + + //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) { - objid = StaticData.SnowId.NextId(), - orderId = item.rawOutstockId, - taskType = 38, - containerNo = location.containerCode, - createBy = "WCS", - createTime = DateTime.Now, - taskStatus = 0, - materialId = item.materialId, - currPointId = location.locationId, - currPointNo = location.locationCode, - startPointId = location.locationId, - startPointNo = location.locationCode, - nextPointId = ctuEquip.objid, - nextPointNo = ctuEquip.equipNo, - endPointId = lineEquip.objid, - endPointNo = lineEquip.equipNo, - equipmentNo = ctuEquip.equipNo, - useFlag = 1, - qty = qty - }; - location.outstockFlag = "1"; - location.locationStatus = "6"; - location.updateBy = "SYS"; - location.updateTime = DateTime.Now; - WcsOutstockLock stockLock = new() + 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.occupyAmount - stock.frozenAmount <= needNumber)//该料箱全部出 + { + RealOutNumber += stock.totalAmount - stock.occupyAmount - stock.frozenAmount; + outNumber = Convert.ToInt32(stock.totalAmount - stock.occupyAmount - stock.frozenAmount); + qty = Convert.ToInt32(stock.totalAmount - stock.frozenAmount); + stock.updateDate = DateTime.Now; + } + else + { + RealOutNumber += needNumber; + outNumber = Convert.ToInt32(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 = 0, + materialId = item.materialId, + currPointId = location.locationId, + currPointNo = location.locationCode, + startPointId = location.locationId, + startPointNo = location.locationCode, + nextPointId = ctuEquip.objid, + nextPointNo = ctuEquip.equipNo, + endPointId = lineEquip.objid, + endPointNo = lineEquip.equipNo, + equipmentNo = ctuEquip.equipNo, + useFlag = 1, + qty = outNumber + }; + location.outstockFlag = "1"; + location.locationStatus = "6"; + location.updateBy = "WCS"; + location.updateTime = DateTime.Now; + wcsOutstockLock.boxStatus = 1; + dbContext.Update(location); + dbContext.Add(wcsTask); + dbContext.Update(stock); + dbContext.SaveChanges(); + if (qty >= needNumber) + { + break; + } + } + if (item.beginTime == null) { - objid = StaticData.SnowId.NextId(), - boxNo = stock.palletInfoCode, - boxStatus = 0, - createTime = DateTime.Now, - createBy = "SYS", - floorNum = 5, - materialId = item.materialId, - qty = qty, - warehouseId = item.warehouseId, - wmsOrderId = item.orderId, - wmsOrderDetailId = item.rawOutstockId, - orderType = 2, - taskId = wcsTask.objid, - useFlag = 1, - }; - dbContext.Add(stockLock); - dbContext.Update(location); - dbContext.Add(wcsTask); - dbContext.Update(stock); + item.beginTime = DateTime.Now; + } + dbContext.Update(wcsOutstockLock); + dbContext.Update(item); dbContext.SaveChanges(); - if (qty >= needNumber) - { - break; - } } - dbContext.Update(item); - dbContext.SaveChanges(); }//CTU出库 - else if (endEquip.equipType == 10) + else if (endEquip.equipType == 10)//CTU出库到装配区 { - var wmsRawStocks = rawStock - .Where(t => t.materialId == item.materialId && 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 => wmsRawStocks.Contains(t.containerCode)) - .ToList(); - - decimal needNumber = item.outstockAmount - item.realOutstockAmount; - if (needNumber <= 0) + WcsOutstockLock wcsOutstockLock = dbContext.WcsOutstockLock + .Where(t => t.warehouseId == 512) + .First(); + if (wcsOutstockLock.qty == 0 && wcsOutstockLock.boxStatus == 0) { - item.executeStatus = "2"; - dbContext.Update(item); - dbContext.SaveChanges(); - continue; - } + var orderList = rawOutStock.Where(t => t.endStationCode == item.endStationCode).ToList(); + foreach (var order in orderList) + { + decimal? RealOutNummber = order.realOutstockAmount; + 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 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.occupyAmount - t.b.frozenAmount).Sum() > needNumber) - { - bill = bill.OrderBy(t => t.a.locColumn).ToList(); - } - else - { - bill = bill.OrderByDescending(t => t.a.locColumn).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(); - 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.occupyAmount - stock.frozenAmount <= needNumber)//该料箱全部出 - { - item.realOutstockAmount += stock.totalAmount - stock.occupyAmount - stock.frozenAmount; - qty = Convert.ToInt32(stock.totalAmount - stock.frozenAmount); - stock.occupyAmount += qty; - stock.updateDate = DateTime.Now; - } - else - { - item.realOutstockAmount += needNumber; - stock.occupyAmount += 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 = 0, - materialId = item.materialId, - currPointId = location.locationId, - currPointNo = location.locationCode, - startPointId = location.locationId, - startPointNo = location.locationCode, - nextPointId = ctuEquip.objid, - nextPointNo = ctuEquip.equipNo, - endPointId = lineEquip.objid, - endPointNo = lineEquip.equipNo, - equipmentNo = ctuEquip.equipNo, - useFlag = 1, - qty = qty - }; - location.outstockFlag = "1"; - location.locationStatus = "6"; - location.updateBy = "SYS"; - location.updateTime = DateTime.Now; - WcsOutstockLock stockLock = new() - { - objid = StaticData.SnowId.NextId(), - boxNo = stock.palletInfoCode, - boxStatus = 0, - createTime = DateTime.Now, - createBy = "SYS", - floorNum = 5, - materialId = item.materialId, - qty = qty, - warehouseId = item.warehouseId, - wmsOrderId = item.orderId, - wmsOrderDetailId = item.rawOutstockId, - orderType = 2, - taskId = wcsTask.objid, - useFlag = 1, - }; - dbContext.Add(stockLock); - dbContext.Update(location); - dbContext.Add(wcsTask); - dbContext.Update(stock); - dbContext.SaveChanges(); - if (qty >= needNumber) - { - break; + decimal? needNumber = order.outstockAmount - RealOutNummber; + + 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.occupyAmount - 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.occupyAmount - stock.frozenAmount <= needNumber)//该料箱全部出 + { + RealOutNummber += stock.totalAmount - stock.occupyAmount - stock.frozenAmount; + qty = Convert.ToInt32(stock.totalAmount - stock.frozenAmount); + stock.occupyAmount += qty; + stock.updateDate = DateTime.Now; + } + else + { + RealOutNummber += needNumber; + stock.occupyAmount += 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 = 0, + materialId = item.materialId, + currPointId = location.locationId, + currPointNo = location.locationCode, + startPointId = location.locationId, + startPointNo = location.locationCode, + nextPointId = ctuEquip.objid, + nextPointNo = ctuEquip.equipNo, + endPointId = lineEquip.objid, + endPointNo = lineEquip.equipNo, + equipmentNo = ctuEquip.equipNo, + useFlag = 1, + qty = qty + }; + location.outstockFlag = "1"; + location.locationStatus = "6"; + location.updateBy = "WCS"; + location.updateTime = DateTime.Now; + wcsOutstockLock.qty += 1; + dbContext.Update(wcsOutstockLock); + dbContext.Update(location); + dbContext.Add(wcsTask); + dbContext.Update(stock); + dbContext.SaveChanges(); + if (qty >= needNumber) + { + break; + } + } + } + + 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 = "", + startPointId = startStationEquip.objid, + startPointNo = startStationEquip.equipNo, + 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 = 0, + equipmentNo = startStationEquip.equipNo, + remark = "组装出库", + floorNo = 5, + masterId = item.materialId, + fromFloorNo = 5, + materialNo = item.materialBatch, + }; + if (item.beginTime == null) + { + item.beginTime = DateTime.Now; + } + wcsOutstockLock.boxStatus = 1; + dbContext.Update(wcsOutstockLock); + dbContext.Add(bearAgvTask); + dbContext.Update(item); + dbContext.SaveChanges(); } } - 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 = "", - startPointId = startStationEquip.objid, - startPointNo = startStationEquip.equipNo, - 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 = 0, - equipmentNo = startStationEquip.equipNo, - remark = "组装出库", - floorNo = 5, - masterId = item.materialId, - fromFloorNo = 5, - materialNo = item.materialBatch, - }; - dbContext.Add(bearAgvTask); - dbContext.Update(item); - dbContext.SaveChanges(); - - }//CTU出库到装配区 + } else if (endEquip.equipType == 12 || endEquip.equipType == 13)//原材料到柜体验收区 { 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") .Select(t => t.palletInfoCode) .ToList(); @@ -606,7 +777,7 @@ namespace Khd.Core.Wcs.Wcs .Where(t => wmsRawStocks.Contains(t.containerCode)) .ToList(); - decimal needNumber = item.outstockAmount - item.realOutstockAmount; + decimal? needNumber = item.outstockAmount - item.realOutstockAmount; if (needNumber <= 0) { item.executeStatus = "2"; @@ -622,11 +793,11 @@ namespace Khd.Core.Wcs.Wcs //如果第一列满足需求,则按第一列排序,否则按最后一列排序 if (bill.Where(t => t.a.locColumn == 1).Select(t => t.b.totalAmount - t.b.occupyAmount - t.b.frozenAmount).Sum() > needNumber) { - bill = bill.OrderBy(t => t.a.locColumn).ToList(); + bill = bill.OrderBy(t => t.a.locColumn).Take(1).ToList(); } else { - bill = bill.OrderByDescending(t => t.a.locColumn).ToList(); + bill = bill.OrderByDescending(t => t.a.locColumn).Take(1).ToList(); } BaseEquip bearAgvEquip = StaticData.BaseEquip.First(t => t.objid == 10); @@ -656,7 +827,7 @@ namespace Khd.Core.Wcs.Wcs { objid = StaticData.SnowId.NextId(), orderId = item.rawOutstockId, - taskType = endEquip.equipType == 12 ? 27 : 33,//如果是12那么就是原材料到柜体验收区,如果是13那么就是原材料到背板安装区 + taskType = endEquip.equipType == 12 ? 46 : 33,//如果是12那么就是原材料到柜体验收区,如果是13那么就是原材料到背板安装区 containerNo = location.containerCode, createBy = "WCS", createTime = DateTime.Now, @@ -676,7 +847,7 @@ namespace Khd.Core.Wcs.Wcs }; location.outstockFlag = "1"; location.locationStatus = "6"; - location.updateBy = "SYS"; + location.updateBy = "WCS"; location.updateTime = DateTime.Now; dbContext.Update(location); dbContext.Add(wcsTask); @@ -687,76 +858,15 @@ namespace Khd.Core.Wcs.Wcs break; } } + if (item.beginTime == null) + { + item.beginTime = DateTime.Now; + } dbContext.Update(item); dbContext.SaveChanges(); } } - - - //var objid = StaticData.SnowId.NextId(); - //long orderID = 0; - ////插入锁定库存 - //WcsOutstockLock stockLock = new() - //{ - // objid = objid, - // materialId = item.productId, - // qty = 1, - // warehouseId = item.warehouseId, - // wmsOrderId = item.rawOutstockId, - // wmsOrderDetailId = item.rawOutstockId, - // createBy = "sys", - // createTime = DateTime.Now - //}; - //dbContext.Add(stockLock); - //if (item.warehouseId == 5)//五楼辅料出库 - //{ - // //辅料出库时,需创建订单表数据 - // orderID = StaticData.SnowId.NextId(); - // WcsWarehouseOrder order = new() - // { - // objid = orderID, - // wmsOrderId = item.rawOutstockId, - // orderType = Convert.ToInt32(item.taskType), - // qty = 1, - // createBy = "", - // createTime = DateTime.Now - // }; - // dbContext.Add(order); - //} - //var dic = StaticData.BaseDictionary.Where(t => t.dicKey == "TaskType" && t.ud1 == "O").FirstOrDefault(); - //if (dic != null) - //{ - // WcsTask rawTask = new() - // { - // objid = StaticData.SnowId.NextId(), - // orderId = item.rawOutstockId, - // masterId = orderID, - // taskType = Convert.ToInt32(dic.dicValue), - // containerNo = "", - // taskStatus = 0, - // materialId = item.materialId, - // qty = 1, - // startPointId = item.warehouseId, - // startPointNo = "", - // currPointId = item.warehouseId, - // currPointNo = "", - // endPointId = item.warehouseId, - // endPointNo = "" - // }; - // dbContext.Add(rawTask); - - // //获取最早入库时间 - // var firstDate = rawStock.Where(t => t.materialId == item.productId && t.warehouseId == item.warehouseId).OrderBy(t => t.createDate).FirstOrDefault(); - - // //回写wms出库记录表 - // dbContext.WmsRawOutstock.Where(t => t.rawOutstockId == item.rawOutstockId).Update(t => new WmsProductOutstock() - // { - // executeStatus = "1", - // updateDate = DateTime.Now - // }); - //} } - } catch { @@ -766,5 +876,14 @@ namespace Khd.Core.Wcs.Wcs } + + //五楼原材料出库,完成 + //五楼原材料出库到组装区,完成 + //五楼成品出库完成 + + //五楼原材料返库待完成 + //五楼背板安装--半成品基本完成,待完善 + //五楼原材料--背板安装待完成 + //五楼原材料--柜体验收待完成 } } diff --git a/src/Khd.Core.Wcs/Wcs/FirstFloor.cs b/src/Khd.Core.Wcs/Wcs/FirstFloor.cs index 2641094..e956f23 100644 --- a/src/Khd.Core.Wcs/Wcs/FirstFloor.cs +++ b/src/Khd.Core.Wcs/Wcs/FirstFloor.cs @@ -2,12 +2,14 @@ using Khd.Core.Application.Interface; using Khd.Core.Domain.Models; using Khd.Core.EntityFramework; +using Khd.Core.Library.Mapper; using Khd.Core.Plc; using Khd.Core.Plc.S7; using Khd.Core.Wcs.Global; using Masuit.Tools.Logging; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using System.Diagnostics; using Z.EntityFramework.Plus; namespace Khd.Core.Wcs.Wcs @@ -133,12 +135,25 @@ namespace Khd.Core.Wcs.Wcs var task = dbContext.WcsTask.Where(t => t.containerNo == RFID001Value && t.taskStatus < 1).FirstOrDefault(); if (task == null) { - //入库 - //根据托盘号获取物料码 var material = dbContext.MesBasePalletInfo.Where(t => t.palletInfoCode == RFID001Value).FirstOrDefault(); if (material != null) { + var lastTask = dbContext.WcsTaskLog.Where(t => t.containerNo == RFID001Value).OrderByDescending(t => t.createTime).FirstOrDefault(); + if (lastTask != null) + { + if (lastTask.materialId == material.materialId && lastTask.ud3 != "10") + { + lastTask.ud2 = "1"; + lastTask.ud3 = "1"; + dbContext.Update(lastTask); + dbContext.SaveChanges(); + LogManager.Info("一楼接驳位线程:托盘" + RFID001Value + "绑定信息未更新,请人工确认是否再次入库"); + Console.WriteLine(DateTime.Now + ":一楼接驳位线程:托盘" + RFID001Value + "绑定信息未更新,请人工确认是否再次入库"); + Thread.Sleep(3000); + continue; + } + } var warehouseId = dbContext.WmsWarehouseMaterial.Where(t => t.storageType == "1" && t.storageId == material.materialId).FirstOrDefault()?.warehouseId; if (warehouseId != null) { @@ -147,7 +162,7 @@ namespace Khd.Core.Wcs.Wcs { //插入task表 - var dic = StaticData.BaseDictionary.Where(t => t.dicKey == "TaskType" && t.ud1 == "I" && t.dicField == TargetFloor.warehouseInstockType).FirstOrDefault(); + var dic = StaticData.BaseDictionary.Where(t => t.dicKey == "TaskType" && t.agvType == "I" && t.dicField == TargetFloor.warehouseInstockType).FirstOrDefault(); if (dic != null) { var newTask = new WcsTask() @@ -175,7 +190,10 @@ namespace Khd.Core.Wcs.Wcs createTime = DateTime.Now, remark = "一楼创建入库任务" }; + WcsTaskLog wcsTaskLog = CoreMapper.Map(newTask); + dbContext.Add(wcsTaskLog); dbContext.Add(newTask); + dbContext.SaveChanges(); } } } @@ -193,28 +211,50 @@ namespace Khd.Core.Wcs.Wcs task.updateBy = "一楼接驳位线程"; task.updateTime = DateTime.Now; task.remark = "一楼创建入库任务"; - dbContext.WcsTask.Update(task); + WcsTaskLog wcsTaskLog = CoreMapper.Map(task); + dbContext.Update(wcsTaskLog); + dbContext.Update(task); dbContext.SaveChanges(); } } //出库 else { - //清空托盘绑定 - var material = dbContext.MesBasePalletInfo.Where(t => t.palletInfoCode == RFID001Value).FirstOrDefault(); - if (material != null) - { - material.bindAmount = 0; - material.materialBarcode = null; - material.materialCode = null; - material.materialId = null; - material.materialName = null; - material.updateBy = "SYS"; - material.updateTime = DateTime.Now; - dbContext.Update(material); - //dbContext.MesBasePalletInfo.Where(t => t.palletInfoCode == RFID001Value).Delete(); - dbContext.SaveChanges(); - } + dbContext.WcsTask.Where(t => t.objid == task.objid).Delete(); + dbContext.WcsTaskLog.Where(t => t.objid == task.objid).Update(t => new WcsTaskLog { taskStatus = 4 }); + //没有绑定信息 + + //WmsProductOutstock? wmsProductOutstock = dbContext.WmsProductOutstock.FirstOrDefault(t => t.palletInfoCode == RFID001Value&& t.executeStatus =="1"); + //WmsRawOutstock? wmsRawOutstock = dbContext.WmsRawOutstock.FirstOrDefault(t => t.palletInfoCode == RFID001Value && t.executeStatus == "1"); + //if (wmsProductOutstock != null || wmsRawOutstock != null) + //{ + // //清空托盘绑定 + // var material = dbContext.MesBasePalletInfo.Where(t => t.palletInfoCode == RFID001Value).FirstOrDefault(); + // if (material != null) + // { + // material.bindAmount = 0; + // material.materialBarcode = null; + // material.materialCode = null; + // material.materialId = null; + // material.materialName = null; + // material.updateBy = "WCS"; + // material.updateTime = DateTime.Now; + // dbContext.Update(material); + // if (wmsRawOutstock != null) + // { + // wmsRawOutstock.executeStatus = "2"; + // dbContext.Update(wmsRawOutstock); + // } + // else if(wmsProductOutstock != null) + // { + // wmsProductOutstock.executeStatus = "2"; + // dbContext.Update(wmsProductOutstock); + // } + // //dbContext.MesBasePalletInfo.Where(t => t.palletInfoCode == RFID001Value).Delete(); + // dbContext.SaveChanges(); + + // } + //} } } } @@ -223,14 +263,13 @@ namespace Khd.Core.Wcs.Wcs { if (ex is PlcException) { - try + foreach (var item in StaticData.PlcDic) { - this._plc = new Plc.S7.Plc(this._plc.CPU, this._plc.IP, this._plc.Port, this._plc.Rack, this._plc.Slot); - this._plc.Open(); - } - catch - { - + if (item.Value.IP == ex.Message) + { + StaticData.PlcDic[item.Key] = new Plc.S7.Plc(item.Value.CPU, item.Value.IP, item.Value.Port, item.Value.Rack, item.Value.Slot); + StaticData.PlcDic[item.Key].Open(); + } } } LogManager.Error(ex); @@ -265,11 +304,22 @@ namespace Khd.Core.Wcs.Wcs //提升机空闲 if (Convert.ToInt32(equipstate06Value) == 0) { - var wcsTasks = dbContext.WcsTask.Where(t => t.nextPointId == T01).OrderBy(t => t.createTime); + var wcsTasks = dbContext.WcsTask.Where(t => t.nextPointId == T01).OrderBy(t => t.createTime).ToList(); foreach (var wcsTask in wcsTasks) { + if (wcsTasks.Where(t => t.taskStatus > 0).Where(t => t.objid != wcsTask.objid).Any()) + { + LogManager.Info("提升机线程:有其他任务正在执行,跳过当前任务"); + continue; + } + BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.objid == wcsTask.floorNo); if (wcsTask.taskStatus == 0 && Convert.ToInt32(hoisterTrayIn06Value) == 0)//创建状态,并且里面没有货物 { + if (lineEquip.equipStatus == 1) + { + LogManager.Info("提升机线程:" + wcsTask.floorNo + "楼接驳位有AGV任务,跳过当前任务"); + continue; + } BasePlcpoint floorPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID00" + wcsTask.fromFloorNo); if (wcsTask.containerNo == this._plc.ReadRFID(floorPoint.plcpointAddress)) { @@ -285,6 +335,9 @@ namespace Khd.Core.Wcs.Wcs this._plc.WriteToPoint(basePlcpoint.plcpointAddress, "1", basePlcpoint.plcpointLength.ToString()); this._plc.WriteToPoint(this.serialno06.plcpointAddress, wcsTask.serialNo.ToString(), this.serialno06.plcpointLength.ToString()); dbContext.Update(wcsTask); + dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 2, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行中" }); + lineEquip.equipStatus = 1; + dbContext.Update(lineEquip); dbContext.SaveChanges(); } } @@ -297,6 +350,9 @@ namespace Khd.Core.Wcs.Wcs this._plc.WriteToPoint(this.targetfloor06.plcpointAddress, wcsTask.fromFloorNo.ToString(), this.targetfloor06.plcpointLength.ToString());//目的地楼层 this._plc.WriteToPoint(this.serialno06.plcpointAddress, wcsTask.serialNo.ToString(), this.serialno06.plcpointLength.ToString()); dbContext.Update(wcsTask); + dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 1, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行中" }); + lineEquip.equipStatus = 1; + dbContext.Update(lineEquip); dbContext.SaveChanges(); } } @@ -318,6 +374,7 @@ namespace Khd.Core.Wcs.Wcs this._plc.WriteToPoint(basePlcpoint.plcpointAddress, "1", basePlcpoint.plcpointLength.ToString()); this._plc.WriteToPoint(this.serialno06.plcpointAddress, wcsTask.serialNo.ToString(), this.serialno06.plcpointLength.ToString()); dbContext.Update(wcsTask); + dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 2, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行中" }); dbContext.SaveChanges(); } } @@ -333,6 +390,7 @@ namespace Khd.Core.Wcs.Wcs wcsTask.remark = "提升机任务执行完成"; this._plc.WriteToPoint(this.targetfloor06.plcpointAddress, wcsTask.floorNo.ToString(), this.targetfloor06.plcpointLength.ToString());//目的地楼层 dbContext.Update(wcsTask); + dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 3, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行完成" }); dbContext.SaveChanges(); } } @@ -347,9 +405,26 @@ namespace Khd.Core.Wcs.Wcs BasePlcpoint basePlcpoint = StaticData.BasePlcpointList.First(t => t.floorNo == wcsTask.fromFloorNo && t.plcpointNo.Contains("wcsrun")); this._plc.WriteToPoint(basePlcpoint.plcpointAddress, "2", basePlcpoint.plcpointLength.ToString());//去向为2,表示提升机已到达目的地,让货出去 dbContext.Update(wcsTask); + dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 4, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行完成" }); dbContext.SaveChanges(); } } + else if (wcsTask.taskStatus == 4) + { + BaseEquip floorEquip = StaticData.BaseEquip.First(t => t.objid == wcsTask.floorNo); + wcsTask.nextPointId = floorEquip.objid; + wcsTask.nextPointNo = floorEquip.equipNo; + wcsTask.taskStatus = 5; + wcsTask.updateBy = "提升机线程"; + wcsTask.updateTime = DateTime.Now; + wcsTask.remark = "提升机任务执行完成"; + lineEquip.equipStatus = 0; + dbContext.Update(lineEquip); + dbContext.SaveChanges(); + dbContext.Update(wcsTask); + dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid).Update(t => new WcsTaskLog { taskStatus = 5, nextPointId = floorEquip.objid, nextPointNo = floorEquip.equipNo, updateBy = "提升机线程", updateTime = DateTime.Now, remark = "提升机任务执行完成" }); + dbContext.SaveChanges(); + } break; } } @@ -361,8 +436,14 @@ namespace Khd.Core.Wcs.Wcs { try { - this._plc = new Plc.S7.Plc(this._plc.CPU, this._plc.IP, this._plc.Port, this._plc.Rack, this._plc.Slot); - this._plc.Open(); + foreach (var item in StaticData.PlcDic) + { + if (item.Value.IP == ex.Message) + { + StaticData.PlcDic[item.Key] = new Plc.S7.Plc(item.Value.CPU, item.Value.IP, item.Value.Port, item.Value.Rack, item.Value.Slot); + StaticData.PlcDic[item.Key].Open(); + } + } } catch { diff --git a/src/Khd.Core.Wcs/Wcs/FiveFloorAGV.cs b/src/Khd.Core.Wcs/Wcs/FiveFloorAGV.cs index 4519fea..2c11fdf 100644 --- a/src/Khd.Core.Wcs/Wcs/FiveFloorAGV.cs +++ b/src/Khd.Core.Wcs/Wcs/FiveFloorAGV.cs @@ -2,6 +2,7 @@ using Khd.Core.Domain.Dto.webapi; using Khd.Core.Domain.Models; using Khd.Core.EntityFramework; +using Khd.Core.Library.Mapper; using Khd.Core.Wcs.Global; using Masuit.Tools.Logging; using Microsoft.Extensions.DependencyInjection; @@ -64,6 +65,7 @@ namespace Khd.Core.Wcs.Wcs using var scope = _host.Services.CreateScope(); using var dbContext = scope.ServiceProvider.GetRequiredService(); List taskType = new() { 1, 3, 5, 7 }; + BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.objid == agvID); while (true) { try @@ -78,12 +80,17 @@ namespace Khd.Core.Wcs.Wcs } foreach (var item in taskList) { + if (taskList.Where(t => t.taskStatus > 0).Where(t => t.objid != item.objid).Any()) + { + LogManager.Info($"5楼AGV线程:有其他任务正在执行,跳过当前任务{item.objid}"); + continue; + } if (item.taskStatus == 0)//下发任务 { if (item.taskType == 37)//入库任务 { WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId); - BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.floorNo == 5 && t.equipType == 1); + BaseEquip currentEquip = StaticData.BaseEquip.First(t => t.floorNo == 5 && t.equipType == 1); WcsCmd wcsCmd = new() { objid = StaticData.SnowId.NextId(), @@ -95,7 +102,7 @@ namespace Khd.Core.Wcs.Wcs createTime = DateTime.Now, createBy = FloorNo + "楼AGV", currPointId = item.currPointId, - currPointNo = baseEquip.agvPositionCode, + currPointNo = currentEquip.agvPositionCode, nextPointId = item.endPointId, nextPointNo = wmsBaseLocation.agvPositionCode, }; @@ -118,7 +125,7 @@ namespace Khd.Core.Wcs.Wcs ctnrTyp = "2", }; string message = JsonConvert.SerializeObject(agvTask); - string result = HttpHelper.SendPostMessage("172.16.12.24", 8182, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); var reponseMessage = JsonConvert.DeserializeObject(result); if (reponseMessage != null && reponseMessage.message == "成功") { @@ -126,23 +133,33 @@ namespace Khd.Core.Wcs.Wcs wcsCmd.cmdStatus = 1; item.taskStatus = 1; dbContext.Update(item); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 1 }); + WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd); + dbContext.Add(wcsCmdLog); dbContext.Add(wcsCmd); dbContext.SaveChanges(); } else { - + LogManager.Info("五楼Agv下发任务失败" + item.taskType + message); } } else if (item.taskType == 38)//出库任务 { - if (Convert.ToInt32(this._plc.Read(LineSignal.plcpointAddress)) == 1) + BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.objid == 5); + bool canSend = dbContext.WcsTask.Where(t => t.nextPointId == lineEquip.objid && t.taskStatus > 0).Any(); + if (lineEquip.equipStatus == 1) + { + LogManager.Info("五楼AGV:接驳位有任务,无法下发出库任务"); + continue; + } + if (Convert.ToInt32(this._plc.Read(LineSignal.plcpointAddress)) == 1 && !canSend) { Console.WriteLine($"{DateTime.Now}:5楼接驳位上有货,无法下发Agv出库任务"); continue; } WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.startPointId); - BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.floorNo == 5 && t.equipType == 1); + BaseEquip nextEquip = StaticData.BaseEquip.First(t => t.floorNo == 5 && t.equipType == 1); WcsCmd wcsCmd = new() { objid = item.objid, @@ -156,7 +173,7 @@ namespace Khd.Core.Wcs.Wcs currPointId = item.currPointId, currPointNo = wmsBaseLocation.agvPositionCode, nextPointId = item.endPointId, - nextPointNo = baseEquip.agvPositionCode, + nextPointNo = nextEquip.agvPositionCode, }; RequestAGVTaskDto agvTask = new() { @@ -178,7 +195,67 @@ namespace Khd.Core.Wcs.Wcs ctnrTyp = "2" }; string message = JsonConvert.SerializeObject(agvTask); - string result = HttpHelper.SendPostMessage("172.16.12.24", 8182, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); + var reponseMessage = JsonConvert.DeserializeObject(result); + if (reponseMessage != null && reponseMessage.message == "成功") + { + wcsCmd.taskCode = reponseMessage.data; + wcsCmd.cmdStatus = 1; + item.taskStatus = 1; + lineEquip.equipStatus = 1; + dbContext.Update(lineEquip); + dbContext.Update(item); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 1 }); + WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd); + dbContext.Add(wcsCmdLog); + dbContext.Add(wcsCmd); + dbContext.SaveChanges(); + } + else + { + LogManager.Info("五楼Agv下发任务失败" + item.taskType + message); + } + } + else if (item.taskType == 33)//原材料到背板安装 + { + BaseEquip endEquip = StaticData.BaseEquip.First(t => t.objid == 30); + WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.startPointId); + WcsCmd wcsCmd = new() + { + objid = item.objid, + cmdStatus = 0, + taskId = item.orderId, + useFlag = 1, + cmdType = item.taskType, + containerNo = item.containerNo, + createTime = DateTime.Now, + createBy = FloorNo + "楼AGV", + currPointId = item.currPointId, + currPointNo = wmsBaseLocation.agvPositionCode, + nextPointId = 30, + nextPointNo = endEquip.agvPositionCode, + }; + RequestAGVTaskDto agvTask = new() + { + reqCode = item.objid.ToString(), + positionCodePath = new List + { + new () + { + positionCode=wcsCmd.currPointNo, + type="00" + }, + new () + { + positionCode=wcsCmd.nextPointNo, + type="00" + } + }, + taskTyp = "", + ctnrTyp = "2" + }; + string message = JsonConvert.SerializeObject(agvTask); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); var reponseMessage = JsonConvert.DeserializeObject(result); if (reponseMessage != null && reponseMessage.message == "成功") { @@ -186,14 +263,249 @@ namespace Khd.Core.Wcs.Wcs wcsCmd.cmdStatus = 1; item.taskStatus = 1; dbContext.Update(item); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 1 }); + WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd); + dbContext.Add(wcsCmdLog); dbContext.Add(wcsCmd); dbContext.SaveChanges(); } + else + { + LogManager.Info("五楼Agv下发任务失败" + item.taskType + message); + } + } + else if (item.taskType == 34)//背板安装到半成品 + { + WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId); + BaseEquip currentEquip = StaticData.BaseEquip.First(t => t.objid == 30); + WcsCmd wcsCmd = new() + { + objid = StaticData.SnowId.NextId(), + cmdStatus = 0, + taskId = item.objid, + useFlag = 1, + cmdType = item.taskType, + containerNo = item.containerNo, + createTime = DateTime.Now, + createBy = FloorNo + "楼AGV", + currPointId = item.currPointId, + currPointNo = currentEquip.agvPositionCode, + nextPointId = item.endPointId, + nextPointNo = wmsBaseLocation.agvPositionCode, + }; + var agvTask = new RequestAGVTaskDto + { + reqCode = item.objid.ToString(), + positionCodePath = new List + { + new () + { + positionCode=wcsCmd.currPointNo, + type="00" + }, + new () + { + positionCode=wcsCmd.nextPointNo, + type="00" + } + }, + ctnrTyp = "2", + }; + string message = JsonConvert.SerializeObject(agvTask); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); + var reponseMessage = JsonConvert.DeserializeObject(result); + if (reponseMessage != null && reponseMessage.message == "成功") + { + wcsCmd.taskCode = reponseMessage.data; + wcsCmd.cmdStatus = 1; + item.taskStatus = 1; + dbContext.Update(item); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 1 }); + WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd); + dbContext.Add(wcsCmdLog); + dbContext.Add(wcsCmd); + dbContext.SaveChanges(); + } + else + { + LogManager.Info("五楼Agv下发任务失败" + item.taskType + message); + } + } + else if (item.taskType == 46)//原材料到拆分区 + { + WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.startPointId); + BaseEquip currentEquip = StaticData.BaseEquip.First(t => t.objid == 29); + WcsCmd wcsCmd = new() + { + objid = item.objid, + cmdStatus = 0, + taskId = item.orderId, + useFlag = 1, + cmdType = item.taskType, + containerNo = item.containerNo, + createTime = DateTime.Now, + createBy = FloorNo + "楼AGV", + currPointId = item.currPointId, + currPointNo = wmsBaseLocation.agvPositionCode, + nextPointId = 29, + nextPointNo = currentEquip.agvPositionCode, + }; + RequestAGVTaskDto agvTask = new() + { + reqCode = item.objid.ToString(), + positionCodePath = new List + { + new () + { + positionCode=wcsCmd.currPointNo, + type="00" + }, + new () + { + positionCode=wcsCmd.nextPointNo, + type="00" + } + }, + taskTyp = "", + ctnrTyp = "2" + }; + string message = JsonConvert.SerializeObject(agvTask); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); + var reponseMessage = JsonConvert.DeserializeObject(result); + if (reponseMessage != null && reponseMessage.message == "成功") + { + wcsCmd.taskCode = reponseMessage.data; + wcsCmd.cmdStatus = 1; + item.taskStatus = 1; + dbContext.Update(item); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 1 }); + WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd); + dbContext.Add(wcsCmdLog); + dbContext.Add(wcsCmd); + dbContext.SaveChanges(); + } + else + { + LogManager.Info("五楼Agv下发任务失败" + item.taskType + message); + } + } + else if (item.taskType == 28)//拆分区返库 + { + BaseEquip currentEquip = StaticData.BaseEquip.First(t => t.objid == 29); + WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId); + WcsCmd wcsCmd = new() + { + objid = item.objid, + cmdStatus = 0, + taskId = item.orderId, + useFlag = 1, + cmdType = item.taskType, + containerNo = item.containerNo, + createTime = DateTime.Now, + createBy = FloorNo + "楼AGV", + currPointId = item.currPointId, + currPointNo = currentEquip.agvPositionCode, + nextPointId = item.endPointId, + nextPointNo = wmsBaseLocation.agvPositionCode, + }; + RequestAGVTaskDto agvTask = new() + { + reqCode = item.objid.ToString(), + positionCodePath = new List + { + new() + { + positionCode = wcsCmd.currPointNo, + type = "00" + }, + new() + { + positionCode = wcsCmd.nextPointNo, + type = "00" + } + } + }; + string message = JsonConvert.SerializeObject(agvTask); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); + var reponseMessage = JsonConvert.DeserializeObject(result); + if (reponseMessage != null && reponseMessage.message == "成功") + { + wcsCmd.taskCode = reponseMessage.data; + wcsCmd.cmdStatus = 1; + item.taskStatus = 1; + dbContext.Update(item); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 1 }); + WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd); + dbContext.Add(wcsCmdLog); + dbContext.Add(wcsCmd); + dbContext.SaveChanges(); + } + else + { + LogManager.Info("五楼Agv下发任务失败" + item.taskType + message); + } + } + else if (item.taskType == 47)//原材料入库 + { + BaseEquip startEquip = StaticData.BaseEquip.First(t => t.objid == 5); + WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId); + WcsCmd wcsCmd = new WcsCmd + { + objid = StaticData.SnowId.NextId(), + cmdStatus = 0, + taskId = item.objid, + useFlag = 1, + cmdType = item.taskType, + containerNo = item.containerNo, + createTime = DateTime.Now, + createBy = FloorNo + "楼AGV", + currPointId = startEquip.objid, + currPointNo = startEquip.agvPositionCode, + nextPointId = item.endPointId, + nextPointNo = wmsBaseLocation.agvPositionCode, + }; + var agvTask = new RequestAGVTaskDto + { + reqCode = item.objid.ToString(), + positionCodePath = new List + { + new () + { + positionCode=wcsCmd.currPointNo, + type="00" + }, + new () + { + positionCode=wcsCmd.nextPointNo, + type="00" + } + }, + ctnrTyp = "2", + }; + string message = JsonConvert.SerializeObject(agvTask); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); + var reponseMessage = JsonConvert.DeserializeObject(result); + if (reponseMessage != null && reponseMessage.message == "成功") + { + wcsCmd.taskCode = reponseMessage.data; + wcsCmd.cmdStatus = 1; + item.taskStatus = 1; + dbContext.Update(item); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 1 }); + WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd); + dbContext.Add(wcsCmdLog); + dbContext.Add(wcsCmd); + dbContext.SaveChanges(); + } + else + { + LogManager.Info("五楼Agv下发任务失败" + item.taskType + message); + } } } else { - WcsCmd? wcsCmd = dbContext.WcsCmd.FirstOrDefault(t => t.objid == item.objid); + WcsCmd? wcsCmd = dbContext.WcsCmd.FirstOrDefault(t => t.taskId == item.objid); if (wcsCmd != null) { if (wcsCmd.cmdStatus == 3) @@ -204,86 +516,254 @@ namespace Khd.Core.Wcs.Wcs taskCode = wcsCmd.taskCode }; string message = JsonConvert.SerializeObject(agvTask); - string result = HttpHelper.SendPostMessage("172.16.12.24", 8182, "rcms/services/rest/hikRpcService/continueTask", message); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/continueTask", message); ReponseMessage? reponseMessage = JsonConvert.DeserializeObject(result); if (reponseMessage != null && reponseMessage.message == "成功") { wcsCmd.cmdStatus = 4; + dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmd() { cmdStatus = 4 }); dbContext.Update(wcsCmd); + dbContext.WcsTask.Where(t => t.objid == item.objid).Update(t => new WcsTask() { taskStatus = 4 }); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 4 }); dbContext.SaveChanges(); } } else if (wcsCmd.cmdStatus == 5) { - //任务完成 - //如果是入库任务,更新库存信息,并删除任务 - if (taskType.Contains(item.taskType)) + if (item.taskType == 37)//入库 { + + //WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation + // .First(t => t.locationId == item.startPointId && t.warehouseFloor == 5); + //wmsBaseLocation.locationStatus = "1"; + //wmsBaseLocation.instockFlag = "0"; + //wmsBaseLocation.containerCode = item.containerNo; + //wmsBaseLocation.updateTime = DateTime.Now; + //wmsBaseLocation.updateBy = "WCS"; + //MesBasePalletInfo? mesBasePalletInfo = dbContext.MesBasePalletInfo.Where(t => t.palletInfoCode == item.containerNo).FirstOrDefault(); + //if (mesBasePalletInfo != null) + //{ + // WmsProductStock wmsProductStock = new WmsProductStock() + // { + // productBatch = mesBasePalletInfo.materialBarcode, + // palletInfoCode = mesBasePalletInfo.palletInfoCode, + // activeFlag = "1", + // createBy = "WCS", + // createDate = DateTime.Now, + // frozenAmount = 0, + // instockDate = DateTime.Now, + // locationCode = wmsBaseLocation.locationCode, + // occupyAmount = 0, + // warehouseFloor = 5, + // saleorderCode = mesBasePalletInfo.materialBarcode, + // stockType = "3", + // totalAmount = 1, + + // }; + // dbContext.Update(wmsBaseLocation); + // dbContext.WcsTask.Where(t => t.objid == item.objid).Delete(); + // dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 6 }); + // dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog { cmdStatus = 6 }); + // dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete(); + // dbContext.SaveChanges(); + //} + + } + else if (item.taskType == 38)//出库 + { + BaseEquip lineEquip = StaticData.BaseEquip.First(t=>t.objid==5); WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation - .First(t => t.locationId == item.startPointId && t.warehouseFloor == 5); + .First(t => t.locationId == item.endPointId && t.warehouseFloor == 5); wmsBaseLocation.outstockFlag = "0"; wmsBaseLocation.locationStatus = "1"; + wmsBaseLocation.containerCode = ""; + wmsBaseLocation.updateTime = DateTime.Now; + wmsBaseLocation.updateBy = "WCS"; dbContext.Update(wmsBaseLocation); - - + dbContext.WmsProductStock.Where(t => t.locationCode == wmsBaseLocation.locationCode).Delete(); + BaseEquip floorLineEquip = StaticData.BaseEquip.First(t => t.equipType == 1 && t.floorNo == 5); + item.nextPointId = floorLineEquip.objid; + item.nextPointNo = floorLineEquip.equipNo; + item.fromFloorNo = 5; + item.floorNo = 1; + item.taskStatus = 6; + lineEquip.equipStatus = 0; + dbContext.Update(lineEquip); + dbContext.Update(item); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 6, nextPointId = floorLineEquip.objid, nextPointNo = floorLineEquip.equipNo, fromFloorNo = 5, floorNo = 1 }); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog { cmdStatus = 6 }); dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete(); - dbContext.WcsTask.Where(t => t.objid == item.objid).Delete(); dbContext.SaveChanges(); } - else//如果是出库任务,更新库存信息,下一个任务为提升机 + else if (item.taskType == 33)//原材料到背板安装 { - WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation - .First(t => t.locationId == item.startPointId && t.warehouseFloor == 5); - if (item.taskType == 38)//出库 + WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.startPointId); + wmsBaseLocation.locationStatus = "1"; + wmsBaseLocation.outstockFlag = "0"; + wmsBaseLocation.containerCode = ""; + wmsBaseLocation.updateTime = DateTime.Now; + wmsBaseLocation.updateBy = "WCS"; + dbContext.Update(wmsBaseLocation); + dbContext.WmsRawStock.Where(t => t.locationCode == wmsBaseLocation.locationCode).Delete(); + dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete(); + dbContext.WcsTask.Where(t => t.objid == item.objid).Delete(); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 6 }); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog { cmdStatus = 6 }); + dbContext.SaveChanges(); + } + else if (item.taskType == 34)//半成品入库 + { + WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId); + wmsBaseLocation.locationStatus = "1"; + wmsBaseLocation.instockFlag = "0"; + wmsBaseLocation.containerCode = item.containerNo; + wmsBaseLocation.updateTime = DateTime.Now; + wmsBaseLocation.updateBy = "WCS"; + var mesBasePalletInfo = dbContext.MesBasePalletInfo.Where(t => t.palletInfoCode == item.containerNo).FirstOrDefault(); + var wmsProductInstock = dbContext.WmsProductInstock + .Where(t => t.palletInfoCode == item.containerNo) + .Where(t => t.instockType == "2" && t.executeStatus == "1" && t.productType == "2" && t.warehouseFloor == 5) + .FirstOrDefault(); + if (mesBasePalletInfo != null && wmsProductInstock != null) { - wmsBaseLocation.outstockFlag = "0"; - wmsBaseLocation.locationStatus = "1"; - wmsBaseLocation.containerCode = ""; - wmsBaseLocation.updateTime = DateTime.Now; - wmsBaseLocation.updateBy = "SYS"; - - + WmsProductStock wmsProductStock = new WmsProductStock() + { + productId = wmsProductInstock.productId, + activeFlag = "1", + updateBy = "WCS", + updateDate = DateTime.Now, + saleorderCode = wmsProductInstock.saleorderCode, + saleOrderId = wmsProductInstock.SaleOrderId, + stockType = "2", + productStockId = wmsProductInstock.productInstockId, + qualityStatus = "0", + createBy = "WCS", + createDate = DateTime.Now, + locationCode = wmsBaseLocation.locationCode, + warehouseFloor = 5, + totalAmount = 1, + instockDate = DateTime.Now, + productBatch = mesBasePalletInfo.materialBarcode, + palletInfoCode = mesBasePalletInfo.palletInfoCode, + frozenAmount = 0, + occupyAmount = 0, + planCode = wmsProductInstock.planCode, + planDetailCode = wmsProductInstock.planDetailCode, + warehouseId = 512 + }; + dbContext.Add(wmsProductStock); dbContext.Update(wmsBaseLocation); - - BaseEquip floorLineEquip = StaticData.BaseEquip.First(t => t.equipType == 1 && t.floorNo == 5); - BaseEquip eletorEquip = StaticData.BaseEquip.First(t => t.equipType == 2); - item.nextPointId = floorLineEquip.objid; - item.nextPointNo = floorLineEquip.equipNo; - item.fromFloorNo = 5; - item.floorNo = 1; - item.taskStatus = 6; - dbContext.Update(item); + dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete(); + dbContext.WcsTask.Where(t => t.objid == item.objid).Delete(); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 6 }); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog { cmdStatus = 6 }); + dbContext.SaveChanges(); + } + } + else if (item.taskType == 46)//该任务结束后,立刻生成一个新的返库任务,但是是否使用标志未0,等待mes通知 + { + WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.startPointId); + wmsBaseLocation.outstockFlag = "0"; + wmsBaseLocation.instockFlag = "1"; + wmsBaseLocation.containerCode = ""; + wmsBaseLocation.updateTime = DateTime.Now; + wmsBaseLocation.updateBy = "WCS"; + dbContext.Update(wmsBaseLocation); + dbContext.WcsTask.Where(t => t.objid == item.objid).Delete(); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 6 }); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog { cmdStatus = 6 }); + dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete(); + item.objid = StaticData.SnowId.NextId(); + item.currPointId = item.endPointId; + item.currPointNo = item.endPointNo; + item.endPointId = item.startPointId; + item.endPointNo = item.startPointNo; + item.startPointId = item.currPointId; + item.startPointNo = item.currPointNo; + item.taskType = 28; + item.taskStatus = 0; + item.useFlag = 0; + dbContext.Add(item); + WcsTaskLog wcsTaskLog = CoreMapper.Map(item); + dbContext.Add(wcsTaskLog); + dbContext.SaveChanges(); + } + else if (item.taskType == 28)//柜体拆分到原材料 + { + WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId); + wmsBaseLocation.locationStatus = "1"; + wmsBaseLocation.instockFlag = "0"; + wmsBaseLocation.containerCode = item.containerNo; + wmsBaseLocation.updateTime = DateTime.Now; + wmsBaseLocation.updateBy = "WCS"; + wmsBaseLocation.returnFlag = "1"; + var wmsRawStock = dbContext.WmsRawStock.FirstOrDefault(t => t.locationCode == wmsBaseLocation.locationCode); + if (wmsRawStock != null) + { + wmsRawStock.completeFlag = "0"; + wmsRawStock.updateDate = DateTime.Now; + wmsRawStock.updateBy = "WCS"; + dbContext.Update(wmsRawStock); + dbContext.Update(wmsBaseLocation); + dbContext.WcsTask.Where(t => t.objid == item.objid).Delete(); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 6 }); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog { cmdStatus = 6 }); dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete(); dbContext.SaveChanges(); } - else if (item.taskType == 37)//入库 + + } + else if (item.taskType == 47) + { + WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId); + wmsBaseLocation.instockFlag = "0"; + wmsBaseLocation.locationStatus = "1"; + wmsBaseLocation.containerCode = item.containerNo; + var mesBasePalletInfo = dbContext.MesBasePalletInfo.FirstOrDefault(t => t.palletInfoCode == item.containerNo); + if (mesBasePalletInfo != null) { - wmsBaseLocation.locationStatus = "1"; - wmsBaseLocation.instockFlag = "0"; - - - dbContext.Update(wmsBaseLocation); - BaseEquip floorLineEquip = StaticData.BaseEquip.First(t => t.equipType == 1 && t.floorNo == 5); - BaseEquip eletorEquip = StaticData.BaseEquip.First(t => t.equipType == 2); - item.nextPointId = floorLineEquip.objid; - item.nextPointNo = floorLineEquip.equipNo; - item.fromFloorNo = 5; - item.floorNo = 1; - item.taskStatus = 6; - dbContext.Update(item); - dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete(); - dbContext.SaveChanges(); - + var mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == mesBasePalletInfo.materialBarcode); + if (mesBaseBarcodeInfo != null) + { + WmsRawStock wmsRawStock = new() + { + palletInfoCode = mesBasePalletInfo.palletInfoCode, + activeFlag = "1", + createBy = "WCS", + createDate = DateTime.Now, + frozenAmount = 0, + instockDate = DateTime.Now, + locationCode = wmsBaseLocation.locationCode, + occupyAmount = 0, + warehouseFloor = 5, + stockType = "1", + totalAmount = 1, + saleOrderId = 0, + supplierId = mesBaseBarcodeInfo.manufacturerId, + materialId = mesBasePalletInfo.materialId, + qualityStatus = "0", + rawStockId = StaticData.SnowId.NextId(), + completeFlag = "1", + instockBatch = mesBaseBarcodeInfo.batchCode, + updateBy = "WCS", + updateDate = DateTime.Now, + warehouseId = 511 + }; + dbContext.Add(wmsRawStock); + dbContext.Add(wmsBaseLocation); + dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete(); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog { cmdStatus = 6 }); + dbContext.WcsTask.Where(t => t.objid == item.objid).Delete(); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 6 }); + dbContext.SaveChanges(); + } } } } } } + break; } - //foreach (var item in taskList) - //{ - // SendAndUpdateTask(item); - //} } catch (Exception ex) { @@ -297,102 +777,5 @@ namespace Khd.Core.Wcs.Wcs } - public List GetTask(int floorNo, string equipNo) - { - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - List wcsTask = new List(); - var wareHouseList = StaticData.WmsBaseWarehouse.ToList(); - var equip = StaticData.BaseEquip.Where(t => t.floorNo == floorNo && t.equipType == 4).FirstOrDefault(); - //入库类型 - List taskInType = new() { 1, 3, 5, 7 }; - List taskOutType = new() { 2, 4, 6, 8 }; - try - { - //获取条码号,如果该条码任务存在就继续任务,如果条码不存在,创建入库任务并调度agv - var taskList = StaticData.WcsTask.Where(t => t.nextPointId == equip.objid).ToList(); - if (taskList.Count() == 0) - { return null; } - wcsTask = taskList; - } - catch (Exception ex) - { - LogManager.Info(floorNo + "楼AGV异常" + ex.Message); - throw; - } - return wcsTask; - } - - public void SendAndUpdateTask(WcsTask task) - { - //获取 - if (task == null) return; - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - WcsToWms wcsToWms = new WcsToWms(); - //首先判断是否已下发指令 - var cmd = dbContext.WcsCmd.Where(t => t.taskId == task.objid).FirstOrDefault(); - var locList = dbContext.WmsBaseLocation.Where(t => t.activeFlag == "1").ToList(); - if (locList.Count == 0) return; - //指令表存在说明已下发 - if (cmd == null) - { //获取下发agv指令 - string ip = ""; int port = 0; string url = ""; - RequestAGVTaskDto agvtask = new RequestAGVTaskDto(); - agvtask.reqCode = task.objid.ToString(); - //var json = JsonConvert.SerializeObject(agvtask); - //HttpHelper.SendPostMessage(ip, port, url, json); - agvtask.positionCodePath = new List(); - Position p = new Position(); - WmsBaseLocation putPos = new WmsBaseLocation(); //放料点 - WmsBaseLocation setPos = new WmsBaseLocation(); //取料点 - if (task.taskType == 5) //入库 - { - setPos = locList.Where(t => t.locationId == task.nextPointId).FirstOrDefault(); - } - else - { - setPos = locList.Where(t => t.locationId == task.nextPointId).FirstOrDefault(); - } - putPos = locList.Where(t => t.locationId == task.nextPointId).FirstOrDefault(); - p.positionCode = setPos?.agvPositionCode; - p.type = ""; - agvtask.positionCodePath.Add(p); - p.positionCode = putPos?.agvPositionCode; - p.type = ""; - //取料点 - agvtask.positionCodePath.Add(p); - agvtask.taskTyp = ""; - //给agv创建任务 - var reponseMessage = wcsToWms.genAgvSchedulingTask(agvtask); - if (reponseMessage != null) - { - - } - //未下发给agv下发指令 - WcsCmd taskCmd = new WcsCmd() - { - taskId = task.objid, - cmdType = task.taskType, - serialNo = task.serialNo, - equipmentNo = task.equipmentNo, - cmdStatus = 1, - createBy = FloorNo + "楼AGV", - createTime = DateTime.Now, - }; - dbContext.Add(taskCmd); - dbContext.SaveChanges(); - //更新任务表 - dbContext.WcsTask.Where(t => t.objid == task.objid).Update(t => new WcsTask() - { - currPointId = task.currPointId, - currPointNo = task.currPointNo, - nextPointId = task.nextPointId, - nextPointNo = task.nextPointNo, - updateTime = DateTime.Now, - updateBy = "agv出库", - }); - } - } } } diff --git a/src/Khd.Core.Wcs/Wcs/FiveFloorBearAgv.cs b/src/Khd.Core.Wcs/Wcs/FiveFloorBearAgv.cs index 2319d77..84c609f 100644 --- a/src/Khd.Core.Wcs/Wcs/FiveFloorBearAgv.cs +++ b/src/Khd.Core.Wcs/Wcs/FiveFloorBearAgv.cs @@ -1,6 +1,7 @@ using Khd.Core.Domain.Dto.webapi; using Khd.Core.Domain.Models; using Khd.Core.EntityFramework; +using Khd.Core.Library.Mapper; using Khd.Core.Wcs.Global; using Masuit.Tools.Logging; using Microsoft.Extensions.DependencyInjection; @@ -15,7 +16,10 @@ using Z.EntityFramework.Plus; namespace Khd.Core.Wcs.Wcs { - internal class FiveFloorBearAgv + /// + /// 背负式AGV + /// + public class FiveFloorBearAgv { List ScanPoint { get; set; }//点位信息 @@ -66,26 +70,26 @@ namespace Khd.Core.Wcs.Wcs using var scope = _host.Services.CreateScope(); using var dbContext = scope.ServiceProvider.GetRequiredService(); List taskType = new() { 1, 3, 5, 7 }; + BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.objid == agvID); while (true) { try { dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); var taskList = dbContext.WcsTask - .Where(t => t.useFlag == 1) .Where(t => t.nextPointId == agvID) .OrderBy(t => t.createTime).ToList(); if (taskList.Count == 0) { LogManager.Info(FloorNo + "楼AGV无任务"); } - foreach (var item in taskList) + foreach (var item in taskList)//出库 { if (item.taskStatus == 0)//下发任务 { BaseEquip startEquip = StaticData.BaseEquip.First(t => t.objid == item.startPointId); BaseEquip endEquip = StaticData.BaseEquip.First(t => t.objid == item.endPointId); - BaseDictionary baseDictionary = dbContext.BaseDictionary.First(t=>t.objid==item.taskType); + BaseDictionary baseDictionary = dbContext.BaseDictionary.First(t => t.objid == item.taskType); WcsCmd wcsCmd = new() { objid = StaticData.SnowId.NextId(), @@ -109,19 +113,19 @@ namespace Khd.Core.Wcs.Wcs new () { positionCode=wcsCmd.currPointNo, - type="00" + type=baseDictionary.agvType }, new () { positionCode=wcsCmd.nextPointNo, - type="00" + type=baseDictionary.agvType } }, - taskTyp=baseDictionary.dicValue, + taskTyp = baseDictionary.dicValue, ctnrTyp = "2", }; string message = JsonConvert.SerializeObject(agvTask); - string result = HttpHelper.SendPostMessage("172.16.12.24", 8182, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); var reponseMessage = JsonConvert.DeserializeObject(result); if (reponseMessage != null && reponseMessage.code == "0") { @@ -129,6 +133,9 @@ namespace Khd.Core.Wcs.Wcs wcsCmd.cmdStatus = 1; item.taskStatus = 1; dbContext.Update(item); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 1 }); + WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd); + dbContext.Add(wcsCmdLog); dbContext.Add(wcsCmd); dbContext.SaveChanges(); } @@ -139,56 +146,70 @@ namespace Khd.Core.Wcs.Wcs } else { - WcsCmd? wcsCmd = dbContext.WcsCmd.FirstOrDefault(t => t.taskId == item.objid); - if (wcsCmd != null) + if (item.useFlag == 1)//接料位-工位默认为1,工位到接料位需Mes通知 { - if (wcsCmd.cmdStatus == 3) + WcsCmd? wcsCmd = dbContext.WcsCmd.FirstOrDefault(t => t.taskId == item.objid); + if (wcsCmd != null) { - var agvTask = new RequestAGVTaskDto + if (wcsCmd.cmdStatus == 3) { - reqCode = StaticData.SnowId.NextId().ToString(), - taskCode = wcsCmd.taskCode - }; - string message = JsonConvert.SerializeObject(agvTask); - string result = HttpHelper.SendPostMessage("172.16.12.24", 8182, "rcms/services/rest/hikRpcService/continueTask", message); - ReponseMessage? reponseMessage = JsonConvert.DeserializeObject(result); - if (reponseMessage != null && reponseMessage.message == "成功") + var agvTask = new RequestAGVTaskDto + { + reqCode = StaticData.SnowId.NextId().ToString(), + taskCode = wcsCmd.taskCode + }; + string message = JsonConvert.SerializeObject(agvTask); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/continueTask", message); + ReponseMessage? reponseMessage = JsonConvert.DeserializeObject(result); + if (reponseMessage != null && reponseMessage.message == "成功") + { + dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmd() { cmdStatus = 4 }); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog() { cmdStatus = 4 }); + dbContext.WcsTask.Where(t => t.objid == item.objid).Update(t => new WcsTask() { taskStatus = 4 }); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 4 }); + dbContext.SaveChanges(); + } + } + else if (wcsCmd.cmdStatus == 5) { - dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Update(t => t.cmdStatus == 4); - dbContext.WcsTask.Where(t => t.objid == item.objid).Update(t => t.taskStatus == 4); + dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmd() { cmdStatus = 6 }); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog() { cmdStatus = 6 }); + dbContext.WcsTask.Where(t => t.objid == item.objid).Update(t => new WcsTask() { taskStatus = 6 }); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 6 }); dbContext.SaveChanges(); } - } - else if (wcsCmd.cmdStatus == 5) - { - dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Update(t=>t.cmdStatus==6); - dbContext.WcsTask.Where(t => t.objid == item.objid).Update(t => t.taskStatus == 6); - dbContext.SaveChanges(); - } - else if (wcsCmd.cmdStatus == 7) - { - var agvTask = new RequestAGVTaskDto + else if (wcsCmd.cmdStatus == 7) { - reqCode = StaticData.SnowId.NextId().ToString(), - taskCode = wcsCmd.taskCode - }; - string message = JsonConvert.SerializeObject(agvTask); - string result = HttpHelper.SendPostMessage("172.16.12.24", 8182, "rcms/services/rest/hikRpcService/continueTask", message); - ReponseMessage? reponseMessage = JsonConvert.DeserializeObject(result); - if (reponseMessage != null && reponseMessage.message == "成功") - { - dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete(); - dbContext.WcsTask.Where(t => t.objid == item.objid).Delete(); - dbContext.SaveChanges(); + var agvTask = new RequestAGVTaskDto + { + reqCode = StaticData.SnowId.NextId().ToString(), + taskCode = wcsCmd.taskCode + }; + string message = JsonConvert.SerializeObject(agvTask); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/continueTask", message); + ReponseMessage? reponseMessage = JsonConvert.DeserializeObject(result); + if (reponseMessage != null && reponseMessage.message == "成功") + { + dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete(); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog() { cmdStatus = 8 }); + dbContext.WcsTask.Where(t => t.objid == item.objid).Delete(); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 8 }); + if (item.taskType == 48) + { + dbContext.WmsRawReturn.Where(t => t.rawReturnId == item.orderId).Update(t => new WmsRawReturn { executeStatus = "2" }); + } + else + { + + } + dbContext.SaveChanges(); + } } } } } + break; } - //foreach (var item in taskList) - //{ - // SendAndUpdateTask(item); - //} } catch (Exception ex) { diff --git a/src/Khd.Core.Wcs/Wcs/FiveFloorCTU.cs b/src/Khd.Core.Wcs/Wcs/FiveFloorCTU.cs index e50ac2d..a2b1ce5 100644 --- a/src/Khd.Core.Wcs/Wcs/FiveFloorCTU.cs +++ b/src/Khd.Core.Wcs/Wcs/FiveFloorCTU.cs @@ -1,11 +1,18 @@ -using Khd.Core.Domain.Dto.webapi; +using AngleSharp.Css.Dom; +using Castle.Core.Logging; +using Khd.Core.Domain.Dto.webapi; using Khd.Core.Domain.Models; using Khd.Core.EntityFramework; +using Khd.Core.Library.Mapper; +using Khd.Core.Plc; +using Khd.Core.Plc.S7; using Khd.Core.Wcs.Global; +using Masuit.Tools; using Masuit.Tools.Logging; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Newtonsoft.Json; +using System; using Z.EntityFramework.Plus; namespace Khd.Core.Wcs.Wcs @@ -17,10 +24,12 @@ namespace Khd.Core.Wcs.Wcs { List ScanPoint { get; set; }//点位信息 private readonly IHost _host; - private readonly Plc.S7.Plc _plc; + private Plc.S7.Plc _plc; private readonly BasePlcpoint LineRFID; private readonly BasePlcpoint isarrive; private readonly BasePlcpoint isput; + private bool isWait = false; + private bool isSendWait = false; int FloorNo { get; set; } string EquipNo = ""; int CTUID = 11; @@ -57,8 +66,12 @@ namespace Khd.Core.Wcs.Wcs Thread FlowPointThread = new Thread(MonitorInLocatorPoint); FlowPointThread.Start(); - //Thread FlowCTUInWareThread = new Thread(MonitorInWare); - //FlowCTUInWareThread.Start(); + Thread FlowCTUInWareThread = new Thread(MonitorInWare); + FlowCTUInWareThread.Start(); + + Thread CtuWaitThread = new Thread(CtuWaitLogic); + CtuWaitThread.Start(); + Console.WriteLine(DateTime.Now + ":五楼CTU上件扫描监听启动"); LogManager.Info("五楼CTU上件扫描监听启动"); } @@ -72,71 +85,155 @@ namespace Khd.Core.Wcs.Wcs try { dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); - var rfid = this._plc.Read(LineRFID.plcpointAddress); + var rfid = this._plc.ReadRFID(LineRFID.plcpointAddress); var isArrive = this._plc.Read(isarrive.plcpointAddress); if (rfid != null && isArrive != null && Convert.ToInt32(isArrive) == 1) { - //根据rfid找到库位 - //生成入库任务 - var wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.containerCode == rfid.ToString()); - BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.equipNo == "FL051"); - BaseEquip ctuEquip = StaticData.BaseEquip.First(t => t.objid == 11); - if (wmsBaseLocation != null) + rfid = rfid[rfid.IndexOf('C')..]; + WcsTask? task = dbContext.WcsTask.FirstOrDefault(t => t.containerNo == rfid); + if (task == null) { - var wcsTask = new WcsTask() + //根据rfid找到库位 + //生成入库任务 + var wmsBaseLocation = dbContext.WmsBaseLocation.FirstOrDefault(t => t.containerCode == rfid); + if (wmsBaseLocation != null) { - objid = StaticData.SnowId.NextId(), - startPointId = baseEquip.objid, - startPointNo = baseEquip.agvPositionCode, - currPointId = baseEquip.objid, - currPointNo = baseEquip.agvPositionCode, - nextPointId = ctuEquip.objid, - nextPointNo = ctuEquip.equipNo, - endPointId = wmsBaseLocation.locationId, - endPointNo = wmsBaseLocation.agvPositionCode, - taskType = 1, - taskStatus = 0, - floorNo = 5, - ud1 = "0",//是否是最后一个任务 - containerNo = rfid.ToString(), - equipmentNo = baseEquip.equipNo, - createBy = FloorNo + "楼CTU", - createTime = DateTime.Now, - }; - dbContext.Add(wcsTask); - dbContext.SaveChanges(); + BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.equipNo == "FL051"); + BaseEquip ctuEquip = StaticData.BaseEquip.First(t => t.objid == 11); + if (wmsBaseLocation != null) + { + var wcsTask = new WcsTask() + { + objid = StaticData.SnowId.NextId(), + startPointId = baseEquip.objid, + startPointNo = baseEquip.agvPositionCode, + currPointId = baseEquip.objid, + currPointNo = baseEquip.agvPositionCode, + nextPointId = ctuEquip.objid, + nextPointNo = ctuEquip.equipNo, + endPointId = wmsBaseLocation.locationId, + endPointNo = wmsBaseLocation.agvPositionCode, + taskType = 29, + taskStatus = 0, + floorNo = 5, + containerNo = rfid.ToString(), + equipmentNo = baseEquip.equipNo, + createBy = FloorNo + "楼CTU", + createTime = DateTime.Now, + }; + wmsBaseLocation.instockFlag = "1"; + wmsBaseLocation.locationStatus = "2"; + dbContext.Update(wmsBaseLocation); + dbContext.Add(wcsTask); + //WcsTaskLog wcsTaskLog = CoreMapper.Map(wcsTask); + //dbContext.WcsTaskLog.Add(wcsTaskLog); + dbContext.SaveChanges(); + } + } } } } - catch + catch(Exception ex) { + if (ex is PlcException) + { + try + { + this._plc = new Plc.S7.Plc(this._plc.CPU, this._plc.IP, this._plc.Port, this._plc.Rack, this._plc.Slot); + this._plc.Open(); + } + catch + { + } + } } + Thread.Sleep(1000); } } + /// + /// 预执行任务下发 + /// + private void CtuWaitLogic() + { + BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.objid == CTUID); + BaseEquip Fl051 = StaticData.BaseEquip.First(t => t.objid == 19);//入库输送线 + while (true) + { + try + { + while (isWait) + { + var waitTask = new + { + reqCode = StaticData.SnowId.NextId().ToString(), + positionCode = "CTU_IN", + nextTask = 1200 + }; + string waitMessage = JsonConvert.SerializeObject(waitTask); + string waitResult = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genPreScheduleTask", waitMessage); + var waitReponse = JsonConvert.DeserializeObject(waitResult); + if (waitReponse != null && waitReponse.code == "0") + { + isSendWait = true; + } + else + { + LogManager.Info("CTU下发预执行任务失败:\nwaitTask:" + waitMessage + "\nwaitResult:" + waitResult); + } + Thread.Sleep(1000 * 60 * 10);//每10分钟重新下发预执行任务 + } + isSendWait = false; + } + catch (Exception ex) + { + LogManager.Error(ex); + } + Thread.Sleep(3000); + } + } + + /// + /// 监控上件扫描点位 + /// public void MonitorInLocatorPoint() { List taskType = new() { 1, 3, 5, 7 }; using var scope = _host.Services.CreateScope(); using var dbContext = scope.ServiceProvider.GetRequiredService(); + BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.objid == CTUID); while (true) { try { dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); - var taskList = dbContext.WcsTask.Where(t => t.nextPointId == CTUID).ToList(); + var taskList = dbContext.WcsTask.Where(t => t.nextPointId == CTUID).OrderBy(t=>t.createTime).ToList(); if (taskList.Count == 0) { LogManager.Info(FloorNo + "楼CTU无任务"); } foreach (var item in taskList) { + if (!taskList.Where(t => t.taskType == 29 && t.ud1 == "2").Any()) + { + if (item.ud1 == "1") + { + ExecuteInTask(baseEquip); + WcsOutstockLock wcsOutstockLock = dbContext.WcsOutstockLock.Where(t => t.warehouseId == 512).First(); + wcsOutstockLock.qty = 0; + wcsOutstockLock.boxStatus = 0; + dbContext.Update(wcsOutstockLock); + isWait = false; + item.ud1 = "2"; + dbContext.Update(item); + } + } if (item.taskStatus == 0)//CTU会同时生成多个任务,生成就下发? { if (item.taskType == 30)//出库任务 { - BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.objid == item.endPointId); + BaseEquip endEquip = StaticData.BaseEquip.First(t => t.objid == item.endPointId); WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.startPointId); var wcsCmd = new WcsCmd() { @@ -150,8 +247,8 @@ namespace Khd.Core.Wcs.Wcs createBy = FloorNo + "楼CTU", currPointId = wmsBaseLocation.locationId, currPointNo = wmsBaseLocation.agvPositionCode, - nextPointId = baseEquip.objid, - nextPointNo = baseEquip.agvPositionCode, + nextPointId = endEquip.objid, + nextPointNo = endEquip.agvPositionCode, taskCode = null }; var agvTask = new RequestAGVTaskDto @@ -174,21 +271,31 @@ namespace Khd.Core.Wcs.Wcs taskTyp = "F504" }; string message = JsonConvert.SerializeObject(agvTask); - string result = HttpHelper.HttpPost("http://172.16.12.24:8182/rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); var reponseMessage = JsonConvert.DeserializeObject(result); - if (reponseMessage != null && reponseMessage.message == "成功") + if (reponseMessage != null && reponseMessage.code == "0") { wcsCmd.taskCode = reponseMessage.data; wcsCmd.cmdStatus = 1; item.taskStatus = 1; dbContext.Update(item); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 1 }); + WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd); + dbContext.Add(wcsCmdLog); + WcsOutstockLock wcsOutstockLock = dbContext.WcsOutstockLock.Where(t => t.warehouseId == 512).First(); + wcsOutstockLock.qty = wcsOutstockLock.qty + 1; + dbContext.Update(wcsOutstockLock); dbContext.WcsCmd.Add(wcsCmd); dbContext.SaveChanges(); } + else + { + LogManager.Info("CTU下发出库任务失败:" + reponseMessage?.message); + } } else if (item.taskType == 29)//入库任务 { - BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.objid == item.startPointId); + BaseEquip startEquip = StaticData.BaseEquip.First(t => t.objid == item.startPointId); WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId); var wcsCmd = new WcsCmd() { @@ -202,13 +309,16 @@ namespace Khd.Core.Wcs.Wcs createBy = FloorNo + "楼CTU", nextPointId = wmsBaseLocation.locationId, nextPointNo = wmsBaseLocation.agvPositionCode, - currPointId = baseEquip.objid, - currPointNo = baseEquip.agvPositionCode, + currPointId = startEquip.objid, + currPointNo = startEquip.agvPositionCode, }; - var agvTask = new RequestAGVTaskDto + isWait = true; + if (isSendWait) { - reqCode = StaticData.SnowId.NextId().ToString(), - positionCodePath = new List + var agvTask = new + { + reqCode = StaticData.SnowId.NextId().ToString(), + positionCodePath = new List { new() { @@ -221,21 +331,38 @@ namespace Khd.Core.Wcs.Wcs type = "05" }, }, - ctnrTyp = "1", - taskTyp = "F503" - }; - string message = JsonConvert.SerializeObject(agvTask); - string result = HttpHelper.HttpPost("http://172.16.12.24:8182/rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); - var reponseMessage = JsonConvert.DeserializeObject(result); - if (reponseMessage != null && reponseMessage.message == "成功") - { - wcsCmd.taskCode = reponseMessage.data; - wcsCmd.cmdStatus = 1; - item.taskStatus = 1; - dbContext.Update(wmsBaseLocation); - dbContext.Update(item); - dbContext.Add(wcsCmd); - dbContext.SaveChanges(); + ctnrTyp = "1", + taskTyp = "F503" + }; + string message = JsonConvert.SerializeObject(agvTask); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); + var reponseMessage = JsonConvert.DeserializeObject(result); + if (reponseMessage != null && reponseMessage.code == "0") + { + wcsCmd.taskCode = reponseMessage.data; + wcsCmd.cmdStatus = 1; + item.taskStatus = 1; + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 1 }); + WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd); + dbContext.Add(wcsCmdLog); + dbContext.Update(item); + dbContext.Add(wcsCmd); + int ctuTaskCount = dbContext.WcsTask.Where(t => t.taskType == 29 || t.taskType == 30).Count(); + WcsOutstockLock wcsOutstockLock = dbContext.WcsOutstockLock.Where(t => t.warehouseId == 512).First(); + if (ctuTaskCount >= 6 || wcsOutstockLock.qty == ctuTaskCount)//如果CTU当前任务数量很多,取消预执行任务 + { + ExecuteInTask(baseEquip); + wcsOutstockLock.qty = 0; + wcsOutstockLock.boxStatus = 0; + dbContext.Update(wcsOutstockLock); + isWait = false; + } + dbContext.SaveChanges(); + } + else + { + LogManager.Info("CTU下发入库任务失败:" + reponseMessage?.message); + } } } } @@ -246,10 +373,11 @@ namespace Khd.Core.Wcs.Wcs { if (wcsCmd.cmdStatus == 3) { - var canOut = this._plc.Read(""); - if (canOut != null && Convert.ToInt64(canOut) == 1) + + if (item.taskType == 30) { - if (item.taskType == 30) + var canOut = this._plc.Read(isput.plcpointAddress); + if (canOut != null && Convert.ToInt64(canOut) == 1) { var agvTask = new { @@ -258,40 +386,52 @@ namespace Khd.Core.Wcs.Wcs type = 2 }; string message = JsonConvert.SerializeObject(agvTask); - string result = HttpHelper.HttpPost("http://172.16.12.24:8182/rcms/services/rest/hikRpcService/boxApplyPass", message); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/boxApplyPass", message); ReponseMessage? reponseMessage = JsonConvert.DeserializeObject(result); - if (reponseMessage != null && reponseMessage.message == "成功") + if (reponseMessage != null && reponseMessage.code == "0") { - wcsCmd.cmdStatus = 4; - dbContext.Update(wcsCmd); + dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmd() { cmdStatus = 4 }); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog() { cmdStatus = 4 }); + dbContext.WcsTask.Where(t => t.objid == item.objid).Update(t => new WcsTask() { taskStatus = 4 }); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 4 }); dbContext.SaveChanges(); } + else + { + LogManager.Info("CTU第一次下发继续任务失败:" + reponseMessage?.message); + } } - else if(item.taskType ==29) + } + if (item.taskType == 29) + { + var agvTask = new { - var agvTask = new - { - reqCode = StaticData.SnowId.NextId().ToString(), - taskCode = wcsCmd.taskCode, - type = 1 - }; - string message = JsonConvert.SerializeObject(agvTask); - string result = HttpHelper.HttpPost("http://172.16.12.24:8182/rcms/services/rest/hikRpcService/boxApplyPass", message); - ReponseMessage? reponseMessage = JsonConvert.DeserializeObject(result); - if (reponseMessage != null && reponseMessage.message == "成功") - { - wcsCmd.cmdStatus = 4; - dbContext.Update(wcsCmd); - dbContext.SaveChanges(); - } + reqCode = StaticData.SnowId.NextId().ToString(), + taskCode = wcsCmd.taskCode, + type = 1 + }; + string message = JsonConvert.SerializeObject(agvTask); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/boxApplyPass", message); + ReponseMessage? reponseMessage = JsonConvert.DeserializeObject(result); + if (reponseMessage != null && reponseMessage.code == "0") + { + dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmd() { cmdStatus = 4 }); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog() { cmdStatus = 4 }); + dbContext.WcsTask.Where(t => t.objid == item.objid).Update(t => new WcsTask() { taskStatus = 4 }); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 4 }); + dbContext.SaveChanges(); + } + else + { + LogManager.Info("CTU第二次下发继续任务失败:" + reponseMessage?.message); } } } else if (wcsCmd.cmdStatus == 5) { //任务完成 - //如果是入库任务,更新库存信息,并删除任务 - if (taskType.Contains(item.taskType)) + //如果是出库任务,更新库存信息,并删除任务 + if (item.taskType == 30) { WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation .First(t => t.locationId == item.startPointId && t.warehouseFloor == 5); @@ -300,29 +440,22 @@ namespace Khd.Core.Wcs.Wcs dbContext.Update(wmsBaseLocation); dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete(); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog() { cmdStatus = 6 }); dbContext.WcsTask.Where(t => t.objid == item.objid).Delete(); + dbContext.WcsTaskLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsTaskLog() { taskStatus = 6 }); dbContext.SaveChanges(); } - else//如果是出库任务,更新库存信息,下一个任务为提升机 + else//如果是入库任务,更新库存信息,下一个任务为提升机 { WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation - .First(t => t.locationId == item.startPointId && t.warehouseFloor == 5); - if (item.taskType == 29) - { - wmsBaseLocation.outstockFlag = "0"; - wmsBaseLocation.locationStatus = "1"; - dbContext.Update(wmsBaseLocation); - } - - BaseEquip floorLineEquip = StaticData.BaseEquip.First(t => t.equipType == 1 && t.floorNo == 5); - BaseEquip eletorEquip = StaticData.BaseEquip.First(t => t.equipType == 2); - item.nextPointId = floorLineEquip.objid; - item.nextPointNo = floorLineEquip.equipNo; - item.fromFloorNo = 5; - item.floorNo = 1; - item.taskStatus = 6; - dbContext.Update(item); + .First(t => t.locationId == item.endPointId && t.warehouseFloor == 5); + wmsBaseLocation.instockFlag = "0"; + wmsBaseLocation.locationStatus = "1"; + dbContext.Update(wmsBaseLocation); dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete(); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog() { cmdStatus = 6 }); + dbContext.WcsTask.Where(t => t.objid == item.objid).Delete(); + dbContext.WcsTaskLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsTaskLog() { taskStatus = 6 }); dbContext.SaveChanges(); } } @@ -341,7 +474,34 @@ namespace Khd.Core.Wcs.Wcs } } - + /// + /// 通知CTU取消预执行任务 + /// + /// + /// + private void ExecuteInTask(BaseEquip baseEquip) + { + //while (isWait) + { + var executeTask = new + { + reqCode = StaticData.SnowId.NextId().ToString(), + positionCode = "CTU_IN", + nextTask = -1 + }; + string executeMessage = JsonConvert.SerializeObject(executeTask); + string executeResult = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genPreScheduleTask", executeMessage); + var executeReponse = JsonConvert.DeserializeObject(executeResult); + if (executeReponse != null && executeReponse.code == "0") + { + LogManager.Info("下发CTU执行入库任务成功"); + } + else + { + LogManager.Info("下发CTU执行入库任务失败"); + } + } + } /// /// 下发任务 diff --git a/src/Khd.Core.Wcs/Wcs/FiveFloorLine.cs b/src/Khd.Core.Wcs/Wcs/FiveFloorLine.cs index 9c5b267..b6defab 100644 --- a/src/Khd.Core.Wcs/Wcs/FiveFloorLine.cs +++ b/src/Khd.Core.Wcs/Wcs/FiveFloorLine.cs @@ -1,120 +1,120 @@ -using Khd.Core.Domain.Dto.webapi; -using Khd.Core.Domain.Models; -using Khd.Core.EntityFramework; -using Khd.Core.Wcs.Global; -using Masuit.Tools.Logging; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Z.EntityFramework.Plus; +//using Khd.Core.Domain.Dto.webapi; +//using Khd.Core.Domain.Models; +//using Khd.Core.EntityFramework; +//using Khd.Core.Wcs.Global; +//using Masuit.Tools.Logging; +//using Microsoft.Extensions.DependencyInjection; +//using Microsoft.Extensions.Hosting; +//using Z.EntityFramework.Plus; -namespace Khd.Core.Wcs.Wcs -{ - /// - /// 五楼人工分拣输送线 - /// - public class FiveFloorLine - { - List ScanPoint { get; set; }//点位信息 - private readonly IHost _host; - private readonly Plc.S7.Plc _plc; - private readonly BasePlcpoint LineRFID; - private readonly BasePlcpoint IsArrive; - private readonly BasePlcpoint IsPut; - int FloorNo { get; set; } - string EquipNo = ""; - int CTUID = 11; - public FiveFloorLine(IHost host, Plc.S7.Plc plc, int floor, string equipNo) - { - this._host = host; - this._plc = plc; - FloorNo = floor; - EquipNo = equipNo; - this.ScanPoint = StaticData.BasePlcpointList.Where(t => t.floorNo == floor).ToList();//加载当前站点所对应的点位 - this.LineRFID = this.ScanPoint.First(t => t.plcpointNo == "RFID5001"); - this.IsArrive = this.ScanPoint.First(t => t.plcpointNo.Contains("isarrive")); - this.IsPut = this.ScanPoint.First(t => t.plcpointNo == "isput"); +//namespace Khd.Core.Wcs.Wcs +//{ +// /// +// /// 五楼人工分拣输送线 +// /// +// public class FiveFloorLine +// { +// List ScanPoint { get; set; }//点位信息 +// private readonly IHost _host; +// private readonly Plc.S7.Plc _plc; +// private readonly BasePlcpoint LineRFID; +// private readonly BasePlcpoint IsArrive; +// private readonly BasePlcpoint IsPut; +// int FloorNo { get; set; } +// string EquipNo = ""; +// int CTUID = 11; +// public FiveFloorLine(IHost host, Plc.S7.Plc plc, int floor, string equipNo) +// { +// this._host = host; +// this._plc = plc; +// FloorNo = floor; +// EquipNo = equipNo; +// this.ScanPoint = StaticData.BasePlcpointList.Where(t => t.floorNo == floor).ToList();//加载当前站点所对应的点位 +// this.LineRFID = this.ScanPoint.First(t => t.plcpointNo == "RFID5001"); +// this.IsArrive = this.ScanPoint.First(t => t.plcpointNo.Contains("isarrive")); +// this.IsPut = this.ScanPoint.First(t => t.plcpointNo == "isput"); - //var lineRFID = this._plc.Read(NodeSettingCarNo.plcpointAddress); - try - { - //默认启动,清理plc的上位机写入点位值 - this._plc.Write(LineRFID.plcpointAddress, MainCentralControl.QingKongDianWei); - } - catch (Exception ex) - { - Console.WriteLine("楼层" + floor + " 初始化数据异常" + ex.Message); - LogManager.Error(ex); - } - } - /// - /// 启动上件扫描监听 - /// - public void StartPoint() - { +// //var lineRFID = this._plc.Read(NodeSettingCarNo.plcpointAddress); +// try +// { +// //默认启动,清理plc的上位机写入点位值 +// this._plc.Write(LineRFID.plcpointAddress, MainCentralControl.QingKongDianWei); +// } +// catch (Exception ex) +// { +// Console.WriteLine("楼层" + floor + " 初始化数据异常" + ex.Message); +// LogManager.Error(ex); +// } +// } +// /// +// /// 启动上件扫描监听 +// /// +// public void StartPoint() +// { - Thread FlowPointThread = new Thread(MonitorInLocatorPoint); - FlowPointThread.Start(); - Console.WriteLine(DateTime.Now+":五楼人工分拣输送线启动成功"); - LogManager.Info("五楼人工分拣输送线启动成功"); - } +// Thread FlowPointThread = new Thread(MonitorInLocatorPoint); +// FlowPointThread.Start(); +// Console.WriteLine(DateTime.Now+":五楼人工分拣输送线启动成功"); +// LogManager.Info("五楼人工分拣输送线启动成功"); +// } - public void MonitorInLocatorPoint() - { - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - while (true) - { - try - { - dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); - var rfid = this._plc.Read(LineRFID.plcpointAddress); - var isarrive = this._plc.Read(IsArrive.plcpointAddress); - //获取条码信息 - var palletNo = Convert.ToString(rfid); - var taskid = 0; - WcsToWms wcsToWms = new WcsToWms(); - continueTaskDto agvtask = new continueTaskDto(); - //入库:待取料 - if (rfid != null && isarrive != null) - { - //正常读到输送线信息 有到位信号,并且有托盘,获取条码信息 - if (Convert.ToInt32(isarrive) == 1) - { - var wcsTaskList = dbContext.WcsTask.Where(t => t.taskType == 7).ToList(); - var cmd = dbContext.WcsCmd.Where(t => t.containerNo == rfid && t.cmdStatus == 14).FirstOrDefault(); - if (cmd != null) - { - agvtask.reqCode = cmd.taskId.ToString(); - //给ctu下发继续任务指令 - wcsToWms.continueTask(agvtask); - } - } - } - //出库:取料完成待放料 - if (IsPut != null) - { - var cmdList = dbContext.WcsCmd.Where(t => t.cmdStatus == 15).ToList(); - if (cmdList == null) return; - foreach (var item in cmdList) - { - if (item != null) - { - agvtask.reqCode = item.taskId.ToString(); - //给ctu下发继续任务指令 - wcsToWms.continueTask(agvtask); - } - } - } - } - catch (Exception ex) - { - LogManager.Error(ex); - } - finally - { - Thread.Sleep(1000); - } - } - } - } -} +// public void MonitorInLocatorPoint() +// { +// using var scope = _host.Services.CreateScope(); +// using var dbContext = scope.ServiceProvider.GetRequiredService(); +// while (true) +// { +// try +// { +// dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); +// var rfid = this._plc.Read(LineRFID.plcpointAddress); +// var isarrive = this._plc.Read(IsArrive.plcpointAddress); +// //获取条码信息 +// var palletNo = Convert.ToString(rfid); +// var taskid = 0; +// WcsToWms wcsToWms = new WcsToWms(); +// continueTaskDto agvtask = new continueTaskDto(); +// //入库:待取料 +// if (rfid != null && isarrive != null) +// { +// //正常读到输送线信息 有到位信号,并且有托盘,获取条码信息 +// if (Convert.ToInt32(isarrive) == 1) +// { +// var wcsTaskList = dbContext.WcsTask.Where(t => t.taskType == 7).ToList(); +// var cmd = dbContext.WcsCmd.Where(t => t.containerNo == rfid && t.cmdStatus == 14).FirstOrDefault(); +// if (cmd != null) +// { +// agvtask.reqCode = cmd.taskId.ToString(); +// //给ctu下发继续任务指令 +// wcsToWms.continueTask(agvtask); +// } +// } +// } +// //出库:取料完成待放料 +// if (IsPut != null) +// { +// var cmdList = dbContext.WcsCmd.Where(t => t.cmdStatus == 15).ToList(); +// if (cmdList == null) return; +// foreach (var item in cmdList) +// { +// if (item != null) +// { +// agvtask.reqCode = item.taskId.ToString(); +// //给ctu下发继续任务指令 +// wcsToWms.continueTask(agvtask); +// } +// } +// } +// } +// catch (Exception ex) +// { +// LogManager.Error(ex); +// } +// finally +// { +// Thread.Sleep(1000); +// } +// } +// } +// } +//} diff --git a/src/Khd.Core.Wcs/Wcs/FiveFloorPoint.cs b/src/Khd.Core.Wcs/Wcs/FiveFloorPoint.cs index c86820c..e939791 100644 --- a/src/Khd.Core.Wcs/Wcs/FiveFloorPoint.cs +++ b/src/Khd.Core.Wcs/Wcs/FiveFloorPoint.cs @@ -1,6 +1,7 @@ using Khd.Core.Domain.Dto.webapi; using Khd.Core.Domain.Models; using Khd.Core.EntityFramework; +using Khd.Core.Library.Mapper; using Khd.Core.Plc; using Khd.Core.Wcs.Global; using Masuit.Tools.Logging; @@ -8,6 +9,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Newtonsoft.Json; using System.Security.Cryptography; +using Z.EntityFramework.Plus; namespace Khd.Core.Wcs.Wcs { @@ -82,10 +84,10 @@ namespace Khd.Core.Wcs.Wcs var palletNo = Convert.ToString(rfid); BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.equipType == 1 && t.floorNo == FloorNo); var wcsTask = dbContext.WcsTask.OrderBy(t => t.createTime) - .FirstOrDefault(t => t.floorNo == FloorNo && t.containerNo == palletNo); + .FirstOrDefault(t => t.containerNo == palletNo && t.nextPointId == baseEquip.objid); if (wcsTask != null) { - if (ITypes.Contains(wcsTask.taskType) && wcsTask.taskStatus == 4)//入库,提升机任务是完成状态 + if (wcsTask.taskStatus == 5)//入库,提升机任务是完成状态 { var wmsBaseLocations = dbContext.WmsBaseLocation.Where(t => t.warehouseFloor == FloorNo) .Where(t => t.activeFlag == "1") @@ -96,69 +98,137 @@ namespace Khd.Core.Wcs.Wcs //.Where(t => t.locationStatus == "1") //.Where(t => string.IsNullOrEmpty(t.containerCode)) .ToList(); - - List containerCodes = wmsBaseLocations.Where(t => t.locDeep == 1).Select(t => t.containerCode).ToList();//深库位的托盘 - List mesBasePalletInfos = dbContext.MesBasePalletInfo - .Where(t => t.materialId == wcsTask.materialId) - .Where(t => containerCodes.Contains(t.palletInfoCode)).ToList();//深库位的托盘的物料等于当前任务的物料 - - var bill = from a in mesBasePalletInfos - join b in wmsBaseLocations.Where(t => t.locDeep == 1) on a.palletInfoCode equals b.containerCode - select new { b };//等于当前任务的物料的托盘的库位信息 - - var outBill = from a in bill - from b in wmsBaseLocations - where a.b.layerNum == b.layerNum - && b.locDeep == 2 - && a.b.locRow == b.locRow - && a.b.locColumn == b.locColumn - && b.locationStatus == "1" - && b.outstockFlag == "0" - && b.instockFlag == "0" - && string.IsNullOrEmpty(b.containerCode) - select new { a.b };//在上面的基础上获取对应托盘的外侧库位的空库位信息 - - WmsBaseLocation? wmsBaseLocation = null; - wmsBaseLocation ??= outBill.FirstOrDefault()?.b;//先找相同物料的外侧库位 - wmsBaseLocation ??= wmsBaseLocations.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault(t => t.locDeep == 2);//找不到再找深库位 - wmsBaseLocation ??= wmsBaseLocations.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault();//找不到再找任意库位 - //深浅库位问题?库位入库优先级等 - - var AgvEquip = StaticData.BaseEquip.First(t => t.floorNo == 5 && t.equipType == 5);//背负Agv - if (wmsBaseLocations.Count > 0 && wmsBaseLocation != null) + if (wmsBaseLocations.Count > 0) { - wcsTask.taskStatus = 0;//创建状态 - wcsTask.updateTime = DateTime.Now; - wcsTask.currPointId = baseEquip.objid; - wcsTask.currPointNo = baseEquip.equipNo; - wcsTask.nextPointId = AgvEquip.objid; - wcsTask.nextPointNo = AgvEquip.equipNo; - wcsTask.endPointId = wmsBaseLocation.locationId; - wcsTask.endPointNo = wmsBaseLocation.locationCode; - wcsTask.useFlag = 0;//什么情况下需要确认 - wmsBaseLocation.instockFlag = "1"; - wmsBaseLocation.locationStatus = "2"; - dbContext.Update(wmsBaseLocation); - dbContext.Update(wcsTask); - dbContext.SaveChanges(); + List containerCodes = wmsBaseLocations.Where(t => t.locDeep == 1).Select(t => t.containerCode).ToList();//深库位的托盘 + List mesBasePalletInfos = dbContext.MesBasePalletInfo + .Where(t => t.materialId == wcsTask.materialId) + .Where(t => containerCodes.Contains(t.palletInfoCode)).ToList();//深库位的托盘的物料等于当前任务的物料 + + var bill = from a in mesBasePalletInfos + join b in wmsBaseLocations.Where(t => t.locDeep == 1) on a.palletInfoCode equals b.containerCode + select new { b };//等于当前任务的物料的托盘的库位信息 + + var outBill = from a in bill + from b in wmsBaseLocations + where a.b.layerNum == b.layerNum + && b.locDeep == 2 + && a.b.locRow == b.locRow + && a.b.locColumn == b.locColumn + && b.locationStatus == "1" + && b.outstockFlag == "0" + && b.instockFlag == "0" + && string.IsNullOrEmpty(b.containerCode) + select new { a.b };//在上面的基础上获取对应托盘的外侧库位的空库位信息 + + WmsBaseLocation? wmsBaseLocation = null; + wmsBaseLocation ??= outBill.FirstOrDefault()?.b;//先找相同物料的外侧库位 + wmsBaseLocation ??= wmsBaseLocations.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault(t => t.locDeep == 2);//找不到再找深库位 + wmsBaseLocation ??= wmsBaseLocations.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault();//找不到再找任意库位 + //深浅库位问题?库位入库优先级等 + + var AgvEquip = StaticData.BaseEquip.First(t => t.floorNo == 5 && t.equipType == 5);//背负Agv + if (wmsBaseLocations.Count > 0 && wmsBaseLocation != null) + { + wcsTask.taskStatus = 0;//创建状态 + wcsTask.updateTime = DateTime.Now; + wcsTask.currPointId = baseEquip.objid; + wcsTask.currPointNo = baseEquip.equipNo; + wcsTask.nextPointId = AgvEquip.objid; + wcsTask.nextPointNo = AgvEquip.equipNo; + wcsTask.endPointId = wmsBaseLocation.locationId; + wcsTask.endPointNo = wmsBaseLocation.locationCode; + if (wmsBaseLocation.warehouseId == 531) + { + wcsTask.taskType = 37; + wcsTask.useFlag = 1; + } + else if (wmsBaseLocation.warehouseId == 511 && wcsTask.fromFloorNo == 4) + { + wcsTask.taskType = 47;//?28? + wcsTask.useFlag = 0; + } + else if (wmsBaseLocation.warehouseId == 511) + { + wcsTask.taskType = 47; + wcsTask.useFlag = 1; + } + else + { + Console.WriteLine($"{DateTime.Now}:5楼接驳位查找入库类型失败"); + Thread.Sleep(1000); + continue; + } + wmsBaseLocation.instockFlag = "1"; + wmsBaseLocation.locationStatus = "2"; + dbContext.Update(wmsBaseLocation); + dbContext.Update(wcsTask); + WcsTaskLog wcsTaskLog = CoreMapper.Map(wcsTask); + dbContext.Add(wcsTaskLog); + dbContext.SaveChanges(); + } + else + { + Console.WriteLine(DateTime.Now + ":五楼接驳位调度入库任务,未找到库位"); + LogManager.Info("五楼接驳位调度入库任务,未找到库位"); + } + } + + } + else if (wcsTask.taskStatus == 6) //出库任务,小车任务是完成状态 + { + int? floor = 0; + var wmsProductOutstock = dbContext.WmsProductOutstock.FirstOrDefault(t => t.saleOrderId == wcsTask.orderId); + if (wmsProductOutstock != null) + { + var endEquip = StaticData.BaseEquip.FirstOrDefault(t => t.equipNo == wmsProductOutstock.endStationCode); + if (endEquip != null) + { + floor = endEquip.floorNo; + } } else { - Console.WriteLine(DateTime.Now + ":五楼接驳位调度入库任务,未找到库位"); + var wmsRawOutstock = dbContext.WmsRawOutstock.FirstOrDefault(t => t.orderId == wcsTask.orderId); + if (wmsRawOutstock != null) + { + BaseEquip endEquip = StaticData.BaseEquip.FirstOrDefault(t => t.equipNo == wmsRawOutstock.endStationCode); + if (endEquip != null) + { + floor = endEquip.floorNo; + } + } + } + if (floor == 0) + { + Console.WriteLine($"{DateTime.Now}:5楼接驳位未找到目的地楼层"); + LogManager.Info("5楼接驳位未找到目的地楼层"); + Thread.Sleep(1000); + continue; } - } - else//出库 - { BaseEquip nextEquip = StaticData.BaseEquip.First(t => t.equipType == 2);//提升机 wcsTask.nextPointId = nextEquip.objid; wcsTask.nextPointNo = nextEquip.equipNo; wcsTask.currPointId = baseEquip.objid; wcsTask.currPointNo = baseEquip.equipNo; wcsTask.fromFloorNo = FloorNo; - wcsTask.floorNo = 1;//出库到一楼 + wcsTask.taskType = 6;//成品出库 + wcsTask.floorNo = floor;//出库到一楼 wcsTask.taskStatus = 0; wcsTask.updateTime = DateTime.Now; dbContext.Update(wcsTask); + dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid) + .Update(t => new WcsTaskLog + { + nextPointId = nextEquip.objid, + nextPointNo = nextEquip.equipNo, + currPointId = baseEquip.objid, + currPointNo = baseEquip.equipNo, + fromFloorNo = FloorNo, + floorNo = floor, + taskStatus = 0, + updateTime = DateTime.Now, + }); dbContext.SaveChanges(); } } @@ -192,7 +262,7 @@ namespace Khd.Core.Wcs.Wcs //查询该条码绑定的物料信息 var material = StaticData.WmsWarehouseMaterial.Where(t => t.storageId == palletInfo.materialId).FirstOrDefault(); var wareHouse = wareHouseList.Where(t => t.warehouseId == material.warehouseId).FirstOrDefault(); - var dic = StaticData.BaseDictionary.Where(t => t.dicKey == "TaskType" && t.ud1 == "I" && t.dicField == wareHouse.warehouseInstockType).FirstOrDefault(); + var dic = StaticData.BaseDictionary.Where(t => t.dicKey == "TaskType" && t.agvType == "I" && t.dicField == wareHouse.warehouseInstockType).FirstOrDefault(); var equip = StaticData.BaseEquip.ToList(); var startEquip = equip.Where(t => t.equipNo == equipNo).FirstOrDefault(); var endPoint = wareHouseList.Where(t => t.warehouseFloor == floorNo).FirstOrDefault(); diff --git a/src/Khd.Core.Wcs/Wcs/FourthFloorPoint.cs b/src/Khd.Core.Wcs/Wcs/FourthFloorPoint.cs index 63d8ea3..1de147b 100644 --- a/src/Khd.Core.Wcs/Wcs/FourthFloorPoint.cs +++ b/src/Khd.Core.Wcs/Wcs/FourthFloorPoint.cs @@ -1,5 +1,7 @@ using Khd.Core.Domain.Models; using Khd.Core.EntityFramework; +using Khd.Core.Library.Mapper; +using Khd.Core.Plc; using Khd.Core.Plc.S7; using Khd.Core.Wcs.Global; using Masuit.Tools.Logging; @@ -21,7 +23,7 @@ namespace Khd.Core.Wcs.Wcs { private readonly int Floor; private readonly Plc.S7.Plc _plc; - private readonly IHost host; + private readonly IHost _host; private readonly BasePlcpoint LineRFID; private readonly BasePlcpoint LineSignal; private readonly BasePlcpoint WcsRun; @@ -29,7 +31,7 @@ namespace Khd.Core.Wcs.Wcs { Floor = floor; _plc = plc; - this.host = host; + this._host = host; this.LineRFID = StaticData.BasePlcpointList.First(t => t.floorNo == 4 && t.plcpointNo.Contains("RFID")); this.LineSignal = StaticData.BasePlcpointList.First(t => t.floorNo == 4 && t.plcpointNo.Contains("signal")); this.WcsRun = StaticData.BasePlcpointList.First(t => t.floorNo == 4 && t.plcpointNo.Contains("wcsrun")); @@ -37,103 +39,85 @@ namespace Khd.Core.Wcs.Wcs public void StartPoint() { - Thread MonitorInLocatorPointThread=new Thread(MonitorInLocatorPoint); + Thread MonitorInLocatorPointThread = new Thread(MonitorInLocatorPoint); MonitorInLocatorPointThread.Start(); } private void MonitorInLocatorPoint() { - List Itpyes = new() { 1, 3, 5, 7 }; - using var scope = host.Services.CreateScope(); + List ITypes = new List { 1, 3, 5, 7 }; + using var scope = _host.Services.CreateScope(); using var dbContext = scope.ServiceProvider.GetRequiredService(); while (true) { try { dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); - var RFID004Value = this._plc.Read(this.LineRFID.plcpointAddress); //一楼RFID 读 - var linesignal04Value = this._plc.Read(this.LineSignal.plcpointAddress); //到位信号 读 - var wcsrun04Value = this._plc.Read(this.WcsRun.plcpointAddress); //去向 写 - - //正常读到plc值 - if (linesignal04Value != null && RFID004Value != null) + //入库任务 + var rfid = this._plc.ReadRFID(LineRFID.plcpointAddress); + var isSignal = this._plc.Read(LineSignal.plcpointAddress); + if (rfid != null && isSignal != null) { - //正常托盘到位 - if (Convert.ToInt32(linesignal04Value) == 1) + + if (Convert.ToInt32(isSignal) == 1)//托盘到位 { - - //判断task表里没有该rfid的未完成的入库信息,未下发去向 - var task = dbContext.WcsTask.Where(t => t.containerNo == RFID004Value.ToString() && t.taskStatus < 1).FirstOrDefault(); - if (task == null) + BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.floorNo == 5 && t.equipType == 1); + var wcsTask = dbContext.WcsTask.FirstOrDefault(t => t.containerNo == rfid && t.nextPointId == baseEquip.objid); + if (wcsTask != null)//如果不是null { - //入库 - - //根据托盘号获取物料码 - var material = dbContext.MesBasePalletInfo.Where(t => t.palletInfoCode == RFID004Value.ToString()).FirstOrDefault(); - if (material != null) + int? floor = 0; + var wmsProductOutstock = dbContext.WmsProductOutstock.FirstOrDefault(t => t.saleOrderId == wcsTask.orderId); + if (wmsProductOutstock != null) { - var warehouseId = dbContext.WmsWarehouseMaterial.Where(t => t.storageType == "1" && t.storageId == material.materialId).FirstOrDefault()?.warehouseId; - if (warehouseId != null) + var endEquip = StaticData.BaseEquip.FirstOrDefault(t => t.equipNo == wmsProductOutstock.endStationCode); + if (endEquip != null) { - var TargetFloor = dbContext.WmsBaseWarehouse.Where(t => t.warehouseId == warehouseId).FirstOrDefault(); - if (TargetFloor != null) + floor = endEquip.floorNo; + } + } + else + { + var wmsRawOutstock = dbContext.WmsRawOutstock.FirstOrDefault(t => t.orderId == wcsTask.orderId); + if (wmsRawOutstock != null) + { + BaseEquip endEquip = StaticData.BaseEquip.FirstOrDefault(t => t.equipNo == wmsRawOutstock.endStationCode); + if (endEquip != null) { - //插入task表 - - var dic = StaticData.BaseDictionary.Where(t => t.dicKey == "TaskType" && t.ud1 == "I" && t.dicField == TargetFloor.warehouseInstockType).FirstOrDefault(); - if (dic != null) - { - var newTask = new WcsTask() - { - objid = StaticData.SnowId.NextId(), - serialNo = 1235, - equipmentNo = "F04", - taskType = Convert.ToInt32(dic.dicValue), - taskStatus = 0, - containerNo = RFID004Value.ToString(), - materialNo = material.materialCode, - materialId = material.materialId, - qty = Convert.ToInt32(material.bindAmount), - startPointId = 4, - startPointNo = "F04", - currPointId = 4, - currPointNo = "F04", - nextPointId = 6, - nextPointNo = "T01", - endPointId = warehouseId, - fromFloorNo = 4, - floorNo = TargetFloor.warehouseFloor, - useFlag = 1, - createBy = "四楼接驳位", - createTime = DateTime.Now, - remark = "四楼创建入库任务" - }; - dbContext.Add(newTask); - } + floor = endEquip.floorNo; } } } - } - else if (Itpyes.Contains(task.taskType)) - { - if (task.nextPointId != 6) + if (floor == 0) { - task.currPointId = 4; - task.currPointNo = "F04"; - task.nextPointId = 6; - task.nextPointNo = "T01"; - task.taskStatus = 0; - task.updateBy = "四楼接驳位线程"; - task.updateTime = DateTime.Now; - task.remark = "四楼创建入库任务"; - dbContext.WcsTask.Update(task); - dbContext.SaveChanges(); + Console.WriteLine($"{DateTime.Now}:4楼接驳位未找到目的地楼层"); + LogManager.Info("4楼接驳位未找到目的地楼层"); + Thread.Sleep(1000); + continue; } - } - //出库 - else - { - + BaseEquip nextEquip = StaticData.BaseEquip.First(t => t.equipType == 2);//提升机 + wcsTask.nextPointId = nextEquip.objid; + wcsTask.nextPointNo = nextEquip.equipNo; + wcsTask.currPointId = baseEquip.objid; + wcsTask.currPointNo = baseEquip.equipNo; + wcsTask.fromFloorNo = 4; + wcsTask.taskType = 6;//成品出库 + wcsTask.floorNo = floor;//出库到一楼 + wcsTask.taskStatus = 0; + wcsTask.updateTime = DateTime.Now; + dbContext.Update(wcsTask); + dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid) + .Update(t => new WcsTaskLog + { + nextPointId = nextEquip.objid, + nextPointNo = nextEquip.equipNo, + currPointId = baseEquip.objid, + currPointNo = baseEquip.equipNo, + fromFloorNo = 4, + floorNo = floor, + taskStatus = 0, + updateTime = DateTime.Now, + }); + dbContext.SaveChanges(); } } } @@ -142,7 +126,10 @@ namespace Khd.Core.Wcs.Wcs { LogManager.Error(ex); } - Thread.Sleep(1000); + finally + { + Thread.Sleep(1000); + } } } } diff --git a/src/Khd.Core.Wcs/Wcs/SecondFloorAGV.cs b/src/Khd.Core.Wcs/Wcs/SecondFloorAGV.cs index 1c0be47..ae36c90 100644 --- a/src/Khd.Core.Wcs/Wcs/SecondFloorAGV.cs +++ b/src/Khd.Core.Wcs/Wcs/SecondFloorAGV.cs @@ -74,113 +74,7 @@ namespace Khd.Core.Wcs.Wcs { dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); //获取条码号,如果该条码任务存在就继续任务,如果条码不存在,创建入库任务并调度agv - var taskList = StaticData.WcsTask.Where(t => t.nextPointId == EquipID && t.currPointId != EquipID && (t.taskType == 11 || t.taskType == 5 || t.taskType == 6)).ToList(); - if (taskList.Count == 0) - { - LogManager.Info(FloorNo + "楼AGV无任务"); - } - foreach (var item in taskList) - { - if (item.taskType == 5 || item.taskType == 11)//入库 - { - var loc = dbContext.WmsBaseLocation.Where(t => t.activeFlag == "1").ToList(); - var stock = dbContext.WmsProductStock.Where(t => t.activeFlag == "1").ToList(); - //获取有物料的库位 - var locStock = from l in loc - join s in stock on l.locationCode equals s.locationCode - select new - { - LocId = l.locationId, - locCode = l.locationCode, - LocDeep = l.locDeep, - productBatch = s.productBatch - }; - //获取空库位 - var nullLocList = loc.Where(r => !locStock.Select(t => t.locCode).Contains(r.locationCode) && r.warehouseId == 1).ToList(); - var location = nullLocList.OrderBy(t => t.locColumn).FirstOrDefault(); - if (location == null) return; - item.currPointId = 8; - item.currPointNo = "AGV01"; - item.nextPointId = location.locationId; - item.nextPointNo = location.locationCode; - //锁定库位 - dbContext.WmsBaseLocation.Where(t => t.locRow == location.locRow && t.locColumn == location.locColumn && t.layerNum == location.layerNum).Update(t => new WmsBaseLocation() - { - locationStatus = "6", - updateTime = DateTime.Now, - updateBy = "agv出库", - }); - //下发agv出库指令 - SendAndUpdateTask(item); - } - else if (item.taskType == 6) - { - var locList = dbContext.WmsBaseLocation.Where(t => t.activeFlag == "1").ToList(); - var outProStock = dbContext.WmsProductOutstock.Where(t => t.productOutstockId == item.orderId).FirstOrDefault(); - //获取库存 - var proStock = dbContext.WmsProductStock.Where(t => t.activeFlag == "1" && t.stockType == "3" && t.planCode == outProStock.planCode && t.saleorderCode == outProStock.saleorderCode).ToList(); - - var dic = dbContext.BaseDictionary.Where(t => t.dicKey == "OutStockDate").FirstOrDefault(); - var DateRange = Convert.ToInt32(dic.dicValue); - var stockList = from t in proStock.Where(r => r.productId == item.materialId) - join b in locList on t.locationCode equals b.locationCode - into temp - from newStock in temp.DefaultIfEmpty() - select new - { - proID = t.productStockId, - locID = newStock.locationId, - locCode = t.locationCode, - layerNum = newStock.layerNum, - locColumn = newStock.locColumn, - locRow = newStock.locRow, - locDeep = newStock.locDeep, - inStockDate = newStock.createTime, - }; - //先查出最早入库时间 - var inStockModel = stockList.OrderBy(t => t.inStockDate).FirstOrDefault(); - var inStockDate = inStockModel.inStockDate; - //查出符合条件的成品 - var outStockList = stockList.Where(t => t.inStockDate >= inStockDate && t.inStockDate <= inStockDate.GetValueOrDefault().AddDays(DateRange)).ToList(); - var outModel = outStockList.OrderBy(t => t.locColumn).ThenByDescending(t => t.locDeep).FirstOrDefault(); - if (outModel.locDeep == 1) - { - //自动获取id - - var objid = StaticData.SnowId.NextId(); - var isExiStock = stockList.Where(t => t.locRow == outModel.locRow && t.locColumn == outModel.locColumn && t.locDeep == 2).FirstOrDefault(); - if (isExiStock != null) - { - //创建成品移库任务 - WcsTask newTask = new() - { - objid = objid, - taskType = 11, - containerNo = "", - taskStatus = 0, - materialId = isExiStock.locID, - qty = 1, - startPointId = isExiStock.locID, - currPointId = isExiStock.locID, - endPointId = 12, - endPointNo = "WH02", - }; - dbContext.Add(newTask); - dbContext.SaveChanges(); - return; - } - } - //锁定库位 - dbContext.WmsBaseLocation.Where(t => t.locRow == outModel.locRow && t.locColumn == outModel.locColumn && t.layerNum == outModel.layerNum).Update(t => new WmsBaseLocation() - { - locationStatus = "6", - updateTime = DateTime.Now, - updateBy = "agv出库", - }); - //下发agv出库指令 - SendAndUpdateTask(item); - } - } + var taskList = dbContext.WcsTask.Where(t => t.nextPointId == EquipID).ToList(); } catch (Exception ex) { @@ -193,117 +87,5 @@ namespace Khd.Core.Wcs.Wcs } } - public void SendAndUpdateTask(WcsTask task) - { - //获取 - if (task == null) return; - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - WcsToWms wcsToWms = new WcsToWms(); - //首先判断是否已下发指令 - var cmd = dbContext.WcsCmd.Where(t => t.taskId == task.objid).FirstOrDefault(); - var locList = dbContext.WmsBaseLocation.Where(t => t.activeFlag == "1").ToList(); - if (locList.Count == 0) return; - //指令表存在说明已下发 - if (cmd == null) - { //获取下发agv指令 - string ip = ""; int port = 0; string url = ""; - RequestAGVTaskDto agvtask = new RequestAGVTaskDto(); - agvtask.reqCode = task.objid.ToString(); - //var json = JsonConvert.SerializeObject(agvtask); - //HttpHelper.SendPostMessage(ip, port, url, json); - agvtask.positionCodePath = new List(); - Position p = new Position(); - WmsBaseLocation putPos = new WmsBaseLocation(); //放料点 - WmsBaseLocation setPos = new WmsBaseLocation(); //取料点 - if (task.taskType == 5) //入库 - { - setPos = locList.Where(t => t.locationId == task.nextPointId).FirstOrDefault(); - } - else - { - setPos = locList.Where(t => t.locationId == task.nextPointId).FirstOrDefault(); - } - putPos = locList.Where(t => t.locationId == task.nextPointId).FirstOrDefault(); - p.positionCode = setPos?.agvPositionCode; - p.type = ""; - agvtask.positionCodePath.Add(p); - p.positionCode = putPos?.agvPositionCode; - p.type = ""; - //取料点 - agvtask.positionCodePath.Add(p); - agvtask.taskTyp = ""; - //给agv创建任务 - wcsToWms.genAgvSchedulingTask(agvtask); - //未下发给agv下发指令 - WcsCmd taskCmd = new WcsCmd() - { - taskId = task.objid, - cmdType = task.taskType, - serialNo = task.serialNo, - equipmentNo = task.equipmentNo, - cmdStatus = 1, - createBy = FloorNo + "楼AGV", - createTime = DateTime.Now, - }; - dbContext.Add(taskCmd); - dbContext.SaveChanges(); - } - else - { - //获取接驳位是否有托盘 - var IsPallet = this._plc.Read(this.LineIsPallet.plcpointAddress); - if (cmd.sendFlag == 0) - { - if (taskInType.Contains(task.taskType.GetValueOrDefault()))//入库 - { - //入库时有托盘继续任务 - if (Convert.ToInt32(IsPallet) == 1) - { - continueTaskDto continueTask = new continueTaskDto(); - continueTask.taskCode = task.objid.ToString(); - wcsToWms.continueTask(continueTask); - //未下发给agv下发指令 - WcsCmd taskCmd = new WcsCmd() - { - taskId = task.objid, - sendFlag = 1, - createBy = FloorNo + "楼AGV", - createTime = DateTime.Now, - }; - dbContext.Update(taskCmd); - dbContext.SaveChanges(); - } - } - else - { - //出库时没有托盘继续任务 - if (Convert.ToInt32(IsPallet) == 0) - { - continueTaskDto continueTask = new continueTaskDto(); - continueTask.taskCode = task.objid.ToString(); - wcsToWms.continueTask(continueTask); - //更新任务 - dbContext.WcsCmd.Where(t => t.taskId == task.objid).Update(t => new WcsCmd() - { - sendFlag = 1, - updateTime = DateTime.Now, - updateBy = "agv出库", - }); - } - } - } - } - //更新任务表 - dbContext.WcsTask.Where(t => t.objid == task.objid).Update(t => new WcsTask() - { - currPointId = task.currPointId, - currPointNo = task.currPointNo, - nextPointId = task.nextPointId, - nextPointNo = task.nextPointNo, - updateTime = DateTime.Now, - updateBy = "agv出库", - }); - } } } diff --git a/src/Khd.Core.Wcs/Wcs/SecondFloorLine.cs b/src/Khd.Core.Wcs/Wcs/SecondFloorLine.cs index 95bdee3..4e7b3f0 100644 --- a/src/Khd.Core.Wcs/Wcs/SecondFloorLine.cs +++ b/src/Khd.Core.Wcs/Wcs/SecondFloorLine.cs @@ -129,7 +129,7 @@ namespace Khd.Core.Wcs.Wcs //查询该条码绑定的物料信息 var material = StaticData.WmsWarehouseMaterial.Where(t => t.storageId == palletInfo.materialId).FirstOrDefault(); var wareHouse = wareHouseList.Where(t => t.warehouseId == material.warehouseId).FirstOrDefault(); - var dic = StaticData.BaseDictionary.Where(t => t.dicKey == "TaskType" && t.ud1 == "I" && t.dicField == wareHouse.warehouseInstockType).FirstOrDefault(); + var dic = StaticData.BaseDictionary.Where(t => t.dicKey == "TaskType" && t.agvType == "I" && t.dicField == wareHouse.warehouseInstockType).FirstOrDefault(); var equip = StaticData.BaseEquip.ToList(); var startEquip = equip.Where(t => t.equipNo == equipNo).FirstOrDefault(); var endPoint = wareHouseList.Where(t => t.warehouseFloor == floorNo).FirstOrDefault(); diff --git a/src/Khd.Core.Wcs/Wcs/SecondFloorPoint.cs b/src/Khd.Core.Wcs/Wcs/SecondFloorPoint.cs index 9c7ac10..8103c5f 100644 --- a/src/Khd.Core.Wcs/Wcs/SecondFloorPoint.cs +++ b/src/Khd.Core.Wcs/Wcs/SecondFloorPoint.cs @@ -89,7 +89,7 @@ namespace Khd.Core.Wcs.Wcs var wmsProductOutstock = dbContext.WmsProductOutstock.Where(t => t.saleOrderId == wcsTask.orderId).FirstOrDefault(); if (wmsProductOutstock != null) { - long? endStationCode = wmsProductOutstock.endStationCode; + string endStationCode = wmsProductOutstock.endStationCode; //找到目的地楼层 int floorNo=0; //下发去提升机的去向 diff --git a/src/Khd.Core.Wcs/Wcs/SystemTimer.cs b/src/Khd.Core.Wcs/Wcs/SystemTimer.cs new file mode 100644 index 0000000..79b3a28 --- /dev/null +++ b/src/Khd.Core.Wcs/Wcs/SystemTimer.cs @@ -0,0 +1,377 @@ +using Khd.Core.Domain.Dto.webapi; +using Khd.Core.Domain.Models; +using Khd.Core.EntityFramework; +using Khd.Core.Plc; +using Khd.Core.Plc.S7; +using Khd.Core.Wcs.Global; +using Masuit.Tools; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Khd.Core.Wcs.Wcs +{ + public class SystemTimer + { + private readonly IHost host; + private Plc.S7.Plc Plc30 = StaticData.PlcDic[0]; + private Plc.S7.Plc Plc31 = StaticData.PlcDic[0]; + private Plc.S7.Plc Plc220 = StaticData.PlcDic[2]; + public SystemTimer(IHost host) + { + this.host = host; + } + + public void Start() + { + Thread messageSynchronousThread = new(MessageSynchronousLogic); + messageSynchronousThread.Start(); + + Thread baseEquipThread = new Thread(BaseEquipLogic); + baseEquipThread.Start(); + } + + private void BaseEquipLogic(object? obj) + { + using var scope = host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + while (true) + { + try + { + dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); + List updateEquips = dbContext.BaseEquip.Where(t => t.remark == "99").ToList(); + if (updateEquips.Count > 0) + { + foreach (var equip in updateEquips) + { + equip.remark = "0"; + dbContext.BaseEquip.Update(equip); + dbContext.SaveChanges(); + } + StaticData.BaseEquip = dbContext.BaseEquip.ToList(); + } + } + catch + { + + } + Thread.Sleep(5000); + } + } + + private void MessageSynchronousLogic(object? obj) + { + try + { + using var scope = host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + HositerLogic(); + CtuLineLogic(); + ThirdAgvLogic(dbContext); + SecondAgvLogic(dbContext); + FiveAgvLogic(dbContext); + FiveBearAgvLogic(dbContext); + CtuCmdLogic(dbContext); + } + catch (Exception ex) + { + try + { + if (ex is PlcException) + { + foreach (var item in StaticData.PlcDic) + { + if (item.Value.IP == ex.Message) + { + StaticData.PlcDic[item.Key] = new Plc.S7.Plc(item.Value.CPU, item.Value.IP, item.Value.Port, item.Value.Rack, item.Value.Slot); + StaticData.PlcDic[item.Key].Open(); + } + } + } + } + catch + { + + } + } + Thread.Sleep(5000); + } + + private void ThirdAgvLogic(DefaultDbContext dbContext) + { + var baseEquip = StaticData.BaseEquip.First(t => t.objid == 9); + dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); + var basePlcs = StaticData.basePlcs.Where(t => t.Station == "3楼AGV").ToList(); + var data = new + { + reqCode = StaticData.SnowId.NextId(), + mapCode = "BB" + }; + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms-dps/rest/queryAgvStatus", data.ToJsonString()); + var reponse = JsonConvert.DeserializeObject(result); + if (reponse != null && reponse.code == "0") + { + cardStatus cardStatus = reponse.data.First(t => t.robotCode == "2032"); + var quantityPlc = basePlcs.First(t => t.Name.Contains("电量")); + this.Plc220.WriteToPoint(quantityPlc.Address, cardStatus.battery, quantityPlc.type); + var XPlc = basePlcs.First(t => t.Name.Contains('X')); + var Ylc = basePlcs.First(t => t.Name.Contains('Y')); + this.Plc220.WriteToPoint(XPlc.Address, cardStatus.posX.ToString(), XPlc.type); + this.Plc220.WriteToPoint(Ylc.Address, cardStatus.posY.ToString(), Ylc.type); + } + } + + private void SecondAgvLogic(DefaultDbContext dbContext) + { + var baseEquip = StaticData.BaseEquip.First(t => t.objid == 8); + dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); + var basePlcs = StaticData.basePlcs.Where(t => t.Station == "2楼AGV").ToList(); + var data = new + { + reqCode = StaticData.SnowId.NextId(), + mapCode = "CC" + }; + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms-dps/rest/queryAgvStatus", data.ToJsonString()); + var reponse = JsonConvert.DeserializeObject(result); + if (reponse != null && reponse.code == "0") + { + cardStatus cardStatus = reponse.data.First(t => t.robotCode == "2033"); + var quantityPlc = basePlcs.First(t => t.Name.Contains("电量")); + this.Plc220.WriteToPoint(quantityPlc.Address, cardStatus.battery, quantityPlc.type); + var XPlc = basePlcs.First(t => t.Name.Contains('X')); + var Ylc = basePlcs.First(t => t.Name.Contains('Y')); + this.Plc220.WriteToPoint(XPlc.Address, cardStatus.posX.ToString(), XPlc.type); + this.Plc220.WriteToPoint(Ylc.Address, cardStatus.posY.ToString(), Ylc.type); + } + } + + private void FiveAgvLogic(DefaultDbContext dbContext) + { + var baseEquip = StaticData.BaseEquip.First(t => t.objid == 10); + dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); + var basePlcs = StaticData.basePlcs.Where(t => t.Station == "5楼AGV").ToList(); + List type = new List() { 27, 28, 34, 35, 37, 38, 46, 47 }; + var wcsCmds = dbContext.WcsCmd.Where(t => type.Contains(t.cmdType)).ToList(); + if (wcsCmds.Count > 0) + { + WcsCmd wcsCmd = wcsCmds.First(); + var endPlc = basePlcs.Where(t => t.Name.Contains("目的地")).First(); + Plc220.WriteToPoint(endPlc.Address, wcsCmd.nextPointId.ToString(), endPlc.type); + var startPlc = basePlcs.First(t => t.Name.Contains("起始点")); + Plc220.WriteToPoint(startPlc.Address, wcsCmd.currPointId.ToString(), startPlc.type); + var cmdPlc = basePlcs.First(t => t.Name.Contains("任务代号")); + string cmdType = StaticData.BaseDictionary.First(t => t.objid == wcsCmd.cmdType).ToPlc; + Plc220.WriteToPoint(cmdPlc.Address, cmdType, cmdPlc.type); + } + else + { + var endPlc = basePlcs.Where(t => t.Name.Contains("目的地")).First(); + this.Plc220.WriteToPoint(endPlc.Address, "0", endPlc.type); + var startPlc = basePlcs.First(t => t.Name.Contains("起始点")); + Plc220.WriteToPoint(startPlc.Address, "0", startPlc.type); + var cmdPlc = basePlcs.First(t => t.Name.Contains("任务代号")); + Plc220.WriteToPoint(cmdPlc.Address, "0", cmdPlc.type); + } + var data = new + { + reqCode = StaticData.SnowId.NextId(), + mapCode = "EE" + }; + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms-dps/rest/queryAgvStatus", data.ToJsonString()); + var reponse = JsonConvert.DeserializeObject(result); + if (reponse != null && reponse.code == "0") + { + cardStatus cardStatus = reponse.data.First(t => t.robotCode == "2034"); + var quantityPlc = basePlcs.First(t => t.Name.Contains("电量")); + this.Plc220.WriteToPoint(quantityPlc.Address, cardStatus.battery, quantityPlc.type); + var XPlc = basePlcs.First(t => t.Name.Contains('X')); + var Ylc = basePlcs.First(t => t.Name.Contains('Y')); + this.Plc220.WriteToPoint(XPlc.Address, cardStatus.posX.ToString(), XPlc.type); + this.Plc220.WriteToPoint(Ylc.Address, cardStatus.posY.ToString(), Ylc.type); + + cardStatus = reponse.data.First(t => t.robotCode == "6011"); + quantityPlc = basePlcs.First(t => t.Name.Contains("电量")); + this.Plc220.WriteToPoint(quantityPlc.Address, cardStatus.battery, quantityPlc.type); + XPlc = basePlcs.First(t => t.Name.Contains('X')); + Ylc = basePlcs.First(t => t.Name.Contains('Y')); + this.Plc220.WriteToPoint(XPlc.Address, cardStatus.posX.ToString(), XPlc.type); + this.Plc220.WriteToPoint(Ylc.Address, cardStatus.posY.ToString(), Ylc.type); + + cardStatus = reponse.data.First(t => t.robotCode == "8161"); + quantityPlc = basePlcs.First(t => t.Name.Contains("电量")); + this.Plc220.WriteToPoint(quantityPlc.Address, cardStatus.battery, quantityPlc.type); + XPlc = basePlcs.First(t => t.Name.Contains("X")); + Ylc = basePlcs.First(t => t.Name.Contains("Y")); + this.Plc220.WriteToPoint(XPlc.Address, cardStatus.posX.ToString(), XPlc.type); + this.Plc220.WriteToPoint(Ylc.Address, cardStatus.posY.ToString(), Ylc.type); + } + } + + private void FiveBearAgvLogic(DefaultDbContext dbContext) + { + var baseEquip = StaticData.BaseEquip.First(t => t.objid == 10); + dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); + var basePlcs = StaticData.basePlcs.Where(t => t.Station == "5楼背负式").ToList(); + var wcsCmds = dbContext.WcsCmd.Where(t => t.cmdType == 32 || t.cmdType == 48).ToList(); + if (wcsCmds.Count > 0) + { + WcsCmd wcsCmd = wcsCmds.First(); + var endPlc = basePlcs.Where(t => t.Name.Contains("目的地")).First(); + Plc220.WriteToPoint(endPlc.Address, wcsCmd.nextPointId.ToString(), endPlc.type); + var startPlc = basePlcs.First(t => t.Name.Contains("起始点")); + Plc220.WriteToPoint(startPlc.Address, wcsCmd.currPointId.ToString(), startPlc.type); + var cmdPlc = basePlcs.First(t => t.Name.Contains("任务代号")); + string cmdType = StaticData.BaseDictionary.First(t => t.objid == wcsCmd.cmdType).ToPlc; + Plc220.WriteToPoint(cmdPlc.Address, cmdType, cmdPlc.type); + } + else + { + var endPlc = basePlcs.Where(t => t.Name.Contains("目的地")).First(); + this.Plc220.WriteToPoint(endPlc.Address, "0", endPlc.type); + var startPlc = basePlcs.First(t => t.Name.Contains("起始点")); + Plc220.WriteToPoint(startPlc.Address, "0", startPlc.type); + var cmdPlc = basePlcs.First(t => t.Name.Contains("任务代号")); + Plc220.WriteToPoint(cmdPlc.Address, "0", cmdPlc.type); + } + } + + private void CtuCmdLogic(DefaultDbContext dbContext) + { + var baseEquip = StaticData.BaseEquip.First(t => t.objid == 11); + dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); + var basePlcs = StaticData.basePlcs.Where(t => t.Station == "5楼CTU").ToList(); + var wcsCmds = dbContext.WcsCmd.Where(t => t.cmdType == 29 || t.cmdType == 30 || t.cmdType == 31).ToList(); + if (wcsCmds.Count > 0) + { + var wcsCmd = wcsCmds.First(); + List startList = new List(); + List endList = new List(); + if (wcsCmd.cmdType != 30) + { + startList.Add(wcsCmd.currPointId); + endList.AddRange(wcsCmds.Select(t => t.nextPointId).ToList()); + } + else + { + startList.Add(wcsCmd.nextPointId); + endList.AddRange(wcsCmds.Select(t => t.currPointId).ToList()); + } + while (endList.Count < 6) + { + endList.Add(0); + } + var endPlcs = basePlcs.Where(t => t.Name.Contains("目的地")).OrderBy(t => t.Name).ToList(); + for (int i = 0; i < endPlcs.Count; i++) + { + this.Plc220.WriteToPoint(endPlcs[i].Address, endList[i].ToString(), endPlcs[i].type); + } + var startPlc = basePlcs.First(t => t.Name.Contains("起始点")); + Plc220.WriteToPoint(startPlc.Address, wcsCmd.currPointId.ToString(), startPlc.type); + var cmdPlc = basePlcs.First(t => t.Name.Contains("任务代号")); + string cmdType = StaticData.BaseDictionary.First(t => t.objid == wcsCmd.cmdType).ToPlc; + Plc220.WriteToPoint(cmdPlc.Address, cmdType, cmdPlc.type); + + } + else + { + var endPlcs = basePlcs.Where(t => t.Name.Contains("目的地")).OrderBy(t => t.Name).ToList(); + for (int i = 0; i < endPlcs.Count; i++) + { + this.Plc220.WriteToPoint(endPlcs[i].Address, "0", endPlcs[i].type); + } + var startPlc = basePlcs.First(t => t.Name.Contains("起始点")); + Plc220.WriteToPoint(startPlc.Address, "0", startPlc.type); + var cmdPlc = basePlcs.First(t => t.Name.Contains("任务代号")); + Plc220.WriteToPoint(cmdPlc.Address, "0", cmdPlc.type); + } + } + + private void CtuLineLogic() + { + var basePlcpoints = StaticData.BasePlcpointList.ToList(); + var basePlcs = StaticData.basePlcs.ToList(); + var bill = from a in basePlcpoints + from b in basePlcs + where a.plcpointNo == b.Name && b.Station == "U型线" + select new { a, b }; + foreach (var item in bill) + { + if (item.a.plcpointNo.Contains("RFID")) + { + string? rfid = Plc31.ReadRFID(item.a.plcpointAddress); + if (!string.IsNullOrEmpty(rfid)) + { + rfid = rfid[(rfid.IndexOf("C") + 1)..]; + Plc220.WriteToPoint(item.b.Address, rfid, item.b.type); + } + else + { + Plc220.WriteToPoint(item.b.Address, "0", item.b.type); + } + } + else + { + var value = Plc31.Read(item.a.plcpointAddress); + if (value != null && !string.IsNullOrEmpty(value.ToString())) + { + Plc220.WriteToPoint(item.b.Address, value.ToString(), item.b.type); + } + else + { + Plc220.WriteToPoint(item.b.Address, "0", item.b.type); + } + } + } + } + + /// + /// 提升机和接驳位信息同步 + /// + private void HositerLogic() + { + + var basePlcpoints = StaticData.BasePlcpointList.ToList(); + var basePlcs = StaticData.basePlcs.ToList(); + var bill = from a in basePlcpoints + from b in basePlcs + where a.plcpointNo == b.Name && b.Station != "U型线" + select new { a, b }; + foreach (var item in bill) + { + if (item.a.plcpointNo.Contains("RFID")) + { + string? rfid = Plc30.ReadRFID(item.a.plcpointAddress); + if (!string.IsNullOrEmpty(rfid)) + { + rfid = rfid[(rfid.IndexOf("JYHB") + 4)..]; + Plc220.WriteToPoint(item.b.Address, rfid, item.b.type); + } + else + { + Plc220.WriteToPoint(item.b.Address, "0", item.b.type); + } + } + else + { + var value = Plc30.Read(item.a.plcpointAddress); + if (value != null && !string.IsNullOrEmpty(value.ToString())) + { + Plc220.WriteToPoint(item.b.Address, value.ToString(), item.b.type); + } + else + { + Plc220.WriteToPoint(item.b.Address, "0", item.b.type); + } + } + } + } + } + +} + diff --git a/src/Khd.Core.Wcs/Wcs/ThirdFloorAGV.cs b/src/Khd.Core.Wcs/Wcs/ThirdFloorAGV.cs index 278d82d..c2b876b 100644 --- a/src/Khd.Core.Wcs/Wcs/ThirdFloorAGV.cs +++ b/src/Khd.Core.Wcs/Wcs/ThirdFloorAGV.cs @@ -1,10 +1,12 @@ using Khd.Core.Domain.Dto.webapi; using Khd.Core.Domain.Models; using Khd.Core.EntityFramework; +using Khd.Core.Library.Mapper; using Khd.Core.Wcs.Global; using Masuit.Tools.Logging; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Newtonsoft.Json; using Z.EntityFramework.Plus; namespace Khd.Core.Wcs.Wcs @@ -68,119 +70,456 @@ namespace Khd.Core.Wcs.Wcs { using var scope = _host.Services.CreateScope(); using var dbContext = scope.ServiceProvider.GetRequiredService(); + BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.objid == 9); while (true) { try { dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); //获取条码号,如果该条码任务存在就继续任务,如果条码不存在,创建入库任务并调度agv - var taskList = dbContext.WcsTask.Where(t => t.nextPointId == EquipID && t.currPointId != EquipID && (t.taskType == 1 || t.taskType == 2 || t.taskType == 9)).ToList(); - if (taskList.Count == 0) - { - LogManager.Info(FloorNo + "楼AGV无任务"); - } + var taskList = dbContext.WcsTask.Where(t => t.nextPointId == baseEquip.objid).OrderBy(t => t.createTime).ToList(); foreach (var item in taskList) { - if (item.taskType == 1 || item.taskType == 9)//入库||移库 + if (item.taskStatus == 0) { - var loc = dbContext.WmsBaseLocation.Where(t => t.activeFlag == "1").ToList(); - - //3楼原材料 - var stock = dbContext.WmsRawStock.Where(t => t.activeFlag == "1").ToList(); - //获取有物料的库位 - var locStock = from l in loc - join s in stock on l.locationCode equals s.locationCode - select new - { - LocId = l.locationId, - locCode = l.locationCode, - LocDeep = l.locDeep, - productBatch = s.instockBatch - }; - //获取空库位 - var nullLocList = loc.Where(r => !locStock.Select(t => t.locCode).Contains(r.locationCode) && r.warehouseId == 2).ToList(); - var location = nullLocList.OrderBy(t => t.locColumn).FirstOrDefault(); - item.currPointId = 9; - item.currPointNo = "AGV02"; - item.nextPointId = location.locationId; - item.nextPointNo = location.locationCode; - dbContext.Update(item); - //锁定库位 - dbContext.WmsBaseLocation.Where(t => t.locRow == location.locRow && t.locColumn == location.locColumn && t.layerNum == location.layerNum).Update(t => new WmsBaseLocation() + if (item.taskType == 39) { - locationStatus = "6", - updateTime = DateTime.Now, - updateBy = "agv出库", - }); - //下发agv出库指令 - SendAndUpdateTask(item); - } - else if (item.taskType == 2) - { - var locList = dbContext.WmsBaseLocation.Where(t => t.activeFlag == "1").ToList(); - //获取库存 - var rawStock = dbContext.WmsRawStock.Where(t => t.activeFlag == "1" && t.stockType == "1" && t.materialId == item.materialId).ToList(); - - var dic = dbContext.BaseDictionary.Where(t => t.dicKey == "OutStockDate").FirstOrDefault(); - var DateRange = Convert.ToInt32(dic.dicValue); - var stockList = from t in rawStock - join b in locList on t.locationCode equals b.locationCode - into temp - from newStock in temp.DefaultIfEmpty() - select new - { - rawID = t.rawStockId, - locID = newStock.locationId, - locCode = t.locationCode, - layerNum = newStock.layerNum, - locColumn = newStock.locColumn, - locRow = newStock.locRow, - locDeep = newStock.locDeep, - inStockDate = newStock.createTime, - }; - //先查出最早入库时间 - var inStockModel = stockList.OrderBy(t => t.inStockDate).FirstOrDefault(); - var inStockDate = inStockModel.inStockDate; - //查出符合条件的成品 - var outStockList = stockList.Where(t => t.inStockDate >= inStockDate && t.inStockDate <= inStockDate.GetValueOrDefault().AddDays(DateRange)).ToList(); - var outModel = outStockList.OrderBy(t => t.locColumn).ThenByDescending(t => t.locDeep).FirstOrDefault(); - if (outModel.locDeep == 1) - { - //自动获取id - - var objid = StaticData.SnowId.NextId(); - var isExiStock = stockList.Where(t => t.locRow == outModel.locRow && t.locColumn == outModel.locColumn && t.locDeep == 2).FirstOrDefault(); - if (isExiStock != null) + BaseEquip startEquip = StaticData.BaseEquip.First(t => t.objid == 3); + WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId); + WcsCmd wcsCmd = new WcsCmd() { - //创建成品移库任务 - WcsTask newTask = new() + objid = StaticData.SnowId.NextId(), + cmdStatus = 0, + taskId = item.objid, + useFlag = 1, + cmdType = item.taskType, + containerNo = item.containerNo, + createTime = DateTime.Now, + createBy = FloorNo + "楼AGV", + currPointId = startEquip.objid, + currPointNo = startEquip.agvPositionCode, + nextPointId = item.endPointId, + nextPointNo = wmsBaseLocation.agvPositionCode, + }; + var agvTask = new RequestAGVTaskDto + { + reqCode = StaticData.SnowId.NextId().ToString(), + positionCodePath = new List { - objid = objid, - taskType = 11, - containerNo = "", - taskStatus = 0, - materialId = isExiStock.locID, - qty = 1, - startPointId = isExiStock.locID, - currPointId = isExiStock.locID, - endPointId = 12, - endPointNo = "WH02", - }; - dbContext.Add(newTask); + new () + { + positionCode=wcsCmd.currPointNo, + type="00" + }, + new () + { + positionCode=wcsCmd.nextPointNo, + type="00" + } + }, + taskTyp = "F300", + ctnrTyp = "2", + }; + string message = JsonConvert.SerializeObject(agvTask); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); + var reponseMessage = JsonConvert.DeserializeObject(result); + if (reponseMessage != null && reponseMessage.message == "成功") + { + wcsCmd.taskCode = reponseMessage.data; + wcsCmd.cmdStatus = 1; + item.taskStatus = 1; + dbContext.Update(item); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 1 }); + WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd); + dbContext.Add(wcsCmdLog); + dbContext.Add(wcsCmd); dbContext.SaveChanges(); - return; + } + else + { + LogManager.Info("三楼Agv下发任务失败" + item.taskType + message); } } - //锁定库位 - dbContext.WmsBaseLocation.Where(t => t.locationCode == outModel.locCode).Update(t => new WmsBaseLocation() + else if (item.taskType == 41) { - locationStatus = "1", - updateTime = DateTime.Now, - updateBy = "agv出库", - }); - //下发agv出库指令 - SendAndUpdateTask(item); + BaseEquip endEquip = StaticData.BaseEquip.First(t => t.objid == 31); + WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.startPointId); + WcsCmd wcsCmd = new WcsCmd() + { + objid = StaticData.SnowId.NextId(), + cmdStatus = 0, + taskId = item.objid, + useFlag = 1, + cmdType = item.taskType, + containerNo = item.containerNo, + createTime = DateTime.Now, + createBy = FloorNo + "楼AGV", + currPointId = item.startPointId, + currPointNo = wmsBaseLocation.agvPositionCode, + nextPointId = endEquip.objid, + nextPointNo = endEquip.agvPositionCode, + }; + var agvTask = new RequestAGVTaskDto + { + reqCode = StaticData.SnowId.NextId().ToString(), + positionCodePath = new List + { + new () + { + positionCode=wcsCmd.currPointNo, + type="00" + }, + new () + { + positionCode=wcsCmd.nextPointNo, + type="00" + } + }, + taskTyp="F301", + ctnrTyp = "2", + }; + string message = JsonConvert.SerializeObject(agvTask); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); + var reponseMessage = JsonConvert.DeserializeObject(result); + if (reponseMessage != null && reponseMessage.message == "成功") + { + wcsCmd.taskCode = reponseMessage.data; + wcsCmd.cmdStatus = 1; + item.taskStatus = 1; + dbContext.Update(item); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 1 }); + WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd); + dbContext.Add(wcsCmdLog); + dbContext.Add(wcsCmd); + dbContext.SaveChanges(); + } + else + { + LogManager.Info("三楼Agv下发任务失败" + item.taskType + message); + } + } + else if (item.taskType == 42) + { + BaseEquip startEquip = StaticData.BaseEquip.First(t => t.objid == 31); + BaseEquip endEquip = StaticData.BaseEquip.First(); + WcsCmd wcsCmd = new WcsCmd() + { + objid = StaticData.SnowId.NextId(), + cmdStatus = 0, + taskId = item.objid, + useFlag = 1, + cmdType = item.taskType, + containerNo = item.containerNo, + createTime = DateTime.Now, + createBy = FloorNo + "楼AGV", + currPointId = startEquip.objid, + currPointNo = startEquip.agvPositionCode, + nextPointId = endEquip.objid, + nextPointNo = endEquip.agvPositionCode, + }; + var agvTask = new RequestAGVTaskDto + { + reqCode = StaticData.SnowId.NextId().ToString(), + positionCodePath = new List + { + new () + { + positionCode=wcsCmd.currPointNo, + type="00" + }, + new () + { + positionCode=wcsCmd.nextPointNo, + type="00" + } + }, + taskTyp="F302", + ctnrTyp = "2", + }; + string message = JsonConvert.SerializeObject(agvTask); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); + var reponseMessage = JsonConvert.DeserializeObject(result); + if (reponseMessage != null && reponseMessage.message == "成功") + { + wcsCmd.taskCode = reponseMessage.data; + wcsCmd.cmdStatus = 1; + item.taskStatus = 1; + dbContext.Update(item); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 1 }); + WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd); + dbContext.Add(wcsCmdLog); + dbContext.Add(wcsCmd); + dbContext.SaveChanges(); + } + else + { + LogManager.Info("三楼Agv下发任务失败" + item.taskType + message); + } + } + else if (item.taskType == 43) + { + BaseEquip emptyEquip = StaticData.BaseEquip.First(t => t.objid == item.startPointId); + BaseEquip endEquip = StaticData.BaseEquip.First(t => t.floorNo == 3 && t.equipType == 1); + WcsCmd wcsCmd = new WcsCmd() + { + objid = StaticData.SnowId.NextId(), + cmdStatus = 0, + taskId = item.objid, + useFlag = 1, + cmdType = item.taskType, + containerNo = item.containerNo, + createTime = DateTime.Now, + createBy = FloorNo + "楼AGV", + currPointId = item.startPointId, + currPointNo = emptyEquip.agvPositionCode, + nextPointId = endEquip.objid, + nextPointNo = endEquip.agvPositionCode, + }; + var agvTask = new RequestAGVTaskDto + { + reqCode = StaticData.SnowId.NextId().ToString(), + positionCodePath = new List + { + new () + { + positionCode=wcsCmd.currPointNo, + type="00" + }, + new () + { + positionCode=wcsCmd.nextPointNo, + type="00" + } + }, + taskTyp="F303", + ctnrTyp = "2", + }; + string message = JsonConvert.SerializeObject(agvTask); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); + var reponseMessage = JsonConvert.DeserializeObject(result); + if (reponseMessage != null && reponseMessage.message == "成功") + { + wcsCmd.taskCode = reponseMessage.data; + wcsCmd.cmdStatus = 1; + item.taskStatus = 1; + dbContext.Update(item); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 1 }); + WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd); + dbContext.Add(wcsCmdLog); + dbContext.Add(wcsCmd); + dbContext.SaveChanges(); + } + else + { + LogManager.Info("三楼Agv下发任务失败" + item.taskType + message); + } + } + else if (item.taskType == 44) + { + BaseEquip startEquip = StaticData.BaseEquip.First(t => t.objid == item.startPointId); + BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.objid == 3); + WcsCmd wcsCmd = new WcsCmd() + { + objid = StaticData.SnowId.NextId(), + cmdStatus = 0, + taskId = item.objid, + useFlag = 1, + cmdType = item.taskType, + containerNo = item.containerNo, + createTime = DateTime.Now, + createBy = FloorNo + "楼AGV", + currPointId = startEquip.objid, + currPointNo = startEquip.agvPositionCode, + nextPointId = lineEquip.objid, + nextPointNo = lineEquip.equipNo, + }; + var agvTask = new RequestAGVTaskDto + { + reqCode = StaticData.SnowId.NextId().ToString(), + positionCodePath = new List + { + new() + { + positionCode = wcsCmd.currPointNo, + type = "00" + }, + new() + { + positionCode = wcsCmd.nextPointNo, + type = "00" + } + }, + taskTyp="F304", + ctnrTyp="2" + }; + string message = JsonConvert.SerializeObject(agvTask); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message); + var reponseMessage = JsonConvert.DeserializeObject(result); + if (reponseMessage != null && reponseMessage.message == "成功") + { + wcsCmd.taskCode = reponseMessage.data; + wcsCmd.cmdStatus = 1; + item.taskStatus = 1; + dbContext.Update(item); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 1 }); + WcsCmdLog wcsCmdLog = CoreMapper.Map(wcsCmd); + dbContext.Add(wcsCmdLog); + dbContext.Add(wcsCmd); + dbContext.SaveChanges(); + } + else + { + LogManager.Info("三楼Agv下发任务失败" + item.taskType + message); + } + } } + else + { + WcsCmd? wcsCmd = dbContext.WcsCmd.FirstOrDefault(t => t.taskId == item.objid); + if (wcsCmd != null) + { + if (item.taskStatus == 3) + { + var agvTask = new RequestAGVTaskDto + { + reqCode = StaticData.SnowId.NextId().ToString(), + taskCode = wcsCmd.taskCode + }; + string message = JsonConvert.SerializeObject(agvTask); + string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/continueTask", message); + ReponseMessage? reponseMessage = JsonConvert.DeserializeObject(result); + if (reponseMessage != null && reponseMessage.message == "成功") + { + wcsCmd.cmdStatus = 4; + dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmd() { cmdStatus = 4 }); + dbContext.Update(wcsCmd); + dbContext.WcsTask.Where(t => t.objid == item.objid).Update(t => new WcsTask() { taskStatus = 4 }); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 4 }); + dbContext.SaveChanges(); + } + } + else if (item.taskStatus == 5) + { + if (item.taskType == 39) + { + WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation + .First(t => t.locationId == item.endPointId && t.warehouseFloor == 3); + wmsBaseLocation.locationStatus = "1"; + wmsBaseLocation.instockFlag = "0"; + wmsBaseLocation.containerCode = item.containerNo; + wmsBaseLocation.updateTime = DateTime.Now; + wmsBaseLocation.updateBy = "WCS"; + var mesBasePalletInfo = dbContext.MesBasePalletInfo.FirstOrDefault(t => t.palletInfoCode == item.containerNo); + if (mesBasePalletInfo != null) + { + var mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == mesBasePalletInfo.materialBarcode); + if (mesBaseBarcodeInfo != null) + { + var wmsRawStock = new WmsRawStock() + { + rawStockId = StaticData.SnowId.NextId(), + activeFlag = "1", + saleOrderId = item.orderId, + stockType = "1", + supplierId = mesBaseBarcodeInfo.manufacturerId, + qualityStatus = "1", + completeFlag = "1", + createBy = "WCS", + createDate = DateTime.Now, + frozenAmount = 0, + instockBatch = mesBaseBarcodeInfo.batchCode, + instockDate = DateTime.Now, + locationCode = wmsBaseLocation.locationCode, + materialId = mesBaseBarcodeInfo.materialId, + occupyAmount = 0, + palletInfoCode = item.containerNo, + totalAmount = 1, + warehouseFloor = 3, + warehouseId = 311 + }; + dbContext.Add(wmsRawStock); + dbContext.Update(wmsBaseLocation); + dbContext.WcsTask.Where(t => t.objid == item.objid).Delete(); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 6 }); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog { cmdStatus = 6 }); + dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete(); + dbContext.SaveChanges(); + } + } + + } + else if (item.taskType == 41) + { + WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation + .First(t => t.locationId == item.currPointId); + wmsBaseLocation.outstockFlag = "0"; + wmsBaseLocation.locationStatus = "1"; + wmsBaseLocation.containerCode = ""; + wmsBaseLocation.updateTime = DateTime.Now; + wmsBaseLocation.updateBy = "WCS"; + dbContext.WmsRawOutstock.Where(t => t.orderId == item.orderId).Update(t => new WmsRawOutstock + { + executeStatus = "2" + }); + dbContext.Update(wmsBaseLocation); + dbContext.WmsRawStock.Where(t => t.locationCode == wmsBaseLocation.locationCode).Delete(); + dbContext.WcsTask.Where(t => t.objid == item.objid).Delete(); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 6 }); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog { cmdStatus = 6 }); + dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete(); + dbContext.SaveChanges(); + } + else if (item.taskType == 42) + { + BaseEquip emptyEquip = StaticData.BaseEquip.First(t => t.objid == 35); + BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.objid == 3); + emptyEquip.emptyCount += 1; + emptyEquip.updateTime = DateTime.Now; + emptyEquip.updateBy = "WCS"; + dbContext.Update(emptyEquip); + dbContext.WcsTask.Where(t => t.objid == item.objid).Delete(); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 6 }); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog { cmdStatus = 6 }); + dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete(); + dbContext.SaveChanges(); + } + else if (item.taskType == 43) + { + BaseEquip emptyEquip = StaticData.BaseEquip.First(t => t.objid == 35); + BaseEquip endEquip = StaticData.BaseEquip.First(t => t.objid == item.endPointId); + emptyEquip.emptyCount = 0; + emptyEquip.updateTime = DateTime.Now; + emptyEquip.updateBy = "WCS"; + endEquip.emptyCount = emptyEquip.emptyCount; + endEquip.updateTime = DateTime.Now; + endEquip.updateBy = "WCS"; + dbContext.Update(endEquip); + dbContext.Update(emptyEquip); + } + else if (item.taskType == 44) + { + BaseEquip startEquip = StaticData.BaseEquip.First(t => t.objid == item.startPointId); + BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.objid == 3); + startEquip.emptyCount = 0; + startEquip.updateTime = DateTime.Now; + startEquip.updateBy = "WCS"; + dbContext.Update(startEquip); + BaseEquip endEquip = StaticData.BaseEquip.First(t => t.objid == item.endPointId); + item.nextPointId = lineEquip.objid; + item.nextPointNo = lineEquip.equipNo; + item.fromFloorNo = 3; + item.floorNo = endEquip.floorNo; + item.taskStatus = 6; + dbContext.Update(item); + dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 6, nextPointId = lineEquip.objid, nextPointNo = lineEquip.equipNo, fromFloorNo = 3, floorNo = endEquip.floorNo }); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog { cmdStatus = 6 }); + dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete(); + dbContext.SaveChanges(); + } + } + } + } + break; } } catch (Exception ex) @@ -194,219 +533,5 @@ namespace Khd.Core.Wcs.Wcs } } - public void SendAndUpdateTask(WcsTask task) - { - //获取 - if (task == null) return; - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - WcsToWms wcsToWms = new WcsToWms(); - //首先判断是否已下发指令 - var cmd = dbContext.WcsCmd.Where(t => t.taskId == task.objid).FirstOrDefault(); - var locList = dbContext.WmsBaseLocation.Where(t => t.activeFlag == "1").ToList(); - if (locList.Count == 0) return; - //指令表存在说明已下发 - if (cmd == null) - { //获取下发agv指令 - string ip = ""; int port = 0; string url = ""; - RequestAGVTaskDto agvtask = new RequestAGVTaskDto(); - agvtask.reqCode = task.objid.ToString(); - //var json = JsonConvert.SerializeObject(agvtask); - //HttpHelper.SendPostMessage(ip, port, url, json); - agvtask.positionCodePath = new List(); - Position p = new Position(); - WmsBaseLocation putPos = new WmsBaseLocation(); //放料点 - WmsBaseLocation setPos = new WmsBaseLocation(); //取料点 - if (task.taskType == 5) //入库 - { - setPos = locList.Where(t => t.locationId == task.nextPointId).FirstOrDefault(); - } - else - { - setPos = locList.Where(t => t.locationId == task.nextPointId).FirstOrDefault(); - } - putPos = locList.Where(t => t.locationId == task.nextPointId).FirstOrDefault(); - p.positionCode = setPos?.agvPositionCode; - p.type = ""; - agvtask.positionCodePath.Add(p); - p.positionCode = putPos?.agvPositionCode; - p.type = ""; - //取料点 - agvtask.positionCodePath.Add(p); - agvtask.taskTyp = ""; - //给agv创建任务 - wcsToWms.genAgvSchedulingTask(agvtask); - //未下发给agv下发指令 - WcsCmd taskCmd = new WcsCmd() - { - taskId = task.objid, - cmdType = task.taskType, - serialNo = task.serialNo, - equipmentNo = task.equipmentNo, - cmdStatus = 1, - createBy = FloorNo + "楼AGV", - createTime = DateTime.Now, - }; - dbContext.Add(taskCmd); - dbContext.SaveChanges(); - } - else - { - //获取接驳位是否有托盘 - var IsPallet = this._plc.Read(this.LineIsPallet.plcpointAddress); - if (cmd.sendFlag == 0) - { - if (taskInType.Contains(task.taskType.GetValueOrDefault()))//入库 - { - //入库时有托盘继续任务 - if (Convert.ToInt32(IsPallet) == 1) - { - continueTaskDto continueTask = new continueTaskDto(); - continueTask.taskCode = task.objid.ToString(); - wcsToWms.continueTask(continueTask); - //未下发给agv下发指令 - WcsCmd taskCmd = new WcsCmd() - { - taskId = task.objid, - sendFlag = 1, - createBy = FloorNo + "楼AGV", - createTime = DateTime.Now, - }; - dbContext.Update(taskCmd); - dbContext.SaveChanges(); - } - } - else - { - //出库时没有托盘继续任务 - if (Convert.ToInt32(IsPallet) == 0) - { - continueTaskDto continueTask = new continueTaskDto(); - continueTask.taskCode = task.objid.ToString(); - wcsToWms.continueTask(continueTask); - //更新任务 - dbContext.WcsCmd.Where(t => t.taskId == task.objid).Update(t => new WcsCmd() - { - sendFlag = 1, - updateTime = DateTime.Now, - updateBy = "agv出库", - }); - } - } - } - } - //更新任务表 - dbContext.WcsTask.Where(t => t.objid == task.objid).Update(t => new WcsTask() - { - currPointId = task.currPointId, - currPointNo = task.currPointNo, - nextPointId = task.nextPointId, - nextPointNo = task.nextPointNo, - updateTime = DateTime.Now, - updateBy = "agv出库", - }); - } - //public List GetTask(int floorNo) - //{ - // using var scope = _host.Services.CreateScope(); - // using var dbContext = scope.ServiceProvider.GetRequiredService(); - // List wcsTask = new List(); - // var equip = StaticData.BaseEquip.Where(t => t.floorNo == floorNo && t.equipType == 4).FirstOrDefault(); - // try - // { - // //获取条码号,如果该条码任务存在就继续任务,如果条码不存在,创建入库任务并调度agv - // var taskList = StaticData.WcsTask.Where(t => t.nextPointId == equip.objid && (t.taskType == 1 || t.taskType == 2 || t.taskType == 5 || t.taskType == 6)).ToList(); - // if (taskList.Count() == 0) - // { return null; } - // wcsTask = taskList; - // } - // catch (Exception ex) - // { - // LogManager.Info(floorNo + "楼AGV异常" + ex.Message); - // throw; - // } - // return wcsTask; - //} - //public void SendTask(WcsTask task) - //{ - // //获取 - // if (task == null) return; - // using var scope = _host.Services.CreateScope(); - // using var dbContext = scope.ServiceProvider.GetRequiredService(); - // WcsToWms wcsToWms = new WcsToWms(); - // //首先判断是否已下发指令 - // var cmd = StaticData.WcsCmd.Where(t => t.taskId == task.objid).FirstOrDefault(); - // //指令表存在说明已下发 - // if (cmd == null) - // { //获取下发agv指令 - // string ip = ""; int port = 0; string url = ""; - // RequestAGVTaskDto agvtask = new RequestAGVTaskDto(); - // agvtask.reqCode = task.serialNo.ToString(); - // //var json = JsonConvert.SerializeObject(agvtask); - // //HttpHelper.SendPostMessage(ip, port, url, json); - // wcsToWms.genAgvSchedulingTask(agvtask); - // //未下发给agv下发指令 - // WcsCmd taskCmd = new WcsCmd() - // { - // taskId = task.objid, - // cmdType = task.taskType, - // serialNo = task.serialNo, - // equipmentNo = task.equipmentNo, - // cmdStatus = 1, - // createBy = FloorNo + "楼AGV", - // createTime = DateTime.Now, - // }; - // dbContext.Add(taskCmd); - // dbContext.SaveChanges(); - // } - // else - // { - // //获取接驳位是否有托盘 - // var IsPallet = this._plc.Read(this.LineIsPallet.plcpointAddress); - // if (cmd.sendFlag == 0) - // { - // if (taskInType.Contains(task.taskType.GetValueOrDefault()))//入库 - // { - // //入库时有托盘继续任务 - // if (Convert.ToInt32(IsPallet) == 1) - // { - - // continueTaskDto continueTask = new continueTaskDto(); - // continueTask.taskCode = task.objid.ToString(); - // wcsToWms.continueTask(continueTask); - // //未下发给agv下发指令 - // WcsCmd taskCmd = new WcsCmd() - // { - // taskId = task.objid, - // sendFlag = 1, - // createBy = FloorNo + "楼AGV", - // createTime = DateTime.Now, - // }; - // dbContext.Update(taskCmd); - // dbContext.SaveChanges(); - // } - // } - // else - // { - // //出库时没有托盘继续任务 - // if (Convert.ToInt32(IsPallet) == 0) - // { - // continueTaskDto continueTask = new continueTaskDto(); - // continueTask.taskCode = task.objid.ToString(); - - // wcsToWms.continueTask(continueTask); - // //更新任务 - // dbContext.WcsCmd.Where(t => t.taskId == task.objid).Update(t => new WcsCmd() - // { - // sendFlag = 1, - // updateTime = DateTime.Now, - // updateBy = "agv出库", - // }); - // } - // } - // } - // } - //} - } } diff --git a/src/Khd.Core.Wcs/Wcs/ThirdFloorPoint.cs b/src/Khd.Core.Wcs/Wcs/ThirdFloorPoint.cs index d155d20..39db367 100644 --- a/src/Khd.Core.Wcs/Wcs/ThirdFloorPoint.cs +++ b/src/Khd.Core.Wcs/Wcs/ThirdFloorPoint.cs @@ -1,11 +1,14 @@ using Khd.Core.Domain.Dto.webapi; using Khd.Core.Domain.Models; using Khd.Core.EntityFramework; +using Khd.Core.Library.Mapper; +using Khd.Core.Plc; using Khd.Core.Wcs.Global; using Masuit.Tools.Logging; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Newtonsoft.Json; +using Z.EntityFramework.Plus; namespace Khd.Core.Wcs.Wcs { @@ -64,6 +67,7 @@ namespace Khd.Core.Wcs.Wcs public void MonitorInLocatorPoint() { + List ITypes = new List { 1, 3, 5, 7 }; using var scope = _host.Services.CreateScope(); using var dbContext = scope.ServiceProvider.GetRequiredService(); while (true) @@ -72,26 +76,113 @@ namespace Khd.Core.Wcs.Wcs { dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); //入库任务 - var rfid = this._plc.Read(LineRFID.plcpointAddress); + var rfid = this._plc.ReadRFID(LineRFID.plcpointAddress); var isSignal = this._plc.Read(LineSignal.plcpointAddress); - var isPallet = this._plc.Read(LineIsPallet.plcpointAddress); - if (rfid != null && isSignal != null && isPallet != null) + if (rfid != null && isSignal != null) { - //正常读到输送线信息 有到位信号,并且有托盘,获取条码信息 - if (Convert.ToInt32(isSignal) > 0 && Convert.ToInt32(isPallet) == 1) + + if (Convert.ToInt32(isSignal) == 1)//托盘到位 { - //获取条码信息 - var palletNo = Convert.ToString(rfid); - //获取入库任务 - var wcsTask = GetTask(palletNo, FloorNo, EquipNo); - var nextEquip = StaticData.BaseEquip.Where(t => t.floorNo == FloorNo && t.equipType == 4).FirstOrDefault(); - //更新任务下一点位为AGV - wcsTask.nextPointId = nextEquip.objid; - wcsTask.nextPointNo = nextEquip.equipNo; - wcsTask.updateTime = DateTime.Now; - wcsTask.updateBy = FloorNo + "楼输送线"; - dbContext.Update(wcsTask); - dbContext.SaveChanges(); + BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.floorNo == 3 && t.equipType == 1); + var wcsTask = dbContext.WcsTask.FirstOrDefault(t => t.containerNo == rfid && t.nextPointId == baseEquip.objid); + if (wcsTask != null)//如果不是null + { + if (wcsTask.taskStatus == 5)//提升机任务是完成状态 + { + var wmsBaseLocations = dbContext.WmsBaseLocation.Where(t => t.warehouseFloor == FloorNo) + .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") + .ToList(); + + List containerCodes = wmsBaseLocations.Where(t => t.locDeep == 1).Select(t => t.containerCode).ToList();//深库位的托盘 + List mesBasePalletInfos = dbContext.MesBasePalletInfo + .Where(t => t.materialId == wcsTask.materialId) + .Where(t => containerCodes.Contains(t.palletInfoCode)).ToList();//深库位的托盘的物料等于当前任务的物料 + + var bill = from a in mesBasePalletInfos + join b in wmsBaseLocations.Where(t => t.locDeep == 1) on a.palletInfoCode equals b.containerCode + select new { b };//等于当前任务的物料的托盘的库位信息 + + var outBill = from a in bill + from b in wmsBaseLocations + where a.b.layerNum == b.layerNum + && b.locDeep == 2 + && a.b.locRow == b.locRow + && a.b.locColumn == b.locColumn + && b.locationStatus == "1" + && b.outstockFlag == "0" + && b.instockFlag == "0" + && string.IsNullOrEmpty(b.containerCode) + select new { a.b };//在上面的基础上获取对应托盘的外侧库位的空库位信息 + WmsBaseLocation? wmsBaseLocation = null; + wmsBaseLocation ??= outBill.FirstOrDefault()?.b;//先找相同物料的外侧库位 + wmsBaseLocation ??= wmsBaseLocations.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault(t => t.locDeep == 2);//找不到再找深库位 + wmsBaseLocation ??= wmsBaseLocations.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault();//找不到再找任意库位 + //深浅库位问题?库位入库优先级等 + + var AgvEquip = StaticData.BaseEquip.First(t => t.floorNo == 3 && t.equipType == 4);//背负Agv + if (wmsBaseLocations.Count > 0 && wmsBaseLocation != null) + { + wcsTask.taskStatus = 0;//创建状态 + wcsTask.updateTime = DateTime.Now; + wcsTask.currPointId = baseEquip.objid; + wcsTask.currPointNo = baseEquip.equipNo; + wcsTask.nextPointId = AgvEquip.objid; + wcsTask.nextPointNo = AgvEquip.equipNo; + wcsTask.endPointId = wmsBaseLocation.locationId; + wcsTask.endPointNo = wmsBaseLocation.locationCode; + if (wmsBaseLocation.warehouseId == 311) + { + wcsTask.taskType = 39; + } + else + { + Console.WriteLine("查找入库库位失败"); + Thread.Sleep(1000); + continue; + } + wcsTask.useFlag = 1; + wmsBaseLocation.instockFlag = "1"; + wmsBaseLocation.locationStatus = "2"; + dbContext.Update(wmsBaseLocation); + dbContext.Update(wcsTask); + WcsTaskLog wcsTaskLog = CoreMapper.Map(wcsTask); + dbContext.Add(wcsTaskLog); + dbContext.SaveChanges(); + } + else + { + Console.WriteLine(DateTime.Now + ":三楼楼接驳位调度入库任务,未找到库位"); + LogManager.Info("三楼接驳位调度入库任务,未找到库位"); + } + } + else if (wcsTask.taskStatus == 6)//小车任务是完成状态,说明是出库 + { + BaseEquip nextEquip = StaticData.BaseEquip.First(t => t.equipType == 2);//提升机 + wcsTask.nextPointId = nextEquip.objid; + wcsTask.nextPointNo = nextEquip.equipNo; + wcsTask.currPointId = baseEquip.objid; + wcsTask.currPointNo = baseEquip.equipNo; + wcsTask.fromFloorNo = FloorNo; + wcsTask.taskStatus = 0; + wcsTask.updateTime = DateTime.Now; + dbContext.Update(wcsTask); + dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid) + .Update(t => new WcsTaskLog + { + nextPointId = nextEquip.objid, + nextPointNo = nextEquip.equipNo, + currPointId = baseEquip.objid, + currPointNo = baseEquip.equipNo, + taskStatus = 0, + updateTime = DateTime.Now, + }); + dbContext.SaveChanges(); + } + } } } } @@ -105,121 +196,5 @@ namespace Khd.Core.Wcs.Wcs } } } - //获取输送线上的任务 - public WcsTask GetTask(string containerNo, int floorNo, string equipNo) - { - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - var wcsTask = new WcsTask(); - var wareHouseList = StaticData.WmsBaseWarehouse.ToList(); - try - { - //获取条码号,如果该条码任务存在就继续任务,如果条码不存在,创建入库任务并调度agv - var task = StaticData.WcsTask.Where(t => t.containerNo == containerNo).FirstOrDefault(); - if (task == null) - { - var palletInfo = StaticData.MesBasePalletInfo.Where(t => t.palletInfoCode == containerNo).FirstOrDefault(); - //查询该条码绑定的物料信息 - var material = StaticData.WmsWarehouseMaterial.Where(t => t.storageId == palletInfo.materialId).FirstOrDefault(); - var wareHouse = wareHouseList.Where(t => t.warehouseId == material.warehouseId).FirstOrDefault(); - var dic = StaticData.BaseDictionary.Where(t => t.dicKey == "TaskType" && t.ud1 == "I" && t.dicField == wareHouse.warehouseInstockType).FirstOrDefault(); - var equip = StaticData.BaseEquip.ToList(); - var startEquip = equip.Where(t => t.equipNo == equipNo).FirstOrDefault(); - var endPoint = wareHouseList.Where(t => t.warehouseFloor == floorNo).FirstOrDefault(); - //var currEquip= - if (palletInfo != null) - { - //自动获取id - - var objid = StaticData.SnowId.NextId(); - WcsTask newTask = new() - { - objid = objid, - taskType = Convert.ToInt32(dic.dicValue), - containerNo = containerNo, - taskStatus = 0, - materialId = material.storageId, - qty = Convert.ToInt32(palletInfo.bindAmount), - startPointId = startEquip.objid, - startPointNo = equipNo, - currPointId = startEquip.objid, - currPointNo = equipNo, - endPointId = endPoint.warehouseId, - endPointNo = endPoint.warehouseCode, - }; - dbContext.Add(newTask); - dbContext.SaveChanges(); - wcsTask = newTask; - } - else - { - LogManager.Info(floorNo + "楼接驳位,托盘" + containerNo + "未绑定!"); - } - } - else - { - wcsTask = StaticData.WcsTask.Where(t => t.currPointNo == equipNo).FirstOrDefault(); - } - } - catch (Exception ex) - { - LogManager.Info(floorNo + "楼接驳位异常" + ex.Message); - throw; - } - return wcsTask; - } - /// - /// 下发任务 - /// - /// - public void SendTask(WcsTask task) - { - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - //入库类型 - List taskInType = new List { 1, 3, 5, 7 }; - List taskOutType = new List { 2, 4, 6, 8 }; - try - { - //获取 - if (task == null) return; - if (taskInType.Contains(task.taskType.GetValueOrDefault())) - { - //首先判断是否已下发指令 - var cmd = StaticData.WcsCmd.Where(t => t.taskId == task.objid).FirstOrDefault(); - //指令表存在说明已下发 - if (cmd != null) return; - //获取下发agv指令 - string ip = ""; int port = 0; string url = ""; - RequestAGVTaskDto agvtask = new RequestAGVTaskDto(); - agvtask.reqCode = task.serialNo.ToString(); - var json = JsonConvert.SerializeObject(agvtask); - HttpHelper.SendPostMessage(ip, port, url, json); - //未下发给agv下发指令 - WcsCmd taskCmd = new WcsCmd() - { - taskId = task.objid, - cmdType = task.taskType, - serialNo = task.serialNo, - equipmentNo = task.equipmentNo, - cmdStatus = 1, - createBy = "", - createTime = DateTime.Now, - }; - dbContext.Add(taskCmd); - dbContext.SaveChanges(); - } - else - { - - } - - } - catch (Exception) - { - - throw; - } - } } } diff --git a/src/Khd.Core.Wcs/Wcs/WcsToWms.cs b/src/Khd.Core.Wcs/Wcs/WcsToWms.cs index f6a9a9a..3560269 100644 --- a/src/Khd.Core.Wcs/Wcs/WcsToWms.cs +++ b/src/Khd.Core.Wcs/Wcs/WcsToWms.cs @@ -7,119 +7,6 @@ namespace Khd.Core.Wcs.Wcs { public class WcsToWms { - /// - /// 手工出库调用 - /// - /// - /// - public bool ManualOutWare(RequestManualOutWare requestManualOutWare) - { - //手工出库调用 - var url = "/api/Interface/ManualOutWare"; - var concontentType = "application/json"; - var result = HttpHelper.HttpPost(url, requestManualOutWare.ToJsonString(), concontentType, 60, null); - var model = (ReponseBase)JsonConvert.DeserializeObject(result.ToString(), typeof(ReponseBase)); - if (model.CODE == "S") - { - LogManager.Info("调用成功。"); - } - else - { - LogManager.Info("调用失败。"); - } - return true; - } - /// - /// 盘盈调用 - /// - /// - /// - public bool CheckProfit(RequestCheck requestCheck) - { - //盘盈调用 - var url = "/api/Interface/CheckProfit"; - var concontentType = "application/json"; - var result = HttpHelper.HttpPost(url, requestCheck.ToJsonString(), concontentType, 60, null); - var model = (ReponseBase)JsonConvert.DeserializeObject(result.ToString(), typeof(ReponseBase)); - if (model.CODE == "S") - { - LogManager.Info("调用成功。"); - } - else - { - LogManager.Info("调用失败。"); - } - return true; - } - /// - /// 盘亏调用 - /// - /// - /// - public bool CheckLoss(RequestCheck requestCheck) - { - //盘亏调用 - var url = "/api/Interface/CheckLoss"; - var concontentType = "application/json"; - var result = HttpHelper.HttpPost(url, requestCheck.ToJsonString(), concontentType, 60, null); - var model = (ReponseBase)JsonConvert.DeserializeObject(result.ToString(), typeof(ReponseBase)); - if (model.CODE == "S") - { - LogManager.Info("调用成功。"); - } - else - { - LogManager.Info("调用失败。"); - } - return true; - } - /// - /// 生成任务单 - /// - /// - /// - public ReponseMessage? genAgvSchedulingTask(RequestAGVTaskDto requestAGVTaskDto) - { - //生成任务单 - var url = "http://IP:PORT/rcms/services/rest/hikRpcService/genAgvSchedulingTask"; - var concontentType = "application/json"; - var result = HttpHelper.HttpPost(url, requestAGVTaskDto.ToJsonString(), concontentType, 60, null); - return JsonConvert.DeserializeObject(result.ToString()); - } - /// - /// 继续执行 - /// - /// - /// - public ReponseMessage? continueTask(continueTaskDto continueTaskDto) - { - //继续执行 - var url = "http://IP:PORT/rcms/services/rest/hikRpcService/continueTask"; - var concontentType = "application/json"; - var result = HttpHelper.HttpPost(url, continueTaskDto.ToJsonString(), concontentType, 60, null); - return JsonConvert.DeserializeObject(result.ToString()); - } - /// - /// 继续执行 - /// - /// - /// - public bool cancelTask(RequestAGVTaskDto requestAGVTaskDto) - { - //推送出库数据 - var url = "http://IP:PORT/rcms/services/rest/hikRpcService/cancelTask"; - var concontentType = "application/json"; - var result = HttpHelper.HttpPost(url, requestAGVTaskDto.ToJsonString(), concontentType, 60, null); - var model = (ReponseMessage)JsonConvert.DeserializeObject(result.ToString(), typeof(ReponseMessage)); - if (model.code == "0") - { - LogManager.Info("调用成功。"); - } - else - { - LogManager.Info("调用失败。"); - } - return true; - } + } } diff --git a/src/Khd.Core.Wcs/appsettings.json b/src/Khd.Core.Wcs/appsettings.json index f4a6cf7..c5106ba 100644 --- a/src/Khd.Core.Wcs/appsettings.json +++ b/src/Khd.Core.Wcs/appsettings.json @@ -12,7 +12,23 @@ "Rack": 0, "Slot": 1, "Code": 0 - } + }, + //{ + // "IP": "192.168.2.31", + // "Port": 102, //102是默认端口 + // "CpuType": 40, + // "Rack": 0, + // "Slot": 1, + // "Code": 1 + //}, + //{ + // "IP": "192.168.2.220", + // "Port": 102, //102是默认端口 + // "CpuType": 40, + // "Rack": 0, + // "Slot": 1, + // "Code": 2 + //} ], "PLCSetting": { "Mode": "0", diff --git a/src/Khd.Core.Wpf/App.xaml.cs b/src/Khd.Core.Wpf/App.xaml.cs index fd411d0..518b4b5 100644 --- a/src/Khd.Core.Wpf/App.xaml.cs +++ b/src/Khd.Core.Wpf/App.xaml.cs @@ -1,6 +1,8 @@ using Masuit.Tools; using Microsoft.Extensions.Configuration; using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using System.Windows; namespace Khd.Core.Wpf @@ -25,11 +27,8 @@ namespace Khd.Core.Wpf .AddJsonFile("appsettings.json") .Build(); - PlcConfig.CpuType = configuration["PlcConfig:CpuType"].ToInt32(40); - PlcConfig.IP = configuration["PlcConfig:IP"].ToString(); - PlcConfig.Port = configuration["PlcConfig:Port"].ToInt32(102); - PlcConfig.Rack = (short)(configuration["PlcConfig:Rack"].ToInt32(0)); - PlcConfig.Slot = (short)(configuration["PlcConfig:Slot"].ToInt32(0)); + SystemData.PlcConfigs = configuration.GetSection("PlcConfigs").Get>(); + ConnectionStrings.ConnectionString = configuration["ConnectionStrings:DefaultConnection"].ToString(); //配置文件 加载 Thrift 推送端口 ThriftConfig.ThriftIpAddress = configuration["ThriftConfig:ThriftIpAddress"].ToString(); diff --git a/src/Khd.Core.Wpf/Form/FormBoard.xaml b/src/Khd.Core.Wpf/Form/FormBoard.xaml index 15577cf..1bf068c 100644 --- a/src/Khd.Core.Wpf/Form/FormBoard.xaml +++ b/src/Khd.Core.Wpf/Form/FormBoard.xaml @@ -208,6 +208,7 @@ + + + + + + + + + + + + + + + + + --> + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Khd.Core.Wpf/Form/FormBoardT.xaml.cs b/src/Khd.Core.Wpf/Form/FormBoardT.xaml.cs index 4e45165..b5cdc7d 100644 --- a/src/Khd.Core.Wpf/Form/FormBoardT.xaml.cs +++ b/src/Khd.Core.Wpf/Form/FormBoardT.xaml.cs @@ -16,6 +16,19 @@ using System.Windows.Input; using Khd.Core.Wpf.Scan; using System.IO.Ports; using System.Threading; +using System.Diagnostics; +using Jc.SnowId; +using System.IO; +using System.Runtime.InteropServices; +using System.Windows.Media; +using HandyControl.Tools.Extension; +using Khd.Core.Wpf.TaskForm; +using Microsoft.IdentityModel.Tokens; +using Khd.Core.Plc; +using Khd.Core.Plc.S7; +using System.Threading.Tasks; +using System.Windows.Media.Media3D; +using Masuit.Tools.Logging; namespace Khd.Core.Wpf.Form { @@ -24,6 +37,7 @@ namespace Khd.Core.Wpf.Form /// public partial class FormBoardT : Window { + public static readonly JcSnowId _jcSnowId = new JcSnowId(); private readonly IHost _host; private Khd.Core.Plc.S7.Plc _plc; private DispatcherTimer ShowTimer;//刷新时间 @@ -36,15 +50,10 @@ namespace Khd.Core.Wpf.Form private SerialPortHelper serialPortHelper; List basePlcpoints = new List(); object timerjilu; - public class barcodeinfo - { - public string barcode { get; set; } - public long? materialId { get; set; } + Dictionary SelectedItem = new Dictionary(); + Dictionary InSelectedItem = new Dictionary(); + public List barcodeLsit = new List(); - public decimal? qty { get; set; } - } - - public List barcodeLsit = new List(); private void ScanMessage() @@ -66,7 +75,6 @@ namespace Khd.Core.Wpf.Form SystemData.isUpdate = false; } }); - //检测到哪个文本框获取到了焦点 } } } @@ -102,18 +110,60 @@ namespace Khd.Core.Wpf.Form MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight; WindowState = WindowState.Maximized; } - serialPortModel = new SerialPortModel(); - serialPortModel.PortName = "COM7"; - serialPortModel.BaudRate = 9600; - serialPortModel.DataBits = 8; - serialPortModel.Parity = Parity.None; - serialPortModel.StopBits = StopBits.One; - serialPortHelper = new SerialPortHelper(); - serialPortHelper.OpenMyConn(serialPortModel); + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + SystemData.BasePlcpoints = dbContext.BasePlcpoint.ToList(); + SystemData.BaseDictionary = dbContext.BaseDictionary.ToList(); + SystemData.BaseEquip = dbContext.BaseEquip.ToList(); + SystemData.BaseWareHouse = dbContext.WmsBaseWarehouse.ToList(); + WarehourseId.ItemsSource = SystemData.BaseWareHouse.Where(t => t.warehouseFloor != 1 && t.warehouseFloor != 4).ToList(); + Task.Run(() => + { + while (true) + { + try + { + serialPortModel = new SerialPortModel(); + serialPortModel.PortName = "COM7"; + serialPortModel.BaudRate = 9600; + serialPortModel.DataBits = 8; + serialPortModel.Parity = Parity.None; + serialPortModel.StopBits = StopBits.One; + serialPortHelper = new SerialPortHelper(); + serialPortHelper.OpenMyConn(serialPortModel); - Thread scanThread = new Thread(ScanMessage); - scanThread.IsBackground = true; - scanThread.Start(); + Thread scanThread = new Thread(ScanMessage); + scanThread.IsBackground = true; + scanThread.Start(); + break; + } + catch + { + + } + Thread.Sleep(10000); + } + }); + Task.Run(() => + { + foreach (var plcConfig in SystemData.PlcConfigs) + { + if (!SystemData.PlcDic.Any(t => t.Key == plcConfig.Code)) + { + Plc.S7.Plc plc; + plc = new Plc.S7.Plc(plcConfig.CpuType, plcConfig.IP, plcConfig.Port, plcConfig.Rack, plcConfig.Slot); + try + { + plc.Open(); + } + catch(Exception ex) + { + LogManager.Error(ex); + } + SystemData.PlcDic.TryAdd(plcConfig.Code, plc); + } + } + }); //加载dategrid信息 //LoadMaterial_GetMessage(""); //连接PLC判断 @@ -152,13 +202,15 @@ namespace Khd.Core.Wpf.Form // "102上件点", // "103上件点" // }; - } catch (Exception ex) { MessageBox.Show(ex.Message); } } + + + /// /// 显示序号事件 /// @@ -192,13 +244,63 @@ namespace Khd.Core.Wpf.Form { GetTask(); } + + //private void GetTaskLog() + //{ + // try + // { + // using var scope = _host.Services.CreateScope(); + // using var dbContext = scope.ServiceProvider.GetRequiredService(); + // List wcsTaskLogs = new List(); + // for (int i = 1; i <= 5; i++) + // { + // BasePlcpoint basePlcpoint = SystemData.BasePlcpoints.First(t => t.plcpointNo == "RFID00" + i); + // string? rifd = SystemData.PlcDic[0].ReadRFID(basePlcpoint.plcpointAddress); + // string floor = i.ToString(); + // var wcsTaskLog = dbContext.WcsTaskLog.FirstOrDefault(t => t.ud3 == "1" && t.ud2 == floor && t.containerNo == rifd); + // if (wcsTaskLog != null) + // { + // wcsTaskLogs.Add(wcsTaskLog); + // } + // } + // this.WcsTaskLogDataGrid.ItemsSource = wcsTaskLogs; + // this.WcsTaskLogDataGrid.Items.Refresh(); + // if (wcsTaskLogs.Count == 0) + // { + // MessageBox.Show("未查询到数据"); + // } + // } + // catch (Exception ex) + // { + // if (ex is PlcException) + // { + // try + // { + // SystemData.PlcDic[0] = new Plc.S7.Plc(SystemData.PlcDic[0].CPU, SystemData.PlcDic[0].IP, SystemData.PlcDic[0].Port, SystemData.PlcDic[0].Rack, SystemData.PlcDic[0].Slot); + // SystemData.PlcDic[0].Open(); + // GetTaskLog(); + // } + // catch + // { + // MessageBox.Show("PLC连接失败,无法读取任务"); + // } + // } + // } + + //} + private void GetTask() { using var scope = _host.Services.CreateScope(); using var dbContext = scope.ServiceProvider.GetRequiredService(); var equipCode = lba_ThrifTtitle1.Text; var palletNo = lba_ThrifTtitle2.Text; - var data = dbContext.WcsTask.Where(t => t.useFlag == 1 && t.containerNo.Contains(palletNo) && t.equipmentNo.Contains(equipCode)).ToList(); + var data = dbContext.WcsTask.Where(t => t.containerNo.Contains(palletNo) && t.equipmentNo.Contains(equipCode)).ToList(); + SelectedItem.Clear(); + foreach (var item in data) + { + SelectedItem.Add(item.objid, false); + } this.LoadMaterial0.ItemsSource = null; this.LoadMaterial0.ItemsSource = data; this.LoadMaterial0.Items.Refresh(); @@ -220,13 +322,30 @@ namespace Khd.Core.Wpf.Form } else { - var Currentselected = LoadMaterial0.SelectedItem as WcsTask; - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - Currentselected.useFlag = 0; - dbContext.WcsTask.Update(Currentselected); - dbContext.SaveChanges(); - GetTask(); + MessageBoxResult messageBoxResult = MessageBox.Show("确定要删除这些任务吗?", "提示信息", MessageBoxButton.YesNo); + if (messageBoxResult == MessageBoxResult.Yes) + { + var Currentselected = LoadMaterial0.SelectedItem as WcsTask; + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + List ids = new List(); + foreach (var item in SelectedItem) + { + if (item.Value == true) + { + ids.Add(item.Key); + } + } + dbContext.WcsTask.Where(t => ids.Contains(t.objid)).Delete(); + dbContext.WcsTaskLog.Where(t => ids.Contains(t.objid)).Update(t => new WcsTaskLog { IsDelete = 1 }); + dbContext.SaveChanges(); + GetTask(); + } + else + { + + } + } } /// @@ -278,88 +397,109 @@ namespace Khd.Core.Wpf.Form /// private void btnGetStocK_Click(object sender, RoutedEventArgs e) { + if (WarehourseId.SelectedItem is WmsBaseWarehouse warehouse) + { + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + var locationCode = lba_ThrifTtitle6.Text; + long materialId = 0; + try + { + materialId = Convert.ToInt64(lba_ThrifTtitle5.Text); + } + catch + { + + } + var data = dbContext.WmsRawStock + .WhereIf(!string.IsNullOrEmpty(lba_ThrifTtitle6.Text), t => t.locationCode.Contains(locationCode)) + .WhereIf(!string.IsNullOrEmpty(lba_ThrifTtitle5.Text), t => t.materialId == materialId) + .Where(t => t.warehouseId == warehouse.warehouseId) + .ToList(); + this.LoadMaterial1.ItemsSource = null; + this.LoadMaterial1.ItemsSource = data; + this.LoadMaterial1.Items.Refresh(); + if (data.Count == 0) + { + MessageBox.Show("未查询到数据"); + } - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - var locationCode = lba_ThrifTtitle6.Text; - var materialCode = lba_ThrifTtitle5.Text; - var data = dbContext.WcsStock.Where(t => t.useFlag == 1 && t.materialCode.Contains(materialCode) && t.locationCode.Contains(locationCode)).ToList(); - this.LoadMaterial1.ItemsSource = null; - this.LoadMaterial1.ItemsSource = data; - this.LoadMaterial1.Items.Refresh(); - if (data.Count == 0) - { - MessageBox.Show("未查询到数据"); - } - } - /// - /// 查询指令信息 - /// - /// - /// - private void btnGetWcsCmd_Click(object sender, RoutedEventArgs e) - { - GetWcsCmd(); - } - private void GetWcsCmd() - { - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - var equipCode = txtEquipNo.Text; - var ContainNo = txtContainNo.Text; - var data = dbContext.WcsCmd.Where(t => t.useFlag == 1 && t.containerNo.Contains(ContainNo) && t.equipmentNo.Contains(equipCode)).ToList(); - this.LoadMaterial.ItemsSource = null; - this.LoadMaterial.ItemsSource = data; - this.LoadMaterial.Items.Refresh(); - if (data.Count == 0) - { - MessageBox.Show("未查询到数据"); - } - } - /// - /// 删除指令 - /// - /// - /// - private void btnDelCmd_Click(object sender, RoutedEventArgs e) - { - if (LoadMaterial.SelectedIndex == -1) - { - MessageBox.Show("请选择要删除的指令!"); } else { - var Currentselected = LoadMaterial.SelectedItem as WcsCmd; - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - Currentselected.useFlag = 0; - dbContext.WcsCmd.Update(Currentselected); - dbContext.SaveChanges(); - GetWcsCmd(); - } - } - /// - /// 重发指令 - /// - /// - /// - private void btnReSendCmd_Click(object sender, RoutedEventArgs e) - { - if (LoadMaterial.SelectedIndex == -1) - { - MessageBox.Show("请选择要重发的指令!"); - } - else - { - var Currentselected = LoadMaterial.SelectedItem as WcsCmd; - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - Currentselected.sendFlag = 0; - dbContext.WcsCmd.Update(Currentselected); - dbContext.SaveChanges(); - GetWcsCmd(); + MessageBox.Show("请选择仓库!"); + return; } + } + ///// + ///// 查询指令信息 + ///// + ///// + ///// + //private void btnGetWcsCmd_Click(object sender, RoutedEventArgs e) + //{ + // GetWcsCmd(); + //} + //private void GetWcsCmd() + //{ + // using var scope = _host.Services.CreateScope(); + // using var dbContext = scope.ServiceProvider.GetRequiredService(); + // var equipCode = txtEquipNo.Text; + // var ContainNo = txtContainNo.Text; + // var data = dbContext.WcsCmd.Where(t => t.useFlag == 1 && t.containerNo.Contains(ContainNo) && t.equipmentNo.Contains(equipCode)).ToList(); + // this.LoadMaterial.ItemsSource = null; + // this.LoadMaterial.ItemsSource = data; + // this.LoadMaterial.Items.Refresh(); + // if (data.Count == 0) + // { + // MessageBox.Show("未查询到数据"); + // } + //} + ///// + ///// 删除指令 + ///// + ///// + ///// + //private void btnDelCmd_Click(object sender, RoutedEventArgs e) + //{ + // if (LoadMaterial.SelectedIndex == -1) + // { + // MessageBox.Show("请选择要删除的指令!"); + // } + // else + // { + // var Currentselected = LoadMaterial.SelectedItem as WcsCmd; + // using var scope = _host.Services.CreateScope(); + // using var dbContext = scope.ServiceProvider.GetRequiredService(); + // Currentselected.useFlag = 0; + // dbContext.WcsCmd.Update(Currentselected); + // dbContext.SaveChanges(); + // GetWcsCmd(); + // } + //} + ///// + ///// 重发指令 + ///// + ///// + ///// + //private void btnReSendCmd_Click(object sender, RoutedEventArgs e) + //{ + // if (LoadMaterial.SelectedIndex == -1) + // { + // MessageBox.Show("请选择要重发的指令!"); + // } + // else + // { + // var Currentselected = LoadMaterial.SelectedItem as WcsCmd; + // using var scope = _host.Services.CreateScope(); + // using var dbContext = scope.ServiceProvider.GetRequiredService(); + // Currentselected.sendFlag = 0; + // dbContext.WcsCmd.Update(Currentselected); + // dbContext.SaveChanges(); + // GetWcsCmd(); + // } + //} /// /// 呼叫料箱 /// @@ -367,47 +507,42 @@ namespace Khd.Core.Wpf.Form /// private void btnCallBox_Click(object sender, RoutedEventArgs e) { - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - - if (int.TryParse(txtNum.Text, out int num)) + try { - //目的地 - var endEquip = dbContext.BaseEquip.Where(t => t.equipNo == "FL05").FirstOrDefault(); - //所有辅料库位 - var wmsBaseLocation = dbContext.WmsBaseLocation.Where(t => t.warehouseId == 5).ToList(); //五楼辅料库 - //有库存的库位 - var wmsStock = dbContext.WcsStock.Where(t => t.useFlag == 1).Select(t => t.locationCode).ToList(); - var EmptyBox = wmsBaseLocation.Where(t => !t.locationCode.Contains(wmsStock)).ToList(); - - for (int i = 0; i < num; i++) + if (!string.IsNullOrEmpty(callMaterialId.Text)) { - var wcsTask = new WcsTask() + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + + if (int.TryParse(txtNum.Text, out int num)) { - objid = Global.SnowId.NextId(), - startPointId = EmptyBox[i].locationId, - startPointNo = EmptyBox[i].agvPositionCode, - currPointId = EmptyBox[i].locationId, - currPointNo = EmptyBox[i].agvPositionCode, - nextPointId = endEquip.objid, - nextPointNo = endEquip.equipNo, - endPointId = endEquip.objid, - endPointNo = endEquip.equipNo, - taskType = 13, - taskStatus = 0, - floorNo = 5, - containerNo = EmptyBox[i].containerCode, - equipmentNo = endEquip.equipNo, - createBy = "5楼呼叫料箱任务", - createTime = System.DateTime.Now, - }; - dbContext.Add(wcsTask); - dbContext.SaveChanges(); + WmsRawOutstock wmsRawOutstock = new WmsRawOutstock() + { + rawOutstockId = _jcSnowId.NextId(), + taskCode = "task", + warehouseId = 512, + materialId = Convert.ToInt32(callMaterialId.Text), + outstockAmount = Convert.ToInt32(txtNum.Text), + realOutstockAmount = 0, + endStationCode = "FL052", + auditStatus = "0", + operationType = "1", + taskType = "1", + executeStatus = "0" + }; + dbContext.Add(wmsRawOutstock); + dbContext.SaveChanges(); + MessageBox.Show("料箱呼叫任务添加成功!"); + } + else + { + MessageBox.Show("请输入有效的数字"); + } } } - else + catch { - MessageBox.Show("请输入有效的数字"); + } } /// @@ -427,27 +562,34 @@ namespace Khd.Core.Wpf.Form /// /// /// - private void txtBarCode_KeyDown(object sender, KeyEventArgs e) + private void txtBarCode_KeyDown(object sender, RoutedEventArgs e) { - if (e.Key == Key.Enter) + try { - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - var mesInfo = dbContext.MesBaseBarcodeInfo.Where(t => t.barcodeInfo == txtBarCode.Text).FirstOrDefault(); - if (mesInfo == null) + if (!string.IsNullOrEmpty(txtBarCode.Text)) { - MessageBox.Show("请扫描正确的条码"); - return; + if (!(barcodeLsit.Where(t => t.barcodeInfo == txtBarCode.Text).Count() > 0)) + { + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + var mesInfo = dbContext.MesBaseBarcodeInfo.Where(t => t.barcodeInfo == txtBarCode.Text).FirstOrDefault(); + if (mesInfo == null) + { + MessageBox.Show("请扫描正确的条码"); + return; + } + barcodeLsit.Add(mesInfo); + txtBarCode.SelectAll(); + txtBarCode.Focus(); + txtScan.Text = $"{(mesInfo.batchFlag == "1" ? 1 : mesInfo.amount)}"; + } } - barcodeinfo barcodeinfo = new barcodeinfo(); - barcodeinfo.barcode = txtBarCode.Text; - barcodeinfo.materialId = mesInfo.materialId; - barcodeinfo.qty = mesInfo.amount; - barcodeLsit.Add(barcodeinfo); - txtBarCode.SelectAll(); - txtBarCode.Focus(); - txtScan.Text = $"已扫描{barcodeLsit.Count}个"; } + catch + { + + } + } /// /// 确认 @@ -456,112 +598,508 @@ namespace Khd.Core.Wpf.Form /// private void btnConfirmBox_Click(object sender, RoutedEventArgs e) { - var box = txtBox.Text; - if (string.IsNullOrEmpty(box)) + try { - MessageBox.Show("容器号不能为空!"); - return; - } - if (barcodeLsit.Count == 0) - { - MessageBox.Show("未扫描条码!"); - return; - } - using var scope = _host.Services.CreateScope(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); - if (cbxType.Text == "入库") - { - //写入wms_raw_instock - var wmsRawInstock = new WmsRawInstock() + var box = txtBox.Text; + if (string.IsNullOrEmpty(box)) { - rawInstockId = Global.SnowId.NextId(), - warehouseId = 5, - operationType = "3", - instockType = "9", - materialId = barcodeLsit.FirstOrDefault().materialId, - palletInfoCode = txtBox.Text, - instockAmount = barcodeLsit.Sum(t => t.qty), - executeStatus = "0", - applyBy = "扫描入库", - applyDate = System.DateTime.Now - }; - dbContext.WmsRawInstock.Add(wmsRawInstock); - dbContext.SaveChanges(); - var startEquip = dbContext.BaseEquip.Where(t => t.equipNo == "FL05").FirstOrDefault(); - var warehouse = dbContext.WmsBaseWarehouse.Where(t => t.warehouseId == 5).FirstOrDefault(); - //写入wcs任务 - var wcsTask = new WcsTask() + MessageBox.Show("容器号不能为空!"); + return; + } + if (barcodeLsit.Count == 0) { - objid = Global.SnowId.NextId(), - startPointId = startEquip.objid, - startPointNo = startEquip.agvPositionCode, - currPointId = startEquip.objid, - currPointNo = startEquip.agvPositionCode, - nextPointId = warehouse.warehouseId, - nextPointNo = warehouse.warehouseCode, - endPointId = warehouse.warehouseId, - endPointNo = warehouse.warehouseCode, - taskType = 4, - taskStatus = 0, - floorNo = 5, - containerNo = txtBox.Text, - equipmentNo = startEquip.equipNo, - createBy = "5楼入库任务", - createTime = System.DateTime.Now, - }; - dbContext.Add(wcsTask); - dbContext.SaveChanges(); + MessageBox.Show("未扫描条码!"); + return; + } + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + WmsBaseLocation? wmsBaseLocation = dbContext.WmsBaseLocation.Where(t => t.warehouseId == 512 && t.containerCode == box).FirstOrDefault(); + if (wmsBaseLocation == null) + { + MessageBox.Show("容器号不存在!,请重新扫描!"); + return; + } + if (cbxType.Text == "入库") + { + var batchCodes = barcodeLsit.Select(t => t.batchCode); + List wmsRawStocks = dbContext.WmsRawStock + .Where(t => batchCodes.Contains(t.instockBatch)) + .Where(t => t.warehouseFloor == 5 && t.warehouseId == 512).ToList(); + if (wmsRawStocks.Count > 0) + { + MessageBox.Show("该批次已入库!"); + return; + } + foreach (var item in barcodeLsit) + { + WmsRawStock? wmsRawStock = dbContext.WmsRawStock + .Where(t => t.palletInfoCode == box) + .Where(t => t.instockBatch == item.batchCode).FirstOrDefault(); + if (wmsRawStock == null) + { + var newRawStock = new WmsRawStock() + { + materialId = item.materialId, + supplierId = item.manufacturerId, + instockBatch = item.batchCode, + locationCode = wmsBaseLocation.locationCode, + stockType = "1", + palletInfoCode = box, + totalAmount = item.batchFlag == "1" ? 1 : item.amount, + activeFlag = "1", + occupyAmount = 0, + completeFlag = "1", + frozenAmount = 0, + instockDate = System.DateTime.Now, + rawStockId = Global.SnowId.NextId(), + saleOrderId = item.saleOrderId, + warehouseFloor = 5, + warehouseId = 512, + createBy = "扫描入库", + createDate = System.DateTime.Now + }; + dbContext.WmsRawStock.Add(newRawStock); + } + else + { + MessageBox.Show("该批次已入库!"); + return; + } + } + dbContext.SaveChanges(); + MessageBox.Show("入库成功!"); + } + if (cbxType.Text == "出库") + { + long? materialId = barcodeLsit.FirstOrDefault().materialId; + WmsRawOutstock? wmsRawOutstock = dbContext.WmsRawOutstock + .Where(t => t.auditStatus == "1") + .Where(t => t.executeStatus == "1") + .Where(t => t.warehouseId == 512) + .Where(t => t.realOutstockAmount < t.outstockAmount) + .Where(t => t.materialId == materialId) + .FirstOrDefault(); + if (wmsRawOutstock != null) + { + //从料箱里拿出来 + WmsRawStock? wmsRawStock = dbContext.WmsRawStock.Where(t => t.palletInfoCode == box).Where(t => t.materialId == materialId).FirstOrDefault(); + if (wmsRawStock != null) + { + dbContext.WmsRawStock.Where(t => t.rawStockId == wmsRawStock.rawStockId).Delete(); + wmsRawOutstock.realOutstockAmount += 1; + if (wmsRawOutstock.realOutstockAmount >= wmsRawOutstock.outstockAmount) + { + wmsRawOutstock.executeStatus = "2"; + wmsRawOutstock.endTime = DateTime.Now; + } + dbContext.Update(wmsRawOutstock); + dbContext.SaveChanges(); + } + else + { + MessageBox.Show("当前容器不存在当前扫描物料"); + } + } + + } + if (cbxType.Text == "回库") + { + var batchCodes = barcodeLsit.Select(t => t.batchCode); + List wmsRawStocks = dbContext.WmsRawStock + .Where(t => batchCodes.Contains(t.instockBatch)) + .Where(t => t.warehouseFloor == 5 && t.warehouseId == 512).ToList(); + if (wmsRawStocks.Count > 0) + { + MessageBox.Show("该批次已入库!"); + return; + } + foreach (var item in barcodeLsit) + { + WmsRawStock? wmsRawStock = dbContext.WmsRawStock + .Where(t => t.palletInfoCode == box) + .Where(t => t.instockBatch == item.batchCode).FirstOrDefault(); + if (wmsRawStock == null) + { + var newRawStock = new WmsRawStock() + { + materialId = item.materialId, + supplierId = item.manufacturerId, + instockBatch = item.batchCode, + locationCode = wmsBaseLocation.locationCode, + stockType = "1", + palletInfoCode = box, + totalAmount = item.batchFlag == "1" ? 1 : item.amount, + activeFlag = "1", + occupyAmount = 0, + completeFlag = "1", + frozenAmount = 0, + instockDate = System.DateTime.Now, + rawStockId = Global.SnowId.NextId(), + saleOrderId = item.saleOrderId, + warehouseFloor = 5, + warehouseId = 512, + createBy = "扫描回库", + createDate = System.DateTime.Now + }; + dbContext.WmsRawStock.Add(newRawStock); + } + else + { + MessageBox.Show("该批次已入库!"); + return; + } + } + dbContext.SaveChanges(); + MessageBox.Show("回库成功!"); + } } - if (cbxType.Text == "出库") + catch { - //从料箱里拿出来 + } - if (cbxType.Text == "回库") + + } + /// + /// 退出程序 + /// + /// + /// + private void WindowClose_Click(object sender, RoutedEventArgs e) + { + if (MessageBox.Show("是否确认关闭程序", "提示信息", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { - //写入wms_raw_instock - var wmsRawInstock = new WmsRawInstock() - { - rawInstockId = Global.SnowId.NextId(), - warehouseId = 5, - operationType = "3", - instockType = "9", - materialId = barcodeLsit.FirstOrDefault().materialId, - palletInfoCode = txtBox.Text, - instockAmount = barcodeLsit.Sum(t => t.qty), - executeStatus = "0", - applyBy = "扫描回库", - applyDate = System.DateTime.Now - }; - dbContext.WmsRawInstock.Add(wmsRawInstock); - dbContext.SaveChanges(); - var startEquip = dbContext.BaseEquip.Where(t => t.equipNo == "FL05").FirstOrDefault(); - var warehouse = dbContext.WmsBaseWarehouse.Where(t => t.warehouseId == 5).FirstOrDefault(); - //写入wcs任务 - var wcsTask = new WcsTask() - { - objid = Global.SnowId.NextId(), - startPointId = startEquip.objid, - startPointNo = startEquip.agvPositionCode, - currPointId = startEquip.objid, - currPointNo = startEquip.agvPositionCode, - nextPointId = warehouse.warehouseId, - nextPointNo = warehouse.warehouseCode, - endPointId = warehouse.warehouseId, - endPointNo = warehouse.warehouseCode, - taskType = 4, - taskStatus = 0, - floorNo = 5, - containerNo = txtBox.Text, - equipmentNo = startEquip.equipNo, - createBy = "5楼回库任务", - createTime = System.DateTime.Now, - }; - dbContext.Add(wcsTask); - dbContext.SaveChanges(); + System.Environment.Exit(System.Environment.ExitCode); } } + /// + /// 获取聚焦打开键盘 + /// + /// + /// + private void TextBoxGetFocus(object sender, RoutedEventArgs e) + { + try + { + Process process = new Process() + { + StartInfo ={ + UseShellExecute=true, + FileName="osk.exe" + } + }; + process.Start(); + } + catch (Exception ex) + { + MessageBox.Show("打开软键盘时出错: " + ex.Message); + } + } + /// + /// 失去焦点,关闭软键盘 + /// + /// + /// + private void TextBoxLostFocus(object sender, RoutedEventArgs e) + { + try + { + //将打开的osk.exe进程关闭 + Process[] processes = Process.GetProcessesByName("osk"); + foreach (Process process in processes) + { + process.Kill(); + } + } + catch (Exception ex) + { + MessageBox.Show("打开软键盘时出错: " + ex.Message); + } + } + /// + /// 背负式小车确认完成 + /// + /// + /// + private void btnBearConfirmBox_Click(object sender, RoutedEventArgs e) + { + try + { + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + var wcsCmd = dbContext.WcsCmd + .Where(t => t.cmdStatus == 6) + .Where(t => t.nextPointId == 21) + .FirstOrDefault(); + if (wcsCmd == null) + { + MessageBox.Show("未查询到当前有背负式Agv由装配区到捡料区任务"); + } + else + { + dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmd { cmdStatus = 7 }); + dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog { cmdStatus = 7 }); + dbContext.WcsTask.Where(t => t.objid == wcsCmd.taskId).Update(t => new WcsTask { taskStatus = 7 }); + dbContext.WcsTaskLog.Where(t => t.objid == wcsCmd.taskId).Update(t => new WcsTaskLog { taskStatus = 7 }); + MessageBox.Show("背负式Agv任务确认完成成功"); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + /// + /// 获取到所有控件 + /// + /// + /// + private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + List visuals = this.GetChildren().ToList(); + + foreach (var control in visuals)//遍历所有控件 + { + if (control is TextBox textBox)//如果控件是文本框 + { + textBox.GotFocus += TextBoxGetFocus;//获取焦点事件 + textBox.LostFocus += TextBoxLostFocus;//失去焦点事件 + } + } + } + /// + /// 添加任务 + /// + /// + /// + private void AddTaskButton_Click(object sender, RoutedEventArgs e) + { + AddTask addTask = new AddTask(_host); + addTask.ShowDialog(); + } + /// + /// 清除RFID + /// + /// + /// + private void clearRFID_Click(object sender, RoutedEventArgs e) + { + txtBox.Text = string.Empty; + } + /// + /// 清除条码 + /// + /// + /// + private void clearBarCode_Click(object sender, RoutedEventArgs e) + { + txtScan.Text = string.Empty; + barcodeLsit.Clear(); + txtBarCode.Text = string.Empty; + } + /// + /// 人工叫料失去焦点 + /// + /// + /// + private void callMaterialId_LostFocus(object sender, RoutedEventArgs e) + { + try + { + if (!string.IsNullOrEmpty(callMaterialId.Text)) + { + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + var material = dbContext.WmsRawStock.Where(t => t.instockBatch == callMaterialId.Text).FirstOrDefault(); + if (material == null) + { + MessageBox.Show("批次号不存在!"); + callMaterialId.Text = string.Empty; + } + else + { + + } + } + } + catch + { + + } + + } + /// + /// 开始任务 + /// + /// + /// + private void btnEditTask_Click(object sender, RoutedEventArgs e) + { + try + { + if (LoadMaterial0.SelectedIndex == -1) + { + MessageBox.Show("请选择要开始的任务!"); + } + else + { + var Currentselected = LoadMaterial0.SelectedItem as WcsTask; + using var scope = _host.Services.CreateScope(); + using var dbContext = scope.ServiceProvider.GetRequiredService(); + List wcsTasks = dbContext.WcsTask.ToList(); + List ids = new List(); + foreach (var item in SelectedItem) + { + if (item.Value == true) + { + WcsTask? wcsTask = wcsTasks.FirstOrDefault(); + if (wcsTask != null && wcsTask.taskStatus <= 0) + { + ids.Add(item.Key); + } + } + } + dbContext.WcsTask.Where(t => ids.Contains(t.objid)).Update(t => new WcsTask { useFlag = 1, taskStatus = 0 }); + GetTask(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + + } + /// + /// 单选 + /// + /// + /// + private void CheckBox_Click(object sender, RoutedEventArgs e) + { + if (sender is CheckBox checkbox && LoadMaterial0.SelectedItem is WcsTask Currentselected) + { + SelectedItem[Currentselected.objid] = checkbox.IsChecked ?? false; + } + //} + ///// + ///// 入库确认单选 + ///// + ///// + ///// + //private void InCheckBox_Click(object sender, RoutedEventArgs e) + //{ + // if (sender is CheckBox checkbox && WcsTaskLogDataGrid.SelectedItem is WcsTaskLog Currentselected) + // { + // InSelectedItem[Currentselected.objid] = checkbox.IsChecked ?? false; + // } + //} + ///// + ///// 搜素 + ///// + ///// + ///// + //private void InSearchButton_Click(object sender, RoutedEventArgs e) + //{ + // GetTaskLog(); + //} + /// + /// 入库确认 + /// + /// + /// + //private void ConfirmTaskButton_Click(object sender, RoutedEventArgs e) + //{ + // try + // { + // List ids = new List(); + // foreach (var item in InSelectedItem) + // { + // if (item.Value == true) + // { + // ids.Add(item.Key); + // } + // } + // using var scope = _host.Services.CreateScope(); + // using var dbContext = scope.ServiceProvider.GetRequiredService(); + // dbContext.WcsTaskLog.Where(t => ids.Contains(t.objid)).Update(t => new WcsTask { ud3 = "10" }); + // GetTaskLog(); + // } + // catch(Exception ex) + // { + // MessageBox.Show(ex.Message); + // } + + //} + } + + private void btnRefreshPlc_Click(object sender, RoutedEventArgs e) + { + try + { + for (int i = 1; i <= 5; i++) + { + BasePlcpoint rfid = SystemData.BasePlcpoints.First(t => t.plcpointNo == $"RFID00{i}"); + BasePlcpoint linesignal = SystemData.BasePlcpoints.First(t => t.plcpointNo == $"linesignal0{i}"); + BasePlcpoint wcsrun = SystemData.BasePlcpoints.First(t => t.plcpointNo == $"wcsrun0{i}"); + var textBlock = FindName(rfid.plcpointNo) as TextBlock; + if (textBlock != null) + { + textBlock.Text = SystemData.PlcDic[0].ReadRFID(rfid.plcpointAddress); + } + textBlock = FindName(linesignal.plcpointNo) as TextBlock; + if (textBlock != null) + { + textBlock.Text = SystemData.PlcDic[0].Read(linesignal.plcpointAddress)?.ToString(); + } + textBlock = FindName(wcsrun.plcpointNo) as TextBlock; + if (textBlock != null) + { + textBlock.Text = SystemData.PlcDic[0].Read(wcsrun.plcpointAddress)?.ToString(); + } + } + BasePlcpoint RFID5001 = SystemData.BasePlcpoints.First(t => t.plcpointNo == "RFID5001"); + BasePlcpoint isarrive = SystemData.BasePlcpoints.First(t => t.plcpointNo == "isarrive"); + BasePlcpoint isput = SystemData.BasePlcpoints.First(t => t.plcpointNo == "isput"); + var CtuTextBlock = FindName(RFID5001.plcpointNo) as TextBlock; + if (CtuTextBlock != null) + { + CtuTextBlock.Text = SystemData.PlcDic[1].ReadRFID(RFID5001.plcpointAddress); + } + CtuTextBlock = FindName(isarrive.plcpointNo) as TextBlock; + if (CtuTextBlock != null) + { + CtuTextBlock.Text = SystemData.PlcDic[1].Read(isarrive.plcpointAddress)?.ToString(); + } + CtuTextBlock = FindName(isput.plcpointNo) as TextBlock; + if (CtuTextBlock != null) + { + CtuTextBlock.Text = SystemData.PlcDic[1].Read(isput.plcpointAddress)?.ToString(); + } + } + catch(Exception ex) + { + try + { + if (ex is PlcException) + { + foreach (var item in SystemData.PlcDic) + { + if (item.Value.IP == ex.Message) + { + SystemData.PlcDic[item.Key] = new Plc.S7.Plc(item.Value.CPU, item.Value.IP, item.Value.Port, item.Value.Slot, item.Value.Rack); + SystemData.PlcDic[item.Key].Open(); + break; + } + } + } + } + catch + { + MessageBox.Show("PLC连接失败!"); + } + + } + + } } - - } diff --git a/src/Khd.Core.Wpf/Global/PlcConfig.cs b/src/Khd.Core.Wpf/Global/PlcConfig.cs index 8cc45ba..397d254 100644 --- a/src/Khd.Core.Wpf/Global/PlcConfig.cs +++ b/src/Khd.Core.Wpf/Global/PlcConfig.cs @@ -1,14 +1,16 @@ using Jc.SnowId; +using Khd.Core.Plc.S7; namespace Khd.Core.Wpf { - public static class PlcConfig + public class PlcConfig { - public static int CpuType { get; set; } - public static string IP { get; set; } - public static int Port { get; set; } - public static short Rack { get; set; } - public static short Slot { get; set; } + public CpuType CpuType { get; set; } + public string IP { get; set; } + public int Port { get; set; } + public short Rack { get; set; } + public short Slot { get; set; } + public int Code { get; set; } } public static class ConnectionStrings { diff --git a/src/Khd.Core.Wpf/SystemData.cs b/src/Khd.Core.Wpf/SystemData.cs index 3d8da34..149e7b0 100644 --- a/src/Khd.Core.Wpf/SystemData.cs +++ b/src/Khd.Core.Wpf/SystemData.cs @@ -1,13 +1,41 @@ -using System; +using Khd.Core.Domain.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Media; namespace Khd.Core.Wpf { - public class SystemData + public static class SystemData { + public static IEnumerable GetChildren(this Visual parent, bool recurse = true) + { + if (parent != null) + { + int count = VisualTreeHelper.GetChildrenCount(parent); + for (int i = 0; i < count; i++) + { + // Retrieve child visual at specified index value. + var child = VisualTreeHelper.GetChild(parent, i) as Visual; + + if (child != null) + { + yield return child;// 聚集函数,调用到这不会立刻结束方法,而是在集合中添加元素,直到方法结束,将集合返回 + + if (recurse) + { + foreach (var grandChild in child.GetChildren(true)) + { + yield return grandChild; + } + } + } + } + } + } + public static string _message { get; set; } public static object _lock = new object(); @@ -51,5 +79,13 @@ namespace Khd.Core.Wpf } } } + + public static List BasePlcpoints { get; set; } + public static List BaseEquip { get; internal set; } + public static List BaseWareHouse { get; internal set; } + + public static List BaseDictionary =new List(); + public static List PlcConfigs =new List(); + public static Dictionary PlcDic=new Dictionary(); } } diff --git a/src/Khd.Core.Wpf/TaskForm/AddTask.xaml b/src/Khd.Core.Wpf/TaskForm/AddTask.xaml new file mode 100644 index 0000000..c393f2e --- /dev/null +++ b/src/Khd.Core.Wpf/TaskForm/AddTask.xaml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +