using Masuit.Tools;
|
using Newtonsoft.Json.Serialization;
|
using System.ComponentModel.DataAnnotations;
|
using WIDESEA_Common.Boxing;
|
using WIDESEA_Model.Models;
|
|
namespace WIDESEA_StorageBasicService;
|
|
public class BoxingInfoService : ServiceBase<DtBoxingInfo, IBoxingInfoRepository>, IBoxingInfoService
|
{
|
private readonly IStockInfoRepository stockInfoRepository;
|
private readonly IBoxingInfoDetailRepository boxingInfoDetailRepository;
|
public BoxingInfoService(IBoxingInfoRepository BaseDal, IStockInfoRepository stockInfoRepository, IBoxingInfoDetailRepository boxingInfoDetailRepository) : base(BaseDal)
|
{
|
this.stockInfoRepository = stockInfoRepository;
|
this.boxingInfoDetailRepository = boxingInfoDetailRepository;
|
}
|
|
// 验证模型
|
public static List<ValidationResult> ValidateModel(object model)
|
{
|
// 创建一个验证结果列表
|
var validationResults = new List<ValidationResult>();
|
// 创建一个验证上下文
|
var validationContext = new ValidationContext(model, serviceProvider: null, items: null);
|
|
// 使用验证器尝试验证模型,并将验证结果添加到验证结果列表中
|
Validator.TryValidateObject(model, validationContext, validationResults, validateAllProperties: true);
|
|
// 返回验证结果列表
|
return validationResults;
|
}
|
|
public WebResponseContent AddBoxingInfo(SaveModel saveModel)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
string palletcode = saveModel.MainData["palletCode"].ToString();
|
List<BoxingInfos> obj = JsonConvert.DeserializeObject<List<BoxingInfos>>(saveModel.MainData["jsonData"].ToString());
|
if (obj == null || obj.Count == 0) throw new Exception("物料信息为空,请输入");
|
|
var info = BaseDal.QueryFirst(x => x.PalletCode == palletcode);
|
if (info != null) throw new Exception("该托盘已存在组盘");
|
|
var stockinfo = stockInfoRepository.QueryFirst(x => x.PalletCode == palletcode);
|
if (stockinfo != null) throw new Exception("该托盘已存在库存数据");
|
|
foreach (var item in obj)
|
{
|
if (boxingInfoDetailRepository.QueryFirst(x => x.MaterielName == item.MaterilName) != null) throw new Exception($"{item.MaterilName}已存在组盘数据");
|
}
|
|
DtBoxingInfo dtBoxingInfo = new DtBoxingInfo()
|
{
|
Creater = App.User.UserName,
|
CreateDate = DateTime.Now,
|
PalletCode = palletcode,
|
CurrentStatue = 1,
|
BoxingInfoDetails = obj.Select(detail => new DtBoxingInfoDetail()
|
{
|
MaterielName = detail.MaterilName,
|
Quantity = detail.Num
|
}).ToList(),
|
};
|
|
var isBox = BaseDal.AddDataNavAsync(dtBoxingInfo).Result;
|
if (isBox)
|
{
|
return content.OK();
|
}
|
else
|
{
|
return content.Error();
|
}
|
|
}
|
catch (Exception ex)
|
{
|
return content.Error(ex.Message);
|
}
|
|
}
|
}
|