配方管理

This commit is contained in:
gcw_MV9p2JJN 2025-12-10 19:05:52 +08:00
parent 1f2d42ae14
commit 8d84f51e44
8 changed files with 138 additions and 59 deletions

View File

@ -99,10 +99,10 @@ public class WorkOrderProgressController : BaseController
//TODO 开始某个工单
[HttpGet("start_workorder")]
public IActionResult StartWorkOrder(string workorder)
public async Task<IActionResult> StartWorkOrder(string workorder)
{
if (string.IsNullOrEmpty(workorder)) return SUCCESS(null);
var response = workorderProgressService.StartWorkOrder(workorder);
var response = await workorderProgressService.StartWorkOrder(workorder);
return SUCCESS(response);
}

View File

@ -106,10 +106,10 @@ namespace DOAN.Admin.Mobile.Controllers
//TODO 开始某个工单
[HttpGet("start_workorder")]
public IActionResult StartWorkOrder(string workorder)
public async Task<IActionResult> StartWorkOrder(string workorder)
{
if (string.IsNullOrEmpty(workorder)) return SUCCESS(null);
var response = padReportWorkService.StartWorkOrder(workorder);
var response =await padReportWorkService.StartWorkOrder(workorder);
return SUCCESS(response);
}

View File

@ -25,6 +25,9 @@
<ItemGroup>
<Compile Remove="Controllers\MES\base\BaseMaterialListController.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="Controllers\JobKanban\WorkOrderProgressController.cs~RF24b900.TMP" />
</ItemGroup>
<ItemGroup>
<Content Include="Controllers\MES\base\material_account\BaseMaterialListController.cs">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>

View File

@ -59,7 +59,7 @@
"RefreshTokenTime": 5, //
"TokenType": "Bearer"
},
"InjectClass": [ "DOAN.Repository", "DOAN.Service", "DOAN.Tasks", "DOAN.ServiceCore" ], //
"InjectClass": [ "DOAN.Repository", "DOAN.Service", "DOAN.Tasks", "DOAN.ServiceCore" ,"MDM"], //
"ShowDbLog": false, //db
"InitDb": false, //db
"DemoMode": false, //

View File

@ -61,8 +61,10 @@ namespace DOAN.Model.MES.product.Dto
/// </summary>
public string Specification { get; set; }
//public string Project { get; set; }
/// <summary>
/// 项目号
/// </summary>
public string Project { get; set; }
/// <summary>
/// 客户编码
/// </summary>

View File

@ -25,7 +25,7 @@ namespace DOAN.Service.JobKanban.IService
ProWorkorderDto4 GetWorkOrderDetail(string workorder);
KanbanInfo GetKanbanNum(DateTime today, string line_code, string group_code);
int StartWorkOrder(string workorder);
Task<int> StartWorkOrder(string workorder);
int FinishWorkOrder(string workorder);
ProWorkorder GetProductingWorkorder(string line_code, DateTime handleDate);
int AddLabelLog(string labelContext, string workOrder);

View File

