From c2a2d9d0df4acc245fbe28d8d8d40d8b76299656 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Mon, 18 Nov 2024 09:40:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9C=8D=E5=8A=A1=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Constants/MultiLanguageConst.cs | 61 ++ .../ServiceProject/ServiceProjectBaseDto.cs | 2 +- .../ServiceProjectBaseQueryExtDto.cs | 60 ++ .../ServiceProject/TrackingSystemMapper.cs | 4 +- .../ServiceProject/ServiceProjectBaseInfo.cs | 78 +- .../ServiceProject/IServiceProjectService.cs | 13 +- .../ServiceProject/ServiceProjectService.cs | 740 +++++++++++++++++- .../ServiceProject/StatusSkuBaseService.cs | 6 +- .../Dtos/Mapper/AddTaskPlatMapsterSetup.cs | 4 +- 9 files changed, 950 insertions(+), 18 deletions(-) create mode 100644 ds-wms-service/DS.WMS.Core/Op/Dtos/ServiceProject/ServiceProjectBaseQueryExtDto.cs diff --git a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs index b38dc97c..0fbac815 100644 --- a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs +++ b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs @@ -1810,5 +1810,66 @@ public static class MultiLanguageConst [Description("部分状态获取失败,请确认状态是否存在")] public const string ServiceProjectStatusSkuEntityPartNull = "ServiceProject_StatusSku_EntityPartNull"; + /// + /// 服务项目代码或名称不能为空 + /// + [Description("状态代码或名称不能为空")] + public const string ServiceProjectSaveNameNull = "ServiceProject_SaveNameNull"; + + /// + /// 服务项目排序值不能小于等于0 + /// + [Description("排序值不能小于等于0")] + public const string ServiceProjectSaveSortNotEqualLessZero = "ServiceProject_SaveSortNotEqualLessZero"; + + /// + /// 服务项目不能为空 + /// + [Description("服务项目不能为空")] + public const string ServiceProjectSaveModelNull = "ServiceProject_SaveModelNull"; + + /// + /// 服务项目代码已存在不能重复保存 + /// + [Description("服务项目代码已存在不能重复保存")] + public const string ServiceProjectSaveCodeExists = "ServiceProject_SaveCodeExists"; + + /// + /// 服务项目获取失败,服务项目信息不存在或已作废 + /// + [Description("服务项目获取失败,服务项目信息不存在或已作废")] + public const string ServiceProjectEntityNull = "ServiceProject_EntityNull"; + + /// + /// 当前服务项目已关联服务流程,不能修改 + /// + [Description("当前服务项目已关联服务流程,不能修改")] + public const string ServiceProjectHasRelateWFActNotSave = "ServiceProject_HasRelateWFActNotSave"; + + /// + ///服务项目代码和状态名称不能小于2个字符,不能修改 + /// + [Description("服务项目代码和状态名称不能小于2个字符,不能修改")] + public const string ServiceProjectCodeNameLessTwoChar = "ServiceProject_HasRelateWFAct"; + + /// + /// 当前服务项目已关联服务流程,不能取消启用 + /// + [Description("当前服务项目已关联服务流程,不能取消启用")] + public const string ServiceProjectHasRelateWFActNotSetUnEnable = "ServiceProject_HasRelateWFActNotSetUnEnable"; + + /// + /// 服务项目主键数组不能为空 + /// + [Description("服务项目主键数组不能为空")] + public const string ServiceProjectBatchIdsNull = "ServiceProject_BatchIdsNull"; + + /// + /// 部分服务项目获取失败,请服务项目信息是否存在 + /// + [Description("服务项目获取失败,请服务项目信息是否存在")] + public const string ServiceProjectEntityPartNull = "ServiceProject_EntityPartNull"; + + #endregion } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/ServiceProject/ServiceProjectBaseDto.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/ServiceProject/ServiceProjectBaseDto.cs index b1229a0e..bcacb6f8 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Dtos/ServiceProject/ServiceProjectBaseDto.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/ServiceProject/ServiceProjectBaseDto.cs @@ -14,7 +14,7 @@ namespace DS.WMS.Core.Op.Dtos /// /// 主键 /// - public string Id { get; set; } + public string PKId { get; set; } /// /// 服务项目代码 diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/ServiceProject/ServiceProjectBaseQueryExtDto.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/ServiceProject/ServiceProjectBaseQueryExtDto.cs new file mode 100644 index 00000000..05c99e31 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/ServiceProject/ServiceProjectBaseQueryExtDto.cs @@ -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 +{ + /// + /// + /// + public class ServiceProjectBaseQueryExtDto + { + /// + /// 创建起始时间 + /// + public Nullable CreateStart { get; set; } + + /// + /// 创建结束时间 + /// + public Nullable CreateEnd { get; set; } + + /// + /// 更新起始时间 + /// + public Nullable UpdateStart { get; set; } + + /// + /// 更新结束时间 + /// + public Nullable UpdateEnd { get; set; } + + /// + /// 是否启用 1-已启用 2-未启用 + /// + /// + public string IsEnable { get; set; } + + /// + /// 服务项目名称 + /// + public string ServiceProjectName { get; set; } + + /// + /// 服务项目备注 + /// + public string ServiceProjectNote { get; set; } + + /// + /// 创建人 + /// + public Nullable CreateBy { get; set; } + + /// + /// 更新人 + /// + public Nullable UpdateBy { get; set; } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/ServiceProject/TrackingSystemMapper.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/ServiceProject/TrackingSystemMapper.cs index f9bf41cf..7e0d1546 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Dtos/ServiceProject/TrackingSystemMapper.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/ServiceProject/TrackingSystemMapper.cs @@ -17,14 +17,14 @@ namespace DS.WMS.Core.Op.Dtos { config.ForType() - .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() - .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); diff --git a/ds-wms-service/DS.WMS.Core/Op/Entity/ServiceProject/ServiceProjectBaseInfo.cs b/ds-wms-service/DS.WMS.Core/Op/Entity/ServiceProject/ServiceProjectBaseInfo.cs index 2dde0efb..6deb3b03 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Entity/ServiceProject/ServiceProjectBaseInfo.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Entity/ServiceProject/ServiceProjectBaseInfo.cs @@ -15,8 +15,14 @@ namespace DS.WMS.Core.Op.Entity /// 服务项目主表 /// [SqlSugar.SugarTable("service_project_base", "服务项目主表")] - public class ServiceProjectBaseInfo : BaseModelV2 + public class ServiceProjectBaseInfo { + /// + /// 主键 + /// + [SugarColumn(ColumnDescription = "主键", IsPrimaryKey = true)] + public string PK_ID { get; set; } + /// /// 服务项代码 /// @@ -41,5 +47,75 @@ namespace DS.WMS.Core.Op.Entity /// 服务项目说明 /// public string SERVICE_PROJECT_NOTE { get; set; } + + /// + /// 创建时间 + /// + [Description("创建时间")] + [SugarColumn(IsOnlyIgnoreUpdate = true, ColumnDescription = "创建时间")] + public DateTime CreateTime { get; set; } + + /// + /// 创建人 + /// + [Description("创建人")] + [SugarColumn(IsOnlyIgnoreUpdate = true, IsNullable = true, ColumnDescription = "创建人")] + public long CreateBy { get; set; } + + /// + /// 修改人 + /// + [Description("修改人")] + [SugarColumn(IsNullable = true, ColumnDescription = "修改人")] + public long? UpdateBy { get; set; } + + /// + /// 更新时间 + /// + [Description("更新时间")] + [SugarColumn(IsNullable = true, ColumnDescription = "更新时间")] + public Nullable UpdateTime { get; set; } + + /// + /// 删除 + /// + [Description("删除")] + [SugarColumn(ColumnDescription = "是否删除", DefaultValue = "0")] + public bool Deleted { get; set; } + + /// + /// 删除时间 + /// + [Description("删除时间")] + [SugarColumn(IsNullable = true, ColumnDescription = "删除时间", IsOnlyIgnoreInsert = true)] + public Nullable DeleteTime { get; set; } + + /// + /// 删除人 + /// + [Description("删除人")] + [SugarColumn(IsNullable = true, ColumnDescription = "删除人", IsOnlyIgnoreInsert = true)] + public Nullable DeleteBy { get; set; } + + /// + /// 创建人名称 + /// + [Description("创建人名称")] + [SugarColumn(IsOnlyIgnoreUpdate = true, IsNullable = true, ColumnDescription = "创建人名称", Length = 50)] + public string CreateUserName { get; set; } + + /// + /// 修改人名称 + /// + [Description("修改人名称")] + [SugarColumn(IsNullable = true, ColumnDescription = "修改人名称", Length = 50)] + public string UpdateUserName { get; set; } + + /// + /// 删除人名称 + /// + [Description("删除人名称")] + [SugarColumn(IsNullable = true, ColumnDescription = "删除人名称", Length = 50, IsOnlyIgnoreInsert = true)] + public string DeleteUserName { get; set; } } } diff --git a/ds-wms-service/DS.WMS.Core/Op/Interface/ServiceProject/IServiceProjectService.cs b/ds-wms-service/DS.WMS.Core/Op/Interface/ServiceProject/IServiceProjectService.cs index cbdc8b0a..879b48f6 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Interface/ServiceProject/IServiceProjectService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Interface/ServiceProject/IServiceProjectService.cs @@ -18,14 +18,14 @@ namespace DS.WMS.Core.Op.Interface /// /// 服务项目详情 /// 返回回执 - Task> Save(ServiceProjectBaseDto info); + Task> Save(ServiceProjectBaseDto info); /// /// 保存并启用 /// /// 服务项目详情 /// 返回回执 - Task> SaveAndEnable(ServiceProjectBaseDto info); + Task> SaveAndEnable(ServiceProjectBaseDto info); /// /// 启用 @@ -39,14 +39,14 @@ namespace DS.WMS.Core.Op.Interface /// /// 服务项目主键数组 /// 返回回执 - Task> SetUnEnable(string[] pkIds); + Task> SetUnEnable(string[] pkIds); /// /// 删除 /// /// 服务项目主键数组 /// 返回回执 - Task> Delete(string[] pkIds); + Task> Delete(string[] pkIds); /// /// 获取服务项目详情 @@ -66,10 +66,9 @@ namespace DS.WMS.Core.Op.Interface /// /// 服务项目台账查询 /// - /// 服务项目台账查询请求 + /// 服务项目台账查询请求 /// 返回结果 - Task> GetPageAsync(QueryServiceProjectBaseDto QuerySearch); - + Task>> GetPageAsync(PageRequest querySearch); } diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/ServiceProject/ServiceProjectService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/ServiceProject/ServiceProjectService.cs index aa2e2c63..c48aced8 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/ServiceProject/ServiceProjectService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/ServiceProject/ServiceProjectService.cs @@ -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(); + user = _serviceProvider.GetRequiredService(); + saasService = _serviceProvider.GetRequiredService(); + } + + #region 保存 + /// + /// 保存 + /// + /// 服务项目详情 + /// 返回回执 + public async Task> Save(ServiceProjectBaseDto info) + { + return await InnerSave(info); + } + #endregion + + #region 保存内部方法 + /// + /// 保存内部方法 + /// + /// 服务项目详情 + /// 是否启用 + /// 返回派车Id + private async Task> InnerSave(ServiceProjectBaseDto info, bool isSetEnable = false) + { + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + + ServiceProjectBaseInfo entity = info.Adapt(); + + 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().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(entity).ExecuteCommand(); + } + else + { + var model = tenantDb.Queryable().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(entity).IgnoreColumns(it => new + { + it.UpdateTime, + it.UpdateBy, + it.UpdateUserName, + }).ExecuteCommandAsync(); + + } + + return DataResult.Success(entity.PK_ID); + } + #endregion + + #region 校验 + /// + /// 校验 + /// + /// 服务项目详情 + /// 操作类型枚举 + /// + private void ValidateServiceProject(ServiceProjectBaseInfo entity, TrackingOperateTypeEnum opTypeEnum) + { + /* + 1、服务项目代码和名称不能低于2个字符。 + 2、服务项目修改,需要判断当前服务项目是否关联服务流程。已关联的不能修改服务项目。 + 3、取消启用时,需要判断当前服务项目是否关联服务流程。已关联的不能取消启用。 + */ + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + + if (opTypeEnum == TrackingOperateTypeEnum.Save) + { + if (tenantDb.Queryable().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().Any(a => a.SERVICE_PROJECT_ID == entity.PK_ID)) + { + //当前服务项目已关联服务流程,不能取消启用 + throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectHasRelateWFActNotSetUnEnable))); + } + } + } + #endregion + + #region 保存并启用 + /// + /// 保存并启用 + /// + /// 服务项目详情 + /// 返回回执 + public async Task> SaveAndEnable([FromBody] ServiceProjectBaseDto info) + { + return await InnerSave(info, true); + } + #endregion + + #region 启用 + /// + /// 启用 + /// + /// 服务项目主键数组 + /// 返回回执 + public async Task> 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() + .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> rltList = new List>(); + + 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.Failed($"启用服务项目异常,原因:{ex.Message}"); + } + + return DataResult.Success(batchTotal); + } + #endregion + + #region 取消启用 + /// + /// 取消启用 + /// + /// 服务项目主键数组 + /// 返回回执 + public async Task> 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() + .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> rltList = new List>(); + + 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.Failed($"取消启用服务项目异常,原因:{ex.Message}"); + } + + return DataResult.Success(batchTotal); + } + #endregion + + #region 删除 + /// + /// 删除 + /// + /// 服务项目主键数组 + /// 返回回执 + public async Task> 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() + .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> rltList = new List>(); + + 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.Failed($"删除服务项目异常,原因:{ex.Message}"); + } + + return DataResult.Success(batchTotal); + } + #endregion + + #region 处理服务项目内部方法 + /// + /// 处理服务项目内部方法 + /// + /// 服务项目详情 + /// 操作类型 + /// 返回回执 + private async Task> 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(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(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(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.Failed($"执行失败,原因:{ex.Message}"); + } + + return DataResult.Success(name); + } + #endregion + + #region 获取服务项目详情 + /// + /// 获取服务项目详情 + /// + /// 服务项目主键 + /// 返回回执 + public async Task> GetInfo(string pkId) + { + var model = InnerGetInfo(pkId); + + var showModel = model.Adapt(); + + return DataResult.Success(showModel); + } + #endregion + + #region 单票查询 + /// + /// 单票查询 + /// + /// 状态主键 + 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().First(a => a.PK_ID == id); + + if (model == null) + { + //服务项目获取失败,服务项目信息不存在或已作废 + throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuEntityNull))); + } + + return model; + } + #endregion + + #region 检索服务项目列表 + /// + /// 检索服务项目列表 + /// + /// 检索值 + /// 最大返回行数(默认15) + /// 返回回执 + public async Task>> QueryList([FromQuery] string queryItem, [FromQuery] int topNum = 15) + { + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + + var list = await tenantDb.Queryable().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>(); + + return DataResult>.Success(rltList); + } + #endregion + + #region 服务项目台账查询 + /// + /// 服务项目台账查询 + /// + /// 服务项目台账查询请求 + /// 返回结果 + public async Task>> GetPageAsync(PageRequest querySearch) + { + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + + List whereList = null; + + ServiceProjectBaseQueryExtDto otherQueryCondition = new ServiceProjectBaseQueryExtDto(); + + whereList = GetPageCondition(querySearch, out otherQueryCondition); + + + var query = tenantDb.Queryable() + .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 resultList = new List(); + + if (result.Data.Count > 0) + { + resultList = result.Data.Adapt>(); + } + + return DataResult>.PageList(result.Count, resultList, MultiLanguageConst.DataQuerySuccess); + } + #endregion + + #region 获取台账查询条件 + /// + /// 获取台账查询条件 + /// + /// 原始查询条件 + /// 其他查询条件 + /// + private List GetPageCondition(PageRequest querySearch, out ServiceProjectBaseQueryExtDto queryExt) + { + List whereList = null; + + queryExt = new ServiceProjectBaseQueryExtDto(); + + if (!string.IsNullOrWhiteSpace(querySearch.OtherQueryCondition)) + { + queryExt = JsonConvert.DeserializeObject(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 } } diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/ServiceProject/StatusSkuBaseService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/ServiceProject/StatusSkuBaseService.cs index 4e53f621..4e2959ff 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/ServiceProject/StatusSkuBaseService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/ServiceProject/StatusSkuBaseService.cs @@ -52,7 +52,7 @@ namespace DS.WMS.Core.Op.Method /// /// 状态详情 /// 返回回执 - public async Task> Save([FromBody] StatusSkuBaseDto info) + public async Task> Save(StatusSkuBaseDto info) { return await InnerSave(info); } @@ -569,7 +569,7 @@ namespace DS.WMS.Core.Op.Method /// /// 状态台账查询 /// - /// 状态台账查询请求 + /// 状态台账查询请求 /// 返回结果 public async Task>> 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) diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/Mapper/AddTaskPlatMapsterSetup.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/Mapper/AddTaskPlatMapsterSetup.cs index 4eb67a6e..9c96b983 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/Mapper/AddTaskPlatMapsterSetup.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/Mapper/AddTaskPlatMapsterSetup.cs @@ -855,7 +855,7 @@ namespace DS.WMS.Core.TaskPlat.Dtos.Mapper { TypeAdapterConfig.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.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);