2025-12-10 19:05:52 +08:00
|
|
|
|
using DOAN.Infrastructure.Helper;
|
|
|
|
|
|
using DOAN.Model.JobKanban;
|
2024-09-19 09:34:54 +08:00
|
|
|
|
using DOAN.Model.MES.base_;
|
2024-09-19 10:03:04 +08:00
|
|
|
|
using DOAN.Model.MES.mm;
|
2024-11-06 15:10:26 +08:00
|
|
|
|
using DOAN.Model.MES.product;
|
|
|
|
|
|
using DOAN.Model.MES.product.Dto;
|
2025-12-10 19:05:52 +08:00
|
|
|
|
using DOAN.Model.MES.recipe;
|
2025-04-10 16:51:14 +08:00
|
|
|
|
using DOAN.Model.Mobile;
|
2024-11-06 15:10:26 +08:00
|
|
|
|
using DOAN.Service.JobKanban.IService;
|
2025-03-31 14:59:37 +08:00
|
|
|
|
using DOAN.Service.MES.mm.line;
|
2025-12-27 13:28:10 +08:00
|
|
|
|
using DOAN.Service.MES.product;
|
2024-11-06 15:10:26 +08:00
|
|
|
|
using Infrastructure.Attribute;
|
2024-11-07 11:35:17 +08:00
|
|
|
|
using Mapster;
|
2025-12-27 13:28:10 +08:00
|
|
|
|
using NPOI.SS.Formula.Functions;
|
2024-11-17 20:28:38 +08:00
|
|
|
|
using Org.BouncyCastle.Asn1;
|
2024-11-06 16:14:12 +08:00
|
|
|
|
using SqlSugar.SplitTableExtensions;
|
2025-12-27 13:28:10 +08:00
|
|
|
|
using System.Net.Http;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2024-11-06 15:10:26 +08:00
|
|
|
|
|
|
|
|
|
|
namespace DOAN.Service.JobKanban;
|
2024-09-19 09:34:54 +08:00
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
[AppService(ServiceType = typeof(IWorkorderProgressService), ServiceLifetime = LifeTime.Transient)]
|
|
|
|
|
|
public class WorkorderProgressService : BaseService<ProWorkorder>, IWorkorderProgressService
|
2024-09-19 09:34:54 +08:00
|
|
|
|
{
|
2025-12-27 13:28:10 +08:00
|
|
|
|
private ProProducttypeSpecService _proProducttypeSpecService = new ProProducttypeSpecService();
|
2024-11-06 15:10:26 +08:00
|
|
|
|
public List<BaseWorkRoute> GetRoutes()
|
2024-09-19 09:34:54 +08:00
|
|
|
|
{
|
2024-11-06 15:10:26 +08:00
|
|
|
|
return Context.Queryable<BaseWorkRoute>().Where(it => it.Status == 1).ToList();
|
|
|
|
|
|
}
|
2024-09-19 09:34:54 +08:00
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
public List<BaseGroup> GetGroups()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context.Queryable<BaseGroup>().Where(it => it.Status == 1).ToList();
|
|
|
|
|
|
}
|
2024-09-19 09:42:54 +08:00
|
|
|
|
|
2024-11-07 16:45:06 +08:00
|
|
|
|
public List<ProWorkorder> GetWorkOrderList(string group_code, string line_code, DateTime handleDate)
|
|
|
|
|
|
{
|
|
|
|
|
|
handleDate = handleDate.ToLocalTime().Date;
|
2024-09-19 09:42:54 +08:00
|
|
|
|
|
2024-11-07 16:45:06 +08:00
|
|
|
|
return Context.Queryable<ProWorkorder>().Where(it => it.GroupCode == group_code)
|
|
|
|
|
|
.Where(it => it.LineCode == line_code)
|
|
|
|
|
|
.Where(it => it.WorkorderDate == handleDate)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
}
|
2024-11-14 16:47:47 +08:00
|
|
|
|
|
2024-11-15 16:06:55 +08:00
|
|
|
|
|
2024-11-07 10:58:06 +08:00
|
|
|
|
public List<ProReportwork> GetReportWorkRecord(string group_code, string line_code, DateTime handleDate)
|
2024-11-06 15:10:26 +08:00
|
|
|
|
{
|
2024-11-07 10:58:06 +08:00
|
|
|
|
return Context.Queryable<ProWorkorder>().LeftJoin<ProReportwork>((w, r) => w.Workorder == r.FkWorkorder)
|
2024-11-17 20:28:38 +08:00
|
|
|
|
.Where((w, r) => w.GroupCode == group_code)
|
|
|
|
|
|
.Where((w, r) => w.LineCode == line_code)
|
|
|
|
|
|
.Where((w, r) => w.WorkorderDate == handleDate)
|
|
|
|
|
|
.Select((w, r) => new
|
|
|
|
|
|
{
|
|
|
|
|
|
FkWorkorder = w.Workorder,
|
|
|
|
|
|
DispatchNum = w.DeliveryNum,
|
|
|
|
|
|
FinishedNum = r.FinishedNum,
|
|
|
|
|
|
})
|
|
|
|
|
|
.ToList().Adapt<List<ProReportwork>>();
|
2024-11-06 15:10:26 +08:00
|
|
|
|
}
|
2024-09-19 09:53:04 +08:00
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取工单列表 未完成
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="today"></param>
|
|
|
|
|
|
/// <param name="LineCode"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public List<ProWorkorderDto4> GetWorkOrderListNoFinish(DateTime today, string line_code, string group_code)
|
|
|
|
|
|
{
|
|
|
|
|
|
today = today.ToLocalTime().Date;
|
|
|
|
|
|
var query1 = Context.Queryable<ProWorkorder>()
|
2024-09-19 10:03:04 +08:00
|
|
|
|
.Where(it => it.WorkorderDate == today)
|
2024-09-19 10:51:31 +08:00
|
|
|
|
.Where(it => it.LineCode == line_code)
|
|
|
|
|
|
.Where(it => it.GroupCode == group_code)
|
2024-09-19 10:03:04 +08:00
|
|
|
|
.Where(it => it.Status == 1 || it.Status == 2)
|
2024-11-06 15:10:26 +08:00
|
|
|
|
;
|
2024-09-19 10:03:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
var ProWorkorderDto4List = Context.Queryable(query1)
|
|
|
|
|
|
.LeftJoin<ProReportwork>((q, r) => q.Workorder == r.FkWorkorder)
|
|
|
|
|
|
.Select((q, r) => new ProWorkorderDto4
|
2024-09-19 10:03:04 +08:00
|
|
|
|
{
|
2024-11-06 15:10:26 +08:00
|
|
|
|
FinishNum = r.FinishedNum
|
|
|
|
|
|
}, true)
|
|
|
|
|
|
.MergeTable()
|
|
|
|
|
|
.OrderBy(it => it.Sort)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
if (ProWorkorderDto4List.Count > 0)
|
|
|
|
|
|
foreach (var item in ProWorkorderDto4List)
|
|
|
|
|
|
item.progress = SearchMaterialPreparationProgress(item.Workorder);
|
2024-09-19 10:03:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
return ProWorkorderDto4List;
|
|
|
|
|
|
}
|
2024-09-19 10:03:04 +08:00
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
public ProWorkorderDto4 GetWorkOrderDetail(string workorder)
|
|
|
|
|
|
{
|
|
|
|
|
|
var query = Context.Queryable<ProWorkorder>()
|
|
|
|
|
|
.Where(it => it.Workorder == workorder);
|
2024-09-19 10:03:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
return Context.Queryable(query)
|
|
|
|
|
|
.LeftJoin<ProReportwork>((q, r) => q.Workorder == r.FkWorkorder)
|
|
|
|
|
|
.Select((q, r) => new ProWorkorderDto4
|
2024-09-19 10:03:04 +08:00
|
|
|
|
{
|
2024-11-06 15:10:26 +08:00
|
|
|
|
FinishNum = r.FinishedNum
|
|
|
|
|
|
}, true).First();
|
|
|
|
|
|
}
|
2024-09-19 10:03:04 +08:00
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
public KanbanInfo GetKanbanNum(DateTime today, string line_code, string group_code)
|
|
|
|
|
|
{
|
|
|
|
|
|
var kanbanInfo = new KanbanInfo();
|
|
|
|
|
|
today = today.ToLocalTime().Date;
|
|
|
|
|
|
kanbanInfo.TotalTaskNum = Context.Queryable<ProWorkorder>()
|
|
|
|
|
|
.Where(it => it.WorkorderDate == today)
|
|
|
|
|
|
.Where(it => it.LineCode == line_code)
|
|
|
|
|
|
.Where(it => it.GroupCode == group_code)
|
|
|
|
|
|
.Count();
|
|
|
|
|
|
|
|
|
|
|
|
kanbanInfo.RemainTasKNum = Context.Queryable<ProWorkorder>()
|
|
|
|
|
|
.Where(it => it.WorkorderDate == today)
|
|
|
|
|
|
.Where(it => it.LineCode == line_code)
|
|
|
|
|
|
.Where(it => it.GroupCode == group_code)
|
|
|
|
|
|
.Where(it => it.Status == 1 || it.Status == 2)
|
|
|
|
|
|
.Count();
|
|
|
|
|
|
|
|
|
|
|
|
return kanbanInfo;
|
|
|
|
|
|
}
|
2024-09-19 10:03:04 +08:00
|
|
|
|
|
2025-12-10 19:05:52 +08:00
|
|
|
|
public async Task<int> StartWorkOrder(string workorder)
|
2024-11-06 15:10:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
var result = 0;
|
|
|
|
|
|
// 获取同一天 同一组 同一线 的所有工单 把状态2 设为init 1
|
|
|
|
|
|
var handleWorkorder =
|
|
|
|
|
|
Context.Queryable<ProWorkorder>().Where(it => it.Workorder == workorder).First();
|
|
|
|
|
|
UseTran2(() =>
|
2024-09-19 10:03:04 +08:00
|
|
|
|
{
|
2024-11-06 15:10:26 +08:00
|
|
|
|
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();
|
2024-09-19 10:03:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
result = Context.Updateable<ProWorkorder>().SetColumns(it => it.Status == 2)
|
|
|
|
|
|
.SetColumns(it => it.StartTime == DateTime.Now)
|
|
|
|
|
|
.Where(it => it.Workorder == workorder).ExecuteCommand();
|
2025-12-10 19:05:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
});
|
2025-12-27 14:08:13 +08:00
|
|
|
|
//新增QMS首检
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
QMSFirstInspection(handleWorkorder);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-10 19:05:52 +08:00
|
|
|
|
//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
|
|
|
|
|
|
};
|
2025-12-27 13:28:10 +08:00
|
|
|
|
|
2025-12-10 19:05:52 +08:00
|
|
|
|
|
|
|
|
|
|
string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(combinedObject, Newtonsoft.Json.Formatting.Indented);
|
|
|
|
|
|
//插入配方派发日志
|
|
|
|
|
|
if (RecipeMesg != null && !string.IsNullOrEmpty(RecipeMesg.RecipeCode))
|
2025-12-27 13:28:10 +08:00
|
|
|
|
{
|
2025-12-10 19:05:52 +08:00
|
|
|
|
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();
|
|
|
|
|
|
|
2025-12-27 13:28:10 +08:00
|
|
|
|
}
|
2025-12-10 19:05:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MqttHelper _mqttHelper = new MqttHelper("192.168.50.163", 1883);
|
|
|
|
|
|
|
|
|
|
|
|
// 连接
|
|
|
|
|
|
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-10 19:05:52 +08:00
|
|
|
|
|
|
|
|
|
|
// 断开连接
|
|
|
|
|
|
await _mqttHelper.DisconnectAsync();
|
2024-11-06 15:10:26 +08:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2024-09-19 10:03:04 +08:00
|
|
|
|
|
2025-12-27 13:28:10 +08:00
|
|
|
|
//新增每天首检,按规格号查对应的产品类型,如果产品类型是今天首次做,就触发首检,记录发送首检记录
|
|
|
|
|
|
//暂时是每次开工都首检
|
|
|
|
|
|
private async Task QMSFirstInspection(ProWorkorder handleWorkorder)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (handleWorkorder != null && !string.IsNullOrEmpty(handleWorkorder.Specification))
|
|
|
|
|
|
{
|
|
|
|
|
|
var queryType = _proProducttypeSpecService.Queryable()
|
|
|
|
|
|
.Where(it => it.Specification == handleWorkorder.Specification)
|
|
|
|
|
|
.First();
|
|
|
|
|
|
if (queryType != null && !string.IsNullOrEmpty(queryType.ProductionType))
|
|
|
|
|
|
{
|
|
|
|
|
|
//查询记录表,看今天这个产品类型是否已经首检
|
|
|
|
|
|
//构造首检信息
|
|
|
|
|
|
InspectionRecordDto inspectionRecordDto = new InspectionRecordDto();
|
|
|
|
|
|
inspectionRecordDto.assemblyModel = queryType.Specification;
|
|
|
|
|
|
inspectionRecordDto.type = queryType.ProductionType;
|
|
|
|
|
|
inspectionRecordDto.triggerTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
inspectionRecordDto.inspectionTimes = "1";
|
|
|
|
|
|
inspectionRecordDto.inspectionStatus = "未巡检";
|
|
|
|
|
|
//调用QMS接口,发送首检记录
|
|
|
|
|
|
string qmsApiUrl = "https://aliwork.zitoo.com.cn/ganxiang/patrol-info"; // QMS接口地址
|
|
|
|
|
|
// 序列化DTO为JSON请求体
|
|
|
|
|
|
string requestJson = JsonConvert.SerializeObject(inspectionRecordDto);
|
|
|
|
|
|
var content = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
|
|
|
|
HttpClient httpClient = new HttpClient();
|
|
|
|
|
|
// 发送POST请求(接口通常为POST,若为GET需调整)
|
|
|
|
|
|
HttpResponseMessage response = await httpClient.PostAsync(qmsApiUrl, content);
|
|
|
|
|
|
string responseJson = await response.Content.ReadAsStringAsync();
|
|
|
|
|
|
QmsFirstInspectionResponseDto responseDto = JsonConvert.DeserializeObject<QmsFirstInspectionResponseDto>(responseJson);
|
|
|
|
|
|
// 解析接口响应
|
|
|
|
|
|
if (responseDto != null && responseDto.Code == "200")
|
|
|
|
|
|
{
|
|
|
|
|
|
// 首检记录发送成功,记录到本地数据库
|
|
|
|
|
|
//TODO 记录首检日志
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
public int FinishWorkOrder(string workorder)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context.Updateable<ProWorkorder>()
|
|
|
|
|
|
.SetColumns(it => it.Status == 3)
|
|
|
|
|
|
.SetColumns(it => it.EndTime == DateTime.Now)
|
|
|
|
|
|
.Where(it => it.Workorder == workorder).ExecuteCommand();
|
|
|
|
|
|
}
|
2024-09-19 10:03:04 +08:00
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
public ProWorkorder GetProductingWorkorder(string line_code, DateTime handleDate)
|
|
|
|
|
|
{
|
|
|
|
|
|
//TODO 这个日期有问题??????
|
|
|
|
|
|
if (handleDate.Kind == DateTimeKind.Utc)
|
|
|
|
|
|
handleDate = handleDate.ToLocalTime().Date;
|
|
|
|
|
|
else
|
|
|
|
|
|
handleDate = handleDate.Date;
|
2024-09-19 09:53:04 +08:00
|
|
|
|
|
2024-09-19 16:13:09 +08:00
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
return Context.Queryable<ProWorkorder>()
|
|
|
|
|
|
.Where(it => it.LineCode == line_code)
|
|
|
|
|
|
.Where(it => it.WorkorderDate == handleDate)
|
|
|
|
|
|
.Where(it => it.Status == 2)
|
|
|
|
|
|
//.Select(it=>it.Workorder)
|
|
|
|
|
|
.First();
|
|
|
|
|
|
}
|
2024-09-19 16:13:09 +08:00
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
public int AddLabelLog(string labelContext, string workOrder)
|
|
|
|
|
|
{
|
2024-12-26 16:25:01 +08:00
|
|
|
|
var log = new ProReportworkDetail();
|
2024-11-06 15:10:26 +08:00
|
|
|
|
log.Id = XueHua;
|
2025-04-06 16:14:18 +08:00
|
|
|
|
log.ProductionLabelCode = labelContext;
|
2024-11-06 15:10:26 +08:00
|
|
|
|
log.Workorder = workOrder;
|
2025-12-10 19:05:52 +08:00
|
|
|
|
// log.Status = 1;
|
2024-11-06 15:10:26 +08:00
|
|
|
|
log.CreatedTime = DateTime.Now;
|
2024-12-23 13:49:34 +08:00
|
|
|
|
log.CreatedBy = "终检台";
|
2024-11-06 15:10:26 +08:00
|
|
|
|
|
2024-12-26 16:25:01 +08:00
|
|
|
|
return Context.Insertable(log).SplitTable().ExecuteCommand();
|
2024-11-06 15:10:26 +08:00
|
|
|
|
}
|
2024-10-16 16:17:59 +08:00
|
|
|
|
|
2024-09-19 10:03:04 +08:00
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
public int LabelWorkOrderMatch(string LabelContext, string workOrder)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context.Updateable<ProLabelTraceLog>()
|
|
|
|
|
|
.Where(it => it.Workorder == workOrder)
|
|
|
|
|
|
.Where(it => it.LabelContext == LabelContext)
|
|
|
|
|
|
.SetColumns(it => it.Status == 1)
|
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
}
|
2024-09-19 10:03:04 +08:00
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
/// <summary>
|
2025-02-21 17:17:23 +08:00
|
|
|
|
/// 防错并且报工
|
2024-11-06 15:10:26 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="workorder"></param>
|
|
|
|
|
|
/// <param name="labelContext"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int ErrorProofingAndReportingWork(string workorder, string labelContext)
|
|
|
|
|
|
{
|
|
|
|
|
|
var checked_workorder = Context.Queryable<ProWorkorder>().Where(it => it.Workorder == workorder)
|
|
|
|
|
|
.First();
|
2024-12-02 09:18:14 +08:00
|
|
|
|
//if (!labelContext.Contains(checked_workorder.Specification))
|
2025-12-10 19:05:52 +08:00
|
|
|
|
// 产品不属于这个工单里
|
2024-12-02 09:18:14 +08:00
|
|
|
|
if (labelContext.IndexOf(checked_workorder.Specification, StringComparison.OrdinalIgnoreCase) < 0)
|
|
|
|
|
|
{
|
2025-12-10 19:05:52 +08:00
|
|
|
|
return -1;
|
2024-12-02 09:18:14 +08:00
|
|
|
|
}
|
2025-01-07 11:37:15 +08:00
|
|
|
|
// 增加标签长度判断 36个字符
|
2025-02-21 17:17:23 +08:00
|
|
|
|
//if (labelContext.Length != 40)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// return -2;
|
|
|
|
|
|
//}
|
2024-11-06 15:10:26 +08:00
|
|
|
|
|
|
|
|
|
|
// 记录条码
|
|
|
|
|
|
var detail = new ProReportworkDetail();
|
|
|
|
|
|
detail.Id = XueHua;
|
|
|
|
|
|
detail.Workorder = workorder;
|
2025-04-06 16:14:18 +08:00
|
|
|
|
detail.ProductionLabelCode = labelContext;
|
2024-11-06 15:10:26 +08:00
|
|
|
|
detail.CreatedBy = "MES";
|
|
|
|
|
|
detail.CreatedTime = DateTime.Now;
|
2024-12-26 16:25:01 +08:00
|
|
|
|
Context.Insertable(detail).SplitTable().ExecuteCommand();
|
2024-11-06 15:10:26 +08:00
|
|
|
|
|
|
|
|
|
|
// 累加报工数
|
|
|
|
|
|
var reportWork = new ProReportwork();
|
|
|
|
|
|
reportWork.Id = XueHua;
|
|
|
|
|
|
reportWork.FkWorkorder = workorder;
|
|
|
|
|
|
reportWork.DispatchNum = checked_workorder.DeliveryNum;
|
|
|
|
|
|
reportWork.FinishedNum = 1;
|
|
|
|
|
|
reportWork.GroupCode = checked_workorder.GroupCode;
|
|
|
|
|
|
reportWork.LineCode = checked_workorder.LineCode;
|
|
|
|
|
|
reportWork.CreatedTime = DateTime.Now;
|
|
|
|
|
|
reportWork.CreatedBy = "kanban";
|
|
|
|
|
|
reportWork.UpdatedBy = "kanban";
|
|
|
|
|
|
reportWork.UpdatedTime = DateTime.Now;
|
2025-12-10 19:05:52 +08:00
|
|
|
|
var ExistReportwork = Context.Queryable<ProReportwork>().Where(it => it.FkWorkorder == workorder).First();
|
2024-11-06 15:10:26 +08:00
|
|
|
|
var result = 0;
|
|
|
|
|
|
if (ExistReportwork != null)
|
2024-09-19 11:15:11 +08:00
|
|
|
|
{
|
2024-11-06 15:10:26 +08:00
|
|
|
|
reportWork.FinishedNum = ExistReportwork.FinishedNum + 1;
|
2025-02-21 17:17:23 +08:00
|
|
|
|
result += Context.Updateable<ProReportwork>().Where(it => it.FkWorkorder == workorder)
|
|
|
|
|
|
.SetColumns(it => new ProReportwork()
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdatedBy = reportWork.UpdatedBy,
|
|
|
|
|
|
UpdatedTime = reportWork.UpdatedTime,
|
|
|
|
|
|
FinishedNum = reportWork.FinishedNum
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
2024-11-06 15:10:26 +08:00
|
|
|
|
.ExecuteCommand();
|
2024-09-19 11:15:11 +08:00
|
|
|
|
}
|
2024-11-06 15:10:26 +08:00
|
|
|
|
else
|
2024-09-27 10:56:01 +08:00
|
|
|
|
{
|
2024-11-06 15:10:26 +08:00
|
|
|
|
reportWork.FinishedNum = 1;
|
|
|
|
|
|
result += Context.Insertable(reportWork).ExecuteCommand();
|
2024-09-27 10:56:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-31 14:59:37 +08:00
|
|
|
|
// TODO 线边库出库(产线触摸屏)
|
2025-12-10 19:05:52 +08:00
|
|
|
|
/* try
|
2025-03-31 14:59:37 +08:00
|
|
|
|
{
|
2025-12-10 19:05:52 +08:00
|
|
|
|
// 计算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);
|
|
|
|
|
|
}
|
2025-03-31 14:59:37 +08:00
|
|
|
|
}
|
2025-12-10 19:05:52 +08:00
|
|
|
|
catch (Exception)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}*/
|
2024-11-17 20:28:38 +08:00
|
|
|
|
|
2024-09-19 14:33:52 +08:00
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2024-09-19 14:33:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
public int FinishWorkorder(string workorder, int finish_num)
|
|
|
|
|
|
{
|
|
|
|
|
|
var result = 0;
|
2024-10-16 16:17:59 +08:00
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
result = Context.Updateable<ProWorkorder>()
|
|
|
|
|
|
.Where(it => it.Workorder == workorder)
|
2024-11-08 12:21:11 +08:00
|
|
|
|
.SetColumns(it => it.EndTime == DateTime.Now.ToLocalTime())
|
2024-11-06 15:10:26 +08:00
|
|
|
|
.SetColumns(it => it.Status == 3)
|
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2024-09-19 14:41:13 +08:00
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
public (int, int) GetWorkOrderProgress(string workorder)
|
|
|
|
|
|
{
|
2024-11-07 10:58:06 +08:00
|
|
|
|
var result = Context.Queryable<ProReportwork>().Where(it => it.FkWorkorder == workorder)
|
2024-11-06 15:10:26 +08:00
|
|
|
|
.Select(it => new { it.DispatchNum, it.FinishedNum }).First();
|
2024-11-06 15:20:37 +08:00
|
|
|
|
if (result == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (0, 0);
|
|
|
|
|
|
}
|
2024-11-17 20:28:38 +08:00
|
|
|
|
|
2024-11-07 10:58:06 +08:00
|
|
|
|
(int, int) tuple = (result.DispatchNum ?? 0, result.FinishedNum ?? 0);
|
2024-11-06 15:10:26 +08:00
|
|
|
|
return tuple;
|
|
|
|
|
|
}
|
2024-09-19 14:41:13 +08:00
|
|
|
|
|
2024-11-06 16:14:12 +08:00
|
|
|
|
public (DateTime, float) GetWorkOrderTime(string workorder)
|
2024-11-06 15:16:32 +08:00
|
|
|
|
{
|
2024-11-07 10:58:06 +08:00
|
|
|
|
var result = Context.Queryable<ProWorkorder>().Where(it => it.Workorder == workorder)
|
|
|
|
|
|
.Select(it => new { it.StartTime, it.Beat, it.DeliveryNum }).First();
|
|
|
|
|
|
|
2024-11-17 20:28:38 +08:00
|
|
|
|
(DateTime, float) tuple = (result.StartTime ?? DateTime.MinValue,
|
|
|
|
|
|
(result.Beat * result.DeliveryNum ?? 0) / 3600);
|
2024-11-06 15:16:32 +08:00
|
|
|
|
return tuple;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-14 16:47:47 +08:00
|
|
|
|
|
|
|
|
|
|
//查询工单下的扫描条码信息
|
|
|
|
|
|
public List<ProReportworkDetail> GetWorkOrderScanCodeInfo(string workorder)
|
|
|
|
|
|
{
|
2024-12-26 16:25:01 +08:00
|
|
|
|
return Context.Queryable<ProReportworkDetail>().SplitTable(tabs => tabs.Take(1)).Where(it => it.Workorder == workorder).ToList();
|
2024-11-14 16:47:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-17 20:28:38 +08:00
|
|
|
|
|
2025-12-10 19:05:52 +08:00
|
|
|
|
|
2024-11-17 20:28:38 +08:00
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据工单号 查询每个工单号进度
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="Workorder"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private MaterialPreparationProgress SearchMaterialPreparationProgress(string Workorder)
|
|
|
|
|
|
{
|
|
|
|
|
|
var progress = new MaterialPreparationProgress();
|
|
|
|
|
|
//TODO 查询工单总任务数
|
|
|
|
|
|
progress.WorkOrder = Workorder;
|
|
|
|
|
|
progress.Preparation_all_num = Context.Queryable<MmPreparationTask>()
|
|
|
|
|
|
.Where(it => it.FkWorkorder == Workorder)
|
|
|
|
|
|
.Count();
|
2024-09-19 15:39:51 +08:00
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
progress.Preparationed_num = Context.Queryable<MmPreparationTask>().Where(it => it.FkWorkorder == Workorder)
|
|
|
|
|
|
.Where(it => it.PreparationStatus == 2)
|
|
|
|
|
|
.Count();
|
|
|
|
|
|
if (progress.Preparationed_num == progress.Preparation_all_num)
|
|
|
|
|
|
progress.PreparationStatus = 2;
|
|
|
|
|
|
else if (progress.Preparationed_num < progress.Preparation_all_num) progress.PreparationStatus = 1;
|
2024-09-19 15:39:51 +08:00
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
if (progress.Preparation_all_num == 0) progress.PreparationStatus = 0;
|
2024-09-19 14:41:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-11-06 15:10:26 +08:00
|
|
|
|
return progress;
|
2024-09-19 09:34:54 +08:00
|
|
|
|
}
|
2025-04-10 16:51:14 +08:00
|
|
|
|
public bool SwitchWorkOrderCheckLabel(string pre_workorder)
|
|
|
|
|
|
{
|
|
|
|
|
|
var result = Context.Queryable<ProInspectionLabel>().Where(it => it.Workorder == pre_workorder)
|
|
|
|
|
|
.Select(it => it.EndLabel).First();
|
2025-12-10 19:05:52 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(result))
|
2025-04-10 16:51:14 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-11-06 15:10:26 +08:00
|
|
|
|
}
|