添加项目文件。
This commit is contained in:
158
extend/Tnb.Extend/ProductService.cs
Normal file
158
extend/Tnb.Extend/ProductService.cs
Normal file
@@ -0,0 +1,158 @@
|
||||
using System.Collections.Generic;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Filter;
|
||||
using JNPF.Common.Security;
|
||||
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 Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace JNPF.Extend;
|
||||
|
||||
/// <summary>
|
||||
/// 业务实现:订单示例.
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = "Extend", Name = "Product", Order = 200)]
|
||||
[Route("api/extend/saleOrder/[controller]")]
|
||||
public class ProductService : IDynamicApiController, ITransient
|
||||
{
|
||||
/// <summary>
|
||||
/// 服务基础仓储.
|
||||
/// </summary>
|
||||
private readonly ISqlSugarRepository<ProductEntity> _repository;
|
||||
|
||||
/// <summary>
|
||||
/// 用户管理.
|
||||
/// </summary>
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化一个<see cref="ProductService"/>类型的新实例.
|
||||
/// </summary>
|
||||
public ProductService(
|
||||
ISqlSugarRepository<ProductEntity> extProductRepository,
|
||||
IUserManager userManager)
|
||||
{
|
||||
_repository = extProductRepository;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取订单示例.
|
||||
/// </summary>
|
||||
/// <param name="id">主键值.</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}")]
|
||||
public async Task<dynamic> GetInfo(string id)
|
||||
{
|
||||
return (await _repository.AsQueryable()
|
||||
.Includes(x => x.productEntryList.Select(it => new ProductEntryEntity
|
||||
{
|
||||
ProductCode = it.ProductCode,
|
||||
ProductName = it.ProductName,
|
||||
ProductSpecification = it.ProductSpecification,
|
||||
Qty = it.Qty,
|
||||
Type = it.Type,
|
||||
Money = it.Money,
|
||||
Price = it.Price,
|
||||
Amount = it.Amount,
|
||||
Description = it.Description
|
||||
}).ToList()).Where(a => a.Id.Equals(id))
|
||||
.ToListAsync(it => new ProductInfoOutput
|
||||
{
|
||||
id = it.Id,
|
||||
code = it.Code,
|
||||
customerName = it.CustomerName,
|
||||
customerId = it.CustomerId,
|
||||
auditName = it.AuditName,
|
||||
auditDate = it.AuditDate,
|
||||
goodsWarehouse = it.GoodsWarehouse,
|
||||
goodsDate = it.GoodsDate,
|
||||
gatheringType = it.GatheringType,
|
||||
business = it.Business,
|
||||
address = it.Address,
|
||||
contactTel = it.ContactTel,
|
||||
harvestMsg = it.HarvestMsg,
|
||||
harvestWarehouse = it.HarvestWarehouse,
|
||||
issuingName = it.IssuingName,
|
||||
partPrice = it.PartPrice,
|
||||
reducedPrice = it.ReducedPrice,
|
||||
discountPrice = it.DiscountPrice,
|
||||
description = it.Description,
|
||||
productEntryList = it.productEntryList.Adapt<List<ProductEntryInfoOutput>>()
|
||||
}))?.FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取订单示例列表.
|
||||
/// </summary>
|
||||
/// <param name="input">请求参数.</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("")]
|
||||
public async Task<dynamic> GetList([FromQuery] ProductListQueryInput input)
|
||||
{
|
||||
var data = await _repository.AsQueryable()
|
||||
.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.auditState), it => it.AuditState.Equals(input.auditState))
|
||||
.WhereIF(!string.IsNullOrEmpty(input.closeState), it => it.CloseState.Equals(input.closeState))
|
||||
.Select(it => new ProductListOutput
|
||||
{
|
||||
id = it.Id,
|
||||
code = it.Code,
|
||||
customerName = it.CustomerName,
|
||||
business = it.Business,
|
||||
address = it.Address,
|
||||
contactTel = it.ContactTel,
|
||||
salesmanName = it.SalesmanName,
|
||||
auditState = it.AuditState,
|
||||
goodsState = it.GoodsState,
|
||||
closeState = it.CloseState,
|
||||
closeDate = it.CloseDate,
|
||||
contactName = it.ContactName
|
||||
}).MergeTable().OrderByIF(string.IsNullOrEmpty(input.sidx), it => it.id).OrderByIF(!string.IsNullOrEmpty(input.sidx), input.sidx + " " + input.sort).ToPagedListAsync(input.currentPage, input.pageSize);
|
||||
return PageResult<ProductListOutput>.SqlSugarPageResult(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取订单示例列表.
|
||||
/// </summary>
|
||||
/// <param name="id">请求参数.</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("ProductEntry/{id}")]
|
||||
public async Task<dynamic> GetProductEntryList(string id)
|
||||
{
|
||||
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
|
||||
{
|
||||
productCode = it.ProductCode,
|
||||
productName = it.ProductName,
|
||||
qty = it.Qty,
|
||||
type = it.Type,
|
||||
activity = it.Activity,
|
||||
}).ToListAsync();
|
||||
|
||||
productEntryList.ForEach(item =>
|
||||
{
|
||||
item.dataList = new List<ProductEntryMdoel>();
|
||||
List<ProductEntryMdoel> dataList = new List<ProductEntryMdoel>();
|
||||
var randomData = new Random();
|
||||
int num = randomData.Next(1, dataAll.Count);
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
dataList.Add(dataAll[i]);
|
||||
}
|
||||
|
||||
item.dataList = dataList;
|
||||
});
|
||||
|
||||
return new { list = productEntryList };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user