440 lines
20 KiB
C#
440 lines
20 KiB
C#
using Admin.NET.Core.Service;
|
|
using Admin.NET.Application.Const;
|
|
using Admin.NET.Application.Entity;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Admin.NET.Application.Utils;
|
|
|
|
namespace Admin.NET.Application;
|
|
/// <summary>
|
|
/// 汇报单详情服务
|
|
/// </summary>
|
|
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)]
|
|
public class ReportDetailTableService : IDynamicApiController, ITransient
|
|
{
|
|
private readonly SqlSugarRepository<ReportDetailTable> _rep;
|
|
//private readonly WarehouseDetailsService _warehouseDetails;
|
|
//private readonly MaterialClassifyService _materialClassifyService;
|
|
//private readonly WarehousingStatisticsService _warehousingStatisticsService;
|
|
private readonly MaterialsService _materialsService;
|
|
private readonly SysUnitService _sysUnitService;
|
|
private readonly PrintCodeDetailService _codeDetailService;
|
|
private readonly ProductRetrospectService _productRetrospect;
|
|
private readonly ReportTableService _reportTableService;
|
|
private readonly UserManager _userManager;
|
|
//private readonly ProductWarehousingService _productWarehousing;
|
|
public ReportDetailTableService(SqlSugarRepository<ReportDetailTable> rep,
|
|
UserManager userManager,
|
|
MaterialsService materialsService,
|
|
SysUnitService sysUnitService,
|
|
PrintCodeDetailService codeDetailService,
|
|
ReportTableService reportTableService,
|
|
ProductRetrospectService productRetrospect)
|
|
{
|
|
_rep = rep;
|
|
_userManager = userManager;
|
|
_materialsService = materialsService;
|
|
_sysUnitService = sysUnitService;
|
|
_codeDetailService = codeDetailService;
|
|
_productRetrospect = productRetrospect;
|
|
_reportTableService = reportTableService;
|
|
//_warehouseDetails = warehouseDetails;
|
|
//_materialClassifyService = materialClassifyService;
|
|
//_warehousingStatisticsService = warehousingStatisticsService;
|
|
//_productWarehousing = productWarehousing;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页查询汇报单详情
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[ApiDescriptionSettings(Name = "Page")]
|
|
public async Task<SqlSugarPagedList<ReportDetailTableOutput>> Page(ReportDetailTableInput input)
|
|
{
|
|
var query = _rep.AsQueryable().Where(a => !a.IsDelete)
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
|
|
u.ProductName.Contains(input.SearchKey.Trim())
|
|
|| u.ProductCodeNum.Contains(input.SearchKey.Trim())
|
|
|| u.OddNumber.Contains(input.SearchKey.Trim())
|
|
|| u.State.Contains(input.SearchKey.Trim())
|
|
|| u.ProductType.Contains(input.SearchKey.Trim())
|
|
|| u.ProductionLine.Contains(input.SearchKey.Trim())
|
|
|| u.CodeNum.Contains(input.SearchKey.Trim())
|
|
|| u.SourceNumber.Contains(input.SearchKey.Trim())
|
|
|| u.Specifications.Contains(input.SearchKey.Trim())
|
|
|| u.Unit.Contains(input.SearchKey.Trim())
|
|
|| u.BaseUnit.Contains(input.SearchKey.Trim())
|
|
|| u.Batch.Contains(input.SearchKey.Trim())
|
|
|| u.Package.Contains(input.SearchKey.Trim())
|
|
|| u.TeamGroup.Contains(input.SearchKey.Trim())
|
|
|| u.Operator.Contains(input.SearchKey.Trim())
|
|
|| u.SourceOddNumber.Contains(input.SearchKey.Trim())
|
|
|| u.Remarks.Contains(input.SearchKey.Trim())
|
|
)
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ProductName), u => u.ProductName.Contains(input.ProductName.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ProductCodeNum), u => u.ProductCodeNum.Contains(input.ProductCodeNum.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.OddNumber), u => u.OddNumber.Contains(input.OddNumber.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.State), u => u.State.Contains(input.State.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ProductType), u => u.ProductType.Contains(input.ProductType.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ProductionLine), u => u.ProductionLine.Contains(input.ProductionLine.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CodeNum), u => u.CodeNum.Contains(input.CodeNum.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SourceNumber), u => u.SourceNumber.Contains(input.SourceNumber.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Specifications), u => u.Specifications.Contains(input.Specifications.Trim()))
|
|
.WhereIF(input.ProductCount>0, u => u.ProductCount == input.ProductCount)
|
|
.WhereIF(input.PutWarehouse>0, u => u.PutWarehouse == input.PutWarehouse)
|
|
.WhereIF(input.BaseProductCount>0, u => u.BaseProductCount == input.BaseProductCount)
|
|
.WhereIF(input.BasePutWarehouse>0, u => u.BasePutWarehouse == input.BasePutWarehouse)
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Unit), u => u.Unit.Contains(input.Unit.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.BaseUnit), u => u.BaseUnit.Contains(input.BaseUnit.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Batch), u => u.Batch.Contains(input.Batch.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Package), u => u.Package.Contains(input.Package.Trim()))
|
|
.WhereIF(input.PackageCount>0, u => u.PackageCount == input.PackageCount)
|
|
.WhereIF(input.GatherFalseCount>0, u => u.GatherFalseCount == input.GatherFalseCount)
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.TeamGroup), u => u.TeamGroup.Contains(input.TeamGroup.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Operator), u => u.Operator.Contains(input.Operator.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SourceOddNumber), u => u.SourceOddNumber.Contains(input.SourceOddNumber.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Remarks), u => u.Remarks.Contains(input.Remarks.Trim()))
|
|
.Select<ReportDetailTableOutput>();
|
|
if(input.ProductDateRange != null && input.ProductDateRange.Count >0)
|
|
{
|
|
DateTime? start= input.ProductDateRange[0];
|
|
query = query.WhereIF(start.HasValue, u => u.ProductDate > start);
|
|
if (input.ProductDateRange.Count >1 && input.ProductDateRange[1].HasValue)
|
|
{
|
|
var end = input.ProductDateRange[1].Value.AddDays(1);
|
|
query = query.Where(u => u.ProductDate < end);
|
|
}
|
|
}
|
|
if(input.EndDateRange != null && input.EndDateRange.Count >0)
|
|
{
|
|
DateTime? start= input.EndDateRange[0];
|
|
query = query.WhereIF(start.HasValue, u => u.EndDate > start);
|
|
if (input.EndDateRange.Count >1 && input.EndDateRange[1].HasValue)
|
|
{
|
|
var end = input.EndDateRange[1].Value.AddDays(1);
|
|
query = query.Where(u => u.EndDate < 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(AddReportDetailTableInput input)
|
|
{
|
|
var entity = input.Adapt<ReportDetailTable>();
|
|
await _rep.InsertAsync(entity);
|
|
if (input.UpdateUserId > 0)
|
|
{
|
|
var details = await _codeDetailService.List();
|
|
if (details == null || details.Count < 1)
|
|
{
|
|
return 0;
|
|
}
|
|
var printDetails = details.FindAll(a => a.TempListId == input.UpdateUserId);
|
|
if (printDetails.Count < 1)
|
|
{
|
|
return 0;
|
|
}
|
|
for (int i = 0; i < printDetails.Count; i++)
|
|
{
|
|
var item = printDetails[i];
|
|
item.ReportTableId = entity.Id;
|
|
var ent = item.Adapt<PrintCodeDetail>();
|
|
await _codeDetailService.UpdateByEntity(ent);
|
|
}
|
|
}
|
|
return entity.Id;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 生产任务单关联
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[ApiDescriptionSettings(Name = "ProductionTask")]
|
|
public async Task ProductionTask(AddProductCodeInput input)
|
|
{
|
|
if (input == null || input.WarehousingTableId == null || input.CodeDatas == null || input.CodeDatas.Count == 0)
|
|
{
|
|
throw Oops.Oh(ErrorCodeEnum.xg1002);
|
|
}
|
|
|
|
var repeatCodes = await _codeDetailService.GetRepeat(input.CodeDatas);
|
|
if (repeatCodes!=null&&repeatCodes.Count>0)
|
|
{
|
|
var repeats = repeatCodes.ConvertAll(a => a.Code).Distinct();
|
|
throw Oops.Oh($"条码重复:{string.Join("、", repeats)}");
|
|
}
|
|
|
|
var warehousing = await Detail(new QueryByIdReportDetailTableInput() { Id = input.WarehousingTableId.Value });
|
|
if (warehousing == null)
|
|
{
|
|
throw Oops.Oh(ErrorCodeEnum.xg1002);
|
|
}
|
|
var materials = await _materialsService.GetById(warehousing.MaterialsId);
|
|
if (materials == null)
|
|
{
|
|
throw Oops.Oh(ErrorCodeEnum.xg1002);
|
|
}
|
|
var units = await _sysUnitService.ListByGroupId(materials.UnitGroupId);
|
|
var baseUnit = units.FirstOrDefault().Name;
|
|
var userId = _userManager.UserId;
|
|
var userName = _userManager.RealName;
|
|
var topDatas = input.CodeDatas.FindAll(a => string.IsNullOrEmpty(a.FatherCode));
|
|
Dictionary<AddPrintCodeDetailInput, long> list = new Dictionary<AddPrintCodeDetailInput, long>();
|
|
foreach (var item in topDatas)
|
|
{
|
|
var code = CodeHelper.GetCode(item.BarCode, item.QrCode);
|
|
var codeType = string.IsNullOrEmpty(item.BarCode) ? "二维码" : "条码";
|
|
var unit = units.Find(a => a.Name == item.PackageName);
|
|
|
|
var detail = new AddPrintCodeDetailInput()
|
|
{
|
|
ReportTableId = input.WarehousingTableId,
|
|
Code = code,
|
|
CodeName = codeType,
|
|
ChildCount = unit.ChildUnitCount,
|
|
Count = 1,
|
|
Unit = item.PackageName,
|
|
BaseCount = unit.Rate,
|
|
BaseUnit = baseUnit,
|
|
PrintCodeTime = DateTime.Now,
|
|
CreateUserId = userId,
|
|
CreateUserName = userName
|
|
};
|
|
var detailId = await _codeDetailService.Add(detail);
|
|
list.Add(detail, detailId);
|
|
|
|
var childs = input.CodeDatas.FindAll(a => a.FatherCode == code);
|
|
foreach (var child in childs)
|
|
{
|
|
var code2 = CodeHelper.GetCode(child.BarCode, child.QrCode);
|
|
var unit2 = units.Find(a => a.Name == child.PackageName);
|
|
var detail2 = new AddPrintCodeDetailInput()
|
|
{
|
|
ReportTableId = input.WarehousingTableId,
|
|
Code = code2,
|
|
CodeName = codeType,
|
|
ChildCount = unit2.ChildUnitCount,
|
|
Count = 1,
|
|
Unit = child.PackageName,
|
|
BaseCount = unit2.Rate,
|
|
BaseUnit = baseUnit,
|
|
PrintCodeTime = DateTime.Now,
|
|
CreateUserId = userId,
|
|
CreateUserName = userName,
|
|
FatherCode = code,
|
|
FatherId = detailId
|
|
};
|
|
var detailId2 = await _codeDetailService.Add(detail2);
|
|
list.Add(detail2, detailId2);
|
|
|
|
var childs3 = input.CodeDatas.FindAll(a => a.FatherCode == code2);
|
|
foreach (var child3 in childs3)
|
|
{
|
|
var code3 = CodeHelper.GetCode(child3.BarCode, child3.QrCode);
|
|
var unit3 = units.Find(a => a.Name == child3.PackageName);
|
|
var detail3 = new AddPrintCodeDetailInput()
|
|
{
|
|
ReportTableId = input.WarehousingTableId,
|
|
Code = code3,
|
|
CodeName = codeType,
|
|
ChildCount = unit3.ChildUnitCount,
|
|
Count = 1,
|
|
Unit = child3.PackageName,
|
|
BaseCount = unit3.Rate,
|
|
BaseUnit = baseUnit,
|
|
PrintCodeTime = DateTime.Now,
|
|
CreateUserId = userId,
|
|
CreateUserName = userName,
|
|
FatherCode = code2,
|
|
FatherId = detailId2
|
|
};
|
|
var detailId3 = await _codeDetailService.Add(detail3);
|
|
list.Add(detail3, detailId3);
|
|
if (input.CodeDatas.Any(a => a.FatherCode == code3))
|
|
{
|
|
var childs4 = input.CodeDatas.FindAll(a => a.FatherCode == code3);
|
|
foreach (var child4 in childs4)
|
|
{
|
|
var code4 = CodeHelper.GetCode(child4.BarCode, child4.QrCode);
|
|
var unit4 = units.Find(a => a.Name == child4.PackageName);
|
|
var detail4 = new AddPrintCodeDetailInput()
|
|
{
|
|
ReportTableId = input.WarehousingTableId,
|
|
Code = code4,
|
|
CodeName = codeType,
|
|
ChildCount = unit4.ChildUnitCount,
|
|
Count = 1,
|
|
Unit = child4.PackageName,
|
|
BaseCount = unit4.Rate,
|
|
BaseUnit = baseUnit,
|
|
PrintCodeTime = DateTime.Now,
|
|
CreateUserId = userId,
|
|
CreateUserName = userName,
|
|
FatherCode = code3,
|
|
FatherId = detailId3
|
|
};
|
|
var detailId4 = await _codeDetailService.Add(detail4);
|
|
list.Add(detail4, detailId4);
|
|
if (input.CodeDatas.Any(a => a.FatherCode == code4))
|
|
{
|
|
var childs5 = input.CodeDatas.FindAll(a => a.FatherCode == code4);
|
|
foreach (var child5 in childs5)
|
|
{
|
|
var code5 = CodeHelper.GetCode(child5.BarCode, child5.QrCode);
|
|
var unit5 = units.Find(a => a.Name == child5.PackageName);
|
|
var detail5 = new AddPrintCodeDetailInput()
|
|
{
|
|
ReportTableId = input.WarehousingTableId,
|
|
Code = code5,
|
|
CodeName = codeType,
|
|
ChildCount = unit5.ChildUnitCount,
|
|
Count = 1,
|
|
Unit = child5.PackageName,
|
|
BaseCount = unit5.Rate,
|
|
BaseUnit = baseUnit,
|
|
PrintCodeTime = DateTime.Now,
|
|
CreateUserId = userId,
|
|
CreateUserName = userName,
|
|
FatherCode = code4,
|
|
FatherId = detailId4
|
|
};
|
|
var detailId5 = await _codeDetailService.Add(detail5);
|
|
list.Add(detail5, detailId5);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach (var dic in list)
|
|
{
|
|
var item = dic.Key;
|
|
var retrospect1 = new AddProductRetrospectInput()
|
|
{
|
|
BaseCount = item.BaseCount,
|
|
BaseUnit = baseUnit,
|
|
Batch = warehousing.Batch,
|
|
BusinessType = "生产任务单",
|
|
CodeType = item.CodeName,
|
|
Department = warehousing.ProductionLine,
|
|
//WarehouseID = input.WarehouseId,
|
|
WarehousingDate = DateTime.Now,
|
|
Count = 1,
|
|
CreateTime = DateTime.Now,
|
|
ScanCodeTime = DateTime.Now,
|
|
CreateUserId = userId,
|
|
CreateUserName = userName,
|
|
MaterialsId = dic.Value,
|
|
OddNumber = warehousing.OddNumber,
|
|
Receipt = "汇报单",
|
|
SourceId = warehousing.Id,
|
|
Unit = item.Unit,
|
|
Name = materials.Name,
|
|
Code = item.Code
|
|
};//Destination = warehousing.Supplier,
|
|
await _productRetrospect.Add(retrospect1);
|
|
}
|
|
|
|
var report = await _reportTableService.GetBySource(input.WarehousingTableId);
|
|
if (report == null)
|
|
{
|
|
var newReport = new AddReportTableInput() { CreateTime = DateTime.Now, IsDelete = false, OddNumber = warehousing.OddNumber, State = 0, MaterialsId = warehousing.MaterialsId, SourceId = input.WarehousingTableId, ProductType = warehousing.ProductType, ProductionLine = warehousing.ProductionLine };
|
|
var addReport = await _reportTableService.Add(newReport);
|
|
}
|
|
|
|
|
|
//var details = await _warehouseDetails.List();
|
|
//if (details != null && details.Any(a => a.MaterialsId == warehousing.MaterialsId && a.Unit == warehousing.Unit))
|
|
//{
|
|
// var unit = units.Find(a => a.Name == warehousing.Unit);
|
|
// var detail = details.Find(a => a.MaterialsId == warehousing.MaterialsId && a.Unit == warehousing.Unit);
|
|
// detail.Count += warehousing.Count;
|
|
// if (unit != null)
|
|
// {
|
|
// detail.BaseCount = detail.Count * unit.Rate;
|
|
// }
|
|
// await _warehouseDetails.UpdateByEntity(detail.Adapt<WarehouseDetails>());
|
|
//}
|
|
//else
|
|
//{
|
|
// var newEnt = warehousing.Adapt<AddWarehouseDetailsInput>();
|
|
// newEnt.SourceId = warehousing.Id;
|
|
// var addId = await _warehouseDetails.Add(newEnt);
|
|
//}
|
|
|
|
//var newDetail = warehousing.Adapt<AddWarehousingStatisticsInput>();
|
|
//newDetail.SourceId = warehousing.Id;
|
|
//await _warehousingStatisticsService.Add(newDetail);
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 删除汇报单详情
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[ApiDescriptionSettings(Name = "Delete")]
|
|
public async Task Delete(DeleteReportDetailTableInput 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(UpdateReportDetailTableInput input)
|
|
{
|
|
var entity = input.Adapt<ReportDetailTable>();
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取汇报单详情
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[ApiDescriptionSettings(Name = "Detail")]
|
|
public async Task<ReportDetailTable> Detail([FromQuery] QueryByIdReportDetailTableInput 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<ReportDetailTableOutput>> List()
|
|
{
|
|
return await _rep.AsQueryable().Where(a => !a.IsDelete).Select<ReportDetailTableOutput>().ToListAsync();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|