wet 1 year ago
commit 3f94bb24c7

@ -45,6 +45,11 @@ namespace Myshipping.Application.Entity
/// </summary>
public string RELEASE_VERSION { get; set; }
/// <summary>
/// 当前编辑版本,发布后版本被清除
/// </summary>
public string DEVELOP_VERSION { get; set; }
/// <summary>
/// 是否启用 1-启用 0-未启用
/// </summary>

@ -23,7 +23,7 @@ namespace Myshipping.Application.Entity
/// <summary>
/// 服务流程主键
/// </summary>
public string SERVICE_WORKFLOW_ID { get; set; }
public string SERVICE_WF_ID { get; set; }
/// <summary>
/// 发布版本

@ -86,6 +86,11 @@ namespace Myshipping.Application
/// </summary>
public string ReleaseVersion { get; set; }
/// <summary>
/// 当前编辑版本
/// </summary>
public string DevelopVersion { get; set; }
/// <summary>
/// 发布人
/// </summary>

@ -112,6 +112,7 @@ namespace Myshipping.Application
.Map(dest => dest.UpdatedUserId, src => src.UpdatedUserId)
.Map(dest => dest.UpdatedUserName, src => src.UpdatedUserName)
.Map(dest => dest.ReleaseVersion, src => src.RELEASE_VERSION)
.Map(dest => dest.DevelopVersion, src => src.DEVELOP_VERSION)
.Map(dest => dest.IsEnable, src => src.IS_ENABLE)
.Map(dest => dest.BelongTenantId, src => src.BELONG_TENANT_ID)
.Map(dest => dest.BelongTenantName, src => src.BELONG_TENANT_NAME)

