新增服务项目方法

dev
jianghaiqing 1 week ago
parent 93d2850892
commit c2a2d9d0df

@ -1810,5 +1810,66 @@ public static class MultiLanguageConst
[Description("部分状态获取失败,请确认状态是否存在")]
public const string ServiceProjectStatusSkuEntityPartNull = "ServiceProject_StatusSku_EntityPartNull";
/// <summary>
/// 服务项目代码或名称不能为空
/// </summary>
[Description("状态代码或名称不能为空")]
public const string ServiceProjectSaveNameNull = "ServiceProject_SaveNameNull";
/// <summary>
/// 服务项目排序值不能小于等于0
/// </summary>
[Description("排序值不能小于等于0")]
public const string ServiceProjectSaveSortNotEqualLessZero = "ServiceProject_SaveSortNotEqualLessZero";
/// <summary>
/// 服务项目不能为空
/// </summary>
[Description("服务项目不能为空")]
public const string ServiceProjectSaveModelNull = "ServiceProject_SaveModelNull";
/// <summary>
/// 服务项目代码已存在不能重复保存
/// </summary>
[Description("服务项目代码已存在不能重复保存")]
public const string ServiceProjectSaveCodeExists = "ServiceProject_SaveCodeExists";
/// <summary>
/// 服务项目获取失败,服务项目信息不存在或已作废
/// </summary>
[Description("服务项目获取失败,服务项目信息不存在或已作废")]
public const string ServiceProjectEntityNull = "ServiceProject_EntityNull";
/// <summary>
/// 当前服务项目已关联服务流程,不能修改
/// </summary>
[Description("当前服务项目已关联服务流程,不能修改")]
public const string ServiceProjectHasRelateWFActNotSave = "ServiceProject_HasRelateWFActNotSave";
/// <summary>
///服务项目代码和状态名称不能小于2个字符不能修改
/// </summary>
[Description("服务项目代码和状态名称不能小于2个字符不能修改")]
public const string ServiceProjectCodeNameLessTwoChar = "ServiceProject_HasRelateWFAct";
/// <summary>
/// 当前服务项目已关联服务流程,不能取消启用
/// </summary>
[Description("当前服务项目已关联服务流程,不能取消启用")]
public const string ServiceProjectHasRelateWFActNotSetUnEnable = "ServiceProject_HasRelateWFActNotSetUnEnable";
/// <summary>
/// 服务项目主键数组不能为空
/// </summary>
[Description("服务项目主键数组不能为空")]
public const string ServiceProjectBatchIdsNull = "ServiceProject_BatchIdsNull";
/// <summary>
/// 部分服务项目获取失败,请服务项目信息是否存在
/// </summary>
[Description("服务项目获取失败,请服务项目信息是否存在")]
public const string ServiceProjectEntityPartNull = "ServiceProject_EntityPartNull";
#endregion
}

@ -14,7 +14,7 @@ namespace DS.WMS.Core.Op.Dtos
/// <summary>
/// 主键
/// </summary>
public string Id { get; set; }
public string PKId { get; set; }
/// <summary>
/// 服务项目代码

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DS.WMS.Core.Op.Dtos
{
/// <summary>
///
/// </summary>
public class ServiceProjectBaseQueryExtDto
{
/// <summary>
/// 创建起始时间
/// </summary>
public Nullable<DateTime> CreateStart { get; set; }
/// <summary>
/// 创建结束时间
/// </summary>
public Nullable<DateTime> CreateEnd { get; set; }
/// <summary>
/// 更新起始时间
/// </summary>
public Nullable<DateTime> UpdateStart { get; set; }
/// <summary>
/// 更新结束时间
/// </summary>
public Nullable<DateTime> UpdateEnd { get; set; }
/// <summary>
/// 是否启用 1-已启用 2-未启用
/// </summary>
/// <example></example>
public string IsEnable { get; set; }
/// <summary>
/// 服务项目名称
/// </summary>
public string ServiceProjectName { get; set; }
/// <summary>
/// 服务项目备注
/// </summary>
public string ServiceProjectNote { get; set; }
/// <summary>
/// 创建人
/// </summary>
public Nullable<long> CreateBy { get; set; }
/// <summary>
/// 更新人
/// </summary>
public Nullable<long> UpdateBy { get; set; }
}
}

