外包装入库申请
This commit is contained in:
@@ -259,10 +259,10 @@ namespace Tnb.ProductionMgr
|
||||
/// <returns></returns>
|
||||
/// <exception cref="AppFriendlyException"></exception>
|
||||
[AllowAnonymous]
|
||||
public async Task<dynamic> InstockTypeOne(InstockInput inut)
|
||||
public async Task<dynamic> InstockTypeOne(InstockInput input)
|
||||
{
|
||||
string equip_code = inut.equip_code;
|
||||
string label_code = inut.label_code;
|
||||
string equip_code = input.equip_code;
|
||||
string label_code = input.label_code;
|
||||
string warehouse_id = "2";
|
||||
if (!string.IsNullOrEmpty(equip_code))
|
||||
{
|
||||
@@ -399,6 +399,7 @@ namespace Tnb.ProductionMgr
|
||||
{
|
||||
_ = await db.Insertable<PrdInstockD>(prdInstockDs).ExecuteCommandAsync();
|
||||
}
|
||||
//todo 入库申请后是否修改提报记录状态
|
||||
});
|
||||
}
|
||||
|
||||
@@ -626,9 +627,189 @@ namespace Tnb.ProductionMgr
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public Task<string> InstockOutPack(InstockInput inut)
|
||||
public async Task<string> InstockOutPack(InstockInput input)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
string equip_code = input.equip_code;
|
||||
string label_code = input.label_code;
|
||||
string warehouse_id = "26103367464997";//四楼解析库
|
||||
if (!string.IsNullOrEmpty(equip_code))
|
||||
{
|
||||
throw Oops.Bah("请传机台号");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(label_code))
|
||||
{
|
||||
throw Oops.Bah("请传标签号");
|
||||
}
|
||||
|
||||
ISqlSugarClient db = _repository.AsSugarClient();
|
||||
EqpEquipment equipment = await db.Queryable<EqpEquipment>()
|
||||
.LeftJoin<EqpDaq>((x,y)=>x.id==y.equip_id)
|
||||
.Where((x,y) => y.equip_code==equip_code && y.label_name==label_code && y.label_point=="外包装成品码垛点位")
|
||||
.Select((x,y)=>x)
|
||||
.FirstAsync();
|
||||
|
||||
|
||||
if (equipment == null)
|
||||
{
|
||||
throw Oops.Bah("未找到机台");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(equipment.as_location_id))
|
||||
{
|
||||
throw Oops.Bah("未找到入库库位");
|
||||
}
|
||||
|
||||
BasLocation basLocation = await db.Queryable<BasLocation>().SingleAsync(x => x.id == equipment.as_location_id);
|
||||
if (basLocation == null)
|
||||
{
|
||||
throw Oops.Bah("未找到入库库位");
|
||||
}
|
||||
|
||||
OrganizeEntity station = await db.Queryable<OrganizeEntity>()
|
||||
.LeftJoin<OrganizeRelationEntity>((x, y) => x.Id == y.OrganizeId)
|
||||
.Where((x, y) => y.ObjectType == "Eqp" && y.ObjectId == equipment.id).FirstAsync();
|
||||
|
||||
if (station == null)
|
||||
{
|
||||
throw Oops.Bah("未找到工位");
|
||||
}
|
||||
|
||||
PrdOutPacking prdOutPacking = await db.Queryable<PrdOutPacking>().Where(x=>x.station_id==station.Id && x.status=="0").OrderByDescending(x=>x.create_time).FirstAsync();
|
||||
if (prdOutPacking == null)
|
||||
{
|
||||
throw Oops.Bah("未找到托盘");
|
||||
}
|
||||
|
||||
var prdOutPackMarkLabelList = await db.Queryable<PrdOutPackMarkLabel>().Where(x=>x.station_id==station.Id && x.status=="1").ToListAsync();
|
||||
if (prdOutPackMarkLabelList == null || prdOutPackMarkLabelList.Count <= 0)
|
||||
{
|
||||
throw Oops.Bah("未找到提报记录");
|
||||
}
|
||||
|
||||
List<string> reportIds = prdOutPackMarkLabelList.Select(x => x.report_id).ToList();
|
||||
|
||||
List<PrdReport> prdReports = await db.Queryable<PrdReport>().Where(x => reportIds.Contains(x.id)).ToListAsync();
|
||||
|
||||
if (prdReports == null || prdReports.Count<=0)
|
||||
{
|
||||
throw Oops.Bah("未找到提报记录");
|
||||
}
|
||||
|
||||
PrdInstockH? prdInstockH = null;
|
||||
List<PrdInstockD> prdInstockDs = new() { };
|
||||
DbResult<bool> result2 = new();
|
||||
string material_id = prdReports[0].material_id;
|
||||
BasMaterial basMaterial = await db.Queryable<BasMaterial>().SingleAsync(x => x.id == material_id);
|
||||
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
||||
{
|
||||
OrganizeEntity workline = await _organizeService.GetAnyParentByWorkstationId(station.Id, DictConst.RegionCategoryWorklineCode);
|
||||
OrganizeEntity workshop = await _organizeService.GetAnyParentByWorkstationId(station.Id, DictConst.RegionCategoryWorkshopCode);
|
||||
|
||||
prdInstockH = new PrdInstockH()
|
||||
{
|
||||
bill_type = DictConst.CHANCHENGPINRUKUDAN,
|
||||
bill_date = DateTime.Now,
|
||||
create_id = _userManager.UserId,
|
||||
location_code = basLocation.location_code,
|
||||
carry_code = prdOutPacking.code,
|
||||
is_check = 1,
|
||||
station_id = station.Id,
|
||||
workline_id = workline?.Id ?? "",
|
||||
workshop_id = workshop?.Id ?? "",
|
||||
org_id = _userManager.GetUserInfo().Result.organizeId,
|
||||
// warehouse_id = basLocation?.wh_id,
|
||||
warehouse_id = warehouse_id,
|
||||
status = 0,
|
||||
};
|
||||
|
||||
foreach (var prdReport in prdReports)
|
||||
{
|
||||
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()
|
||||
{
|
||||
instock = new MESWmsInstockHInput()
|
||||
{
|
||||
org_id = _userManager.GetUserInfo().Result.organizeId,
|
||||
bill_date = DateTime.Now,
|
||||
bill_type = DictConst.CHANCHENGPINRUKUDAN,
|
||||
// warehouse_id = basLocation?.wh_id,
|
||||
warehouse_id = warehouse_id,
|
||||
source_id = prdInstockH.id,
|
||||
create_id = _userManager.UserId,
|
||||
carry_code = prdOutPacking.code,
|
||||
location_code = basLocation.location_code,
|
||||
is_check = 1,
|
||||
},
|
||||
instockds = new List<MESWmsInstockDInput>(),
|
||||
instockcodes = new List<MESWmsInstockCodeInput>()
|
||||
};
|
||||
|
||||
foreach (var prdReport in prdReports)
|
||||
{
|
||||
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()
|
||||
{
|
||||
["Authorization"] = App.HttpContext.Request.Headers["Authorization"]
|
||||
};
|
||||
string sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_INSTOCK, JsonConvert.SerializeObject(mesCreateInstockInput), header);
|
||||
Log.Information(sendResult);
|
||||
AuthResponse authResponse = JsonConvert.DeserializeObject<AuthResponse>(sendResult);
|
||||
result2 = authResponse.code != 200 || !authResponse.data.ObjToBool()
|
||||
? throw Oops.Bah(authResponse.msg)
|
||||
: await db.Ado.UseTranAsync(async () =>
|
||||
{
|
||||
_ = await _repository.InsertAsync(prdInstockH);
|
||||
|
||||
if (prdInstockDs.Count > 0)
|
||||
{
|
||||
_ = await db.Insertable<PrdInstockD>(prdInstockDs).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
await db.Updateable<PrdOutPackMarkLabel>()
|
||||
.SetColumns(x => x.status == "2")
|
||||
.Where(x => x.station_id == station.Id && x.status == "1").ExecuteCommandAsync();
|
||||
|
||||
//todo 入库申请后是否修改提报记录状态
|
||||
});
|
||||
}
|
||||
|
||||
return !result2.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : (dynamic)(result2.IsSuccess ? "申请成功" : result2.ErrorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user