2024-06-06 10:22:07 +00:00
|
|
|
|
using Admin.NET.Core.Service;
|
|
|
|
|
using Admin.NET.Application.Const;
|
|
|
|
|
using Admin.NET.Application.Entity;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2024-06-26 10:33:33 +00:00
|
|
|
|
using static SKIT.FlurlHttpClient.Wechat.Api.Models.TCBGetPressureTestReportResponse.Types;
|
|
|
|
|
|
2024-06-06 10:22:07 +00:00
|
|
|
|
namespace Admin.NET.Application;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 商品追溯服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)]
|
|
|
|
|
public class ProductRetrospectService : IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
private readonly SqlSugarRepository<ProductRetrospect> _rep;
|
|
|
|
|
private readonly PrintCodeDetailService _codeDetailService;
|
2024-06-26 10:33:33 +00:00
|
|
|
|
private readonly UserManager _userManager;
|
2024-06-06 10:22:07 +00:00
|
|
|
|
public ProductRetrospectService(SqlSugarRepository<ProductRetrospect> rep,
|
2024-06-26 10:33:33 +00:00
|
|
|
|
PrintCodeDetailService codeDetailService,
|
|
|
|
|
UserManager userManager)
|
2024-06-06 10:22:07 +00:00
|
|
|
|
{
|
|
|
|
|
_rep = rep;
|
|
|
|
|
_codeDetailService = codeDetailService;
|
2024-06-26 10:33:33 +00:00
|
|
|
|
_userManager = userManager;
|
2024-06-06 10:22:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分页查询商品追溯
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Page")]
|
|
|
|
|
public async Task<SqlSugarPagedList<ProductRetrospectOutput>> Page(ProductRetrospectInput input)
|
|
|
|
|
{
|
|
|
|
|
var query = _rep.AsQueryable().Where(a => !a.IsDelete)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
|
|
|
|
|
u.OddNumber.Contains(input.SearchKey.Trim())
|
2024-06-26 10:33:33 +00:00
|
|
|
|
|| u.Code.Contains(input.SearchKey.Trim())
|
2024-06-06 10:22:07 +00:00
|
|
|
|
|| u.CodeType.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.BusinessType.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.Destination.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.Location.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.Receipt.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.Department.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.Batch.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.Unit.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.BaseUnit.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.Remarks.Contains(input.SearchKey.Trim())
|
|
|
|
|
)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.OddNumber), u => u.OddNumber.Contains(input.OddNumber.Trim()))
|
2024-06-26 10:33:33 +00:00
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Code), u => u.Code.Contains(input.Code.Trim()))
|
2024-06-06 10:22:07 +00:00
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CodeType), u => u.CodeType.Contains(input.CodeType.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.BusinessType), u => u.BusinessType.Contains(input.BusinessType.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Destination), u => u.Destination.Contains(input.Destination.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Location), u => u.Location.Contains(input.Location.Trim()))
|
|
|
|
|
.WhereIF(input.WarehouseID>0, u => u.WarehouseID == input.WarehouseID)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Receipt), u => u.Receipt.Contains(input.Receipt.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Department), u => u.Department.Contains(input.Department.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Batch), u => u.Batch.Contains(input.Batch.Trim()))
|
|
|
|
|
.WhereIF(input.Count>0, u => u.Count == input.Count)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Unit), u => u.Unit.Contains(input.Unit.Trim()))
|
|
|
|
|
.WhereIF(input.BaseCount>0, u => u.BaseCount == input.BaseCount)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.BaseUnit), u => u.BaseUnit.Contains(input.BaseUnit.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Remarks), u => u.Remarks.Contains(input.Remarks.Trim()))
|
|
|
|
|
.Select<ProductRetrospectOutput>();
|
|
|
|
|
if(input.ScanCodeTimeRange != null && input.ScanCodeTimeRange.Count >0)
|
|
|
|
|
{
|
|
|
|
|
DateTime? start= input.ScanCodeTimeRange[0];
|
|
|
|
|
query = query.WhereIF(start.HasValue, u => u.ScanCodeTime > start);
|
|
|
|
|
if (input.ScanCodeTimeRange.Count >1 && input.ScanCodeTimeRange[1].HasValue)
|
|
|
|
|
{
|
|
|
|
|
var end = input.ScanCodeTimeRange[1].Value.AddDays(1);
|
|
|
|
|
query = query.Where(u => u.ScanCodeTime < end);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(input.WarehousingDateRange != null && input.WarehousingDateRange.Count >0)
|
|
|
|
|
{
|
|
|
|
|
DateTime? start= input.WarehousingDateRange[0];
|
|
|
|
|
query = query.WhereIF(start.HasValue, u => u.WarehousingDate > start);
|
|
|
|
|
if (input.WarehousingDateRange.Count >1 && input.WarehousingDateRange[1].HasValue)
|
|
|
|
|
{
|
|
|
|
|
var end = input.WarehousingDateRange[1].Value.AddDays(1);
|
|
|
|
|
query = query.Where(u => u.WarehousingDate < end);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 增加商品追溯
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Add")]
|
|
|
|
|
public async Task<long> Add(AddProductRetrospectInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = input.Adapt<ProductRetrospect>();
|
|
|
|
|
await _rep.InsertAsync(entity);
|
|
|
|
|
return entity.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除商品追溯
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Delete")]
|
|
|
|
|
public async Task Delete(DeleteProductRetrospectInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = await _rep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
|
|
|
|
|
await _rep.FakeDeleteAsync(entity); //假删除
|
|
|
|
|
//await _rep.DeleteAsync(entity); //真删除
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新商品追溯
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Update")]
|
|
|
|
|
public async Task Update(UpdateProductRetrospectInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = input.Adapt<ProductRetrospect>();
|
|
|
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取商品追溯
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Detail")]
|
|
|
|
|
public async Task<ProductRetrospect> Detail([FromQuery] QueryByIdProductRetrospectInput input)
|
|
|
|
|
{
|
|
|
|
|
return await _rep.GetFirstAsync(u => u.Id == input.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取商品追溯列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ApiDescriptionSettings(Name = "List")]
|
|
|
|
|
public async Task<List<ProductRetrospectOutput>> List()
|
|
|
|
|
{
|
|
|
|
|
return await _rep.AsQueryable().Select<ProductRetrospectOutput>().Where(a => !a.IsDelete).ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 03:23:29 +00:00
|
|
|
|
|
2024-06-06 10:22:07 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取商品追溯列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="productCode"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ApiDescriptionSettings(Name = "RetrospectByProductCode")]
|
|
|
|
|
public async Task<List<ProductRetrospectOutput>> RetrospectByProductCode(string? productCode)
|
|
|
|
|
{
|
|
|
|
|
return await _rep.AsQueryable().Where(u => !u.IsDelete && u.Code == productCode).Select<ProductRetrospectOutput>().ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 03:23:29 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询打印条码状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="productCode"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ApiDescriptionSettings(Name = "CheckCodeStatus")]
|
2024-07-08 16:45:18 +00:00
|
|
|
|
public async Task<CheckCodeStatusOutInput> CheckCodeStatus(string? productCode)
|
2024-07-02 03:23:29 +00:00
|
|
|
|
{
|
2024-07-08 16:45:18 +00:00
|
|
|
|
int state = 0;
|
2024-07-02 03:23:29 +00:00
|
|
|
|
var codeEnt = await _rep.AsQueryable().Where(u => !u.IsDelete && u.Code == productCode).Select<ProductRetrospectOutput>().ToListAsync();
|
|
|
|
|
if (codeEnt == null || codeEnt.Count<1)
|
|
|
|
|
{
|
2024-07-08 16:45:18 +00:00
|
|
|
|
state = 0;
|
2024-07-02 03:23:29 +00:00
|
|
|
|
}
|
|
|
|
|
var last = codeEnt.OrderBy(a => a.WarehousingDate).FirstOrDefault();
|
|
|
|
|
var receipt = last.Receipt == null ? "" : last.Receipt;
|
|
|
|
|
if (receipt.Contains("汇报单"))
|
|
|
|
|
{
|
2024-07-08 16:45:18 +00:00
|
|
|
|
state = 1;
|
2024-07-02 03:23:29 +00:00
|
|
|
|
}
|
|
|
|
|
else if (receipt.Contains("仓库"))
|
|
|
|
|
{
|
2024-07-08 16:45:18 +00:00
|
|
|
|
state = 2;
|
2024-07-02 03:23:29 +00:00
|
|
|
|
}
|
|
|
|
|
else if (receipt.Contains("发货"))
|
|
|
|
|
{
|
2024-07-08 16:45:18 +00:00
|
|
|
|
state = 3;
|
2024-07-02 03:23:29 +00:00
|
|
|
|
}
|
|
|
|
|
else if (receipt.Contains("分销"))
|
|
|
|
|
{
|
2024-07-08 16:45:18 +00:00
|
|
|
|
state = 3;
|
2024-07-02 03:23:29 +00:00
|
|
|
|
}
|
2024-07-08 16:45:18 +00:00
|
|
|
|
return new CheckCodeStatusOutInput { State = state };
|
2024-07-02 03:23:29 +00:00
|
|
|
|
}
|
|
|
|
|
public async Task AddRetrospect(PrintCodeDetail item ,ReportTable report,string receipt, string location ,long? sourceId,long? warehousingId)
|
2024-06-26 10:33:33 +00:00
|
|
|
|
{
|
|
|
|
|
var userId = _userManager.UserId;
|
|
|
|
|
var userName = _userManager.RealName;
|
|
|
|
|
var retrospect1 = new AddProductRetrospectInput()
|
|
|
|
|
{
|
|
|
|
|
BaseCount = item.BaseCount,
|
|
|
|
|
BaseUnit = item.BaseUnit,
|
|
|
|
|
Batch = report.Batch,
|
|
|
|
|
BusinessType = report.ProductType,
|
|
|
|
|
CodeType = item.CodeName,
|
|
|
|
|
Location = location,
|
|
|
|
|
Department = report.ProductionLine,
|
2024-07-02 03:23:29 +00:00
|
|
|
|
WarehouseID = warehousingId,
|
2024-06-26 10:33:33 +00:00
|
|
|
|
WarehousingDate = DateTime.Now,
|
|
|
|
|
Count = 1,
|
|
|
|
|
CreateTime = DateTime.Now,
|
|
|
|
|
ScanCodeTime = DateTime.Now,
|
|
|
|
|
CreateUserId = userId,
|
|
|
|
|
CreateUserName = userName,
|
|
|
|
|
MaterialsId = report.MaterialsId,
|
|
|
|
|
OddNumber = report.OddNumber,
|
|
|
|
|
Receipt = receipt,
|
|
|
|
|
SourceId = sourceId,
|
|
|
|
|
Unit = item.Unit,
|
|
|
|
|
Name = item.CodeName,
|
|
|
|
|
Code = item.Code,
|
|
|
|
|
//Destination = invoice.Consignee
|
|
|
|
|
};
|
|
|
|
|
await Add(retrospect1);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-06 10:22:07 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|