using System.Collections;
using JNPF.Common.Core.Manager;
using JNPF.Common.Dtos.VisualDev;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
using JNPF.Common.Filter;
using JNPF.Common.Security;
using JNPF.EventBus;
using JNPF.FriendlyException;
using JNPF.Systems.Entitys.System;
using JNPF.Systems.Interfaces.System;
using JNPF.VisualDev;
using JNPF.VisualDev.Entitys;
using JNPF.VisualDev.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Tnb.BasicData.Entities;
using Tnb.BasicData.Interfaces;
using Tnb.ProductionMgr.Entities.Dto.PrdManage;
using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Entities.Attributes;
using Tnb.WarehouseMgr.Entities.Consts;
using Tnb.WarehouseMgr.Entities.Dto;
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
using Tnb.WarehouseMgr.Entities.Enums;
using Tnb.WarehouseMgr.Interfaces;
namespace Tnb.WarehouseMgr
{
///
/// 销售出库服务
///
[OverideVisualDev(ModuleConsts.MODULE_WMSSORTINGTASK_ID)]
[ServiceModule(BizTypeId)]
public class WmsSortingtaskService : BaseWareHouseService, IPdaStroage
{
private const string BizTypeId = "34088685351445";
private readonly ISqlSugarClient _db;
private readonly IRunService _runService;
private readonly IVisualDevService _visualDevService;
private readonly IBasLocationService _basLocationService;
private readonly IWareHouseService _wareHouseService;
private readonly IBillRullService _billRullService;
private readonly IUserManager _userManager;
private readonly IWmsCarryBindService _wmsCarryBindService;
public WmsSortingtaskService(
ISqlSugarRepository repository,
IRunService runService,
IVisualDevService visualDevService,
IBasLocationService basLocationService,
IBillRullService billRullService,
IWareHouseService wareHouseService,
IUserManager userManager,
IEventPublisher eventPublisher
)
{
_db = repository.AsSugarClient();
_runService = runService;
_visualDevService = visualDevService;
_basLocationService = basLocationService;
_billRullService = billRullService;
_wareHouseService = wareHouseService;
_userManager = userManager;
OverideFuncs.CreateAsync = Create;
}
private async Task Create(VisualDevModelDataCrInput input)
{
//在线开发
try
{
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSSORTINGTASK_ID, true);
await _runService.Create(templateEntity, input);
}
catch (Exception)
{
throw;
}
return Task.FromResult(1);
}
public override async Task ModifyAsync(WareHouseUpInput input)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
int row = await _db.Updateable().SetColumns(it => new WmsDelivery { status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID }).Where(it => it.id == input.requireId).ExecuteCommandAsync();
if (row < 1)
{
throw Oops.Oh(ErrorCode.COM1001);
}
}
[HttpPost]
public async Task WmsSourtingtaskList(WmsSortingtaskListOutput input)
{
Dictionary queryJson = string.IsNullOrEmpty(input.queryJson) ? new Dictionary() : input.queryJson.ToObject>();
string? status = queryJson.ContainsKey("status") ? queryJson["status"].ToString() : "";
if (string.IsNullOrEmpty(input.sidx))
{
input.sidx = "a.id";
}
else
{
input.sidx = input.sidx.Replace("create_time", "a.create_time").Replace("erp_bill_code", "e.erp_bill_code");
}
var _result = await _db.Queryable()
.InnerJoin((a, b) => a.carry_id == b.carry_id)
.InnerJoin((a, b, c) => b.material_id == c.id)
.InnerJoin((a, b, c, d) => a.source_id == d.id)
.InnerJoin((a, b, c, d, e) => e.id == d.bill_id)
.InnerJoin((a, b, c, d, e, f) => f.Id == a.status)
.WhereIF(!string.IsNullOrEmpty(status), (a, b, c, d, e, f) => a.status == status)
.Select((a, b, c, d, e, f) => new WmsSortingtask
{
id = a.id,
create_time = DateTime.Parse(a.create_time.ToString("yyyy-MM-dd HH:mm:ss")),
material_id = c.id,
material_code = c.code,
material_name = c.name,
material_specification = c.material_specification,
container_no = c.material_standard,
code_batch = b.code_batch,
erp_bill_code = e.erp_bill_code,
status = f.FullName
}, true)
.OrderBy($"{input.sidx} {input.sort}")
.ToPagedListAsync(input.currentPage, input.pageSize);
var result = PageResult.SqlSugarPageResult(_result);
return result;
}
}
}