33
schangxiang@126.com
2025-05-18 daf2a4075e8ce949cda132de6a03b7ea86597b37
PipeLineLems/server/src/CMS.Plugin.PipeLineLems.Application/Implements/CallMaterialOrderRecordAppService.cs
@@ -1,127 +1,129 @@
using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.CallMaterialOrderRecord;
using CMS.Plugin.PipeLineLems.Application.Contracts.Services;
using CMS.Plugin.PipeLineLems.Domain.Shared;
using CmsQueryExtensions;
using CMS.Plugin.PipeLineLems.Domain.CallMaterialOrderRecord;
using CmsQueryExtensions.Extension;
using System.Linq.Expressions;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Data;
using Volo.Abp.ObjectExtending;
using Volo.Abp.ObjectMapping;
namespace CMS.Plugin.PipeLineLems.Application.Implements;
using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.CallMaterialOrderRecord;
using CMS.Plugin.PipeLineLems.Application.Contracts.Services;
using CMS.Plugin.PipeLineLems.Domain.Shared;
using CmsQueryExtensions;
using CMS.Plugin.PipeLineLems.Domain.CallMaterialOrderRecord;
using CmsQueryExtensions.Extension;
using System.Linq.Expressions;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Data;
using Volo.Abp.ObjectExtending;
using Volo.Abp.ObjectMapping;
using CmsQueryExtensions.Entitys;
namespace CMS.Plugin.PipeLineLems.Application.Implements;
/// <summary> 
/// 叫料记录表应用服务 
/// </summary> 
public class CallMaterialOrderRecordAppService : CMSPluginAppService, ICallMaterialOrderRecordAppService
{
    private readonly ICallMaterialOrderRecordRepository callMaterialOrderRecordRepository;
public class CallMaterialOrderRecordAppService : CMSPluginAppService, ICallMaterialOrderRecordAppService
{
    private readonly ICallMaterialOrderRecordRepository _callMaterialOrderRecordRepository;
    /// <summary> 
    /// Initializes a new instance of the <see cref="CallMaterialOrderRecordAppService"/> class. 
    /// </summary> 
    /// <param name="CallMaterialOrderRecordRepository">The task job repository.</param> 
    public CallMaterialOrderRecordAppService(ICallMaterialOrderRecordRepository _CallMaterialOrderRecordRepository)
    {
        callMaterialOrderRecordRepository = _CallMaterialOrderRecordRepository;
    }
    public CallMaterialOrderRecordAppService(ICallMaterialOrderRecordRepository callMaterialOrderRecordRepository)
    {
        _callMaterialOrderRecordRepository = callMaterialOrderRecordRepository;
    }
    /// <summary> 
    /// 获取指定叫料记录表 
    /// </summary> 
    /// <param name="id"></param> 
    /// <returns></returns> 
    public virtual async Task<CallMaterialOrderRecordDto> GetAsync(Guid id)
    {
        return ObjectMapper.Map<CallMaterialOrderRecord, CallMaterialOrderRecordDto>(await callMaterialOrderRecordRepository.GetAsync(id));
    }
    public virtual async Task<CallMaterialOrderRecordDto> GetAsync(Guid id)
    {
        return ObjectMapper.Map<CallMaterialOrderRecord, CallMaterialOrderRecordDto>(await _callMaterialOrderRecordRepository.GetAsync(id));
    }
    /// <summary> 
    /// 分页获取叫料记录表 
    /// </summary> 
    /// <param name="input"></param> 
    /// <returns></returns> 
    public virtual async Task<PagedResultDto<CallMaterialOrderRecordDto>> GetListAsync(GetCallMaterialOrderRecordInput input)
    {
        Check.NotNull(input, nameof(input));
        if (input.Sorting.IsNullOrWhiteSpace())
        {
            input.Sorting = nameof(CallMaterialOrderRecord.Sort);
        }
    public virtual async Task<PagedResultDto<CallMaterialOrderRecordDto>> GetListAsync(GetCallMaterialOrderRecordInput input)
    {
        Check.NotNull(input, nameof(input));
        if (input.Sorting.IsNullOrWhiteSpace())
        {
            input.Sorting = nameof(CallMaterialOrderRecord.Sort);
        }
        #region 动态构造查询条件  
        //动态构造查询条件  
        var whereConditions = DynamicGetQueryParams(input);
        #endregion
        var count = await callMaterialOrderRecordRepository.GetCountAsync(whereConditions);
        var list = await callMaterialOrderRecordRepository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount);
        return new PagedResultDto<CallMaterialOrderRecordDto>(count, ObjectMapper.Map<List<CallMaterialOrderRecord>, List<CallMaterialOrderRecordDto>>(list));
    }
        var whereConditions = DynamicGetQueryParams(input);
        #endregion
        var count = await _callMaterialOrderRecordRepository.GetCountAsync(whereConditions);
        var list = await _callMaterialOrderRecordRepository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount);
        return new PagedResultDto<CallMaterialOrderRecordDto>(count, ObjectMapper.Map<List<CallMaterialOrderRecord>, List<CallMaterialOrderRecordDto>>(list));
    }
    /// <summary>  
    /// 动态构造查询条件  
    /// </summary>  
    /// <param name="input">输入参数</param>  
    /// <returns></returns>  
    private FunReturnResultModel<Expression<Func<CallMaterialOrderRecord, bool>>> DynamicGetQueryParams(GetCallMaterialOrderRecordInput input)
    {
    private FunReturnResultModel<Expression<Func<CallMaterialOrderRecord, bool>>> DynamicGetQueryParams(GetCallMaterialOrderRecordInput input)
    {
        //动态构造查询条件  
        var whereConditions = WhereConditionsExtensions.GetWhereConditions<CallMaterialOrderRecord, GetCallMaterialOrderRecordInput>(input);
        if (!whereConditions.IsSuccess)
        {
            throw new Exception("动态构造查询条件失败:" + whereConditions.ErrMsg);
        }
        var whereConditions = WhereConditionsExtensions.GetWhereConditions<CallMaterialOrderRecord, GetCallMaterialOrderRecordInput>(input);
        if (!whereConditions.IsSuccess)
        {
            throw new Exception("动态构造查询条件失败:" + whereConditions.ErrMsg);
        }
        //也可再次自定义构建查询条件  
        Expression<Func<CallMaterialOrderRecord, bool>> extendExpression = a => a.IsDeleted == false;
        Expression<Func<CallMaterialOrderRecord, bool>> extendExpression = a => a.IsDeleted == false;
        // 使用 System.Linq.PredicateBuilder 的 And 
        var pres = (System.Linq.Expressions.Expression<Func<CallMaterialOrderRecord, bool>>)(whereConditions.data);
        whereConditions.data = System.Linq.PredicateBuilder.And(pres, extendExpression);
        return whereConditions;
    }
        var pres = (System.Linq.Expressions.Expression<Func<CallMaterialOrderRecord, bool>>)(whereConditions.data);
        whereConditions.data = System.Linq.PredicateBuilder.And(pres, extendExpression);
        return whereConditions;
    }
    /// <summary> 
    /// 新建叫料记录表 
    /// </summary> 
    /// <param name="input"></param> 
    /// <returns></returns> 
    /// <exception cref="UserFriendlyException"></exception> 
    public virtual async Task<CallMaterialOrderRecordDto> CreateAsync(CallMaterialOrderRecordCreateDto input)
    {
        await CheckCreateOrUpdateDtoAsync(input);
        var exist = await callMaterialOrderRecordRepository.NameExistAsync(input.DataIdentifier);
        if (exist)
        {
            throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.DataIdentifier]);
        }
        var maxSort = await callMaterialOrderRecordRepository.GetMaxSortAsync();
        var sort = input.Sort ?? maxSort;
        var insertObj = ObjectMapper.Map<CallMaterialOrderRecordCreateDto, CallMaterialOrderRecord>(input);
        insertObj.Sort = sort;
        input.MapExtraPropertiesTo(insertObj, MappingPropertyDefinitionChecks.None);
        await callMaterialOrderRecordRepository.InsertAsync(insertObj);
    public virtual async Task<CallMaterialOrderRecordDto> CreateAsync(CallMaterialOrderRecordCreateDto input)
    {
        await CheckCreateOrUpdateDtoAsync(input);
        var exist = await _callMaterialOrderRecordRepository.NameExistAsync(input.DataIdentifier);
        if (exist)
        {
            throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.DataIdentifier]);
        }
        var maxSort = await _callMaterialOrderRecordRepository.GetMaxSortAsync();
        var sort = input.Sort ?? maxSort;
        var insertObj = ObjectMapper.Map<CallMaterialOrderRecordCreateDto, CallMaterialOrderRecord>(input);
        insertObj.Sort = sort;
        input.MapExtraPropertiesTo(insertObj, MappingPropertyDefinitionChecks.None);
        insertObj.CreatorName = input.CreatorName;//创建人
        await _callMaterialOrderRecordRepository.InsertAsync(insertObj);
        //if (input.Sort.HasValue && insertObj.Sort != maxSort) 
        //{ 
        //    await AdjustSortAsync(insertObj.Id, insertObj.Sort); 
        //} 
        return ObjectMapper.Map<CallMaterialOrderRecord, CallMaterialOrderRecordDto>(insertObj);
    }
        return ObjectMapper.Map<CallMaterialOrderRecord, CallMaterialOrderRecordDto>(insertObj);
    }
    /// <summary> 
    /// 更新叫料记录表 
    /// </summary> 
