根据工位id获取当前进行中的任务单 生产投料新接口
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -1447,6 +1447,7 @@ namespace Tnb.ProductionMgr
|
||||
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 equip = await db.Queryable<EqpEquipment>().SingleAsync(x=>x.id==prdMoTask.eqp_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,6 +1725,11 @@ namespace Tnb.ProductionMgr
|
||||
// }
|
||||
// }
|
||||
|
||||
if (equip.tube == "1")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (!result.IsSuccess) throw Oops.Bah(result.ErrorMessage);
|
||||
@@ -2627,6 +2633,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 +2650,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 +2679,18 @@ namespace Tnb.ProductionMgr
|
||||
return prdMoTaskList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据工位获取进行中的任务单信息
|
||||
/// </summary>
|
||||
/// <param name="dic"></param>
|
||||
/// <returns></returns>
|
||||
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("工位错误");
|
||||
|
||||
return await _db.Queryable<PrdMoTask>().Where(x => x.workstation_id == station_id && x.parent_id!=null && x.mo_task_status==DictConst.InProgressEnCode).FirstAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user