init commit

This commit is contained in:
路 范
2022-03-30 17:54:33 +08:00
parent df01841625
commit 904bdd16cd
500 changed files with 217251 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
using Furion.DependencyInjection;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Localization;
using RoadFlow.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RoadFlow.Data
{
public class WorkDate: RoadFlowRepository<RoadFlow.Model.rf_workdate>, IWorkDate, ITransient
{
/// <summary>
/// 得到一个时间加上几天之后的工作时间
/// </summary>
/// <param name="days">天数</param>
/// <param name="dt">时间</param>
/// <returns></returns>
public DateTime GetWorkDateTime(double days, DateTime? dt = null)
{
DateTime dateTime = dt != null && dt.HasValue ? dt.Value : Utility.DateExtensions.Now;
var yearList = GetYearList(dateTime.Year);
int max = (int)Math.Floor(days);
for (int i = 0; i < max; i++)
{
if (yearList.Exists(p => p.WorkDay == dateTime.AddDays(i).Date && p.IsWork == 0))
{
max++;
}
}
return dateTime.AddDays(max + (days - Math.Floor(days)));
}
/// <summary>
/// 得到一年所有工作日
/// </summary>
/// <returns></returns>
public List<Model.rf_workdate> GetYearList(int year)
{
string cacheKey = CACHEKEY + "_" + year.ToString();
object obj = _memoryCache.Get(cacheKey);
if (null == obj)
{
List<Model.rf_workdate> workDates = db.Queryable<Model.rf_workdate>()
.Where("YEAR(WorkDay)="+ year)
.ToList();
_memoryCache.Set(CACHEKEY, workDates);
return workDates;
/*
using (var db = new DataContext())
{
string sql = db.IsOracle ? "SELECT * FROM RF_WorkDate WHERE TO_CHAR(WorkDay,'yyyy')=" + year :
db.IsPostgreSql ? "select * from rf_workdate where extract(year from WorkDay)=" + year :
"SELECT * FROM RF_WorkDate WHERE YEAR(WorkDay)=" + year;
var workDates = db.Query<Model.WorkDate>(sql);
_memoryCache.set(CACHEKEY, workDates);
return workDates;
}*/
}
else
{
return (List<Model.rf_workdate>)obj;
}
}
}
}