修改服务项目

optimize
jianghaiqing 1 year ago
parent bf3c54aa40
commit c71d002700

@ -46,6 +46,16 @@ namespace Myshipping.Application
/// 派车回写详情 /// 派车回写详情
/// </summary> /// </summary>
[Description("派车回写详情")] [Description("派车回写详情")]
DispatchBackSave DispatchBackSave,
/// <summary>
/// 设定启用
/// </summary>
[Description("设定启用")]
SetEnable,
/// <summary>
/// 设定不启用
/// </summary>
[Description("设定不启用")]
SetUnEnable
} }
} }

@ -29,23 +29,23 @@ namespace Myshipping.Application
/// <summary> /// <summary>
/// 启用 /// 启用
/// </summary> /// </summary>
/// <param name="pkId">服务项目主键</param> /// <param name="pkIds">服务项目主键数组</param>
/// <returns>返回回执</returns> /// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> SetEnable(string pkId); Task<TaskManageOrderResultDto> SetEnable(string[] pkIds);
/// <summary> /// <summary>
/// 取消启用 /// 取消启用
/// </summary> /// </summary>
/// <param name="pkId">服务项目主键</param> /// <param name="pkIds">服务项目主键数组</param>
/// <returns>返回回执</returns> /// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> SetUnEnable(string pkId); Task<TaskManageOrderResultDto> SetUnEnable(string[] pkIds);
/// <summary> /// <summary>
/// 删除 /// 删除
/// </summary> /// </summary>
/// <param name="pkId">服务项目主键</param> /// <param name="pkIds">服务项目主键数组</param>
/// <returns>返回回执</returns> /// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> Delete(string pkId); Task<TaskManageOrderResultDto> Delete(string[] pkIds);
/// <summary> /// <summary>
/// 获取服务项目详情 /// 获取服务项目详情