@ -1,8 +1,10 @@
using DOAN.Model.JobKanban;
using DOAN.Infrastructure.Helper;
using DOAN.Model.JobKanban;
using DOAN.Model.MES.base_;
using DOAN.Model.MES.mm;
using DOAN.Model.MES.product;
using DOAN.Model.MES.product.Dto;
using DOAN.Model.MES.recipe;
using DOAN.Model.Mobile;
using DOAN.Service.JobKanban.IService;
using DOAN.Service.MES.mm.line;
@ -120,7 +122,7 @@ public class WorkorderProgressService : BaseService<ProWorkorder>, IWorkorderPro
return kanbanInfo;
}
public int StartWorkOrder(string workorder)
public async Task<int> StartWorkOrder(string workorder)
{
var result = 0;
// 获取同一天 同一组 同一线 的所有工单 把状态2 设为init 1
@ -139,7 +141,68 @@ public class WorkorderProgressService : BaseService<ProWorkorder>, IWorkorderPro
result = Context.Updateable<ProWorkorder>().SetColumns(it => it.Status == 2)
.SetColumns(it => it.StartTime == DateTime.Now)
.Where(it => it.Workorder == workorder).ExecuteCommand();
});
//TODO 拼接MQTT消息发送给设备工单信息和配方信息
var spec = handleWorkorder.Specification;
var RecipeMesg = Context.Queryable<PfRefProductRecipe>()
.LeftJoin<PfRecipeVersion>((rpr, r) => rpr.RecipeCode == r.RecipeCode)
.Where((rpr, r) => SqlFunc.Like(spec, rpr.RecipeCode + "%"))
.Where((rpr, r) => r.Status == 1)
.Select((rpr, r) => new
{
RecipeCode = r.RecipeCode,
Version = r.Version,
ParamList = SqlFunc.Subqueryable<PfRecipeParameters>()
.Where(it => it.RecipeCode == r.RecipeCode && it.Version == r.Version)
.ToList(),
// 添加匹配长度用于排序
MatchLength = rpr.RecipeCode.Length
})
.MergeTable()
.OrderByDescending(x => x.MatchLength) // 按匹配长度降序排列
.First(); // 取第一个(匹配最长的)
// 合并两个对象为匿名对象
var combinedObject = new
{
WorkorderInfo = handleWorkorder,
RecipeInfo = RecipeMesg
};
string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(combinedObject, Newtonsoft.Json.Formatting.Indented);
//插入配方派发日志
if (RecipeMesg != null && !string.IsNullOrEmpty(RecipeMesg.RecipeCode))
{
PfRecipeIssueLog pfRecipeIssueLog = new PfRecipeIssueLog();
pfRecipeIssueLog.RecipeCode = RecipeMesg.RecipeCode;
pfRecipeIssueLog.Version = RecipeMesg.Version;
pfRecipeIssueLog.IssueTime = DateTime.Now;
pfRecipeIssueLog.Workorder = handleWorkorder.Workorder;
pfRecipeIssueLog.Productcode = handleWorkorder.ProductionCode;
pfRecipeIssueLog.Productname = handleWorkorder.ProductionName;
pfRecipeIssueLog.CreatedBy = "PDA";
pfRecipeIssueLog.CreatedTime = DateTime.Now;
Context.Insertable(pfRecipeIssueLog).ExecuteCommand();
}
MqttHelper _mqttHelper = new MqttHelper("192.168.50.163", 1883);
// 连接
await _mqttHelper.ConnectAsync();
// 发送多条消息
await _mqttHelper.PublishMessageAsync("MES/Workorder/Start", jsonString);
// 断开连接
await _mqttHelper.DisconnectAsync();
return result;
}
@ -174,7 +237,7 @@ public class WorkorderProgressService : BaseService<ProWorkorder>, IWorkorderPro
log.Id = XueHua;
log.ProductionLabelCode = labelContext;
log.Workorder = workOrder;
// log.Status = 1;
// log.Status = 1;
log.CreatedTime = DateTime.Now;
log.CreatedBy = "终检台";
@ -202,10 +265,10 @@ public class WorkorderProgressService : BaseService<ProWorkorder>, IWorkorderPro
var checked_workorder = Context.Queryable<ProWorkorder>().Where(it => it.Workorder == workorder)
.First();
//if (!labelContext.Contains(checked_workorder.Specification))
// 产品不属于这个工单里
// 产品不属于这个工单里
if (labelContext.IndexOf(checked_workorder.Specification, StringComparison.OrdinalIgnoreCase) < 0)
{
return -1;
return -1;
}
// 增加标签长度判断 36个字符
//if (labelContext.Length != 40)
@ -234,7 +297,7 @@ public class WorkorderProgressService : BaseService<ProWorkorder>, IWorkorderPro
reportWork.CreatedBy = "kanban";
reportWork.UpdatedBy = "kanban";
reportWork.UpdatedTime = DateTime.Now;
var ExistReportwork =Context.Queryable<ProReportwork>().Where(it => it.FkWorkorder == workorder).First();
var ExistReportwork = Context.Queryable<ProReportwork>().Where(it => it.FkWorkorder == workorder).First();
var result = 0;
if (ExistReportwork != null)
{
@ -256,27 +319,27 @@ public class WorkorderProgressService : BaseService<ProWorkorder>, IWorkorderPro
}
// TODO 线边库出库(产线触摸屏)
/* try
{
// 计算Bom表
string InvCode = checked_workorder.ProductionCode;
// 查看需要的子件
var bomList = Context.Queryable<BaseMaterialBom>().Where(it => it.InvCode == InvCode).ToList();
foreach(BaseMaterialBom bom in bomList)
{
int quantity = 0;
if (int.TryParse(bom.Iusequantity, out int res))
/* try
{
quantity = res;
// 计算Bom表
string InvCode = checked_workorder.ProductionCode;
// 查看需要的子件
var bomList = Context.Queryable<BaseMaterialBom>().Where(it => it.InvCode == InvCode).ToList();
foreach(BaseMaterialBom bom in bomList)
{
int quantity = 0;
if (int.TryParse(bom.Iusequantity, out int res))
{
quantity = res;
}
MmLineInventoryService mmLineInventoryService = new MmLineInventoryService();
mmLineInventoryService.outboundLineMaterial(2,reportWork.LineCode, bom.SubInvCode, checked_workorder.Workorder, reportWork.LineCode, quantity);
}
}
MmLineInventoryService mmLineInventoryService = new MmLineInventoryService();
mmLineInventoryService.outboundLineMaterial(2,reportWork.LineCode, bom.SubInvCode, checked_workorder.Workorder, reportWork.LineCode, quantity);
}
}
catch (Exception)
{
throw;
}*/
catch (Exception)
{
throw;
}*/
return result;
@ -326,7 +389,7 @@ public class WorkorderProgressService : BaseService<ProWorkorder>, IWorkorderPro
}
/// <summary>
/// 根据工单号 查询每个工单号进度
@ -358,7 +421,7 @@ public class WorkorderProgressService : BaseService<ProWorkorder>, IWorkorderPro
{
var result = Context.Queryable<ProInspectionLabel>().Where(it => it.Workorder == pre_workorder)
.Select(it => it.EndLabel).First();
if (!string.IsNullOrEmpty(result) )
if (!string.IsNullOrEmpty(result))
{
return true;
}

View File

@ -186,19 +186,26 @@ namespace DOAN.Service.Mobile
});
//TODO 拼接MQTT消息发送给设备工单信息和配方信息
var RecipeMesg = Context.Queryable<PfRefProductRecipe>().LeftJoin<PfRecipeVersion>((rpr, r) => rpr.RecipeCode == r.RecipeCode)
.Where((rpr, r) => rpr.Productcode == handleWorkorder.ProductionCode)
.Where((rpr, r) => r.Status == 1)
.Select((rpr, r) => new
{
RecipeCode = r.RecipeCode,
Version = r.Version,
ParamList = Context.Queryable<PfRecipeParameters>().Where(it => it.RecipeCode == r.RecipeCode && it.Version == r.Version).ToList()
}).First();
if (RecipeMesg == null)
{
throw new Exception("未找到对应的配方信息,请检查产品与配方的关联关系,或配方状态是否有效");
}
var spec = handleWorkorder.Specification;
var RecipeMesg = Context.Queryable<PfRefProductRecipe>()
.LeftJoin<PfRecipeVersion>((rpr, r) => rpr.RecipeCode == r.RecipeCode)
.Where((rpr, r) => SqlFunc.Like(spec, rpr.RecipeCode + "%"))
.Where((rpr, r) => r.Status == 1)
.Select((rpr, r) => new
{
RecipeCode = r.RecipeCode,
Version = r.Version,
ParamList = SqlFunc.Subqueryable<PfRecipeParameters>()
.Where(it => it.RecipeCode == r.RecipeCode && it.Version == r.Version)
.ToList(),
// 添加匹配长度用于排序
MatchLength = rpr.RecipeCode.Length
})
.MergeTable()
.OrderByDescending(x => x.MatchLength) // 按匹配长度降序排列
.First(); // 取第一个(匹配最长的)
// 合并两个对象为匿名对象
var combinedObject = new
@ -210,19 +217,23 @@ namespace DOAN.Service.Mobile
string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(combinedObject, Newtonsoft.Json.Formatting.Indented);
//插入配方派发日志
PfRecipeIssueLog pfRecipeIssueLog = new PfRecipeIssueLog();
pfRecipeIssueLog.RecipeCode = RecipeMesg.RecipeCode;
pfRecipeIssueLog.Version = RecipeMesg.Version;
pfRecipeIssueLog.IssueTime = DateTime.Now;
pfRecipeIssueLog.Workorder = handleWorkorder.Workorder;
pfRecipeIssueLog.Productcode = handleWorkorder.ProductionCode;
pfRecipeIssueLog.Productname = handleWorkorder.ProductionName;
pfRecipeIssueLog.CreatedBy = "PDA";
pfRecipeIssueLog.CreatedTime = DateTime.Now;
Context.Insertable(pfRecipeIssueLog).ExecuteCommand();
if (RecipeMesg != null && !string.IsNullOrEmpty(RecipeMesg.RecipeCode))
{
PfRecipeIssueLog pfRecipeIssueLog = new PfRecipeIssueLog();
pfRecipeIssueLog.RecipeCode = RecipeMesg.RecipeCode;
pfRecipeIssueLog.Version = RecipeMesg.Version;
pfRecipeIssueLog.IssueTime = DateTime.Now;
pfRecipeIssueLog.Workorder = handleWorkorder.Workorder;
pfRecipeIssueLog.Productcode = handleWorkorder.ProductionCode;
pfRecipeIssueLog.Productname = handleWorkorder.ProductionName;
pfRecipeIssueLog.CreatedBy = "PDA";
pfRecipeIssueLog.CreatedTime = DateTime.Now;
Context.Insertable(pfRecipeIssueLog).ExecuteCommand();
}
MqttHelper _mqttHelper = new MqttHelper("mqtt://192.168.50.163", 8883);
MqttHelper _mqttHelper = new MqttHelper("192.168.50.163", 1883);
// 连接
await _mqttHelper.ConnectAsync();