using Admin.NET.Core.Service;
using Admin.NET.Application.Const;
using Admin.NET.Application.Entity;
using Microsoft.AspNetCore.Http;
using Admin.NET.Application.Utils;
using AngleSharp.Dom;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using static Nest.JoinField;
namespace Admin.NET.Application;
///
/// 汇报单详情服务
///
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)]
public class ReportDetailTableService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _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 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;
}
///
/// 分页查询汇报单详情
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "Page")]
public async Task> 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==(input.State)
|| 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(input.State!=null, u => u.State==input.State)
.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();
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);
}
///
/// 增加汇报单详情
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "Add")]
public async Task Add(AddReportDetailTableInput input)
{
var entity = input.Adapt();
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();
await _codeDetailService.UpdateByEntity(ent);
}
}
return entity.Id;
}
///
/// 生产任务单关联
///
///
///
[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 reportDetailTable = await _rep.GetByIdAsync(input.WarehousingTableId);
var repeatCodes = await _codeDetailService.GetRepeat(input.CodeDatas);
var codesToKeep = new List();
foreach (var repeatCode in repeatCodes)
{
if (repeatCode.ReportTableId > 0)
{
var reportTable = await _reportTableService.Detail(new QueryByIdReportTableInput { Id = repeatCode.ReportTableId ?? 0 });
if (reportTable != null)
{
if (string.IsNullOrWhiteSpace(reportTable.ProductType) || reportTable.ProductType.Equals("普通生产"))
{
codesToKeep.Add(repeatCode);
}
}
}
}
repeatCodes = codesToKeep;
if (reportDetailTable.ProductType=="普通生产" && 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));
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,
ProductCount = warehousing.ProductCount,
Batch = warehousing.Batch,
CodeNum = materials.CodeNum,
Name = materials.Name,
CreateUserId = userId,
CreateUserName = userName,
StartDate = DateTime.Now,
EndDate = input.EndDt,
SourceNumber = warehousing.SourceNumber,
Unit = warehousing.Unit,
Remarks = warehousing.Remarks,
};
reprotId = await _reportTableService.Add(newReport);
}
else
{
reprotId = report.Id;
}
Dictionary list = new Dictionary();
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);
await ReplaceCode(code);
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);
var detail = new AddPrintCodeDetailInput()
{
ReportTableId = reprotId,
Code = code,
CodeName = codeType,
ChildCount = unit.ChildUnitCount,
Count = 1,
Unit = item.PackageName,
BaseCount = GetUnitCount(units, item.PackageName, warehousing.Package),
BaseUnit = warehousing.Package,
PrintCodeTime = DateTime.Now,
CreateUserId = userId,
CreateUserName = userName,
ScanCodeTime = DateTime.Now,
ScanCodeName = userName,
State = 1
};
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);
await ReplaceCode(code2);
var unit2 = units.Find(a => a.Name == child.PackageName);
var detail2 = new AddPrintCodeDetailInput()
{
ReportTableId = reprotId,
Code = code2,
CodeName = codeType,
ChildCount = unit2.ChildUnitCount,
Count = 1,
Unit = child.PackageName,
BaseCount = GetUnitCount(units, child.PackageName, warehousing.Package),
BaseUnit = warehousing.Package,
PrintCodeTime = DateTime.Now,
CreateUserId = userId,
CreateUserName = userName,
FatherCode = code,
FatherId = detailId,
ScanCodeTime = DateTime.Now,
ScanCodeName = userName,
State = 1
};
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);
await ReplaceCode(code3);
var unit3 = units.Find(a => a.Name == child3.PackageName);
var detail3 = new AddPrintCodeDetailInput()
{
ReportTableId = reprotId,
Code = code3,
CodeName = codeType,
ChildCount = unit3.ChildUnitCount,
BaseCount = GetUnitCount(units, child3.PackageName, warehousing.Package),
Unit = child3.PackageName,
BaseUnit = warehousing.Package,
PrintCodeTime = DateTime.Now,
CreateUserId = userId,
CreateUserName = userName,
FatherCode = code2,
FatherId = detailId2,
ScanCodeTime = DateTime.Now,
ScanCodeName = userName,
Count = 1,
State = 1
};
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);
await ReplaceCode(code4);
var unit4 = units.Find(a => a.Name == child4.PackageName);
var detail4 = new AddPrintCodeDetailInput()
{
ReportTableId = reprotId,
Code = code4,
CodeName = codeType,
ChildCount = unit4.ChildUnitCount,
Count = 1,
Unit = child4.PackageName,
BaseCount = GetUnitCount(units, child4.PackageName, warehousing.Package),
BaseUnit = warehousing.Package,
PrintCodeTime = DateTime.Now,
CreateUserId = userId,
CreateUserName = userName,
FatherCode = code3,
FatherId = detailId3,
ScanCodeTime = DateTime.Now,
ScanCodeName = userName,
State = 1
};
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);
await ReplaceCode(code5);
var unit5 = units.Find(a => a.Name == child5.PackageName);
var detail5 = new AddPrintCodeDetailInput()
{
ReportTableId = reprotId,
Code = code5,
CodeName = codeType,
ChildCount = unit5.ChildUnitCount,
Count = 1,
Unit = child5.PackageName,
BaseCount = GetUnitCount(units, child5.PackageName, warehousing.Package),
BaseUnit = warehousing.Package,
PrintCodeTime = DateTime.Now,
CreateUserId = userId,
CreateUserName = userName,
FatherCode = code4,
FatherId = detailId4,
ScanCodeTime = DateTime.Now,
ScanCodeName = userName,
State = 1
};
var detailId5 = await _codeDetailService.Add(detail5);
list.Add(detail5, detailId5);
}
}
}
}
}
}
}
foreach (var dic in list)
{
var item = dic.Key;
var retrospect1 = new AddProductRetrospectInput()
{
BaseCount = (int?)(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 upReportTable = await _reportTableService.GetBySource(warehousing.Id);
var printCodeDetails = await _codeDetailService.GetByReportTableId(upReportTable.Id);
var printCodesNullFatherCode = printCodeDetails.Where(t=>t.Unit == warehousing.Package && string.IsNullOrWhiteSpace(t.FatherCode));
var clonedList = new List(printCodeDetails);
foreach (var item in printCodesNullFatherCode)
{
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);
}
}
}
}
}
}
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;
var updateReportTableInput = upReportTable.Adapt();
await _reportTableService.Update(updateReportTableInput);
//upReportTable.
//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());
//}
//else
//{
// var newEnt = warehousing.Adapt();
// newEnt.SourceId = warehousing.Id;
// var addId = await _warehouseDetails.Add(newEnt);
//}
//var newDetail = warehousing.Adapt();
//newDetail.SourceId = warehousing.Id;
//await _warehousingStatisticsService.Add(newDetail);
}
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 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;
}
///
/// 删除汇报单详情
///
///
///
[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); //真删除
}
///
/// 更新汇报单详情
///
///
///
[HttpPost]
[ApiDescriptionSettings(Name = "Update")]
public async Task Update(UpdateReportDetailTableInput input)
{
var entity = input.Adapt();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
///
/// 获取汇报单详情
///
///
///
[HttpGet]
[ApiDescriptionSettings(Name = "Detail")]
public async Task Detail([FromQuery] QueryByIdReportDetailTableInput input)
{
return await _rep.GetFirstAsync(u => u.Id == input.Id);
}
///
/// 获取汇报单详情列表
///
///
///
[HttpGet]
[ApiDescriptionSettings(Name = "List")]
public async Task> List()
{
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().ToListAsync();
}
///
/// 修改汇报单审核状态
///
///
[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();
}
}
///
/// 更新生产状态
///
///
///
///
[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();
reportTable.ProductState = input.ProductState;
if (reportTable.ProductState == 0)
{
reportTable.EndDate = DateTime.Now;
}
await _reportTableService.Update(entity);
}
}
}
///
/// 替换条码
///
///
///
[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)
{
throw Oops.Oh($"条码重复");
}
else
{
codeDetail.Code = input.NewCodeName;
await _codeDetailService.UpdateByEntity(codeDetail);
}
}
}