| | |
| | | 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 |
| | | { |
| | |
| | | |
| | | public class bzxxModel |
| | | { |
| | | public string machineNo { get; set; } |
| | | public string mesCode { get; set; } |
| | | } |
| | | |
| | |
| | | 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 }); |
| | |
| | | |
| | | internal static BZXXResult Bzxx(bzxxModel models) |
| | | { |
| | | BZXXResult result = new BZXXResult() {sucess = false }; |
| | | 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) |
| | | { |
| | | 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, |
| | | timeStamp = 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("timeStamp", 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("-", ""); |
| | | string timeCuo2 = req.data.mesCode.ToString(); |
| | | 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", timeCuo2), UpdateFlags.None); |
| | | |
| | | //上报条码表 |
| | | 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); |
| | | |
| | | 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 = timeCuo2 }); |
| | | |
| | | //上报条码表 |
| | | 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); |
| | | |
| | | break; |
| | | } |
| | | else CMMLog.Debug($"PDA打包下线:AMS调用API失败,开始重新调用!"); |
| | | } |
| | | } |
| | | else CMMLog.Debug("打包下线口接驳位点位未配置"); |
| | | } |
| | | if(amsResult == null || amsResult.success == false) |
| | | { |
| | | result.errMsg = "任务生成失败,接驳位有任务占用"; |
| | | } |
| | | } |
| | | else CMMLog.Debug("打包下线口接驳位未配置"); |
| | | } |
| | | else |
| | | { |
| | | result.errMsg = $"数据解析失败"; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | result.errMsg = $"查询mes信息失败,mesCode:{models.mesCode}"; |
| | | } |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | result.errMsg = ex.Message; |
| | | } |
| | | } |
| | | 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 isSucess { 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 int 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 |
| | |
| | | |
| | | public class BZXXResult |
| | | { |
| | | public bool sucess { get; set;} |
| | | public bool success { get; set;} |
| | | public string errMsg { get; set; } |
| | | } |
| | | |