From 4e3a00523de26f61807f5a6132ee9b9d9e7caaca Mon Sep 17 00:00:00 2001 From: shangzhongyuan Date: Mon, 21 Jul 2025 18:01:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UnderlyingModule/UnderlyingHelper.cs | 47 +++++-------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/YLErpDAL/Modules/UnderlyingModule/UnderlyingHelper.cs b/YLErpDAL/Modules/UnderlyingModule/UnderlyingHelper.cs index 17936953..48fb0846 100644 --- a/YLErpDAL/Modules/UnderlyingModule/UnderlyingHelper.cs +++ b/YLErpDAL/Modules/UnderlyingModule/UnderlyingHelper.cs @@ -253,43 +253,22 @@ namespace YLErp.Modules.UnderlyingModule /// 返回3.12格式 public static double? getYearTerm(DateTime? calcDate, DateTime? sourceDate) { - if (!calcDate.HasValue) + if (!calcDate.HasValue || !sourceDate.HasValue) + return null; + + if (calcDate.Value > sourceDate.Value) + throw new ArgumentException("计算日期必须小于原日期", nameof(calcDate)); + + int totalMonths = (sourceDate.Value.Year - calcDate.Value.Year) * 12 + + (sourceDate.Value.Month - calcDate.Value.Month); + + if (sourceDate.Value.Day < calcDate.Value.Day) { - return null;//不限 + totalMonths--; } - if (sourceDate.HasValue) - { - if (calcDate > sourceDate) - { - throw new ArgumentException("计算日期必须小于原日期", nameof(calcDate)); - } - //计算sourceDate与calcDate年限差 - int yearDiff = sourceDate.Value.Year - calcDate.Value.Year; - int monthDiff = sourceDate.Value.Month - calcDate.Value.Month; - int dayDiff = sourceDate.Value.Day - calcDate.Value.Day; - // 如果月差为负,说明还没到整年,需要向前借一年 - if (monthDiff < 0) - { - yearDiff -= 1; - monthDiff += 12; - } - - // 如果天数为负,说明还没到整月,需要向前借一个月 - if (dayDiff < 0) - { - monthDiff -= 1; - if (monthDiff < 0) - { - yearDiff -= 1; - monthDiff += 12; - } - } - - double yearTerm = yearDiff + monthDiff / 12.0; - return yearTerm; - } - return null;//不限 + double yearTerm = totalMonths / 12.0; + return yearTerm; } /// /// 根据标的发行年限和剩余期限计算适用保证金率