merge from 2023-03-14

This commit is contained in:
2023-03-24 09:37:07 +08:00
parent f95ef4cf73
commit 3de92dab06
57 changed files with 1538 additions and 528 deletions

View File

@@ -1,13 +1,16 @@
using System.Collections.Generic;
using JNPF.Common.Core.Manager;
using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Filter;
using JNPF.Common.Security;
using JNPF.DatabaseAccessor;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Extend.Entitys;
using JNPF.Extend.Entitys.Dto.Product;
using JNPF.Extend.Entitys.Dto.ProductEntry;
using JNPF.Extend.Entitys.Model;
using JNPF.FriendlyException;
using JNPF.Systems.Interfaces.System;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
@@ -31,17 +34,26 @@ public class ProductService : IDynamicApiController, ITransient
/// </summary>
private readonly IUserManager _userManager;
/// <summary>
/// 单据规则服务.
/// </summary>
private readonly IBillRullService _billRullService;
/// <summary>
/// 初始化一个<see cref="ProductService"/>类型的新实例.
/// </summary>
public ProductService(
ISqlSugarRepository<ProductEntity> extProductRepository,
IBillRullService billRullService,
IUserManager userManager)
{
_repository = extProductRepository;
_billRullService = billRullService;
_userManager = userManager;
}
#region Get
/// <summary>
/// 获取订单示例.
/// </summary>
@@ -51,7 +63,7 @@ public class ProductService : IDynamicApiController, ITransient
public async Task<dynamic> GetInfo(string id)
{
return (await _repository.AsQueryable()
.Includes(x => x.productEntryList.Select(it => new ProductEntryEntity
.Includes(x => x.productEntryList.Where(it => it.DeleteMark == null).Select(it => new ProductEntryEntity
{
ProductCode = it.ProductCode,
ProductName = it.ProductName,
@@ -62,7 +74,7 @@ public class ProductService : IDynamicApiController, ITransient
Price = it.Price,
Amount = it.Amount,
Description = it.Description
}).ToList()).Where(a => a.Id.Equals(id))
}).ToList()).Where(a => a.Id.Equals(id) && a.DeleteMark == null)
.ToListAsync(it => new ProductInfoOutput
{
id = it.Id,
@@ -96,10 +108,15 @@ public class ProductService : IDynamicApiController, ITransient
[HttpGet("")]
public async Task<dynamic> GetList([FromQuery] ProductListQueryInput input)
{
if (input.auditState == "0")
input.auditState = null;
if (input.closeState == "0")
input.closeState = null;
var data = await _repository.AsQueryable()
.Where(it => it.DeleteMark == null)
.WhereIF(!string.IsNullOrEmpty(input.code), it => it.Code.Contains(input.code))
.WhereIF(!string.IsNullOrEmpty(input.customerName), it => it.Type.Contains(input.customerName))
.WhereIF(!string.IsNullOrEmpty(input.contactTel), it => it.CustomerId.Contains(input.contactTel))
.WhereIF(!string.IsNullOrEmpty(input.customerName), it => it.CustomerName.Contains(input.customerName))
.WhereIF(!string.IsNullOrEmpty(input.contactTel), it => it.ContactTel.Contains(input.contactTel))
.WhereIF(!string.IsNullOrEmpty(input.auditState), it => it.AuditState.Equals(input.auditState))
.WhereIF(!string.IsNullOrEmpty(input.closeState), it => it.CloseState.Equals(input.closeState))
.Select(it => new ProductListOutput
@@ -130,7 +147,7 @@ public class ProductService : IDynamicApiController, ITransient
{
string data = "[{\"id\":\"37c995b4044541009fb7e285bcf9845d\",\"productSpecification\":\"120ml\",\"qty\":16,\"money\":510,\"price\":120,\"commandType\":\"唯一码\",\"util\":\"盒\"},{\"id\":\"2dbb11d3cde04c299985ac944d130ba0\",\"productSpecification\":\"150ml\",\"qty\":15,\"money\":520,\"price\":310,\"commandType\":\"唯一码\",\"util\":\"盒\"},{\"id\":\"f8ec261ccdf045e5a2e1f0e5485cda76\",\"productSpecification\":\"40ml\",\"qty\":13,\"money\":530,\"price\":140,\"commandType\":\"唯一码\",\"util\":\"盒\"},{\"id\":\"6c110b57ae56445faa8ce9be501c8997\",\"productSpecification\":\"103ml\",\"qty\":2,\"money\":504,\"price\":150,\"commandType\":\"唯一码\",\"util\":\"盒\"},{\"id\":\"f2ee981aaf934147a4d090a0eed2203f\",\"productSpecification\":\"120ml\",\"qty\":21,\"money\":550,\"price\":160,\"commandType\":\"唯一码\",\"util\":\"盒\"}]";
List<ProductEntryMdoel> dataAll = data.ToObject<List<ProductEntryMdoel>>();
List<ProductEntryListOutput> productEntryList = await _repository.AsSugarClient().Queryable<ProductEntryEntity>().Where(it => it.ProductId.Equals(id)).Select(it => new ProductEntryListOutput
List<ProductEntryListOutput> productEntryList = await _repository.AsSugarClient().Queryable<ProductEntryEntity>().Where(it => it.ProductId.Equals(id) && it.DeleteMark == null).Select(it => new ProductEntryListOutput
{
productCode = it.ProductCode,
productName = it.ProductName,
@@ -155,4 +172,126 @@ public class ProductService : IDynamicApiController, ITransient
return new { list = productEntryList };
}
#endregion
#region POST
/// <summary>
/// 新建.
/// </summary>
/// <param name="input">请求参数.</param>
/// <returns></returns>
[HttpPost("")]
[UnitOfWork]
public async Task Create([FromBody] ProductCrInput input)
{
var entity = input.Adapt<ProductEntity>();
entity.Code = await _billRullService.GetBillNumber("OrderNumber", false);
entity.Id = SnowflakeIdHelper.NextId();
entity.CreatorTime = DateTime.Now;
entity.CreatorUserId = _userManager.UserId;
var productEntryList = input.productEntryList.Adapt<List<ProductEntryEntity>>();
if (productEntryList != null)
{
productEntryList.ForEach(item =>
{
item.Id = SnowflakeIdHelper.NextId();
item.ProductId = entity.Id;
item.CreatorTime = DateTime.Now;
item.CreatorUserId = _userManager.UserId;
});
entity.productEntryList = productEntryList;
}
var isOk = await _repository.AsSugarClient().InsertNav(entity)
.Include(it => it.productEntryList).ExecuteCommandAsync();
if (!isOk)
throw Oops.Oh(ErrorCode.COM1000);
}
/// <summary>
/// 更新订单示例.
/// </summary>
/// <param name="id">主键值.</param>
/// <param name="input">参数.</param>
/// <returns></returns>
[HttpPut("{id}")]
[UnitOfWork]
public async Task Update(string id, [FromBody] ProductUpInput input)
{
var entity = input.Adapt<ProductEntity>();
entity.LastModifyTime = DateTime.Now;
entity.LastModifyUserId = _userManager.UserId;
await _repository.AsSugarClient().Updateable<ProductEntryEntity>()
.Where(it => it.ProductId.Equals(entity.Id) && !input.productEntryList.Select(a => a.id).ToList().Contains(it.Id))
.SetColumns(it => new ProductEntryEntity()
{
DeleteMark = 1,
DeleteUserId = _userManager.UserId,
DeleteTime = SqlFunc.GetDate()
}).ExecuteCommandAsync();
var productEntryList = input.productEntryList.Adapt<List<ProductEntryEntity>>();
productEntryList.ForEach(item =>
{
item.Id = item.Id == null ? SnowflakeIdHelper.NextId() : item.Id;
item.ProductId = entity.Id;
});
await _repository.AsSugarClient().Storageable(productEntryList).ExecuteCommandAsync();
var isOk = await _repository.AsUpdateable(entity).UpdateColumns(it => new
{
it.Code,
it.CustomerName,
it.ContactTel,
it.Address,
it.GoodsWarehouse,
it.Business,
it.GatheringType,
it.PartPrice,
it.ReducedPrice,
it.DiscountPrice,
it.Description,
it.LastModifyUserId,
it.LastModifyTime
}).ExecuteCommandAsync();
if (!(isOk > 0))
throw Oops.Oh(ErrorCode.COM1001);
}
/// <summary>
/// 删除订单示例.
/// </summary>
/// <returns></returns>
[HttpDelete("{id}")]
[UnitOfWork]
public async Task Delete(string id)
{
await _repository.AsSugarClient().Updateable<ProductEntryEntity>()
.Where(it => it.ProductId.Equals(id))
.SetColumns(it => new ProductEntryEntity()
{
DeleteMark = 1,
DeleteUserId = _userManager.UserId,
DeleteTime = SqlFunc.GetDate()
}).ExecuteCommandAsync();
var isOk = await _repository.AsUpdateable()
.Where(it => it.Id.Equals(id))
.SetColumns(it => new ProductEntity()
{
DeleteMark = 1,
DeleteUserId = _userManager.UserId,
DeleteTime = SqlFunc.GetDate()
}).ExecuteCommandAsync();
if (!(isOk > 0))
throw Oops.Oh(ErrorCode.COM1002);
}
#endregion
}