修改服务项目

optimize
jianghaiqing 1 year ago
parent bf3c54aa40
commit c71d002700

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

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

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

Loading…
Cancel
Save