2025-12-08 19:50:04 +08:00
|
|
|
|
using DOAN.Infrastructure.Helper;
|
2024-11-18 11:24:35 +08:00
|
|
|
|
using DOAN.Model;
|
2024-11-18 10:39:51 +08:00
|
|
|
|
using DOAN.Model.MES.base_;
|
|
|
|
|
|
using DOAN.Model.MES.mm;
|
|
|
|
|
|
using DOAN.Model.MES.product;
|
2024-11-18 11:24:35 +08:00
|
|
|
|
using DOAN.Model.MES.product.Dto;
|
2025-12-08 19:50:04 +08:00
|
|
|
|
using DOAN.Model.MES.recipe;
|
2024-11-18 11:24:35 +08:00
|
|
|
|
using DOAN.Repository;
|
2025-03-31 14:59:37 +08:00
|
|
|
|
using DOAN.Service.MES.mm.line;
|
2024-11-18 10:39:51 +08:00
|
|
|
|
using DOAN.Service.Mobile.IService;
|
|
|
|
|
|
using Infrastructure.Attribute;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DOAN.Service.Mobile
|
|
|
|
|
|
{
|
|
|
|
|
|
[AppService(ServiceType = typeof(IPADReportWorkService), ServiceLifetime = LifeTime.Transient)]
|
|
|
|
|
|
public class PADReportWorkService : BaseService<ProReportwork>, IPADReportWorkService
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 不防错直接报工
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="wokorder"></param>
|
|
|
|
|
|
/// <param name="reportNum"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int NoErrorProofingAndReportingReport(string wokorder, int reportNum)
|
|
|
|
|
|
{
|
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-11-18 12:32:32 +08:00
|
|
|
|
var selected_workorder = Context.Queryable<ProReportwork>().Where(it => it.FkWorkorder == wokorder)
|
2024-11-18 10:39:51 +08:00
|
|
|
|
.First();
|
|
|
|
|
|
if (selected_workorder != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//修改
|
|
|
|
|
|
result = Context.Updateable<ProReportwork>().Where(it => it.FkWorkorder == wokorder)
|
|
|
|
|
|
.SetColumns(it => it.FinishedNum == reportNum)
|
|
|
|
|
|
.SetColumns(it => it.UpdatedTime == DateTime.Now)
|
|
|
|
|
|
.SetColumns(it => it.UpdatedBy == "PDA")
|
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
//新增
|
2024-11-18 13:56:59 +08:00
|
|
|
|
var handle_workorder= Context.Queryable<ProWorkorder>().Where(it => it.Workorder == wokorder).First();
|
2024-11-18 10:39:51 +08:00
|
|
|
|
var reportWork = new ProReportwork();
|
|
|
|
|
|
reportWork.Id = XueHua;
|
|
|
|
|
|
reportWork.FkWorkorder = wokorder;
|
2024-11-18 12:32:32 +08:00
|
|
|
|
reportWork.DispatchNum = handle_workorder.DeliveryNum;
|
2024-11-18 10:39:51 +08:00
|
|
|
|
reportWork.FinishedNum = reportNum;
|
2024-11-18 12:36:00 +08:00
|
|
|
|
reportWork.GroupCode = handle_workorder.GroupCode;
|
|
|
|
|
|
reportWork.LineCode = handle_workorder.LineCode;
|
2024-11-18 10:39:51 +08:00
|
|
|
|
reportWork.CreatedTime = DateTime.Now;
|
2024-11-18 12:32:32 +08:00
|
|
|
|
reportWork.CreatedBy = "PDA";
|
|
|
|
|
|
|
2024-11-18 10:39:51 +08:00
|
|
|
|
result = Context.Insertable(reportWork).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-31 14:59:37 +08:00
|
|
|
|
/* // TODO 线边库出库(PDA)
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// 工单信息查询
|
|
|
|
|
|
var workorderInfo = Context.Queryable<ProWorkorder>().Where(it => it.Workorder == wokorder).First();
|
|
|
|
|
|
// 计算Bom表
|
|
|
|
|
|
string InvCode = workorderInfo.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(1, workorderInfo.LineCode, bom.SubInvCode, workorderInfo.Workorder, workorderInfo.LineCode, quantity);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}*/
|
2024-11-18 10:39:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-18 11:24:35 +08:00
|
|
|
|
public List<BaseWorkRoute> GetAllRoute()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context.Queryable<BaseWorkRoute>().ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<BaseGroup> GetGroupList()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context.Queryable<BaseGroup>().Where(it => it.Status == 1).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-18 11:43:17 +08:00
|
|
|
|
public ProWorkorderDto4 GetWorkOrderDetail(string workorder)
|
2024-11-18 11:24:35 +08:00
|
|
|
|
{
|
2024-11-18 11:43:17 +08:00
|
|
|
|
var query = Context.Queryable<ProWorkorder>()
|
|
|
|
|
|
.Where(it => it.Workorder == workorder);
|
2024-11-18 11:24:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-11-18 11:43:17 +08:00
|
|
|
|
return Context.Queryable(query)
|
|
|
|
|
|
.LeftJoin<ProReportwork>((q, r) => q.Workorder == r.FkWorkorder)
|
|
|
|
|
|
.Select((q, r) => new ProWorkorderDto4
|
|
|
|
|
|
{
|
|
|
|
|
|
FinishNum = r.FinishedNum
|
|
|
|
|
|
}, true).First();
|
|
|
|
|
|
}
|
2024-11-18 11:24:35 +08:00
|
|
|
|
|
2024-11-18 11:43:17 +08:00
|
|
|
|
public List<ProReportworkDto> GetWorkOrderStatusList(string group_code, int status, DateTime handleDate)
|
|
|
|
|
|
{
|
|
|
|
|
|
var query = Context.Queryable<ProWorkorder>().Where(it => it.GroupCode == group_code)
|
|
|
|
|
|
.Where(it => it.Status == status)
|
|
|
|
|
|
.Where(it => it.WorkorderDate == handleDate);
|
|
|
|
|
|
|
|
|
|
|
|
return Context.Queryable(query)
|
2024-11-18 11:24:35 +08:00
|
|
|
|
.LeftJoin<ProReportwork>((w, r) => w.Workorder == r.FkWorkorder)
|
|
|
|
|
|
.Select((w, r) => new ProReportworkDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = r.Id,
|
|
|
|
|
|
ProductionCode = w.ProductionCode,
|
|
|
|
|
|
ProductionName = w.ProductionName,
|
|
|
|
|
|
Specification = w.Specification,
|
|
|
|
|
|
QualifiedNumber = r.QualifiedNumber,
|
|
|
|
|
|
UnqualifiedNumber = r.UnqualifiedNumber,
|
|
|
|
|
|
ReworkNumber = r.ReworkNumber,
|
|
|
|
|
|
ScrapNumber = r.ScrapNumber,
|
|
|
|
|
|
Remark = r.Remark,
|
|
|
|
|
|
Difference = r.QualifiedNumber - r.FinishedNum ?? 0,
|
|
|
|
|
|
FkWorkorder = w.Workorder,
|
|
|
|
|
|
GroupCode = w.GroupCode,
|
|
|
|
|
|
LineCode = w.LineCode,
|
|
|
|
|
|
DispatchNum = w.DeliveryNum ?? 0,
|
|
|
|
|
|
Priority = w.Priority,
|
|
|
|
|
|
Status = w.Status,
|
|
|
|
|
|
Beat = w.Beat
|
2024-11-18 11:43:17 +08:00
|
|
|
|
}, true).ToList();
|
2024-11-18 11:24:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 修改报工表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int UpdateProReportwork(ProReportwork model)
|
|
|
|
|
|
{
|
2024-11-18 10:39:51 +08:00
|
|
|
|
|
2024-11-18 11:24:35 +08:00
|
|
|
|
|
|
|
|
|
|
//var response = Update(w => w.Id == model.Id, it => new ProReportwork()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// FkWorkorder = model.FkWorkorder,
|
|
|
|
|
|
// DispatchNum = model.DispatchNum,
|
|
|
|
|
|
// FinishedNum = model.FinishedNum,
|
|
|
|
|
|
// GroupCode = model.GroupCode,
|
|
|
|
|
|
// LineCode = model.LineCode,
|
|
|
|
|
|
// CreatedBy = model.CreatedBy,
|
|
|
|
|
|
// CreatedTime = model.CreatedTime,
|
|
|
|
|
|
// UpdatedBy = model.UpdatedBy,
|
|
|
|
|
|
// UpdatedTime = model.UpdatedTime,
|
|
|
|
|
|
//});
|
|
|
|
|
|
//return response;
|
|
|
|
|
|
return Update(model, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-08 19:50:04 +08:00
|
|
|
|
public async Task<int> StartWorkOrder(string workorder)
|
2024-11-18 10:39:51 +08:00
|
|
|
|
{
|
2024-11-18 11:24:35 +08:00
|
|
|
|
var result = 0;
|
|
|
|
|
|
// 获取同一天 同一组 同一线 的所有工单 把状态2 设为init 1
|
|
|
|
|
|
var handleWorkorder =
|
|
|
|
|
|
Context.Queryable<ProWorkorder>().Where(it => it.Workorder == workorder).First();
|
|
|
|
|
|
UseTran2(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Updateable<ProWorkorder>().SetColumns(it => it.Status == 1)
|
|
|
|
|
|
.Where(it => it.Status == 2)
|
|
|
|
|
|
.Where(it => it.WorkorderDate == handleWorkorder.WorkorderDate)
|
|
|
|
|
|
.Where(it => it.GroupCode == handleWorkorder.GroupCode)
|
|
|
|
|
|
.Where(it => it.LineCode == handleWorkorder.LineCode)
|
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = Context.Updateable<ProWorkorder>().SetColumns(it => it.Status == 2)
|
|
|
|
|
|
.SetColumns(it => it.StartTime == DateTime.Now)
|
|
|
|
|
|
.Where(it => it.Workorder == workorder).ExecuteCommand();
|
|
|
|
|
|
});
|
2025-12-08 11:42:44 +08:00
|
|
|
|
|
|
|
|
|
|
//TODO 拼接MQTT消息,发送给设备,工单信息和配方信息
|
2025-12-10 19:05:52 +08:00
|
|
|
|
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(); // 取第一个(匹配最长的)
|
|
|
|
|
|
|
2025-12-08 19:50:04 +08:00
|
|
|
|
|
|
|
|
|
|
// 合并两个对象为匿名对象
|
|
|
|
|
|
var combinedObject = new
|
|
|
|
|
|
{
|
|
|
|
|
|
WorkorderInfo = handleWorkorder,
|
|
|
|
|
|
RecipeInfo = RecipeMesg
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(combinedObject, Newtonsoft.Json.Formatting.Indented);
|
|
|
|
|
|
//插入配方派发日志
|
2025-12-10 19:05:52 +08:00
|
|
|
|
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);
|
2025-12-08 19:50:04 +08:00
|
|
|
|
|
|
|
|
|
|
// 连接
|
|
|
|
|
|
await _mqttHelper.ConnectAsync();
|
|
|
|
|
|
|
|
|
|
|
|
// 发送多条消息
|
2025-12-31 13:59:14 +08:00
|
|
|
|
string line = handleWorkorder.LineCode == null ? "-1" : handleWorkorder.LineCode;
|
|
|
|
|
|
await _mqttHelper.PublishMessageAsync("MES/Workorder/Start/handleWorkorder/" + line, jsonString);
|
2025-12-08 19:50:04 +08:00
|
|
|
|
|
|
|
|
|
|
// 断开连接
|
|
|
|
|
|
await _mqttHelper.DisconnectAsync();
|
2025-12-08 11:42:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-11-18 11:24:35 +08:00
|
|
|
|
return result;
|
2024-11-18 10:39:51 +08:00
|
|
|
|
}
|
2024-11-18 11:24:35 +08:00
|
|
|
|
|
|
|
|
|
|
public int FinishWorkOrder(string workorder)
|
2024-11-18 10:39:51 +08:00
|
|
|
|
{
|
2024-11-18 11:24:35 +08:00
|
|
|
|
return Context.Updateable<ProWorkorder>()
|
|
|
|
|
|
.SetColumns(it => it.Status == 3)
|
|
|
|
|
|
.SetColumns(it => it.EndTime == DateTime.Now)
|
|
|
|
|
|
.Where(it => it.Workorder == workorder).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-11-18 11:43:17 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 查询报工表列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="parm"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public PagedInfo<ProReportworkDto> GetList(ProReportworkQueryDto parm)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (parm.TimeRange != null && parm.TimeRange.Length == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
parm.TimeRange[0] = parm.TimeRange[0].Date;
|
|
|
|
|
|
// parm.TimeRange[1] = parm.TimeRange[1].Date.AddDays(1);
|
|
|
|
|
|
parm.TimeRange[1] = parm.TimeRange[1].Date;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var predicate = Expressionable.Create<ProWorkorder, ProReportwork>()
|
|
|
|
|
|
.AndIF(!string.IsNullOrEmpty(parm.FkWorkorder), (w, r) => w.Workorder.Contains(parm.FkWorkorder))
|
|
|
|
|
|
.AndIF(!string.IsNullOrEmpty(parm.GroupCode), (w, r) => w.GroupCode == parm.GroupCode)
|
|
|
|
|
|
.AndIF(!string.IsNullOrEmpty(parm.LineCode), (w, r) => w.LineCode == parm.LineCode)
|
|
|
|
|
|
.AndIF(parm.WarehouseconfirmationNum > 0, (w, r) => r.QualifiedNumber > 0)
|
|
|
|
|
|
.AndIF(
|
|
|
|
|
|
parm.TimeRange != null && parm.TimeRange.Length == 2 && parm.TimeRange[0] > DateTime.MinValue,
|
|
|
|
|
|
(w, r) => w.WorkorderDate >= parm.TimeRange[0])
|
|
|
|
|
|
.AndIF(
|
|
|
|
|
|
parm.TimeRange != null && parm.TimeRange.Length == 2 && parm.TimeRange[1] > DateTime.MinValue,
|
|
|
|
|
|
(w, r) => w.WorkorderDate <= parm.TimeRange[1])
|
|
|
|
|
|
.AndIF(parm.Status > 0, (w, r) => w.Status == parm.Status)
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var response = Context.Queryable<ProWorkorder>()
|
|
|
|
|
|
.LeftJoin<ProReportwork>((w, r) => w.Workorder == r.FkWorkorder)
|
|
|
|
|
|
.Where(predicate.ToExpression())
|
|
|
|
|
|
.Select((w, r) => new ProReportworkDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = r.Id,
|
|
|
|
|
|
ProductionCode = w.ProductionCode,
|
|
|
|
|
|
ProductionName = w.ProductionName,
|
|
|
|
|
|
Specification = w.Specification,
|
|
|
|
|
|
QualifiedNumber = r.QualifiedNumber,
|
|
|
|
|
|
UnqualifiedNumber = r.UnqualifiedNumber,
|
|
|
|
|
|
ReworkNumber = r.ReworkNumber,
|
|
|
|
|
|
ScrapNumber = r.ScrapNumber,
|
|
|
|
|
|
Remark = r.Remark,
|
|
|
|
|
|
Difference = r.QualifiedNumber - r.FinishedNum ?? 0,
|
|
|
|
|
|
FkWorkorder = w.Workorder,
|
|
|
|
|
|
GroupCode = w.GroupCode,
|
|
|
|
|
|
LineCode = w.LineCode,
|
|
|
|
|
|
DispatchNum = w.DeliveryNum ?? 0,
|
|
|
|
|
|
Priority = w.Priority,
|
|
|
|
|
|
Status = w.Status,
|
|
|
|
|
|
Beat = w.Beat
|
|
|
|
|
|
}, true).ToPage_NO_Convert<ProReportworkDto>(parm);
|
|
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-11-18 11:24:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-03-17 09:48:32 +08:00
|
|
|
|
|
2024-11-18 10:39:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|