修改触发器编辑

optimize
jianghaiqing 1 year ago
parent 40e2f684a7
commit ec1841d2e2

@ -1,6 +1,8 @@
using Furion.DependencyInjection; using Furion.DependencyInjection;
using Furion.DistributedIDGenerator;
using Furion.DynamicApiController; using Furion.DynamicApiController;
using Furion.FriendlyException; using Furion.FriendlyException;
using Furion.JsonSerialization;
using Mapster; using Mapster;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -47,16 +49,16 @@ namespace Myshipping.Application
try try
{ {
//var id = await InnerSave(info); var id = await InnerSave(info);
result.succ = true; result.succ = true;
result.msg = "保存成功"; result.msg = "保存成功";
//result.ext = id; result.ext = id;
} }
catch (Exception ex) catch (Exception ex)
{ {
result.succ = false; result.succ = false;
result.msg = $"保存服务项目异常,原因:{ex.Message}"; result.msg = $"保存触发器异常,原因:{ex.Message}";
} }
return result; return result;
@ -73,21 +75,119 @@ namespace Myshipping.Application
try try
{ {
//var id = await InnerSave(info); var id = await InnerSave(info);
result.succ = true; result.succ = true;
result.msg = "保存成功"; result.msg = "保存成功";
//result.ext = id; result.ext = id;
} }
catch (Exception ex) catch (Exception ex)
{ {
result.succ = false; result.succ = false;
result.msg = $"保存服务项目异常,原因:{ex.Message}"; result.msg = $"保存触发器异常,原因:{ex.Message}";
} }
return result; 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)
{
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();
_statusTriggerBaseInfoRepository.Insert(entity);
if(info.ConditionList != null && info.ConditionList.Count > 0)
{
info.ConditionList.ForEach(async cd => {
var conditionModel = cd.Adapt<StatusTriggerConditionInfo>();
await _statusTriggerConditionInfoRepository.InsertAsync(conditionModel);
});
}
}
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();
if (info.ConditionList != null && info.ConditionList.Count > 0)
{
_statusTriggerConditionInfoRepository.EntityContext.Deleteable<StatusTriggerConditionInfo>()
.EnableQueryFilter().Where(a => a.P_ID == entity.PK_ID).ExecuteCommand();
info.ConditionList.ForEach(async cd => {
var conditionModel = cd.Adapt<StatusTriggerConditionInfo>();
await _statusTriggerConditionInfoRepository.InsertAsync(conditionModel);
});
}
}
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>
/// 启用 /// 启用
/// </summary> /// </summary>
@ -99,20 +199,143 @@ namespace Myshipping.Application
try try
{ {
//var id = await InnerSave(info); 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(InnerExcuteServiceProject(pr, OperateTypeEnum.SetEnable).GetAwaiter().GetResult());
});
result.succ = true; result.succ = true;
result.msg = "保存成功"; result.msg = rltList.FirstOrDefault().msg;
//result.ext = id;
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) catch (Exception ex)
{ {
result.succ = false; result.succ = false;
result.msg = $"保存服务项目异常,原因:{ex.Message}"; result.msg = $"启用触发器异常,原因:{ex.Message}";
}
return result;
}
#region 处理服务项目内部方法
/// <summary>
/// 处理服务项目内部方法
/// </summary>
/// <param name="model">服务项目详情</param>
/// <param name="opTypeEnum">操作类型</param>
/// <returns>返回回执</returns>
private async Task<TaskManageOrderResultDto> InnerExcuteServiceProject(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)
{
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; return result;
} }
#endregion
/// <summary> /// <summary>
/// 取消启用 /// 取消启用

Loading…
Cancel
Save