120 lines
3.8 KiB
C#
120 lines
3.8 KiB
C#
using LearningOfficer.OA.Common.Enums;
|
||
using LearningOfficer.OA.Common.Exceptions;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using UserCenter.Model.Common;
|
||
using UserCenter.Model.Enum;
|
||
|
||
namespace LearningOfficer.OA.Common.Helpers
|
||
{
|
||
/// <summary>
|
||
/// 解决方案工具年级转换帮助类
|
||
/// </summary>
|
||
public class SolutionToolGradeHelper
|
||
{
|
||
public static SolutionSemesterEnum ConvertToSolutionToolGradeEnum(string gradeLevel, int graduationYear)
|
||
{
|
||
var grade = GradeHelper.GetGradeByStudentGradeBase(gradeLevel, graduationYear);
|
||
if (string.IsNullOrWhiteSpace(grade) || grade.Contains("届") || gradeLevel == GradeLevelEnum.小.ToString())
|
||
{
|
||
return SolutionSemesterEnum.None;
|
||
}
|
||
|
||
var gradeValue = GetGradeValue(gradeLevel, graduationYear);
|
||
if (gradeValue == 0)
|
||
{
|
||
return SolutionSemesterEnum.None;
|
||
}
|
||
|
||
var semesterValue = GetSemesterValue();
|
||
|
||
|
||
return (SolutionSemesterEnum)(gradeValue + semesterValue);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 获取年级的基础值
|
||
/// </summary>
|
||
/// <param name="gradeLevel"></param>
|
||
/// <param name="graduationYear"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="BusinessException"></exception>
|
||
private static int GetGradeValue(string gradeLevel, int graduationYear)
|
||
{
|
||
var now = DateTime.Now;
|
||
|
||
// 获取当前年份与毕业年份的差值
|
||
var diffYear = graduationYear - now.Year;
|
||
if (diffYear < 0 || (diffYear == 0 && now.Date > new DateTime(now.Year, 8, 1)))
|
||
{
|
||
// 如果毕业年份小于当前年份,或者毕业年份为当前年份但当前日期在8月1日之后,代表已毕业,则返回0
|
||
return 0;
|
||
}
|
||
// 取绝对值
|
||
diffYear = Math.Abs(diffYear);
|
||
if (now.Date > new DateTime(now.Year, 8, 1))
|
||
{
|
||
// 如果当前日期在8月31日之后,说明已经进入新学年
|
||
diffYear--;
|
||
}
|
||
diffYear = diffYear * 10;
|
||
|
||
var baseYearValue = 0;
|
||
switch (gradeLevel)
|
||
{
|
||
case "初":
|
||
baseYearValue = 90;
|
||
break;
|
||
case "高":
|
||
baseYearValue = 120;
|
||
break;
|
||
default:
|
||
throw new BusinessException("未知年级值,年级转换值失败");
|
||
}
|
||
// 获取年级值
|
||
return baseYearValue - diffYear;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取学期阶段基础值
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private static int GetSemesterValue()
|
||
{
|
||
DateTime now = DateTime.Today;
|
||
int month = now.Month;
|
||
int day = now.Day;
|
||
|
||
// 1月直接返回4
|
||
if (month == 1)
|
||
{
|
||
return 2;
|
||
}
|
||
// 2月、3月 或 4月1-25日 返回1
|
||
else if ((month == 2 || month == 3) || (month == 4 && day <= 25))
|
||
{
|
||
return 3;
|
||
}
|
||
// 4月26日-7月31日 返回2
|
||
else if ((month == 4 && day >= 26) || (month >= 5 && month <= 7))
|
||
{
|
||
return 4;
|
||
}
|
||
// 8月、 9月、10月 或 11月1-8日 返回3
|
||
else if ((month == 8 || month == 9 || month == 10) || (month == 11 && day <= 8))
|
||
{
|
||
return 1;
|
||
}
|
||
// 剩余情况(11月9日-12月31日)返回4
|
||
else
|
||
{
|
||
return 2;
|
||
}
|
||
}
|
||
}
|
||
}
|