diff --git a/Myshipping.Application/Enum/OperateTypeEnum.cs b/Myshipping.Application/Enum/OperateTypeEnum.cs
index 12534d4d..683107cc 100644
--- a/Myshipping.Application/Enum/OperateTypeEnum.cs
+++ b/Myshipping.Application/Enum/OperateTypeEnum.cs
@@ -46,6 +46,16 @@ namespace Myshipping.Application
/// 派车回写详情
///
[Description("派车回写详情")]
- DispatchBackSave
+ DispatchBackSave,
+ ///
+ /// 设定启用
+ ///
+ [Description("设定启用")]
+ SetEnable,
+ ///
+ /// 设定不启用
+ ///
+ [Description("设定不启用")]
+ SetUnEnable
}
}
diff --git a/Myshipping.Application/Service/TrackingSystem/Interface/IServiceProjectService.cs b/Myshipping.Application/Service/TrackingSystem/Interface/IServiceProjectService.cs
index 5b4021db..a62f375e 100644
--- a/Myshipping.Application/Service/TrackingSystem/Interface/IServiceProjectService.cs
+++ b/Myshipping.Application/Service/TrackingSystem/Interface/IServiceProjectService.cs
@@ -29,23 +29,23 @@ namespace Myshipping.Application
///
/// 启用
///
- /// 服务项目主键
+ /// 服务项目主键数组
/// 返回回执
- Task SetEnable(string pkId);
+ Task SetEnable(string[] pkIds);
///
/// 取消启用
///
- /// 服务项目主键
+ /// 服务项目主键数组
/// 返回回执
- Task SetUnEnable(string pkId);
+ Task SetUnEnable(string[] pkIds);
///
/// 删除
///
- /// 服务项目主键
+ /// 服务项目主键数组
/// 返回回执
- Task Delete(string pkId);
+ Task Delete(string[] pkIds);
///
/// 获取服务项目详情
diff --git a/Myshipping.Application/Service/TrackingSystem/ServiceProjectService.cs b/Myshipping.Application/Service/TrackingSystem/ServiceProjectService.cs
index c94f764b..3d3da575 100644
--- a/Myshipping.Application/Service/TrackingSystem/ServiceProjectService.cs
+++ b/Myshipping.Application/Service/TrackingSystem/ServiceProjectService.cs
@@ -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,165 +181,297 @@ namespace Myshipping.Application
}
#endregion
+ #region 启用
///
/// 启用
///
- /// 服务项目主键
+ /// 服务项目主键数组
/// 返回回执
- [HttpGet("/ServiceProject/SetEnable")]
- public async Task SetEnable([FromQuery] string pkId)
+ [HttpPost("/ServiceProject/SetEnable")]
+ public async Task 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 rltList = new List();
- 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 取消启用
///
/// 取消启用
///
- /// 服务项目主键
+ /// 服务项目主键数组
/// 返回回执
[HttpGet("/ServiceProject/SetUnEnable")]
- public async Task SetUnEnable([FromQuery] string pkId)
+ public async Task 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));
-
- _logger.LogInformation($"更新服务项目前,获取原始记录 JSON={JSON.Serialize(model)}");
+ if (list.Count == 0)
+ throw Oops.Oh($"服务项目获取失败,请服务项目信息是否存在", typeof(InvalidOperationException));
- ValidateServiceProject(model, true);
+ if (list.Count != pkIds.Length)
+ throw Oops.Oh($"部分服务项目获取失败,请服务项目信息是否存在", typeof(InvalidOperationException));
- model.UpdatedTime = DateTime.Now;
- model.UpdatedUserId = UserManager.UserId;
- model.UpdatedUserName = UserManager.Name;
- model.IS_ENABLE = 0;
+ List rltList = new List();
- await _serviceProjectBaseInfoRepository.AsUpdateable(model).UpdateColumns(it => new
- {
- it.IS_ENABLE,
- it.UpdatedTime,
- it.UpdatedUserId,
- it.UpdatedUserName
+ list.ForEach(pr => {
- }).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 删除
///
/// 删除
///
- /// 服务项目主键
+ /// 服务项目主键数组
/// 返回回执
- [HttpGet("/ServiceProject/Delete")]
- public async Task Delete([FromQuery] string pkId)
+ [HttpPost("/ServiceProject/Delete")]
+ public async Task 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 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 rltList = new List();
+
+ 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 处理服务项目内部方法
+ ///
+ /// 处理服务项目内部方法
+ ///
+ /// 服务项目详情
+ /// 操作类型
+ /// 返回回执
+ private async Task 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)
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;
- model.IsDeleted = true;
- await _serviceProjectBaseInfoRepository.AsUpdateable(model).UpdateColumns(it => new
+ if(opTypeEnum == OperateTypeEnum.SetEnable)
{
- it.IsDeleted,
- it.UpdatedTime,
- it.UpdatedUserId,
- it.UpdatedUserName
+ model.IS_ENABLE = 1;
- }).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.msg = "执行成功";
+
}
catch (Exception ex)
{
result.succ = false;
- result.msg = $"保存派车异常,原因:{ex.Message}";
+ result.msg = $"执行启用异常,原因:{ex.Message}";
}
return result;
}
+ #endregion
#region 获取服务项目详情
///