DigitalFactory/Admin.NET/Admin.NET.Application/Service/ReportDetailTable/ReportDetailTableService.cs

740 lines
33 KiB
C#
Raw Normal View History

2024-05-25 10:46:26 +00:00
using Admin.NET.Core.Service;
using Admin.NET.Application.Const;
using Admin.NET.Application.Entity;
using Microsoft.AspNetCore.Http;
2024-06-24 10:21:52 +00:00
using Admin.NET.Application.Utils;
2024-07-04 15:34:54 +00:00
using AngleSharp.Dom;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
2024-07-12 16:18:35 +00:00
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
2024-07-16 15:22:15 +00:00
using static Nest.JoinField;
2024-06-24 10:21:52 +00:00
2024-05-25 10:46:26 +00:00
namespace Admin.NET.Application;
/// <summary>
/// 汇报单详情服务
/// </summary>
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)]
public class ReportDetailTableService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<ReportDetailTable> _rep;
2024-06-07 11:13:15 +00:00
//private readonly WarehouseDetailsService _warehouseDetails;
//private readonly MaterialClassifyService _materialClassifyService;
//private readonly WarehousingStatisticsService _warehousingStatisticsService;
2024-06-12 10:10:50 +00:00
private readonly MaterialsService _materialsService;
private readonly SysUnitService _sysUnitService;
2024-05-30 10:18:10 +00:00
private readonly PrintCodeDetailService _codeDetailService;
2024-06-07 11:13:15 +00:00
private readonly ProductRetrospectService _productRetrospect;
2024-06-12 10:10:50 +00:00
private readonly ReportTableService _reportTableService;
2024-06-07 11:13:15 +00:00
private readonly UserManager _userManager;
2024-06-12 10:10:50 +00:00
//private readonly ProductWarehousingService _productWarehousing;
2024-06-07 11:13:15 +00:00
public ReportDetailTableService(SqlSugarRepository<ReportDetailTable> rep,
UserManager userManager,
MaterialsService materialsService,
SysUnitService sysUnitService,
PrintCodeDetailService codeDetailService,
2024-06-12 10:10:50 +00:00
ReportTableService reportTableService,
2024-06-07 11:13:15 +00:00
ProductRetrospectService productRetrospect)
2024-05-25 10:46:26 +00:00
{
_rep = rep;
2024-06-07 11:13:15 +00:00
_userManager = userManager;
_materialsService = materialsService;
_sysUnitService = sysUnitService;
2024-05-30 10:18:10 +00:00
_codeDetailService = codeDetailService;
2024-06-07 11:13:15 +00:00
_productRetrospect = productRetrospect;
2024-06-12 10:10:50 +00:00
_reportTableService = reportTableService;
2024-06-07 11:13:15 +00:00
//_warehouseDetails = warehouseDetails;
//_materialClassifyService = materialClassifyService;
//_warehousingStatisticsService = warehousingStatisticsService;
//_productWarehousing = productWarehousing;
2024-05-25 10:46:26 +00:00
}
/// <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())
2024-07-12 16:18:35 +00:00
|| u.State==(input.State)
2024-05-25 10:46:26 +00:00
|| 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()))
2024-07-12 16:18:35 +00:00
.WhereIF(input.State!=null, u => u.State==input.State)
2024-05-25 10:46:26 +00:00
.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)
{
2024-06-07 11:13:15 +00:00
var entity = input.Adapt<ReportDetailTable>();
await _rep.InsertAsync(entity);
if (input.UpdateUserId > 0)
2024-05-30 10:18:10 +00:00
{
2024-06-07 11:13:15 +00:00
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);
}
2024-05-30 10:18:10 +00:00
}
2024-06-07 11:13:15 +00:00
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)
2024-05-30 10:18:10 +00:00
{
2024-06-07 11:13:15 +00:00
throw Oops.Oh(ErrorCodeEnum.xg1002);
2024-05-30 10:18:10 +00:00
}
2024-07-16 15:22:15 +00:00
var reportDetailTable = await _rep.GetByIdAsync(input.WarehousingTableId);
2024-06-12 10:10:50 +00:00
var repeatCodes = await _codeDetailService.GetRepeat(input.CodeDatas);
2024-07-04 15:34:54 +00:00
var codesToKeep = new List<PrintCodeDetailOutput>();
foreach (var repeatCode in repeatCodes)
{
if (repeatCode.ReportTableId > 0)
{
var reportTable = await _reportTableService.Detail(new QueryByIdReportTableInput { Id = repeatCode.ReportTableId ?? 0 });
2024-07-06 14:34:20 +00:00
if (reportTable != null)
2024-07-04 15:34:54 +00:00
{
2024-07-06 14:34:20 +00:00
if (string.IsNullOrWhiteSpace(reportTable.ProductType) || reportTable.ProductType.Equals("普通生产"))
{
codesToKeep.Add(repeatCode);
}
2024-07-04 15:34:54 +00:00
}
}
}
repeatCodes = codesToKeep;
2024-07-16 15:22:15 +00:00
if (reportDetailTable.ProductType=="普通生产" && repeatCodes != null && repeatCodes.Count > 0)
2024-06-12 10:10:50 +00:00
{
var repeats = repeatCodes.ConvertAll(a => a.Code).Distinct();
throw Oops.Oh($"条码重复:{string.Join("", repeats)}");
}
2024-06-07 11:13:15 +00:00
var warehousing = await Detail(new QueryByIdReportDetailTableInput() { Id = input.WarehousingTableId.Value });
if (warehousing == null)
2024-05-30 10:18:10 +00:00
{
2024-06-07 11:13:15 +00:00
throw Oops.Oh(ErrorCodeEnum.xg1002);
2024-05-30 10:18:10 +00:00
}
2024-06-07 11:13:15 +00:00
var materials = await _materialsService.GetById(warehousing.MaterialsId);
if (materials == null)
{
throw Oops.Oh(ErrorCodeEnum.xg1002);
}
var units = await _sysUnitService.ListByGroupId(materials.UnitGroupId);
2024-06-12 10:10:50 +00:00
var baseUnit = units.FirstOrDefault().Name;
2024-06-07 11:13:15 +00:00
var userId = _userManager.UserId;
var userName = _userManager.RealName;
var topDatas = input.CodeDatas.FindAll(a => string.IsNullOrEmpty(a.FatherCode));
2024-07-02 03:23:29 +00:00
long reprotId = 0;
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,
BaseProductCount = repeatCodes.Count,
2024-07-12 16:18:35 +00:00
ProductCount = warehousing.ProductCount,
2024-07-02 03:23:29 +00:00
Batch = warehousing.Batch,
CodeNum = materials.CodeNum,
Name = materials.Name,
CreateUserId = userId,
CreateUserName = userName,
StartDate = DateTime.Now,
2024-07-06 14:34:20 +00:00
EndDate = input.EndDt,
2024-07-02 03:23:29 +00:00
SourceNumber = warehousing.SourceNumber,
Unit = warehousing.Unit,
2024-07-16 15:22:15 +00:00
Remarks = warehousing.Remarks,
2024-07-02 03:23:29 +00:00
};
reprotId = await _reportTableService.Add(newReport);
}
else
{
reprotId = report.Id;
}
2024-07-12 16:18:35 +00:00
2024-06-07 11:13:15 +00:00
Dictionary<AddPrintCodeDetailInput, long> list = new Dictionary<AddPrintCodeDetailInput, long>();
foreach (var item in topDatas)
{
2024-06-24 10:21:52 +00:00
var code = CodeHelper.GetCode(item.BarCode, item.QrCode);
2024-06-07 11:13:15 +00:00
var codeType = string.IsNullOrEmpty(item.BarCode) ? "二维码" : "条码";
var unit = units.Find(a => a.Name == item.PackageName);
2024-07-16 15:22:15 +00:00
await ReplaceCode(code);
2024-07-12 16:18:35 +00:00
var unitRate = Convert.ToDecimal(units.Where(t => t.Name == item.PackageName).FirstOrDefault()?.Rate);
var productRate = Convert.ToDecimal(units.Where(t => t.Name == warehousing.Package).FirstOrDefault()?.Rate);
decimal unitCount = Math.Round(unitRate / productRate, 2);
2024-06-07 11:13:15 +00:00
var detail = new AddPrintCodeDetailInput()
{
2024-07-02 03:23:29 +00:00
ReportTableId = reprotId,
2024-06-07 11:13:15 +00:00
Code = code,
CodeName = codeType,
ChildCount = unit.ChildUnitCount,
Count = 1,
Unit = item.PackageName,
2024-07-16 15:22:15 +00:00
BaseCount = GetUnitCount(units, item.PackageName, warehousing.Package),
2024-07-12 16:18:35 +00:00
BaseUnit = warehousing.Package,
2024-06-07 11:13:15 +00:00
PrintCodeTime = DateTime.Now,
CreateUserId = userId,
2024-07-06 14:34:20 +00:00
CreateUserName = userName,
ScanCodeTime = DateTime.Now,
2024-07-16 15:22:15 +00:00
ScanCodeName = userName,
State = 1
2024-06-07 11:13:15 +00:00
};
var detailId = await _codeDetailService.Add(detail);
list.Add(detail, detailId);
var childs = input.CodeDatas.FindAll(a => a.FatherCode == code);
foreach (var child in childs)
{
2024-06-24 10:21:52 +00:00
var code2 = CodeHelper.GetCode(child.BarCode, child.QrCode);
2024-07-16 15:22:15 +00:00
await ReplaceCode(code2);
2024-06-07 11:13:15 +00:00
var unit2 = units.Find(a => a.Name == child.PackageName);
2024-07-16 15:22:15 +00:00
2024-06-07 11:13:15 +00:00
var detail2 = new AddPrintCodeDetailInput()
{
2024-07-02 03:23:29 +00:00
ReportTableId = reprotId,
2024-06-07 11:13:15 +00:00
Code = code2,
CodeName = codeType,
ChildCount = unit2.ChildUnitCount,
Count = 1,
Unit = child.PackageName,
2024-07-16 15:22:15 +00:00
BaseCount = GetUnitCount(units, child.PackageName, warehousing.Package),
2024-07-12 16:18:35 +00:00
BaseUnit = warehousing.Package,
2024-06-07 11:13:15 +00:00
PrintCodeTime = DateTime.Now,
CreateUserId = userId,
CreateUserName = userName,
FatherCode = code,
2024-07-06 14:34:20 +00:00
FatherId = detailId,
ScanCodeTime = DateTime.Now,
2024-07-16 15:22:15 +00:00
ScanCodeName = userName,
State = 1
2024-06-07 11:13:15 +00:00
};
var detailId2 = await _codeDetailService.Add(detail2);
list.Add(detail2, detailId2);
2024-07-16 15:22:15 +00:00
2024-06-07 11:13:15 +00:00
var childs3 = input.CodeDatas.FindAll(a => a.FatherCode == code2);
2024-06-12 10:10:50 +00:00
foreach (var child3 in childs3)
2024-06-07 11:13:15 +00:00
{
2024-06-24 10:21:52 +00:00
var code3 = CodeHelper.GetCode(child3.BarCode, child3.QrCode);
2024-07-16 15:22:15 +00:00
await ReplaceCode(code3);
2024-06-07 11:13:15 +00:00
var unit3 = units.Find(a => a.Name == child3.PackageName);
var detail3 = new AddPrintCodeDetailInput()
{
2024-07-02 03:23:29 +00:00
ReportTableId = reprotId,
2024-06-07 11:13:15 +00:00
Code = code3,
CodeName = codeType,
ChildCount = unit3.ChildUnitCount,
2024-07-16 15:22:15 +00:00
BaseCount = GetUnitCount(units, child3.PackageName, warehousing.Package),
2024-06-07 11:13:15 +00:00
Unit = child3.PackageName,
2024-07-12 16:18:35 +00:00
BaseUnit = warehousing.Package,
2024-06-07 11:13:15 +00:00
PrintCodeTime = DateTime.Now,
CreateUserId = userId,
CreateUserName = userName,
FatherCode = code2,
2024-07-06 14:34:20 +00:00
FatherId = detailId2,
ScanCodeTime = DateTime.Now,
2024-07-16 15:22:15 +00:00
ScanCodeName = userName,
Count = 1,
State = 1
2024-06-07 11:13:15 +00:00
};
var detailId3 = await _codeDetailService.Add(detail3);
list.Add(detail3, detailId3);
2024-07-16 15:22:15 +00:00
2024-06-07 11:13:15 +00:00
if (input.CodeDatas.Any(a => a.FatherCode == code3))
{
var childs4 = input.CodeDatas.FindAll(a => a.FatherCode == code3);
2024-06-12 10:10:50 +00:00
foreach (var child4 in childs4)
2024-06-07 11:13:15 +00:00
{
2024-06-24 10:21:52 +00:00
var code4 = CodeHelper.GetCode(child4.BarCode, child4.QrCode);
2024-07-16 15:22:15 +00:00
await ReplaceCode(code4);
2024-06-07 11:13:15 +00:00
var unit4 = units.Find(a => a.Name == child4.PackageName);
var detail4 = new AddPrintCodeDetailInput()
{
2024-07-02 03:23:29 +00:00
ReportTableId = reprotId,
2024-06-07 11:13:15 +00:00
Code = code4,
CodeName = codeType,
ChildCount = unit4.ChildUnitCount,
Count = 1,
Unit = child4.PackageName,
2024-07-16 15:22:15 +00:00
BaseCount = GetUnitCount(units, child4.PackageName, warehousing.Package),
2024-07-12 16:18:35 +00:00
BaseUnit = warehousing.Package,
2024-06-07 11:13:15 +00:00
PrintCodeTime = DateTime.Now,
CreateUserId = userId,
CreateUserName = userName,
FatherCode = code3,
2024-07-06 14:34:20 +00:00
FatherId = detailId3,
ScanCodeTime = DateTime.Now,
2024-07-16 15:22:15 +00:00
ScanCodeName = userName,
State = 1
2024-06-07 11:13:15 +00:00
};
var detailId4 = await _codeDetailService.Add(detail4);
list.Add(detail4, detailId4);
2024-07-16 15:22:15 +00:00
2024-06-07 11:13:15 +00:00
if (input.CodeDatas.Any(a => a.FatherCode == code4))
{
var childs5 = input.CodeDatas.FindAll(a => a.FatherCode == code4);
2024-06-12 10:10:50 +00:00
foreach (var child5 in childs5)
2024-06-07 11:13:15 +00:00
{
2024-06-24 10:21:52 +00:00
var code5 = CodeHelper.GetCode(child5.BarCode, child5.QrCode);
2024-07-16 15:22:15 +00:00
await ReplaceCode(code5);
2024-06-07 11:13:15 +00:00
var unit5 = units.Find(a => a.Name == child5.PackageName);
var detail5 = new AddPrintCodeDetailInput()
{
2024-07-02 03:23:29 +00:00
ReportTableId = reprotId,
2024-06-07 11:13:15 +00:00
Code = code5,
CodeName = codeType,
ChildCount = unit5.ChildUnitCount,
Count = 1,
Unit = child5.PackageName,
2024-07-16 15:22:15 +00:00
BaseCount = GetUnitCount(units, child5.PackageName, warehousing.Package),
2024-07-12 16:18:35 +00:00
BaseUnit = warehousing.Package,
2024-06-07 11:13:15 +00:00
PrintCodeTime = DateTime.Now,
CreateUserId = userId,
CreateUserName = userName,
FatherCode = code4,
2024-07-06 14:34:20 +00:00
FatherId = detailId4,
ScanCodeTime = DateTime.Now,
2024-07-16 15:22:15 +00:00
ScanCodeName = userName,
State = 1
2024-06-07 11:13:15 +00:00
};
var detailId5 = await _codeDetailService.Add(detail5);
list.Add(detail5, detailId5);
2024-07-16 15:22:15 +00:00
2024-06-07 11:13:15 +00:00
}
}
}
}
}
}
}
foreach (var dic in list)
{
var item = dic.Key;
var retrospect1 = new AddProductRetrospectInput()
{
2024-07-12 16:18:35 +00:00
BaseCount = (int?)(item.BaseCount),
2024-06-07 11:13:15 +00:00
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);
}
2024-07-12 16:18:35 +00:00
var upReportTable = await _reportTableService.GetBySource(warehousing.Id);
var printCodeDetails = await _codeDetailService.GetByReportTableId(upReportTable.Id);
2024-07-16 15:22:15 +00:00
var printCodesNullFatherCode = printCodeDetails.Where(t=>t.Unit == warehousing.Package && string.IsNullOrWhiteSpace(t.FatherCode));
var clonedList = new List<PrintCodeDetail>(printCodeDetails);
foreach (var item in printCodesNullFatherCode)
2024-07-12 16:18:35 +00:00
{
2024-07-16 15:22:15 +00:00
var chilrens1 = printCodeDetails.Where(t => t.FatherCode == item.Code).ToList();
foreach (var chilren1 in chilrens1)
{
clonedList.Remove(chilren1);
var chilrens2 = printCodeDetails.Where(t => t.FatherCode == chilren1.Code).ToList();
foreach (var chilren2 in chilrens2)
{
clonedList.Remove(chilren2);
var chilrens3 = printCodeDetails.Where(t => t.FatherCode == chilren2.Code).ToList();
foreach (var chilren3 in chilrens3)
{
clonedList.Remove(chilren3);
var chilrens4 = printCodeDetails.Where(t => t.FatherCode == chilren3.Code).ToList();
foreach (var chilren4 in chilrens4)
{
clonedList.Remove(chilren4);
var chilrens5 = printCodeDetails.Where(t => t.FatherCode == chilren4.Code).ToList();
foreach (var chilren5 in chilrens5)
{
clonedList.Remove(chilren5);
}
}
}
}
}
2024-07-12 16:18:35 +00:00
}
2024-07-16 15:22:15 +00:00
var printCodesNotNullFatherCode = printCodeDetails.Where(t => t.Unit == warehousing.Package && !string.IsNullOrWhiteSpace(t.FatherCode));
foreach (var item in printCodesNotNullFatherCode)
{
var parents1 = printCodeDetails.Where(t => t.Code == item.FatherCode).ToList();
foreach (var parent1 in parents1)
{
clonedList.Remove(parent1);
var parents2 = printCodeDetails.Where(t => t.Code == parent1.FatherCode).ToList();
foreach (var parent2 in parents2)
{
clonedList.Remove(parent2);
var parents3 = printCodeDetails.Where(t => t.Code == parent2.FatherCode).ToList();
foreach (var parent3 in parents3)
{
clonedList.Remove(parent3);
var parents4 = printCodeDetails.Where(t => t.Code == parent3.FatherCode).ToList();
foreach (var parent4 in parents4)
{
clonedList.Remove(parent4);
var parents5 = printCodeDetails.Where(t => t.Code == parent4.FatherCode).ToList();
foreach (var parent5 in parents5)
{
clonedList.Remove(parent5);
}
}
}
}
}
var chilrens1 = printCodeDetails.Where(t => t.FatherCode == item.Code).ToList();
foreach (var chilren1 in chilrens1)
{
clonedList.Remove(chilren1);
var chilrens2 = printCodeDetails.Where(t => t.FatherCode == chilren1.Code).ToList();
foreach (var chilren2 in chilrens2)
{
clonedList.Remove(chilren2);
var chilrens3 = printCodeDetails.Where(t => t.FatherCode == chilren2.Code).ToList();
foreach (var chilren3 in chilrens3)
{
clonedList.Remove(chilren3);
var chilrens4 = printCodeDetails.Where(t => t.FatherCode == chilren3.Code).ToList();
foreach (var chilren4 in chilrens4)
{
clonedList.Remove(chilren4);
var chilrens5 = printCodeDetails.Where(t => t.FatherCode == chilren4.Code).ToList();
foreach (var chilren5 in chilrens5)
{
clonedList.Remove(chilren5);
}
}
}
}
}
}
decimal unitSumCount = (printCodesNullFatherCode.Sum(t=>t.BaseCount) ?? 0) + (printCodesNotNullFatherCode.Sum(t => t.BaseCount)??0);
//最大单位
foreach (var item in clonedList.Where(t=>t.Unit!=warehousing.Package))
{
unitSumCount += GetUnitCount(units,item.Unit,warehousing.Package);
}
upReportTable.BaseProductCount = unitSumCount;
2024-07-12 16:18:35 +00:00
var updateReportTableInput = upReportTable.Adapt<UpdateReportTableInput>();
await _reportTableService.Update(updateReportTableInput);
//upReportTable.
2024-06-07 11:13:15 +00:00
//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);
2024-05-25 10:46:26 +00:00
}
2024-06-06 10:22:07 +00:00
2024-07-16 15:22:15 +00:00
public async Task ReplaceCode(string code)
{
var upPrintCodeDetails = await _codeDetailService.GetByProductCodes2(code);
var printCodeDetails = await _codeDetailService.GetByReportTableId(upPrintCodeDetails.FirstOrDefault()?.ReportTableId);
foreach (var upPrintCodeDetail in upPrintCodeDetails)
{
var oldCode = upPrintCodeDetail.Code;
var year = DateTime.Now.ToString("yy");
var month = DateTime.Now.Month;
var day = DateTime.Now.Day;
int milliseconds = DateTime.Now.Millisecond; // 获取当前时间的毫秒部分0-999
upPrintCodeDetail.Code = "F" + year + month + day + milliseconds + "#" + upPrintCodeDetail.Code;
await _codeDetailService.UpdateByEntity(upPrintCodeDetail);
var chilrens = printCodeDetails.Where(t => t.FatherCode == oldCode).ToList();
foreach (var chilren in chilrens)
{
chilren.FatherCode = upPrintCodeDetail.Code;
await _codeDetailService.UpdateByEntity(chilren);
}
}
}
public decimal GetUnitCount(List<SysUnitOutput> units,string packageName,string wareHousingPackage)
{
var unitRate = Convert.ToDecimal(units.Where(t => t.Name == packageName).FirstOrDefault()?.Rate);
var productRate = Convert.ToDecimal(units.Where(t => t.Name == wareHousingPackage).FirstOrDefault()?.Rate);
decimal unitCount = Math.Round(unitRate / productRate, 2);
return unitCount;
}
2024-05-25 10:46:26 +00:00
/// <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()
{
2024-07-12 16:48:34 +00:00
var list = await _rep.AsQueryable().Where(a => !a.IsDelete && a.State == 1).ToListAsync();
foreach (var item in list)
{
var reportTable = await _reportTableService.GetBySource(item.Id);
if (reportTable != null && reportTable.BaseProductCount>item.ProductCount)
{
item.State = 2;
await _rep.AsUpdateable(item).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
}
return await _rep.AsQueryable().Where(a => !a.IsDelete && a.State == 1).Select<ReportDetailTableOutput>().ToListAsync();
2024-05-25 10:46:26 +00:00
}
2024-07-04 15:34:54 +00:00
/// <summary>
/// 修改汇报单审核状态
/// </summary>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "UpdateState")]
public async Task UpdateState(UpdateStateReportDetailTableInput input)
{
foreach (var id in input.Ids)
{
var entity = await _rep.GetByIdAsync(id);
entity.State = input.State;
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
}
2024-05-25 10:46:26 +00:00
2024-07-12 16:18:35 +00:00
/// <summary>
/// 更新生产状态
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
[HttpPost]
[ApiDescriptionSettings(Name = "UpdateProductState")]
public async Task UpdateProductState(UpdateProductStateReportDetailTableInput input)
{
var reportDetailTable = await _rep.AsQueryable()
.Where(t => !t.IsDelete)
.Where(t => t.OddNumber == input.OddNumber && t.MaterialsId == input.MaterialsId)
.FirstAsync();
if (reportDetailTable != null)
{
reportDetailTable.ProductState = input.ProductState;
await _rep.AsUpdateable(reportDetailTable).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
var reportTable = await _reportTableService.GetBySource(reportDetailTable.Id);
if (reportTable != null)
{
var entity = reportTable.Adapt<UpdateReportTableInput>();
reportTable.ProductState = input.ProductState;
if (reportTable.ProductState == 0)
{
reportTable.EndDate = DateTime.Now;
}
await _reportTableService.Update(entity);
}
}
}
2024-05-25 10:46:26 +00:00
2024-07-15 03:04:27 +00:00
/// <summary>
/// 替换条码
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
[ApiDescriptionSettings(Name = "ReplaceCode")]
public async Task ReplaceCode(ReportDetailTableReplaceDto input)
{
var codeDetail = await _codeDetailService.GetByProductCode(input.OldCodeName);
if (codeDetail == null)
{
throw Oops.Oh($"条码不存在");
}
if (codeDetail.State != 1)
{
throw Oops.Oh($"条码状态必须是生产状态");
}
if (codeDetail.Unit != input.Unit)
{
throw Oops.Oh($"条码单位不一致",codeDetail.Unit);
}
var newCodeDetail = await _codeDetailService.GetByProductCode(input.NewCodeName);
if (newCodeDetail != null)
{
2024-07-16 15:22:15 +00:00
throw Oops.Oh($"条码重复");
2024-07-15 03:04:27 +00:00
}
else
{
codeDetail.Code = input.NewCodeName;
await _codeDetailService.UpdateByEntity(codeDetail);
}
}
2024-05-25 10:46:26 +00:00
}