To find the state of this project's repository at the time of any of these versions, check out the tags.
HistoryDB.cs 1.97 KB
using FLY.OBJComponents.Server;
using FLY.OBJComponents.Server.Model;
using SQLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FLY.FeedbackRenZiJia.Server.Model
{
    public class HistoryDb
    {
        DbModel dbModel;
        public BufferSQLite<Lc_ThickHeat, Db_ThickHeat> ThickHeatBuffer;
        public BufferError ErrorBuffer;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dbModel"></param>
        public void Init(DbModel dbModel)
        {
            this.dbModel = dbModel;
            ThickHeatBuffer = new BufferSQLite<Lc_ThickHeat, Db_ThickHeat>();
            ThickHeatBuffer.Init(dbModel.TbThickHeat,
                (lc) => Lc_AutoMapperProfile.Mapper.Map<Db_ThickHeat>(lc),
                (db) => Lc_AutoMapperProfile.Mapper.Map<Lc_ThickHeat>(db)
                );
            ErrorBuffer = new OBJComponents.Server.BufferError();
            ErrorBuffer.Init(dbModel.TbError);
        }

        /// <summary>
        /// 按时间删除数据库
        /// </summary>
        /// <param name="month"></param>
        public void KeepDBSize(int month)
        {
            if (month <= 3)
                month = 3;

            DateTime del_time = DateTime.Now - TimeSpan.FromDays(month * 30);
            string det_time_str = del_time.ToStringOfSQLiteFieldType();
            List<string> sqls = new List<string>();


            sqls.Add(
                $"DELETE FROM {dbModel.TbThickHeat.TableName}" +
                $" WHERE Time < {det_time_str}");

            sqls.Add(
                $"DELETE FROM {dbModel.TbError.TableName}" +
                $" WHERE Time < {det_time_str}");
            

            dbModel.sqliteHelper.QueryTran(sqls);

        }

        /// <summary>
        /// 
        /// </summary>
        public void AddThickHeat(
            Lc_ThickHeat thickHeat)
        {
            ThickHeatBuffer.Add(thickHeat);
        }

    }
}