一般出库申请
This commit is contained in:
@@ -169,6 +169,16 @@ public static class DictConst
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const string CHANCHENGPINRUKUDAN = "40";
|
public const string CHANCHENGPINRUKUDAN = "40";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生产领料单
|
||||||
|
/// </summary>
|
||||||
|
public const string SHENGCHANLINGLIAO = "23";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生产补料单
|
||||||
|
/// </summary>
|
||||||
|
public const string SHENGCHANBULIAO = "24";
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
namespace Tnb.ProductionMgr.Entities.Dto
|
||||||
|
{
|
||||||
|
public class GeneralOutstockInput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 目标库位编号
|
||||||
|
/// </summary>
|
||||||
|
public string location_code { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// 所属工位
|
||||||
|
/// </summary>
|
||||||
|
public string? workstation_id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 任务单
|
||||||
|
/// </summary>
|
||||||
|
public string? mo_task_id { get; set; }
|
||||||
|
|
||||||
|
public List<GeneralOutstockDInput> details { get; set; } = new List<GeneralOutstockDInput>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GeneralOutstockDInput
|
||||||
|
{
|
||||||
|
public string material_id { get; set; }
|
||||||
|
public string material_code { get; set; }
|
||||||
|
public string material_name { get; set; }
|
||||||
|
public decimal num { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,7 +32,7 @@ public partial class PrdOutstockD : BaseEntity<string>
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 出库需求数量
|
/// 出库需求数量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? pr_qty { get; set; }
|
public decimal? pr_qty { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 来源单据id
|
/// 来源单据id
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
using Tnb.ProductionMgr.Entities.Dto;
|
||||||
|
|
||||||
namespace Tnb.ProductionMgr.Interfaces
|
namespace Tnb.ProductionMgr.Interfaces
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -5,6 +7,10 @@ namespace Tnb.ProductionMgr.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IPrdOutstockService
|
public interface IPrdOutstockService
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 一般出库申请
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Task<dynamic> GeneralOutstock(GeneralOutstockInput input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,9 @@ using JNPF.Extras.CollectiveOAuth.Models;
|
|||||||
using JNPF.Extras.CollectiveOAuth.Utils;
|
using JNPF.Extras.CollectiveOAuth.Utils;
|
||||||
using JNPF.FriendlyException;
|
using JNPF.FriendlyException;
|
||||||
using JNPF.Logging;
|
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.Systems.Interfaces.System;
|
||||||
using JNPF.VisualDev;
|
using JNPF.VisualDev;
|
||||||
using JNPF.VisualDev.Entitys;
|
using JNPF.VisualDev.Entitys;
|
||||||
@@ -14,10 +17,12 @@ using JNPF.VisualDev.Interfaces;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Spire.Pdf.Exporting.XPS.Schema;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Tnb.BasicData;
|
using Tnb.BasicData;
|
||||||
using Tnb.BasicData.Entities;
|
using Tnb.BasicData.Entities;
|
||||||
using Tnb.ProductionMgr.Entities;
|
using Tnb.ProductionMgr.Entities;
|
||||||
|
using Tnb.ProductionMgr.Entities.Dto;
|
||||||
using Tnb.ProductionMgr.Interfaces;
|
using Tnb.ProductionMgr.Interfaces;
|
||||||
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||||||
|
|
||||||
@@ -37,10 +42,11 @@ namespace Tnb.ProductionMgr
|
|||||||
private readonly IRunService _runService;
|
private readonly IRunService _runService;
|
||||||
private readonly IVisualDevService _visualDevService;
|
private readonly IVisualDevService _visualDevService;
|
||||||
private readonly IDictionaryDataService _dictionaryDataService;
|
private readonly IDictionaryDataService _dictionaryDataService;
|
||||||
|
private readonly IOrganizeService _organizeService;
|
||||||
private readonly IUserManager _userManager;
|
private readonly IUserManager _userManager;
|
||||||
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
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();
|
_db = repository.AsSugarClient();
|
||||||
_runService = runService;
|
_runService = runService;
|
||||||
@@ -48,6 +54,7 @@ namespace Tnb.ProductionMgr
|
|||||||
_dictionaryDataService = dictionaryDataService;
|
_dictionaryDataService = dictionaryDataService;
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
|
_organizeService = organizeService;
|
||||||
OverideFuncs.CreateAsync = Create;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user