调wms接口返回成功后再操作数据库

This commit is contained in:
2023-07-20 14:06:35 +08:00
parent 716c1f5d14
commit 818e259205
8 changed files with 177 additions and 29 deletions

View File

@@ -104,4 +104,9 @@ public partial class PerProcessStandardsH : BaseEntity<string>
/// </summary>
public string? f_flowid { get; set; }
/// <summary>
/// 成型周期
/// </summary>
public decimal? moulding_cycle { get; set; }
}

View File

@@ -27,5 +27,7 @@ namespace Tnb.ProductionMgr.Entities.Dto
public string? create_id { get; set; } = string.Empty;
public string? create_id_id { get; set; } = string.Empty;
public string? create_time { get; set; } = string.Empty;
public string? batch { get; set; } = string.Empty;
}
}

View File

@@ -21,5 +21,11 @@ namespace Tnb.ProductionMgr.Interfaces
/// <param name="input"></param>
/// <returns></returns>
public Task<dynamic> SaveDataNew(MaterialReceiptNewInput input);
/// <summary>
/// 投料记录
/// </summary>
/// <returns></returns>
public Task<dynamic> GetFeedingRecordTree();
}
}

View File

@@ -4,10 +4,13 @@ using JNPF.Common.Enums;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Extras.CollectiveOAuth.Models;
using JNPF.Extras.CollectiveOAuth.Utils;
using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Interfaces.System;
using JNPF.VisualDev.Entitys;
using Microsoft.AspNetCore.Mvc;
using Microsoft.ClearScript.Util.Web;
using Newtonsoft.Json;
@@ -163,6 +166,9 @@ namespace Tnb.ProductionMgr
public async Task<dynamic> SaveDataNew(MaterialReceiptNewInput input)
{
var db = _repository.AsSugarClient();
PrdFeedingH prdFeedingH = null;
List<PrdFeedingD> list = new List<PrdFeedingD>();
DbResult<bool> result2 = new DbResult<bool>();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
var moTask = await db.Queryable<PrdMoTask>().FirstAsync(x => x.id == input.mo_task_id);
@@ -176,9 +182,8 @@ namespace Tnb.ProductionMgr
.ToListAsync();
string code = await _billRullService.GetBillNumber(Tnb.BasicData.CodeTemplateConst.FEEDING_CODE);
PrdFeedingH prdFeedingH = new PrdFeedingH()
prdFeedingH = new PrdFeedingH()
{
code = code,
station_id = input.station_id,
@@ -196,7 +201,6 @@ namespace Tnb.ProductionMgr
org_id = _userManager.GetUserInfo().Result.organizeId
};
List<PrdFeedingD> list = new List<PrdFeedingD>();
if (input.details != null && input.details.Count > 0)
{
foreach (var item in input.details)
@@ -253,8 +257,8 @@ namespace Tnb.ProductionMgr
}
await db.Insertable<PrdFeedingH>(prdFeedingH).ExecuteCommandAsync();
await db.Insertable<PrdFeedingD>(list).ExecuteCommandAsync();
// await db.Insertable<PrdFeedingH>(prdFeedingH).ExecuteCommandAsync();
// await db.Insertable<PrdFeedingD>(list).ExecuteCommandAsync();
});
@@ -281,10 +285,69 @@ namespace Tnb.ProductionMgr
["Authorization"] = 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();
});
}
}
if(!result.IsSuccess) throw Oops.Oh(result.ErrorMessage);
return result.IsSuccess ? "签收成功" : result.ErrorMessage;
if(!result2.IsSuccess) throw Oops.Oh(result2.ErrorMessage);
return result2.IsSuccess ? "签收成功" : result2.ErrorMessage;
}
[HttpPost]
public async Task<dynamic> GetFeedingRecordTree()
{
var db = _repository.AsSugarClient();
var 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 (var 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;
}
}
}

View File

