From 4dd08f59fde4842adb88987560bfbe266450419f Mon Sep 17 00:00:00 2001 From: zhangyousheng Date: Sat, 29 Jul 2023 13:20:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=A7=AF=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/UserPoint.cs | 19 ++++ .../UserPointConfiguration.cs | 25 ++++++ .../20230729051855_AddUserPoint.Designer.cs | 90 +++++++++++++++++++ .../Migrations/20230729051855_AddUserPoint.cs | 35 ++++++++ ...erPointManagementDbContextModelSnapshot.cs | 32 +++++++ .../UserPointManagementDbContext.cs | 3 + .../Layouts/BasicLayout.razor | 7 ++ .../Pages/UserPoint/UserPoint.razor | 8 ++ 8 files changed, 219 insertions(+) create mode 100644 src/UserPointManagement.Model/Entities/UserPoint.cs create mode 100644 src/UserPointManagement.Persistence/EntityTypeConfigurations/UserPointConfiguration.cs create mode 100644 src/UserPointManagement.Persistence/Migrations/20230729051855_AddUserPoint.Designer.cs create mode 100644 src/UserPointManagement.Persistence/Migrations/20230729051855_AddUserPoint.cs create mode 100644 src/UserPointManagement.Web/Pages/UserPoint/UserPoint.razor diff --git a/src/UserPointManagement.Model/Entities/UserPoint.cs b/src/UserPointManagement.Model/Entities/UserPoint.cs new file mode 100644 index 0000000..b8b2470 --- /dev/null +++ b/src/UserPointManagement.Model/Entities/UserPoint.cs @@ -0,0 +1,19 @@ +namespace UserPointManagement.Model.Entities; + +public class UserPoint +{ + public long Id { get; set; } + + public int UserId { get; set; } + + public int Point { get; set; } + + public DateTime CreateTime { get; } + + public UserPoint(int userId, int point) + { + UserId = userId; + Point = point; + CreateTime = DateTime.Now; + } +} \ No newline at end of file diff --git a/src/UserPointManagement.Persistence/EntityTypeConfigurations/UserPointConfiguration.cs b/src/UserPointManagement.Persistence/EntityTypeConfigurations/UserPointConfiguration.cs new file mode 100644 index 0000000..d960f8f --- /dev/null +++ b/src/UserPointManagement.Persistence/EntityTypeConfigurations/UserPointConfiguration.cs @@ -0,0 +1,25 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using UserPointManagement.Model.Entities; + +namespace UserPointManagement.Persistence.EntityTypeConfigurations; + +public class UserPointConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.HasKey(e => e.Id); + + builder.Property(e => e.Id) + .HasComment("主键"); + + builder.Property(e => e.UserId) + .HasComment("用户Id"); + + builder.Property(e => e.Point) + .HasComment("积分"); + + builder.Property(e => e.CreateTime) + .HasComment("新增时间"); + } +} \ No newline at end of file diff --git a/src/UserPointManagement.Persistence/Migrations/20230729051855_AddUserPoint.Designer.cs b/src/UserPointManagement.Persistence/Migrations/20230729051855_AddUserPoint.Designer.cs new file mode 100644 index 0000000..c2b90c4 --- /dev/null +++ b/src/UserPointManagement.Persistence/Migrations/20230729051855_AddUserPoint.Designer.cs @@ -0,0 +1,90 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using UserPointManagement.Persistence; + +#nullable disable + +namespace UserPointManagement.Persistence.Migrations +{ + [DbContext(typeof(UserPointManagementDbContext))] + [Migration("20230729051855_AddUserPoint")] + partial class AddUserPoint + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("UserPointManagement.Model.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id") + .HasComment("主键"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Mobile") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("character varying(30)") + .HasColumnName("mobile") + .HasComment("手机号"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasColumnName("name") + .HasComment("姓名"); + + b.HasKey("Id") + .HasName("pk_user"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("UserPointManagement.Model.Entities.UserPoint", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasColumnName("id") + .HasComment("主键"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreateTime") + .HasColumnType("timestamp with time zone") + .HasColumnName("create_time") + .HasComment("新增时间"); + + b.Property("Point") + .HasColumnType("integer") + .HasColumnName("point") + .HasComment("积分"); + + b.Property("UserId") + .HasColumnType("integer") + .HasColumnName("user_id") + .HasComment("用户Id"); + + b.HasKey("Id") + .HasName("pk_user_point"); + + b.ToTable("user_point", (string)null); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/UserPointManagement.Persistence/Migrations/20230729051855_AddUserPoint.cs b/src/UserPointManagement.Persistence/Migrations/20230729051855_AddUserPoint.cs new file mode 100644 index 0000000..49cd731 --- /dev/null +++ b/src/UserPointManagement.Persistence/Migrations/20230729051855_AddUserPoint.cs @@ -0,0 +1,35 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace UserPointManagement.Persistence.Migrations +{ + public partial class AddUserPoint : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "user_point", + columns: table => new + { + id = table.Column(type: "bigint", nullable: false, comment: "主键") + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + user_id = table.Column(type: "integer", nullable: false, comment: "用户Id"), + point = table.Column(type: "integer", nullable: false, comment: "积分"), + create_time = table.Column(type: "timestamp with time zone", nullable: false, comment: "新增时间") + }, + constraints: table => + { + table.PrimaryKey("pk_user_point", x => x.id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "user_point"); + } + } +} diff --git a/src/UserPointManagement.Persistence/Migrations/UserPointManagementDbContextModelSnapshot.cs b/src/UserPointManagement.Persistence/Migrations/UserPointManagementDbContextModelSnapshot.cs index 86235b8..8a3c442 100644 --- a/src/UserPointManagement.Persistence/Migrations/UserPointManagementDbContextModelSnapshot.cs +++ b/src/UserPointManagement.Persistence/Migrations/UserPointManagementDbContextModelSnapshot.cs @@ -1,4 +1,5 @@ // +using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; @@ -50,6 +51,37 @@ namespace UserPointManagement.Persistence.Migrations b.ToTable("user", (string)null); }); + + modelBuilder.Entity("UserPointManagement.Model.Entities.UserPoint", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasColumnName("id") + .HasComment("主键"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreateTime") + .HasColumnType("timestamp with time zone") + .HasColumnName("create_time") + .HasComment("新增时间"); + + b.Property("Point") + .HasColumnType("integer") + .HasColumnName("point") + .HasComment("积分"); + + b.Property("UserId") + .HasColumnType("integer") + .HasColumnName("user_id") + .HasComment("用户Id"); + + b.HasKey("Id") + .HasName("pk_user_point"); + + b.ToTable("user_point", (string)null); + }); #pragma warning restore 612, 618 } } diff --git a/src/UserPointManagement.Persistence/UserPointManagementDbContext.cs b/src/UserPointManagement.Persistence/UserPointManagementDbContext.cs index 611d648..7b7d34b 100644 --- a/src/UserPointManagement.Persistence/UserPointManagementDbContext.cs +++ b/src/UserPointManagement.Persistence/UserPointManagementDbContext.cs @@ -11,10 +11,13 @@ public class UserPointManagementDbContext : Microsoft.EntityFrameworkCore.DbCont } public virtual DbSet Users { get; set; } + + public virtual DbSet UserPoints { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.SnakeCaseTableNameConvention(); modelBuilder.ApplyConfiguration(new UserConfiguration()); + modelBuilder.ApplyConfiguration(new UserPointConfiguration()); } } \ No newline at end of file diff --git a/src/UserPointManagement.Web/Layouts/BasicLayout.razor b/src/UserPointManagement.Web/Layouts/BasicLayout.razor index 2795645..bde0434 100644 --- a/src/UserPointManagement.Web/Layouts/BasicLayout.razor +++ b/src/UserPointManagement.Web/Layouts/BasicLayout.razor @@ -26,6 +26,13 @@ Name = "用户管理", Key = "user", Icon = "smile", + }, + new MenuDataItem + { + Path = "/user-point", + Name = "用户积分", + Key = "user-point", + Icon = "smile", } }; diff --git a/src/UserPointManagement.Web/Pages/UserPoint/UserPoint.razor b/src/UserPointManagement.Web/Pages/UserPoint/UserPoint.razor new file mode 100644 index 0000000..cb4101c --- /dev/null +++ b/src/UserPointManagement.Web/Pages/UserPoint/UserPoint.razor @@ -0,0 +1,8 @@ +@page "/user-point" + + + + +@code { + +} \ No newline at end of file