Merge pull request 'develop' (#2) from develop into master
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: #2master
commit
229dfbf5d1
|
|
@ -0,0 +1,69 @@
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: deployment
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: check
|
||||||
|
image: alpine
|
||||||
|
commands:
|
||||||
|
- ls -la
|
||||||
|
- ls -la Dockerfile # 查看当前文件夹是否包含了Dockerfile
|
||||||
|
- name: publish
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
username:
|
||||||
|
from_secret: nexus_username
|
||||||
|
password:
|
||||||
|
from_secret: nexus_password
|
||||||
|
pull: if-not-exists # 如果镜像不存在则拉取,免去每次都要重新下载
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
tags: latest
|
||||||
|
# you need insecure: true since we don't have a TLS certificate
|
||||||
|
insecure: true
|
||||||
|
registry: 192.168.31.104:8082
|
||||||
|
repo: 192.168.31.104:8082/tiamo/user-point-management
|
||||||
|
volumes: # 将容器内目录挂载到宿主机,仓库需要开启Trusted设置
|
||||||
|
- name: dockersock
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
- name: deploy
|
||||||
|
pull: if-not-exists
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
environment:
|
||||||
|
Connection:
|
||||||
|
from_secret: connection
|
||||||
|
NEXUS_USER:
|
||||||
|
from_secret: nexus_username
|
||||||
|
NEXUS_PASSWORD:
|
||||||
|
from_secret: nexus_password
|
||||||
|
settings:
|
||||||
|
host: 192.168.31.225
|
||||||
|
port: 22
|
||||||
|
username: drone
|
||||||
|
password: dronepw
|
||||||
|
command_timeout: 2m
|
||||||
|
envs: [ NEXUS_USER, NEXUS_PASSWORD ]
|
||||||
|
script:
|
||||||
|
- echo $NEXUS_PASSWORD | docker login -u $NEXUS_USER --password-stdin 192.168.31.104:8082
|
||||||
|
- docker pull 192.168.31.104:8082/tiamo/user-point-management
|
||||||
|
- echo 开始停止容器
|
||||||
|
- docker stop user-point-management
|
||||||
|
- echo 开始强制清除停止容器
|
||||||
|
- docker container prune -f
|
||||||
|
- echo 开始清除镜像
|
||||||
|
- docker image prune -f
|
||||||
|
- echo 开始标签镜像
|
||||||
|
- docker tag 192.168.31.104:8082/tiamo/user-point-management tiamo/user-point-management:latest
|
||||||
|
- echo 开始运行容器
|
||||||
|
- docker run --name user-point-management -d -p 29029:5000
|
||||||
|
-e Connection__UserPointManagement="Server=192.168.31.225;Port=5432;UserId=postgres;Password=postgres;Database=tiamo;"
|
||||||
|
tiamo/user-point-management
|
||||||
|
- echo 执行完成
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
host:
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
branch:
|
||||||
|
- master
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
|
||||||
|
|
||||||
|
WORKDIR /docker
|
||||||
|
EXPOSE 5000
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
||||||
|
WORKDIR /build
|
||||||
|
COPY . .
|
||||||
|
RUN dotnet restore src/UserPointManagement.Web/UserPointManagement.Web.csproj --configfile ./NuGet.Config
|
||||||
|
WORKDIR src/UserPointManagement.Web
|
||||||
|
RUN dotnet build UserPointManagement.Web.csproj -c Release
|
||||||
|
|
||||||
|
FROM build AS publish
|
||||||
|
RUN dotnet publish UserPointManagement.Web.csproj -c Release -o /app
|
||||||
|
|
||||||
|
FROM base AS final
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=publish /app .
|
||||||
|
|
||||||
|
ENV ASPNETCORE_URLS http://*:5000
|
||||||
|
ENV TZ Asia/Shanghai
|
||||||
|
ENV Connection__UserPointManagement=""
|
||||||
|
|
||||||
|
ENTRYPOINT ["dotnet", "UserPointManagement.Web.dll"]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<packageSources>
|
||||||
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||||
|
<add key="azure" value="https://nuget.cdn.azure.cn/v3/index.json" protocolVersion="3" />
|
||||||
|
</packageSources>
|
||||||
|
</configuration>
|
||||||
|
|
@ -18,6 +18,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserPointManagement.Persist
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserPointManagement.Application.Tests", "test\UserPointManagement.Application.Tests\UserPointManagement.Application.Tests.csproj", "{5770D3E5-9B3E-40FC-8209-62F0B4B45BD4}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserPointManagement.Application.Tests", "test\UserPointManagement.Application.Tests\UserPointManagement.Application.Tests.csproj", "{5770D3E5-9B3E-40FC-8209-62F0B4B45BD4}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{08F901D9-600A-4B4D-A942-AD2F61EDFE49}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
Dockerfile = Dockerfile
|
||||||
|
README.md = README.md
|
||||||
|
NuGet.Config = NuGet.Config
|
||||||
|
.drone.yml = .drone.yml
|
||||||
|
.gitignore = .gitignore
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ namespace UserPointManagement.Application.Services;
|
||||||
|
|
||||||
public interface IUserPointService
|
public interface IUserPointService
|
||||||
{
|
{
|
||||||
Task<PageResultDto<UserPointDto>> GetUserPoints(GetUserPointDto req);
|
Task<PageResultDto<UserPointInfoDto>> GetUserPoints(GetUserPointDto req);
|
||||||
|
|
||||||
Task CreateUserPoint(CreateUserPointDto input);
|
Task CreateUserPoint(CreateUserPointDto input);
|
||||||
|
|
||||||
|
|
@ -24,26 +24,39 @@ public class UserPointService : IUserPointService
|
||||||
_dbContextFactory = dbContextFactory;
|
_dbContextFactory = dbContextFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<PageResultDto<UserPointDto>> GetUserPoints(GetUserPointDto req)
|
public async Task<PageResultDto<UserPointInfoDto>> GetUserPoints(GetUserPointDto req)
|
||||||
{
|
{
|
||||||
await using var _userPointManagementDbContext = await _dbContextFactory.CreateDbContextAsync();
|
await using var _userPointManagementDbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
var queryable = from userPoint in _userPointManagementDbContext.UserPoints
|
|
||||||
join user in _userPointManagementDbContext.Users on userPoint.UserId equals user.Id
|
var queryable = _userPointManagementDbContext.Users
|
||||||
|
.Where(x => x.Id == req.UserId, req.UserId.HasValue);
|
||||||
|
|
||||||
|
// 分页筛选只能针对用户
|
||||||
|
var users = await queryable.OrderByDescending(x => x.Id).Paging(req).ToListAsync();
|
||||||
|
|
||||||
|
// 查出用户底下积分明细
|
||||||
|
var userPoints = await (from userPoint in _userPointManagementDbContext.UserPoints
|
||||||
|
where users.Select(x => x.Id).Contains(userPoint.UserId)
|
||||||
select new UserPointDto()
|
select new UserPointDto()
|
||||||
{
|
{
|
||||||
UserPointId = userPoint.Id,
|
UserPointId = userPoint.Id,
|
||||||
UserId = user.Id,
|
UserId = userPoint.UserId,
|
||||||
Name = user.Name,
|
|
||||||
Point = userPoint.Point,
|
Point = userPoint.Point,
|
||||||
CreateTime = userPoint.CreateTime
|
CreateTime = userPoint.CreateTime
|
||||||
};
|
}).ToListAsync();
|
||||||
|
|
||||||
queryable = queryable.Where(x => x.UserId == req.UserId, req.UserId.HasValue);
|
var data = userPoints.GroupBy(x => x.UserId)
|
||||||
|
.Select(x => new UserPointInfoDto()
|
||||||
|
{
|
||||||
|
UserId = x.Key,
|
||||||
|
Name = users.First(p => p.Id == x.Key).Name,
|
||||||
|
TotalPoint = x.Sum(p => p.Point),
|
||||||
|
Items = x.ToList()
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
var count = queryable.Count();
|
var count = queryable.Count();
|
||||||
var data = await queryable.OrderByDescending(x => x.CreateTime).Paging(req).ToListAsync().ConfigureAwait(false);
|
|
||||||
|
|
||||||
return new PageResultDto<UserPointDto>()
|
return new PageResultDto<UserPointInfoDto>()
|
||||||
{
|
{
|
||||||
Items = data,
|
Items = data,
|
||||||
TotalCount = count
|
TotalCount = count
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,8 @@ public class UserService : IUserService
|
||||||
public async Task CreateUser(User input)
|
public async Task CreateUser(User input)
|
||||||
{
|
{
|
||||||
await using var _userPointManagementDbContext = await _dbContextFactory.CreateDbContextAsync();
|
await using var _userPointManagementDbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
if (_userPointManagementDbContext.Users.Any(x => x.Mobile == input.Mobile))
|
if (!string.IsNullOrWhiteSpace(input.Mobile) &&
|
||||||
|
_userPointManagementDbContext.Users.Any(x => x.Mobile == input.Mobile))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("手机号不可重复!");
|
throw new ArgumentException("手机号不可重复!");
|
||||||
}
|
}
|
||||||
|
|
@ -72,6 +73,7 @@ public class UserService : IUserService
|
||||||
{
|
{
|
||||||
throw new ArgumentException("名称不可重复!");
|
throw new ArgumentException("名称不可重复!");
|
||||||
}
|
}
|
||||||
|
|
||||||
_userPointManagementDbContext.Users.Add(input);
|
_userPointManagementDbContext.Users.Add(input);
|
||||||
await _userPointManagementDbContext.SaveChangesAsync().ConfigureAwait(false);
|
await _userPointManagementDbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,5 @@
|
||||||
|
|
||||||
public class GetUserDto : PageBase
|
public class GetUserDto : PageBase
|
||||||
{
|
{
|
||||||
public string Keyword { get; set; }
|
public string? Keyword { get; set; }
|
||||||
}
|
}
|
||||||
|
|
@ -6,8 +6,6 @@ public class UserPointDto
|
||||||
|
|
||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public int Point { get; set; }
|
public int Point { get; set; }
|
||||||
|
|
||||||
public DateTime CreateTime { get; set; }
|
public DateTime CreateTime { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
namespace UserPointManagement.Model.Dtos.UserPoint;
|
||||||
|
|
||||||
|
public class UserPointInfoDto
|
||||||
|
{
|
||||||
|
public int UserId { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public int TotalPoint { get; set; }
|
||||||
|
|
||||||
|
public List<UserPointDto> Items { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -6,5 +6,5 @@ public class User
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public string Mobile { get; set; }
|
public string? Mobile { get; set; }
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,89 @@
|
||||||
|
// <auto-generated />
|
||||||
|
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("20230730134035_ModifyUser")]
|
||||||
|
partial class ModifyUser
|
||||||
|
{
|
||||||
|
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<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("id")
|
||||||
|
.HasComment("主键");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Mobile")
|
||||||
|
.HasMaxLength(30)
|
||||||
|
.HasColumnType("character varying(30)")
|
||||||
|
.HasColumnName("mobile")
|
||||||
|
.HasComment("手机号");
|
||||||
|
|
||||||
|
b.Property<string>("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<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint")
|
||||||
|
.HasColumnName("id")
|
||||||
|
.HasComment("主键");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreateTime")
|
||||||
|
.HasColumnType("timestamp without time zone")
|
||||||
|
.HasColumnName("create_time")
|
||||||
|
.HasComment("新增时间");
|
||||||
|
|
||||||
|
b.Property<int>("Point")
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("point")
|
||||||
|
.HasComment("积分");
|
||||||
|
|
||||||
|
b.Property<int>("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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace UserPointManagement.Persistence.Migrations
|
||||||
|
{
|
||||||
|
public partial class ModifyUser : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "mobile",
|
||||||
|
table: "user",
|
||||||
|
type: "character varying(30)",
|
||||||
|
maxLength: 30,
|
||||||
|
nullable: true,
|
||||||
|
comment: "手机号",
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(30)",
|
||||||
|
oldMaxLength: 30,
|
||||||
|
oldComment: "手机号");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "mobile",
|
||||||
|
table: "user",
|
||||||
|
type: "character varying(30)",
|
||||||
|
maxLength: 30,
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: "",
|
||||||
|
comment: "手机号",
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(30)",
|
||||||
|
oldMaxLength: 30,
|
||||||
|
oldNullable: true,
|
||||||
|
oldComment: "手机号");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -33,7 +33,6 @@ namespace UserPointManagement.Persistence.Migrations
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
b.Property<string>("Mobile")
|
b.Property<string>("Mobile")
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(30)
|
.HasMaxLength(30)
|
||||||
.HasColumnType("character varying(30)")
|
.HasColumnType("character varying(30)")
|
||||||
.HasColumnName("mobile")
|
.HasColumnName("mobile")
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ public class UserPointManagementDbContextFactory : IDesignTimeDbContextFactory<U
|
||||||
{
|
{
|
||||||
var optionsBuilder = new DbContextOptionsBuilder<UserPointManagementDbContext>();
|
var optionsBuilder = new DbContextOptionsBuilder<UserPointManagementDbContext>();
|
||||||
optionsBuilder
|
optionsBuilder
|
||||||
.UseNpgsql("Server=67.230.184.225;Port=58007;UserId=postgres;Password=postgres;Database=tiamo;")
|
.UseNpgsql("Server=67.230.184.225;Port=58007;UserId=postgres;Password=postgres;Database=tiamo_dev;")
|
||||||
.UseSnakeCaseNamingConvention();
|
.UseSnakeCaseNamingConvention();
|
||||||
|
|
||||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using UserPointManagement.Application.Services;
|
||||||
|
using UserPointManagement.Model;
|
||||||
|
using UserPointManagement.Model.Dtos.User;
|
||||||
|
using UserPointManagement.Model.Entities;
|
||||||
|
|
||||||
|
namespace UserPointManagement.Web.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class UserController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IUserService _userService;
|
||||||
|
|
||||||
|
public UserController(IUserService userService)
|
||||||
|
{
|
||||||
|
_userService = userService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取用户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="req"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<PageResultDto<User>> GetUsers([FromQuery]GetUserDto req)
|
||||||
|
{
|
||||||
|
return await _userService.GetUsers(req).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Routing;
|
||||||
|
|
||||||
|
namespace UserPointManagement.Web;
|
||||||
|
|
||||||
|
public static class MvcOptionsExtensions
|
||||||
|
{
|
||||||
|
private static void UseGeneralRoutePrefix(this MvcOptions opts, IRouteTemplateProvider routeAttribute)
|
||||||
|
{
|
||||||
|
opts.Conventions.Add(new RoutePrefixConvention(routeAttribute));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UseGeneralRoutePrefix(this MvcOptions opts, string
|
||||||
|
prefix)
|
||||||
|
{
|
||||||
|
opts.UseGeneralRoutePrefix(new RouteAttribute(prefix));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RoutePrefixConvention : IApplicationModelConvention
|
||||||
|
{
|
||||||
|
private readonly AttributeRouteModel _routePrefix;
|
||||||
|
|
||||||
|
public RoutePrefixConvention(IRouteTemplateProvider route)
|
||||||
|
{
|
||||||
|
_routePrefix = new AttributeRouteModel(route);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Apply(ApplicationModel application)
|
||||||
|
{
|
||||||
|
foreach (var selector in application.Controllers.SelectMany(c => c.Selectors))
|
||||||
|
{
|
||||||
|
if (selector.AttributeRouteModel != null)
|
||||||
|
{
|
||||||
|
selector.AttributeRouteModel = AttributeRouteModel.CombineAttributeRouteModel(_routePrefix, selector.AttributeRouteModel);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
selector.AttributeRouteModel = _routePrefix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -92,7 +92,7 @@
|
||||||
<FormItem Label="姓名" Rules=@(new FormValidationRule[] { new FormValidationRule { Required = true, Message = "名称不可为空!" }, new FormValidationRule() { Len = 50, Message = "名称上限50字" } })>
|
<FormItem Label="姓名" Rules=@(new FormValidationRule[] { new FormValidationRule { Required = true, Message = "名称不可为空!" }, new FormValidationRule() { Len = 50, Message = "名称上限50字" } })>
|
||||||
<Input @bind-Value="@context.Name"/>
|
<Input @bind-Value="@context.Name"/>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<FormItem Label="手机号" Rules="@(new FormValidationRule[] { new FormValidationRule { Type = FormFieldType.Regexp, Pattern = @"^1\d{10}$", Message = "请输入正确手机号", Required = true } })">
|
<FormItem Label="手机号" Rules="@(new FormValidationRule[] { new FormValidationRule { Type = FormFieldType.Regexp, Pattern = @"^1\d{10}$", Message = "请输入正确手机号", Required = false } })">
|
||||||
<Input @bind-Value="@context.Mobile"/>
|
<Input @bind-Value="@context.Mobile"/>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
|
||||||
|
|
@ -36,23 +36,36 @@
|
||||||
</Space>
|
</Space>
|
||||||
</GridCol>
|
</GridCol>
|
||||||
</GridRow>
|
</GridRow>
|
||||||
<Table TItem="UserPointDto" DataSource="@_userPoints"
|
<Table TItem="UserPointInfoDto" DataSource="@_userPoints"
|
||||||
Total="_total"
|
Total="_total"
|
||||||
Loading="_loading"
|
Loading="_loading"
|
||||||
PageIndex="@_pageIndex"
|
PageIndex="@_pageIndex"
|
||||||
PageSize="@_pageSize"
|
PageSize="@_pageSize"
|
||||||
|
OnExpand="OnRowExpand"
|
||||||
OnPageIndexChange="OnPageIndexChanged"
|
OnPageIndexChange="OnPageIndexChanged"
|
||||||
OnPageSizeChange="OnPageSizeChange">
|
OnPageSizeChange="OnPageSizeChange">
|
||||||
|
<ChildContent Context="data">
|
||||||
<PropertyColumn Property="c => c.Name" title="用户姓名"/>
|
<PropertyColumn Property="c => c.Name" title="用户姓名"/>
|
||||||
|
<PropertyColumn Property="c => c.TotalPoint" title="总积分"/>
|
||||||
|
<ActionColumn Title="操作" Width="220">
|
||||||
|
<Button Type="Primary" OnClick="() => Add(data.UserId)">新增积分</Button>
|
||||||
|
</ActionColumn>
|
||||||
|
</ChildContent>
|
||||||
|
<ExpandTemplate Context="rowData">
|
||||||
|
<Table DataSource="rowData.Data.Items" Loading="rowData.Data.Items == null" HidePagination>
|
||||||
|
<ChildContent Context="data">
|
||||||
<PropertyColumn Property="c => c.Point" title="积分"/>
|
<PropertyColumn Property="c => c.Point" title="积分"/>
|
||||||
<PropertyColumn Property="c => c.CreateTime" title="新增时间" Format="yyyy-MM-dd HH:mm"/>
|
<PropertyColumn Property="c => c.CreateTime" title="新增时间" Format="yyyy-MM-dd HH:mm"/>
|
||||||
<ActionColumn Title="操作" Width="220">
|
<ActionColumn Title="Action">
|
||||||
<Space Size=@("middle")>
|
<Space Size="@("middle")">
|
||||||
<SpaceItem>
|
<SpaceItem>
|
||||||
<Button Danger OnClick="()=>Delete(context.UserPointId)">删除</Button>
|
<Button Danger OnClick="() => Delete(data.UserPointId)">删除积分</Button>
|
||||||
</SpaceItem>
|
</SpaceItem>
|
||||||
</Space>
|
</Space>
|
||||||
</ActionColumn>
|
</ActionColumn>
|
||||||
|
</ChildContent>
|
||||||
|
</Table>
|
||||||
|
</ExpandTemplate>
|
||||||
</Table>
|
</Table>
|
||||||
</PageContainer>
|
</PageContainer>
|
||||||
|
|
||||||
|
|
@ -68,7 +81,7 @@
|
||||||
@ref="@_form">
|
@ref="@_form">
|
||||||
<FormItem Label="姓名">
|
<FormItem Label="姓名">
|
||||||
<Select TItem="UserDto"
|
<Select TItem="UserDto"
|
||||||
TItemValue="int"
|
TItemValue="int?"
|
||||||
Mode="default"
|
Mode="default"
|
||||||
DataSource="@_users"
|
DataSource="@_users"
|
||||||
@bind-Value="@context.UserId"
|
@bind-Value="@context.UserId"
|
||||||
|
|
@ -93,10 +106,10 @@
|
||||||
public class Model
|
public class Model
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
public int UserId { get; set; }
|
public int? UserId { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int Point { get; set; }
|
public int? Point { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private Model model = new Model();
|
private Model model = new Model();
|
||||||
|
|
@ -123,6 +136,8 @@
|
||||||
|
|
||||||
private void HandleCancel(MouseEventArgs e)
|
private void HandleCancel(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
|
model.UserId = null;
|
||||||
|
model.Point = null;
|
||||||
_visible = false;
|
_visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,10 +170,16 @@
|
||||||
_form.Submit();
|
_form.Submit();
|
||||||
await UserPointService.CreateUserPoint(new CreateUserPointDto()
|
await UserPointService.CreateUserPoint(new CreateUserPointDto()
|
||||||
{
|
{
|
||||||
UserId = model.UserId,
|
UserId = model.UserId.Value,
|
||||||
Point = model.Point
|
Point = model.Point.Value
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
await RefreshTable().ConfigureAwait(false);
|
await RefreshTable().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task Add(int userId)
|
||||||
|
{
|
||||||
|
model.UserId = userId;
|
||||||
|
_visible = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AntDesign;
|
using AntDesign;
|
||||||
|
using AntDesign.TableModels;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using UserPointManagement.Application.Services;
|
using UserPointManagement.Application.Services;
|
||||||
using UserPointManagement.Model.Dtos.User;
|
using UserPointManagement.Model.Dtos.User;
|
||||||
|
|
@ -15,7 +17,7 @@ public class UserPointDetailBase : ComponentBase
|
||||||
[Inject] private IUserService UserService { get; set; }
|
[Inject] private IUserService UserService { get; set; }
|
||||||
[Inject] private MessageService MessageService { get; set; }
|
[Inject] private MessageService MessageService { get; set; }
|
||||||
|
|
||||||
protected List<UserPointDto> _userPoints;
|
protected List<UserPointInfoDto> _userPoints;
|
||||||
protected List<UserDto> _users;
|
protected List<UserDto> _users;
|
||||||
protected int _pageIndex = 1;
|
protected int _pageIndex = 1;
|
||||||
protected int _pageSize = 20;
|
protected int _pageSize = 20;
|
||||||
|
|
@ -72,4 +74,12 @@ public class UserPointDetailBase : ComponentBase
|
||||||
await MessageService.Success("删除成功!");
|
await MessageService.Success("删除成功!");
|
||||||
await RefreshTable();
|
await RefreshTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected async Task OnRowExpand(RowData<UserPointInfoDto> rowData)
|
||||||
|
{
|
||||||
|
if (rowData.Data.Items != null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5,9 +5,12 @@ using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore;
|
using Microsoft.AspNetCore;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using UserPointManagement.Persistence;
|
||||||
|
|
||||||
namespace UserPointManagement.Web
|
namespace UserPointManagement.Web
|
||||||
{
|
{
|
||||||
|
|
@ -15,7 +18,13 @@ namespace UserPointManagement.Web
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
CreateHostBuilder(args).Build().Run();
|
var host = CreateHostBuilder(args).Build();
|
||||||
|
using (var serviceScope = host.Services.CreateScope())
|
||||||
|
{
|
||||||
|
var context = serviceScope.ServiceProvider.GetRequiredService<UserPointManagementDbContext>();
|
||||||
|
context.Database.Migrate();
|
||||||
|
}
|
||||||
|
host.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
|
"Connection:UserPointManagement": "Server=67.230.184.225;Port=58007;UserId=postgres;Password=postgres;Database=tiamo;"
|
||||||
},
|
},
|
||||||
"applicationUrl": "https://localhost:5001;http://localhost:5000"
|
"applicationUrl": "https://localhost:5001;http://localhost:5000"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using AntDesign.ProLayout;
|
using AntDesign.ProLayout;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
|
@ -26,6 +28,20 @@ namespace UserPointManagement.Web
|
||||||
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
|
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
|
services.AddControllers(options =>
|
||||||
|
{
|
||||||
|
options.UseGeneralRoutePrefix("/api");
|
||||||
|
});
|
||||||
|
services.AddEndpointsApiExplorer();
|
||||||
|
services.AddSwaggerGen(options =>
|
||||||
|
{
|
||||||
|
Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.xml").ToList().ForEach(file =>
|
||||||
|
{
|
||||||
|
options.IncludeXmlComments(file, true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
services.AddRouting(options => options.LowercaseUrls = true);
|
||||||
|
|
||||||
services.AddRazorPages();
|
services.AddRazorPages();
|
||||||
services.AddServerSideBlazor();
|
services.AddServerSideBlazor();
|
||||||
services.AddAntDesign();
|
services.AddAntDesign();
|
||||||
|
|
@ -46,6 +62,7 @@ namespace UserPointManagement.Web
|
||||||
|
|
||||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||||
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
|
|
@ -54,6 +71,16 @@ namespace UserPointManagement.Web
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
|
app.UseSwagger(o =>
|
||||||
|
{
|
||||||
|
// o.RouteTemplate = $"/api/swagger/{{documentName}}/swagger.json";
|
||||||
|
});
|
||||||
|
app.UseSwaggerUI(c =>
|
||||||
|
{
|
||||||
|
// c.RoutePrefix = $"/api/swagger";
|
||||||
|
// c.SwaggerEndpoint($"/api/swagger/v1/swagger.json",
|
||||||
|
// "UserPointManagement.Api API V1");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -69,6 +96,7 @@ namespace UserPointManagement.Web
|
||||||
|
|
||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
|
endpoints.MapControllers();
|
||||||
endpoints.MapBlazorHub();
|
endpoints.MapBlazorHub();
|
||||||
endpoints.MapFallbackToPage("/_Host");
|
endpoints.MapFallbackToPage("/_Host");
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
<PackageReference Include="AntDesign.Charts" Version="0.2.3" />
|
<PackageReference Include="AntDesign.Charts" Version="0.2.3" />
|
||||||
<PackageReference Include="AntDesign.ProLayout" Version="0.12.4" />
|
<PackageReference Include="AntDesign.ProLayout" Version="0.12.4" />
|
||||||
<PackageReference Include="System.Net.Http.Json" Version="6.0.0" />
|
<PackageReference Include="System.Net.Http.Json" Version="6.0.0" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft": "Warning",
|
"Microsoft": "Warning",
|
||||||
"Microsoft.Hosting.Lifetime": "Information"
|
"Microsoft.Hosting.Lifetime": "Information",
|
||||||
|
"Microsoft.EntityFrameworkCore.Database": "Information"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ProSettings": {
|
"ProSettings": {
|
||||||
|
|
@ -22,5 +23,6 @@
|
||||||
"MenuRender": true,
|
"MenuRender": true,
|
||||||
"MenuHeaderRender": true,
|
"MenuHeaderRender": true,
|
||||||
"HeaderHeight": 48
|
"HeaderHeight": 48
|
||||||
}
|
},
|
||||||
|
"Connection:UserPointManagement": "Server=67.230.184.225;Port=58007;UserId=postgres;Password=postgres;Database=tiamo_dev;"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,5 @@
|
||||||
"MenuRender": true,
|
"MenuRender": true,
|
||||||
"MenuHeaderRender": true,
|
"MenuHeaderRender": true,
|
||||||
"HeaderHeight": 48
|
"HeaderHeight": 48
|
||||||
},
|
}
|
||||||
"Connection:UserPointManagement": "Server=67.230.184.225;Port=58007;UserId=postgres;Password=postgres;Database=tiamo;"
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue