794 lines
38 KiB
C#
794 lines
38 KiB
C#
using JNPF.Common.Core.Manager;
|
||
using JNPF.Common.Filter;
|
||
using JNPF.Common.Security;
|
||
using JNPF.DependencyInjection;
|
||
using JNPF.DynamicApiController;
|
||
using JNPF.FriendlyException;
|
||
using JNPF.Logging;
|
||
using JNPF.Systems.Entitys.Permission;
|
||
using JNPF.Systems.Entitys.System;
|
||
using JNPF.Systems.Interfaces.System;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using SqlSugar;
|
||
using Tnb.BasicData;
|
||
using Tnb.BasicData.Entities;
|
||
using Tnb.EquipMgr.Entities;
|
||
using Tnb.ProductionMgr.Entities;
|
||
using Tnb.ProductionMgr.Entities.Dto;
|
||
using Tnb.ProductionMgr.Interfaces;
|
||
using Tnb.WarehouseMgr;
|
||
using Tnb.WarehouseMgr.Entities;
|
||
using Tnb.WarehouseMgr.Entities.Consts;
|
||
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||
using Tnb.WarehouseMgr.Interfaces;
|
||
using Tnb.WarehouseMgr.Entities.Enums;
|
||
|
||
namespace Tnb.ProductionMgr
|
||
{
|
||
/// <summary>
|
||
/// 业务实现:物料投料
|
||
/// </summary>
|
||
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
|
||
[Route("api/[area]/[controller]/[action]")]
|
||
public class PrdFeedingService : IPrdFeedingService, IDynamicApiController, ITransient
|
||
{
|
||
private readonly ISqlSugarRepository<PrdFeedingH> _repository;
|
||
private readonly IUserManager _userManager;
|
||
private readonly IPrdMoTaskService _prdMoTaskService;
|
||
private readonly IBillRullService _billRullService;
|
||
private readonly IDictionaryDataService _dictionaryDataService;
|
||
private readonly IWmsCarryBindService _wmsCarryBindService;
|
||
private readonly IWmsCarryUnbindService _wmsCarryUnbindService;
|
||
// private readonly WmsSignForDeliveryService _wmsSignForDeliveryService;
|
||
|
||
|
||
|
||
public PrdFeedingService(
|
||
ISqlSugarRepository<PrdFeedingH> repository,
|
||
IBillRullService billRullService,
|
||
IPrdMoTaskService prdMoTaskService,
|
||
// WmsSignForDeliveryService wmsSignForDeliveryService,
|
||
IDictionaryDataService dictionaryDataService,
|
||
IWmsCarryBindService wmsCarryBindService,
|
||
IWmsCarryUnbindService wmsCarryUnbindService,
|
||
IUserManager userManager
|
||
)
|
||
{
|
||
_repository = repository;
|
||
_userManager = userManager;
|
||
_prdMoTaskService = prdMoTaskService;
|
||
// _wmsSignForDeliveryService = _wmsSignForDeliveryService;
|
||
_dictionaryDataService = dictionaryDataService;
|
||
_billRullService = billRullService;
|
||
_wmsCarryBindService = wmsCarryBindService;
|
||
_wmsCarryUnbindService = wmsCarryUnbindService;
|
||
}
|
||
|
||
|
||
[HttpPost]
|
||
public async Task<dynamic> SaveData(MaterialReceiptInput input)
|
||
{
|
||
ISqlSugarClient db = _repository.AsSugarClient();
|
||
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
||
{
|
||
PrdMoTask moTask = await db.Queryable<PrdMoTask>().FirstAsync(x => x.id == input.mo_task_id);
|
||
List<string> inputMaterials = await db.Queryable<BasMbomInput>()
|
||
.Where(x => x.mbom_id == moTask.bom_id && x.mbom_process_id == input.mbom_process_id)
|
||
.Select(x => x.material_id)
|
||
.ToListAsync();
|
||
|
||
string code = await _billRullService.GetBillNumber(Tnb.BasicData.CodeTemplateConst.FEEDING_CODE);
|
||
PrdFeedingH prdFeedingH = new()
|
||
{
|
||
code = code,
|
||
station_id = input.station_id,
|
||
mo_task_id = input.mo_task_id,
|
||
process_id = input.process_id,
|
||
equip_id = input.equip_id,
|
||
workshop_id = input.workshop_id,
|
||
carry_id = input.carry_id,
|
||
workline_id = input.workline_id,
|
||
carry_code = input.carry_code,
|
||
remark = input.remark,
|
||
mbom_process_id = input.mbom_process_id,
|
||
create_id = _userManager.UserId,
|
||
create_time = DateTime.Now,
|
||
org_id = _userManager.GetUserInfo().Result.organizeId
|
||
};
|
||
|
||
List<PrdFeedingD> list = new();
|
||
if (input.details != null && input.details.Count > 0)
|
||
{
|
||
foreach (Dictionary<string, object> item in input.details)
|
||
{
|
||
if (!inputMaterials.Contains(item["material_id"]))
|
||
{
|
||
throw new Exception("该物料不是生产bom投入物料,不能签收");
|
||
}
|
||
|
||
PrdMaterialReceiptD? detail = await db.Queryable<PrdMaterialReceiptD>()
|
||
.Where(x => x.carry_id == input.carry_id && 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"]?.ToString(),
|
||
num = num,
|
||
batch = item["batch"]?.ToString(),
|
||
unit_id = item["unit_id"]?.ToString(),
|
||
carry_id = input.carry_id,
|
||
status = "0",
|
||
use_num = 0,
|
||
});
|
||
|
||
if (detail != null)
|
||
{
|
||
if (detail.feeding_num + num > detail.num)
|
||
{
|
||
throw new Exception("投料数量不能大于签收数量");
|
||
}
|
||
else
|
||
{
|
||
_ = 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()
|
||
: 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("没有签收物料");
|
||
}
|
||
|
||
PrdMo mo = await db.Queryable<PrdMo>().SingleAsync(x => x.id == moTask.mo_id);
|
||
BasMaterial? material = await db.Queryable<BasMaterial>().SingleAsync(x => x.id == moTask.material_id);
|
||
OrganizeEntity station = await db.Queryable<OrganizeEntity>().SingleAsync(x => x.Id == input.station_id);
|
||
BasMaterial process = await db.Queryable<BasMaterial>().SingleAsync(x => x.id == input.process_id);
|
||
PrdTaskLog taskLog = new()
|
||
{
|
||
id = SnowflakeIdHelper.NextId(),
|
||
mo_code = mo?.mo_code!,
|
||
eqp_code = (await db.Queryable<EqpEquipment>().FirstAsync(it => it.id == input.equip_id))?.code!,
|
||
mold_code = "",
|
||
item_code = material?.code!,
|
||
item_standard = material?.material_specification!,
|
||
status = "生产投料",
|
||
operator_name = _userManager.RealName,
|
||
create_id = _userManager.UserId,
|
||
create_time = DateTime.Now,
|
||
mo_task_id = moTask.id,
|
||
mo_task_code = moTask.mo_task_code,
|
||
station_code = station?.EnCode,
|
||
process_code = process.code
|
||
};
|
||
|
||
_ = await db.Insertable<PrdFeedingH>(prdFeedingH).ExecuteCommandAsync();
|
||
_ = await db.Insertable<PrdFeedingD>(list).ExecuteCommandAsync();
|
||
_ = await db.Insertable<PrdTaskLog>(taskLog).ExecuteCommandAsync();
|
||
|
||
});
|
||
|
||
if (result.IsSuccess)
|
||
{
|
||
//签收后调用载具签收接口
|
||
// await _wmsSignForDeliveryService.MESCarrySign(new MESCarrySignInput()
|
||
// {
|
||
// org_id = _userManager.GetUserInfo().Result.organizeId,
|
||
// create_id = _userManager.UserId,
|
||
// carry_code = input.carry_code ?? "",
|
||
// });
|
||
}
|
||
|
||
return !result.IsSuccess ? throw Oops.Oh(result.ErrorMessage) : (dynamic)(result.IsSuccess ? "投料成功" : result.ErrorMessage);
|
||
}
|
||
|
||
[HttpPost]
|
||
public async Task<dynamic> SaveDataNew(MaterialReceiptNewInput input)
|
||
{
|
||
ISqlSugarClient db = _repository.AsSugarClient();
|
||
PrdFeedingH? prdFeedingH = null;
|
||
List<PrdFeedingD> list = new();
|
||
DbResult<bool> result2 = new();
|
||
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
||
{
|
||
PrdMoTask moTask = await db.Queryable<PrdMoTask>().FirstAsync(x => x.id == input.mo_task_id);
|
||
PrdMoTask 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;
|
||
}
|
||
WmsCarryH carry = await db.Queryable<WmsCarryH>().SingleAsync(x => x.carry_code == input.carry_code);
|
||
OrganizeEntity workline = await db.Queryable<OrganizeEntity>().SingleAsync(x => x.Id == worklineId);
|
||
OrganizeEntity workshop = await db.Queryable<OrganizeEntity>().SingleAsync(x => x.Id == workline.ParentId);
|
||
List<string> 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 = input.mo_task_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 (Dictionary<string, string> item in input.details)
|
||
{
|
||
if (!inputMaterials.Contains(item["material_id"]))
|
||
{
|
||
throw new Exception("该物料不是生产bom投入物料,不能投料");
|
||
}
|
||
|
||
PrdMaterialReceiptD? 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
|
||
{
|
||
_ = 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()
|
||
: 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)
|
||
{
|
||
//签收后调用载具签收接口
|
||
// await _wmsSignForDeliveryService.MESCarrySign(new MESCarrySignInput()
|
||
// {
|
||
// org_id = _userManager.GetUserInfo().Result.organizeId,
|
||
// create_id = _userManager.UserId,
|
||
// carry_code = input.carry_code ?? "",
|
||
// });
|
||
|
||
// var mesCarrySignInput = new MESCarrySignInput()
|
||
// {
|
||
// org_id = _userManager.GetUserInfo().Result.organizeId,
|
||
// create_id = _userManager.UserId,
|
||
// carry_code = input.carry_code ?? "",
|
||
// };
|
||
//
|
||
// string domain = _userManager.Domain;
|
||
// Dictionary<string, object> header = new Dictionary<string, object>()
|
||
// {
|
||
// ["Authorization"] = App.HttpContext!=null ? App.HttpContext.Request.Headers["Authorization"] : ""
|
||
// };
|
||
// var sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CARRY_SIGN,JsonConvert.SerializeObject(mesCarrySignInput),header);
|
||
// Log.Information(sendResult);
|
||
// AuthResponse authResponse = JsonConvert.DeserializeObject<AuthResponse>(sendResult);
|
||
// if (authResponse.code != 200)
|
||
// {
|
||
// throw Oops.Bah(authResponse.msg);
|
||
// }
|
||
// else
|
||
// {
|
||
// result2 = await db.Ado.UseTranAsync(async () =>
|
||
// {
|
||
// await db.Insertable<PrdFeedingH>(prdFeedingH).ExecuteCommandAsync();
|
||
// await db.Insertable<PrdFeedingD>(list).ExecuteCommandAsync();
|
||
// });
|
||
//
|
||
// }
|
||
}
|
||
|
||
return !result.IsSuccess ? throw Oops.Bah(result.ErrorMessage) : (dynamic)(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(FeedingInput input)
|
||
{
|
||
ISqlSugarClient db = _repository.AsSugarClient();
|
||
PrdMoTask 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();
|
||
|
||
try
|
||
{
|
||
await db.Ado.BeginTranAsync();
|
||
|
||
PrdMoTask 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;
|
||
}
|
||
WmsCarryH carry = await db.Queryable<WmsCarryH>().SingleAsync(x => x.carry_code == input.carry_code);
|
||
OrganizeEntity workline = await db.Queryable<OrganizeEntity>().SingleAsync(x => x.Id == worklineId);
|
||
OrganizeEntity workshop = await db.Queryable<OrganizeEntity>().SingleAsync(x => x.Id == workline.ParentId);
|
||
List<string> 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
|
||
};
|
||
|
||
PrdMaterialReceiptH prdMaterialReceiptH = null;
|
||
if (input.details != null && input.details.Count > 0)
|
||
{
|
||
foreach (var item in input.details)
|
||
{
|
||
if (!inputMaterials.Contains(item.material_id))
|
||
{
|
||
throw new Exception("该物料不是生产bom投入物料,不能签收");
|
||
}
|
||
|
||
PrdMaterialReceiptD? detail = null;
|
||
if (carry.carrystd_id == WmsWareHouseConst.CARRY_ZYXCSTD_ID || carry.carrystd_id == WmsWareHouseConst.CARRY_ZYLJSTD_ID)
|
||
{
|
||
detail = await db.Queryable<PrdMaterialReceiptD>().Where(x => x.carry_id == carry.id && x.is_all_feeding == 0).FirstAsync();
|
||
}
|
||
else
|
||
{
|
||
detail = await db.Queryable<PrdMaterialReceiptD>().Where(x => x.member_carry_code == input.carry_code && x.is_all_feeding == 0).FirstAsync();
|
||
}
|
||
|
||
if (prdMaterialReceiptH == null)
|
||
{
|
||
prdMaterialReceiptH = await db.Queryable<PrdMaterialReceiptH>()
|
||
.SingleAsync(x => x.id == detail.material_receipt_id);
|
||
}
|
||
WmsCarryCode wmsCarryCode = await db.Queryable<WmsCarryCode>().Where(x=>x.carry_id==carry.id).FirstAsync();
|
||
if (wmsCarryCode == null)
|
||
{
|
||
throw Oops.Bah($"未找到条码信息,载具id{carry.id}");
|
||
}
|
||
|
||
decimal num = item.codeqty;
|
||
list.Add(new PrdFeedingD
|
||
{
|
||
feeding_id = prdFeedingH.id,
|
||
material_receipt_detail_id = detail?.id,
|
||
material_id = item.material_id,
|
||
num = num,
|
||
batch = wmsCarryCode.code_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
|
||
{
|
||
_ = 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()
|
||
: await db.Updateable<PrdMaterialReceiptD>()
|
||
.SetColumns(x => x.feeding_num == x.feeding_num + num)
|
||
.Where(x => x.id == detail.id)
|
||
.ExecuteCommandAsync();
|
||
|
||
if (detail.feeding_num + num < detail.num)
|
||
{
|
||
if (wmsCarryCode.codeqty < num)
|
||
{
|
||
throw new Exception("条码数量小于投料数量");
|
||
}
|
||
await db.Updateable<WmsCarryCode>()
|
||
.SetColumns(x => x.codeqty == x.codeqty - num)
|
||
.Where(x => x.carry_id == carry.id)
|
||
.ExecuteCommandAsync();
|
||
}
|
||
else
|
||
{
|
||
// await db.Updateable<WmsCarryCode>()
|
||
// .SetColumns(x => x.codeqty == 0)
|
||
// .Where(x => x.carry_id == detail.member_carry_id)
|
||
// .ExecuteCommandAsync();
|
||
|
||
await db.Updateable<WmsCarryH>()
|
||
.SetColumns(x => x.carry_status == ((int)EnumCarryStatus.空闲).ToString())
|
||
.Where(x => x.carry_code==input.carry_code)
|
||
.ExecuteCommandAsync();
|
||
|
||
|
||
if (carry.carrystd_id == WmsWareHouseConst.CARRY_ZYXCSTD_ID || carry.carrystd_id == WmsWareHouseConst.CARRY_ZYLJSTD_ID)
|
||
{
|
||
Tnb.WarehouseMgr.Entities.Dto.Outputs.Result result = await _wmsCarryUnbindService.CarryCodeUnbind(new CarryCodeUnbindInput()
|
||
{
|
||
carry_id = carry.id
|
||
});
|
||
|
||
|
||
if (result.code != JNPF.Common.Enums.HttpStatusCode.OK)
|
||
{
|
||
throw Oops.Bah(result.msg);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Tnb.WarehouseMgr.Entities.Dto.Outputs.Result result = await _wmsCarryUnbindService.CarryCodeUnbind(new CarryCodeUnbindInput()
|
||
{
|
||
carry_id = detail.member_carry_id
|
||
});
|
||
|
||
|
||
if (result.code != JNPF.Common.Enums.HttpStatusCode.OK)
|
||
{
|
||
throw Oops.Bah(result.msg);
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
throw new Exception("没有签收单,无法投料");
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
throw new Exception("没有签收物料,无法投料");
|
||
}
|
||
|
||
|
||
_ = await db.Insertable<PrdFeedingH>(prdFeedingH).ExecuteCommandAsync();
|
||
_ = await db.Insertable<PrdFeedingD>(list).ExecuteCommandAsync();
|
||
|
||
if (prdMaterialReceiptH == null)
|
||
{
|
||
throw Oops.Bah("未找到投料记录");
|
||
}
|
||
|
||
if (prdMaterialReceiptH.first_feed && carry.carrystd_id==WmsWareHouseConst.CARRY_LXSTD_ID)
|
||
{
|
||
await db.Updateable<PrdMaterialReceiptH>()
|
||
.SetColumns(x => x.first_feed == false)
|
||
.Where(x => x.id == prdMaterialReceiptH.id)
|
||
.ExecuteCommandAsync();
|
||
|
||
List<PrdMaterialReceiptD> dList = await db.Queryable<PrdMaterialReceiptD>()
|
||
.Where(x => x.material_receipt_id == prdMaterialReceiptH.id).ToListAsync();
|
||
|
||
//List<String> carryIds = dList.Select(x => x.member_carry_id).ToList();
|
||
List<String> carryIds = new List<string>();
|
||
carryIds.Add(prdMaterialReceiptH.carry_id);
|
||
// foreach (var item in dList)
|
||
// {
|
||
Tnb.WarehouseMgr.Entities.Dto.Outputs.Result result2 = await _wmsCarryUnbindService.CarryUnbind(new CarryBindInput()
|
||
{
|
||
org = prdFeedingH.org_id,
|
||
create_id = prdFeedingH.create_id,
|
||
carry_id = prdMaterialReceiptH.carry_id,
|
||
carry_code = prdMaterialReceiptH.carry_code,
|
||
carrystd_id = carry.carrystd_id,
|
||
membercarry_code = "",
|
||
membercarry_id = "",
|
||
});
|
||
|
||
await db.Updateable<WmsCarryH>()
|
||
.SetColumns(x => x.carry_status == ((int)EnumCarryStatus.空闲).ToString())
|
||
.Where(x => carryIds.Contains(x.id))
|
||
.ExecuteCommandAsync();
|
||
|
||
if (result2.code != JNPF.Common.Enums.HttpStatusCode.OK)
|
||
{
|
||
throw Oops.Bah(result2.msg);
|
||
}
|
||
// }
|
||
|
||
}
|
||
|
||
await db.Ado.CommitTranAsync();
|
||
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Log.Error(e.Message,e);
|
||
await db.Ado.RollbackTranAsync();
|
||
throw Oops.Bah(e.Message);
|
||
}
|
||
|
||
|
||
return "投料成功";
|
||
}
|
||
|
||
[HttpPost]
|
||
public async Task<dynamic> GetFeedingRecordTree()
|
||
{
|
||
ISqlSugarClient db = _repository.AsSugarClient();
|
||
List<FeedingRecordTreeOutput> result = await db.Queryable<PrdMoTask>()
|
||
.Where(a => a.schedule_type == 2 && a.parent_id != null)
|
||
.Select(a => new FeedingRecordTreeOutput()
|
||
{
|
||
mo_task_code = a.mo_task_code,
|
||
children = SqlFunc.Subqueryable<PrdFeedingH>().Where(b => a.id == b.mo_task_id).ToList(b => new FeedingRecordChildren()
|
||
{
|
||
id = b.id,
|
||
code = b.code,
|
||
// children = SqlFunc.Subqueryable<PrdFeedingD>().LeftJoin<BasMaterial>((c,d)=>c.material_id==d.id)
|
||
// .Where((c,d)=>SqlFunc.IIF(b==null,"0",b.id)==c.feeding_id).ToList((c,d)=>new FeedingRecordMaterialChildren()
|
||
// {
|
||
// // material_code = d.code,
|
||
// // material_name = d.name,
|
||
// })
|
||
// children = new List<FeedingRecordMaterialChildren>(),
|
||
// children = b!=null ? SqlFunc.Subqueryable<PrdFeedingD>()
|
||
// .Where((c)=>"26897270557717"=="26897270557717").ToList((c)=>new FeedingRecordMaterialChildren()
|
||
// {
|
||
// // material_code = d.code,
|
||
// // material_name = d.name,
|
||
// }) : new List<FeedingRecordMaterialChildren>()
|
||
})
|
||
}).Mapper(x =>
|
||
{
|
||
foreach (FeedingRecordChildren item in x.children)
|
||
{
|
||
item.children = db.Queryable<PrdFeedingD>()
|
||
.LeftJoin<BasMaterial>((c, d) => c.material_id == d.id)
|
||
.Where((c, d) => item.id == c.feeding_id).Select((c, d) => new FeedingRecordMaterialChildren()
|
||
{
|
||
material_code = d.code,
|
||
material_name = d.name,
|
||
}).ToList();
|
||
}
|
||
})
|
||
.ToListAsync();
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// pad app 领料记录列表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public async Task<dynamic> FeedingRecordList(FeedingRecordListInput input)
|
||
{
|
||
if (string.IsNullOrEmpty(input.stationId))
|
||
{
|
||
return new
|
||
{
|
||
pagination = new PageResult(),
|
||
list = Array.Empty<string>()
|
||
};
|
||
}
|
||
var db = _repository.AsSugarClient();
|
||
|
||
Dictionary<string, object> queryJson = string.IsNullOrEmpty(input.queryJson) ? new Dictionary<string, object>() : input.queryJson.ToObject<Dictionary<string, object>>();
|
||
string? code = queryJson.ContainsKey("code") ? queryJson["code"].ToString() : "";
|
||
string? status = queryJson.ContainsKey("status") ? queryJson["status"].ToString() : "";
|
||
// DateTime? start_time = queryJson.ContainsKey("start_time") ? queryJson["start_time"].ToString() == "" ? null : Convert.ToDateTime(queryJson["start_time"]) : null;
|
||
// DateTime? end_time = queryJson.ContainsKey("end_time") ? queryJson["end_time"].ToString() == "" ? null : Convert.ToDateTime(queryJson["end_time"]) : null;
|
||
|
||
Dictionary<string, object> dic = await _dictionaryDataService.GetDicByKey(DictConst.DOCUMENTSTATU);
|
||
|
||
if (string.IsNullOrEmpty(input.sidx))
|
||
{
|
||
input.sidx = "create_time";
|
||
input.sort = "desc";
|
||
}
|
||
|
||
List<string> statusList = new();
|
||
if (!string.IsNullOrEmpty(status))
|
||
{
|
||
switch (status)
|
||
{
|
||
case "1":
|
||
statusList.Add(DictConst.OUTSTOCKSTATUSADD);
|
||
statusList.Add(DictConst.OUTSTOCKSTATUSCALLED);
|
||
break;
|
||
case "2":
|
||
statusList.Add(DictConst.OUTSTOCKSTATUSTOBEDELIVERED);
|
||
statusList.Add(DictConst.OUTSTOCKSTATUSWORKING);
|
||
break;
|
||
case "3":
|
||
statusList.Add(DictConst.OUTSTOCKSTATUSCANCEL);
|
||
statusList.Add(DictConst.OUTSTOCKSTATUSCOMPLETED);
|
||
break;
|
||
}
|
||
}
|
||
|
||
var queryable1 = db.Queryable<PrdKittingOutH>()
|
||
.LeftJoin<UserEntity>((a, b) => a.create_id == b.Id)
|
||
.LeftJoin<WmsKittingoutH>((a,b,c)=>a.id==c.source_id)
|
||
.LeftJoin<DictionaryTypeEntity>((a,b,c,d)=>d.EnCode==DictConst.DOCUMENTSTATU)
|
||
.LeftJoin<DictionaryDataEntity>((a,b,c,d,e)=>e.DictionaryTypeId==d.Id && c.status==e.Id)
|
||
.Where((a,b)=>a.workstation_id==input.stationId)
|
||
.WhereIF(statusList.Count>0,(a,b,c,d,e)=>statusList.Contains(SqlFunc.IsNull(e.EnCode,a.status)))
|
||
.Select((a, b,c,d,e) => new FeedingRecordListOutput()
|
||
{
|
||
id = a.id,
|
||
code = a.code,
|
||
type_name = "齐套出库",
|
||
type = "0",
|
||
create_name = b.RealName,
|
||
create_time = a.create_time==null ? "" : a.create_time.Value.ToString(DbTimeFormat.SS),
|
||
status = SqlFunc.IsNull(e.FullName,a.status)
|
||
});
|
||
|
||
var queryable2 = db.Queryable<PrdOutstockH>()
|
||
.LeftJoin<UserEntity>((a, b) => a.create_id == b.Id)
|
||
.LeftJoin<WmsOutstockH>((a,b,c)=>a.id==c.source_id)
|
||
.LeftJoin<DictionaryTypeEntity>((a,b,c,d)=>d.EnCode==DictConst.DOCUMENTSTATU)
|
||
.LeftJoin<DictionaryDataEntity>((a,b,c,d,e)=>e.DictionaryTypeId==d.Id && c.status==e.Id)
|
||
.Where((a,b)=>a.workstation_id==input.stationId)
|
||
.WhereIF(statusList.Count>0,(a,b,c,d,e)=>statusList.Contains(SqlFunc.IsNull(e.EnCode,a.status)))
|
||
.Select((a, b,c,d,e) => new FeedingRecordListOutput()
|
||
{
|
||
id = a.id,
|
||
code = a.bill_code,
|
||
type_name = a.type=="1" ? "一般出库" : "物料出库",
|
||
type = a.type,
|
||
create_name = b.RealName,
|
||
create_time = a.create_time==null ? "" : a.create_time.Value.ToString(DbTimeFormat.SS),
|
||
status = SqlFunc.IsNull(e.FullName,a.status)
|
||
});
|
||
var result = await db.UnionAll(queryable1,queryable2)
|
||
.MergeTable()
|
||
.OrderBy($"{input.sidx} {input.sort}")
|
||
.Mapper(a =>
|
||
{
|
||
if (dic.ContainsKey(a.status))
|
||
{
|
||
a.status = dic[a.status].ToString();
|
||
}
|
||
})
|
||
.ToPagedListAsync(input.currentPage, input.pageSize);
|
||
|
||
return PageResult<FeedingRecordListOutput>.SqlSugarPageResult(result);
|
||
|
||
}
|
||
|
||
[HttpPost]
|
||
public async Task<dynamic> GetFeedingRecordInFoById(FeedingRecordInfoInput input)
|
||
{
|
||
var db = _repository.AsSugarClient();
|
||
if (input.type == "0")
|
||
{
|
||
var result = await db.Queryable<PrdKittingOutD>()
|
||
.LeftJoin<BasMaterial>((a, b) => a.material_id == b.id)
|
||
.LeftJoin<DictionaryTypeEntity>((a,b,c)=>c.EnCode==DictConst.MeasurementUnit)
|
||
.LeftJoin<DictionaryDataEntity>((a,b,c,d)=>d.DictionaryTypeId==c.Id && a.unit_id==d.Id)
|
||
.Where((a, b) => a.kitting_out_id == input.id)
|
||
.Select((a, b,c,d) => new FeedingRecordInfoOutput
|
||
{
|
||
id = a.id,
|
||
material_id = a.material_id,
|
||
material_code = b.code,
|
||
material_name = b.name,
|
||
num = a.pr_qty,
|
||
unit_name = d.FullName
|
||
}).ToListAsync();
|
||
return result;
|
||
}
|
||
else
|
||
{
|
||
var result = await db.Queryable<PrdOutstockD>()
|
||
.LeftJoin<BasMaterial>((a, b) => a.material_id == b.id)
|
||
.LeftJoin<DictionaryTypeEntity>((a,b,c)=>c.EnCode==DictConst.MeasurementUnit)
|
||
.LeftJoin<DictionaryDataEntity>((a,b,c,d)=>d.DictionaryTypeId==c.Id && a.unit_id==d.Id)
|
||
.Where((a, b) => a.outstock_id == input.id)
|
||
.Select((a, b,c,d) => new FeedingRecordInfoOutput
|
||
{
|
||
id = a.id,
|
||
material_id = a.material_id,
|
||
material_code = b.code,
|
||
material_name = b.name,
|
||
num = a.pr_qty,
|
||
unit_name = d.FullName
|
||
}).ToListAsync();
|
||
|
||
return result;
|
||
}
|
||
}
|
||
}
|
||
} |