diff --git a/WCS.BLL/DbModels/ShelfInfo.cs b/WCS.BLL/DbModels/ShelfInfo.cs index 9753562..cc4b64e 100644 --- a/WCS.BLL/DbModels/ShelfInfo.cs +++ b/WCS.BLL/DbModels/ShelfInfo.cs @@ -103,6 +103,18 @@ namespace WCS.DAL.DbModels [SugarColumn(ColumnName = "Bind_shelf_code", IsNullable = true, ColumnDescription = "串联绑定后的大货架编码")] public string? BigShelfCode { get; set; } = string.Empty; + /// + /// 每块板子的灯数量 + /// + [SugarColumn(ColumnName = "light_count", IsNullable = true, ColumnDescription = "每块板子的灯数量")] + public int LightCount { get; set; } + + /// + /// 每块板子的灯数量 + /// + [SugarColumn(ColumnName = "first_board_id", IsNullable = true, ColumnDescription = "左上角的板子id")] + public int FirtstBoardId { get; set; } + /// /// 序号 /// diff --git a/WCS.BLL/Tool/TCPClient.cs b/WCS.BLL/Tool/TCPClient.cs index c43d3b8..2f5d5e6 100644 --- a/WCS.BLL/Tool/TCPClient.cs +++ b/WCS.BLL/Tool/TCPClient.cs @@ -260,7 +260,8 @@ namespace WCS.BLL } catch (Exception ex) { - Logs.Write("【发送指令时发生异常】" + ex.Message, LogsType.Instructions); + var clientIpHost = tcpClient.IP + ":" + tcpClient.Port; + Logs.Write($"【发送指令时发生异常{clientIpHost}】" + ex.Message, LogsType.Instructions); //因异常断连时(网线已经被断了) 手动重连一次 if (ex is NotConnectedException) { diff --git a/WCS.WebApi/Controllers/StoreInfoController.cs b/WCS.WebApi/Controllers/StoreInfoController.cs index 4c95616..b3d3abb 100644 --- a/WCS.WebApi/Controllers/StoreInfoController.cs +++ b/WCS.WebApi/Controllers/StoreInfoController.cs @@ -7,6 +7,8 @@ using WCS.Model.ApiModel.StoreInfo; using WCS.BLL.DbModels; using WCS.Model.ApiModel.MatBaseInfo; using WCS.DAL.DbModels; +using WCS.DAL.Db; +using WCS.BLL.Config; namespace WCS.WebApi.Controllers { @@ -102,6 +104,125 @@ namespace WCS.WebApi.Controllers { return await _storeInfoService.getDisablePercent(); } + + + + [Route("genModuleStoreInfos")] + [HttpPost(Name = "genModuleStoreInfos")] + public async Task genModuleStoreInfos(RequestBase request) + { + try + { + if (request.UserName != "aaa") + { + return new ResponseBase() + { + Code = 300, + Message = "用户名不对头!无法生成模组库位" + }; + } + //获取货架 此组后端管的货架 + var shelfInfos = DbHelp.db.Queryable() + .Where(t => t.GroupName == LocalFile.Config.GroupName) + .OrderBy(t => t.BigShelfCode) + .OrderBy(t => t.ShelfCode) + .ToList(); + + var lastBindBigShelfCode = string.Empty; + var lastColumnCount = 1; + + List moduleInfos = new List(); + //生成模组 + foreach (var shelfInfo in shelfInfos) + { + var modulePreFix = shelfInfo.IsBind ? shelfInfo.BigShelfCode : shelfInfo.ShelfCode; + //不绑定或者绑定换了面 重新从1开始计数 + if (shelfInfo.BigShelfCode != lastBindBigShelfCode) + { + lastColumnCount = 1; + } + lastBindBigShelfCode = shelfInfo.BigShelfCode; + for (int rowIndex = 0; rowIndex < shelfInfo.Rowcounts; rowIndex++) + { + for (int columnIndex = 0; columnIndex < shelfInfo.Columncounts; columnIndex++) + { + var moduleCode = modulePreFix + "-R" + (rowIndex + 1).ToString() + "C" + (lastColumnCount + columnIndex).ToString(); + var moduleInfo = new ModuleInfo() + { + ModuleCode = moduleCode, + ShelfTypeId = shelfInfo.ShelfTypeId, + ShelfId = shelfInfo.Id, + ShelfCode = shelfInfo.ShelfCode, + BoardId = shelfInfo.FirtstBoardId++, + LightCount = shelfInfo.LightCount, + CleintIp = shelfInfo.ClientIp, + GroupName = shelfInfo.GroupName, + R = (rowIndex + 1).ToString(), + C = (lastColumnCount + columnIndex).ToString(), + Bigshelfcode = shelfInfo.BigShelfCode, + IsEnable = true, + CurrentMode = BLL.HardWare.Mode.待机模式, + }; + moduleInfos.Add(moduleInfo); + } + } + lastColumnCount = lastColumnCount + shelfInfo.Columncounts; + } + DbHelp.db.Insertable(moduleInfos).ExecuteCommand(); + //生成库位 + moduleInfos = DbHelp.db.Queryable() + .Where(t => t.GroupName == LocalFile.Config.GroupName) + .OrderBy(t => t.Id) + .ToList(); + List storeInfos = new List(); + + foreach (var moduleInfo in moduleInfos) + { + for (int wei = 0; wei < moduleInfo.LightCount; wei++) + { + var storeCode = moduleInfo.ModuleCode + "-" + (wei + 1).ToString(); + var stroreInfo = new StoreInfo() + { + StoreCode = storeCode, + ShelfTypeId = moduleInfo.ShelfTypeId, + ModuleId = moduleInfo.Id, + ModuleCode = moduleInfo.ModuleCode, + ShelfId = moduleInfo.ShelfId, + ShelfCode = moduleInfo.ShelfCode, + BoardId = moduleInfo.BoardId, + LightNumber = wei + 1, + Priority = 0, + CurrentMatSn = string.Empty, + CurrentVoltage = 0, + StandardVoltage = 0, + OffsetVoltage = 0, + BigShelfCode = moduleInfo.Bigshelfcode, + R = moduleInfo.R, + C = moduleInfo.C, + Wei = (wei + 1).ToString(), + GroupName = moduleInfo.GroupName + }; + storeInfos.Add(stroreInfo); + + } + } + DbHelp.db.Insertable(storeInfos).ExecuteCommand(); + + return new ResponseBase() + { + Code = 200, + Message = "生成库位成功" + }; + } + catch (Exception ex) + { + return new ResponseBase() + { + Code = 300, + Message = ex.Message + }; + } + } #endregion } }