116 lines
4.2 KiB
C#
116 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Aop.Api.Domain;
|
|
using Aspose.Cells.Drawing;
|
|
using JNPF.Common.Dtos.VisualDev;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.Common.Filter;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys;
|
|
using JNPF.VisualDev.Interfaces;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using SqlSugar;
|
|
using Tnb.WarehouseMgr.Entities;
|
|
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
|
using Tnb.WarehouseMgr.Entities.Dto.Outputs;
|
|
using Tnb.WarehouseMgr.Interfaces;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
/// <summary>
|
|
/// 齐套配套方案服务
|
|
/// </summary>
|
|
[OverideVisualDev(ModuleId)]
|
|
public class WmsCollocationSchemeSevice : BaseWareHouseService, IWmsCollocationSchemeSevice
|
|
{
|
|
private const string ModuleId = "26167204892965";
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IRunService _runService;
|
|
private readonly IVisualDevService _visualDevService;
|
|
private readonly ISqlSugarRepository<WmsCollocationSchemeH> _repository;
|
|
|
|
|
|
|
|
public WmsCollocationSchemeSevice(
|
|
ISqlSugarRepository<WmsCollocationSchemeH> repository,
|
|
IRunService runService,
|
|
IVisualDevService visualDevService
|
|
)
|
|
{
|
|
_repository = repository;
|
|
_db = repository.AsSugarClient();
|
|
_runService = runService;
|
|
_visualDevService = visualDevService;
|
|
OverideFuncs.CreateAsync = Create;
|
|
}
|
|
|
|
private async Task<dynamic> Create(VisualDevModelDataCrInput input)
|
|
{
|
|
string materialCode = "";
|
|
int seq = 0;
|
|
|
|
if (input.data.ContainsKey(nameof(WmsCollocationSchemeH.material_code)))
|
|
{
|
|
materialCode = input.data[nameof(WmsCollocationSchemeH.material_code)]?.ToString()!;
|
|
}
|
|
if (input.data.ContainsKey(nameof(WmsCollocationSchemeH.seq)) && input.data[nameof(WmsCollocationSchemeH.seq)] != null)
|
|
{
|
|
seq = input.data[nameof(WmsCollocationSchemeH.seq)].ParseToInt();
|
|
}
|
|
if (!materialCode.IsNullOrEmpty() && seq > 0)
|
|
{
|
|
var item = await _repository.GetFirstAsync(it => it.material_code == materialCode && it.seq == seq);
|
|
if (item != null)
|
|
{
|
|
throw new AppFriendlyException($"物料+顺序【{materialCode}{seq}】,在数据库中已存在", 500);
|
|
}
|
|
}
|
|
try
|
|
{
|
|
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
|
|
await _runService.Create(templateEntity, input);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return Task.FromResult(false);
|
|
}
|
|
return await Task.FromResult(true);
|
|
}
|
|
/// <summary>
|
|
/// MES齐套搭配方案查询接口
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
//[NonUnify]
|
|
public async Task<dynamic?> MESCollocationSchemeQuery(MESCollocationSchemeQueryInput input)
|
|
{
|
|
if (input.IsNull()) throw new ArgumentNullException("input");
|
|
SqlSugarPagedList<CollocationSchemeOutput> pageData = new();
|
|
try
|
|
{
|
|
pageData = await _db.Queryable<WmsCollocationSchemeH>()
|
|
.Where(a => a.material_id == input.material_id)
|
|
.Select(a => new CollocationSchemeOutput
|
|
{
|
|
list = SqlFunc.Subqueryable<WmsCollocationSchemeD>().Where(b => b.bill_id == a.id).ToList(),
|
|
}, true)
|
|
.Mapper(it => it.CollocationSchemeDsJson = JsonConvert.SerializeObject(it.list))
|
|
.ToPagedListAsync(input.currentPage, input.pageSize);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
return pageData == null ? Enumerable.Empty<dynamic>() : PageResult<CollocationSchemeOutput>.SqlSugarPageResult(pageData);
|
|
}
|
|
}
|
|
}
|