修改服务流程保存

optimize
jianghaiqing 1 year ago
parent ec85f7c0af
commit acd1392775

@ -9,7 +9,46 @@ namespace Myshipping.Application
/// <summary>
///
/// </summary>
public class ServiceWorkFlowActivitiesShowDto: ServiceWorkFlowActivitiesDto
public class ServiceWorkFlowActivitiesShowDto
{
/// <summary>
/// 主键
/// </summary>
public string PKId { get; set; }
/// <summary>
/// 状态主键
/// </summary>
public string StatusSKUId { get; set; }
/// <summary>
/// 状态显示名称
/// </summary>
public string ShowName { get; set; }
/// <summary>
/// 显示顺序号
/// </summary>
public int SortNo { get; set; }
/// <summary>
/// 是否包含子状态 1-包含 0-不包含
/// </summary>
public int IsContainsSub { get; set; }
/// <summary>
/// 子活动列表
/// </summary>
public List<ServiceWorkFlowActivitiesSubShowDto> SubList { get; set; }
/// <summary>
/// 状态详情
/// </summary>
public StatusSkuBaseDto statusSkuBase { get; set; }
}
public class ServiceWorkFlowActivitiesSubShowDto: ServiceWorkFlowActivitiesSubDto
{
/// <summary>
/// 状态详情

@ -56,6 +56,12 @@ namespace Myshipping.Application
.Map(dest => dest.STATUS_SKU_NOTE, src => src.StatusSKUNote)
.Map(dest => dest.BACKGROUND_COLOR, src => src.BackgroundColor);
config.ForType<StatusSkuBaseInfo, StatusSkuBaseDto>()
.Map(dest => dest.PKId, src => src.PK_ID)
.Map(dest => dest.StatusSKUCode, src => src.STATUS_SKU_CODE)
.Map(dest => dest.StatusSKUName, src => src.STATUS_SKU_NAME)
.Map(dest => dest.SortNo, src => src.SORT_NO);
config.ForType<StatusSkuBaseInfo, StatusSkuBaseShowDto>()
.Map(dest => dest.PKId, src => src.PK_ID)
.Map(dest => dest.StatusSKUCode, src => src.STATUS_SKU_CODE)
@ -115,6 +121,16 @@ namespace Myshipping.Application
.Map(dest => dest.PK_ID, src => src.PKId)
.Map(dest => dest.STATUS_SKU_ID, src => src.StatusSKUId)
.Map(dest => dest.SHOW_NAME, src => src.ShowName);
config.ForType<ServiceWorkFlowActivitiesInfo, ServiceWorkFlowActivitiesShowDto>()
.Map(dest => dest.PKId, src => src.PK_ID)
.Map(dest => dest.StatusSKUId, src => src.STATUS_SKU_ID)
.Map(dest => dest.ShowName, src => src.SHOW_NAME);
config.ForType<ServiceWorkFlowActivitiesInfo, ServiceWorkFlowActivitiesDto>()
.Map(dest => dest.PKId, src => src.PK_ID)
.Map(dest => dest.StatusSKUId, src => src.STATUS_SKU_ID)
.Map(dest => dest.ShowName, src => src.SHOW_NAME);
}
}
}