@ -9,6 +9,7 @@ using Microsoft.Extensions.Logging;
using Myshipping.Application.Entity; using Myshipping.Application.Entity;
using Myshipping.Application.Helper; using Myshipping.Application.Helper;
using Myshipping.Core; using Myshipping.Core;
using MySqlX.XDevAPI.Common;
using StackExchange.Profiling.Internal; using StackExchange.Profiling.Internal;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -180,165 +181,297 @@ namespace Myshipping.Application
} }
#endregion #endregion
#region 启用
/// <summary> /// <summary>
/// 启用 /// 启用
/// </summary> /// </summary>
/// <param name="pkId">服务项目主键</param> /// <param name="pkIds">服务项目主键数组</param>
/// <returns>返回回执</returns> /// <returns>返回回执</returns>
[HttpGet("/ServiceProject/SetEnable")] [HttpPost("/ServiceProject/SetEnable")]
public async Task<TaskManageOrderResultDto> SetEnable([FromQuery] string pkId) public async Task<TaskManageOrderResultDto> SetEnable([FromBody] string[] pkIds)
{ {
TaskManageOrderResultDto result = new TaskManageOrderResultDto(); TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try try
{ {
if (string.IsNullOrWhiteSpace(pkId)) if (pkIds.Length == 0)
{ {
throw Oops.Oh($"服务项目主键不能为空", typeof(InvalidOperationException)); throw Oops.Oh($"服务项目主键数组不能为空", typeof(InvalidOperationException));
} }
var list = _serviceProjectBaseInfoRepository.AsQueryable()
.Where(a => pkIds.Contains(a.PK_ID)).ToList();
var model = _serviceProjectBaseInfoRepository.AsQueryable().First(a => a.PK_ID == pkId); if (list.Count == 0)
throw Oops.Oh($"服务项目获取失败,请服务项目信息是否存在", typeof(InvalidOperationException));
if (model == null) if (list.Count != pkIds.Length)
throw Oops.Oh($"服务项目获取失败,服务项目信息不存在或已作废", typeof(InvalidOperationException)); throw Oops.Oh($"部分服务项目获取失败,请服务项目信息是否存在", typeof(InvalidOperationException));
_logger.LogInformation($"更新服务项目前,获取原始记录 JSON={JSON.Serialize(model)}"); List<TaskManageOrderResultDto> rltList = new List<TaskManageOrderResultDto>();
ValidateServiceProject(model, true); list.ForEach(pr => {
model.UpdatedTime = DateTime.Now; rltList.Add(InnerExcuteServiceProject(pr, OperateTypeEnum.SetEnable).GetAwaiter().GetResult());
model.UpdatedUserId = UserManager.UserId; });
model.UpdatedUserName = UserManager.Name;
model.IS_ENABLE = 1;
await _serviceProjectBaseInfoRepository.AsUpdateable(model).UpdateColumns(it => new result.succ = true;
{ result.msg = rltList.FirstOrDefault().msg;
it.IS_ENABLE,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync(); result.ext = rltList;
result.succ = true; var succ = rltList.Count(x => x.succ);
result.msg = "执行成功"; 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; return result;
} }
#endregion
#region 取消启用
/// <summary> /// <summary>
/// 取消启用 /// 取消启用
/// </summary> /// </summary>
/// <param name="pkId">服务项目主键</param> /// <param name="pkIds">服务项目主键数组</param>
/// <returns>返回回执</returns> /// <returns>返回回执</returns>
[HttpGet("/ServiceProject/SetUnEnable")] [HttpGet("/ServiceProject/SetUnEnable")]
public async Task<TaskManageOrderResultDto> SetUnEnable([FromQuery] string pkId) public async Task<TaskManageOrderResultDto> SetUnEnable([FromBody] string[] pkIds)
{ {
TaskManageOrderResultDto result = new TaskManageOrderResultDto(); TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try try
{ {
if (string.IsNullOrWhiteSpace(pkId)) if (pkIds.Length == 0)
{ {
throw Oops.Oh($"服务项目主键不能为空", typeof(InvalidOperationException)); throw Oops.Oh($"服务项目主键数组不能为空", typeof(InvalidOperationException));
} }
var model = _serviceProjectBaseInfoRepository.AsQueryable().First(a => a.PK_ID == pkId); var list = _serviceProjectBaseInfoRepository.AsQueryable()
.Where(a => pkIds.Contains(a.PK_ID)).ToList();
if (model == null) if (list.Count == 0)
throw Oops.Oh($"服务项目获取失败,服务项目信息不存在或已作废", typeof(InvalidOperationException)); throw Oops.Oh($"服务项目获取失败,请服务项目信息是否存在", typeof(InvalidOperationException));
_logger.LogInformation($"更新服务项目前,获取原始记录 JSON={JSON.Serialize(model)}");
ValidateServiceProject(model, true); if (list.Count != pkIds.Length)
throw Oops.Oh($"部分服务项目获取失败,请服务项目信息是否存在", typeof(InvalidOperationException));
model.UpdatedTime = DateTime.Now; List<TaskManageOrderResultDto> rltList = new List<TaskManageOrderResultDto>();
model.UpdatedUserId = UserManager.UserId;
model.UpdatedUserName = UserManager.Name;
model.IS_ENABLE = 0;
await _serviceProjectBaseInfoRepository.AsUpdateable(model).UpdateColumns(it => new list.ForEach(pr => {
{
it.IS_ENABLE,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync(); rltList.Add(InnerExcuteServiceProject(pr, OperateTypeEnum.SetUnEnable).GetAwaiter().GetResult());
});
result.succ = true; result.succ = true;
result.msg = "执行成功"; 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) catch (Exception ex)
{ {
result.succ = false; result.succ = false;
result.msg = $"执行启用异常,原因:{ex.Message}"; result.msg = $"启用服务项目异常,原因:{ex.Message}";
} }
return result; return result;
} }
#endregion
#region 删除
/// <summary> /// <summary>
/// 删除 /// 删除
/// </summary> /// </summary>
/// <param name="pkId">服务项目主键</param> /// <param name="pkIds">服务项目主键数组</param>
/// <returns>返回回执</returns> /// <returns>返回回执</returns>
[HttpGet("/ServiceProject/Delete")] [HttpPost("/ServiceProject/Delete")]
public async Task<TaskManageOrderResultDto> Delete([FromQuery] string pkId) public async Task<TaskManageOrderResultDto> Delete([FromBody] string[] pkIds)
{ {
TaskManageOrderResultDto result = new TaskManageOrderResultDto(); TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try try
{ {
if (string.IsNullOrWhiteSpace(pkId)) if (pkIds.Length == 0)
{ {
throw Oops.Oh($"服务项目主键不能为空", typeof(InvalidOperationException)); throw Oops.Oh($"服务项目主键数组不能为空", typeof(InvalidOperationException));
}
var list = _serviceProjectBaseInfoRepository.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.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;
}
#endregion
#region 处理服务项目内部方法
/// <summary>
/// 处理服务项目内部方法
/// </summary>
/// <param name="model">服务项目详情</param>
/// <param name="opTypeEnum">操作类型</param>
/// <returns>返回回执</returns>
private async Task<TaskManageOrderResultDto> InnerExcuteServiceProject(ServiceProjectBaseInfo model,OperateTypeEnum opTypeEnum)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
var model = _serviceProjectBaseInfoRepository.AsQueryable().First(a => a.PK_ID == pkId); result.bno = model?.SERVICE_PROJECT_NAME;
try
{
if (model == null) if (model == null)
throw Oops.Oh($"服务项目获取失败,服务项目信息不存在或已作废", typeof(InvalidOperationException)); throw Oops.Oh($"服务项目获取失败,服务项目信息不存在或已作废", typeof(InvalidOperationException));
_logger.LogInformation($"更新服务项目前,获取原始记录 JSON={JSON.Serialize(model)}"); _logger.LogInformation($"更新服务项目前,获取原始记录 JSON={JSON.Serialize(model)}");
if(model.IS_ENABLE == 1)
ValidateServiceProject(model, true);
model.UpdatedTime = DateTime.Now; model.UpdatedTime = DateTime.Now;
model.UpdatedUserId = UserManager.UserId; model.UpdatedUserId = UserManager.UserId;
model.UpdatedUserName = UserManager.Name; model.UpdatedUserName = UserManager.Name;
model.IsDeleted = true;
await _serviceProjectBaseInfoRepository.AsUpdateable(model).UpdateColumns(it => new if(opTypeEnum == OperateTypeEnum.SetEnable)
{ {
it.IsDeleted, model.IS_ENABLE = 1;
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync(); await _serviceProjectBaseInfoRepository.AsUpdateable(model).UpdateColumns(it => new
{
it.IS_ENABLE,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync();
}
else if (opTypeEnum == OperateTypeEnum.SetUnEnable)
{
ValidateServiceProject(model, true);
model.IS_ENABLE = 0;
await _serviceProjectBaseInfoRepository.AsUpdateable(model).UpdateColumns(it => new
{
it.IS_ENABLE,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync();
}
else if (opTypeEnum == OperateTypeEnum.Delete)
{
ValidateServiceProject(model, true);
model.IsDeleted = true;
await _serviceProjectBaseInfoRepository.AsUpdateable(model).UpdateColumns(it => new
{
it.IsDeleted,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync();
}
result.succ = true; result.succ = true;
result.msg = "执行成功"; result.msg = "执行成功";
} }
catch (Exception ex) catch (Exception ex)
{ {
result.succ = false; result.succ = false;
result.msg = $"保存派车异常,原因:{ex.Message}"; result.msg = $"执行启用异常,原因:{ex.Message}";
} }
return result; return result;
} }
#endregion
#region 获取服务项目详情 #region 获取服务项目详情
/// <summary> /// <summary>

Loading…
Cancel
Save