合并
This commit is contained in:
@@ -45,7 +45,7 @@ namespace Tnb.ProductionMgr
|
||||
private readonly IBillRullService _billRullService;
|
||||
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
||||
|
||||
public PrdOutstockService(ISqlSugarRepository<PrdOutstockH> repository, IOrganizeService organizeService, IBillRullService billRullService, IRunService runService, IUserManager userManager, IVisualDevService visualDevService, IDictionaryDataService dictionaryDataService)
|
||||
public PrdOutstockService(ISqlSugarRepository<PrdOutstockH> repository, IOrganizeService organizeService, IBillRullService billRullService,IRunService runService, IUserManager userManager, IVisualDevService visualDevService, IDictionaryDataService dictionaryDataService)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_runService = runService;
|
||||
@@ -98,7 +98,7 @@ namespace Tnb.ProductionMgr
|
||||
string domain = _userManager.Domain;
|
||||
Dictionary<string, object> header = new()
|
||||
{
|
||||
["Authorization"] = App.HttpContext != null ? App.HttpContext.Request.Headers["Authorization"] : ""
|
||||
["Authorization"] = App.HttpContext!=null ? App.HttpContext.Request.Headers["Authorization"] : ""
|
||||
};
|
||||
string sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_OUTSTOCK, JsonConvert.SerializeObject(input), header);
|
||||
Log.Information(sendResult);
|
||||
@@ -190,7 +190,7 @@ namespace Tnb.ProductionMgr
|
||||
string domain = _userManager.Domain;
|
||||
Dictionary<string, object> header = new()
|
||||
{
|
||||
["Authorization"] = App.HttpContext != null ? App.HttpContext.Request.Headers["Authorization"] : ""
|
||||
["Authorization"] = App.HttpContext!=null ? App.HttpContext.Request.Headers["Authorization"] : ""
|
||||
};
|
||||
string sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_OUTSTOCK, JsonConvert.SerializeObject(input), header);
|
||||
Log.Information(sendResult);
|
||||
@@ -266,12 +266,12 @@ namespace Tnb.ProductionMgr
|
||||
MESCreateOutstockInput input = new MESCreateOutstockInput();
|
||||
input.outstock = new MESWmsOutstockHInput();
|
||||
input.outstockDs = new List<MESWmsOutstockDInput>();
|
||||
|
||||
PrdMoTask prdMoTask = await db.Queryable<PrdMoTask>().SingleAsync(x => x.id == materialOutstockInput.mo_task_id);
|
||||
BasLocation location = await db.Queryable<BasLocation>().Where(x => x.location_code == materialOutstockInput.location_code).FirstAsync();
|
||||
|
||||
PrdMoTask prdMoTask = await db.Queryable<PrdMoTask>().SingleAsync(x=>x.id==materialOutstockInput.mo_task_id);
|
||||
BasLocation location = await db.Queryable<BasLocation>().Where(x=>x.location_code==materialOutstockInput.location_code).FirstAsync();
|
||||
if (location == null) throw Oops.Bah("未找到库位");
|
||||
string locationId = location.id;
|
||||
|
||||
|
||||
PrdOutstockH prdOutstockH = new()
|
||||
{
|
||||
bill_code = await _billRullService.GetBillNumber(CodeTemplateConst.PRDOUTSTOCK_CODE),
|
||||
@@ -287,17 +287,17 @@ namespace Tnb.ProductionMgr
|
||||
input.outstock.source_code = prdOutstockH.bill_code;
|
||||
input.outstock.source_id = prdOutstockH.id;
|
||||
OrganizeEntity workline = await _organizeService.GetAnyParentByWorkstationId(materialOutstockInput.workstation_id, DictConst.RegionCategoryWorklineCode);
|
||||
|
||||
|
||||
List<string> materialIds = materialOutstockInput.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>()
|
||||
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
|
||||
.Where((a,b,c)=>materialIds.Contains(a.id))
|
||||
.Select((a, b, c) => new
|
||||
{
|
||||
key = a.id,
|
||||
value = c.Id
|
||||
value = c.Id
|
||||
})
|
||||
.ToDictionaryAsync(x => x.key, x => x.value);
|
||||
|
||||
@@ -306,18 +306,18 @@ namespace Tnb.ProductionMgr
|
||||
input.outstockDs.Add(new MESWmsOutstockDInput()
|
||||
{
|
||||
material_id = item.material_id,
|
||||
material_code = basMaterials.First(x => x.id == item.material_id).code,
|
||||
material_code = basMaterials.First(x=>x.id==item.material_id).code,
|
||||
pr_qty = item.num,
|
||||
unit_id = unitIdDic[item.material_id].ToString()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
string domain = _userManager.Domain;
|
||||
Dictionary<string, object> header = new Dictionary<string, object>()
|
||||
{
|
||||
["Authorization"] = App.HttpContext != null ? App.HttpContext.Request.Headers["Authorization"] : ""
|
||||
["Authorization"] = App.HttpContext!=null ? App.HttpContext.Request.Headers["Authorization"] : ""
|
||||
};
|
||||
var sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_OUTSTOCK, JsonConvert.SerializeObject(input), header);
|
||||
var sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_OUTSTOCK,JsonConvert.SerializeObject(input),header);
|
||||
Log.Information(sendResult);
|
||||
|
||||
AuthResponse authResponse = JsonConvert.DeserializeObject<AuthResponse>(sendResult);
|
||||
@@ -346,16 +346,16 @@ namespace Tnb.ProductionMgr
|
||||
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,
|
||||
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 () =>
|
||||
|
||||
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
|
||||
{
|
||||
await _repository.InsertAsync(prdOutstockH);
|
||||
if (prdOutstockDs.Count > 0)
|
||||
@@ -379,132 +379,5 @@ namespace Tnb.ProductionMgr
|
||||
throw Oops.Bah(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<dynamic> MaterialOutstockTest(MaterialOutstockInput materialOutstockInput)
|
||||
{
|
||||
try
|
||||
{
|
||||
var db = _repository.AsSugarClient();
|
||||
string warehouse_id = "1";//一楼原材料仓
|
||||
|
||||
MESCreateOutstockInput input = new MESCreateOutstockInput();
|
||||
input.outstock = new MESWmsOutstockHInput();
|
||||
input.outstockDs = new List<MESWmsOutstockDInput>();
|
||||
|
||||
BasLocation location = await db.Queryable<BasLocation>().Where(x => x.location_code == materialOutstockInput.location_code).FirstAsync();
|
||||
if (location == null) throw new AppFriendlyException("未找到库位", 500);
|
||||
string locationId = location.id;
|
||||
|
||||
PrdOutstockH prdOutstockH = new()
|
||||
{
|
||||
bill_code = await _billRullService.GetBillNumber(CodeTemplateConst.PRDOUTSTOCK_CODE),
|
||||
};
|
||||
|
||||
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 ?? "";
|
||||
input.outstock.source_code = prdOutstockH.bill_code;
|
||||
input.outstock.source_id = prdOutstockH.id;
|
||||
OrganizeEntity workline = await _organizeService.GetAnyParentByWorkstationId(materialOutstockInput.workstation_id, DictConst.RegionCategoryWorklineCode);
|
||||
|
||||
List<string> materialIds = materialOutstockInput.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 materialOutstockInput.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 = _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_CREATE_OUTSTOCK, JsonConvert.SerializeObject(input), header);
|
||||
Log.Information(sendResult);
|
||||
|
||||
AuthResponse authResponse = JsonConvert.DeserializeObject<AuthResponse>(sendResult);
|
||||
if (authResponse.code != 200)
|
||||
{
|
||||
throw new AppFriendlyException(authResponse.msg, 500);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
prdOutstockH.bill_type = DictConst.SHENGCHANLINGLIAO;
|
||||
prdOutstockH.type = "2";
|
||||
prdOutstockH.warehouse_id = warehouse_id;
|
||||
prdOutstockH.location_code = materialOutstockInput.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.create_time = DateTime.Now;
|
||||
prdOutstockH.workstation_id = materialOutstockInput.workstation_id;
|
||||
prdOutstockH.workline = workline?.Id ?? "";
|
||||
prdOutstockH.status = DictConst.OUTSTOCKSTATUSADD;
|
||||
prdOutstockH.mo_task_id = "";
|
||||
|
||||
List<PrdOutstockD> prdOutstockDs = new List<PrdOutstockD>();
|
||||
foreach (var item in materialOutstockInput.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 = ""
|
||||
});
|
||||
}
|
||||
|
||||
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 new AppFriendlyException(result.ErrorMessage, 500);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
throw new AppFriendlyException(e.Message, 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user