@ -17,14 +17,14 @@ namespace DS.WMS.Core.Op.Dtos
{
config.ForType<ServiceProjectBaseDto, ServiceProjectBaseInfo>()
.Map(dest => dest.Id, src => src.Id)
.Map(dest => dest.PK_ID, src => src.PKId)
.Map(dest => dest.SERVICE_PROJECT_CODE, src => src.ServiceProjectCode)
.Map(dest => dest.SERVICE_PROJECT_NAME, src => src.ServiceProjectName)
.Map(dest => dest.SORT_NO, src => src.SortNo)
.Map(dest => dest.SERVICE_PROJECT_NOTE, src => src.ServiceProjectNote);
config.ForType<ServiceProjectBaseInfo, ServiceProjectBaseDto>()
.Map(dest => dest.Id, src => src.Id)
.Map(dest => dest.PKId, src => src.PK_ID)
.Map(dest => dest.ServiceProjectCode, src => src.SERVICE_PROJECT_CODE)
.Map(dest => dest.ServiceProjectName, src => src.SERVICE_PROJECT_NAME)
.Map(dest => dest.SortNo, src => src.SORT_NO);

@ -15,8 +15,14 @@ namespace DS.WMS.Core.Op.Entity
/// 服务项目主表
/// </summary>
[SqlSugar.SugarTable("service_project_base", "服务项目主表")]
public class ServiceProjectBaseInfo : BaseModelV2<long>
public class ServiceProjectBaseInfo
{
/// <summary>
/// 主键
/// </summary>
[SugarColumn(ColumnDescription = "主键", IsPrimaryKey = true)]
public string PK_ID { get; set; }
/// <summary>
/// 服务项代码
/// </summary>
@ -41,5 +47,75 @@ namespace DS.WMS.Core.Op.Entity
/// 服务项目说明
/// </summary>
public string SERVICE_PROJECT_NOTE { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[Description("创建时间")]
[SugarColumn(IsOnlyIgnoreUpdate = true, ColumnDescription = "创建时间")]
public DateTime CreateTime { get; set; }
/// <summary>
/// 创建人
/// </summary>
[Description("创建人")]
[SugarColumn(IsOnlyIgnoreUpdate = true, IsNullable = true, ColumnDescription = "创建人")]
public long CreateBy { get; set; }
/// <summary>
/// 修改人
/// </summary>
[Description("修改人")]
[SugarColumn(IsNullable = true, ColumnDescription = "修改人")]
public long? UpdateBy { get; set; }
/// <summary>
/// 更新时间
/// </summary>
[Description("更新时间")]
[SugarColumn(IsNullable = true, ColumnDescription = "更新时间")]
public Nullable<DateTime> UpdateTime { get; set; }
/// <summary>
/// 删除
/// </summary>
[Description("删除")]
[SugarColumn(ColumnDescription = "是否删除", DefaultValue = "0")]
public bool Deleted { get; set; }
/// <summary>
/// 删除时间
/// </summary>
[Description("删除时间")]
[SugarColumn(IsNullable = true, ColumnDescription = "删除时间", IsOnlyIgnoreInsert = true)]
public Nullable<DateTime> DeleteTime { get; set; }
/// <summary>
/// 删除人
/// </summary>
[Description("删除人")]
[SugarColumn(IsNullable = true, ColumnDescription = "删除人", IsOnlyIgnoreInsert = true)]
public Nullable<long> DeleteBy { get; set; }
/// <summary>
/// 创建人名称
/// </summary>
[Description("创建人名称")]
[SugarColumn(IsOnlyIgnoreUpdate = true, IsNullable = true, ColumnDescription = "创建人名称", Length = 50)]
public string CreateUserName { get; set; }
/// <summary>
/// 修改人名称
/// </summary>
[Description("修改人名称")]
[SugarColumn(IsNullable = true, ColumnDescription = "修改人名称", Length = 50)]
public string UpdateUserName { get; set; }
/// <summary>
/// 删除人名称
/// </summary>
[Description("删除人名称")]
[SugarColumn(IsNullable = true, ColumnDescription = "删除人名称", Length = 50, IsOnlyIgnoreInsert = true)]
public string DeleteUserName { get; set; }
}
}

@ -18,14 +18,14 @@ namespace DS.WMS.Core.Op.Interface
/// </summary>
/// <param name="info">服务项目详情</param>
/// <returns>返回回执</returns>
Task<DataResult<long>> Save(ServiceProjectBaseDto info);
Task<DataResult<string>> Save(ServiceProjectBaseDto info);
/// <summary>
/// 保存并启用
/// </summary>
/// <param name="info">服务项目详情</param>
/// <returns>返回回执</returns>
Task<DataResult<long>> SaveAndEnable(ServiceProjectBaseDto info);
Task<DataResult<string>> SaveAndEnable(ServiceProjectBaseDto info);
/// <summary>
/// 启用
@ -39,14 +39,14 @@ namespace DS.WMS.Core.Op.Interface
/// </summary>
/// <param name="pkIds">服务项目主键数组</param>
/// <returns>返回回执</returns>
Task<DataResult<long>> SetUnEnable(string[] pkIds);
Task<DataResult<string>> SetUnEnable(string[] pkIds);
/// <summary>
/// 删除
/// </summary>
/// <param name="pkIds">服务项目主键数组</param>
/// <returns>返回回执</returns>
Task<DataResult<long>> Delete(string[] pkIds);
Task<DataResult<string>> Delete(string[] pkIds);
/// <summary>
/// 获取服务项目详情
@ -66,10 +66,9 @@ namespace DS.WMS.Core.Op.Interface
/// <summary>
/// 服务项目台账查询
/// </summary>
/// <param name="QuerySearch">服务项目台账查询请求</param>
/// <param name="querySearch">服务项目台账查询请求</param>
/// <returns>返回结果</returns>
Task<SqlSugarPagedList<ServiceProjectBasePageDto>> GetPageAsync(QueryServiceProjectBaseDto QuerySearch);
Task<DataResult<List<ServiceProjectBasePageDto>>> GetPageAsync(PageRequest querySearch);
}

