From 6ab4c28d4d7d86fdbd7b117ff9597801c9e30f37 Mon Sep 17 00:00:00 2001 From: wxd <123@qq.com> Date: Thu, 21 Mar 2024 17:04:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CardBills/CardBillManager.cs | 4 +- .../CardRegisters/CardRegisterManager.cs | 10 ++- .../CardTypes/CardTypeManager.cs | 4 +- src/Shentun.Peis.Domain/DataHelper.cs | 63 +++++++++++++------ .../ItemTypes/ItemTypeManager.cs | 6 +- src/Shentun.Peis.Domain/Items/ItemManager.cs | 16 ++--- 6 files changed, 64 insertions(+), 39 deletions(-) diff --git a/src/Shentun.Peis.Domain/CardBills/CardBillManager.cs b/src/Shentun.Peis.Domain/CardBills/CardBillManager.cs index ef74f64..af9cb76 100644 --- a/src/Shentun.Peis.Domain/CardBills/CardBillManager.cs +++ b/src/Shentun.Peis.Domain/CardBills/CardBillManager.cs @@ -34,9 +34,9 @@ namespace Shentun.Peis.CardBills ) { DataHelper.CheckEntityIsNull(entity); - DataHelper.CheckGuidIsNull(entity.CardRegisterId, "卡登记编号"); + DataHelper.CheckGuidIsDefaultValue(entity.CardRegisterId, "卡登记编号"); DataHelper.CheckStringIsNull(entity.PayModeId, "支付方式"); - DataHelper.CheckDecimalIsNull(entity.BillMoney, "记账金额"); + DataHelper.CheckDecimalIsGeaterThanZero(entity.BillMoney, "记账金额"); return new CardBill(GuidGenerator.Create()) { diff --git a/src/Shentun.Peis.Domain/CardRegisters/CardRegisterManager.cs b/src/Shentun.Peis.Domain/CardRegisters/CardRegisterManager.cs index 9b5e06c..4bbfbeb 100644 --- a/src/Shentun.Peis.Domain/CardRegisters/CardRegisterManager.cs +++ b/src/Shentun.Peis.Domain/CardRegisters/CardRegisterManager.cs @@ -97,7 +97,7 @@ namespace Shentun.Peis.CardRegisters public async Task UpdateActive(CardRegister entity, char isActive) { DataHelper.CheckEntityIsNull(entity); - DataHelper.CheckCharIsNull(isActive, "使用标志", true); + DataHelper.CheckCharIsYOrN(isActive, "使用标志"); if (isActive == 'N') { @@ -126,7 +126,6 @@ namespace Shentun.Peis.CardRegisters public CardBill CreateCardBill(CardRegister entity, string payModeId, char billFlag, decimal amount) { DataHelper.CheckEntityIsNull(entity); - DataHelper.CheckCharIsNull(billFlag, "记账标志"); if (amount == 0) { throw new ArgumentException("金额等于0"); @@ -164,7 +163,6 @@ namespace Shentun.Peis.CardRegisters public void AddCardBill(CardRegister entity, string payModeId, char billFlag, decimal amount) { DataHelper.CheckEntityIsNull(entity); - DataHelper.CheckCharIsNull(billFlag, "记账标志"); if (amount == 0) { throw new ArgumentException("金额等于0"); @@ -198,9 +196,9 @@ namespace Shentun.Peis.CardRegisters DataHelper.CheckStringIsNull(entity.CustomerName, "领用者"); DataHelper.CheckStringIsNull(entity.IdNo, "身份证号"); DataHelper.CheckStringIsNull(entity.IdNo, "手机号"); - DataHelper.CheckGuidIsNull(entity.CardTypeId, "卡类型"); - DataHelper.CheckGuidIsNull(entity.OrganizationUnitId, "体检中心"); - DataHelper.CheckCharIsNull(entity.IsActive, "使用标志", true); + DataHelper.CheckGuidIsDefaultValue(entity.CardTypeId, "卡类型"); + DataHelper.CheckGuidIsDefaultValue(entity.OrganizationUnitId, "体检中心"); + DataHelper.CheckCharIsYOrN(entity.IsActive, "使用标志"); } } } diff --git a/src/Shentun.Peis.Domain/CardTypes/CardTypeManager.cs b/src/Shentun.Peis.Domain/CardTypes/CardTypeManager.cs index 805aa04..19518bc 100644 --- a/src/Shentun.Peis.Domain/CardTypes/CardTypeManager.cs +++ b/src/Shentun.Peis.Domain/CardTypes/CardTypeManager.cs @@ -95,8 +95,8 @@ namespace Shentun.Peis.CardTypes private void Verify(CardType entity) { DataHelper.CheckStringIsNull(entity.DisplayName, "名称"); - DataHelper.CheckIntIsNull(entity.Discount, "折扣率"); - DataHelper.CheckIntIsNull(entity.ExpiryDay, "有效期"); + DataHelper.CheckIntIsGeaterThanZero(entity.Discount, "折扣率"); + DataHelper.CheckIntIsGeaterThanZero(entity.ExpiryDay, "有效期"); } diff --git a/src/Shentun.Peis.Domain/DataHelper.cs b/src/Shentun.Peis.Domain/DataHelper.cs index 22f98b6..3f5aacb 100644 --- a/src/Shentun.Peis.Domain/DataHelper.cs +++ b/src/Shentun.Peis.Domain/DataHelper.cs @@ -392,25 +392,21 @@ namespace Shentun.Peis } } + #region 验证char类型参数 /// - /// 数据检查 字符 + /// 验证char类型参数是否为null /// /// 需要验证的值 /// 字段名称 - /// 默认false(true 验证为Y跟N false 不验证) /// 异常提示后缀 /// - public static void CheckCharIsNull(char? value, string parameterName, bool IsBoolValue = false, string ExceptionMessage = "不能为空") + public static void CheckCharIsNull(char? value, string parameterName, string ExceptionMessage = "不能为空") { - if (value == null || value == '0') + if (value == null) { throw new ArgumentException($"{parameterName}{ExceptionMessage}"); } - if (IsBoolValue && value != 'Y' && value != 'N') - { - throw new ArgumentException($"{parameterName}参数为:{value},是无效值"); - } } /// @@ -433,27 +429,26 @@ namespace Shentun.Peis /// /// 需要验证的值 /// 字段名称 - /// 默认false(true 验证为Y跟N false 不验证) - /// 异常提示后缀 /// - public static void CheckCharValidValue(char value, string parameterName, string ExceptionMessage = "是无效值,只能为Y跟N") + public static void CheckCharIsYOrN(char value, string parameterName) { if (value != 'Y' && value != 'N') { - throw new ArgumentException($"{parameterName}参数为:{value},是无效值"); + throw new ArgumentException($"{parameterName}参数为:{value},是无效值,只能为Y跟N"); } } + #endregion /// - /// 数据检查 整型 + /// 验证Int类型数据是否>0 /// /// 需要验证的值 /// 字段名称 /// 异常提示后缀 /// - public static void CheckIntIsNull(int? value, string parameterName, string ExceptionMessage = "不能为空") + public static void CheckIntIsGeaterThanZero(int value, string parameterName, string ExceptionMessage = "只能为大于0的值") { - if (value == null || value == 0) + if (value > 0) { throw new ArgumentException($"{parameterName}{ExceptionMessage}"); } @@ -461,7 +456,7 @@ namespace Shentun.Peis /// - /// 数据检查 Guid + /// 验证Guid数据是否为null /// /// 需要验证的值 /// 字段名称 @@ -469,12 +464,44 @@ namespace Shentun.Peis /// public static void CheckGuidIsNull(Guid? value, string parameterName, string ExceptionMessage = "不能为空") { - if (value == null || value == Guid.Empty) + if (value == null) + { + throw new ArgumentException($"{parameterName}{ExceptionMessage}"); + } + } + + + /// + /// 验证Guid数据是否为默认值00000000-0000-0000-0000-000000000000 + /// + /// 需要验证的值 + /// 字段名称 + /// 异常提示后缀 + /// + public static void CheckGuidIsDefaultValue(Guid? value, string parameterName, string ExceptionMessage = "不能为默认值00000000-0000-0000-0000-000000000000") + { + if (value == Guid.Empty) + { + throw new ArgumentException($"{parameterName}{ExceptionMessage}"); + } + } + + /// + ///验证decimal类型数据大于0 + /// + /// 需要验证的值 + /// 字段名称 + /// 异常提示后缀 + /// + public static void CheckDecimalIsGeaterThanZero(decimal value, string parameterName, string ExceptionMessage = "值只能大于0") + { + if (value > 0) { throw new ArgumentException($"{parameterName}{ExceptionMessage}"); } } + /// /// 数据检查 decimal /// @@ -484,7 +511,7 @@ namespace Shentun.Peis /// public static void CheckDecimalIsNull(decimal? value, string parameterName, string ExceptionMessage = "不能为空") { - if (value == null || value == 0) + if (value == null ) { throw new ArgumentException($"{parameterName}{ExceptionMessage}"); } diff --git a/src/Shentun.Peis.Domain/ItemTypes/ItemTypeManager.cs b/src/Shentun.Peis.Domain/ItemTypes/ItemTypeManager.cs index 5db548d..d91adc0 100644 --- a/src/Shentun.Peis.Domain/ItemTypes/ItemTypeManager.cs +++ b/src/Shentun.Peis.Domain/ItemTypes/ItemTypeManager.cs @@ -97,9 +97,9 @@ namespace Shentun.Peis.ItemTypes DataHelper.CheckEntityIsNull(entity); DataHelper.CheckStringIsNull(entity.DisplayName, "名称"); - DataHelper.CheckGuidIsNull(entity.GuidTypeId, "指引类别"); - DataHelper.CheckCharIsNull(entity.IsMergeAsbitem, "是否合并组合项目", true); - DataHelper.CheckGuidIsNull(entity.MedicalReportTypeId, "体检报告类别"); + DataHelper.CheckGuidIsDefaultValue(entity.GuidTypeId, "指引类别"); + DataHelper.CheckCharIsYOrN(entity.IsMergeAsbitem, "是否合并组合项目"); + DataHelper.CheckGuidIsDefaultValue(entity.MedicalReportTypeId, "体检报告类别"); } diff --git a/src/Shentun.Peis.Domain/Items/ItemManager.cs b/src/Shentun.Peis.Domain/Items/ItemManager.cs index 1f2ba6f..3532a0b 100644 --- a/src/Shentun.Peis.Domain/Items/ItemManager.cs +++ b/src/Shentun.Peis.Domain/Items/ItemManager.cs @@ -135,14 +135,14 @@ namespace Shentun.Peis.Items { DataHelper.CheckEntityIsNull(entity); DataHelper.CheckStringIsNull(entity.DisplayName, "名称"); - DataHelper.CheckGuidIsNull(entity.ItemTypeId, "项目类别"); - DataHelper.CheckDecimalIsNull(entity.Price, "价格"); - DataHelper.CheckCharIsNull(entity.IsProduceSummary, "是否生成小结", true); - DataHelper.CheckCharIsNull(entity.IsNameIntoSummary, "名称是否进入小结", true); - DataHelper.CheckCharIsNull(entity.IsDiagnosisFunction, "是否启用诊断函数", true); - DataHelper.CheckCharIsNull(entity.IsCalculationItem, "是否计算项目", true); - DataHelper.CheckCharIsNull(entity.IsContinueProcess, "是否继续处理", true); - DataHelper.CheckCharIsNull(entity.IsActive, "是否启用", true); + DataHelper.CheckGuidIsDefaultValue(entity.ItemTypeId, "项目类别"); + + DataHelper.CheckCharIsYOrN(entity.IsProduceSummary, "是否生成小结"); + DataHelper.CheckCharIsYOrN(entity.IsNameIntoSummary, "名称是否进入小结"); + DataHelper.CheckCharIsYOrN(entity.IsDiagnosisFunction, "是否启用诊断函数"); + DataHelper.CheckCharIsYOrN(entity.IsCalculationItem, "是否计算项目"); + DataHelper.CheckCharIsYOrN(entity.IsContinueProcess, "是否继续处理"); + DataHelper.CheckCharIsYOrN(entity.IsActive, "是否启用"); }