| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Threading; |
| | | using System.Timers; |
| | | using static Hanhe.iWCS.JingmenGEMTwoProtocol.MESHelper; |
| | | using static Hanhe.iWCS.JingmenGEMTwoProtocol.PLCControl; |
| | | using static Hanhe.iWCS.JingmenGEMTwoProtocol.ProcessHelper; |
| | | using static Hanhe.iWCS.JingmenGEMTwoProtocol.ProtocolAnalysis; |
| | | using static System.Runtime.CompilerServices.RuntimeHelpers; |
| | | |
| | | namespace Hanhe.iWCS.JingmenGEMTwoProtocol |
| | | { |
| | |
| | | /// </summary> |
| | | public int direction { get; set; } |
| | | } |
| | | |
| | | |
| | | public class bzxxModel |
| | | { |
| | | public string machineNo { get; set; } |
| | | public string mesCode { get; set; } |
| | | } |
| | | |
| | | |
| | | #region 教称流程,人工PDA返回复称平台,包装机复称信息 |
| | | |
| | |
| | | internal static ErrInfoResult getErrInfo(string factory) |
| | | { |
| | | ErrInfoResult result = new ErrInfoResult() { sucess = false }; |
| | | |
| | | if(factory == "sanyuan") |
| | | try |
| | | { |
| | | var errList = MongoDBSingleton.Instance.FindAll<errInfoTable>("ErrInfoResult"); |
| | | if (errList.Count > 0) |
| | | if (factory.Contains("sanyuan")) |
| | | { |
| | | result.sucess = true; |
| | | errList.ForEach(r => |
| | | var errList = MongoDBSingleton.Instance.FindAll<errInfoTable>("errInfoTable"); |
| | | if (errList.Count > 0) |
| | | { |
| | | result.errInfo.Add(new errInfo { taskName = r.taskName, errMsg = r.errMsg, time = r.dateTime }); |
| | | }); |
| | | result.sucess = true; |
| | | result.errInfo = new List<errInfo>(); |
| | | errList.ForEach(r => |
| | | { |
| | | result.errInfo.Add(new errInfo { taskName = r.taskName, errMsg = r.errMsg, time = r.dateTime }); |
| | | }); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | |
| | | } |
| | | } |
| | | else |
| | | catch(Exception ex) |
| | | { |
| | | |
| | | CMMLog.Info("getErrInfo err:"+ex.Message); |
| | | } |
| | | |
| | | |
| | | return result; |
| | | } |
| | |
| | | { |
| | | ZZTPWNumResult result = new ZZTPWNumResult() { sucess = false }; |
| | | |
| | | if(factory == "sanyuan") |
| | | if(factory.Contains("sanyuan")) |
| | | { |
| | | var bzEmpInfo = MongoDBSingleton.Instance.FindAll<BZEmptyPoint>("BZEmptyPoint"); |
| | | if (bzEmpInfo.Count > 0) |
| | | { |
| | | result.sucess = true; |
| | | result.zztpwInfo = new List<zztpwInfo>(); |
| | | bzEmpInfo.ForEach(r => |
| | | { |
| | | result.zztpwInfo.Add(new zztpwInfo { S_LOC_CODE = r.Bit, N_QTY = r.Quantity }); |
| | |
| | | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | internal static BZXXResult Bzxx(bzxxModel models) |
| | | { |
| | | BZXXResult result = new BZXXResult() {success = false }; |
| | | if(models != null && !string.IsNullOrEmpty(models.mesCode)) |
| | | { |
| | | //通过mesCode获取mes的物料信息 |
| | | var res = helper.WebGet(Settings.MESUrl2 + "?mesCode=" + models.mesCode); |
| | | CMMLog.Info($"Bzxx ReqMsg:{JsonConvert.SerializeObject(res)},url:{Settings.MESUrl2}"); |
| | | try |
| | | { |
| | | if (!string.IsNullOrEmpty(res)) |
| | | { |
| | | var req = JsonConvert.DeserializeObject<mesInfo>(res); |
| | | if(req != null) |
| | | { |
| | | if (req.isSuccess) |
| | | { |
| | | var timeCuo = MongoDBSingleton.Instance.FindOne<TimeCuoInfoCom>(Query.EQ("packingMachineNumber", models.machineNo), "TimeCuoInfoCom"); |
| | | if (timeCuo == null) |
| | | { |
| | | MongoDBSingleton.Instance.Insert<TimeCuoInfoCom>(new TimeCuoInfoCom |
| | | { |
| | | isFold = 1, |
| | | packingMachineNumber = models.machineNo, |
| | | needWeight = (int)req.data.FMustQty, |
| | | realWeight = (int)req.data.FMustQty, |
| | | totalWeight = (int)req.data.FMustQty, |
| | | batchNumber = req.data.Flot, |
| | | productModel = req.data.materialSpec, |
| | | bagNumber_1 = req.data.bagNum, |
| | | totalCount = 1, |
| | | timeStampMES = req.data.mesCode, |
| | | photoURL = req.data.barCode, |
| | | ProductionDate = req.data.ywDate, |
| | | // ERP变更-照相机新增字段 |
| | | materialCode = req.data.FMaterialNumber, |
| | | materialName = req.data.materialName, |
| | | measurementUnit = req.data.FUnit, |
| | | createOrganization = req.data.FPrdOrgNumber, |
| | | WarehouseCode = req.data.FStockNumber, |
| | | workshopCode = req.data.FWorkShopNumber, |
| | | BusinessDate = req.data.ywDate, |
| | | barcode = req.data.barCode, |
| | | |
| | | employeeID1 = req.data.jycjj, |
| | | |
| | | //变更注释 |
| | | totalNeedWeight = (int)req.data.FMustQty, |
| | | FEntryID_1 = 0, |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | var query = Query.EQ("packingMachineNumber", models.machineNo); |
| | | //变更注释 |
| | | UpdateBuilder update = Update.Set("isFold", 1).Set("packingMachineNumber", models.machineNo).Set("needWeight", (int)req.data.FMustQty) |
| | | .Set("realWeight", (int)req.data.FMustQty).Set("totalWeight", (int)req.data.FMustQty).Set("batchNumber", req.data.Flot) |
| | | .Set("productModel", req.data.materialSpec).Set("bagNumber_1", req.data.bagNum).Set("totalCount", 1).Set("timeStampMES", req.data.mesCode) |
| | | .Set("photoURL", req.data.barCode).Set("ProductionDate", req.data.ywDate).Set("materialCode", req.data.FMaterialNumber) |
| | | .Set("materialName", req.data.materialName).Set("measurementUnit", req.data.FUnit) |
| | | .Set("createOrganization", req.data.FPrdOrgNumber).Set("WarehouseCode", req.data.FStockNumber).Set("workshopCode", req.data.FWorkShopNumber) |
| | | .Set("BusinessDate", req.data.ywDate).Set("barcode", req.data.barCode).Set("employeeID1", req.data.jycjj) |
| | | .Set("totalNeedWeight", (int)req.data.FMustQty).Set("FEntryID_1", 0); |
| | | MongoDBSingleton.Instance.Update<TimeCuoInfoCom>(query, update, UpdateFlags.None); |
| | | } |
| | | |
| | | //生成到接驳平台的任务 |
| | | string traycode = DateTime.Now.ToString("yyyy-MM-dd").Replace("-", ""); |
| | | var CBInfo = Settings.GetConnectingbitsList().Where(a => a.enable == 1).ToList(); |
| | | if (CBInfo != null) |
| | | { |
| | | AMSHelper.HHAmsExecuteResult amsResult = null; |
| | | foreach (var a in CBInfo) |
| | | { |
| | | if (!string.IsNullOrEmpty(a.locCode)) |
| | | { |
| | | //在中间表中查找点位 |
| | | var CBTable = MongoDBSingleton.Instance.FindOne<ConnectingBits>(Query.EQ("Bit", a.locCode), "ConnectingBits"); |
| | | if (CBTable != null) |
| | | { |
| | | if (string.IsNullOrEmpty(CBTable.trayCode)) |
| | | { |
| | | //生成任务,并且将点位写入中间表 |
| | | amsResult = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), models.machineNo, a.locCode, "PDA打包下线", 0, traycode); |
| | | if (amsResult.success) |
| | | { |
| | | result.success = true; |
| | | CMMLog.Debug($"PDA打包下线:AMS调用API成功!"); |
| | | MongoDBSingleton.Instance.Update<ConnectingBits>(Query.EQ("Bit", a.locCode), Update.Set("trayCode", traycode).Set("timeCuo", req.data.mesCode), UpdateFlags.None); |
| | | |
| | | break; |
| | | } |
| | | else CMMLog.Debug($"PDA打包下线:AMS调用API失败,开始重新调用!"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //生成任务,并且将点位写入中间表 |
| | | amsResult = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), models.machineNo, a.locCode, "PDA打包下线", 0, traycode); |
| | | if (amsResult.success) |
| | | { |
| | | result.success = true; |
| | | CMMLog.Debug($"PDA打包下线:AMS调用API成功!"); |
| | | //打包下线任务生成成功,向中间表插入数据 |
| | | MongoDBSingleton.Instance.Insert<ConnectingBits>(new ConnectingBits { Bit = a.locCode, trayCode = traycode, state = "0", timeCuo = req.data.mesCode }); |
| | | |
| | | break; |
| | | } |
| | | else CMMLog.Debug($"PDA打包下线:AMS调用API失败,开始重新调用!"); |
| | | } |
| | | if (amsResult != null && amsResult.success) |
| | | { |
| | | //上报条码表 |
| | | CMMLog.Info($"INSERT INTO T_JY_BARCODESync (FBarCode, FBarCodeRule,FMaterialNumber,FCreateOrgNumber,FLot,FUnit,FQty,FStockNumber,FDept,FBillDate,F_JY_CZZ,FOpStatus) VALUES ('{req.data.barCode}','01','{req.data.materialName}','02','{req.data.Flot}','{req.data.FUnit}','{req.data.FMustQty}','CK020','BM000161','{req.data.ywDate}','{req.data.jycjj}','0')"); |
| | | new SqlHelper<object>().ExecuteSql($" INSERT INTO T_JY_BARCODESync (FBarCode, FBarCodeRule,FMaterialNumber,FCreateOrgNumber,FLot,FUnit,FQty,FStockNumber,FDept,FBillDate,F_JY_CZZ,FOpStatus) VALUES ('{req.data.barCode}','01','{req.data.materialName}','02','{req.data.Flot}','{req.data.FUnit}','{req.data.FMustQty}','CK020','BM000161','{req.data.ywDate}','{req.data.jycjj}','0')", false); |
| | | //var plc = Settings.GetPlcInfo().Where(b => b.location == models.machineNo && b.enable == 1).First(); |
| | | //if(plc != null) |
| | | //{ |
| | | // var wirteall01 = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel |
| | | // { |
| | | // addr = plc.writeAddr, |
| | | // host = plc.ip, |
| | | // port = plc.port, |
| | | // data = 4 |
| | | // }); |
| | | //} |
| | | |
| | | } |
| | | } |
| | | else CMMLog.Debug("打包下线口接驳位点位未配置"); |
| | | } |
| | | if (amsResult == null || amsResult.success == false) |
| | | { |
| | | result.errMsg = "任务生成失败,接驳位有任务占用"; |
| | | } |
| | | } |
| | | else CMMLog.Debug("打包下线口接驳位未配置"); |
| | | } |
| | | else |
| | | { |
| | | result.errMsg = req.msg; |
| | | } |
| | | |
| | | } |
| | | else |
| | | { |
| | | result.errMsg = $"数据解析失败"; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | result.errMsg = $"查询mes信息失败,mesCode:{models.mesCode}"; |
| | | } |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | result.errMsg = ex.Message; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | result.errMsg = "参数输入错误"; |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 电钴车间包装下线获取wms传入的托盘 |
| | | /// </summary> |
| | | /// <param name="trayCode"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="NotImplementedException"></exception> |
| | | internal static SimpleResult DGPackingLineFull(string trayCode) |
| | | { |
| | | SimpleResult result = new SimpleResult() { success = false,errCode = -1 }; |
| | | |
| | | if (!string.IsNullOrEmpty(trayCode)){ |
| | | var DGInfo = MongoDBSingleton.Instance.FindOne<DGPackingLineFullModel>(Query.EQ("trayCode", trayCode), "DGPackingLineFullModel"); |
| | | if (DGInfo == null) |
| | | { |
| | | MongoDBSingleton.Instance.Insert<DGPackingLineFullModel>(new DGPackingLineFullModel() { trayCode = trayCode, createTime = DateTime.Now }, "DGPackingLineFullModel"); |
| | | result.success = true; |
| | | result.errCode = 0; |
| | | } |
| | | else |
| | | { |
| | | result.errMsg = $"当前托盘号,已存在于ams中间表中,托盘号:{trayCode}"; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | result.errMsg = $"当前托盘号为空"; |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | public class mesInfo |
| | | { |
| | | public int code { get; set; } |
| | | public string msg { get; set; } |
| | | public mesData data { get; set; } |
| | | public bool isSuccess { get; set; } |
| | | } |
| | | |
| | | public class mesData |
| | | { |
| | | /// <summary> |
| | | /// 入库组织 |
| | | /// </summary> |
| | | public string FStockOrgNumber { get; set;} |
| | | /// <summary> |
| | | /// 生产组织 |
| | | /// </summary> |
| | | public string FPrdOrgNumber { get; set; } |
| | | /// <summary> |
| | | /// 入库类型 |
| | | /// </summary> |
| | | public string FInStockType { get; set; } |
| | | /// <summary> |
| | | /// 仓库编码 |
| | | /// </summary> |
| | | public string FStockNumber { get; set; } |
| | | /// <summary> |
| | | /// 生产车间 |
| | | /// </summary> |
| | | public string FWorkShopNumber { get; set; } |
| | | /// <summary> |
| | | /// 库存状态 |
| | | /// </summary> |
| | | public string FStockStatus { get; set; } |
| | | /// <summary> |
| | | /// 单位 |
| | | /// </summary> |
| | | public string FUnit { get; set; } |
| | | /// <summary> |
| | | /// 物料编码 |
| | | /// </summary> |
| | | public string FMaterialNumber { get; set; } |
| | | /// <summary> |
| | | /// 物料名称 |
| | | /// </summary> |
| | | public string materialName { get; set; } |
| | | /// <summary> |
| | | /// 物料规格 |
| | | /// </summary> |
| | | public string materialSpec { get; set; } |
| | | /// <summary> |
| | | /// 批号 |
| | | /// </summary> |
| | | public string Flot { get; set; } |
| | | /// <summary> |
| | | /// 需求重量 |
| | | /// </summary> |
| | | public double FMustQty { get; set; } |
| | | /// <summary> |
| | | /// 退库时间 |
| | | /// </summary> |
| | | public string FProduceDate { get; set; } |
| | | /// <summary> |
| | | /// 唯一标识 |
| | | /// </summary> |
| | | public string FExpiryDate { get; set; } |
| | | /// <summary> |
| | | /// 唯一码 |
| | | /// </summary> |
| | | public string mesCode { get; set; } |
| | | /// <summary> |
| | | /// 完整条码 |
| | | /// </summary> |
| | | public string barCode { get; set; } |
| | | /// <summary> |
| | | /// 袋号 |
| | | /// </summary> |
| | | public string bagNum { get; set; } |
| | | /// <summary> |
| | | /// mes包号 |
| | | /// </summary> |
| | | public string bagCode { get; set; } |
| | | /// <summary> |
| | | /// 员工编码 |
| | | /// </summary> |
| | | public string jycjj { get; set; } |
| | | /// <summary> |
| | | /// 业务日期 |
| | | /// </summary> |
| | | public string ywDate { get; set; } |
| | | } |
| | | |
| | | public class AGV_STATE |
| | |
| | | /// 是否有货 |
| | | /// </summary> |
| | | public int haveItem { get; set; } |
| | | } |
| | | |
| | | public class DGPackingLineFullModel |
| | | { |
| | | public ObjectId _id { get; set; } |
| | | public string trayCode { get; set; } |
| | | public string isUse { get; set; } = "0"; |
| | | public DateTime createTime { get; set; } |
| | | } |
| | | |
| | | public class secondResultCache |
| | |
| | | public int N_QTY { get; set; } |
| | | } |
| | | |
| | | public class BZXXResult |
| | | { |
| | | public bool success { get; set;} |
| | | public string errMsg { get; set; } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// hosttoagv上报车辆状态(参数在hosttoagv服务配置,可修改) |
| | | /// </summary> |