You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.7 KiB
C#

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
{
/// <summary>
/// 文件服务
/// </summary>
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 创建
/// <summary>
/// 创建
/// </summary>
/// <param name="file">文件</param>
/// <returns></returns>
public async Task<FileDO> Insert(FileDO file)
{
return await InsertDO(file);
}
/// <summary>
/// 创建插入
/// </summary>
/// <param name="file">文件</param>
/// <returns></returns>
public async Task<FileDO> InsertDO(FileDO file)
{
await Db.Insertable<FileDO>(file).SplitTable().ExecuteCommandAsync();
file.Data = null;
return file;
}
/// <summary>
/// 创建检查
/// </summary>
/// <param name="file">文件</param>
/// <returns></returns>
public string InsertCheck(FileDO file)
{
var _MaxId = Db.Queryable<FileDO>().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 查询
/// <summary>
/// 查询
/// </summary>
/// <param name="id">编号</param>
/// <returns></returns>
public async Task<FileDO> Get(string id)
{
return await GetDO(id);
}
/// <summary>
/// 查询数据
/// </summary>
/// <param name="id">编号</param>
/// <returns></returns>
public async Task<FileDO> GetDO(string id)
{
SplitDateId SplitDateId = new SplitDateId(id, 2);
return await Db.Queryable<FileDO>().Where(x => x.Id == id).SplitTable(SplitDateId.StartDate, SplitDateId.EndDate).SingleAsync();
}
#endregion
}
}