@ -31,15 +31,17 @@ namespace Myshipping.Application
private readonly SqlSugarRepository<ServiceWorkFlowActivitiesInfo> _serviceWorkFlowActivitiesInfoRepository;
private readonly SqlSugarRepository<ServiceWorkFlowProjectRelation> _serviceWorkFlowProjectRelationRepository;
private readonly SqlSugarRepository<ServiceWorkFlowActivitiesRelation> _serviceWorkFlowActivitiesRelationRepository;
private readonly SqlSugarRepository<ServiceWorkFlowActivitiesSubRelation> _serviceWorkFlowActivitiesSubRelationRepository;
private readonly ILogger<ServiceWorkFlowBaseService> _logger;
public ServiceWorkFlowBaseService(SqlSugarRepository<ServiceWorkFlowBaseInfo> serviceWorkFlowBaseRepository,
ILogger<ServiceWorkFlowBaseService> logger,
SqlSugarRepository<ServiceWorkFlowActivitiesInfo> serviceWorkFlowActivitiesInfoRepository,
SqlSugarRepository<ServiceWorkFlowProjectRelation> serviceWorkFlowProjectRelationRepository,
SqlSugarRepository<ServiceWorkFlowActivitiesRelation> serviceWorkFlowActivitiesRelationRepository)
SqlSugarRepository<ServiceWorkFlowActivitiesRelation> serviceWorkFlowActivitiesRelationRepository,
SqlSugarRepository<ServiceWorkFlowActivitiesSubRelation> serviceWorkFlowActivitiesSubRelationRepository)
{
_serviceWorkFlowBaseRepository = serviceWorkFlowBaseRepository;
_serviceWorkFlowActivitiesInfoRepository = serviceWorkFlowActivitiesInfoRepository;
@ -47,6 +49,7 @@ namespace Myshipping.Application
_serviceWorkFlowActivitiesRelationRepository = serviceWorkFlowActivitiesRelationRepository;
_logger = logger;
_serviceWorkFlowActivitiesSubRelationRepository = serviceWorkFlowActivitiesSubRelationRepository;
}
/// <summary>
@ -203,6 +206,14 @@ namespace Myshipping.Application
_logger.LogInformation($"更新状态前,获取原始记录 JSON={JSON.Serialize(model)}");
if (info.StatusSkuList != null && info.StatusSkuList.Count > 0)
{
if (info.StatusSkuList.Any(a => a.IsContainsSub == 1 && (a.SubList == null || a.SubList.Count == 0)))
{
throw Oops.Oh($"状态已选择包含子状态,子状态列表不能为空", typeof(InvalidOperationException));
}
}
ValidateServiceWorkFlow(entity, OperateTypeEnum.Save);
entity.UpdatedTime = DateTime.Now;
@ -226,6 +237,10 @@ namespace Myshipping.Application
//批量删除服务流程与服务活动关系(物理删除)
_serviceWorkFlowActivitiesRelationRepository.EntityContext.Deleteable<ServiceWorkFlowProjectRelation>()
.Where(a => a.SERVICE_WORKFLOW_ID == entity.PK_ID);
//批量删除服务流程活动与子活动的关系(物理删除)
_serviceWorkFlowActivitiesSubRelationRepository.EntityContext.Deleteable<ServiceWorkFlowActivitiesSubRelation>()
.Where(a => a.SERVICE_WORKFLOW_ID == entity.PK_ID);
}
//服务流程与服务项目关系
@ -250,9 +265,26 @@ namespace Myshipping.Application
PK_ID = IDGen.NextID().ToString(),
SERVICE_WORKFLOW_ID = entity.PK_ID,
SERVICE_ACTIVITIES_ID = sku.PKId,
IS_CONTAINS_SUB = sku.IsContainsSub
};
await _serviceWorkFlowActivitiesRelationRepository.InsertAsync();
await _serviceWorkFlowActivitiesRelationRepository.InsertAsync(wfRelationActivities);
//处理子状态
if(sku.IsContainsSub == 1)
{
sku.SubList.ForEach(async sub => {
var wfRelationActivitiesSub = new ServiceWorkFlowActivitiesSubRelation
{
PK_ID = IDGen.NextID().ToString(),
SERVICE_WORKFLOW_ID = entity.PK_ID,
SERVICE_ACTIVITIES_ID = sku.PKId,
SUB_SERVICE_ACTIVITIES_ID = sub.PKId
};
await _serviceWorkFlowActivitiesSubRelationRepository.InsertAsync(wfRelationActivitiesSub);
});
}
});
}
@ -336,18 +368,64 @@ namespace Myshipping.Application
.LeftJoin<ServiceWorkFlowActivitiesInfo>((rela, act) =>
rela.SERVICE_ACTIVITIES_ID == act.PK_ID && rela.SERVICE_WORKFLOW_ID == pkId)
.LeftJoin<StatusSkuBaseInfo>((rela, act, sku) => act.STATUS_SKU_ID == sku.PK_ID)
.Select((rela, act, sku) => new { Act = act, Sku = sku, SortNo = rela.SORT_NO }).ToList();
.Select((rela, act, sku) =>
new { Act = act, Sku = sku, SortNo = rela.SORT_NO, IsSub = rela.IS_CONTAINS_SUB })
.ToList();
if (activitiesList.Count > 0)
{
showModel.StatusSkuList = activitiesList.OrderBy(a=>a.SortNo)
showModel.StatusSkuList = activitiesList.OrderBy(a => a.SortNo)
.Select(a =>
{
var actModel = a.Act.Adapt<ServiceWorkFlowActivitiesShowDto>();
actModel.SortNo = a.SortNo;
actModel.IsContainsSub = a.IsSub;
actModel.statusSkuBase = a.Sku.Adapt<StatusSkuBaseDto>();
return actModel;
}).ToList();
}
var activitiesSubList = _serviceWorkFlowActivitiesSubRelationRepository.AsQueryable()
.LeftJoin<ServiceWorkFlowActivitiesInfo>((rela, act) =>
rela.SUB_SERVICE_ACTIVITIES_ID == act.PK_ID && rela.SERVICE_WORKFLOW_ID == pkId)
.LeftJoin<StatusSkuBaseInfo>((rela, act, sku) => act.STATUS_SKU_ID == sku.PK_ID)
.Select((rela, act, sku) =>
new { Act = act, Sku = sku, SortNo = rela.SORT_NO, ParentId = rela.SERVICE_ACTIVITIES_ID })
.ToList();
if(activitiesSubList.Count > 0)
{
var subList = activitiesSubList
.GroupBy(a => a.ParentId)
.Select(a => {
var actModel = a.Act.Adapt<ServiceWorkFlowActivitiesShowDto>();
var currArg = a.ToList();
return new { Key = a.Key, SubList = currArg.OrderBy(b=>b.SortNo)
.Select(b => {
var actModel = b.Act.Adapt<ServiceWorkFlowActivitiesSubShowDto>();
actModel.SortNo = b.SortNo;
actModel.statusSkuBase = b.Sku.Adapt<StatusSkuBaseDto>();
return actModel;
}).ToList() };
});
showModel.StatusSkuList.GroupJoin(subList, l => l.PKId, r => r.Key, (l,
r) => {
var currArg = r.ToList();
if (currArg.Count == 0)
return l;
l.SubList = currArg.FirstOrDefault().SubList.ToList();
actModel.statusSkuBase = a.Sku.Adapt<StatusSkuBaseDto>();
return l;
return actModel;
}).ToList();
}).ToList();
}
return showModel;

@ -546,11 +546,11 @@ namespace Myshipping.Application
try
{
var list = await _statusSkuBaseInfoRepository.AsQueryable().Where(a =>
a.IS_ENABLE == 1 && !a.IsDeleted && (a.STATUS_SKU_CODE.Contains(queryItem) || a.STATUS_SKU_NAME.Contains(queryItem)))
a.IS_ENABLE == 1 && !a.IsDeleted && (string.IsNullOrWhiteSpace(queryItem) || (a.STATUS_SKU_CODE.Contains(queryItem) || a.STATUS_SKU_NAME.Contains(queryItem))))
.Take(topNum).ToListAsync();
result.succ = true;
result.ext = list.Adapt<List<ServiceProjectBaseDto>>();
result.ext = list.Adapt<List<StatusSkuBaseDto>>();
}
catch (Exception ex)

Loading…
Cancel
Save