You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BookingHeChuan/Myshipping.Application/Service/TrackingSystem/ServiceWorkFlowBaseService.cs

972 lines
38 KiB
C#

using Furion.DependencyInjection;
using Furion.DistributedIDGenerator;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Furion.JsonSerialization;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Extensions.Logging;
using Myshipping.Application.Entity;
using Myshipping.Application.Helper;
using Myshipping.Core;
using Myshipping.Core.Entity;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
/// <summary>
/// 服务流程
/// </summary>
[ApiDescriptionSettings("Application", Name = "ServiceWorkFlowBase", Order = 10)]
public class ServiceWorkFlowBaseService : IServiceWorkFlowBaseService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<ServiceWorkFlowBaseInfo> _serviceWorkFlowBaseRepository;
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<ServiceWorkFlowActivitiesSubRelation> serviceWorkFlowActivitiesSubRelationRepository)
{
_serviceWorkFlowBaseRepository = serviceWorkFlowBaseRepository;
_serviceWorkFlowActivitiesInfoRepository = serviceWorkFlowActivitiesInfoRepository;
_serviceWorkFlowProjectRelationRepository = serviceWorkFlowProjectRelationRepository;
_serviceWorkFlowActivitiesRelationRepository = serviceWorkFlowActivitiesRelationRepository;
_logger = logger;
_serviceWorkFlowActivitiesSubRelationRepository = serviceWorkFlowActivitiesSubRelationRepository;
}
/// <summary>
/// 保存
/// </summary>
/// <param name="info">服务流程详情</param>
/// <returns>返回回执</returns>
[HttpPost("/ServiceWorkFlowBase/Save")]
public async Task<TaskManageOrderResultDto> Save([FromBody] ServiceWorkFlowBaseDto info)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var id = await InnerSave(info);
result.succ = true;
result.msg = "保存成功";
result.ext = id;
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"保存服务项目异常,原因:{ex.Message}";
}
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="isSetEnable">是否启用</param>
/// <returns>返回派车Id</returns>
[SqlSugarUnitOfWork]
private async Task<string> InnerSave(ServiceWorkFlowBaseDto info, bool isSetEnable = false)
{
ServiceWorkFlowBaseInfo entity = info.Adapt<ServiceWorkFlowBaseInfo>();
if (isSetEnable)
{
entity.IS_ENABLE = 1;
}
if (entity == null)
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();
_serviceWorkFlowBaseRepository.Insert(entity);
}
else
{
var model = InnerGetInfo(entity.PK_ID);
_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;
entity.UpdatedUserId = UserManager.UserId;
entity.UpdatedUserName = UserManager.Name;
await _serviceWorkFlowBaseRepository.AsUpdateable(entity).IgnoreColumns(it => new
{
it.TenantId,
it.TenantName,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName,
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);
//批量删除服务流程活动与子活动的关系(物理删除)
_serviceWorkFlowActivitiesSubRelationRepository.EntityContext.Deleteable<ServiceWorkFlowActivitiesSubRelation>()
.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,
IS_CONTAINS_SUB = sku.IsContainsSub
};
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);
});
}
});
}
return entity.PK_ID;
}
#endregion
#region 校验
/// <summary>
/// 校验
/// </summary>
/// <param name="entity">服务流程详情</param>
/// <param name="opTypeEnum">操作类型枚举</param>
/// <returns></returns>
private void ValidateServiceWorkFlow(ServiceWorkFlowBaseInfo entity, OperateTypeEnum opTypeEnum)
{
/*
12
*/
if (opTypeEnum == OperateTypeEnum.Save)
{
if (_serviceWorkFlowProjectRelationRepository.AsQueryable().Any(a => a.SERVICE_PROJECT_ID == entity.PK_ID))
{
throw Oops.Oh($"当前服务项目已关联服务流程,不能修改", typeof(InvalidOperationException));
}
if (entity.SERVICE_WORKFLOW_CODE.Length < 2 || entity.SERVICE_WORKFLOW_NAME.Length < 2)
throw Oops.Oh($"服务流程代码和状态名称不能小于2个字符不能修改", typeof(InvalidOperationException));
}
}
#endregion
#region 单票查询
/// <summary>
/// 单票查询
/// </summary>
/// <param name="pkId">服务流程主键</param>
private ServiceWorkFlowBaseInfo InnerGetInfo(string pkId)
{
if (string.IsNullOrWhiteSpace(pkId))
{
throw Oops.Oh($"状态主键不能为空", typeof(InvalidOperationException));
}
var model = _serviceWorkFlowBaseRepository.AsQueryable().First(a => a.PK_ID == pkId);
if (model == null)
throw Oops.Oh($"状态获取失败,状态信息不存在或已作废", typeof(InvalidOperationException));
return model;
}
#endregion
#region 单票查询显示详情
/// <summary>
/// 单票查询显示详情
/// </summary>
/// <param name="pkId">服务流程主键</param>
private ServiceWorkFlowBaseShowDto InnerGetShowInfo(string pkId)
{
var model = InnerGetInfo(pkId);
var showModel = model.Adapt<ServiceWorkFlowBaseShowDto>();
/*
1
2
*/
var projectInfo = _serviceWorkFlowProjectRelationRepository.AsQueryable()
.LeftJoin<ServiceProjectBaseInfo>((rela, prj) => rela.SERVICE_PROJECT_ID == prj.PK_ID)
.Where(rela => rela.SERVICE_WORKFLOW_ID == pkId)
.Select((rela, prj) => prj).First();
if (projectInfo != null)
{
showModel.ServiceProject = projectInfo.Adapt<ServiceProjectBaseShowDto>();
}
var activitiesList = _serviceWorkFlowActivitiesRelationRepository.AsQueryable()
.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, IsSub = rela.IS_CONTAINS_SUB })
.ToList();
if (activitiesList.Count > 0)
{
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 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();
return l;
}).ToList();
}
return showModel;
}
#endregion
#region 保存并启用
/// <summary>
/// 保存并启用
/// </summary>
/// <param name="info">服务流程详情</param>
/// <returns>返回回执</returns>
public async Task<TaskManageOrderResultDto> SaveAndEnable(ServiceWorkFlowBaseDto info)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var id = await InnerSave(info, true);
result.succ = true;
result.msg = "执行成功";
result.ext = id;
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"保存并启用状态异常,原因:{ex.Message}";
}
return result;
}
#endregion
#region 处理服务流程内部方法
/// <summary>
/// 处理服务流程内部方法
/// </summary>
/// <param name="model">服务流程详情</param>
/// <param name="opTypeEnum">操作类型</param>
/// <returns>返回回执</returns>
private async Task<TaskManageOrderResultDto> InnerExcuteServiceWF(ServiceWorkFlowBaseInfo model, OperateTypeEnum opTypeEnum)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
result.bno = model?.SERVICE_WORKFLOW_NAME;
try
{
if (model == null)
throw Oops.Oh($"服务流程获取失败,服务流程信息不存在或已作废", typeof(InvalidOperationException));
_logger.LogInformation($"更新服务流程前,获取原始记录 JSON={JSON.Serialize(model)}");
model.UpdatedTime = DateTime.Now;
model.UpdatedUserId = UserManager.UserId;
model.UpdatedUserName = UserManager.Name;
if (opTypeEnum == OperateTypeEnum.SetEnable)
{
model.IS_ENABLE = 1;
await _serviceWorkFlowBaseRepository.AsUpdateable(model).UpdateColumns(it => new
{
it.IS_ENABLE,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync();
}
else if (opTypeEnum == OperateTypeEnum.SetUnEnable)
{
ValidateServiceWorkFlow(model, opTypeEnum);
model.IS_ENABLE = 0;
await _serviceWorkFlowBaseRepository.AsUpdateable(model).UpdateColumns(it => new
{
it.IS_ENABLE,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync();
}
else if (opTypeEnum == OperateTypeEnum.Delete)
{
ValidateServiceWorkFlow(model, opTypeEnum);
model.IsDeleted = true;
await _serviceWorkFlowBaseRepository.AsUpdateable(model).UpdateColumns(it => new
{
it.IsDeleted,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync();
}
result.succ = true;
result.msg = "执行成功";
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"执行启用异常,原因:{ex.Message}";
}
return result;
}
#endregion
/// <summary>
/// 启用
/// </summary>
/// <param name="pkIds">服务流程主键数组</param>
/// <returns>返回回执</returns>
[HttpPost("/ServiceWorkFlowBase/SetEnable")]
public async Task<TaskManageOrderResultDto> SetEnable([FromBody]string[] pkIds)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
if (pkIds.Length == 0)
{
throw Oops.Oh($"服务流程主键数组不能为空", typeof(InvalidOperationException));
}
var list = _serviceWorkFlowBaseRepository.AsQueryable()
.Where(a => pkIds.Contains(a.PK_ID)).ToList();
if (list.Count == 0)
throw Oops.Oh($"服务流程获取失败,请服务流程信息是否存在", typeof(InvalidOperationException));
if (list.Count != pkIds.Length)
throw Oops.Oh($"部分服务流程获取失败,请服务流程信息是否存在", typeof(InvalidOperationException));
List<TaskManageOrderResultDto> rltList = new List<TaskManageOrderResultDto>();
list.ForEach(pr => {
rltList.Add(InnerExcuteServiceWF(pr, OperateTypeEnum.SetUnEnable).GetAwaiter().GetResult());
});
result.succ = true;
result.msg = rltList.FirstOrDefault().msg;
result.ext = rltList;
var succ = rltList.Count(x => x.succ);
var fail = rltList.Count(x => !x.succ);
if (succ > 0)
{
result.batchTotal = succ.ToString();
}
else
{
result.batchTotal = "- ";
}
if (fail > 0)
{
result.batchTotal += "/" + fail.ToString();
}
else
{
result.batchTotal += " -";
}
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"启用服务项目异常,原因:{ex.Message}";
}
return result;
}
/// <summary>
/// 取消启用
/// </summary>
/// <param name="pkIds">服务流程主键数组</param>
/// <returns>返回回执</returns>
[HttpPost("/ServiceWorkFlowBase/SetUnEnable")]
public async Task<TaskManageOrderResultDto> SetUnEnable([FromBody]string[] pkIds)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
if (pkIds.Length == 0)
{
throw Oops.Oh($"服务流程主键数组不能为空", typeof(InvalidOperationException));
}
var list = _serviceWorkFlowBaseRepository.AsQueryable()
.Where(a => pkIds.Contains(a.PK_ID)).ToList();
if (list.Count == 0)
throw Oops.Oh($"服务流程获取失败,请服务流程信息是否存在", typeof(InvalidOperationException));
if (list.Count != pkIds.Length)
throw Oops.Oh($"部分服务流程获取失败,请服务流程信息是否存在", typeof(InvalidOperationException));
List<TaskManageOrderResultDto> rltList = new List<TaskManageOrderResultDto>();
list.ForEach(pr => {
rltList.Add(InnerExcuteServiceWF(pr, OperateTypeEnum.SetUnEnable).GetAwaiter().GetResult());
});
result.succ = true;
result.msg = rltList.FirstOrDefault().msg;
result.ext = rltList;
var succ = rltList.Count(x => x.succ);
var fail = rltList.Count(x => !x.succ);
if (succ > 0)
{
result.batchTotal = succ.ToString();
}
else
{
result.batchTotal = "- ";
}
if (fail > 0)
{
result.batchTotal += "/" + fail.ToString();
}
else
{
result.batchTotal += " -";
}
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"启用服务项目异常,原因:{ex.Message}";
}
return result;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="pkIds">服务流程主键</param>
/// <returns>返回回执</returns>
[HttpPost("/ServiceWorkFlowBase/Delete")]
public async Task<TaskManageOrderResultDto> Delete([FromBody]string[] pkIds)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
if (pkIds.Length == 0)
{
throw Oops.Oh($"服务流程主键数组不能为空", typeof(InvalidOperationException));
}
var list = _serviceWorkFlowBaseRepository.AsQueryable()
.Where(a => pkIds.Contains(a.PK_ID)).ToList();
if (list.Count == 0)
throw Oops.Oh($"服务流程获取失败,请服务流程信息是否存在", typeof(InvalidOperationException));
if (list.Count != pkIds.Length)
throw Oops.Oh($"部分服务流程获取失败,请服务流程信息是否存在", typeof(InvalidOperationException));
List<TaskManageOrderResultDto> rltList = new List<TaskManageOrderResultDto>();
list.ForEach(pr => {
rltList.Add(InnerExcuteServiceWF(pr, OperateTypeEnum.Delete).GetAwaiter().GetResult());
});
result.succ = true;
result.msg = rltList.FirstOrDefault().msg;
result.ext = rltList;
var succ = rltList.Count(x => x.succ);
var fail = rltList.Count(x => !x.succ);
if (succ > 0)
{
result.batchTotal = succ.ToString();
}
else
{
result.batchTotal = "- ";
}
if (fail > 0)
{
result.batchTotal += "/" + fail.ToString();
}
else
{
result.batchTotal += " -";
}
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"启用服务项目异常,原因:{ex.Message}";
}
return result;
}
/// <summary>
/// 复制
/// </summary>
/// <param name="pkId">服务流程主键</param>
/// <returns>返回回执</returns>
[HttpGet("/ServiceWorkFlowBase/Copy")]
public async Task<TaskManageOrderResultDto> Copy([FromQuery] string pkId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
/*
*/
var model = InnerGetInfo(pkId);
result.succ = true;
result.msg = "执行成功";
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"执行启用异常,原因:{ex.Message}";
}
return result;
}
/// <summary>
/// 获取服务流程详情
/// </summary>
/// <param name="pkId">服务流程主键</param>
/// <returns>返回回执</returns>
[HttpGet("/ServiceWorkFlowBase/GetInfo")]
public async Task<TaskManageOrderResultDto> GetInfo([FromQuery]string pkId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
result.succ = true;
result.ext = InnerGetShowInfo(pkId);
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"获取服务流程详情异常,原因:{ex.Message}";
}
return result;
}
/// <summary>
/// 检索服务流程列表
/// </summary>
/// <param name="queryItem">检索值</param>
/// <param name="topNum">最大返回行数默认15</param>
/// <returns>返回回执</returns>
[HttpGet("/ServiceWorkFlowBase/QueryList")]
public async Task<TaskManageOrderResultDto> QueryList([FromQuery]string queryItem, [FromQuery] int topNum = 15)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var list = await _serviceWorkFlowBaseRepository.AsQueryable().Where(a =>
a.IS_ENABLE == 1 && !a.IsDeleted && (a.SERVICE_WORKFLOW_CODE.Contains(queryItem) || a.SERVICE_WORKFLOW_NAME.Contains(queryItem)))
.Take(topNum).ToListAsync();
result.succ = true;
result.ext = list.Adapt<List<ServiceWorkFlowBaseDto>>();
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"检索状态列表异常,原因:{ex.Message}";
}
return result;
}
/// <summary>
/// 服务流程台账查询
/// </summary>
/// <param name="QuerySearch">服务流程台账查询请求</param>
/// <returns>返回结果</returns>
[HttpPost("/ServiceWorkFlowBase/GetPage")]
public async Task<SqlSugarPagedList<ServiceWorkFlowBasePageDto>> GetPageAsync([FromBody]QueryServiceWorkFlowBaseDto QuerySearch)
{
//制单日期
DateTime createBegin = DateTime.MinValue;
DateTime createEnd = DateTime.MinValue;
//更新日期
DateTime updateBegin = DateTime.MinValue;
DateTime updateEnd = DateTime.MinValue;
//制单日期
if (!string.IsNullOrWhiteSpace(QuerySearch.CreateBegin))
{
if (!DateTime.TryParse(QuerySearch.CreateBegin, out createBegin))
throw Oops.Oh($"创建起始日期格式错误,{QuerySearch.CreateBegin}");
}
if (!string.IsNullOrWhiteSpace(QuerySearch.CreateEnd))
{
if (!DateTime.TryParse(QuerySearch.CreateEnd, out createEnd))
throw Oops.Oh($"创建结束日期格式错误,{QuerySearch.CreateEnd}");
createEnd = createEnd.AddDays(1);
}
//更新日期
if (!string.IsNullOrWhiteSpace(QuerySearch.UpdateBegin))
{
if (!DateTime.TryParse(QuerySearch.UpdateBegin, out updateBegin))
throw Oops.Oh($"更新起始日期格式错误,{QuerySearch.UpdateBegin}");
}
if (!string.IsNullOrWhiteSpace(QuerySearch.UpdateEnd))
{
if (!DateTime.TryParse(QuerySearch.UpdateEnd, out updateEnd))
throw Oops.Oh($"更新结束日期格式错误,{QuerySearch.UpdateEnd}");
updateEnd = updateEnd.AddDays(1);
}
string entityOrderCol = "CreatedTime";
//这里因为返回给前端的台账数据是DTO所以这里排序时候需要转换成Entity对应的字段
if (!string.IsNullOrWhiteSpace(QuerySearch.SortField))
entityOrderCol = MapsterExtHelper.GetAdaptProperty<BookingTruckDto, BookingTruck>(QuerySearch.SortField);
var entities = await _serviceWorkFlowBaseRepository.AsQueryable()
.WhereIF(createBegin != DateTime.MinValue, t => t.CreatedTime >= createBegin)
.WhereIF(createEnd != DateTime.MinValue, t => t.CreatedTime < createEnd)
.WhereIF(updateBegin != DateTime.MinValue, t => t.UpdatedTime.HasValue && t.UpdatedTime.Value >= updateBegin)
.WhereIF(updateEnd != DateTime.MinValue, t => t.UpdatedTime.HasValue && t.UpdatedTime.Value < updateEnd)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.IsEnable) && QuerySearch.IsEnable == "1", t => t.IS_ENABLE == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.IsEnable) && QuerySearch.IsEnable == "2", t => t.IS_ENABLE == 0)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.ServiceWorkflowName), t => t.SERVICE_WORKFLOW_NAME.Contains(QuerySearch.ServiceWorkflowName) ||
t.SERVICE_WORKFLOW_CODE.Contains(QuerySearch.ServiceWorkflowName))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.ServiceWorkflowNote), t => t.SERVICE_WORKFLOW_NOTE.Contains(QuerySearch.ServiceWorkflowNote))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.CreateUser), t => t.CreatedUserName.Contains(QuerySearch.CreateUser))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.UpdateUser), t => t.UpdatedUserName.Contains(QuerySearch.UpdateUser))
.OrderBy(entityOrderCol + (QuerySearch.descSort ? " asc " : " desc "))
.ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize);
return entities.Adapt<SqlSugarPagedList<ServiceWorkFlowBasePageDto>>();
}
/// <summary>
/// 发布服务流程
/// </summary>
/// <param name="pkIds">服务流程主键数组</param>
/// <returns>返回回执</returns>
[HttpPost("/ServiceWorkFlowBase/PublishRelease")]
public async Task<TaskManageOrderResultDto> PublishRelease([FromBody]string[] pkIds)
{
return new TaskManageOrderResultDto();
}
#region 获取展示服务流程时间轴列表
/// <summary>
/// 获取展示服务流程时间轴列表
/// </summary>
/// <param name="pkId">服务流程主键</param>
/// <returns>返回回执</returns>
[HttpGet("/ServiceWorkFlowBase/GetShowTimeLine")]
public async Task<TaskManageOrderResultDto> GetShowTimeLine([FromQuery] string pkId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var showModel = new ServiceWorkFlowRunDto();
/*
*/
var model = InnerGetShowInfo(pkId);
if(model != null)
{
showModel.PKId = pkId;
if(model.ServiceProject != null)
{
showModel.ServiceProjectName = model.ServiceProject.ServiceProjectName;
showModel.ServiceProjectCode = model.ServiceProject.ServiceProjectCode;
}
if (model.StatusSkuList != null && model.StatusSkuList.Count > 0)
{
//showModel.ActivitiesList = model.StatusSkuList.Select(a => {
//}).ToList();
}
}
result.succ = true;
result.ext = showModel;
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"检索状态列表异常,原因:{ex.Message}";
}
return result;
}
#endregion
}
}