@ -13,6 +13,7 @@ using Myshipping.Core;
using Myshipping.Core.Entity;
using MySqlX.XDevAPI.Common;
using SqlSugar;
using StackExchange.Profiling.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
@ -200,11 +201,48 @@ namespace Myshipping.Application
entity.BELONG_TENANT_NAME = UserManager.TENANT_NAME;
}
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));
}
if (info.StatusSkuList.Any(a => a.SortNo == 0))
throw Oops.Oh($"状态必需指定大于零的顺序号", typeof(InvalidOperationException));
if (info.StatusSkuList.GroupBy(a => a.SortNo).Any(a => a.ToList().Count > 1))
throw Oops.Oh($"状态顺序号不能重复", typeof(InvalidOperationException));
info.StatusSkuList = info.StatusSkuList.OrderBy(a => a.SortNo).Select((a, idx) =>
{
if (a.SubList == null || a.SubList.Count == 0)
{
a.SortNo = idx + 1;
return a;
}
a.SortNo = idx + 1;
a.SubList = a.SubList.OrderBy(b => b.SortNo).Select((b, sidx) =>
{
b.SortNo = sidx + 1;
return b;
}).ToList();
return a;
}).ToList();
}
_logger.LogInformation($"服务流程保存 JSON={JSON.Serialize(entity)} user={UserManager.UserId}");
string currVersion = string.Empty;
if (string.IsNullOrWhiteSpace(entity.PK_ID))
{
entity.PK_ID = IDGen.NextID().ToString();
entity.DEVELOP_VERSION = "DEVELOP";
currVersion = entity.DEVELOP_VERSION;
_serviceWorkFlowBaseRepository.Insert(entity);
}
@ -214,13 +252,7 @@ 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);
@ -228,6 +260,19 @@ namespace Myshipping.Application
entity.UpdatedUserId = UserManager.UserId;
entity.UpdatedUserName = UserManager.Name;
if(string.IsNullOrWhiteSpace(model.DEVELOP_VERSION) && !string.IsNullOrWhiteSpace(model.RELEASE_VERSION))
entity.DEVELOP_VERSION = "DEVELOP";
if (info.StatusSkuList != null && info.StatusSkuList.Count > 0)
{
entity.STATUS_NUM = info.StatusSkuList.Sum(a =>
{
if (a.SubList != null)
return a.SubList.Count + 1;
return 1;
});
}
await _serviceWorkFlowBaseRepository.AsUpdateable(entity).IgnoreColumns(it => new
{
it.TenantId,
@ -236,19 +281,27 @@ namespace Myshipping.Application
it.CreatedUserId,
it.CreatedUserName,
it.IsDeleted,
it.RELEASE_VERSION,
it.PUBLISH_DATE,
it.PUBLISH_ER,
it.PUBLISH_NAME,
it.DEVELOP_VERSION,
it.IS_LOCK
}).ExecuteCommandAsync();
currVersion = model.DEVELOP_VERSION;
//批量删除服务流程与服务项目关系(物理删除)
_serviceWorkFlowProjectRelationRepository.EntityContext.Deleteable<ServiceWorkFlowProjectRelation>()
.EnableQueryFilter().Where(a => a.SERVICE_WORKFLOW_ID == entity.PK_ID && a.WF_VERSION == "DEVELOP").ExecuteCommand();
.EnableQueryFilter().Where(a => a.SERVICE_WORKFLOW_ID == entity.PK_ID && a.WF_VERSION == currVersion).ExecuteCommand();
//批量删除服务流程与服务活动关系(物理删除)
_serviceWorkFlowActivitiesRelationRepository.EntityContext.Deleteable<ServiceWorkFlowActivitiesRelation>()
.EnableQueryFilter().Where(a => a.SERVICE_WORKFLOW_ID == entity.PK_ID && a.WF_VERSION == "DEVELOP").ExecuteCommand();
.EnableQueryFilter().Where(a => a.SERVICE_WORKFLOW_ID == entity.PK_ID && a.WF_VERSION == currVersion).ExecuteCommand();
//批量删除服务流程活动与子活动的关系(物理删除)
_serviceWorkFlowActivitiesSubRelationRepository.EntityContext.Deleteable<ServiceWorkFlowActivitiesSubRelation>()
.EnableQueryFilter().Where(a => a.SERVICE_WORKFLOW_ID == entity.PK_ID && a.WF_VERSION == "DEVELOP").ExecuteCommand();
.EnableQueryFilter().Where(a => a.SERVICE_WORKFLOW_ID == entity.PK_ID && a.WF_VERSION == currVersion).ExecuteCommand();
}
//服务流程与服务项目关系
@ -258,7 +311,7 @@ namespace Myshipping.Application
PK_ID = IDGen.NextID().ToString(),
SERVICE_WORKFLOW_ID = entity.PK_ID,
SERVICE_PROJECT_ID = info.ServiceProject.PKId,
WF_VERSION = "DEVELOP"
WF_VERSION = currVersion
};
//插入关系
@ -277,7 +330,7 @@ namespace Myshipping.Application
SORT_NO = sku.SortNo,
IS_CONTAINS_SUB = sku.IsContainsSub,
VAL_TYPE = !string.IsNullOrWhiteSpace(sku.ValType)? sku.ValType: StatusSKUValTypeEnum.DATETIME.ToString(),
WF_VERSION = "DEVELOP"
WF_VERSION = currVersion
};
await _serviceWorkFlowActivitiesRelationRepository.InsertAsync(wfRelationActivities);
@ -293,7 +346,8 @@ namespace Myshipping.Application
SERVICE_ACTIVITIES_ID = sku.PKId,
SUB_SERVICE_ACTIVITIES_ID = sub.PKId,
SORT_NO = sub.SortNo,
WF_VERSION = "DEVELOP"
VAL_TYPE = !string.IsNullOrWhiteSpace(sku.ValType) ? sku.ValType : StatusSKUValTypeEnum.DATETIME.ToString(),
WF_VERSION = currVersion
};
await _serviceWorkFlowActivitiesSubRelationRepository.InsertAsync(wfRelationActivitiesSub);
@ -378,9 +432,20 @@ namespace Myshipping.Application
showModel.ServiceProject = projectInfo.Adapt<ServiceProjectBaseShowDto>();
}
string currVersion = string.Empty;
if(!string.IsNullOrWhiteSpace(model.DEVELOP_VERSION))
{
currVersion = model.DEVELOP_VERSION;
}
else
{
currVersion = model.RELEASE_VERSION;
}
var activitiesList = _serviceWorkFlowActivitiesRelationRepository.AsQueryable()
.LeftJoin<ServiceWorkFlowActivitiesInfo>((rela, act) =>
rela.SERVICE_ACTIVITIES_ID == act.PK_ID && rela.SERVICE_WORKFLOW_ID == pkId)
rela.SERVICE_ACTIVITIES_ID == act.PK_ID && rela.SERVICE_WORKFLOW_ID == pkId && rela.WF_VERSION == currVersion)
.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, IsSub = rela.IS_CONTAINS_SUB,ValType = rela.VAL_TYPE })
@ -404,7 +469,7 @@ namespace Myshipping.Application
var activitiesSubList = _serviceWorkFlowActivitiesSubRelationRepository.AsQueryable()
.LeftJoin<ServiceWorkFlowActivitiesInfo>((rela, act) =>
rela.SUB_SERVICE_ACTIVITIES_ID == act.PK_ID && rela.SERVICE_WORKFLOW_ID == pkId)
rela.SUB_SERVICE_ACTIVITIES_ID == act.PK_ID && rela.SERVICE_WORKFLOW_ID == pkId && rela.WF_VERSION == currVersion)
.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 })
@ -980,7 +1045,7 @@ namespace Myshipping.Application
catch (Exception ex)
{
result.succ = false;
result.msg = $"启用服务项目异常,原因:{ex.Message}";
result.msg = $"执行失败,原因:{ex.Message}";
}
return result;
@ -992,6 +1057,7 @@ namespace Myshipping.Application
/// </summary>
/// <param name="model">服务流程详情</param>
/// <returns>返回回执</returns>
[SqlSugarUnitOfWork]
private async Task<TaskManageOrderResultDto> InnerPublishReleasServiceWF(ServiceWorkFlowBaseInfo model)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
@ -1003,16 +1069,18 @@ namespace Myshipping.Application
if (model == null)
throw Oops.Oh($"服务流程获取失败,服务流程信息不存在或已作废", typeof(InvalidOperationException));
if(string.IsNullOrWhiteSpace(model.DEVELOP_VERSION))
throw Oops.Oh($"服务流程未修改,不需要重复发布", typeof(InvalidOperationException));
var lastReleaseInfo = _serviceWorkFlowReleaseInfoRepository.AsQueryable()
.First(a => a.SERVICE_WORKFLOW_ID == model.PK_ID && a.IS_DEL == 0);
.First(a => a.SERVICE_WF_ID == model.PK_ID && a.IS_DEL == 0);
int currNum = lastReleaseInfo == null ? 1 : lastReleaseInfo.TOTAL_NUM;
ServiceWorkFlowReleaseInfo releaseInfo = new ServiceWorkFlowReleaseInfo
{
PK_ID = IDGen.NextID().ToString(),
SERVICE_WORKFLOW_ID = model.PK_ID,
LAST_PK_ID = lastReleaseInfo.PK_ID,
SERVICE_WF_ID = model.PK_ID,
PUBLISH_DATE = DateTime.Now,
IS_DEL = 0,
PUBLISH_ER = UserManager.UserId,
@ -1020,10 +1088,28 @@ namespace Myshipping.Application
TOTAL_NUM = currNum + 1,
};
if (lastReleaseInfo != null)
releaseInfo.LAST_PK_ID = lastReleaseInfo.PK_ID;
lastReleaseInfo.IS_DEL = 1;
_serviceWorkFlowReleaseInfoRepository.AsUpdateable(lastReleaseInfo).UpdateColumns(it => new
{
it.IS_DEL
}).ExecuteCommand();
//写入发布表
_serviceWorkFlowReleaseInfoRepository.Insert(releaseInfo);
model.RELEASE_VERSION = releaseInfo.RELEASE_VERSION;
releaseInfo = _serviceWorkFlowReleaseInfoRepository.AsQueryable()
.First(a => a.SERVICE_WF_ID == model.PK_ID && a.IS_DEL == 0);
string releaseVersion = releaseInfo.RELEASE_VERSION;
var wfBaseInfo = InnerGetShowInfo(model.PK_ID);
string currVersion = wfBaseInfo.DevelopVersion;
model.RELEASE_VERSION = releaseVersion;
model.UpdatedTime = DateTime.Now;
model.UpdatedUserId = UserManager.UserId;
model.UpdatedUserName = UserManager.Name;
@ -1036,6 +1122,84 @@ namespace Myshipping.Application
it.UpdatedUserName,
}).ExecuteCommandAsync();
//重新写入关系
//服务流程与服务项目关系
if (wfBaseInfo.ServiceProject != null && !string.IsNullOrWhiteSpace(wfBaseInfo.ServiceProject.PKId))
{
var wfRelationProject = new ServiceWorkFlowProjectRelation
{
PK_ID = IDGen.NextID().ToString(),
SERVICE_WORKFLOW_ID = wfBaseInfo.PKId,
SERVICE_PROJECT_ID = wfBaseInfo.ServiceProject.PKId,
WF_VERSION = releaseVersion
};
//插入关系
await _serviceWorkFlowProjectRelationRepository.InsertAsync(wfRelationProject);
}
//服务流程与服务活动关系
if (wfBaseInfo.StatusSkuList != null && wfBaseInfo.StatusSkuList.Count > 0)
{
wfBaseInfo.StatusSkuList.ForEach(async sku =>
{
var wfRelationActivities = new ServiceWorkFlowActivitiesRelation
{
PK_ID = IDGen.NextID().ToString(),
SERVICE_WORKFLOW_ID = wfBaseInfo.PKId,
SERVICE_ACTIVITIES_ID = sku.PKId,
SORT_NO = sku.SortNo,
IS_CONTAINS_SUB = sku.IsContainsSub,
VAL_TYPE = !string.IsNullOrWhiteSpace(sku.ValType) ? sku.ValType : StatusSKUValTypeEnum.DATETIME.ToString(),
WF_VERSION = releaseVersion
};
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 = wfBaseInfo.PKId,
SERVICE_ACTIVITIES_ID = sku.PKId,
SUB_SERVICE_ACTIVITIES_ID = sub.PKId,
SORT_NO = sub.SortNo,
VAL_TYPE = !string.IsNullOrWhiteSpace(sku.ValType) ? sku.ValType : StatusSKUValTypeEnum.DATETIME.ToString(),
WF_VERSION = releaseVersion
};
await _serviceWorkFlowActivitiesSubRelationRepository.InsertAsync(wfRelationActivitiesSub);
});
}
});
}
//批量删除服务流程与服务项目关系(物理删除)
_serviceWorkFlowProjectRelationRepository.EntityContext.Deleteable<ServiceWorkFlowProjectRelation>()
.EnableQueryFilter().Where(a => a.SERVICE_WORKFLOW_ID == model.PK_ID && a.WF_VERSION == currVersion).ExecuteCommand();
//批量删除服务流程与服务活动关系(物理删除)
_serviceWorkFlowActivitiesRelationRepository.EntityContext.Deleteable<ServiceWorkFlowActivitiesRelation>()
.EnableQueryFilter().Where(a => a.SERVICE_WORKFLOW_ID == model.PK_ID && a.WF_VERSION == currVersion).ExecuteCommand();
//批量删除服务流程活动与子活动的关系(物理删除)
_serviceWorkFlowActivitiesSubRelationRepository.EntityContext.Deleteable<ServiceWorkFlowActivitiesSubRelation>()
.EnableQueryFilter().Where(a => a.SERVICE_WORKFLOW_ID == model.PK_ID && a.WF_VERSION == currVersion).ExecuteCommand();
var updateModel = _serviceWorkFlowBaseRepository.FirstOrDefault(a => a.PK_ID == model.PK_ID);
updateModel.DEVELOP_VERSION = null;
await _serviceWorkFlowBaseRepository.AsUpdateable(updateModel).UpdateColumns(it => new
{
it.DEVELOP_VERSION,
}).ExecuteCommandAsync();
result.succ = true;
result.msg = "发布成功";
@ -1043,7 +1207,7 @@ namespace Myshipping.Application
catch (Exception ex)
{
result.succ = false;
result.msg = $"执行启用异常,原因:{ex.Message}";
result.msg = $"执行失败,原因:{ex.Message}";
}
return result;

Loading…
Cancel
Save