@@ -3,8 +3,10 @@ using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Extras.CollectiveOAuth.Models;
using JNPF.Extras.CollectiveOAuth.Utils;
using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.RemoteRequest;
using JNPF.Systems.Interfaces.System;
using Mapster;
@@ -48,6 +50,8 @@ namespace Tnb.ProductionMgr
var db = _repository.AsSugarClient();
var location = await db.Queryable<BasLocation>().FirstAsync(x => x.location_code == input.location_code);
PrdInstockH prdInstockH = null;
List<PrdInstockD> prdInstockDs = new List<PrdInstockD>() { };
DbResult<bool> result2 = new DbResult<bool>();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
prdInstockH = new PrdInstockH()
@@ -63,7 +67,6 @@ namespace Tnb.ProductionMgr
status = 0,
};
List<PrdInstockD> prdInstockDs = new List<PrdInstockD>() { };
foreach (var item in input.details)
{
prdInstockDs.Add(new PrdInstockD()
@@ -79,12 +82,12 @@ namespace Tnb.ProductionMgr
});
}
await _repository.InsertAsync(prdInstockH);
if (prdInstockDs.Count > 0)
{
await db.Insertable<PrdInstockD>(prdInstockDs).ExecuteCommandAsync();
}
// await _repository.InsertAsync(prdInstockH);
//
// if (prdInstockDs.Count > 0)
// {
// await db.Insertable<PrdInstockD>(prdInstockDs).ExecuteCommandAsync();
// }
});
@@ -132,11 +135,29 @@ namespace Tnb.ProductionMgr
["Authorization"] = App.HttpContext.Request.Headers["Authorization"]
};
var sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_INSTOCK,JsonConvert.SerializeObject(mesCreateInstockInput),header);
Console.WriteLine(sendResult);
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 _repository.InsertAsync(prdInstockH);
if (prdInstockDs.Count > 0)
{
await db.Insertable<PrdInstockD>(prdInstockDs).ExecuteCommandAsync();
}
});
}
}
if(!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "保存成功" : result.ErrorMessage;
if(!result2.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result2.IsSuccess ? "保存成功" : result2.ErrorMessage;
}
/// <summary>
@@ -147,15 +168,26 @@ namespace Tnb.ProductionMgr
public async Task<dynamic> SyncInstock(Dictionary<string, string> dic)
{
string sourceId = dic.ContainsKey("source_id") ? dic["source_id"] : "";
var db = _repository.AsSugarClient();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
if (!string.IsNullOrEmpty(sourceId))
{
return await _repository.UpdateAsync(x => new PrdInstockH()
await _repository.UpdateAsync(x => new PrdInstockH()
{
status = 1
}, x => x.id == sourceId);
}
var details = await db.Queryable<PrdInstockD>().Where(x => x.instock_id == sourceId).ToListAsync();
return false;
foreach (var item in details)
{
await db.Updateable<PrdReport>().SetColumns(x => x.status == 1)
.Where(x => x.id == item.report_id).ExecuteCommandAsync();
}
}
});
return result.IsSuccess;
}
}
}

View File

@@ -43,6 +43,9 @@ using Microsoft.ClearScript.Util.Web;
using Newtonsoft.Json;
using Tnb.BasicData.Entities.Dto;
using NPOI.SS.Formula.Functions;
using Tnb.PerMgr.Entities;
// using Tnb.PerMgr.Entities;
namespace Tnb.ProductionMgr
{
@@ -1711,5 +1714,39 @@ namespace Tnb.ProductionMgr
{
return await _db.Queryable<PrdMoTask>().Where(it => it.eqp_id == eqpId && it.mo_task_status == DictConst.InProgressEnCode).ToListAsync();
}
[HttpPost]
public async Task<dynamic> GetEstimatedEndTime(CountEstimatedEndTimeInput input)
{
var db = _repository.AsSugarClient();
if (input.type == 1)
{
PerProcessStandardsH processStandardsH = await db.Queryable<PerProcessStandardsH>()
.Where(x => x.equip_id == input.equip_id && x.molds_id == input.molds_id &&
x.output_material_id == input.material_id && x.enabled == 1)
.OrderByDescending(x => x.create_time).FirstAsync();
ToolMolds toolMolds = await db.Queryable<ToolMolds>().SingleAsync(x => x.id == input.molds_id);
if(toolMolds==null) throw Oops.Bah("没找到模具");
if(toolMolds?.mold_cavity<=0) throw Oops.Bah("模穴数错误");
if (processStandardsH == null) throw Oops.Bah("工艺标准成型周期错误");
if (processStandardsH?.moulding_cycle <= 0) throw Oops.Bah("工艺标准成型周期错误");
decimal? addTime = (input.scheduled_qty * toolMolds.mold_cavity - 1) / processStandardsH?.moulding_cycle + 1;
return input.estimated_start_date.AddSeconds((double)addTime.Value).ToString("yyyy-MM-dd HH:mm:ss");
}
else
{
var list = await db.Queryable<BasMbomProcess>()
.LeftJoin<BasStandardTime>((a,b)=>a.process_id==b.process_id)
.Where((a,b)=>a.mbom_id==input.mbom_id).Select((a,b)=>b).ToListAsync();
decimal max = list.Select(x => Convert.ToDecimal(x.standard_time)).Max(x => x);
decimal? addTime = input.scheduled_qty * max;
return input.estimated_start_date.AddSeconds((double)addTime.Value).ToString("yyyy-MM-dd HH:mm:ss");
}
}
}
}

View File

@@ -56,9 +56,6 @@ namespace Tnb.ProductionMgr
try
{
var db = _repository.AsSugarClient();
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
await _runService.Create(templateEntity, visualDevModelDataCrInput);
MESCreateOutstockInput input = new MESCreateOutstockInput();
input.outstock = new MESWmsOutstockHInput();
@@ -101,6 +98,11 @@ namespace Tnb.ProductionMgr
{
throw Oops.Bah(authResponse.msg);
}
else
{
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
await _runService.Create(templateEntity, visualDevModelDataCrInput);
}
return await Task.FromResult(true);
}
catch (Exception e)

View File

@@ -126,7 +126,8 @@ namespace Tnb.ProductionMgr
reported_qty = x.reported_qty,
create_id = y.RealName,
create_id_id = x.create_id,
create_time = x.create_time==null ? "" : x.create_time.Value.ToString("yyyy-MM-dd HH:mm")
create_time = x.create_time==null ? "" : x.create_time.Value.ToString("yyyy-MM-dd HH:mm"),
batch = x.batch
})
}).ToPagedListAsync(input.currentPage, input.pageSize);
return PageResult<ReportRecordListOutput>.SqlSugarPageResult(result);