| | |
| | | using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.WorkPlan; |
| | | using CMS.Plugin.PipeLineLems.Application.Contracts.Services; |
| | | using CMS.Plugin.PipeLineLems.Domain.Shared; |
| | | using CmsQueryExtensions; |
| | | using CMS.Plugin.PipeLineLems.Domain.WorkPlan; |
| | | 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.WorkPlan; |
| | | using CMS.Plugin.PipeLineLems.Application.Contracts.Services; |
| | | using CMS.Plugin.PipeLineLems.Domain.Shared; |
| | | using CmsQueryExtensions; |
| | | using CMS.Plugin.PipeLineLems.Domain.WorkPlan; |
| | | 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 Volo.Abp.Users; |
| | | using CmsQueryExtensions.Entitys; |
| | | using System.Collections.Generic; |
| | | |
| | | namespace CMS.Plugin.PipeLineLems.Application.Implements; |
| | | |
| | | /// <summary> |
| | | /// 作业计划表应用服务 |
| | | /// </summary> |
| | | public class WorkPlanAppService : CMSPluginAppService, IWorkPlanAppService |
| | | { |
| | | private readonly IWorkPlanRepository workPlanRepository; |
| | | |
| | | public class WorkPlanAppService : CMSPluginAppService, IWorkPlanAppService |
| | | { |
| | | private readonly IWorkPlanRepository _workPlanRepository; |
| | | private readonly SharedService _sharedService; |
| | | private readonly IServiceProvider _serviceProvider; |
| | | /// <summary> |
| | | /// Initializes a new instance of the <see cref="WorkPlanAppService"/> class. |
| | | /// </summary> |
| | | /// <param name="WorkPlanRepository">The task job repository.</param> |
| | | public WorkPlanAppService(IWorkPlanRepository _WorkPlanRepository) |
| | | { |
| | | workPlanRepository = _WorkPlanRepository; |
| | | } |
| | | |
| | | public WorkPlanAppService(IWorkPlanRepository workPlanRepository, SharedService sharedService, IServiceProvider serviceProvider) |
| | | { |
| | | _workPlanRepository = workPlanRepository; |
| | | _sharedService = sharedService; |
| | | _serviceProvider = serviceProvider; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取指定作业计划表 |
| | | /// </summary> |
| | | /// <param name="id"></param> |
| | | /// <returns></returns> |
| | | public virtual async Task<WorkPlanDto> GetAsync(Guid id) |
| | | { |
| | | return ObjectMapper.Map<WorkPlan, WorkPlanDto>(await workPlanRepository.GetAsync(id)); |
| | | } |
| | | |
| | | public virtual async Task<WorkPlanDto> GetAsync(Guid id) |
| | | { |
| | | return ObjectMapper.Map<WorkPlan, WorkPlanDto>(await _workPlanRepository.GetAsync(id)); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 分页获取作业计划表 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public virtual async Task<PagedResultDto<WorkPlanDto>> GetListAsync(GetWorkPlanInput input) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | |
| | | if (input.Sorting.IsNullOrWhiteSpace()) |
| | | { |
| | | input.Sorting = nameof(WorkPlan.Sort); |
| | | } |
| | | |
| | | public virtual async Task<PagedResultDto<WorkPlanDto>> GetListAsync(GetWorkPlanInput input) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | |
| | | if (input.Sorting.IsNullOrWhiteSpace()) |
| | | { |
| | | input.Sorting = nameof(WorkPlan.Sort); |
| | | } |
| | | |
| | | #region 动态构造查询条件 |
| | | |
| | | |
| | | //动态构造查询条件 |
| | | var whereConditions = DynamicGetQueryParams(input); |
| | | |
| | | #endregion |
| | | |
| | | var count = await workPlanRepository.GetCountAsync(whereConditions); |
| | | var list = await workPlanRepository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount); |
| | | |
| | | return new PagedResultDto<WorkPlanDto>(count, ObjectMapper.Map<List<WorkPlan>, List<WorkPlanDto>>(list)); |
| | | } |
| | | |
| | | var whereConditions = DynamicGetQueryParams(input); |
| | | |
| | | #endregion |
| | | |
| | | var count = await _workPlanRepository.GetCountAsync(whereConditions); |
| | | var list = await _workPlanRepository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount); |
| | | |
| | | return new PagedResultDto<WorkPlanDto>(count, ObjectMapper.Map<List<WorkPlan>, List<WorkPlanDto>>(list)); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 动态构造查询条件 |
| | | /// </summary> |
| | | /// <param name="input">输入参数</param> |
| | | /// <returns></returns> |
| | | private FunReturnResultModel<Expression<Func<WorkPlan, bool>>> DynamicGetQueryParams(GetWorkPlanInput input) |
| | | { |
| | | private FunReturnResultModel<Expression<Func<WorkPlan, bool>>> DynamicGetQueryParams(GetWorkPlanInput input) |
| | | { |
| | | //动态构造查询条件 |
| | | var whereConditions = WhereConditionsExtensions.GetWhereConditions<WorkPlan, GetWorkPlanInput>(input); |
| | | if (!whereConditions.IsSuccess) |
| | | { |
| | | throw new Exception("动态构造查询条件失败:" + whereConditions.ErrMsg); |
| | | } |
| | | |
| | | var whereConditions = WhereConditionsExtensions.GetWhereConditions<WorkPlan, GetWorkPlanInput>(input); |
| | | if (!whereConditions.IsSuccess) |
| | | { |
| | | throw new Exception("动态构造查询条件失败:" + whereConditions.ErrMsg); |
| | | } |
| | | |
| | | //也可再次自定义构建查询条件 |
| | | Expression<Func<WorkPlan, bool>> extendExpression = a => a.IsDeleted == false; |
| | | Expression<Func<WorkPlan, bool>> extendExpression = a => a.IsDeleted == false; |
| | | // 使用 System.Linq.PredicateBuilder 的 And |
| | | var pres = (System.Linq.Expressions.Expression<Func<WorkPlan, bool>>)(whereConditions.data); |
| | | whereConditions.data = System.Linq.PredicateBuilder.And(pres, extendExpression); |
| | | |
| | | return whereConditions; |
| | | } |
| | | |
| | | var pres = (System.Linq.Expressions.Expression<Func<WorkPlan, 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<WorkPlanDto> CreateAsync(WorkPlanCreateDto input) |
| | | { |
| | | await CheckCreateOrUpdateDtoAsync(input); |
| | | |
| | | var exist = await workPlanRepository.NameExistAsync(input.TaskCode); |
| | | if (exist) |
| | | { |
| | | throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.TaskCode]); |
| | | } |
| | | |
| | | var maxSort = await workPlanRepository.GetMaxSortAsync(); |
| | | var sort = input.Sort ?? maxSort; |
| | | |
| | | var insertObj = ObjectMapper.Map<WorkPlanCreateDto, WorkPlan>(input); |
| | | insertObj.Sort = sort; |
| | | input.MapExtraPropertiesTo(insertObj, MappingPropertyDefinitionChecks.None); |
| | | |
| | | await workPlanRepository.InsertAsync(insertObj); |
| | | |
| | | if (input.Sort.HasValue && insertObj.Sort != maxSort) |
| | | { |
| | | await AdjustSortAsync(insertObj.Id, insertObj.Sort); |
| | | } |
| | | |
| | | return ObjectMapper.Map<WorkPlan, WorkPlanDto>(insertObj); |
| | | } |
| | | |
| | | public virtual async Task<WorkPlanDto> CreateAsync(WorkPlanCreateDto input) |
| | | { |
| | | await CheckCreateOrUpdateDtoAsync(input); |
| | | |
| | | var exist = await _workPlanRepository.NameExistAsync(input.TaskCode); |
| | | if (exist) |
| | | { |
| | | throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.TaskCode]); |
| | | } |
| | | |
| | | var maxSort = await _workPlanRepository.GetMaxSortAsync(); |
| | | var sort = input.Sort ?? maxSort; |
| | | |
| | | var insertObj = ObjectMapper.Map<WorkPlanCreateDto, WorkPlan>(input); |
| | | insertObj.Sort = sort; |
| | | insertObj.CreatorName = "SuperAdmin"; |
| | | input.MapExtraPropertiesTo(insertObj, MappingPropertyDefinitionChecks.None); |
| | | |
| | | await _workPlanRepository.InsertAsync(insertObj); |
| | | |
| | | //if (input.Sort.HasValue && insertObj.Sort != maxSort) |
| | | //{ |
| | | // await AdjustSortAsync(insertObj.Id, insertObj.Sort); |
| | | //} |
| | | |
| | | return ObjectMapper.Map<WorkPlan, WorkPlanDto>(insertObj); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新作业计划表 |
| | | /// </summary> |
| | |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="UserFriendlyException"></exception> |
| | | public virtual async Task<WorkPlanDto> UpdateAsync(Guid id, WorkPlanUpdateDto input) |
| | | { |
| | | await CheckCreateOrUpdateDtoAsync(input); |
| | | |
| | | var updateObj = await workPlanRepository.GetAsync(id); |
| | | var exist = await workPlanRepository.NameExistAsync(input.TaskCode, updateObj.Id); |
| | | if (exist) |
| | | { |
| | | throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.TaskCode]); |
| | | } |
| | | |
| | | updateObj.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp); |
| | | input.MapExtraPropertiesTo(updateObj, MappingPropertyDefinitionChecks.None); |
| | | |
| | | updateObj.TaskCode = input.TaskCode; |
| | | updateObj.OrgMaterialCode = input.OrgMaterialCode; |
| | | updateObj.FactoryCode = input.FactoryCode; |
| | | updateObj.ProductCode = input.ProductCode; |
| | | updateObj.WorkstationCode = input.WorkstationCode; |
| | | updateObj.EquipmentCode = input.EquipmentCode; |
| | | updateObj.WorkpieceName = input.WorkpieceName; |
| | | updateObj.ProcessName = input.ProcessName; |
| | | updateObj.PipeFittingCode = input.PipeFittingCode; |
| | | updateObj.PreSerialNumber = input.PreSerialNumber; |
| | | public virtual async Task<WorkPlanDto> UpdateAsync(Guid id, WorkPlanUpdateDto input) |
| | | { |
| | | await CheckCreateOrUpdateDtoAsync(input); |
| | | |
| | | var updateObj = await _workPlanRepository.GetAsync(id); |
| | | var exist = await _workPlanRepository.NameExistAsync(input.TaskCode, updateObj.Id); |
| | | if (exist) |
| | | { |
| | | throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.TaskCode]); |
| | | } |
| | | |
| | | updateObj.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp); |
| | | input.MapExtraPropertiesTo(updateObj, MappingPropertyDefinitionChecks.None); |
| | | |
| | | updateObj.TaskCode = input.TaskCode; |
| | | updateObj.WorkPlanStatus = input.WorkPlanStatus; |
| | | updateObj.CallMaterialStatus = input.CallMaterialStatus; |
| | | updateObj.DataIdentifier = input.DataIdentifier; |
| | | updateObj.PipeSpecCode = input.PipeSpecCode; |
| | | updateObj.PipeSectionName = input.PipeSectionName; |
| | | updateObj.OuterDiameter = input.OuterDiameter; |
| | | updateObj.Bevel = input.Bevel; |
| | | updateObj.Material = input.Material; |
| | | updateObj.MaterialMode = input.MaterialMode; |
| | | updateObj.Length = input.Length; |
| | | updateObj.DrillingPosition = input.DrillingPosition; |
| | | updateObj.Intersecting = input.Intersecting; |
| | | updateObj.InterfaceRequirement = input.InterfaceRequirement; |
| | | updateObj.HasMainSignature = input.HasMainSignature; |
| | | updateObj.Quantity = input.Quantity; |
| | | updateObj.MarkingContent = input.MarkingContent; |
| | | updateObj.CuttingFile = input.CuttingFile; |
| | | updateObj.BranchOuterDiameter = input.BranchOuterDiameter; |
| | | updateObj.BranchWallThickness = input.BranchWallThickness; |
| | | updateObj.BranchMaterial = input.BranchMaterial; |
| | | updateObj.BranchPortRadius = input.BranchPortRadius; |
| | | updateObj.BranchPortAngle = input.BranchPortAngle; |
| | | updateObj.BranchPortRequirement = input.BranchPortRequirement; |
| | | updateObj.IntersectingLineType = input.IntersectingLineType; |
| | | updateObj.IntersectingLineCategory = input.IntersectingLineCategory; |
| | | updateObj.FinishedProductScale = input.FinishedProductScale; |
| | | updateObj.MarkingPosition = input.MarkingPosition; |
| | | updateObj.CuttingPosition = input.CuttingPosition; |
| | | updateObj.Quantity = input.Quantity; |
| | | updateObj.FlangeThickness = input.FlangeThickness; |
| | | updateObj.FlangeInnerDiameter = input.FlangeInnerDiameter; |
| | | updateObj.WeldingHeatInput = input.WeldingHeatInput; |
| | | updateObj.PipeAllowableStress = input.PipeAllowableStress; |
| | | updateObj.PipeDiameter = input.PipeDiameter; |
| | | updateObj.PipeWallThickness = input.PipeWallThickness; |
| | | updateObj.VRData = input.VRData; |
| | | updateObj.FactoryCode = input.FactoryCode; |
| | | updateObj.ProductCode = input.ProductCode; |
| | | updateObj.WorkstationCode = input.WorkstationCode; |
| | | updateObj.EquipmentCode = input.EquipmentCode; |
| | | |
| | | updateObj.ProcessName = input.ProcessName; |
| | | updateObj.PipeFittingCode = input.PipeFittingCode; |
| | | updateObj.PreSerialNumber = input.PreSerialNumber; |
| | | updateObj.PipeSpecCode = input.PipeSpecCode; |
| | | updateObj.PipeSectionName = input.PipeSectionName; |
| | | updateObj.OuterDiameter = input.OuterDiameter; |
| | | updateObj.Thickness = input.Thickness; |
| | | updateObj.Material = input.Material; |
| | | updateObj.ProcessRouteNumber = input.ProcessRouteNumber; |
| | | updateObj.PlannedStartTime = input.PlannedStartTime; |
| | | updateObj.PlannedEndTime = input.PlannedEndTime; |
| | | updateObj.TimeInfo = input.TimeInfo; |
| | | updateObj.RedundantField1 = input.RedundantField1; |
| | | updateObj.RedundantField2 = input.RedundantField2; |
| | | updateObj.RedundantField3 = input.RedundantField3; |
| | | updateObj.TeamInfo = input.TeamInfo; |
| | | updateObj.Timestamp = input.Timestamp; |
| | | updateObj.Remark = input.Remark; |
| | | updateObj.IsDisabled = input.IsDisabled; |
| | | |
| | | |
| | | await workPlanRepository.UpdateAsync(updateObj); |
| | | |
| | | return ObjectMapper.Map<WorkPlan, WorkPlanDto>(updateObj); |
| | | } |
| | | |
| | | |
| | | |
| | | await _workPlanRepository.UpdateAsync(updateObj); |
| | | |
| | | return ObjectMapper.Map<WorkPlan, WorkPlanDto>(updateObj); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 克隆作业计划表 |
| | | /// </summary> |
| | | /// <param name="ids"></param> |
| | | /// <returns></returns> |
| | | public async Task<List<WorkPlanDto>> CloneAsync(IEnumerable<Guid> ids) |
| | | { |
| | | public async Task<List<WorkPlanDto>> CloneAsync(IEnumerable<Guid> ids) |
| | | { |
| | | //var workPlans = new List<WorkPlan>(); |
| | | //if (ids != null) |
| | | //{ |
| | |
| | | // name += WorkPlanConsts.CloneTag; |
| | | // continue; |
| | | // } |
| | | |
| | | |
| | | // notExist = true; |
| | | // } |
| | | |
| | | |
| | | // //WorkPlan = await workPlanRepository.InsertAsync(WorkPlan.Clone(GuidGenerator.Create(), name, sort++)); |
| | | // workPlans.Add(WorkPlan); |
| | | // } |
| | | // } |
| | | //} |
| | | |
| | | |
| | | //return ObjectMapper.Map<List<WorkPlan>, List<WorkPlanDto>>(workPlans); |
| | | return new List<WorkPlanDto>(); |
| | | } |
| | | |
| | | return new List<WorkPlanDto>(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除单个作业计划表 |
| | | /// </summary> |
| | | /// <param name="id"></param> |
| | | /// <returns></returns> |
| | | public virtual Task DeleteAsync(Guid id) |
| | | { |
| | | return workPlanRepository.DeleteAsync(id); |
| | | } |
| | | |
| | | public virtual Task DeleteAsync(Guid id) |
| | | { |
| | | return _workPlanRepository.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) |
| | | { |
| | | foreach (var id in ids) |
| | | { |
| | | await DeleteAsync(id); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 调整排序作业计划表 |
| | | /// </summary> |
| | | /// <param name="id"></param> |
| | | /// <param name="sort"></param> |
| | | /// <returns></returns> |
| | | public virtual async Task AdjustSortAsync(Guid id, int sort) |
| | | { |
| | | var list = await workPlanRepository.GetListAsync(null, nameof(WorkPlan.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 workPlanRepository.UpdateManyAsync(list); |
| | | } |
| | | |
| | | public virtual async Task AdjustSortAsync(Guid id, int sort) |
| | | { |
| | | var list = await _workPlanRepository.GetListAsync(null, nameof(WorkPlan.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 _workPlanRepository.UpdateManyAsync(list); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 导入作业计划表 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="UserFriendlyException"></exception> |
| | | public async Task ImportAsync(WorkPlansImportModel input) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | |
| | | var workPlanCreateDtos = new List<(int RowIndex, WorkPlanCreateDto Item)>(); |
| | | var workPlanUpdateDtos = new List<(int RowIndex, Guid Id, WorkPlanUpdateDto Item)>(); |
| | | var importItems = input.WorkPlans; |
| | | |
| | | if (importItems != null && importItems.Any()) |
| | | { |
| | | #region 导入校验 |
| | | |
| | | // 判断名称是否重复,并输出第几行重复 |
| | | var duplicateWorkPlans = importItems.GroupBy(x => x.TaskCode).Where(x => x.Count() > 1).ToList(); |
| | | if (duplicateWorkPlans?.Any() == true) |
| | | { |
| | | var duplicateWorkPlanMsgs = duplicateWorkPlans.Select(x => $"第 {string.Join(",", x.Select(x => x.RowIndex))} 行:{x.Key} 名称重复"); |
| | | var errorMsg = $"导入失败!配置, {string.Join(",", duplicateWorkPlanMsgs)},终止导入"; |
| | | throw new UserFriendlyException(errorMsg); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | foreach (var impItem in importItems) |
| | | { |
| | | if (impItem.TaskCode.IsNullOrWhiteSpace()) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | if (impItem.TaskCode.IsNullOrWhiteSpace()) |
| | | { |
| | | var errorMsg = $"导入失败!配置,第{impItem.RowIndex}行:WorkPlan名称不能为空"; |
| | | throw new UserFriendlyException(errorMsg); |
| | | } |
| | | |
| | | var oldWorkPlan = await workPlanRepository.FindByNameAsync(impItem.TaskCode); |
| | | if (oldWorkPlan != null) |
| | | { |
| | | var workPlanUpdateDto = new WorkPlanUpdateDto |
| | | { |
| | | TaskCode = impItem.TaskCode, |
| | | OrgMaterialCode = impItem.OrgMaterialCode, |
| | | FactoryCode = impItem.FactoryCode, |
| | | ProductCode = impItem.ProductCode, |
| | | WorkstationCode = impItem.WorkstationCode, |
| | | EquipmentCode = impItem.EquipmentCode, |
| | | WorkpieceName = impItem.WorkpieceName, |
| | | ProcessName = impItem.ProcessName, |
| | | PipeFittingCode = impItem.PipeFittingCode, |
| | | PreSerialNumber = impItem.PreSerialNumber, |
| | | DataIdentifier = impItem.DataIdentifier, |
| | | PipeSpecCode = impItem.PipeSpecCode, |
| | | PipeSectionName = impItem.PipeSectionName, |
| | | OuterDiameter = impItem.OuterDiameter, |
| | | Bevel = impItem.Bevel, |
| | | Material = impItem.Material, |
| | | Length = impItem.Length, |
| | | DrillingPosition = impItem.DrillingPosition, |
| | | Intersecting = impItem.Intersecting, |
| | | InterfaceRequirement = impItem.InterfaceRequirement, |
| | | HasMainSignature = impItem.HasMainSignature, |
| | | Quantity = impItem.Quantity, |
| | | MarkingContent = impItem.MarkingContent, |
| | | CuttingFile = impItem.CuttingFile, |
| | | BranchOuterDiameter = impItem.BranchOuterDiameter, |
| | | BranchWallThickness = impItem.BranchWallThickness, |
| | | BranchMaterial = impItem.BranchMaterial, |
| | | BranchPortRadius = impItem.BranchPortRadius, |
| | | BranchPortAngle = impItem.BranchPortAngle, |
| | | BranchPortRequirement = impItem.BranchPortRequirement, |
| | | IntersectingLineType = impItem.IntersectingLineType, |
| | | IntersectingLineCategory = impItem.IntersectingLineCategory, |
| | | FinishedProductScale = impItem.FinishedProductScale, |
| | | FlangeThickness = impItem.FlangeThickness, |
| | | FlangeInnerDiameter = impItem.FlangeInnerDiameter, |
| | | WeldingHeatInput = impItem.WeldingHeatInput, |
| | | PipeAllowableStress = impItem.PipeAllowableStress, |
| | | PipeDiameter = impItem.PipeDiameter, |
| | | PipeWallThickness = impItem.PipeWallThickness, |
| | | VRData = impItem.VRData, |
| | | ProcessRouteNumber = impItem.ProcessRouteNumber, |
| | | PlannedStartTime = impItem.PlannedStartTime, |
| | | PlannedEndTime = impItem.PlannedEndTime, |
| | | TimeInfo = impItem.TimeInfo, |
| | | RedundantField1 = impItem.RedundantField1, |
| | | RedundantField2 = impItem.RedundantField2, |
| | | RedundantField3 = impItem.RedundantField3, |
| | | Remark = impItem.Remark, |
| | | IsDisabled = impItem.IsDisabled, |
| | | |
| | | }; |
| | | |
| | | workPlanUpdateDtos.Add((impItem.RowIndex, oldWorkPlan.Id, workPlanUpdateDto)); |
| | | } |
| | | else |
| | | { |
| | | var workPlanCreateDto = new WorkPlanCreateDto |
| | | { |
| | | TaskCode = impItem.TaskCode, |
| | | OrgMaterialCode = impItem.OrgMaterialCode, |
| | | FactoryCode = impItem.FactoryCode, |
| | | ProductCode = impItem.ProductCode, |
| | | WorkstationCode = impItem.WorkstationCode, |
| | | EquipmentCode = impItem.EquipmentCode, |
| | | WorkpieceName = impItem.WorkpieceName, |
| | | ProcessName = impItem.ProcessName, |
| | | PipeFittingCode = impItem.PipeFittingCode, |
| | | PreSerialNumber = impItem.PreSerialNumber, |
| | | DataIdentifier = impItem.DataIdentifier, |
| | | PipeSpecCode = impItem.PipeSpecCode, |
| | | PipeSectionName = impItem.PipeSectionName, |
| | | OuterDiameter = impItem.OuterDiameter, |
| | | Bevel = impItem.Bevel, |
| | | Material = impItem.Material, |
| | | Length = impItem.Length, |
| | | DrillingPosition = impItem.DrillingPosition, |
| | | Intersecting = impItem.Intersecting, |
| | | InterfaceRequirement = impItem.InterfaceRequirement, |
| | | HasMainSignature = impItem.HasMainSignature, |
| | | Quantity = impItem.Quantity, |
| | | MarkingContent = impItem.MarkingContent, |
| | | CuttingFile = impItem.CuttingFile, |
| | | BranchOuterDiameter = impItem.BranchOuterDiameter, |
| | | BranchWallThickness = impItem.BranchWallThickness, |
| | | BranchMaterial = impItem.BranchMaterial, |
| | | BranchPortRadius = impItem.BranchPortRadius, |
| | | BranchPortAngle = impItem.BranchPortAngle, |
| | | BranchPortRequirement = impItem.BranchPortRequirement, |
| | | IntersectingLineType = impItem.IntersectingLineType, |
| | | IntersectingLineCategory = impItem.IntersectingLineCategory, |
| | | FinishedProductScale = impItem.FinishedProductScale, |
| | | FlangeThickness = impItem.FlangeThickness, |
| | | FlangeInnerDiameter = impItem.FlangeInnerDiameter, |
| | | WeldingHeatInput = impItem.WeldingHeatInput, |
| | | PipeAllowableStress = impItem.PipeAllowableStress, |
| | | PipeDiameter = impItem.PipeDiameter, |
| | | PipeWallThickness = impItem.PipeWallThickness, |
| | | VRData = impItem.VRData, |
| | | ProcessRouteNumber = impItem.ProcessRouteNumber, |
| | | PlannedStartTime = impItem.PlannedStartTime, |
| | | PlannedEndTime = impItem.PlannedEndTime, |
| | | TimeInfo = impItem.TimeInfo, |
| | | RedundantField1 = impItem.RedundantField1, |
| | | RedundantField2 = impItem.RedundantField2, |
| | | RedundantField3 = impItem.RedundantField3, |
| | | Remark = impItem.Remark, |
| | | IsDisabled = impItem.IsDisabled, |
| | | |
| | | }; |
| | | |
| | | workPlanCreateDtos.Add((impItem.RowIndex, workPlanCreateDto)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 新增 |
| | | foreach (var workPlanDto in workPlanCreateDtos) |
| | | { |
| | | try |
| | | { |
| | | await CreateAsync(workPlanDto.Item); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | var errorMsg = $"导入失败!配置,第{workPlanDto.RowIndex}行:{e.Message},终止导入"; |
| | | throw new UserFriendlyException(errorMsg); |
| | | } |
| | | } |
| | | |
| | | // 更新 |
| | | foreach (var workPlanDto in workPlanUpdateDtos) |
| | | { |
| | | try |
| | | { |
| | | await UpdateAsync(workPlanDto.Id, workPlanDto.Item); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | var errorMsg = $"导入失败!配置,第{workPlanDto.RowIndex}行:{e.Message},终止导入"; |
| | | throw new UserFriendlyException(errorMsg); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public async Task ImportAsync(WorkPlansImportModel input, MyCurrentUser myCurrentUser) |
| | | { |
| | | //转换数据 |
| | | var result = ObjectMapper.Map<List<WorkPlansImportModel.WorkPlanImportModel>, List<WorkPlanInput>>(input.WorkPlans); |
| | | |
| | | //await CreatebyApsAsync(result); |
| | | await _sharedService.CommonCreatebyApsAsync(result, _serviceProvider, this, myCurrentUser.UserId, myCurrentUser.UserAccount); |
| | | // Check.NotNull(input, nameof(input)); |
| | | |
| | | // var workPlanCreateDtos = new List<(int RowIndex, WorkPlanCreateDto Item)>(); |
| | | // var workPlanUpdateDtos = new List<(int RowIndex, Guid Id, WorkPlanUpdateDto Item)>(); |
| | | // var importItems = input.WorkPlans; |
| | | |
| | | // if (importItems != null && importItems.Any()) |
| | | // { |
| | | // #region 导入校验 |
| | | |
| | | // // 判断名称是否重复,并输出第几行重复 |
| | | // var duplicateWorkPlans = importItems.GroupBy(x => x.TaskCode).Where(x => x.Count() > 1).ToList(); |
| | | // if (duplicateWorkPlans?.Any() == true) |
| | | // { |
| | | // var duplicateWorkPlanMsgs = duplicateWorkPlans.Select(x => $"第 {string.Join(",", x.Select(x => x.RowIndex))} 行:{x.Key} 名称重复"); |
| | | // var errorMsg = $"导入失败!配置, {string.Join(",", duplicateWorkPlanMsgs)},终止导入"; |
| | | // throw new UserFriendlyException(errorMsg); |
| | | // } |
| | | |
| | | // #endregion |
| | | |
| | | // foreach (var impItem in importItems) |
| | | // { |
| | | // if (impItem.TaskCode.IsNullOrWhiteSpace()) |
| | | // { |
| | | // continue; |
| | | // } |
| | | |
| | | // if (impItem.TaskCode.IsNullOrWhiteSpace()) |
| | | // { |
| | | // var errorMsg = $"导入失败!配置,第{impItem.RowIndex}行:WorkPlan名称不能为空"; |
| | | // throw new UserFriendlyException(errorMsg); |
| | | // } |
| | | |
| | | // var oldWorkPlan = await workPlanRepository.FindByNameAsync(impItem.TaskCode); |
| | | // if (oldWorkPlan != null) |
| | | // { |
| | | // var workPlanUpdateDto = new WorkPlanUpdateDto |
| | | // { |
| | | // TaskCode = impItem.TaskCode, |
| | | //WorkPlanStatus = impItem.WorkPlanStatus, |
| | | //CallMaterialStatus = impItem.CallMaterialStatus, |
| | | //DataIdentifier = impItem.DataIdentifier, |
| | | //MaterialMode = impItem.MaterialMode, |
| | | //Length = impItem.Length, |
| | | //MarkingContent = impItem.MarkingContent, |
| | | //MarkingPosition = impItem.MarkingPosition, |
| | | //CuttingPosition = impItem.CuttingPosition, |
| | | //Quantity = impItem.Quantity, |
| | | //FlangeThickness = impItem.FlangeThickness, |
| | | //FlangeInnerDiameter = impItem.FlangeInnerDiameter, |
| | | //WeldingHeatInput = impItem.WeldingHeatInput, |
| | | //PipeAllowableStress = impItem.PipeAllowableStress, |
| | | //PipeDiameter = impItem.PipeDiameter, |
| | | //PipeWallThickness = impItem.PipeWallThickness, |
| | | //FactoryCode = impItem.FactoryCode, |
| | | //ProductCode = impItem.ProductCode, |
| | | //WorkstationCode = impItem.WorkstationCode, |
| | | //EquipmentCode = impItem.EquipmentCode, |
| | | //WorkpieceName = impItem.WorkpieceName, |
| | | //ProcessName = impItem.ProcessName, |
| | | //PipeFittingCode = impItem.PipeFittingCode, |
| | | //PreSerialNumber = impItem.PreSerialNumber, |
| | | //PipeSpecCode = impItem.PipeSpecCode, |
| | | //PipeSectionName = impItem.PipeSectionName, |
| | | //OuterDiameter = impItem.OuterDiameter, |
| | | //Thickness = impItem.Thickness, |
| | | //Material = impItem.Material, |
| | | //ProcessRouteNumber = impItem.ProcessRouteNumber, |
| | | //PlannedStartTime = impItem.PlannedStartTime, |
| | | //PlannedEndTime = impItem.PlannedEndTime, |
| | | //TeamInfo = impItem.TeamInfo, |
| | | //Timestamp = impItem.Timestamp, |
| | | //Remark = impItem.Remark, |
| | | |
| | | // }; |
| | | |
| | | // workPlanUpdateDtos.Add((impItem.RowIndex, oldWorkPlan.Id, workPlanUpdateDto)); |
| | | // } |
| | | // else |
| | | // { |
| | | // var workPlanCreateDto = new WorkPlanCreateDto |
| | | // { |
| | | // TaskCode = impItem.TaskCode, |
| | | //WorkPlanStatus = impItem.WorkPlanStatus, |
| | | //CallMaterialStatus = impItem.CallMaterialStatus, |
| | | //DataIdentifier = impItem.DataIdentifier, |
| | | //MaterialMode = impItem.MaterialMode, |
| | | //Length = impItem.Length, |
| | | //MarkingContent = impItem.MarkingContent, |
| | | //MarkingPosition = impItem.MarkingPosition, |
| | | //CuttingPosition = impItem.CuttingPosition, |
| | | //Quantity = impItem.Quantity, |
| | | //FlangeThickness = impItem.FlangeThickness, |
| | | //FlangeInnerDiameter = impItem.FlangeInnerDiameter, |
| | | //WeldingHeatInput = impItem.WeldingHeatInput, |
| | | //PipeAllowableStress = impItem.PipeAllowableStress, |
| | | //PipeDiameter = impItem.PipeDiameter, |
| | | //PipeWallThickness = impItem.PipeWallThickness, |
| | | //FactoryCode = impItem.FactoryCode, |
| | | //ProductCode = impItem.ProductCode, |
| | | //WorkstationCode = impItem.WorkstationCode, |
| | | //EquipmentCode = impItem.EquipmentCode, |
| | | //WorkpieceName = impItem.WorkpieceName, |
| | | //ProcessName = impItem.ProcessName, |
| | | //PipeFittingCode = impItem.PipeFittingCode, |
| | | //PreSerialNumber = impItem.PreSerialNumber, |
| | | //PipeSpecCode = impItem.PipeSpecCode, |
| | | //PipeSectionName = impItem.PipeSectionName, |
| | | //OuterDiameter = impItem.OuterDiameter, |
| | | //Thickness = impItem.Thickness, |
| | | //Material = impItem.Material, |
| | | //ProcessRouteNumber = impItem.ProcessRouteNumber, |
| | | //PlannedStartTime = impItem.PlannedStartTime, |
| | | //PlannedEndTime = impItem.PlannedEndTime, |
| | | //TeamInfo = impItem.TeamInfo, |
| | | //Timestamp = impItem.Timestamp, |
| | | //Remark = impItem.Remark, |
| | | |
| | | // }; |
| | | |
| | | // workPlanCreateDtos.Add((impItem.RowIndex, workPlanCreateDto)); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | // // 新增 |
| | | // foreach (var workPlanDto in workPlanCreateDtos) |
| | | // { |
| | | // try |
| | | // { |
| | | // await CreateAsync(workPlanDto.Item); |
| | | // } |
| | | // catch (Exception e) |
| | | // { |
| | | // var errorMsg = $"导入失败!配置,第{workPlanDto.RowIndex}行:{e.Message},终止导入"; |
| | | // throw new UserFriendlyException(errorMsg); |
| | | // } |
| | | // } |
| | | |
| | | // // 更新 |
| | | // foreach (var workPlanDto in workPlanUpdateDtos) |
| | | // { |
| | | // try |
| | | // { |
| | | // await UpdateAsync(workPlanDto.Id, workPlanDto.Item); |
| | | // } |
| | | // catch (Exception e) |
| | | // { |
| | | // var errorMsg = $"导入失败!配置,第{workPlanDto.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(GetWorkPlanInput input) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | |
| | | if (input.Sorting.IsNullOrWhiteSpace()) |
| | | { |
| | | input.Sorting = nameof(WorkPlan.Sort); |
| | | } |
| | | |
| | | public async Task<(Dictionary<string, object> Sheets, string FileName)> ExportAsync(GetWorkPlanInput input) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | |
| | | if (input.Sorting.IsNullOrWhiteSpace()) |
| | | { |
| | | input.Sorting = nameof(WorkPlan.Sort); |
| | | } |
| | | |
| | | #region 动态构造查询条件 |
| | | |
| | | |
| | | //动态构造查询条件 |
| | | var whereConditions = DynamicGetQueryParams(input); |
| | | |
| | | #endregion |
| | | |
| | | |
| | | var list = await workPlanRepository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount, includeDetails: true); |
| | | var result = ObjectMapper.Map<List<WorkPlan>, List<WorkPlanDto>>(list); |
| | | |
| | | var sheets = new Dictionary<string, object> |
| | | { |
| | | ["配置"] = ExportHelper.ConvertListToExportData(result), |
| | | }; |
| | | |
| | | var fileName = result.Count > 1 ? "作业计划表列表" : result.Count == 1 ? result[0]?.TaskCode : "WorkPlan模版"; |
| | | return (sheets, fileName); |
| | | } |
| | | |
| | | var whereConditions = DynamicGetQueryParams(input); |
| | | |
| | | #endregion |
| | | |
| | | |
| | | var list = await _workPlanRepository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount, includeDetails: true); |
| | | var result = ObjectMapper.Map<List<WorkPlan>, List<WorkPlanDto>>(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(WorkPlanCreateOrUpdateDtoBase input) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | Check.NotNullOrWhiteSpace(input.TaskCode, "任务编码", 64); |
| | | Check.NotNullOrWhiteSpace(input.OrgMaterialCode, "原料编号", 64); |
| | | Check.NotNull(input.HasMainSignature, "是否有主签"); |
| | | Check.NotNull(input.Quantity, "包括数量"); |
| | | |
| | | return Task.CompletedTask; |
| | | } |
| | | } |
| | | protected Task CheckCreateOrUpdateDtoAsync(WorkPlanCreateOrUpdateDtoBase input) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | Check.NotNullOrWhiteSpace(input.TaskCode, "任务编码", 256); |
| | | Check.NotNull(input.WorkPlanStatus, "计划状态"); |
| | | Check.NotNull(input.CallMaterialStatus, "叫料状态"); |
| | | Check.NotNull(input.Length, "长度(mm)"); |
| | | Check.NotNull(input.MarkingPosition, "打码位置"); |
| | | Check.NotNull(input.CuttingPosition, "切割位置"); |
| | | Check.NotNull(input.Quantity, "管段数量"); |
| | | Check.NotNull(input.FlangeThickness, "法兰厚度(mm)"); |
| | | Check.NotNull(input.FlangeInnerDiameter, "法兰直径(mm)"); |
| | | Check.NotNull(input.PipeDiameter, "套管长度(mm)"); |
| | | Check.NotNull(input.PipeWallThickness, "套管直径(mm)"); |
| | | Check.NotNull(input.OuterDiameter, "外径(mm)"); |
| | | Check.NotNull(input.Thickness, "壁厚(mm)"); |
| | | |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据条件获取作业计划表列表 |
| | | /// </summary> |
| | | /// <param name="whereConditions"></param> |
| | | /// <param name="cancellationToken"></param> |
| | | /// <returns></returns> |
| | | public async Task<List<WorkPlan>> GetListByFilterAsync(Expression<Func<WorkPlan, bool>> whereConditions, CancellationToken cancellationToken = default) |
| | | { |
| | | return await _workPlanRepository.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<WorkPlan> GetSingleByFilterAsync(Expression<Func<WorkPlan, bool>> whereConditions, bool isMultipleThrowException = false, CancellationToken cancellationToken = default) |
| | | { |
| | | return await _workPlanRepository.GetSingleByFilterAsync(whereConditions, isMultipleThrowException); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 根据条件获取作业计划表列表 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public virtual async Task<List<WorkPlanDto>> FindListByFilterAsync(GetWorkPlanInput input, CancellationToken cancellationToken = default) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | |
| | | if (input.Sorting.IsNullOrWhiteSpace()) |
| | | { |
| | | input.Sorting = nameof(WorkPlan.Sort); |
| | | } |
| | | |
| | | #region 动态构造查询条件 |
| | | |
| | | //动态构造查询条件 |
| | | var whereConditions = DynamicGetQueryParams(input); |
| | | |
| | | #endregion |
| | | |
| | | var list = await _workPlanRepository.GetListByFilterAsync(whereConditions?.data); |
| | | |
| | | return new List<WorkPlanDto>(ObjectMapper.Map<List<WorkPlan>, List<WorkPlanDto>>(list)); |
| | | } |
| | | /// <summary> |
| | | /// 根据条件获取单个作业计划表 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public virtual async Task<WorkPlanDto> FindSingleByFilterAsync(GetWorkPlanInput input, CancellationToken cancellationToken = default) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | |
| | | if (input.Sorting.IsNullOrWhiteSpace()) |
| | | { |
| | | input.Sorting = nameof(WorkPlan.Sort); |
| | | } |
| | | |
| | | #region 动态构造查询条件 |
| | | |
| | | //动态构造查询条件 |
| | | var whereConditions = DynamicGetQueryParams(input); |
| | | |
| | | #endregion |
| | | |
| | | var dataObj = await _workPlanRepository.GetSingleByFilterAsync(whereConditions?.data); |
| | | |
| | | return (ObjectMapper.Map<WorkPlan, WorkPlanDto>(dataObj)); |
| | | } |
| | | } |