一般出库申请

This commit is contained in:
2023-11-06 10:08:32 +08:00
parent 904135fdec
commit aad4888c14
5 changed files with 168 additions and 3 deletions

View File

@@ -7,6 +7,9 @@ using JNPF.Extras.CollectiveOAuth.Models;
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;
using JNPF.VisualDev.Entitys;
@@ -14,10 +17,12 @@ using JNPF.VisualDev.Interfaces;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Spire.Pdf.Exporting.XPS.Schema;
using SqlSugar;
using Tnb.BasicData;
using Tnb.BasicData.Entities;
using Tnb.ProductionMgr.Entities;
using Tnb.ProductionMgr.Entities.Dto;
using Tnb.ProductionMgr.Interfaces;
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
@@ -37,10 +42,11 @@ namespace Tnb.ProductionMgr
private readonly IRunService _runService;
private readonly IVisualDevService _visualDevService;
private readonly IDictionaryDataService _dictionaryDataService;
private readonly IOrganizeService _organizeService;
private readonly IUserManager _userManager;
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
public PrdOutstockService(ISqlSugarRepository<PrdOutstockH> repository, IRunService runService, IUserManager userManager,IVisualDevService visualDevService, IDictionaryDataService dictionaryDataService)
public PrdOutstockService(ISqlSugarRepository<PrdOutstockH> repository, IOrganizeService organizeService,IRunService runService, IUserManager userManager,IVisualDevService visualDevService, IDictionaryDataService dictionaryDataService)
{
_db = repository.AsSugarClient();
_runService = runService;
@@ -48,6 +54,7 @@ namespace Tnb.ProductionMgr
_dictionaryDataService = dictionaryDataService;
_repository = repository;
_userManager = userManager;
_organizeService = organizeService;
OverideFuncs.CreateAsync = Create;
}
@@ -114,5 +121,118 @@ namespace Tnb.ProductionMgr
}
}
public async Task<dynamic> GeneralOutstock(GeneralOutstockInput generalOutstockInput)
{
try
{
var db = _repository.AsSugarClient();
string warehouse_id = "26103348825381";//二楼缓存仓
MESCreateOutstockInput input = new MESCreateOutstockInput();
input.outstock = new MESWmsOutstockHInput();
input.outstockDs = new List<MESWmsOutstockDInput>();
PrdMoTask prdMoTask = await db.Queryable<PrdMoTask>().SingleAsync(x=>x.id==generalOutstockInput.mo_task_id);
BasLocation location = await db.Queryable<BasLocation>().Where(x=>x.location_code==generalOutstockInput.location_code).FirstAsync();
if (location == null) throw Oops.Bah("未找到库位");
string locationId = location.id;
input.outstock.bill_type = DictConst.SHENGCHANLINGLIAO;
// input.outstock.bill_date = visualDevModelDataCrInput.data.ContainsKey("bill_date") ? Convert.ToDateTime(visualDevModelDataCrInput.data["bill_date"].ToString()) : DateTime.Now;
input.outstock.bill_date = DateTime.Now;
input.outstock.org_id = _userManager.GetUserInfo().Result.organizeId;
input.outstock.warehouse_id = warehouse_id;
input.outstock.create_id = _userManager.UserId;
input.outstock.location_code = location?.location_code ?? "";
OrganizeEntity workline = await _organizeService.GetAnyParentByWorkstationId(generalOutstockInput.workstation_id, DictConst.RegionCategoryWorklineCode);
List<string> materialIds = generalOutstockInput.details.Select(x => x.material_id).ToList();
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);
foreach (var item in generalOutstockInput.details)
{
input.outstockDs.Add(new MESWmsOutstockDInput()
{
material_id = item.material_id,
material_code = item.material_code,
pr_qty = item.num,
unit_id = unitIdDic[item.material_id].ToString()
});
}
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_CREATE_OUTSTOCK,JsonConvert.SerializeObject(input),header);
Log.Information(sendResult);
AuthResponse authResponse = JsonConvert.DeserializeObject<AuthResponse>(sendResult);
if (authResponse.code != 200)
{
throw Oops.Bah(authResponse.msg);
}
else
{
PrdOutstockH prdOutstockH = new PrdOutstockH();
prdOutstockH.bill_type = DictConst.SHENGCHANLINGLIAO;
prdOutstockH.warehouse_id = warehouse_id;
prdOutstockH.location_code = generalOutstockInput.location_code;
prdOutstockH.create_id = _userManager.UserId;
prdOutstockH.org_id = _userManager.GetUserInfo().Result.organizeId;
prdOutstockH.bill_date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
prdOutstockH.workstation = generalOutstockInput.workstation_id;
prdOutstockH.workline = workline?.Id ?? "";
List<PrdOutstockD> prdOutstockDs = new List<PrdOutstockD>();
foreach (var item in generalOutstockInput.details)
{
prdOutstockDs.Add(new PrdOutstockD()
{
material_id = item.material_id,
material_code = item.material_code,
material_name = item.material_name,
pr_qty = item.num,
unit_id = unitIdDic[item.material_id].ToString(),
outstock_id = prdOutstockH.id,
source_id = prdMoTask.mo_task_code
});
}
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
{
await _repository.InsertAsync(prdOutstockH);
if (prdOutstockDs.Count > 0)
{
await db.Insertable<PrdOutstockD>(prdOutstockDs).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);
}
}
}
}