using HslCommunication.WebSocket; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using WIDESEA_Common.CommonEnum; using WIDESEA_Common.LocationEnum; using WIDESEA_Core; using WIDESEA_Core.BaseController; using WIDESEA_Core.Enums; using WIDESEA_DTO.Basic; using WIDESEA_IBasicRepository; using WIDESEA_IBasicService; using WIDESEA_Model.Models; namespace WIDESEA_WMSServer.Controllers.Basic { /// /// 货位 /// [Route("api/LocationInfo")] [ApiController] public class LocationInfoController : ApiBaseController { private readonly ILocationInfoRepository _repository; public LocationInfoController(ILocationInfoService service, ILocationInfoRepository repository) : base(service) { _repository = repository; } /// /// 初始化货位 /// /// /// [HttpPost, Route("InitializationLocation"), AllowAnonymous] public WebResponseContent InitializationLocation([FromBody] InitializationLocationDTO initializationLocationDTO) { return Service.InitializationLocation(initializationLocationDTO); } /// /// 货位分配 /// /// /// /// [HttpPost, HttpGet, Route("AssignLocation"), AllowAnonymous] public Dt_LocationInfo? AssignLocation(string roadwayNo, int palletType, int warehouseId) { return Service.AssignLocation(roadwayNo, palletType, warehouseId); } /// /// 启用货位 /// /// /// [HttpPost, Route("LocationEnableStatus")] public WebResponseContent LocationEnableStatus([FromBody] int[] keys) { return Service.LocationEnableStatus(keys); ; } /// /// 禁用货位 /// /// /// [HttpPost, Route("LocationDisableStatus")] public WebResponseContent LocationDisableStatus([FromBody] int[] keys) { return Service.LocationDisableStatus(keys); ; } [HttpPost, Route("UpdateLocationStatus"), AllowAnonymous] public WebResponseContent UpdateLocationStatus(string locationCode, int palletType, LocationStatusEnum locationStatus, int warehousId) { try { Service.UpdateLocationStatus(locationCode, palletType, locationStatus, warehousId); return WebResponseContent.Instance.OK(); } catch (Exception e) { return WebResponseContent.Instance.Error(e.Message); } } /// /// 查询条件货位 /// /// /// /// [HttpPost, HttpGet, Route("GetLocationStatus")] public WebResponseContent GetLocationStatus(int row, int warehouseId = 0) { List layers; if (warehouseId == 0) { layers = _repository.QueryData(x => x.Row == row).Select(x => x.Layer).Distinct().ToList(); } else { layers = _repository.QueryData(x => x.Row == row && x.WarehouseId == warehouseId).Select(x => x.Layer).Distinct().ToList(); } List listObj = new List(); foreach (var item in layers) { object locationObj; if (warehouseId == 0) { locationObj = _repository.QueryData(x => x.Row == row && x.Layer == item) .OrderBy(x => x.Columns) .Select(x => new { layer = x.Layer.ToString().PadLeft(2, '0'), row = x.Row.ToString().PadLeft(2, '0'), column = x.Columns.ToString().PadLeft(2, '0'), locationCode = x.LocationCode, location_lock = x.LocationStatus }).ToList(); } else { locationObj = _repository.QueryData(x => x.Row == row && x.Layer == item && x.WarehouseId == warehouseId) .OrderBy(x => x.Columns) .Select(x => new { layer = x.Layer.ToString().PadLeft(2, '0'), row = x.Row.ToString().PadLeft(2, '0'), column = x.Columns.ToString().PadLeft(2, '0'), locationCode = x.LocationCode, location_lock = x.LocationStatus }).ToList(); } object obj = new { layer = item, locationObj }; listObj.Add(obj); } return WebResponseContent.Instance.OK("成功", listObj); } /// /// 查询全部货位 /// /// [HttpPost, HttpGet, Route("GetRow")] public WebResponseContent GetRow() { List listRow = _repository.QueryData().Select(x => x.Row).Distinct().ToList(); return WebResponseContent.Instance.OK("成功", listRow); } /// /// 查询货位RFID /// /// /// [HttpPost, Route("GetRfid")] public WebResponseContent GetRfid([FromBody] dynamic requestData) { try { if (requestData == null) { return WebResponseContent.Instance.Error("请求数据为空"); } // 检查locationCodes字段是否存在且不为null(兼容locationCode) if (requestData.locationCodes == null && requestData.locationCode == null) { return WebResponseContent.Instance.Error("货位编号数组不能为空"); } // 转换为string[],优先使用locationCodes string[] locationCode = null; var locationCodeField = requestData.locationCodes ?? requestData.locationCode; if (locationCodeField is Newtonsoft.Json.Linq.JArray) { locationCode = ((Newtonsoft.Json.Linq.JArray)locationCodeField).ToObject(); } else { return WebResponseContent.Instance.Error("货位编号必须是数组格式"); } // 检查warehouseId字段是否存在 int warehouseId = 0; if (requestData.warehouseId != null) { warehouseId = Convert.ToInt32(requestData.warehouseId); } return Service.GetRfid(locationCode, warehouseId); } catch (Exception ex) { return WebResponseContent.Instance.Error($"参数解析失败: {ex.Message}"); } } } }