齐套出库接口
This commit is contained in:
@@ -10,6 +10,7 @@ using Tnb.BasicData.Entities.Dto;
|
||||
using Tnb.BasicData.Entitys.Dto.BasProcess;
|
||||
using Tnb.BasicData.Interfaces;
|
||||
using Tnb.EquipMgr.Entities;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
|
||||
namespace Tnb.BasicData
|
||||
{
|
||||
@@ -41,8 +42,10 @@ namespace Tnb.BasicData
|
||||
.LeftJoin<OrganizeEntity>((a, b) => a.source_id == b.Id)
|
||||
.LeftJoin<EqpEquipment>((a, b, c) => a.source_id == c.id)
|
||||
.LeftJoin<ToolLocation>((a, b, c, d) => a.source_id == d.id)
|
||||
.LeftJoin<BasLocation>((a,b,c,d,e)=>a.source_id==e.id)
|
||||
.LeftJoin<WmsCarryH>((a,b,c,d,e,f)=>a.source_id==f.id)
|
||||
.Where((a, b, c, d) => a.code == code)
|
||||
.Select((a, b, c, d) => new
|
||||
.Select((a, b, c, d,e,f) => new
|
||||
{
|
||||
id = a.id,
|
||||
source_id = a.source_id,
|
||||
@@ -52,6 +55,10 @@ namespace Tnb.BasicData
|
||||
equip_code = a.code,
|
||||
equip_name = c.name,
|
||||
tool_location_code = d.location_code,
|
||||
bas_location_name = e.location_name,
|
||||
bas_location_code = e.location_code,
|
||||
carry_name = f.carry_name,
|
||||
carry_code = f.carry_code,
|
||||
}).FirstAsync();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace Tnb.ProductionMgr.Entities.Dto
|
||||
{
|
||||
public class KittingOutNewInput
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 目标库位编号
|
||||
/// </summary>
|
||||
public string location_code { get; set; } = string.Empty;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 齐套搭配方案ID
|
||||
/// </summary>
|
||||
public string collocation_scheme_id { get; set; } = string.Empty;
|
||||
|
||||
/// 所属工位
|
||||
/// </summary>
|
||||
public string? workstation_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 任务单
|
||||
/// </summary>
|
||||
public string? mo_task_id { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ using JNPF.Extras.CollectiveOAuth.Utils;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.Logging;
|
||||
using JNPF.Systems.Entitys.Permission;
|
||||
using JNPF.Systems.Entitys.System;
|
||||
using JNPF.Systems.Interfaces.Permission;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
using JNPF.VisualDev;
|
||||
@@ -23,11 +24,12 @@ using Tnb.ProductionMgr.Entities;
|
||||
using Tnb.ProductionMgr.Interfaces;
|
||||
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||||
using Tnb.ProductionMgr.Entities.Dto;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
|
||||
namespace Tnb.ProductionMgr
|
||||
{
|
||||
/// <summary>
|
||||
/// 生产领料
|
||||
/// 齐套出库
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
@@ -262,5 +264,143 @@ namespace Tnb.ProductionMgr
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 齐套出库申请
|
||||
/// </summary>
|
||||
/// <param name="kittingOutInput"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="AppFriendlyException"></exception>
|
||||
[HttpPost]
|
||||
public async Task<dynamic> KittingOutNew(KittingOutNewInput kittingOutInput)
|
||||
{
|
||||
PrdKittingOutH prdKittingOutH = new PrdKittingOutH();
|
||||
string warehouse_id = "26103348825381";//二楼缓存仓
|
||||
try
|
||||
{
|
||||
var db = _repository.AsSugarClient();
|
||||
PrdMoTask prdMoTask = await db.Queryable<PrdMoTask>().SingleAsync(x=>x.id==kittingOutInput.mo_task_id);
|
||||
BasMaterial basMaterial = await db.Queryable<BasMaterial>().SingleAsync(x=>x.id==prdMoTask.material_id);
|
||||
WmsCollocationSchemeH wmsCollocationSchemeH = await db.Queryable<WmsCollocationSchemeH>().SingleAsync(x=>x.id==kittingOutInput.collocation_scheme_id);
|
||||
List<WmsCollocationSchemeD> wmsCollocationSchemeDs = await db.Queryable<WmsCollocationSchemeD>().Where(x=>x.bill_id==kittingOutInput.collocation_scheme_id).ToListAsync();
|
||||
List<string> materialIds = wmsCollocationSchemeDs.Select(x => x.material_id).ToList();
|
||||
List<BasMaterial> basMaterials = await db.Queryable<BasMaterial>().Where(x=>materialIds.Contains(x.id)).ToListAsync();
|
||||
Dictionary<string,object> unitIdDic = await db.Queryable<BasMaterial>()
|
||||
.LeftJoin<DictionaryTypeEntity>((a, b) => b.EnCode == DictConst.MeasurementUnit)
|
||||
.LeftJoin<DictionaryDataEntity>((a, b, c) => b.Id == c.DictionaryTypeId && a.unit_id == c.EnCode)
|
||||
.Where((a,b,c)=>materialIds.Contains(a.id))
|
||||
.Select((a, b, c) => new
|
||||
{
|
||||
key = a.id,
|
||||
value = c.Id
|
||||
})
|
||||
.ToDictionaryAsync(x => x.key, x => x.value);
|
||||
Dictionary<string, string> unitCodeDic = basMaterials.ToDictionary(x => x.id, x => x.unit_id);
|
||||
OrganizeEntity workline = await _organizeService.GetAnyParentByWorkstationId(kittingOutInput.workstation_id, DictConst.RegionCategoryWorklineCode);
|
||||
|
||||
List<MESKittingOutStkInput> input = new List<MESKittingOutStkInput>();
|
||||
input.Add(new MESKittingOutStkInput()
|
||||
{
|
||||
org_id = _userManager.GetUserInfo().Result.organizeId,
|
||||
bill_date = DateTime.Now,
|
||||
warehouse_id = warehouse_id,
|
||||
location_code = kittingOutInput.location_code,
|
||||
material_id = prdMoTask.material_id,
|
||||
material_code = basMaterial.code,
|
||||
collocation_scheme_id = kittingOutInput.collocation_scheme_id,
|
||||
collocation_scheme_code = wmsCollocationSchemeH.bill_code,
|
||||
source_id = prdKittingOutH.id,
|
||||
seq = 0,
|
||||
create_id = _userManager.UserId,
|
||||
wmsKittingoutDs = new List<MESKittingOutStkDInput>(),
|
||||
});
|
||||
|
||||
foreach (var item in wmsCollocationSchemeDs)
|
||||
{
|
||||
input[0].wmsKittingoutDs.Add(new MESKittingOutStkDInput()
|
||||
{
|
||||
material_id = item.material_id,
|
||||
material_code = item.material_code,
|
||||
unit_id = unitIdDic.ContainsKey(item.material_id) ? unitIdDic[item.material_id].ToString() : "",
|
||||
unit_code = unitCodeDic.ContainsKey(item.material_id) ? unitCodeDic[item.material_id].ToString() : "",
|
||||
pr_qty = item.qty,
|
||||
code_batch = "",
|
||||
box = item.box,
|
||||
});
|
||||
}
|
||||
|
||||
string domain = (App.HttpContext.Request.IsHttps ? "https://" : "http://") + App.HttpContext.Request.Host;
|
||||
Dictionary<string, object> header = new Dictionary<string, object>()
|
||||
{
|
||||
["Authorization"] = App.HttpContext.Request.Headers["Authorization"]
|
||||
};
|
||||
var sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_KITTING_OUT_STK,JsonConvert.SerializeObject(input),header);
|
||||
Log.Information(sendResult);
|
||||
|
||||
AuthResponse authResponse = JsonConvert.DeserializeObject<AuthResponse>(sendResult);
|
||||
if (authResponse.code != 200)
|
||||
{
|
||||
throw Oops.Bah(authResponse.msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
prdKittingOutH.code = await _billRullService.GetBillNumber(CodeTemplateConst.PRDKITTINGOUTSTOCK_CODE);
|
||||
prdKittingOutH.warehouse_id = warehouse_id;
|
||||
prdKittingOutH.location_code = kittingOutInput.location_code;
|
||||
prdKittingOutH.material_id = basMaterial.id;
|
||||
prdKittingOutH.material_code = basMaterial.code;
|
||||
prdKittingOutH.collocation_scheme_id = kittingOutInput.collocation_scheme_id;
|
||||
prdKittingOutH.collocation_scheme_code = wmsCollocationSchemeH.bill_code;
|
||||
prdKittingOutH.workline_id = workline?.Id ?? "";
|
||||
prdKittingOutH.workstation_id = kittingOutInput.workstation_id;
|
||||
prdKittingOutH.mo_task_id = kittingOutInput.mo_task_id;
|
||||
prdKittingOutH.seq = "0";
|
||||
prdKittingOutH.create_id = _userManager.UserId;
|
||||
prdKittingOutH.create_time = DateTime.Now;
|
||||
prdKittingOutH.org_id = _userManager.GetUserInfo().Result.organizeId;
|
||||
List<PrdKittingOutD> prdKittingOutDs = new List<PrdKittingOutD>();
|
||||
foreach (var item in wmsCollocationSchemeDs)
|
||||
{
|
||||
prdKittingOutDs.Add(new PrdKittingOutD()
|
||||
{
|
||||
material_id = item.material_id,
|
||||
material_code = item.material_code,
|
||||
unit_id = unitIdDic.ContainsKey(item.material_id) ? unitIdDic[item.material_id].ToString() : "",
|
||||
unit_code = unitCodeDic.ContainsKey(item.material_id) ? unitCodeDic[item.material_id].ToString() : "",
|
||||
pr_qty = item.qty,
|
||||
code_batch = "",
|
||||
box = item.box,
|
||||
kitting_out_id = prdKittingOutH.id,
|
||||
});
|
||||
}
|
||||
|
||||
// VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
|
||||
// await _runService.Create(templateEntity, visualDevModelDataCrInput);
|
||||
|
||||
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
|
||||
{
|
||||
await _repository.InsertAsync(prdKittingOutH);
|
||||
if (prdKittingOutDs.Count > 0)
|
||||
{
|
||||
await db.Insertable<PrdKittingOutD>(prdKittingOutDs).ExecuteCommandAsync();
|
||||
}
|
||||
});
|
||||
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
throw Oops.Bah(result.ErrorMessage);
|
||||
}
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
Log.Error(e.Message);
|
||||
throw Oops.Bah(e.Message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user