Merge branch 'dev' of https://git.tuotong-tech.com/tnb/tnb.server into dev
This commit is contained in:
@@ -169,6 +169,16 @@ public static class DictConst
|
||||
/// </summary>
|
||||
public const string CHANCHENGPINRUKUDAN = "40";
|
||||
|
||||
/// <summary>
|
||||
/// 生产领料单
|
||||
/// </summary>
|
||||
public const string SHENGCHANLINGLIAO = "23";
|
||||
|
||||
/// <summary>
|
||||
/// 生产补料单
|
||||
/// </summary>
|
||||
public const string SHENGCHANBULIAO = "24";
|
||||
|
||||
|
||||
#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; }
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
|
||||
public string parent_id { get; set; }
|
||||
public string material_id { get; set; }
|
||||
public string material_code { get; set; }
|
||||
public string workstation_id { get; set; }
|
||||
public List<MaterialPreparationPlanDDOutput> children { get; set; } = new List<MaterialPreparationPlanDDOutput>();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public partial class PrdOutstockD : BaseEntity<string>
|
||||
/// <summary>
|
||||
/// 出库需求数量
|
||||
/// </summary>
|
||||
public string? pr_qty { get; set; }
|
||||
public decimal? pr_qty { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 来源单据id
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Tnb.ProductionMgr.Entities;
|
||||
using Tnb.ProductionMgr.Entities.Dto;
|
||||
|
||||
namespace Tnb.ProductionMgr.Interfaces
|
||||
@@ -28,5 +29,12 @@ namespace Tnb.ProductionMgr.Interfaces
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public Task<dynamic> InstockTypeOne(InstockInput inut);
|
||||
|
||||
/// <summary>
|
||||
/// 短管挤出入库申请
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public Task<string> InstockTubeOne(PrdReport prdReport);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,13 @@ namespace Tnb.ProductionMgr.Interfaces
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<dynamic> GetMaterialPreparationPlan();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据工位获取进行中的任务单信息
|
||||
/// </summary>
|
||||
/// <param name="dic"></param>
|
||||
/// <returns></returns>
|
||||
Task<PrdMoTask> GetPrdMoTaskInfoByStationId(Dictionary<string, string> dic);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using Tnb.ProductionMgr.Entities.Dto;
|
||||
|
||||
namespace Tnb.ProductionMgr.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
@@ -5,6 +7,10 @@ namespace Tnb.ProductionMgr.Interfaces
|
||||
/// </summary>
|
||||
public interface IPrdOutstockService
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 一般出库申请
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<dynamic> GeneralOutstock(GeneralOutstockInput input);
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ namespace Tnb.ProductionMgr
|
||||
{
|
||||
private readonly ISqlSugarRepository<PrdFeedingH> _repository;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IPrdMoTaskService _prdMoTaskService;
|
||||
private readonly IBillRullService _billRullService;
|
||||
// private readonly WmsSignForDeliveryService _wmsSignForDeliveryService;
|
||||
|
||||
@@ -44,12 +45,14 @@ namespace Tnb.ProductionMgr
|
||||
public PrdFeedingService(
|
||||
ISqlSugarRepository<PrdFeedingH> repository,
|
||||
IBillRullService billRullService,
|
||||
IPrdMoTaskService prdMoTaskService,
|
||||
// WmsSignForDeliveryService wmsSignForDeliveryService,
|
||||
IUserManager userManager
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_userManager = userManager;
|
||||
_prdMoTaskService = prdMoTaskService;
|
||||
// _wmsSignForDeliveryService = _wmsSignForDeliveryService;
|
||||
_billRullService = billRullService;
|
||||
}
|
||||
@@ -331,6 +334,129 @@ namespace Tnb.ProductionMgr
|
||||
if(!result.IsSuccess) throw Oops.Bah(result.ErrorMessage);
|
||||
return result.IsSuccess ? "签收成功" : result.ErrorMessage;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生产投料
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
/// <exception cref="AppFriendlyException"></exception>
|
||||
[HttpPost]
|
||||
public async Task<dynamic> Feeding(MaterialReceiptNewInput input)
|
||||
{
|
||||
var db = _repository.AsSugarClient();
|
||||
var moTask = await _prdMoTaskService.GetPrdMoTaskInfoByStationId(new Dictionary<string, string>()
|
||||
{
|
||||
{"station_id",input.station_id}
|
||||
});
|
||||
|
||||
if (moTask == null) throw Oops.Bah("找不到任务单");
|
||||
PrdFeedingH prdFeedingH = null;
|
||||
List<PrdFeedingD> list = new List<PrdFeedingD>();
|
||||
DbResult<bool> result2 = new DbResult<bool>();
|
||||
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
||||
{
|
||||
var parentMoTask = await db.Queryable<PrdMoTask>().FirstAsync(x => x.id == moTask.parent_id);
|
||||
string worklineId = moTask.workline_id;
|
||||
if (parentMoTask != null && !string.IsNullOrEmpty(parentMoTask.workline_id))
|
||||
{
|
||||
worklineId = parentMoTask.workline_id;
|
||||
}
|
||||
var carry = await db.Queryable<WmsCarryH>().SingleAsync(x => x.carry_code == input.carry_code);
|
||||
var workline = await db.Queryable<OrganizeEntity>().SingleAsync(x => x.Id == worklineId);
|
||||
var workshop = await db.Queryable<OrganizeEntity>().SingleAsync(x=>x.Id==workline.ParentId);
|
||||
var inputMaterials = await db.Queryable<BasMbomInput>()
|
||||
.Where(x => x.mbom_id == moTask.bom_id && x.mbom_process_id == moTask.mbom_process_id)
|
||||
.Select(x=>x.material_id)
|
||||
.ToListAsync();
|
||||
|
||||
|
||||
string code = await _billRullService.GetBillNumber(Tnb.BasicData.CodeTemplateConst.FEEDING_CODE);
|
||||
prdFeedingH = new PrdFeedingH()
|
||||
{
|
||||
code = code,
|
||||
station_id = input.station_id,
|
||||
mo_task_id = moTask.id,
|
||||
process_id = moTask.process_id,
|
||||
equip_id = input.equip_id,
|
||||
workshop_id = workshop?.Id,
|
||||
carry_id = carry.id,
|
||||
workline_id = moTask.workline_id,
|
||||
carry_code = input.carry_code,
|
||||
// remark = input.remark,
|
||||
mbom_process_id = moTask.mbom_process_id,
|
||||
create_id = _userManager.UserId,
|
||||
create_time = DateTime.Now,
|
||||
org_id = _userManager.GetUserInfo().Result.organizeId
|
||||
};
|
||||
|
||||
if (input.details != null && input.details.Count > 0)
|
||||
{
|
||||
foreach (var item in input.details)
|
||||
{
|
||||
if(!inputMaterials.Contains(item["material_id"]))
|
||||
throw new Exception("该物料不是生产bom投入物料,不能签收");
|
||||
|
||||
var detail = await db.Queryable<PrdMaterialReceiptD>()
|
||||
.Where(x => x.member_carry_code == input.carry_code && x.is_all_feeding == 0).FirstAsync();
|
||||
decimal num = Convert.ToDecimal(item["num"]);
|
||||
list.Add(new PrdFeedingD
|
||||
{
|
||||
feeding_id = prdFeedingH.id,
|
||||
material_receipt_detail_id = detail?.id,
|
||||
material_id = item["material_id"],
|
||||
num = num,
|
||||
batch = item["batch"],
|
||||
unit_id = item["unit_id"],
|
||||
carry_id = carry.id,
|
||||
status = "0",
|
||||
use_num = 0,
|
||||
});
|
||||
|
||||
if (detail != null)
|
||||
{
|
||||
if(detail.feeding_num + num > detail.num)
|
||||
{
|
||||
throw new Exception("投料数量不能大于签收数量");
|
||||
}else if (detail.feeding_num + num == detail.num)
|
||||
{
|
||||
await db.Updateable<PrdMaterialReceiptD>()
|
||||
.SetColumns(x => x.feeding_num == x.feeding_num + num)
|
||||
.SetColumns(x => x.is_all_feeding == 1)
|
||||
.Where(x => x.id == detail.id)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await db.Updateable<PrdMaterialReceiptD>()
|
||||
.SetColumns(x => x.feeding_num == x.feeding_num + num)
|
||||
.Where(x => x.id == detail.id)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("没有签收单,无法投料");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("没有签收物料");
|
||||
}
|
||||
|
||||
|
||||
await db.Insertable<PrdFeedingH>(prdFeedingH).ExecuteCommandAsync();
|
||||
await db.Insertable<PrdFeedingD>(list).ExecuteCommandAsync();
|
||||
|
||||
});
|
||||
|
||||
|
||||
if(!result.IsSuccess) throw Oops.Bah(result.ErrorMessage);
|
||||
return result.IsSuccess ? "签收成功" : result.ErrorMessage;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<dynamic> GetFeedingRecordTree()
|
||||
|
||||
@@ -389,5 +389,115 @@ namespace Tnb.ProductionMgr
|
||||
if(!result2.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
|
||||
return result2.IsSuccess ? "申请成功" : result2.ErrorMessage;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<string> InstockTubeOne(PrdReport prdReport)
|
||||
{
|
||||
var db = _repository.AsSugarClient();
|
||||
string location_code = "JMXHC-01";
|
||||
string warehouse_id = "26103348825381";
|
||||
|
||||
PrdInstockH prdInstockH = null;
|
||||
List<PrdInstockD> prdInstockDs = new List<PrdInstockD>() { };
|
||||
DbResult<bool> result2 = new DbResult<bool>();
|
||||
BasMaterial basMaterial = await db.Queryable<BasMaterial>().SingleAsync(x=>x.id==prdReport.material_id);
|
||||
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
||||
{
|
||||
OrganizeEntity workline = await _organizeService.GetAnyParentByWorkstationId(prdReport.station, DictConst.RegionCategoryWorklineCode);
|
||||
OrganizeEntity workshop = await _organizeService.GetAnyParentByWorkstationId(prdReport.station, DictConst.RegionCategoryWorkshopCode);
|
||||
|
||||
prdInstockH = new PrdInstockH()
|
||||
{
|
||||
bill_type = DictConst.CHANCHENGPINRUKUDAN,
|
||||
bill_date = DateTime.Now,
|
||||
create_id = _userManager.UserId,
|
||||
location_code = location_code,
|
||||
carry_code = prdReport.material_box_code,
|
||||
is_check = 1,
|
||||
station_id = prdReport.station,
|
||||
workline_id = workline?.Id ?? "",
|
||||
workshop_id = workshop?.Id ?? "",
|
||||
org_id = _userManager.GetUserInfo().Result.organizeId,
|
||||
warehouse_id = warehouse_id,
|
||||
status = 0,
|
||||
};
|
||||
|
||||
prdInstockDs.Add(new PrdInstockD()
|
||||
{
|
||||
instock_id = prdInstockH.id,
|
||||
report_id = prdReport.create_id,
|
||||
material_id = prdReport.material_id,
|
||||
material_code = basMaterial.code,
|
||||
unit_id = prdReport.unit_id,
|
||||
barcode = prdReport.barcode,
|
||||
code_batch = prdReport.barcode+"0001",
|
||||
quantity = (int)prdReport.reported_qty,
|
||||
});
|
||||
});
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
MESCreateInstockInput mesCreateInstockInput = new MESCreateInstockInput();
|
||||
mesCreateInstockInput.instock = new MESWmsInstockHInput()
|
||||
{
|
||||
org_id = _userManager.GetUserInfo().Result.organizeId,
|
||||
bill_date = DateTime.Now,
|
||||
bill_type = DictConst.CHANCHENGPINRUKUDAN,
|
||||
warehouse_id = warehouse_id,
|
||||
source_id = prdInstockH.id,
|
||||
create_id = _userManager.UserId,
|
||||
carry_code = prdReport.material_box_code,
|
||||
location_code = location_code,
|
||||
is_check = 1,
|
||||
};
|
||||
mesCreateInstockInput.instockds = new List<MESWmsInstockDInput>();
|
||||
mesCreateInstockInput.instockcodes = new List<MESWmsInstockCodeInput>();
|
||||
mesCreateInstockInput.instockds.Add(new MESWmsInstockDInput()
|
||||
{
|
||||
material_id = prdReport.material_id,
|
||||
material_code = basMaterial.code,
|
||||
unit_id = prdReport.unit_id,
|
||||
code_batch = prdReport.barcode,
|
||||
pr_qty = (int)prdReport.reported_qty,
|
||||
});
|
||||
|
||||
mesCreateInstockInput.instockcodes.Add(new MESWmsInstockCodeInput()
|
||||
{
|
||||
material_id = prdReport.material_id,
|
||||
material_code = basMaterial.code,
|
||||
unit_id = prdReport.unit_id,
|
||||
barcode = prdReport.barcode,
|
||||
code_batch = prdReport.barcode+"0001",
|
||||
codeqty = (int)prdReport.reported_qty,
|
||||
});
|
||||
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_INSTOCK,JsonConvert.SerializeObject(mesCreateInstockInput),header);
|
||||
Log.Information(sendResult);
|
||||
AuthResponse authResponse = JsonConvert.DeserializeObject<AuthResponse>(sendResult);
|
||||
if (authResponse.code != 200 || !authResponse.data.ObjToBool())
|
||||
{
|
||||
throw Oops.Bah(authResponse.msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
result2 = await db.Ado.UseTranAsync(async () =>
|
||||
{
|
||||
await _repository.InsertAsync(prdInstockH);
|
||||
|
||||
if (prdInstockDs.Count > 0)
|
||||
{
|
||||
await db.Insertable<PrdInstockD>(prdInstockDs).ExecuteCommandAsync();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return result2.IsSuccess ? "true" : "false";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,7 @@ namespace Tnb.ProductionMgr
|
||||
private static Dictionary<string, object> _dicProcess = new Dictionary<string, object>();
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IBillRullService _billRuleService;
|
||||
private readonly IPrdInstockService _prdInstockService;
|
||||
private readonly IQcCheckPlanService _qcCheckPlanService;
|
||||
|
||||
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
||||
@@ -79,6 +80,7 @@ namespace Tnb.ProductionMgr
|
||||
IDictionaryDataService dictionaryDataService,
|
||||
IRunService runService,
|
||||
IBillRullService billRullService,
|
||||
IPrdInstockService prdInstockService,
|
||||
IVisualDevService visualDevService,
|
||||
IQcCheckPlanService qcCheckPlanService
|
||||
)
|
||||
@@ -92,6 +94,7 @@ namespace Tnb.ProductionMgr
|
||||
OverideFuncs.DeleteAsync = Delete;
|
||||
OverideFuncs.GetListAsync = GetList;
|
||||
_billRuleService = billRullService;
|
||||
_prdInstockService = prdInstockService;
|
||||
_qcCheckPlanService=qcCheckPlanService;
|
||||
}
|
||||
|
||||
@@ -1442,11 +1445,12 @@ namespace Tnb.ProductionMgr
|
||||
public async Task<dynamic> PrdReport(PrdReportCrInput input)
|
||||
{
|
||||
var db = _repository.AsSugarClient();
|
||||
var prdMoTask = await db.Queryable<PrdMoTask>().SingleAsync(x => x.id == input.mo_task_id);
|
||||
var equip = await db.Queryable<EqpEquipment>().SingleAsync(x=>x.id==prdMoTask.eqp_id);
|
||||
var report = await db.Queryable<PrdReport>().FirstAsync(it => it.mo_task_id == input.mo_task_id);
|
||||
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
|
||||
{
|
||||
var row = -1;
|
||||
var report = await db.Queryable<PrdReport>().FirstAsync(it => it.mo_task_id == input.mo_task_id);
|
||||
var prdMoTask = await db.Queryable<PrdMoTask>().SingleAsync(x => x.id == input.mo_task_id);
|
||||
var prdMo = await db.Queryable<PrdMo>().SingleAsync(x => x.id == prdMoTask.mo_id);
|
||||
var mbomProcess = await db.Queryable<BasMbomProcess>().SingleAsync(x => x.id == prdMoTask.mbom_process_id);
|
||||
|
||||
@@ -1724,8 +1728,20 @@ namespace Tnb.ProductionMgr
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
if (equip.tube == "1")
|
||||
{
|
||||
string resultMsg = await _prdInstockService.InstockTubeOne(report);
|
||||
if (resultMsg == "true") return true;
|
||||
throw Oops.Bah(resultMsg);
|
||||
}
|
||||
}
|
||||
|
||||
if (!result.IsSuccess) throw Oops.Bah(result.ErrorMessage);
|
||||
return result.IsSuccess;
|
||||
}
|
||||
@@ -2613,6 +2629,7 @@ namespace Tnb.ProductionMgr
|
||||
/// 获取备料计划
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<dynamic> GetMaterialPreparationPlan()
|
||||
{
|
||||
string now = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
@@ -2627,6 +2644,7 @@ namespace Tnb.ProductionMgr
|
||||
rate_num = SqlFunc.Subqueryable<BasMbom>().Where(o => o.id == a.bom_id)
|
||||
.OrderByDesc(o => o.create_time).Select(o => o.num),
|
||||
parent_id = b.parent_id,
|
||||
workstation_id = b.workstation_id,
|
||||
material_id = b.material_id,
|
||||
material_code = c.code,
|
||||
children = SqlFunc.Subqueryable<BasMbomInput>()
|
||||
@@ -2643,7 +2661,7 @@ namespace Tnb.ProductionMgr
|
||||
|
||||
var prdMoTaskList = await _db.Queryable<PrdMoTask>()
|
||||
.LeftJoin<BasMaterial>((a, b) => a.material_id == b.id)
|
||||
.Where(a => a.schedule_type == 2 && string.IsNullOrEmpty(a.parent_id) && a.estimated_start_date.Value.ToString("yyyy-MM-dd") == now)
|
||||
.Where(a => a.schedule_type == 2 && string.IsNullOrEmpty(a.parent_id) && a.estimated_start_date.Value.ToString("yyyy-MM-dd") == now && (a.mo_task_status==DictConst.MoStatusPauseCode || a.mo_task_status==DictConst.ToBeScheduledEncode || a.mo_task_status==DictConst.ToBeStartedEnCode || a.mo_task_status==DictConst.InProgressEnCode))
|
||||
.Select((a,b)=>new MaterialPreparationPlanOutput()
|
||||
{
|
||||
mo_task_id = a.id,
|
||||
@@ -2672,6 +2690,25 @@ namespace Tnb.ProductionMgr
|
||||
return prdMoTaskList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据工位获取进行中的任务单信息
|
||||
/// </summary>
|
||||
/// <param name="dic"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<PrdMoTask> GetPrdMoTaskInfoByStationId(Dictionary<string, string> dic)
|
||||
{
|
||||
string station_id = dic.ContainsKey("station_id") ? dic["station_id"] : "";
|
||||
if (string.IsNullOrEmpty(station_id)) throw Oops.Bah("工位错误");
|
||||
var prdMoTask = await _db.Queryable<PrdMoTask>().Where(x => x.workstation_id == station_id && x.parent_id!=null && x.mo_task_status==DictConst.InProgressEnCode).FirstAsync();
|
||||
if (prdMoTask != null)
|
||||
{
|
||||
BasMaterial basMaterial = await _db.Queryable<BasMaterial>().SingleAsync(x => x.id == prdMoTask.material_id);
|
||||
prdMoTask.material_name = basMaterial.name;
|
||||
}
|
||||
|
||||
return prdMoTask;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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,119 @@ 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();
|
||||
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);
|
||||
|
||||
foreach (var item in generalOutstockInput.details)
|
||||
{
|
||||
input.outstockDs.Add(new MESWmsOutstockDInput()
|
||||
{
|
||||
material_id = item.material_id,
|
||||
material_code = basMaterials.First(x=>x.id==item.material_id).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 = basMaterials.First(x=>x.id==item.material_id).code,
|
||||
material_name = basMaterials.First(x=>x.id==item.material_id).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