21 changed files with 10563 additions and 3 deletions
@ -0,0 +1,33 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace Lion.AbpPro.Books; |
|||
|
|||
/// <summary>
|
|||
/// 创建书籍
|
|||
/// </summary>
|
|||
public class CreateBookInput |
|||
{ |
|||
/// <summary>
|
|||
/// 编号
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "编号不能为空")] |
|||
public string No { get; set; } |
|||
/// <summary>
|
|||
/// 名称
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "名称不能为空")] |
|||
public string Name { get; set; } |
|||
/// <summary>
|
|||
/// 价格
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "价格不能为空")] |
|||
public decimal Price { get; set; } |
|||
/// <summary>
|
|||
/// 备注
|
|||
/// </summary>
|
|||
public string Remark { get; set; } |
|||
/// <summary>
|
|||
/// 类型
|
|||
/// </summary>
|
|||
public BookType BookType { get; set; } |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
namespace Lion.AbpPro.Books; |
|||
|
|||
/// <summary>
|
|||
/// 删除书籍
|
|||
/// </summary>
|
|||
public class DeleteBookInput |
|||
{ |
|||
/// <summary>
|
|||
/// 书籍Id
|
|||
/// </summary>
|
|||
public Guid Id { get; set; } |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace Lion.AbpPro.Books; |
|||
|
|||
/// <summary>
|
|||
/// 书籍
|
|||
/// </summary>
|
|||
public interface IBookAppService : IApplicationService |
|||
{ |
|||
/// <summary>
|
|||
/// 分页查询书籍
|
|||
/// </summary>
|
|||
Task<PagedResultDto<PageBookOutput>> PageAsync(PageBookInput input); |
|||
|
|||
/// <summary>
|
|||
/// 创建书籍
|
|||
/// </summary>
|
|||
Task CreateAsync(CreateBookInput input); |
|||
|
|||
/// <summary>
|
|||
/// 编辑书籍
|
|||
/// </summary>
|
|||
Task UpdateAsync(UpdateBookInput input); |
|||
|
|||
/// <summary>
|
|||
/// 删除书籍
|
|||
/// </summary>
|
|||
Task DeleteAsync(DeleteBookInput input); |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
namespace Lion.AbpPro.Books; |
|||
|
|||
/// <summary>
|
|||
/// 分页查询书籍
|
|||
/// </summary>
|
|||
public class PageBookInput : PagingBase |
|||
{ |
|||
/// <summary>
|
|||
/// 开始创建时间
|
|||
/// </summary>
|
|||
public DateTime? StartCreationTime { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 结束创建时间
|
|||
/// </summary>
|
|||
public DateTime? EndCreationTime { get; set; } |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
namespace Lion.AbpPro.Books; |
|||
|
|||
/// <summary>
|
|||
/// 分页查询书籍
|
|||
/// </summary>
|
|||
public class PageBookOutput |
|||
{ |
|||
/// <summary>
|
|||
/// 书籍Id
|
|||
/// </summary>
|
|||
public Guid Id { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 编号
|
|||
/// </summary>
|
|||
public string No { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 名称
|
|||
/// </summary>
|
|||
public string Name { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 价格
|
|||
/// </summary>
|
|||
public decimal Price { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 备注
|
|||
/// </summary>
|
|||
public string Remark { get; set; } |
|||
/// <summary>
|
|||
/// 类型
|
|||
/// </summary>
|
|||
public BookType BookType { get; set; } |
|||
public string BookTypeDescription => BookType.ToDescription(); |
|||
|
|||
/// <summary>
|
|||
/// 创建时间
|
|||
/// </summary>
|
|||
public DateTime CreationTime { get; set; } |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace Lion.AbpPro.Books; |
|||
|
|||
/// <summary>
|
|||
/// 更新书籍
|
|||
/// </summary>
|
|||
public class UpdateBookInput |
|||
{ |
|||
/// <summary>
|
|||
/// 书籍Id
|
|||
/// </summary>
|
|||
public Guid Id { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 编号
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "编号不能为空")] |
|||
public string No { get; set; } |
|||
/// <summary>
|
|||
/// 名称
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "名称不能为空")] |
|||
public string Name { get; set; } |
|||
/// <summary>
|
|||
/// 价格
|
|||
/// </summary>
|
|||
[Required(ErrorMessage = "价格不能为空")] |
|||
public decimal Price { get; set; } |
|||
/// <summary>
|
|||
/// 备注
|
|||
/// </summary>
|
|||
public string Remark { get; set; } |
|||
/// <summary>
|
|||
/// 类型
|
|||
/// </summary>
|
|||
public BookType BookType { get; set; } |
|||
} |
|||
@ -0,0 +1,68 @@ |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace Lion.AbpPro.Books; |
|||
|
|||
/// <summary>
|
|||
/// 书籍
|
|||
/// </summary>
|
|||
public class BookAppService : ApplicationService, IBookAppService |
|||
{ |
|||
private readonly BookManager _bookManager; |
|||
|
|||
public BookAppService(BookManager bookManager) |
|||
{ |
|||
_bookManager = bookManager; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 分页查询书籍
|
|||
/// </summary>
|
|||
public async Task<PagedResultDto<PageBookOutput>> PageAsync(PageBookInput input) |
|||
{ |
|||
var result = new PagedResultDto<PageBookOutput>(); |
|||
var totalCount = await _bookManager.GetCountAsync(input.StartCreationTime, input.EndCreationTime); |
|||
result.TotalCount = totalCount; |
|||
if (totalCount <= 0) return result; |
|||
var list = await _bookManager.GetListAsync(input.StartCreationTime, input.EndCreationTime, input.PageSize, input.SkipCount); |
|||
result.Items = ObjectMapper.Map<List<BookDto>, List<PageBookOutput>>(list); |
|||
return result; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 创建书籍
|
|||
/// </summary>
|
|||
public Task CreateAsync(CreateBookInput input) |
|||
{ |
|||
return _bookManager.CreateAsync( |
|||
GuidGenerator.Create(), |
|||
input.No, |
|||
input.Name, |
|||
input.Price, |
|||
input.Remark, |
|||
input.BookType |
|||
); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 编辑书籍
|
|||
/// </summary>
|
|||
public Task UpdateAsync(UpdateBookInput input) |
|||
{ |
|||
return _bookManager.UpdateAsync( |
|||
input.Id, |
|||
input.No, |
|||
input.Name, |
|||
input.Price, |
|||
input.Remark, |
|||
input.BookType |
|||
); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 删除书籍
|
|||
/// </summary>
|
|||
public Task DeleteAsync(DeleteBookInput input) |
|||
{ |
|||
return _bookManager.DeleteAsync(input.Id); |
|||
} |
|||
} |
|||
@ -1,5 +1,5 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Data Source=182.43.18.151;Port=3306;Database=abpvnextpro1;uid=root;pwd=IFKy!Cufe3V9sYcz;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true" |
|||
"Default": "Data Source=182.43.18.151;Port=3306;Database=abpvnextprodemo1;uid=root;pwd=IFKy!Cufe3V9sYcz;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true" |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
namespace Lion.AbpPro.Books; |
|||
|
|||
/// <summary>
|
|||
/// 书籍
|
|||
/// </summary>
|
|||
public class BookDto |
|||
{ |
|||
/// <summary>
|
|||
/// 主键Id
|
|||
/// </summary>
|
|||
public Guid Id { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 创建时间
|
|||
/// </summary>
|
|||
public DateTime CreationTime { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 编号
|
|||
/// </summary>
|
|||
public string No { get; set; } |
|||
/// <summary>
|
|||
/// 名称
|
|||
/// </summary>
|
|||
public string Name { get; set; } |
|||
/// <summary>
|
|||
/// 价格
|
|||
/// </summary>
|
|||
public decimal Price { get; set; } |
|||
/// <summary>
|
|||
/// 备注
|
|||
/// </summary>
|
|||
public string Remark { get; set; } |
|||
/// <summary>
|
|||
/// 类型
|
|||
/// </summary>
|
|||
public BookType BookType { get; set; } |
|||
|
|||
|
|||
private const string CacheKeyFormat = "i:{0}"; |
|||
|
|||
public static string CalculateCacheKey(Guid id) |
|||
{ |
|||
return string.Format(CacheKeyFormat, id); |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System.ComponentModel; |
|||
|
|||
namespace Lion.AbpPro.Books; |
|||
|
|||
/// <summary>
|
|||
/// 类型
|
|||
/// </summary>
|
|||
public enum BookType |
|||
{ |
|||
[Description("历史")] History = 10, |
|||
[Description("小说")] Story = 20, |
|||
[Description("其它")] Other = 30, |
|||
} |
|||
@ -0,0 +1,115 @@ |
|||
using Lion.AbpPro.Core; |
|||
using Volo.Abp.Domain.Entities.Auditing; |
|||
|
|||
namespace Lion.AbpPro.Books; |
|||
|
|||
/// <summary>
|
|||
/// 书籍
|
|||
/// </summary>
|
|||
public class Book : FullAuditedAggregateRoot<Guid> |
|||
{ |
|||
private Book() |
|||
{ |
|||
} |
|||
|
|||
|
|||
public Book( |
|||
Guid id, |
|||
string no, |
|||
string name, |
|||
decimal price, |
|||
string remark, |
|||
BookType bookType |
|||
) : base(id) |
|||
{ |
|||
SetNo(no); |
|||
SetName(name); |
|||
SetPrice(price); |
|||
SetRemark(remark); |
|||
SetBookType(bookType); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 编号
|
|||
/// </summary>
|
|||
public string No { get; private set; } |
|||
/// <summary>
|
|||
/// 名称
|
|||
/// </summary>
|
|||
public string Name { get; private set; } |
|||
/// <summary>
|
|||
/// 价格
|
|||
/// </summary>
|
|||
public decimal Price { get; private set; } |
|||
/// <summary>
|
|||
/// 备注
|
|||
/// </summary>
|
|||
public string Remark { get; private set; } |
|||
/// <summary>
|
|||
/// 类型
|
|||
/// </summary>
|
|||
public BookType BookType { get; private set; } |
|||
|
|||
|
|||
|
|||
/// <summary>
|
|||
/// 设置编号
|
|||
/// </summary>
|
|||
private void SetNo(string no) |
|||
{ |
|||
Guard.NotNullOrWhiteSpace(no, nameof(no), 128, 0); |
|||
No = no; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 设置名称
|
|||
/// </summary>
|
|||
private void SetName(string name) |
|||
{ |
|||
Guard.NotNullOrWhiteSpace(name, nameof(name), 128, 0); |
|||
Name = name; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 设置价格
|
|||
/// </summary>
|
|||
private void SetPrice(decimal price) |
|||
{ |
|||
Price = price; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 设置备注
|
|||
/// </summary>
|
|||
private void SetRemark(string remark) |
|||
{ |
|||
Guard.Length(remark, nameof(remark), 512, 0); |
|||
Remark = remark; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 设置类型
|
|||
/// </summary>
|
|||
private void SetBookType(BookType bookType) |
|||
{ |
|||
BookType = bookType; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 更新书籍
|
|||
/// </summary>
|
|||
public void Update( |
|||
string no, |
|||
string name, |
|||
decimal price, |
|||
string remark, |
|||
BookType bookType |
|||
) |
|||
{ |
|||
SetNo(no); |
|||
SetName(name); |
|||
SetPrice(price); |
|||
SetRemark(remark); |
|||
SetBookType(bookType); |
|||
} |
|||
} |
|||
@ -0,0 +1,73 @@ |
|||
using Volo.Abp; |
|||
|
|||
namespace Lion.AbpPro.Books; |
|||
|
|||
public class BookManager : DomainService |
|||
{ |
|||
private readonly IBookRepository _bookRepository; |
|||
private readonly IObjectMapper _objectMapper; |
|||
|
|||
public BookManager(IBookRepository bookRepository, IObjectMapper objectMapper) |
|||
{ |
|||
_bookRepository = bookRepository; |
|||
_objectMapper = objectMapper; |
|||
} |
|||
|
|||
public async Task<List<BookDto>> GetListAsync(DateTime? startDateTime = null, DateTime? endDateTime = null, int maxResultCount = 10, int skipCount = 0) |
|||
{ |
|||
var list = await _bookRepository.GetListAsync(startDateTime, endDateTime, maxResultCount, skipCount); |
|||
return _objectMapper.Map<List<Book>, List<BookDto>>(list); |
|||
} |
|||
|
|||
public async Task<long> GetCountAsync(DateTime? startDateTime = null, DateTime? endDateTime = null) |
|||
{ |
|||
return await _bookRepository.GetCountAsync(startDateTime, endDateTime); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 创建书籍
|
|||
/// </summary>
|
|||
public async Task<BookDto> CreateAsync( |
|||
Guid id, |
|||
string no, |
|||
string name, |
|||
decimal price, |
|||
string remark, |
|||
BookType bookType |
|||
) |
|||
{ |
|||
var entity = new Book(id, no, name, price, remark, bookType); |
|||
entity = await _bookRepository.InsertAsync(entity); |
|||
return _objectMapper.Map<Book, BookDto>(entity); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 更新书籍
|
|||
/// </summary>
|
|||
public async Task<BookDto> UpdateAsync( |
|||
Guid id, |
|||
string no, |
|||
string name, |
|||
decimal price, |
|||
string remark, |
|||
BookType bookType |
|||
) |
|||
{ |
|||
var entity = await _bookRepository.FindAsync(id); |
|||
if (entity == null) throw new UserFriendlyException($"书籍不存在"); |
|||
entity.Update(no, name, price, remark, bookType); |
|||
entity = await _bookRepository.UpdateAsync(entity); |
|||
return _objectMapper.Map<Book, BookDto>(entity); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 删除书籍
|
|||
/// </summary>
|
|||
public async Task DeleteAsync(Guid id) |
|||
{ |
|||
var entity = await _bookRepository.FindAsync(id); |
|||
if (entity == null) throw new UserFriendlyException($"书籍不存在"); |
|||
await _bookRepository.DeleteAsync(entity); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Lion.AbpPro.Books; |
|||
|
|||
public interface IBookRepository : IBasicRepository<Book, Guid> |
|||
{ |
|||
Task<List<Book>> GetListAsync(DateTime? startDateTime = null, DateTime? endDateTime = null, int maxResultCount = 10, int skipCount = 0); |
|||
|
|||
Task<long> GetCountAsync(DateTime? startDateTime = null, DateTime? endDateTime = null); |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
using Lion.AbpPro.Books; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore; |
|||
|
|||
namespace Lion.AbpPro.EntityFrameworkCore.Books; |
|||
|
|||
/// <summary>
|
|||
/// 书籍 仓储Ef core 实现
|
|||
/// </summary>
|
|||
public class EfCoreBookRepository : |
|||
EfCoreRepository<IAbpProDbContext, Book, Guid>, |
|||
IBookRepository |
|||
{ |
|||
public EfCoreBookRepository(IDbContextProvider<IAbpProDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public async Task<List<Book>> GetListAsync(DateTime? startDateTime = null, DateTime? endDateTime = null,int maxResultCount = 10, int skipCount = 0) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.WhereIf(startDateTime.HasValue, e => e.CreationTime >= startDateTime.Value) |
|||
.WhereIf(endDateTime.HasValue, e => e.CreationTime <= endDateTime.Value) |
|||
.OrderByDescending(e => e.CreationTime) |
|||
.PageBy(skipCount, maxResultCount) |
|||
.ToListAsync(); |
|||
} |
|||
|
|||
public async Task<long> GetCountAsync(DateTime? startDateTime = null, DateTime? endDateTime = null) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.WhereIf(startDateTime.HasValue, e => e.CreationTime >= startDateTime.Value) |
|||
.WhereIf(endDateTime.HasValue, e => e.CreationTime <= endDateTime.Value) |
|||
.CountAsync(); |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,53 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace Lion.AbpPro.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class _101 : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.CreateTable( |
|||
name: "AppBooks", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"), |
|||
No = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false, comment: "编号") |
|||
.Annotation("MySql:CharSet", "utf8mb4"), |
|||
Name = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false, comment: "名称") |
|||
.Annotation("MySql:CharSet", "utf8mb4"), |
|||
Price = table.Column<decimal>(type: "decimal(6,2)", precision: 6, scale: 2, nullable: false, comment: "价格"), |
|||
Remark = table.Column<string>(type: "longtext", nullable: true, comment: "备注") |
|||
.Annotation("MySql:CharSet", "utf8mb4"), |
|||
BookType = table.Column<int>(type: "int", nullable: false, comment: "类型"), |
|||
ExtraProperties = table.Column<string>(type: "longtext", nullable: false) |
|||
.Annotation("MySql:CharSet", "utf8mb4"), |
|||
ConcurrencyStamp = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false) |
|||
.Annotation("MySql:CharSet", "utf8mb4"), |
|||
CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false), |
|||
CreatorId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"), |
|||
LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true), |
|||
LastModifierId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"), |
|||
IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false), |
|||
DeleterId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"), |
|||
DeletionTime = table.Column<DateTime>(type: "datetime(6)", nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_AppBooks", x => x.Id); |
|||
}) |
|||
.Annotation("MySql:CharSet", "utf8mb4"); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "AppBooks"); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,45 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Swashbuckle.AspNetCore.Annotations; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Lion.AbpPro.Books; |
|||
|
|||
namespace Lion.AbpPro.Controllers; |
|||
|
|||
[Route("Books")] |
|||
public class BookController : AbpController, IBookAppService |
|||
{ |
|||
private readonly IBookAppService _bookAppService; |
|||
|
|||
public BookController(IBookAppService bookAppService) |
|||
{ |
|||
_bookAppService = bookAppService; |
|||
} |
|||
|
|||
[HttpPost("Page")] |
|||
[SwaggerOperation(summary: "分页查询书籍", Tags = new[] { "Books" })] |
|||
public async Task<PagedResultDto<PageBookOutput>> PageAsync(PageBookInput input) |
|||
{ |
|||
return await _bookAppService.PageAsync(input); |
|||
} |
|||
|
|||
[HttpPost("Create")] |
|||
[SwaggerOperation(summary: "创建书籍", Tags = new[] { "Books" })] |
|||
public async Task CreateAsync(CreateBookInput input) |
|||
{ |
|||
await _bookAppService.CreateAsync(input); |
|||
} |
|||
|
|||
[HttpPost("Update")] |
|||
[SwaggerOperation(summary: "编辑书籍", Tags = new[] { "Books" })] |
|||
public async Task UpdateAsync(UpdateBookInput input) |
|||
{ |
|||
await _bookAppService.UpdateAsync(input); |
|||
} |
|||
|
|||
[HttpPost("Delete")] |
|||
[SwaggerOperation(summary: "删除书籍", Tags = new[] { "Books" })] |
|||
public async Task DeleteAsync(DeleteBookInput input) |
|||
{ |
|||
await _bookAppService.DeleteAsync(input); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue