157 lines
6.4 KiB
C#
157 lines
6.4 KiB
C#
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
using JNPF.Common.Contracts;
|
||
using JNPF.Common.Core.Manager;
|
||
using JNPF.Common.Dtos.VisualDev;
|
||
using JNPF.Common.Enums;
|
||
using JNPF.Common.Extension;
|
||
using JNPF.Common.Security;
|
||
using JNPF.FriendlyException;
|
||
using JNPF.Logging;
|
||
using JNPF.Systems.Interfaces.System;
|
||
using JNPF.VisualDev;
|
||
using JNPF.VisualDev.Interfaces;
|
||
using Mapster;
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.Extensions.Logging;
|
||
using Npgsql;
|
||
using SqlSugar;
|
||
using Tnb.BasicData.Entities;
|
||
using Tnb.Common.Utils;
|
||
using Tnb.WarehouseMgr.Entities;
|
||
using Tnb.WarehouseMgr.Entities.Consts;
|
||
using Tnb.WarehouseMgr.Entities.Dto;
|
||
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||
using Tnb.WarehouseMgr.Entities.Dto.Outputs;
|
||
using Tnb.WarehouseMgr.Entities.Entity;
|
||
using Tnb.WarehouseMgr.Entities.Enums;
|
||
using Tnb.WarehouseMgr.Interfaces;
|
||
|
||
namespace Tnb.WarehouseMgr
|
||
{
|
||
/// <summary>
|
||
/// 委外收货订单
|
||
/// </summary>
|
||
[OverideVisualDev(ModuleConsts.MODULE_WMSOUTSOURCEORDER_ID)]
|
||
public class WmsOutsourceService : BaseWareHouseService
|
||
{
|
||
private readonly ISqlSugarClient _db;
|
||
private readonly IUserManager _userManager;
|
||
private readonly IBillRullService _billRullService;
|
||
private readonly IRunService _runService;
|
||
private readonly IVisualDevService _visualDevService;
|
||
public WmsOutsourceService(
|
||
ISqlSugarRepository<WmsOutsourceH> repository,
|
||
IUserManager userManager,
|
||
IBillRullService billRullService,
|
||
IRunService runService,
|
||
IVisualDevService visualDevService)
|
||
{
|
||
_db = repository.AsSugarClient();
|
||
_userManager = userManager;
|
||
_billRullService = billRullService;
|
||
_runService = runService;
|
||
_visualDevService = visualDevService;
|
||
}
|
||
|
||
public override async Task ModifyAsync(WareHouseUpInput input)
|
||
{
|
||
if (input == null)
|
||
{
|
||
throw new ArgumentNullException(nameof(input));
|
||
}
|
||
|
||
//if (!isOk)
|
||
//{
|
||
// throw Oops.Oh(ErrorCode.COM1001);
|
||
//}
|
||
}
|
||
|
||
[HttpPost]
|
||
public async Task BarCodePrint(BarCodeInput input)
|
||
{
|
||
if (input == null)
|
||
{
|
||
throw new AppFriendlyException(nameof(input), 500);
|
||
}
|
||
List<string> barcodes = new();
|
||
try
|
||
{
|
||
await _db.Ado.BeginTranAsync();
|
||
if (_db.Queryable<WmsTempCode>().Where(it => input.BillId == it.require_id).Any())
|
||
{
|
||
throw new AppFriendlyException("条码已生成", 500);
|
||
};
|
||
WmsOutsourceD WmsOutsourceD = await _db.Queryable<WmsOutsourceD>().Where(it => input.BillId == it.id).FirstAsync();
|
||
WmsOutsourceH WmsOutsourceH = await _db.Queryable<WmsOutsourceH>().Where(it => WmsOutsourceD.fk_wms_outsource_order_id == it.id).FirstAsync();
|
||
|
||
if (WmsOutsourceD.actual_quantity == 0)
|
||
{
|
||
throw new AppFriendlyException("到货数量为0,没有物料可以打印", 500);
|
||
};
|
||
|
||
List<WmsTempCode> wmsTempCodes = new();
|
||
decimal? minPacking = (await _db.Queryable<BasMaterial>().FirstAsync(it => it.id == WmsOutsourceD.matcode_id))?.minpacking;
|
||
if (!minPacking.HasValue || minPacking.Value <= 0)
|
||
{
|
||
throw new AppFriendlyException($"物料{WmsOutsourceD.matcode} {WmsOutsourceD.matcode_id} 包装数量为空或者等于0,无法打印!", 500);
|
||
};
|
||
int codeNum = 0;
|
||
|
||
if (minPacking.HasValue && minPacking.Value > 0)
|
||
{
|
||
int mod = (int)(WmsOutsourceD.actual_quantity % minPacking.Value);
|
||
codeNum = (int)(mod > 0 ? (WmsOutsourceD.actual_quantity / minPacking.Value) + 1 : WmsOutsourceD.actual_quantity / minPacking.Value);
|
||
|
||
for (int j = 0; j < codeNum; j++)
|
||
{
|
||
int index = j + 1;
|
||
//string code = $"{WmsPurchaseD.material_code}-{WmsPurchaseD.code_batch}-{index.ToString().PadLeft(4, '0')}";
|
||
// 变更加流水号
|
||
string watercode = await _billRullService.GetBillNumber(WmsWareHouseConst.WMS_OUTSOURCE_MAT_ENCODE);
|
||
|
||
string code = $"WWSH{watercode}";
|
||
WmsTempCode barCode = new()
|
||
{
|
||
material_id = WmsOutsourceD.matcode_id,
|
||
material_code = WmsOutsourceD.matcode,
|
||
barcode = code,
|
||
code_batch = WmsOutsourceD.code_batch,
|
||
material_specification = WmsOutsourceD.matspecification,
|
||
codeqty = minPacking,
|
||
unit_id = WmsOutsourceD.unit,
|
||
is_lock = 0,
|
||
is_end = 0,
|
||
require_id = WmsOutsourceD.id,
|
||
require_code = WmsOutsourceH.outsource_order,
|
||
create_id = _userManager.UserId,
|
||
create_time = DateTime.Now,
|
||
required_type = WmsWareHouseConst.BILLTYPE_OUTSOURCE_ID
|
||
};
|
||
if (index == codeNum)
|
||
barCode.codeqty = mod == 0 ? minPacking : mod;
|
||
wmsTempCodes.Add(barCode);
|
||
}
|
||
await _db.Insertable(wmsTempCodes).ExecuteCommandAsync();
|
||
}
|
||
await _db.Ado.CommitTranAsync();
|
||
barcodes.AddRange(wmsTempCodes.Select(p => p.barcode).ToList());
|
||
if (barcodes?.Count > 0)
|
||
{
|
||
var ip = _db.Queryable<BasFactoryConfig>().Where(p => p.key == "printerip").FirstAsync().Result.value;
|
||
base.BarCodePrint(barcodes, 1, ip);
|
||
}
|
||
}
|
||
|
||
|
||
catch (Exception ex)
|
||
{
|
||
Logger.LogError($"【BarCodePrint】" + ex.Message);
|
||
Logger.LogError($"【BarCodePrint】" + ex.StackTrace);
|
||
await _db.Ado.RollbackTranAsync();
|
||
throw;
|
||
}
|
||
}
|
||
}
|
||
} |