@ -3,10 +3,746 @@ 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.Module.Core.Extensions;
using DS.WMS.Core.Op.Dtos.Enum;
using DS.WMS.Core.Op.Interface;
using LanguageExt.Pretty;
namespace DS.WMS.Core.Op.Method.ServiceProject
namespace DS.WMS.Core.Op.Method
{
internal class ServiceProjectService
public class ServiceProjectService: IServiceProjectService
{
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 ServiceProjectService(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(ServiceProjectBaseDto 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(ServiceProjectBaseDto info, bool isSetEnable = false)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
ServiceProjectBaseInfo entity = info.Adapt<ServiceProjectBaseInfo>();
if (isSetEnable)
{
if (string.IsNullOrWhiteSpace(entity.SERVICE_PROJECT_CODE) || string.IsNullOrWhiteSpace(entity.SERVICE_PROJECT_NAME))
{
//服务项目代码或名称不能为空
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectSaveNameNull)));
}
if (entity.SORT_NO <= 0)
{
//排序值不能小于等于0
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectSaveSortNotEqualLessZero)));
}
entity.IS_ENABLE = 1;
}
if (entity == null)
{
//服务项目不能为空
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectSaveModelNull)));
}
Logger.Log(NLog.LogLevel.Info, $"服务项目保存 JSON={JsonConvert.SerializeObject(entity)} user={user.UserId}");
if (!string.IsNullOrWhiteSpace(info.ServiceProjectCode))
{
string pkId = !string.IsNullOrWhiteSpace(info.PKId) ? info.PKId : string.Empty;
if (tenantDb.Queryable<ServiceProjectBaseInfo>().Any(a => a.SERVICE_PROJECT_CODE.Equals(info.ServiceProjectCode) && a.PK_ID != pkId))
{
Logger.Log(NLog.LogLevel.Info, $"服务项目代码已存在不能重复保存");
//服务项目代码已存在不能重复保存
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectSaveCodeExists)));
}
}
if (string.IsNullOrWhiteSpace(entity.PK_ID))
{
entity.PK_ID = SnowFlakeSingle.Instance.NextId().ToString();
tenantDb.Insertable<ServiceProjectBaseInfo>(entity).ExecuteCommand();
}
else
{
var model = tenantDb.Queryable<ServiceProjectBaseInfo>().First(a => a.PK_ID == entity.PK_ID);
if (model == null)
{
//服务项目获取失败,服务项目信息不存在或已作废
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectEntityNull)));
}
Logger.Log(NLog.LogLevel.Info, $"更新服务项目前,获取原始记录 JSON={JsonConvert.SerializeObject(model)}");
ValidateServiceProject(entity, TrackingOperateTypeEnum.Save);
entity.UpdateTime = DateTime.Now;
entity.UpdateBy = long.Parse(user.UserId);
entity.UpdateUserName = user.UserName;
await tenantDb.Updateable<ServiceProjectBaseInfo>(entity).IgnoreColumns(it => new
{
it.UpdateTime,
it.UpdateBy,
it.UpdateUserName,
}).ExecuteCommandAsync();
}
return DataResult<string>.Success(entity.PK_ID);
}
#endregion
#region 校验
/// <summary>
/// 校验
/// </summary>
/// <param name="entity">服务项目详情</param>
/// <param name="opTypeEnum">操作类型枚举</param>
/// <returns></returns>
private void ValidateServiceProject(ServiceProjectBaseInfo entity, TrackingOperateTypeEnum opTypeEnum)
{
/*
12
2
3
*/
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (opTypeEnum == TrackingOperateTypeEnum.Save)
{
if (tenantDb.Queryable<ServiceWorkFlowProjectRelation>().Any(a => a.SERVICE_PROJECT_ID == entity.PK_ID))
{
//当前服务项目已关联服务流程,不能修改
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectHasRelateWFActNotSave)));
}
if (entity.SERVICE_PROJECT_CODE.Length < 2 || entity.SERVICE_PROJECT_NAME.Length < 2)
{
//服务项目代码和状态名称不能小于2个字符不能修改
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectCodeNameLessTwoChar)));
}
}
if (opTypeEnum == TrackingOperateTypeEnum.SetUnEnable)
{
if (tenantDb.Queryable<ServiceWorkFlowProjectRelation>().Any(a => a.SERVICE_PROJECT_ID == entity.PK_ID))
{
//当前服务项目已关联服务流程,不能取消启用
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectHasRelateWFActNotSetUnEnable)));
}
}
}
#endregion
#region 保存并启用
/// <summary>
/// 保存并启用
/// </summary>
/// <param name="info">服务项目详情</param>
/// <returns>返回回执</returns>
public async Task<DataResult<string>> SaveAndEnable([FromBody] ServiceProjectBaseDto info)
{
return await InnerSave(info, true);
}
#endregion
#region 启用
/// <summary>
/// 启用
/// </summary>
/// <param name="ids">服务项目主键数组</param>
/// <returns>返回回执</returns>
public async Task<DataResult<string>> SetEnable([FromBody] string[] ids)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
string batchTotal = string.Empty;
try
{
if (ids.Length == 0)
{
//服务项目主键数组不能为空
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectBatchIdsNull)));
}
var list = tenantDb.Queryable<ServiceProjectBaseInfo>()
.Where(a => ids.Contains(a.PK_ID)).ToList();
if (list.Count == 0)
{
//当前服务项目已关联服务流程,不能取消启用
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectEntityNull)));
}
if (list.Count != ids.Length)
{
//部分服务项目获取失败,请服务项目信息是否存在
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectEntityPartNull)));
}
List<DataResult<string>> rltList = new List<DataResult<string>>();
list.ForEach(pr => {
rltList.Add(InnerExcuteServiceProject(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.ServiceProjectBatchIdsNull)));
}
var list = tenantDb.Queryable<ServiceProjectBaseInfo>()
.Where(a => ids.Contains(a.PK_ID)).ToList();
if (list.Count == 0)
{
//当前服务项目已关联服务流程,不能取消启用
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectEntityNull)));
}
if (list.Count != ids.Length)
{
//部分服务项目获取失败,请服务项目信息是否存在
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectEntityPartNull)));
}
List<DataResult<string>> rltList = new List<DataResult<string>>();
list.ForEach(pr => {
rltList.Add(InnerExcuteServiceProject(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="pkIds">服务项目主键数组</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.ServiceProjectBatchIdsNull)));
}
var list = tenantDb.Queryable<ServiceProjectBaseInfo>()
.Where(a => ids.Contains(a.PK_ID)).ToList();
if (list.Count == 0)
{
//当前服务项目已关联服务流程,不能取消启用
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectEntityNull)));
}
if (list.Count != ids.Length)
{
//部分服务项目获取失败,请服务项目信息是否存在
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectEntityPartNull)));
}
List<DataResult<string>> rltList = new List<DataResult<string>>();
list.ForEach(pr => {
rltList.Add(InnerExcuteServiceProject(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="model">服务项目详情</param>
/// <param name="opTypeEnum">操作类型</param>
/// <returns>返回回执</returns>
private async Task<DataResult<string>> InnerExcuteServiceProject(ServiceProjectBaseInfo model, TrackingOperateTypeEnum opTypeEnum)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
string name = model?.SERVICE_PROJECT_NAME;
try
{
if (model == null)
{
//服务项目获取失败,服务项目信息不存在或已作废
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectEntityNull)));
}
Logger.Log(NLog.LogLevel.Info, $"更新服务项目前,获取原始记录 JSON={JsonConvert.SerializeObject(model)}");
if (opTypeEnum == TrackingOperateTypeEnum.SetEnable)
{
if (string.IsNullOrWhiteSpace(model.SERVICE_PROJECT_CODE) || string.IsNullOrWhiteSpace(model.SERVICE_PROJECT_NAME))
{
//throw Oops.Oh($"服务项代码或名称不能为空", typeof(InvalidOperationException));
}
if (model.SORT_NO <= 0)
{
//throw Oops.Oh($"排序值不能小于等于0", typeof(InvalidOperationException));
}
model.IS_ENABLE = 1;
model.UpdateTime = DateTime.Now;
model.UpdateBy = long.Parse(user.UserId);
model.UpdateUserName = user.UserName;
await tenantDb.Updateable<ServiceProjectBaseInfo>(model).UpdateColumns(it => new
{
it.IS_ENABLE,
it.UpdateTime,
it.UpdateBy,
it.UpdateUserName
}).ExecuteCommandAsync();
}
else if (opTypeEnum == TrackingOperateTypeEnum.SetUnEnable)
{
ValidateServiceProject(model, opTypeEnum);
model.IS_ENABLE = 0;
model.UpdateTime = DateTime.Now;
model.UpdateBy = long.Parse(user.UserId);
model.UpdateUserName = user.UserName;
await tenantDb.Updateable<ServiceProjectBaseInfo>(model).UpdateColumns(it => new
{
it.IS_ENABLE,
it.UpdateTime,
it.UpdateBy,
it.UpdateUserName
}).ExecuteCommandAsync();
}
else if (opTypeEnum == TrackingOperateTypeEnum.Delete)
{
ValidateServiceProject(model, opTypeEnum);
model.Deleted = true;
model.DeleteTime = DateTime.Now;
model.DeleteBy = long.Parse(user.UserId);
model.DeleteUserName = user.UserName;
await tenantDb.Updateable<ServiceProjectBaseInfo>(model).UpdateColumns(it => new
{
it.Deleted,
it.DeleteTime,
it.DeleteBy,
it.DeleteUserName
}).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="pkId">服务项目主键</param>
/// <returns>返回回执</returns>
public async Task<DataResult<ServiceProjectBaseShowDto>> GetInfo(string pkId)
{
var model = InnerGetInfo(pkId);
var showModel = model.Adapt<ServiceProjectBaseShowDto>();
return DataResult<ServiceProjectBaseShowDto>.Success(showModel);
}
#endregion
#region 单票查询
/// <summary>
/// 单票查询
/// </summary>
/// <param name="id">状态主键</param>
private ServiceProjectBaseInfo 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<ServiceProjectBaseInfo>().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="queryItem">检索值</param>
/// <param name="topNum">最大返回行数默认15</param>
/// <returns>返回回执</returns>
public async Task<DataResult<List<ServiceProjectBaseDto>>> QueryList([FromQuery] string queryItem, [FromQuery] int topNum = 15)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var list = await tenantDb.Queryable<ServiceProjectBaseInfo>().Where(a => a.IS_ENABLE == 1 && a.Deleted == false)
.WhereIF(!string.IsNullOrWhiteSpace(queryItem), a => (a.SERVICE_PROJECT_CODE.Contains(queryItem) || a.SERVICE_PROJECT_NAME.Contains(queryItem)))
.Take(topNum).ToListAsync();
var rltList = list.Adapt<List<ServiceProjectBaseDto>>();
return DataResult<List<ServiceProjectBaseDto>>.Success(rltList);
}
#endregion
#region 服务项目台账查询
/// <summary>
/// 服务项目台账查询
/// </summary>
/// <param name="QuerySearch">服务项目台账查询请求</param>
/// <returns>返回结果</returns>
public async Task<DataResult<List<ServiceProjectBasePageDto>>> GetPageAsync(PageRequest querySearch)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
List<IConditionalModel> whereList = null;
ServiceProjectBaseQueryExtDto otherQueryCondition = new ServiceProjectBaseQueryExtDto();
whereList = GetPageCondition(querySearch, out otherQueryCondition);
var query = tenantDb.Queryable<ServiceProjectBaseInfo>()
.Where(whereList)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.ServiceProjectName), a =>
a.SERVICE_PROJECT_CODE.Contains(otherQueryCondition.ServiceProjectName) || a.SERVICE_PROJECT_NAME.Contains(otherQueryCondition.ServiceProjectName))
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.ServiceProjectNote), a =>
a.SERVICE_PROJECT_NOTE.Contains(otherQueryCondition.ServiceProjectNote))
.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<ServiceProjectBasePageDto> resultList = new List<ServiceProjectBasePageDto>();
if (result.Data.Count > 0)
{
resultList = result.Data.Adapt<List<ServiceProjectBasePageDto>>();
}
return DataResult<List<ServiceProjectBasePageDto>>.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 ServiceProjectBaseQueryExtDto queryExt)
{
List<IConditionalModel> whereList = null;
queryExt = new ServiceProjectBaseQueryExtDto();
if (!string.IsNullOrWhiteSpace(querySearch.OtherQueryCondition))
{
queryExt = JsonConvert.DeserializeObject<ServiceProjectBaseQueryExtDto>(querySearch.OtherQueryCondition);
}
if (!string.IsNullOrWhiteSpace(querySearch.QueryCondition))
{
whereList = querySearch.GetConditionalModels(db);
#region 处理查询条件
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("ServiceProjectName", StringComparison.OrdinalIgnoreCase)))
{
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("ServiceProjectName", StringComparison.OrdinalIgnoreCase));
queryExt.ServiceProjectName = ((ConditionalModel)t).FieldValue;
whereList.Remove(t);
}
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("ServiceProjectNote", StringComparison.OrdinalIgnoreCase)))
{
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("ServiceProjectNote", StringComparison.OrdinalIgnoreCase));
queryExt.ServiceProjectNote = ((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
}
}

