using CommonModel;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZhongLianModel;
using ZhongLianInterface;
namespace ZhongLianService
{
///
/// 文件服务
///
public class DriveService : IDriveService
{
public DriveService(IServiceProvider services, ISqlSugarClient sqlSugarClient)
{
Services = services;
Db = sqlSugarClient;
Db.CodeFirst.SplitTables().InitTables(typeof(FileDO));
}
private readonly IServiceProvider Services;
private readonly ISqlSugarClient Db;
#region 创建
///
/// 创建
///
/// 文件
///
public async Task Insert(FileDO file)
{
return await InsertDO(file);
}
///
/// 创建插入
///
/// 文件
///
public async Task InsertDO(FileDO file)
{
await Db.Insertable(file).SplitTable().ExecuteCommandAsync();
file.Data = null;
return file;
}
///
/// 创建检查
///
/// 文件
///
public string InsertCheck(FileDO file)
{
var _MaxId = Db.Queryable().SplitTable(DateTime.Today, DateTime.Today.AddDays(1)).Max(x => x.Id);
if (string.IsNullOrEmpty(_MaxId))
{
file.Id = $"FL{DateTime.Now.ToString("yyyyMMdd")}000001";
}
else
{
file.Id = $"FL{DateTime.Now.ToString("yyyyMMdd")}{(Convert.ToInt32(_MaxId.Substring(10, 6)) + 1).ToString().PadLeft(6, '0')}";
}
file.CreateDate = DateTime.Now;
return "";
}
#endregion
#region 查询
///
/// 查询
///
/// 编号
///
public async Task Get(string id)
{
return await GetDO(id);
}
///
/// 查询数据
///
/// 编号
///
public async Task GetDO(string id)
{
SplitDateId SplitDateId = new SplitDateId(id, 2);
return await Db.Queryable().Where(x => x.Id == id).SplitTable(SplitDateId.StartDate, SplitDateId.EndDate).SingleAsync();
}
#endregion
}
}