1
huangxiaoqiang
2025-10-22 d4b0b578752a1478f6c11b352fbb8d2bad1f9e1d
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Boxing/BoxingInfoService.cs
@@ -1,51 +1,55 @@
using Masuit.Tools;
using Mapster;
using Masuit.Tools;
using SqlSugar;
using System.ComponentModel.DataAnnotations;
using System.Linq.Expressions;
using WIDESEA_Core.BaseRepository;
using WIDESEA_DTO.Basic;
using WIDESEA_IOrderRepository;
namespace WIDESEA_StorageBasicService;
public class BoxingInfoService : ServiceBase<DtBoxingInfo, IBoxingInfoRepository>, IBoxingInfoService
{
    public BoxingInfoService(IBoxingInfoRepository BaseDal) : base(BaseDal)
    private readonly IUnitOfWorkManage _unitOfWorkManage;
    public BoxingInfoService(IBoxingInfoRepository BaseDal,IUnitOfWorkManage unitOfWorkManage) : base(BaseDal)
    {
        _unitOfWorkManage = unitOfWorkManage;
    }
    public async Task<WebResponseContent> AddBoxingInfoAsync(DtBoxingInfo boxingInfo)
    {
        WebResponseContent content = new WebResponseContent();
        var info = await BaseDal.QueryFirstAsync(x => x.PalletCode == boxingInfo.PalletCode);
        if (!info.IsNullOrEmpty())
        {
            content.Error("该托盘已存在组盘");
        }
        else
        {
            // æ·»åŠ ç»„ç›˜ä¿¡æ¯
            var result = await BaseDal.AddDataNavAsync(boxingInfo);
            if (result)
            {
                content.OK("添加成功", boxingInfo);
            }
        }
        return content;
    }
    public override PageGridData<DtBoxingInfo> GetPageData(PageDataOptions options)
    {
        return base.GetPageData(options);
    }
        string wheres = ValidatePageOptions(options);
        //获取排序字段
        Dictionary<string, OrderByType> orderbyDic = GetPageDataSort(options, TProperties);
        List<OrderByModel> orderByModels = new List<OrderByModel>();
        foreach (var item in orderbyDic)
        {
            OrderByModel orderByModel = new()
            {
                FieldName = item.Key,
                OrderByType = item.Value
            };
            orderByModels.Add(orderByModel);
        }
    // éªŒè¯æ¨¡åž‹
    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;
        int totalCount = 0;
        List<SearchParameters> searchParametersList = new List<SearchParameters>();
        if (!string.IsNullOrEmpty(options.Wheres))
        {
            try
            {
                searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
                options.Filter = searchParametersList;
            }
            catch { }
        }
        var data = BaseDal.Db.Queryable<DtBoxingInfo>()
            .Includes(x => x.BoxingInfoDetails)
            .WhereIF(!wheres.IsNullOrEmpty(), wheres)
            .OrderBy(orderByModels)
            .ToPageList(options.Page, options.Rows, ref totalCount);
        new PageGridData<DtBoxingInfo>(totalCount, data);
        return new PageGridData<DtBoxingInfo>(totalCount, data);
    }
}