|
|
|
@ -7,6 +7,7 @@ using Mapster;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using Myshipping.Application.Entity;
|
|
|
|
|
using Myshipping.Application.Helper;
|
|
|
|
|
using Myshipping.Core;
|
|
|
|
@ -38,8 +39,16 @@ namespace Myshipping.Application
|
|
|
|
|
private readonly SqlSugarRepository<ServiceWorkFlowActivitiesSubRelation> _serviceWorkFlowActivitiesSubRelationRepository;
|
|
|
|
|
private readonly SqlSugarRepository<ServiceWorkFlowReleaseInfo> _serviceWorkFlowReleaseInfoRepository;
|
|
|
|
|
private readonly SqlSugarRepository<ServiceWorkFlowActivitiesTriggerRelation> _serviceWorkFlowActivitiesTriggerRelationRepository;
|
|
|
|
|
private readonly SqlSugarRepository<StatusSkuBaseInfo> _statusSkuBaseInfoRepository;
|
|
|
|
|
|
|
|
|
|
private readonly ILogger<ServiceWorkFlowBaseService> _logger;
|
|
|
|
|
|
|
|
|
|
private readonly ICache _cache;
|
|
|
|
|
private readonly CacheOptions _cacheOptions;
|
|
|
|
|
|
|
|
|
|
const string CONST_CACHE_ENABLE_PROJECT = "service_project_list_enable";
|
|
|
|
|
const string CONST_CACHE_ENABLE_PROJECT_STATUS = "service_project_status_list_enable";
|
|
|
|
|
|
|
|
|
|
public ServiceWorkFlowBaseService(SqlSugarRepository<ServiceWorkFlowBaseInfo> serviceWorkFlowBaseRepository,
|
|
|
|
|
ILogger<ServiceWorkFlowBaseService> logger,
|
|
|
|
|
SqlSugarRepository<ServiceWorkFlowActivitiesInfo> serviceWorkFlowActivitiesInfoRepository,
|
|
|
|
@ -47,7 +56,9 @@ namespace Myshipping.Application
|
|
|
|
|
SqlSugarRepository<ServiceWorkFlowActivitiesRelation> serviceWorkFlowActivitiesRelationRepository,
|
|
|
|
|
SqlSugarRepository<ServiceWorkFlowActivitiesSubRelation> serviceWorkFlowActivitiesSubRelationRepository,
|
|
|
|
|
SqlSugarRepository<ServiceWorkFlowActivitiesTriggerRelation> serviceWorkFlowActivitiesTriggerRelationRepository,
|
|
|
|
|
SqlSugarRepository<ServiceWorkFlowReleaseInfo> serviceWorkFlowReleaseInfoRepository)
|
|
|
|
|
SqlSugarRepository<ServiceWorkFlowReleaseInfo> serviceWorkFlowReleaseInfoRepository,
|
|
|
|
|
SqlSugarRepository<StatusSkuBaseInfo> statusSkuBaseInfoRepository,
|
|
|
|
|
IOptions<CacheOptions> cacheOptions, Func<string, ISingleton, object> resolveNamed)
|
|
|
|
|
{
|
|
|
|
|
_serviceWorkFlowBaseRepository = serviceWorkFlowBaseRepository;
|
|
|
|
|
_serviceWorkFlowActivitiesInfoRepository = serviceWorkFlowActivitiesInfoRepository;
|
|
|
|
@ -58,6 +69,10 @@ namespace Myshipping.Application
|
|
|
|
|
_serviceWorkFlowActivitiesSubRelationRepository = serviceWorkFlowActivitiesSubRelationRepository;
|
|
|
|
|
_serviceWorkFlowReleaseInfoRepository = serviceWorkFlowReleaseInfoRepository;
|
|
|
|
|
_serviceWorkFlowActivitiesTriggerRelationRepository = serviceWorkFlowActivitiesTriggerRelationRepository;
|
|
|
|
|
_statusSkuBaseInfoRepository = statusSkuBaseInfoRepository;
|
|
|
|
|
|
|
|
|
|
_cacheOptions = cacheOptions.Value;
|
|
|
|
|
_cache = resolveNamed(_cacheOptions.CacheType.ToString(), default) as ICache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -1702,5 +1717,231 @@ namespace Myshipping.Application
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 检索可用的服务项目列表
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 检索可用的服务项目列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="tenantId">租户ID</param>
|
|
|
|
|
/// <param name="isAvoidCache">是否不从缓存取值</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<List<ServiceProjectBaseDto>> GetEnableProjectList(string tenantId, bool isAvoidCache = false)
|
|
|
|
|
{
|
|
|
|
|
List<ServiceProjectBaseDto> projectList = _cache.Get<List<ServiceProjectBaseDto>>($"{CONST_CACHE_ENABLE_PROJECT}_{tenantId}");
|
|
|
|
|
|
|
|
|
|
if (isAvoidCache || projectList == null || projectList.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
var list = _serviceWorkFlowBaseRepository.AsQueryable().Filter(null, true)
|
|
|
|
|
.InnerJoin<ServiceWorkFlowProjectRelation>((wf, rela)
|
|
|
|
|
=> wf.PK_ID == rela.SERVICE_WORKFLOW_ID && wf.RELEASE_VERSION == rela.WF_VERSION)
|
|
|
|
|
.InnerJoin<ServiceProjectBaseInfo>((wf, rela, prj)
|
|
|
|
|
=> rela.SERVICE_PROJECT_ID == prj.PK_ID)
|
|
|
|
|
.Where((wf, rela, prj)
|
|
|
|
|
=> !string.IsNullOrWhiteSpace(wf.RELEASE_VERSION) && wf.BELONG_TENANT_ID == long.Parse(tenantId)
|
|
|
|
|
&& wf.IS_ENABLE == 1 && !wf.IsDeleted)
|
|
|
|
|
.Select((wf, rela, prj)
|
|
|
|
|
=> prj).ToList();
|
|
|
|
|
|
|
|
|
|
projectList = list.Select(a => a.Adapt<ServiceProjectBaseDto>())
|
|
|
|
|
.Distinct().OrderBy(a => a.SortNo).ToList();
|
|
|
|
|
|
|
|
|
|
await _cache.SetAsync($"{CONST_CACHE_ENABLE_PROJECT}_{tenantId}", projectList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return projectList;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 检索可用的服务项目和状态列表
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 检索可用的服务项目和状态列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="tenantId">租户ID</param>
|
|
|
|
|
/// <param name="isAvoidCache">是否不从缓存取值</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<List<ServiceProjectWithStatusDto>> GetEnableProjectWithStatusList(string tenantId, bool isAvoidCache = false)
|
|
|
|
|
{
|
|
|
|
|
List<ServiceProjectWithStatusDto> statusList = _cache.Get<List<ServiceProjectWithStatusDto>>($"{CONST_CACHE_ENABLE_PROJECT_STATUS}_{tenantId}");
|
|
|
|
|
|
|
|
|
|
if (isAvoidCache || statusList == null || statusList.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
var list = _serviceWorkFlowBaseRepository.AsQueryable().Filter(null, true)
|
|
|
|
|
.InnerJoin<ServiceWorkFlowProjectRelation>((wf, rela)
|
|
|
|
|
=> wf.PK_ID == rela.SERVICE_WORKFLOW_ID && wf.RELEASE_VERSION == rela.WF_VERSION)
|
|
|
|
|
.InnerJoin<ServiceProjectBaseInfo>((wf, rela, prj)
|
|
|
|
|
=> rela.SERVICE_PROJECT_ID == prj.PK_ID)
|
|
|
|
|
.InnerJoin<ServiceWorkFlowActivitiesRelation>((wf, rela, prj,
|
|
|
|
|
arela)
|
|
|
|
|
=> wf.PK_ID == arela.SERVICE_WORKFLOW_ID && wf.RELEASE_VERSION == arela.WF_VERSION)
|
|
|
|
|
.InnerJoin<ServiceWorkFlowActivitiesInfo>((wf, rela, prj,
|
|
|
|
|
arela, act)
|
|
|
|
|
=> arela.SERVICE_ACTIVITIES_ID == act.PK_ID)
|
|
|
|
|
.LeftJoin<ServiceWorkFlowActivitiesSubRelation>((wf, rela, prj,
|
|
|
|
|
arela, act, srela)
|
|
|
|
|
=> wf.PK_ID == srela.SERVICE_WORKFLOW_ID && wf.RELEASE_VERSION == srela.WF_VERSION)
|
|
|
|
|
.LeftJoin<ServiceWorkFlowActivitiesInfo>((wf, rela, prj,
|
|
|
|
|
arela, act, srela, sact)
|
|
|
|
|
=> srela.SERVICE_ACTIVITIES_ID == act.PK_ID)
|
|
|
|
|
.Where((wf, rela, prj,
|
|
|
|
|
arela, act, srela, sact)
|
|
|
|
|
=> !string.IsNullOrWhiteSpace(wf.RELEASE_VERSION) && wf.BELONG_TENANT_ID == long.Parse(tenantId)
|
|
|
|
|
&& wf.IS_ENABLE == 1 && !wf.IsDeleted)
|
|
|
|
|
.Select((wf, rela, prj,
|
|
|
|
|
arela, act, srela, sact)
|
|
|
|
|
=> new { Project = prj, ARela = arela, Act = act, SRela = srela, SAct = sact }).ToList();
|
|
|
|
|
|
|
|
|
|
var statusSKUList = _statusSkuBaseInfoRepository.AsQueryable().Filter(null, true)
|
|
|
|
|
.Where(a => !a.IsDeleted && a.IS_ENABLE == 1 && a.TenantId == long.Parse(tenantId)).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
statusList = list.GroupBy(a
|
|
|
|
|
=> a.Project.PK_ID)
|
|
|
|
|
.Select(a =>
|
|
|
|
|
{
|
|
|
|
|
var currList = a.ToList();
|
|
|
|
|
|
|
|
|
|
var prjDto = a.FirstOrDefault().Project.Adapt<ServiceProjectWithStatusDto>();
|
|
|
|
|
/*
|
|
|
|
|
currList.GroupBy(b=>b.Act.PK_ID)
|
|
|
|
|
.Select(c => {
|
|
|
|
|
var currActList = c.ToList();
|
|
|
|
|
|
|
|
|
|
var actDto = c.FirstOrDefault().Act;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
var actList = currList
|
|
|
|
|
.OrderBy(b=>b.ARela.SORT_NO)
|
|
|
|
|
.Select(b
|
|
|
|
|
=>
|
|
|
|
|
{
|
|
|
|
|
b.
|
|
|
|
|
})
|
|
|
|
|
.Distinct().ToList();
|
|
|
|
|
|
|
|
|
|
b.Act.Adapt<ServiceWorkFlowActivitiesDto>()
|
|
|
|
|
|
|
|
|
|
if (currList.Any(b=>b.SAct != null))
|
|
|
|
|
{
|
|
|
|
|
var subList = currList
|
|
|
|
|
.OrderBy(b => b.SRela.SORT_NO)
|
|
|
|
|
.Where(b =>
|
|
|
|
|
b.SAct != null)
|
|
|
|
|
.Select(b =>
|
|
|
|
|
{
|
|
|
|
|
return new { SRela = b.SRela, SAct = b.SAct };
|
|
|
|
|
})
|
|
|
|
|
.Distinct().ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prjDto.statusList = actList.GroupJoin(statusSKUList, l => l.STATUS_SKU_ID,
|
|
|
|
|
r => r.PK_ID, (l, r) => {
|
|
|
|
|
ServiceProjectStatusDto statusDto = new ServiceProjectStatusDto();
|
|
|
|
|
|
|
|
|
|
var sku = r.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if(sku != null) {
|
|
|
|
|
statusDto = sku.Adapt<ServiceProjectStatusDto>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
statusDto.ShowName = l.SHOW_NAME;
|
|
|
|
|
statusDto.ShowSortNo =
|
|
|
|
|
});
|
|
|
|
|
*/
|
|
|
|
|
return prjDto;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
await _cache.SetAsync($"{CONST_CACHE_ENABLE_PROJECT_STATUS}_{tenantId}", statusList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return statusList;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private void CreateCacheInfo(string tenantId)
|
|
|
|
|
{
|
|
|
|
|
var statusSKUList = _statusSkuBaseInfoRepository.AsQueryable().Filter(null, true)
|
|
|
|
|
.Where(a => !a.IsDeleted && a.IS_ENABLE == 1 && a.TenantId == long.Parse(tenantId)).ToList();
|
|
|
|
|
|
|
|
|
|
/* 读取当前租户可用的已发布的流程详情,并写入缓存。
|
|
|
|
|
*
|
|
|
|
|
1、流程关联服务项目。
|
|
|
|
|
2、流程关联流程活动。
|
|
|
|
|
3、流程关联流程活动的子活动。
|
|
|
|
|
4、活动关联状态。
|
|
|
|
|
5、活动关联触发器。
|
|
|
|
|
6、写入缓存。
|
|
|
|
|
*/
|
|
|
|
|
var list = _serviceWorkFlowBaseRepository.AsQueryable().Filter(null, true)
|
|
|
|
|
.InnerJoin<ServiceWorkFlowProjectRelation>((wf, rela)
|
|
|
|
|
=> wf.PK_ID == rela.SERVICE_WORKFLOW_ID && wf.RELEASE_VERSION == rela.WF_VERSION)
|
|
|
|
|
.InnerJoin<ServiceProjectBaseInfo>((wf, rela, prj)
|
|
|
|
|
=> rela.SERVICE_PROJECT_ID == prj.PK_ID)
|
|
|
|
|
.InnerJoin<ServiceWorkFlowActivitiesRelation>((wf, rela, prj,
|
|
|
|
|
arela)
|
|
|
|
|
=> wf.PK_ID == arela.SERVICE_WORKFLOW_ID && wf.RELEASE_VERSION == arela.WF_VERSION)
|
|
|
|
|
.InnerJoin<ServiceWorkFlowActivitiesInfo>((wf, rela, prj,
|
|
|
|
|
arela, act)
|
|
|
|
|
=> arela.SERVICE_ACTIVITIES_ID == act.PK_ID)
|
|
|
|
|
.LeftJoin<ServiceWorkFlowActivitiesSubRelation>((wf, rela, prj,
|
|
|
|
|
arela, act, srela)
|
|
|
|
|
=> wf.PK_ID == srela.SERVICE_WORKFLOW_ID && wf.RELEASE_VERSION == srela.WF_VERSION)
|
|
|
|
|
.LeftJoin<ServiceWorkFlowActivitiesInfo>((wf, rela, prj,
|
|
|
|
|
arela, act, srela, sact)
|
|
|
|
|
=> srela.SERVICE_ACTIVITIES_ID == act.PK_ID)
|
|
|
|
|
.Where((wf, rela, prj,
|
|
|
|
|
arela, act, srela, sact)
|
|
|
|
|
=> !string.IsNullOrWhiteSpace(wf.RELEASE_VERSION) && wf.BELONG_TENANT_ID == long.Parse(tenantId)
|
|
|
|
|
&& wf.IS_ENABLE == 1 && !wf.IsDeleted)
|
|
|
|
|
.Select((wf, rela, prj,
|
|
|
|
|
arela, act, srela, sact)
|
|
|
|
|
=> new { WF = wf,Project = prj, ARela = arela, Act = act, SRela = srela, SAct = sact }).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var statusList = list.GroupBy(a
|
|
|
|
|
=> a.Project.PK_ID)
|
|
|
|
|
.Select(a =>
|
|
|
|
|
{
|
|
|
|
|
var currList = a.ToList();
|
|
|
|
|
|
|
|
|
|
var wf = a.FirstOrDefault().WF;
|
|
|
|
|
var project = a.FirstOrDefault().Project;
|
|
|
|
|
|
|
|
|
|
ServiceProjectWithStatusDto baseDto = new ServiceProjectWithStatusDto {
|
|
|
|
|
ProjectPKId = project.PK_ID,
|
|
|
|
|
ProjectCode = project.SERVICE_PROJECT_CODE,
|
|
|
|
|
ProjectName = project.SERVICE_PROJECT_NAME,
|
|
|
|
|
SortNo = project.SORT_NO,
|
|
|
|
|
WFPKId = wf.PK_ID,
|
|
|
|
|
WFCode = wf.SERVICE_WORKFLOW_CODE,
|
|
|
|
|
ReleaseVersion = wf.RELEASE_VERSION,
|
|
|
|
|
ReleaseDate = wf.PUBLISH_DATE.Value,
|
|
|
|
|
StatusList = new List<ServiceProjectStatusDto>()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
baseDto.StatusList = currList
|
|
|
|
|
.GroupBy(b => b.Act.PK_ID)
|
|
|
|
|
.Select(c => {
|
|
|
|
|
var currActList = c.ToList();
|
|
|
|
|
|
|
|
|
|
var act = c.FirstOrDefault().Act;
|
|
|
|
|
|
|
|
|
|
var dto = new ServiceProjectStatusDto();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return dto;
|
|
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
return baseDto;
|
|
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|