// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
#nullable disable
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using PVDEMCS.Services.Models;

namespace PVDEMCS.Services.Repositories.Entities;

public partial class EFContext : DbContext
{
    private IConfiguration configuration;

    public EFContext()
    {
        configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build();
    }

    public EFContext(DbContextOptions<EFContext> options)
        : base(options)
    {
    }

    public virtual DbSet<DeviceInfoEntity> DeviceInfos { get; set; }

    public virtual DbSet<DevicePointEntity> DevicePoints { get; set; }

    public virtual DbSet<EquipmentInfoEntity> EquipmentInfos { get; set; }

    public virtual DbSet<EquipmentRecordEntity> EquipmentRecords { get; set; }

    public virtual DbSet<EquipmentRecordDayTotalEntity> EquipmentRecordDayTotals { get; set; }

    public virtual DbSet<EquipmentRecordTotalEntity> EquipmentRecordTotals { get; set; }

    public virtual DbSet<SysConfigEntity> SysConfigs { get; set; }

    public virtual DbSet<SysUserEntity> SysUsers { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseMySql(configuration.GetConnectionString("MySqlConnection"), Microsoft.EntityFrameworkCore.ServerVersion.Parse("8.0.34-mysql"));

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder
            .UseCollation("utf8mb4_0900_ai_ci")
            .HasCharSet("utf8mb4");

        modelBuilder.Entity<DeviceInfoEntity>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("device_info", tb => tb.HasComment("PLC控制器"));

            entity.Property(e => e.Activated)
                .HasDefaultValueSql("b'1'")
                .HasComment("控制器状态,1：启用，0：停用");
            entity.Property(e => e.CreateAt).HasComment("创建时间");
            entity.Property(e => e.CreateBy).HasComment("创建者");
            entity.Property(e => e.DeleteAt).HasComment("删除时间");
            entity.Property(e => e.DeleteBy).HasComment("删除者");
            entity.Property(e => e.DeviceCode).HasComment("控制器编号");
            entity.Property(e => e.DeviceName).HasComment("控制器名称");
            entity.Property(e => e.Host).HasComment("控制器主机地址");
            entity.Property(e => e.IsDelete)
                .HasDefaultValueSql("b'0'")
                .HasComment("是否删除");
            entity.Property(e => e.Port).HasComment("控制器主机端口");
            entity.Property(e => e.Protocol).HasComment("控制器协议:PLC,HTTP,Socket");
            entity.Property(e => e.Remark).HasComment("备注");
            entity.Property(e => e.UpdateAt).HasComment("修改时间");
            entity.Property(e => e.UpdateBy).HasComment("修改者");
        });

        modelBuilder.Entity<DevicePointEntity>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("device_point", tb => tb.HasComment("PLC点位"));

            entity.Property(e => e.Activated)
                .HasDefaultValueSql("b'1'")
                .HasComment("PLC 点位是否启用 (1 启用, 0 禁用)");
            entity.Property(e => e.Address).HasComment("S7 数据存储地址，直连 存储区地址");
            entity.Property(e => e.CreateAt).HasComment("创建时间");
            entity.Property(e => e.CreateBy).HasComment("创建者");
            entity.Property(e => e.DeleteAt).HasComment("删除时间");
            entity.Property(e => e.DeleteBy).HasComment("删除者");
            entity.Property(e => e.DeviceId).HasComment("控制器Id");
            entity.Property(e => e.IsDelete).HasDefaultValueSql("b'0'").HasComment("是否删除");
            entity.Property(e => e.PointCode).HasComment("点位编号");
            entity.Property(e => e.PointName).HasComment("点位名称");
            entity.Property(e => e.Remark).HasComment("备注");
            entity.Property(e => e.DataType).HasComment("字段类型");
            entity.Property(e => e.UpdateAt).HasComment("修改时间");
            entity.Property(e => e.UpdateBy).HasComment("修改者");
        });

        modelBuilder.Entity<EquipmentInfoEntity>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("equipment_info", tb => tb.HasComment("设备信息"));

            entity.Property(e => e.Activated)
                .HasDefaultValueSql("b'1'")
                .HasComment("设备状态,1：启用，0：停用");
            entity.Property(e => e.CreateAt).HasComment("创建时间");
            entity.Property(e => e.CreateBy).HasComment("创建者");
            entity.Property(e => e.DeleteAt).HasComment("删除时间");
            entity.Property(e => e.DeleteBy).HasComment("删除者");
            entity.Property(e => e.EquipmentCode).HasComment("设备编码");
            entity.Property(e => e.EquipmentName).HasComment("设备名称");
            entity.Property(e => e.EquipmentType).HasComment("设备类型：Ionbond，Balzers，Cemecon");
            entity.Property(e => e.Model).HasComment("模式：Auto 自动；Manual手动");
            entity.Property(e => e.IsAlarm).HasComment("是否报警：1 报警；0 不报警（model为Auto）");
            entity.Property(e => e.OrdrNo).HasComment("排序号");
            entity.Property(e => e.IsDelete)
                .HasDefaultValueSql("b'0'")
                .HasComment("是否删除");
            entity.Property(e => e.Remark).HasComment("备注");
            entity.Property(e => e.UpdateAt).HasComment("修改时间");
            entity.Property(e => e.UpdateBy).HasComment("修改者");
        });

        modelBuilder.Entity<EquipmentRecordEntity>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("equipment_record", tb => tb.HasComment("设备状态记录明显"));

            entity.Property(e => e.CreateAt).HasComment("创建时间");
            entity.Property(e => e.CreateBy).HasComment("创建者");
            entity.Property(e => e.EndTime).HasComment("设备名称");
            entity.Property(e => e.EquipmentId).HasComment("设备id");
            entity.Property(e => e.StartTime).HasComment("设备编码");
            entity.Property(e => e.State).HasComment("设备状态,1：运行，2：待机，3：报警");
            entity.Property(e => e.UpdateAt).HasComment("修改时间");
            entity.Property(e => e.UpdateBy).HasComment("修改者");
        });

        modelBuilder.Entity<EquipmentRecordDayTotalEntity>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("equipment_record_day_total", tb => tb.HasComment("设备状态记录日统计\r\n"));

            entity.Property(e => e.CreateAt).HasComment("创建时间");
            entity.Property(e => e.CreateBy).HasComment("创建者");
            entity.Property(e => e.EquipmentId).HasComment("设备Id");
            entity.Property(e => e.FurnaceNum).HasComment("开炉次数");
            entity.Property(e => e.TotalAlarmTime).HasComment("总报警时长");
            entity.Property(e => e.TotalStopTime).HasComment("总待机时长");
            entity.Property(e => e.TotalDay).HasComment("日期");
            entity.Property(e => e.TotalRunningTime).HasComment("总运行时长");
            entity.Property(e => e.UpdateAt).HasComment("修改时间");
            entity.Property(e => e.UpdateBy).HasComment("修改者");
        });

        modelBuilder.Entity<EquipmentRecordTotalEntity>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("equipment_record_total", tb => tb.HasComment("设备状态记录统计\r\n"));

            entity.Property(e => e.CreateAt).HasComment("创建时间");
            entity.Property(e => e.CreateBy).HasComment("创建者");
            entity.Property(e => e.EquipmentId).HasComment("设备Id");
            entity.Property(e => e.FurnaceNum).HasComment("开炉次数");
            entity.Property(e => e.TotalAlarmTime).HasComment("总报警时长");
            entity.Property(e => e.TotalStopTime).HasComment("总待机时长");
            entity.Property(e => e.TotalRunningTime).HasComment("总运行时长");
            entity.Property(e => e.UpdateAt).HasComment("修改时间");
            entity.Property(e => e.UpdateBy).HasComment("修改者");
        });

        modelBuilder.Entity<SysConfigEntity>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("sys_config", tb => tb.HasComment("参数配置表"));

            entity.Property(e => e.Id).HasComment("参数主键");
            entity.Property(e => e.ConfigKey)
                .HasDefaultValueSql("''")
                .HasComment("参数键名");
            entity.Property(e => e.ConfigName)
                .HasDefaultValueSql("''")
                .HasComment("参数名称");
            entity.Property(e => e.ConfigType)
                .HasDefaultValueSql("'N'")
                .IsFixedLength()
                .HasComment("系统内置（Y是 N否）");
            entity.Property(e => e.ConfigValue)
                .HasDefaultValueSql("''")
                .HasComment("参数键值");
            entity.Property(e => e.CreateAt).HasComment("创建时间");
            entity.Property(e => e.CreateBy)
                .HasDefaultValueSql("''")
                .HasComment("创建者");
            entity.Property(e => e.DeleteAt).HasComment("删除时间");
            entity.Property(e => e.DeleteBy).HasComment("删除者");
            entity.Property(e => e.IsDelete)
                .HasDefaultValueSql("b'0'")
                .HasComment("是否删除");
            entity.Property(e => e.Remark).HasComment("备注");
            entity.Property(e => e.UpdateAt).HasComment("更新时间");
            entity.Property(e => e.UpdateBy)
                .HasDefaultValueSql("''")
                .HasComment("更新者");
        });

        modelBuilder.Entity<SysUserEntity>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("sys_user", tb => tb.HasComment("用户信息表"));

            entity.Property(e => e.Id).HasComment("用户ID");
            entity.Property(e => e.Avatar)
                .HasDefaultValueSql("''")
                .HasComment("头像地址");
            entity.Property(e => e.CreateAt).HasComment("创建时间");
            entity.Property(e => e.CreateBy)
                .HasDefaultValueSql("''")
                .HasComment("创建者");
            entity.Property(e => e.DeleteAt).HasComment("删除时间");
            entity.Property(e => e.DeleteBy).HasComment("删除者");
            entity.Property(e => e.Email)
                .HasDefaultValueSql("''")
                .HasComment("用户邮箱");
            entity.Property(e => e.IsDelete)
                .HasDefaultValueSql("b'0'")
                .HasComment("是否删除");
            entity.Property(e => e.LoginDate).HasComment("最后登录时间");
            entity.Property(e => e.LoginIp)
                .HasDefaultValueSql("''")
                .HasComment("最后登录IP");
            entity.Property(e => e.NickName).HasComment("用户昵称");
            entity.Property(e => e.Password)
                .HasDefaultValueSql("''")
                .HasComment("密码");
            entity.Property(e => e.Phonenumber)
                .HasDefaultValueSql("''")
                .HasComment("手机号码");
            entity.Property(e => e.Remark).HasComment("备注");
            entity.Property(e => e.Sex)
                .HasDefaultValueSql("'0'")
                .IsFixedLength()
                .HasComment("用户性别（0男 1女 2未知）");
            entity.Property(e => e.Activated)
                .HasDefaultValueSql("b'1'")
                .IsFixedLength()
                .HasComment("帐号状态（1：启用，0：停用）");
            entity.Property(e => e.UpdateAt).HasComment("更新时间");
            entity.Property(e => e.UpdateBy)
                .HasDefaultValueSql("''")
                .HasComment("更新者");
            entity.Property(e => e.UserName).HasComment("用户账号");
            entity.Property(e => e.UserType)
                .HasDefaultValueSql("'admin'")
                .HasComment("用户类型（admin系统用户,normal普通用户）");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}