|
|
|
@ -0,0 +1,730 @@
|
|
|
|
|
using Myshipping.Application;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using NLog;
|
|
|
|
|
using DS.Module.UserModule;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using DS.Module.SqlSugar;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using DS.Module.DjyServiceStatus;
|
|
|
|
|
using DS.WMS.Core.Op.Dtos;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using DS.WMS.Core.Invoice.Dtos;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using LanguageExt.Common;
|
|
|
|
|
using DS.WMS.Core.Op.Dtos.ServiceProject;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
using DS.WMS.Core.Op.Dtos.Enum;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Op.Method
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 状态管理
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class StatusSkuBaseService: IStatusSkuBaseService
|
|
|
|
|
{
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
|
private readonly IUser user;
|
|
|
|
|
private readonly ISaasDbService saasService;
|
|
|
|
|
|
|
|
|
|
private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
|
|
public StatusSkuBaseService(IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
|
|
|
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 保存
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info">状态详情</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DataResult<string>> Save([FromBody] StatusSkuBaseDto info)
|
|
|
|
|
{
|
|
|
|
|
return await InnerSave(info);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 保存内部方法
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存内部方法
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info">服务项目详情</param>
|
|
|
|
|
/// <param name="isSetEnable">是否启用</param>
|
|
|
|
|
/// <returns>返回派车Id</returns>
|
|
|
|
|
private async Task<DataResult<string>> InnerSave(StatusSkuBaseDto info, bool isSetEnable = false)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
StatusSkuBaseInfo entity = info.Adapt<StatusSkuBaseInfo>();
|
|
|
|
|
|
|
|
|
|
if (isSetEnable)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(entity.STATUS_SKU_CODE) || string.IsNullOrWhiteSpace(entity.STATUS_SKU_NAME))
|
|
|
|
|
{
|
|
|
|
|
//状态代码或名称不能为空
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuSaveNameNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entity.SORT_NO <= 0)
|
|
|
|
|
{
|
|
|
|
|
//排序值不能小于等于0
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuSaveSortNotEqualLessZero)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entity.IS_ENABLE = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entity == null)
|
|
|
|
|
{
|
|
|
|
|
//状态信息不能为空
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuSaveModelNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"服务项目保存 JSON={JsonConvert.SerializeObject(entity)} user={user.UserId}");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(info.StatusSKUCode))
|
|
|
|
|
{
|
|
|
|
|
if (tenantDb.Queryable<StatusSkuBaseInfo>().Any(a => a.STATUS_SKU_CODE.Equals(info.StatusSKUCode) && a.PK_ID != info.PKId))
|
|
|
|
|
{
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"状态代码已存在不能重复保存");
|
|
|
|
|
|
|
|
|
|
//状态代码已存在不能重复保存
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuSaveCodeExists)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(entity.PK_ID))
|
|
|
|
|
{
|
|
|
|
|
tenantDb.Insertable<StatusSkuBaseInfo>(entity);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var model = InnerGetInfo(entity.PK_ID);
|
|
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"更新状态前,获取原始记录 JSON={JsonConvert.SerializeObject(model)}");
|
|
|
|
|
|
|
|
|
|
ValidateServiceStatus(entity, TrackingOperateTypeEnum.Save);
|
|
|
|
|
|
|
|
|
|
await tenantDb.Updateable<StatusSkuBaseInfo>(entity).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Success(entity.PK_ID);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 单票查询
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 单票查询
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">状态主键</param>
|
|
|
|
|
private StatusSkuBaseInfo InnerGetInfo(string id)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(id))
|
|
|
|
|
{
|
|
|
|
|
//状态主键不能为空
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuSaveIdNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var model = tenantDb.Queryable<StatusSkuBaseInfo>().First(a => a.PK_ID == id);
|
|
|
|
|
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
//状态获取失败,状态信息不存在或已作废
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuEntityNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 校验
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 校验
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="entity">服务状态详情</param>
|
|
|
|
|
/// <param name="opTypeEnum">操作类型枚举</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private void ValidateServiceStatus(StatusSkuBaseInfo entity, TrackingOperateTypeEnum opTypeEnum)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
1、状态名称不能低于2个字符。
|
|
|
|
|
2、状态修改,需要判断当前状态是否关联服务的活动。已关联的不能修改状态代码。
|
|
|
|
|
3、取消启用时,需要判断当前状态是否关联服务的活动。已关联的不能取消启用。
|
|
|
|
|
*/
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
if (opTypeEnum == TrackingOperateTypeEnum.Save)
|
|
|
|
|
{
|
|
|
|
|
if (tenantDb.Queryable<ServiceWorkFlowActivitiesInfo>().Any(a => a.STATUS_SKU_ID == entity.PK_ID))
|
|
|
|
|
{
|
|
|
|
|
//当前状态已关联服务流程活动,不能修改
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuHasRelateWFAct)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entity.STATUS_SKU_CODE.Length < 2 || entity.STATUS_SKU_NAME.Length < 2)
|
|
|
|
|
{
|
|
|
|
|
//状态代码和状态名称不能小于2个字符,不能修改
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuCodeNameLessTwoChar)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (opTypeEnum == TrackingOperateTypeEnum.SetUnEnable)
|
|
|
|
|
{
|
|
|
|
|
if (tenantDb.Queryable<ServiceWorkFlowActivitiesInfo>().Any(a => a.STATUS_SKU_ID == entity.PK_ID))
|
|
|
|
|
{
|
|
|
|
|
//当前状态已关联服务流程活动,不能取消启用
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuHasRelateWFActNotSetUnEnable)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 保存并启用
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存并启用
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info">状态详情</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DataResult<string>> SaveAndEnable(StatusSkuBaseDto info)
|
|
|
|
|
{
|
|
|
|
|
return await InnerSave(info, true);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 处理状态内部方法
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 处理状态内部方法
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model">状态详情</param>
|
|
|
|
|
/// <param name="opTypeEnum">操作类型</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
private async Task<DataResult<string>> InnerExcuteServiceStatus(StatusSkuBaseInfo model, TrackingOperateTypeEnum opTypeEnum)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
string name = model?.STATUS_SKU_NAME;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
//状态获取失败,状态信息不存在或已作废
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuEntityNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"更新状态前,获取原始记录 JSON={JsonConvert.SerializeObject(model)}");
|
|
|
|
|
|
|
|
|
|
if (opTypeEnum == TrackingOperateTypeEnum.SetEnable)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.STATUS_SKU_CODE) || string.IsNullOrWhiteSpace(model.STATUS_SKU_NAME))
|
|
|
|
|
{
|
|
|
|
|
//状态代码或名称不能为空
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuSaveNameNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (model.SORT_NO <= 0)
|
|
|
|
|
{
|
|
|
|
|
//排序值不能小于等于0
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuSaveSortNotEqualLessZero)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model.IS_ENABLE = 1;
|
|
|
|
|
model.UpdateBy = long.Parse(user.UserId);
|
|
|
|
|
model.UpdateUserName = user.UserName;
|
|
|
|
|
model.UpdateTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
await tenantDb.Updateable(model).UpdateColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.IS_ENABLE,
|
|
|
|
|
it.UpdateBy,
|
|
|
|
|
it.UpdateUserName,
|
|
|
|
|
it.UpdateTime
|
|
|
|
|
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else if (opTypeEnum == TrackingOperateTypeEnum.SetUnEnable)
|
|
|
|
|
{
|
|
|
|
|
ValidateServiceStatus(model, opTypeEnum);
|
|
|
|
|
|
|
|
|
|
model.IS_ENABLE = 0;
|
|
|
|
|
model.UpdateBy = long.Parse(user.UserId);
|
|
|
|
|
model.UpdateUserName = user.UserName;
|
|
|
|
|
model.UpdateTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
await tenantDb.Updateable(model).UpdateColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.IS_ENABLE,
|
|
|
|
|
it.UpdateBy,
|
|
|
|
|
it.UpdateUserName,
|
|
|
|
|
it.UpdateTime
|
|
|
|
|
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else if (opTypeEnum == TrackingOperateTypeEnum.Delete)
|
|
|
|
|
{
|
|
|
|
|
ValidateServiceStatus(model, opTypeEnum);
|
|
|
|
|
|
|
|
|
|
model.Deleted = true;
|
|
|
|
|
model.DeleteBy = long.Parse(user.UserId);
|
|
|
|
|
model.DeleteUserName = user.UserName;
|
|
|
|
|
model.DeleteTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
await tenantDb.Updateable(model).UpdateColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.Deleted,
|
|
|
|
|
it.DeleteBy,
|
|
|
|
|
it.DeleteUserName,
|
|
|
|
|
it.DeleteTime
|
|
|
|
|
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"执行失败,原因:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Failed($"执行失败,原因:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Success(name);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 启用
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 启用
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids">状态主键数组</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DataResult<string>> SetEnable(string[] ids)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
string batchTotal = string.Empty;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (ids.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
//状态主键数组不能为空
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuBatchIdsNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = tenantDb.Queryable<StatusSkuBaseInfo>()
|
|
|
|
|
.Where(a => ids.Contains(a.PK_ID)).ToList();
|
|
|
|
|
|
|
|
|
|
if (list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
//状态获取失败,请服务项目信息是否存在
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuEntityNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (list.Count != ids.Length)
|
|
|
|
|
{
|
|
|
|
|
//部分状态获取失败,请确认状态是否存在
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuEntityPartNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DataResult<string>> rltList = new List<DataResult<string>>();
|
|
|
|
|
|
|
|
|
|
list.ForEach(pr => {
|
|
|
|
|
|
|
|
|
|
rltList.Add(InnerExcuteServiceStatus(pr, TrackingOperateTypeEnum.SetEnable).GetAwaiter().GetResult());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var succ = rltList.Count(x => x.Succeeded);
|
|
|
|
|
var fail = rltList.Count(x => !x.Succeeded);
|
|
|
|
|
|
|
|
|
|
if (succ > 0)
|
|
|
|
|
{
|
|
|
|
|
batchTotal = succ.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
batchTotal = "- ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fail > 0)
|
|
|
|
|
{
|
|
|
|
|
batchTotal += "/" + fail.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
batchTotal += " -";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"启用状态异常,原因:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Failed($"启用状态异常,原因:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Success(batchTotal);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 取消启用
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 取消启用
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids">状态主键数组</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DataResult<string>> SetUnEnable(string[] ids)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
string batchTotal = string.Empty;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (ids.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
//状态主键数组不能为空
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuBatchIdsNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = tenantDb.Queryable<StatusSkuBaseInfo>()
|
|
|
|
|
.Where(a => ids.Contains(a.PK_ID)).ToList();
|
|
|
|
|
|
|
|
|
|
if (list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
//状态获取失败,请服务项目信息是否存在
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuEntityNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (list.Count != ids.Length)
|
|
|
|
|
{
|
|
|
|
|
//部分状态获取失败,请确认状态是否存在
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuEntityPartNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DataResult<string>> rltList = new List<DataResult<string>>();
|
|
|
|
|
|
|
|
|
|
list.ForEach(pr => {
|
|
|
|
|
|
|
|
|
|
rltList.Add(InnerExcuteServiceStatus(pr, TrackingOperateTypeEnum.SetUnEnable).GetAwaiter().GetResult());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var succ = rltList.Count(x => x.Succeeded);
|
|
|
|
|
var fail = rltList.Count(x => !x.Succeeded);
|
|
|
|
|
|
|
|
|
|
if (succ > 0)
|
|
|
|
|
{
|
|
|
|
|
batchTotal = succ.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
batchTotal = "- ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fail > 0)
|
|
|
|
|
{
|
|
|
|
|
batchTotal += "/" + fail.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
batchTotal += " -";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"取消启用状态异常,原因:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Failed($"取消启用状态异常,原因:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Success(batchTotal);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 删除
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids">状态主键数组</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DataResult<string>> Delete(string[] ids)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
string batchTotal = string.Empty;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (ids.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
//状态主键数组不能为空
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuBatchIdsNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = tenantDb.Queryable<StatusSkuBaseInfo>()
|
|
|
|
|
.Where(a => ids.Contains(a.PK_ID)).ToList();
|
|
|
|
|
|
|
|
|
|
if (list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
//状态获取失败,请服务项目信息是否存在
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuEntityNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (list.Count != ids.Length)
|
|
|
|
|
{
|
|
|
|
|
//部分状态获取失败,请确认状态是否存在
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuEntityPartNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DataResult<string>> rltList = new List<DataResult<string>>();
|
|
|
|
|
|
|
|
|
|
list.ForEach(pr => {
|
|
|
|
|
|
|
|
|
|
rltList.Add(InnerExcuteServiceStatus(pr, TrackingOperateTypeEnum.Delete).GetAwaiter().GetResult());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var succ = rltList.Count(x => x.Succeeded);
|
|
|
|
|
var fail = rltList.Count(x => !x.Succeeded);
|
|
|
|
|
|
|
|
|
|
if (succ > 0)
|
|
|
|
|
{
|
|
|
|
|
batchTotal = succ.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
batchTotal = "- ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fail > 0)
|
|
|
|
|
{
|
|
|
|
|
batchTotal += "/" + fail.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
batchTotal += " -";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"删除状态异常,原因:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Failed($"删除状态异常,原因:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Success(batchTotal);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 获取状态详情
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取状态详情
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pkId">状态主键</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DataResult<StatusSkuBaseShowDto>> GetInfo(string id)
|
|
|
|
|
{
|
|
|
|
|
var model = InnerGetInfo(id);
|
|
|
|
|
|
|
|
|
|
var showModel = model.Adapt<StatusSkuBaseShowDto>();
|
|
|
|
|
|
|
|
|
|
return DataResult<StatusSkuBaseShowDto>.Success(showModel);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 检索状态列表
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 检索状态列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="queryItem">检索值</param>
|
|
|
|
|
/// <param name="topNum">最大返回行数(默认15)</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DataResult<List<StatusSkuBaseDto>>> QueryList(string queryItem, int topNum = 15)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
var list = await tenantDb.Queryable<StatusSkuBaseInfo>().Where(a => a.IS_ENABLE == 1 && a.Deleted == false)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(queryItem), a => (a.STATUS_SKU_CODE.Contains(queryItem) || a.STATUS_SKU_NAME.Contains(queryItem)))
|
|
|
|
|
.Take(topNum).ToListAsync();
|
|
|
|
|
|
|
|
|
|
var rltList = list.Adapt<List<StatusSkuBaseDto>>();
|
|
|
|
|
|
|
|
|
|
return DataResult<List<StatusSkuBaseDto>>.Success(rltList);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 状态台账查询
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 状态台账查询
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="QuerySearch">状态台账查询请求</param>
|
|
|
|
|
/// <returns>返回结果</returns>
|
|
|
|
|
public async Task<DataResult<List<StatusSkuBasePageDto>>> GetPageAsync(PageRequest querySearch)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
List<IConditionalModel> whereList = null;
|
|
|
|
|
|
|
|
|
|
StatusSkuBaseQueryExtDto otherQueryCondition = new StatusSkuBaseQueryExtDto();
|
|
|
|
|
|
|
|
|
|
whereList = GetPageCondition(querySearch, out otherQueryCondition);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var query = tenantDb.Queryable<StatusSkuBaseInfo>()
|
|
|
|
|
.Where(whereList)
|
|
|
|
|
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.StatusSKUName), a =>
|
|
|
|
|
a.STATUS_SKU_CODE.Contains(otherQueryCondition.StatusSKUName) || a.STATUS_SKU_NAME.Contains(otherQueryCondition.StatusSKUName))
|
|
|
|
|
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.StatusSKUNote), a =>
|
|
|
|
|
a.STATUS_SKU_NOTE.Contains(otherQueryCondition.StatusSKUName))
|
|
|
|
|
.WhereIF(otherQueryCondition != null && otherQueryCondition.CreateStart.HasValue, a => a.CreateTime >= otherQueryCondition.CreateStart)
|
|
|
|
|
.WhereIF(otherQueryCondition != null && otherQueryCondition.CreateEnd.HasValue, a => a.CreateTime < otherQueryCondition.CreateEnd)
|
|
|
|
|
.WhereIF(otherQueryCondition != null && otherQueryCondition.UpdateStart.HasValue, a => a.UpdateTime >= otherQueryCondition.UpdateStart)
|
|
|
|
|
.WhereIF(otherQueryCondition != null && otherQueryCondition.UpdateEnd.HasValue, a => a.UpdateTime < otherQueryCondition.UpdateEnd);
|
|
|
|
|
|
|
|
|
|
if (whereList != null)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(whereList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = await query.ToQueryPageAsync(querySearch.PageCondition);
|
|
|
|
|
|
|
|
|
|
List<StatusSkuBasePageDto> resultList = new List<StatusSkuBasePageDto>();
|
|
|
|
|
|
|
|
|
|
if (result.Data.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
resultList = result.Data.Adapt<List<StatusSkuBasePageDto>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<List<StatusSkuBasePageDto>>.PageList(result.Count, resultList, MultiLanguageConst.DataQuerySuccess);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 获取台账查询条件
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取台账查询条件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="querySearch">原始查询条件</param>
|
|
|
|
|
/// <param name="queryExt">其他查询条件</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private List<IConditionalModel> GetPageCondition(PageRequest querySearch, out StatusSkuBaseQueryExtDto queryExt)
|
|
|
|
|
{
|
|
|
|
|
List<IConditionalModel> whereList = null;
|
|
|
|
|
|
|
|
|
|
queryExt = new StatusSkuBaseQueryExtDto();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(querySearch.OtherQueryCondition))
|
|
|
|
|
{
|
|
|
|
|
queryExt = JsonConvert.DeserializeObject<StatusSkuBaseQueryExtDto>(querySearch.OtherQueryCondition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(querySearch.QueryCondition))
|
|
|
|
|
{
|
|
|
|
|
whereList = querySearch.GetConditionalModels(db);
|
|
|
|
|
|
|
|
|
|
#region 处理查询条件
|
|
|
|
|
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("StatusSKUName", StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("StatusSKUName", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
queryExt.StatusSKUName = ((ConditionalModel)t).FieldValue;
|
|
|
|
|
|
|
|
|
|
whereList.Remove(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("StatusSKUNote", StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("StatusSKUNote", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
queryExt.StatusSKUNote = ((ConditionalModel)t).FieldValue;
|
|
|
|
|
|
|
|
|
|
whereList.Remove(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("CreateBy", StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("CreateBy", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
queryExt.CreateBy = long.Parse(((ConditionalModel)t).FieldValue);
|
|
|
|
|
|
|
|
|
|
whereList.Remove(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("UpdateBy", StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("UpdateBy", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
queryExt.UpdateBy = long.Parse(((ConditionalModel)t).FieldValue);
|
|
|
|
|
|
|
|
|
|
whereList.Remove(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("CreateTime", StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
var curList = whereList.Where(t => ((ConditionalModel)t).FieldName.Equals("CreateTime", StringComparison.OrdinalIgnoreCase)).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (ConditionalModel b in curList)
|
|
|
|
|
{
|
|
|
|
|
if (b.ConditionalType == ConditionalType.GreaterThanOrEqual)
|
|
|
|
|
{
|
|
|
|
|
DateTime currDate = DateTime.MinValue;
|
|
|
|
|
if (DateTime.TryParse(b.FieldValue, out currDate))
|
|
|
|
|
{
|
|
|
|
|
queryExt.CreateStart = currDate;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (b.ConditionalType == ConditionalType.LessThanOrEqual)
|
|
|
|
|
{
|
|
|
|
|
DateTime currDate = DateTime.MinValue;
|
|
|
|
|
if (DateTime.TryParse(b.FieldValue, out currDate))
|
|
|
|
|
{
|
|
|
|
|
queryExt.CreateEnd = currDate.AddDays(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
whereList.Remove(b);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("UpdateTime", StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
var curList = whereList.Where(t => ((ConditionalModel)t).FieldName.Equals("UpdateTime", StringComparison.OrdinalIgnoreCase)).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (ConditionalModel b in curList)
|
|
|
|
|
{
|
|
|
|
|
if (b.ConditionalType == ConditionalType.GreaterThanOrEqual)
|
|
|
|
|
{
|
|
|
|
|
DateTime currDate = DateTime.MinValue;
|
|
|
|
|
if (DateTime.TryParse(b.FieldValue, out currDate))
|
|
|
|
|
{
|
|
|
|
|
queryExt.UpdateStart = currDate;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (b.ConditionalType == ConditionalType.LessThanOrEqual)
|
|
|
|
|
{
|
|
|
|
|
DateTime currDate = DateTime.MinValue;
|
|
|
|
|
if (DateTime.TryParse(b.FieldValue, out currDate))
|
|
|
|
|
{
|
|
|
|
|
queryExt.UpdateEnd = currDate.AddDays(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
whereList.Remove(b);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return whereList;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|