@@ -129,288 +131,341 @@
    /// <param name="input"></param> 
    /// <returns></returns> 
    /// <exception cref="UserFriendlyException"></exception> 
    public virtual async Task<CallMaterialOrderRecordDto> UpdateAsync(Guid id, CallMaterialOrderRecordUpdateDto input)
    {
        await CheckCreateOrUpdateDtoAsync(input);
        var updateObj = await callMaterialOrderRecordRepository.GetAsync(id);
        var exist = await callMaterialOrderRecordRepository.NameExistAsync(input.DataIdentifier, updateObj.Id);
        if (exist)
        {
            throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.DataIdentifier]);
        }
        updateObj.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp);
        input.MapExtraPropertiesTo(updateObj, MappingPropertyDefinitionChecks.None);
                updateObj.DataIdentifier = input.DataIdentifier;
    public virtual async Task<CallMaterialOrderRecordDto> UpdateAsync(Guid id, CallMaterialOrderRecordUpdateDto input)
    {
        await CheckCreateOrUpdateDtoAsync(input);
        var updateObj = await _callMaterialOrderRecordRepository.GetAsync(id);
        var exist = await _callMaterialOrderRecordRepository.NameExistAsync(input.DataIdentifier, updateObj.Id);
        if (exist)
        {
            throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.DataIdentifier]);
        }
        updateObj.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp);
        input.MapExtraPropertiesTo(updateObj, MappingPropertyDefinitionChecks.None);
        updateObj.DataIdentifier = input.DataIdentifier;
        updateObj.MaterialMode = input.MaterialMode;
        updateObj.MaterialBatch = input.MaterialBatch;
        updateObj.CallMaterialStatus = input.CallMaterialStatus;
        updateObj.Quantity = input.Quantity;
        updateObj.WmsRetResult = input.WmsRetResult;
        updateObj.WmsTaskNo = input.WmsTaskNo;
        updateObj.Remark = input.Remark;
        await callMaterialOrderRecordRepository.UpdateAsync(updateObj);
        return ObjectMapper.Map<CallMaterialOrderRecord, CallMaterialOrderRecordDto>(updateObj);
    }
        await _callMaterialOrderRecordRepository.UpdateAsync(updateObj);
        return ObjectMapper.Map<CallMaterialOrderRecord, CallMaterialOrderRecordDto>(updateObj);
    }
    /// <summary> 
    /// 克隆叫料记录表 
    /// </summary> 
    /// <param name="ids"></param> 
    /// <returns></returns> 
    public async Task<List<CallMaterialOrderRecordDto>> CloneAsync(IEnumerable<Guid> ids)
    {
    public async Task<List<CallMaterialOrderRecordDto>> CloneAsync(IEnumerable<Guid> ids, MyCurrentUser myCurrentUser)
    {
        //var callMaterialOrderRecords = new List<CallMaterialOrderRecord>(); 
        //if (ids != null) 
        //{ 
        //    var sort = await callMaterialOrderRecordRepository.GetMaxSortAsync();
        //    var sort = await _callMaterialOrderRecordRepository.GetMaxSortAsync();
        //    foreach (var id in ids) 
        //    { 
        //        var CallMaterialOrderRecord = await callMaterialOrderRecordRepository.FindAsync(id);
        //        var CallMaterialOrderRecord = await _callMaterialOrderRecordRepository.FindAsync(id);
        //        if (CallMaterialOrderRecord != null) 
        //        { 
        //            var name = CallMaterialOrderRecord.Name + CallMaterialOrderRecordConsts.CloneTag; 
        //            var notExist = false; 
        //            while (!notExist) 
        //            { 
        //                var exist = await callMaterialOrderRecordRepository.NameExistAsync(name);
        //                var exist = await _callMaterialOrderRecordRepository.NameExistAsync(name);
        //                if (exist || callMaterialOrderRecords.Any(x => x.Name == name)) 
        //                { 
        //                    name += CallMaterialOrderRecordConsts.CloneTag; 
        //                    continue; 
        //                } 
        //                notExist = true; 
        //            } 
        //            //CallMaterialOrderRecord = await callMaterialOrderRecordRepository.InsertAsync(CallMaterialOrderRecord.Clone(GuidGenerator.Create(), name, sort++));
        //            //CallMaterialOrderRecord = await _callMaterialOrderRecordRepository.InsertAsync(CallMaterialOrderRecord.Clone(GuidGenerator.Create(), name, sort++));
        //            callMaterialOrderRecords.Add(CallMaterialOrderRecord); 
        //        } 
        //    } 
        //} 
        //return ObjectMapper.Map<List<CallMaterialOrderRecord>, List<CallMaterialOrderRecordDto>>(callMaterialOrderRecords); 
        return new List<CallMaterialOrderRecordDto>();
    }
        return new List<CallMaterialOrderRecordDto>();
    }
    /// <summary> 
    /// 删除单个叫料记录表 
    /// </summary> 
    /// <param name="id"></param> 
    /// <returns></returns> 
    public virtual Task DeleteAsync(Guid id)
    {
        return callMaterialOrderRecordRepository.DeleteAsync(id);
    }
    public virtual Task DeleteAsync(Guid id)
    {
        return _callMaterialOrderRecordRepository.DeleteAsync(id);
    }
    /// <summary> 
    /// 删除多个叫料记录表 
    /// </summary> 
    /// <param name="ids"></param> 
    /// <returns></returns> 
    public async Task DeleteManyAsync(IEnumerable<Guid> ids)
    {
        foreach (var id in ids)
        {
            await DeleteAsync(id);
        }
    }
    public async Task DeleteManyAsync(IEnumerable<Guid> ids, MyCurrentUser myCurrentUser)
    {
        foreach (var id in ids)
        {
            await DeleteAsync(id);
        }
    }
    /// <summary>
    /// 物理删除叫料记录表
    /// </summary>
    /// <param name="id">主键ID</param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public virtual async Task DeletePermanentlyAsync(Guid id, MyCurrentUser myCurrentUser, CancellationToken cancellationToken = default)
    {
        _callMaterialOrderRecordRepository.DeletePermanentlyAsync(id);
    }
    /// <summary>
    /// 批量物理删除叫料记录表(直接删除,不软删除)
    /// </summary>
    /// <param name="ids">要删除的主键ID列表</param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public virtual async Task BatchDeletePermanentlyAsync(IEnumerable<Guid> ids, MyCurrentUser myCurrentUser, CancellationToken cancellationToken = default)
    {
        _callMaterialOrderRecordRepository.BatchDeletePermanentlyAsync(ids);
    }
    /// <summary> 
    /// 调整排序叫料记录表 
    /// </summary> 
    /// <param name="id"></param> 
    /// <param name="sort"></param> 
    /// <returns></returns> 
    public virtual async Task AdjustSortAsync(Guid id, int sort)
    {
        var list = await callMaterialOrderRecordRepository.GetListAsync(null, nameof(CallMaterialOrderRecord.Sort));
        if (list != null && list.Any())
        {
            var initSort = 1;
            list.ForEach(x => x.AdjustSort(initSort++));
            var entity = list.FirstOrDefault(x => x.Id == id);
            if (entity != null)
            {
                if (sort == 1)
                {
                    list.Where(x => x.Id != id).ToList()?.ForEach(x => x.AdjustSort(x.Sort + 1));
                }
                else if (entity.Sort > sort)
                {
                    list.Where(x => x.Id != id && x.Sort >= sort).ToList()?.ForEach(x => x.AdjustSort(x.Sort + 1));
                    list.Where(x => x.Id != id && x.Sort < sort).ToList()?.ForEach(x => x.AdjustSort(x.Sort - 1));
                }
                else if (entity.Sort < sort)
                {
                    list.Where(x => x.Id != id && x.Sort > sort).ToList()?.ForEach(x => x.AdjustSort(x.Sort + 1));
                    list.Where(x => x.Id != id && x.Sort <= sort).ToList()?.ForEach(x => x.AdjustSort(x.Sort - 1));
                }
                entity.AdjustSort(sort);
            }
        }
        await callMaterialOrderRecordRepository.UpdateManyAsync(list);
    }
    public virtual async Task AdjustSortAsync(Guid id, int sort)
    {
        var list = await _callMaterialOrderRecordRepository.GetListAsync(null, nameof(CallMaterialOrderRecord.Sort));
        if (list != null && list.Any())
        {
            var initSort = 1;
            list.ForEach(x => x.AdjustSort(initSort++));
            var entity = list.FirstOrDefault(x => x.Id == id);
            if (entity != null)
            {
                if (sort == 1)
                {
                    list.Where(x => x.Id != id).ToList()?.ForEach(x => x.AdjustSort(x.Sort + 1));
                }
                else if (entity.Sort > sort)
                {
                    list.Where(x => x.Id != id && x.Sort >= sort).ToList()?.ForEach(x => x.AdjustSort(x.Sort + 1));
                    list.Where(x => x.Id != id && x.Sort < sort).ToList()?.ForEach(x => x.AdjustSort(x.Sort - 1));
                }
                else if (entity.Sort < sort)
                {
                    list.Where(x => x.Id != id && x.Sort > sort).ToList()?.ForEach(x => x.AdjustSort(x.Sort + 1));
                    list.Where(x => x.Id != id && x.Sort <= sort).ToList()?.ForEach(x => x.AdjustSort(x.Sort - 1));
                }
                entity.AdjustSort(sort);
            }
        }
        await _callMaterialOrderRecordRepository.UpdateManyAsync(list);
    }
    /// <summary> 
    /// 导入叫料记录表 
    /// </summary> 
    /// <param name="input"></param> 
    /// <returns></returns> 
    /// <exception cref="UserFriendlyException"></exception> 
    public async Task ImportAsync(CallMaterialOrderRecordsImportModel input)
    {
        Check.NotNull(input, nameof(input));
        var callMaterialOrderRecordCreateDtos = new List<(int RowIndex, CallMaterialOrderRecordCreateDto Item)>();
        var callMaterialOrderRecordUpdateDtos = new List<(int RowIndex, Guid Id, CallMaterialOrderRecordUpdateDto Item)>();
        var importItems = input.CallMaterialOrderRecords;
        if (importItems != null && importItems.Any())
        {
    public async Task ImportAsync(CallMaterialOrderRecordsImportModel input, MyCurrentUser myCurrentUser)
    {
        Check.NotNull(input, nameof(input));
        var callMaterialOrderRecordCreateDtos = new List<(int RowIndex, CallMaterialOrderRecordCreateDto Item)>();
        var callMaterialOrderRecordUpdateDtos = new List<(int RowIndex, Guid Id, CallMaterialOrderRecordUpdateDto Item)>();
        var importItems = input.CallMaterialOrderRecords;
        if (importItems != null && importItems.Any())
        {
            #region 导入校验 
            // 判断名称是否重复,并输出第几行重复 
            var duplicateCallMaterialOrderRecords = importItems.GroupBy(x => x.DataIdentifier).Where(x => x.Count() > 1).ToList();
            if (duplicateCallMaterialOrderRecords?.Any() == true)
            {
                var duplicateCallMaterialOrderRecordMsgs = duplicateCallMaterialOrderRecords.Select(x => $"第 {string.Join(",", x.Select(x => x.RowIndex))} 行:{x.Key}  名称重复");
                var errorMsg = $"导入失败!配置, {string.Join(",", duplicateCallMaterialOrderRecordMsgs)},终止导入";
                throw new UserFriendlyException(errorMsg);
            }
            #endregion
            foreach (var impItem in importItems)
            {
                if (impItem.DataIdentifier.IsNullOrWhiteSpace())
                {
                    continue;
                }
                if (impItem.DataIdentifier.IsNullOrWhiteSpace())
                {
                    var errorMsg = $"导入失败!配置,第{impItem.RowIndex}行:CallMaterialOrderRecord名称不能为空";
                    throw new UserFriendlyException(errorMsg);
                }
                var oldCallMaterialOrderRecord = await callMaterialOrderRecordRepository.FindByNameAsync(impItem.DataIdentifier);
                if (oldCallMaterialOrderRecord != null)
                {
                    var callMaterialOrderRecordUpdateDto = new CallMaterialOrderRecordUpdateDto
                    {
            var duplicateCallMaterialOrderRecords = importItems.GroupBy(x => x.DataIdentifier).Where(x => x.Count() > 1).ToList();
            if (duplicateCallMaterialOrderRecords?.Any() == true)
            {
                var duplicateCallMaterialOrderRecordMsgs = duplicateCallMaterialOrderRecords.Select(x => $"第 {string.Join(",", x.Select(x => x.RowIndex))} 行:{x.Key}  名称重复");
                var errorMsg = $"导入失败!配置, {string.Join(",", duplicateCallMaterialOrderRecordMsgs)},终止导入";
                throw new UserFriendlyException(errorMsg);
            }
            #endregion
            foreach (var impItem in importItems)
            {
                if (impItem.DataIdentifier.IsNullOrWhiteSpace())
                {
                    continue;
                }
                if (impItem.DataIdentifier.IsNullOrWhiteSpace())
                {
                    var errorMsg = $"导入失败!配置,第{impItem.RowIndex}行:CallMaterialOrderRecord名称不能为空";
                    throw new UserFriendlyException(errorMsg);
                }
                var oldCallMaterialOrderRecord = await _callMaterialOrderRecordRepository.FindByNameAsync(impItem.DataIdentifier);
                if (oldCallMaterialOrderRecord != null)
                {
                    var callMaterialOrderRecordUpdateDto = new CallMaterialOrderRecordUpdateDto
                    {
                        DataIdentifier = impItem.DataIdentifier,
MaterialMode = impItem.MaterialMode,
CallMaterialStatus = impItem.CallMaterialStatus,
Quantity = impItem.Quantity,
WmsRetResult = impItem.WmsRetResult,
WmsTaskNo = impItem.WmsTaskNo,
Remark = impItem.Remark,
                    };
                    callMaterialOrderRecordUpdateDtos.Add((impItem.RowIndex, oldCallMaterialOrderRecord.Id, callMaterialOrderRecordUpdateDto));
                }
                else
                {
                    var callMaterialOrderRecordCreateDto = new CallMaterialOrderRecordCreateDto
                    {
                        MaterialMode = impItem.MaterialMode,
                        MaterialBatch = impItem.MaterialBatch,
                        CallMaterialStatus = impItem.CallMaterialStatus,
                        Quantity = impItem.Quantity,
                        WmsRetResult = impItem.WmsRetResult,
                        WmsTaskNo = impItem.WmsTaskNo,
                        Remark = impItem.Remark,
                    };
                    callMaterialOrderRecordUpdateDtos.Add((impItem.RowIndex, oldCallMaterialOrderRecord.Id, callMaterialOrderRecordUpdateDto));
                }
                else
                {
                    var callMaterialOrderRecordCreateDto = new CallMaterialOrderRecordCreateDto
                    {
                        DataIdentifier = impItem.DataIdentifier,
MaterialMode = impItem.MaterialMode,
CallMaterialStatus = impItem.CallMaterialStatus,
Quantity = impItem.Quantity,
WmsRetResult = impItem.WmsRetResult,
WmsTaskNo = impItem.WmsTaskNo,
Remark = impItem.Remark,
                    };
                    callMaterialOrderRecordCreateDtos.Add((impItem.RowIndex, callMaterialOrderRecordCreateDto));
                }
            }
        }
                        MaterialMode = impItem.MaterialMode,
                        MaterialBatch = impItem.MaterialBatch,
                        CallMaterialStatus = impItem.CallMaterialStatus,
                        Quantity = impItem.Quantity,
                        WmsRetResult = impItem.WmsRetResult,
                        WmsTaskNo = impItem.WmsTaskNo,
                        Remark = impItem.Remark,
                    };
                    callMaterialOrderRecordCreateDtos.Add((impItem.RowIndex, callMaterialOrderRecordCreateDto));
                }
            }
        }
        // 新增 
        foreach (var callMaterialOrderRecordDto in callMaterialOrderRecordCreateDtos)
        {
            try
            {
                await CreateAsync(callMaterialOrderRecordDto.Item);
            }
            catch (Exception e)
            {
                var errorMsg = $"导入失败!配置,第{callMaterialOrderRecordDto.RowIndex}行:{e.Message},终止导入";
                throw new UserFriendlyException(errorMsg);
            }
        }
        foreach (var callMaterialOrderRecordDto in callMaterialOrderRecordCreateDtos)
        {
            try
            {
                callMaterialOrderRecordDto.Item.CreatorName = myCurrentUser.UserAccount;//创建人
                await CreateAsync(callMaterialOrderRecordDto.Item);
            }
            catch (Exception e)
            {
                var errorMsg = $"导入失败!配置,第{callMaterialOrderRecordDto.RowIndex}行:{e.Message},终止导入";
                throw new UserFriendlyException(errorMsg);
            }
        }
        // 更新 
        foreach (var callMaterialOrderRecordDto in callMaterialOrderRecordUpdateDtos)
        {
            try
            {
                await UpdateAsync(callMaterialOrderRecordDto.Id, callMaterialOrderRecordDto.Item);
            }
            catch (Exception e)
            {
                var errorMsg = $"导入失败!配置,第{callMaterialOrderRecordDto.RowIndex}行:{e.Message},终止导入";
                throw new UserFriendlyException(errorMsg);
            }
        }
    }
        foreach (var callMaterialOrderRecordDto in callMaterialOrderRecordUpdateDtos)
        {
            try
            {
                callMaterialOrderRecordDto.Item.LastModifierName = myCurrentUser.UserAccount;//修改人
                await UpdateAsync(callMaterialOrderRecordDto.Id, callMaterialOrderRecordDto.Item);
            }
            catch (Exception e)
            {
                var errorMsg = $"导入失败!配置,第{callMaterialOrderRecordDto.RowIndex}行:{e.Message},终止导入";
                throw new UserFriendlyException(errorMsg);
            }
        }
    }
    /// <summary> 
    /// 导出叫料记录表 
    /// </summary> 
    /// <param name="input"></param> 
    /// <returns></returns> 
    public async Task<(Dictionary<string, object> Sheets, string FileName)> ExportAsync(GetCallMaterialOrderRecordInput input)
    {
        Check.NotNull(input, nameof(input));
        if (input.Sorting.IsNullOrWhiteSpace())
        {
            input.Sorting = nameof(CallMaterialOrderRecord.Sort);
        }
    public async Task<(Dictionary<string, object> Sheets, string FileName)> ExportAsync(GetCallMaterialOrderRecordInput input)
    {
        Check.NotNull(input, nameof(input));
        if (input.Sorting.IsNullOrWhiteSpace())
        {
            input.Sorting = nameof(CallMaterialOrderRecord.Sort);
        }
        #region 动态构造查询条件  
        //动态构造查询条件  
        var whereConditions = DynamicGetQueryParams(input);
        #endregion
        var list = await callMaterialOrderRecordRepository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount, includeDetails: true);
        var result = ObjectMapper.Map<List<CallMaterialOrderRecord>, List<CallMaterialOrderRecordDto>>(list);
        var sheets = new Dictionary<string, object>
        {
            ["配置"] = ExportHelper.ConvertListToExportData(result),
        };
        var fileName = "叫料记录";
        return (sheets, fileName);
    }
        var whereConditions = DynamicGetQueryParams(input);
        #endregion
        var list = await _callMaterialOrderRecordRepository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount, includeDetails: true);
        var result = ObjectMapper.Map<List<CallMaterialOrderRecord>, List<CallMaterialOrderRecordDto>>(list);
        var sheets = new Dictionary<string, object>
        {
            ["配置"] = ExportHelper.ConvertListToExportData(result),
        };
        var fileName = "叫料记录";
        return (sheets, fileName);
    }
    /// <summary> 
    /// 校验叫料记录表,当新建或更新时 
    /// </summary> 
    /// <param name="input"></param> 
    /// <returns></returns> 
    protected Task CheckCreateOrUpdateDtoAsync(CallMaterialOrderRecordCreateOrUpdateDtoBase input)
    {
        Check.NotNull(input, nameof(input));
                Check.NotNullOrWhiteSpace(input.DataIdentifier, "原料标识", 256);
    protected Task CheckCreateOrUpdateDtoAsync(CallMaterialOrderRecordCreateOrUpdateDtoBase input)
    {
        Check.NotNull(input, nameof(input));
        Check.NotNullOrWhiteSpace(input.DataIdentifier, "原料标识", 256);
        Check.NotNull(input.CallMaterialStatus, "叫料状态");
        Check.NotNull(input.Quantity, "叫料数量");
        return Task.CompletedTask;
    }
}
        return Task.CompletedTask;
    }
    /// <summary>
    /// 根据条件获取叫料记录表列表
    /// </summary>
    /// <param name="whereConditions"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public async Task<List<CallMaterialOrderRecord>> GetListByFilterAsync(Expression<Func<CallMaterialOrderRecord, bool>> whereConditions, CancellationToken cancellationToken = default)
    {
        return await _callMaterialOrderRecordRepository.GetListByFilterAsync(whereConditions);
    }
    /// <summary>
    ///  根据条件获取单个叫料记录表
    /// </summary>
    /// <param name="whereConditions"></param>
    /// <param name="isMultipleThrowException">是否查询出多条就报错</param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    /// <exception cref="UserFriendlyException"></exception>
    public async Task<CallMaterialOrderRecord> GetSingleByFilterAsync(Expression<Func<CallMaterialOrderRecord, bool>> whereConditions, bool is​MultipleThrowException = false, CancellationToken cancellationToken = default)
    {
        return await _callMaterialOrderRecordRepository.GetSingleByFilterAsync(whereConditions, is​MultipleThrowException);
    }
}