@ -52,7 +52,7 @@ namespace DS.WMS.Core.Op.Method
/// </summary>
/// <param name="info">状态详情</param>
/// <returns>返回回执</returns>
public async Task<DataResult<string>> Save([FromBody] StatusSkuBaseDto info)
public async Task<DataResult<string>> Save(StatusSkuBaseDto info)
{
return await InnerSave(info);
}
@ -569,7 +569,7 @@ namespace DS.WMS.Core.Op.Method
/// <summary>
/// 状态台账查询
/// </summary>
/// <param name="QuerySearch">状态台账查询请求</param>
/// <param name="querySearch">状态台账查询请求</param>
/// <returns>返回结果</returns>
public async Task<DataResult<List<StatusSkuBasePageDto>>> GetPageAsync(PageRequest querySearch)
{
@ -587,7 +587,7 @@ namespace DS.WMS.Core.Op.Method
.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))
a.STATUS_SKU_NOTE.Contains(otherQueryCondition.StatusSKUNote))
.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)

@ -855,7 +855,7 @@ namespace DS.WMS.Core.TaskPlat.Dtos.Mapper
{
TypeAdapterConfig<ServiceProjectBaseDto, ServiceProjectBaseInfo>.NewConfig()
.Map(dest => dest.Id, src => src.Id)
.Map(dest => dest.PK_ID, src => src.PKId)
.Map(dest => dest.SERVICE_PROJECT_CODE, src => src.ServiceProjectCode)
.Map(dest => dest.SERVICE_PROJECT_NAME, src => src.ServiceProjectName)
.Map(dest => dest.SORT_NO, src => src.SortNo)
@ -864,7 +864,7 @@ namespace DS.WMS.Core.TaskPlat.Dtos.Mapper
{
TypeAdapterConfig<ServiceProjectBaseInfo, ServiceProjectBaseDto>.NewConfig()
.Map(dest => dest.Id, src => src.Id)
.Map(dest => dest.PKId, src => src.PK_ID)
.Map(dest => dest.ServiceProjectCode, src => src.SERVICE_PROJECT_CODE)
.Map(dest => dest.ServiceProjectName, src => src.SERVICE_PROJECT_NAME)
.Map(dest => dest.SortNo, src => src.SORT_NO);

Loading…
Cancel
Save