|
|
|
@ -26,14 +26,24 @@ namespace Myshipping.Application
|
|
|
|
|
{
|
|
|
|
|
private readonly SqlSugarRepository<ServiceWorkFlowBaseInfo> _serviceWorkFlowBaseRepository;
|
|
|
|
|
private readonly SqlSugarRepository<ServiceWorkFlowActivitiesInfo> _serviceWorkFlowActivitiesInfoRepository;
|
|
|
|
|
private readonly SqlSugarRepository<ServiceWorkFlowProjectRelation> _serviceWorkFlowProjectRelationRepository;
|
|
|
|
|
private readonly SqlSugarRepository<ServiceWorkFlowActivitiesRelation> _serviceWorkFlowActivitiesRelationRepository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly ILogger<ServiceWorkFlowBaseService> _logger;
|
|
|
|
|
public ServiceWorkFlowBaseService(SqlSugarRepository<ServiceWorkFlowBaseInfo> serviceWorkFlowBaseRepository,
|
|
|
|
|
ILogger<StatusSkuBaseService> logger,
|
|
|
|
|
SqlSugarRepository<ServiceWorkFlowActivitiesInfo> serviceWorkFlowActivitiesInfoRepository)
|
|
|
|
|
ILogger<ServiceWorkFlowBaseService> logger,
|
|
|
|
|
SqlSugarRepository<ServiceWorkFlowActivitiesInfo> serviceWorkFlowActivitiesInfoRepository,
|
|
|
|
|
SqlSugarRepository<ServiceWorkFlowProjectRelation> serviceWorkFlowProjectRelationRepository,
|
|
|
|
|
SqlSugarRepository<ServiceWorkFlowActivitiesRelation> serviceWorkFlowActivitiesRelationRepository)
|
|
|
|
|
{
|
|
|
|
|
_serviceWorkFlowBaseRepository = serviceWorkFlowBaseRepository;
|
|
|
|
|
_serviceWorkFlowActivitiesInfoRepository = serviceWorkFlowActivitiesInfoRepository;
|
|
|
|
|
_serviceWorkFlowProjectRelationRepository = serviceWorkFlowProjectRelationRepository;
|
|
|
|
|
_serviceWorkFlowActivitiesRelationRepository = serviceWorkFlowActivitiesRelationRepository;
|
|
|
|
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -63,11 +73,104 @@ namespace Myshipping.Application
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 保存服务流程活动
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存服务流程活动
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info">保存服务流程活动详情</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
[HttpPost("/ServiceWorkFlowBase/SaveWFActivities")]
|
|
|
|
|
public async Task<TaskManageOrderResultDto> SaveWFActivities([FromBody] ServiceWorkFlowActivitiesDto info)
|
|
|
|
|
{
|
|
|
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
1、状态有记录。
|
|
|
|
|
2、同一状态不能有相同的显示名称
|
|
|
|
|
3、已经关联服务流程的,并且已经发布的不能修改内容。(只可以新增)
|
|
|
|
|
*/
|
|
|
|
|
var entity = info.Adapt<ServiceWorkFlowActivitiesInfo>();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(entity.STATUS_SKU_ID))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Oh($"状态不能为空", typeof(InvalidOperationException));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(entity.SHOW_NAME) || entity.SHOW_NAME.Length < 2)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Oh($"状态显示名称不能为空,并且不能少于2个字符", typeof(InvalidOperationException));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//同一状态不能有相同的显示名称
|
|
|
|
|
var checkList = _serviceWorkFlowActivitiesInfoRepository.AsQueryable()
|
|
|
|
|
.Where(a=>a.STATUS_SKU_ID == entity.STATUS_SKU_ID
|
|
|
|
|
&& a.SHOW_NAME == entity.SHOW_NAME && a.PK_ID != entity.PK_ID).ToList();
|
|
|
|
|
|
|
|
|
|
if (checkList.Count > 0)
|
|
|
|
|
throw Oops.Oh($"已存在相同的状态设置,不能保存", typeof(InvalidOperationException));
|
|
|
|
|
|
|
|
|
|
//_logger.LogInformation($"服务项目保存 JSON={JSON.Serialize(entity)} user={UserManager.UserId}");
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(entity.PK_ID))
|
|
|
|
|
{
|
|
|
|
|
entity.PK_ID = IDGen.NextID().ToString();
|
|
|
|
|
|
|
|
|
|
_serviceWorkFlowActivitiesInfoRepository.Insert(entity);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//已经关联服务流程的,并且已经发布的不能修改内容。(只可以新增)
|
|
|
|
|
var wfRelation = _serviceWorkFlowActivitiesRelationRepository.AsQueryable()
|
|
|
|
|
.Where(a=>a.SERVICE_ACTIVITIES_ID == entity.PK_ID)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
if (wfRelation.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var currArg = wfRelation.Select(a=>a.SERVICE_WORKFLOW_ID).Distinct().ToList();
|
|
|
|
|
|
|
|
|
|
if (_serviceWorkFlowBaseRepository.AsQueryable().Any(a => currArg.Any(b => b == a.PK_ID)
|
|
|
|
|
&& (!string.IsNullOrWhiteSpace(a.RELEASE_VERSION) || a.IS_LOCK == 1)))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Oh($"当前状态已关联发布流程,不能保存", typeof(InvalidOperationException));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entity.UpdatedTime = DateTime.Now;
|
|
|
|
|
entity.UpdatedUserId = UserManager.UserId;
|
|
|
|
|
entity.UpdatedUserName = UserManager.Name;
|
|
|
|
|
|
|
|
|
|
await _serviceWorkFlowActivitiesInfoRepository.AsUpdateable(entity).IgnoreColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.TenantId,
|
|
|
|
|
it.TenantName,
|
|
|
|
|
it.CreatedTime,
|
|
|
|
|
it.CreatedUserId,
|
|
|
|
|
it.CreatedUserName,
|
|
|
|
|
it.IsDeleted,
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.succ = true;
|
|
|
|
|
result.msg = "保存成功";
|
|
|
|
|
result.ext = entity.PK_ID;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.succ = false;
|
|
|
|
|
result.msg = $"保存服务流程活动异常,原因:{ex.Message}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 保存内部方法
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存内部方法
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info">服务项目详情</param>
|
|
|
|
|
/// <param name="info">服务流程详情</param>
|
|
|
|
|
/// <param name="isSetEnable">是否启用</param>
|
|
|
|
|
/// <returns>返回派车Id</returns>
|
|
|
|
|
[SqlSugarUnitOfWork]
|
|
|
|
@ -81,9 +184,9 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entity == null)
|
|
|
|
|
throw Oops.Oh($"服务项目不能为空", typeof(InvalidOperationException));
|
|
|
|
|
throw Oops.Oh($"服务流程不能为空", typeof(InvalidOperationException));
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"服务项目保存 JSON={JSON.Serialize(entity)} user={UserManager.UserId}");
|
|
|
|
|
_logger.LogInformation($"服务流程保存 JSON={JSON.Serialize(entity)} user={UserManager.UserId}");
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(entity.PK_ID))
|
|
|
|
|
{
|
|
|
|
@ -96,11 +199,8 @@ namespace Myshipping.Application
|
|
|
|
|
var model = InnerGetInfo(entity.PK_ID);
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"更新状态前,获取原始记录 JSON={JSON.Serialize(model)}");
|
|
|
|
|
|
|
|
|
|
//if (!entity.STATUS_SKU_CODE.Equals(model.STATUS_SKU_CODE, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
//{
|
|
|
|
|
// ValidateServiceProject(entity, true);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
ValidateServiceWorkFlow(entity, true);
|
|
|
|
|
|
|
|
|
|
entity.UpdatedTime = DateTime.Now;
|
|
|
|
|
entity.UpdatedUserId = UserManager.UserId;
|
|
|
|
@ -116,6 +216,41 @@ namespace Myshipping.Application
|
|
|
|
|
it.IsDeleted,
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
//批量删除服务流程与服务项目关系(物理删除)
|
|
|
|
|
_serviceWorkFlowProjectRelationRepository.EntityContext.Deleteable<ServiceWorkFlowProjectRelation>()
|
|
|
|
|
.Where(a => a.SERVICE_WORKFLOW_ID == entity.PK_ID);
|
|
|
|
|
|
|
|
|
|
//批量删除服务流程与服务活动关系(物理删除)
|
|
|
|
|
_serviceWorkFlowActivitiesRelationRepository.EntityContext.Deleteable<ServiceWorkFlowProjectRelation>()
|
|
|
|
|
.Where(a => a.SERVICE_WORKFLOW_ID == entity.PK_ID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//服务流程与服务项目关系
|
|
|
|
|
if (info.ServiceProject != null && !string.IsNullOrWhiteSpace(info.ServiceProject.PKId))
|
|
|
|
|
{
|
|
|
|
|
var wfRelationProject = new ServiceWorkFlowProjectRelation {
|
|
|
|
|
PK_ID = IDGen.NextID().ToString(),
|
|
|
|
|
SERVICE_WORKFLOW_ID = entity.PK_ID,
|
|
|
|
|
SERVICE_PROJECT_ID = info.ServiceProject.PKId,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//插入关系
|
|
|
|
|
await _serviceWorkFlowProjectRelationRepository.InsertAsync(wfRelationProject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//服务流程与服务活动关系
|
|
|
|
|
if (info.StatusSkuList != null && info.StatusSkuList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
info.StatusSkuList.ForEach(async sku =>
|
|
|
|
|
{
|
|
|
|
|
var wfRelationActivities = new ServiceWorkFlowActivitiesRelation {
|
|
|
|
|
PK_ID = IDGen.NextID().ToString(),
|
|
|
|
|
SERVICE_WORKFLOW_ID = entity.PK_ID,
|
|
|
|
|
SERVICE_ACTIVITIES_ID = sku.PKId,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await _serviceWorkFlowActivitiesRelationRepository.InsertAsync();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return entity.PK_ID;
|
|
|
|
@ -129,8 +264,11 @@ namespace Myshipping.Application
|
|
|
|
|
/// <param name="entity">服务项目详情</param>
|
|
|
|
|
/// <param name="isCheckRelation">是否校验关系</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private void ValidateServiceProject(ServiceWorkFlowBaseInfo entity, bool isCheckRelation = false)
|
|
|
|
|
private void ValidateServiceWorkFlow(ServiceWorkFlowBaseInfo entity, bool isCheckRelation = false)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
//if (isCheckRelation && _serviceWorkFlowActivitiesInfoRepository.Any(a => a.STATUS_SKU_ID == entity.PK_ID))
|
|
|
|
|
//{
|
|
|
|
|
// _logger.LogInformation($"当前状态已关联服务流程不能修改");
|
|
|
|
|