using System; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.Validation; using Win_in.Sfs.Wms.Inventory.Application.Contracts; namespace Win_in.Sfs.Wms.Pda.Controllers.Inventories; /// /// /// [ApiController] [Route($"{PdaHostConst.ROOT_ROUTE}inventory/container")] public class ContainerController : AbpController { private readonly IContainerAppService _containerAppService; /// /// /// /// public ContainerController(IContainerAppService containerAppService) { _containerAppService = containerAppService; } /// /// 根据code获取库位信息 /// /// /// [HttpGet("{code}")] public async Task GetAsync(string code) { var result = await _containerAppService.GetByCodeAsync(code).ConfigureAwait(false); return result; } /// /// 根据Code获取容器信息 /// /// /// [HttpGet("check-by-code/{code}")] public async Task CheckByCodeAsync(string code) { var result = new AbpValidationResult(); var entity = await _containerAppService.GetByCodeAsync(code).ConfigureAwait(false); //TODO 以下的业务逻辑都不应该写在这里 if (entity != null) { result.Errors.Add(new ValidationResult($"号码为 {code} 的器具已存在!")); } //校验是不是最后一个器具号 var args = code.Split('-'); if (args.Length >= 4) { //P - 20220703 - 254L - 0000001 _ = args[1]; //生产日期 var projectCodeRL = args[2]; //项目+左右 var projectCode = string.Empty; var rl = string.Empty; if (projectCodeRL.Length > 1) { projectCode = projectCodeRL.Substring(0, projectCodeRL.Length - 1);//项目 rl = projectCodeRL.Substring(projectCodeRL.Length - 1, 1); //左右 } var seqNo = args[3]; //流水号 entity = await _containerAppService.GetLastByTypeAndProjectCodeAsync(rl, projectCode).ConfigureAwait(false); if (entity == null) { return; } try { var seqNoDeciamlNew = Convert.ToDecimal(seqNo); var seqNoDeciamlLast = Convert.ToDecimal(entity.SeqNo); if (seqNoDeciamlLast + 1 != seqNoDeciamlNew) { result.Errors.Add(new ValidationResult($"托码{code}的流水号为{seqNoDeciamlNew},当前数据库内最大流水号为{seqNoDeciamlLast},它们不是连续的,请按序收货!")); } } catch (Exception) { result.Errors.Add(new ValidationResult($"托码{code}的流水号为{seqNo},或者当前数据库内最大流水号为{entity.SeqNo}不能有效转化为数字进行比较!")); } } else { result.Errors.Add(new ValidationResult($"托码{code}不符合解析规则!")); } if (result.Errors.Any()) { throw new AbpValidationException(result.Errors[0].ErrorMessage, result.Errors); } } }