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/StatusTriggerBaseService.cs

909 lines
35 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Furion.DependencyInjection;
using Furion.DistributedIDGenerator;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Furion.JsonSerialization;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Myshipping.Application.Entity;
using Myshipping.Application.Helper;
using Myshipping.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Myshipping.Application
{
/// <summary>
/// 触发器管理
/// </summary>
[ApiDescriptionSettings("Application", Name = "StatusTriggerBase", Order = 20)]
public class StatusTriggerBaseService: IStatusTriggerBaseService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<StatusTriggerBaseInfo> _statusTriggerBaseInfoRepository;
private readonly SqlSugarRepository<StatusTriggerConditionInfo> _statusTriggerConditionInfoRepository;
private readonly SqlSugarRepository<StatusTriggerConditionNextActInfo> _statusTriggerConditionNextActInfoRepository;
private readonly ILogger<StatusTriggerBaseService> _logger;
public StatusTriggerBaseService(SqlSugarRepository<StatusTriggerBaseInfo> statusTriggerBaseInfoRepository,
SqlSugarRepository<StatusTriggerConditionInfo> statusTriggerConditionInfoRepository,
SqlSugarRepository<StatusTriggerConditionNextActInfo> statusTriggerConditionNextActInfoRepository,
ILogger<StatusTriggerBaseService> logger)
{
_statusTriggerBaseInfoRepository = statusTriggerBaseInfoRepository;
_statusTriggerConditionInfoRepository = statusTriggerConditionInfoRepository;
_statusTriggerConditionNextActInfoRepository = statusTriggerConditionNextActInfoRepository;
_logger = logger;
}
/// <summary>
/// 保存
/// </summary>
/// <param name="info">状态触发器详情</param>
/// <returns>返回回执</returns>
[HttpPost("/StatusTriggerBase/Save")]
public async Task<TaskManageOrderResultDto> Save([FromBody] StatusTriggerBaseDto 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;
}
/// <summary>
/// 保存并启用
/// </summary>
/// <param name="info">状态触发器详情</param>
/// <returns>返回回执</returns>
[HttpPost("/StatusTriggerBase/SaveAndEnable")]
public async Task<TaskManageOrderResultDto> SaveAndEnable([FromBody] StatusTriggerBaseDto 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;
}
#region 保存内部方法
/// <summary>
/// 保存内部方法
/// </summary>
/// <param name="info">服务流程触发器详情</param>
/// <param name="isSetEnable">是否启用</param>
/// <returns>返回派车Id</returns>
[SqlSugarUnitOfWork]
private async Task<string> InnerSave(StatusTriggerBaseDto info, bool isSetEnable = false)
{
StatusTriggerBaseInfo entity = info.Adapt<StatusTriggerBaseInfo>();
if (isSetEnable)
{
if (string.IsNullOrWhiteSpace(entity.STATUS_TRIGGER_CODE) || string.IsNullOrWhiteSpace(entity.STATUS_TRIGGER_NAME))
{
throw Oops.Oh($"触发器代码或名称不能为空", typeof(InvalidOperationException));
}
entity.IS_ENABLE = 1;
}
if (entity == null)
throw Oops.Oh($"服务流程触发器不能为空", typeof(InvalidOperationException));
_logger.LogInformation($"服务流程触发器保存 JSON={JSON.Serialize(entity)} user={UserManager.UserId}");
if (string.IsNullOrWhiteSpace(info.StatusTriggerCode))
{
string pkId = !string.IsNullOrWhiteSpace(info.PKId) ? info.PKId : string.Empty;
if (_statusTriggerBaseInfoRepository.AsQueryable().Any(a => a.STATUS_TRIGGER_CODE.Equals(info.StatusTriggerCode) && a.PK_ID != pkId))
{
_logger.LogInformation($"服务流程触发器代码已存在不能重复保存");
throw Oops.Oh($"服务流程触发器代码已存在不能重复保存", typeof(InvalidOperationException));
}
}
if (string.IsNullOrWhiteSpace(entity.PK_ID))
{
entity.PK_ID = IDGen.NextID().ToString();
_statusTriggerBaseInfoRepository.Insert(entity);
if(info.ConditionList != null && info.ConditionList.Count > 0)
{
info.ConditionList.ForEach(async cd => {
var conditionModel = cd.Adapt<StatusTriggerConditionInfo>();
conditionModel.PK_ID = IDGen.NextID().ToString();
conditionModel.P_ID = entity.PK_ID;
conditionModel.CreatedTime = DateTime.Now;
conditionModel.CreatedUserId = UserManager.UserId;
conditionModel.CreatedUserName = UserManager.Name;
conditionModel.IsDeleted = false;
await _statusTriggerConditionInfoRepository.InsertAsync(conditionModel);
if(cd.NextActionType == StatusTriggerNextActionTypeEnum.TRIGGER_ACTIVITIES.ToString())
{
if(cd.NextActList != null && cd.NextActList.Count > 0)
{
//写入需要触发的其他流程活动
cd.NextActList.ForEach(async nxt => {
var nextModel = new StatusTriggerConditionNextActInfo {
PK_ID = IDGen.NextID().ToString(),
CONDITION_ID = conditionModel.PK_ID,
TRIGGER_ID = entity.PK_ID,
SERVICE_ACTIVITIES_ID = nxt.ServiceActivitiesID,
SHOW_NAME = nxt.ShowName,
};
await _statusTriggerConditionNextActInfoRepository.InsertAsync(nextModel);
});
}
}
});
}
}
else
{
var model = InnerGetInfo(entity.PK_ID);
_logger.LogInformation($"更新服务流程触发器前,获取原始记录 JSON={JSON.Serialize(model)}");
//ValidateServiceStatus(entity, OperateTypeEnum.Save);
entity.UpdatedTime = DateTime.Now;
entity.UpdatedUserId = UserManager.UserId;
entity.UpdatedUserName = UserManager.Name;
await _statusTriggerBaseInfoRepository.AsUpdateable(entity).IgnoreColumns(it => new
{
it.TenantId,
it.TenantName,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName,
it.IsDeleted,
}).ExecuteCommandAsync();
_statusTriggerConditionInfoRepository.EntityContext.Deleteable<StatusTriggerConditionInfo>()
.EnableQueryFilter().Where(a => a.P_ID == entity.PK_ID).ExecuteCommand();
_statusTriggerConditionInfoRepository.EntityContext.Deleteable<StatusTriggerConditionNextActInfo>()
.EnableQueryFilter().Where(a => a.TRIGGER_ID == entity.PK_ID).ExecuteCommand();
if (info.ConditionList != null && info.ConditionList.Count > 0)
{
info.ConditionList.ForEach(async cd => {
var conditionModel = cd.Adapt<StatusTriggerConditionInfo>();
conditionModel.PK_ID = IDGen.NextID().ToString();
conditionModel.P_ID = entity.PK_ID;
conditionModel.CreatedTime = DateTime.Now;
conditionModel.CreatedUserId = UserManager.UserId;
conditionModel.CreatedUserName = UserManager.Name;
conditionModel.IsDeleted = false;
await _statusTriggerConditionInfoRepository.InsertAsync(conditionModel);
if (cd.NextActionType == StatusTriggerNextActionTypeEnum.TRIGGER_ACTIVITIES.ToString())
{
if (cd.NextActList != null && cd.NextActList.Count > 0)
{
//写入需要触发的其他流程活动
cd.NextActList.ForEach(async nxt => {
var nextModel = new StatusTriggerConditionNextActInfo
{
PK_ID = IDGen.NextID().ToString(),
CONDITION_ID = conditionModel.PK_ID,
TRIGGER_ID = entity.PK_ID,
SERVICE_ACTIVITIES_ID = nxt.ServiceActivitiesID,
SHOW_NAME = nxt.ShowName,
};
await _statusTriggerConditionNextActInfoRepository.InsertAsync(nextModel);
});
}
}
});
}
}
return entity.PK_ID;
}
#endregion
#region 单票查询
/// <summary>
/// 单票查询
/// </summary>
/// <param name="pkId">触发器主键</param>
private StatusTriggerBaseInfo InnerGetInfo(string pkId)
{
if (string.IsNullOrWhiteSpace(pkId))
{
throw Oops.Oh($"触发器主键不能为空", typeof(InvalidOperationException));
}
var model = _statusTriggerBaseInfoRepository.AsQueryable().First(a => a.PK_ID == pkId);
if (model == null)
throw Oops.Oh($"触发器获取失败,触发器信息不存在或已作废", typeof(InvalidOperationException));
return model;
}
#endregion
/// <summary>
/// 启用
/// </summary>
/// <param name="pkIds">状态触发器主键数组</param>
/// <returns>返回回执</returns>
[HttpPost("/StatusTriggerBase/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 = _statusTriggerBaseInfoRepository.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(InnerExcuteStatusTrigger(pr, OperateTypeEnum.SetEnable).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;
}
#region 处理服务项目内部方法
/// <summary>
/// 处理服务项目内部方法
/// </summary>
/// <param name="model">服务项目详情</param>
/// <param name="opTypeEnum">操作类型</param>
/// <returns>返回回执</returns>
private async Task<TaskManageOrderResultDto> InnerExcuteStatusTrigger(StatusTriggerBaseInfo model, OperateTypeEnum opTypeEnum)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
result.bno = model?.STATUS_TRIGGER_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)
{
if (string.IsNullOrWhiteSpace(model.STATUS_TRIGGER_CODE) || string.IsNullOrWhiteSpace(model.STATUS_TRIGGER_NAME))
throw Oops.Oh($"触发器代码或名称不能为空", typeof(InvalidOperationException));
model.IS_ENABLE = 1;
await _statusTriggerBaseInfoRepository.AsUpdateable(model).UpdateColumns(it => new
{
it.IS_ENABLE,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync();
}
else if (opTypeEnum == OperateTypeEnum.SetUnEnable)
{
//ValidateServiceProject(model, opTypeEnum);
model.IS_ENABLE = 0;
await _statusTriggerBaseInfoRepository.AsUpdateable(model).UpdateColumns(it => new
{
it.IS_ENABLE,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync();
}
else if (opTypeEnum == OperateTypeEnum.Delete)
{
//ValidateServiceProject(model, opTypeEnum);
model.IsDeleted = true;
await _statusTriggerBaseInfoRepository.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("/StatusTriggerBase/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 = _statusTriggerBaseInfoRepository.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(InnerExcuteStatusTrigger(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("/StatusTriggerBase/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 = _statusTriggerBaseInfoRepository.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(InnerExcuteStatusTrigger(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("/StatusTriggerBase/GetInfo")]
public async Task<TaskManageOrderResultDto> GetInfo([FromQuery] string pkId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var model = InnerGetInfo(pkId);
var showModel = model.Adapt<StatusTriggerBaseShowDto>();
var list = _statusTriggerConditionInfoRepository.AsQueryable().Filter(null, true)
.LeftJoin<StatusTriggerConditionNextActInfo>((cod, nxt) =>
cod.PK_ID == nxt.CONDITION_ID)
.Where((cod, nxt) => cod.P_ID == showModel.PKId)
.Select((cod, nxt) => new { Cod = cod, Next = nxt })
.ToList();
if (list.Count > 0)
{
showModel.ConditionList = list.GroupBy(a => a.Cod.PK_ID)
.Select(a => {
var currList = a.ToList();
var codDto = currList.FirstOrDefault().Cod.Adapt<StatusTriggerConditionDto>();
if(currList.Any(b=>b.Next != null))
codDto.NextActList = currList.Select(b=>b.Next).ToList()
.Adapt<List<StatusTriggerConditionNextActDto>>();
return codDto;
}).ToList();
}
result.succ = true;
result.ext = showModel;
}
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("/StatusTriggerBase/QueryList")]
public async Task<TaskManageOrderResultDto> QueryList([FromQuery] string queryItem, [FromQuery] int topNum = 15)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var list = await _statusTriggerBaseInfoRepository.AsQueryable().Where(a =>
a.IS_ENABLE == 1 && !a.IsDeleted && (string.IsNullOrWhiteSpace(queryItem) || (a.STATUS_TRIGGER_CODE.Contains(queryItem) || a.STATUS_TRIGGER_NAME.Contains(queryItem))))
.Take(topNum).ToListAsync();
result.succ = true;
result.ext = list.Adapt<List<StatusTriggerBaseDto>>();
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"检索状态触发器列表异常,原因:{ex.Message}";
}
return result;
}
/// <summary>
/// 状态触发器台账查询
/// </summary>
/// <param name="QuerySearch">状态触发器台账查询请求</param>
/// <returns>返回结果</returns>
[HttpPost("/StatusTriggerBase/GetPage")]
public async Task<SqlSugarPagedList<StatusTriggerBasePageDto>> GetPageAsync([FromBody] QueryStatusTriggerBaseDto 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<StatusTriggerBasePageDto, StatusTriggerBaseInfo>(QuerySearch.SortField);
var entities = await _statusTriggerBaseInfoRepository.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.StatusTriggerName), t => t.STATUS_TRIGGER_NAME.Contains(QuerySearch.StatusTriggerName) ||
t.STATUS_TRIGGER_CODE.Contains(QuerySearch.StatusTriggerName))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.StatusTriggerNote), t => t.STATUS_TRIGGER_NOTE.Contains(QuerySearch.StatusTriggerNote))
.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<StatusTriggerBasePageDto>>();
}
/// <summary>
/// 获取状态触发器操作类型列表
/// </summary>
/// <returns>返回回执</returns>
[HttpGet("/StatusTriggerBase/GetTriggerOperTypeList")]
public async Task<TaskManageOrderResultDto> GetTriggerOperTypeList()
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var dict = EnumUtil.GetEnumDictionaryWithKey(typeof(StatusTriggerOperTypeEnum));
result.succ = true;
if (dict.Count > 0)
{
result.ext = dict.Select(a => {
var s = a.Value;
bool isShowDays = false;
if (Regex.IsMatch(s, "\\#DAYS\\#"))
{
s = Regex.Replace(s, "\\#DAYS\\#", "");
isShowDays = true;
}
if (s.IndexOf(",") >= 0)
{
s = s.Substring(0, s.IndexOf(","));
}
var model = new TriggerOperTypeDto {
Code = a.Key,
Name = s,
IsShowDays = isShowDays
};
return model;
}).ToList();
}
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"保存服务项目异常,原因:{ex.Message}";
}
return result;
}
/// <summary>
/// 获取状态触发器触发动作列表
/// </summary>
/// <returns>返回回执</returns>
[HttpGet("/StatusTriggerBase/GetTriggerNextActionTypeList")]
public async Task<TaskManageOrderResultDto> GetTriggerNextActionTypeList()
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var dict = EnumUtil.GetEnumDictionaryWithKey(typeof(StatusTriggerNextActionTypeEnum));
result.succ = true;
if (dict.Count > 0)
{
result.ext = dict.Select(a => {
var s = a.Value;
bool isShowActivities = false;
if (Regex.IsMatch(s, "\\#SHOWACTS\\#"))
{
s = Regex.Replace(s, "\\#SHOWACTS\\#", "");
isShowActivities = true;
}
if (s.IndexOf(",") >= 0)
{
s = s.Substring(0, s.IndexOf(","));
}
var model = new TriggerNextActionTypeDto
{
Code = a.Key,
Name = s,
IsShowActivities = isShowActivities
};
return model;
}).ToList();
}
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"保存服务项目异常,原因:{ex.Message}";
}
return result;
}
/// <summary>
/// 生成LIQUID表达式
/// </summary>
/// <param name="info">状态触发器条件详情</param>
/// <returns>返回回执</returns>
[HttpPost("/StatusTriggerBase/CreateLiquidExpression")]
public async Task<TaskManageOrderResultDto> CreateLiquidExpression([FromBody] StatusTriggerConditionDto info)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
if(string.IsNullOrWhiteSpace(info.ServiceActivitiesID))
{
_logger.LogInformation("服务活动不能为空");
throw Oops.Oh($"服务活动不能为空", typeof(InvalidOperationException));
}
if (string.IsNullOrWhiteSpace(info.OperType))
{
_logger.LogInformation("操作类型不能为空");
throw Oops.Oh($"操作类型不能为空", typeof(InvalidOperationException));
}
if (string.IsNullOrWhiteSpace(info.NextActionType))
{
_logger.LogInformation("触发类型不能为空");
throw Oops.Oh($"触发类型不能为空", typeof(InvalidOperationException));
}
string s = string.Empty;
s += "{{ if isyield "+ GetLiquidOperator(info.OperType) + " 1 }}";
if(info.NextActionType.Equals(StatusTriggerNextActionTypeEnum.TRIGGER_ACTIVITIES.ToString(),
StringComparison.OrdinalIgnoreCase))
{
s += " EXEC_ACT ";
}
else
{
s += " SEND_MSG ";
}
s += "{{ end }}";
result.succ = true;
result.ext = s;
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"保存服务项目异常,原因:{ex.Message}";
}
return result;
}
private string GetLiquidOperator(string code)
{
var dict = EnumUtil.GetEnumDictionaryWithKey(typeof(StatusTriggerOperTypeEnum));
if (dict.Keys.Any(a=>a.Equals(code,StringComparison.OrdinalIgnoreCase)))
{
var s = dict[code];
return s.Split(new char[] { ',' }).LastOrDefault();
}
return String.Empty;
}
/// <summary>
/// 测试LIQUID表达式
/// </summary>
/// <param name="info">状态触发器条件详情</param>
/// <param name="liquidExpress">LIQUID表达式</param>
/// <returns>返回回执</returns>
[HttpPost("/StatusTriggerBase/TestLiquidExpression")]
public async Task<TaskManageOrderResultDto> TestLiquidExpression(StatusTriggerConditionDto info, string liquidExpress)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"保存服务项目异常,原因:{ex.Message}";
}
return result;
}
}
}