using Cksoft.Data; using Cksoft.Data.Repository; using Cksoft.Unity; using DllEapCommon.Notice; using DllEapDal; using DllEapDal.OFILM; using DllEapDal.OFILM.MES; using DllEapDal.Onsemi; using DllEapEntity; using DllEapEntity.Onsemi; using DllEapEntity.Rms; using DllHsms; using DllSocketFile; using DllStatusShowDal; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using RabbitMQ.Client; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using WebStatusToolkit.Notice; namespace WebStatusToolkit { public class CallFunction { private static string mesApiPrefix = AppConfigurtaionServices.Configuration["mesApiPrefix"]; //public static string MesApiPrefix //{ // get // { // if (string.IsNullOrEmpty(mesApiPrefix)) // mesApiPrefix = AppConfigurtaionServices.Configuration["mesApiPrefix"]; // return mesApiPrefix; // } //} // private static string mesApiPrefix = "http://192.168.51.100:8080/ofilm/eap/"; public static string CurrDbCode = "eap"; public static string ReadDbCode = "eapslave"; public static MacStatus CallIMacStatus(IModel channel, MacStatus entity, string usercode, ref string errorinfo) { IDatabase CurrDb = null; try { // entity.ProgramName = AppConfigurtaionServices.Configuration["SystemCode"]; CurrDb = DbFactory.Base(CurrDbCode); CurrDb.BeginTrans(); MacStatusDal tempdal = new MacStatusDal(CurrDb); MacStatus laststatus = tempdal.GetLastStatus(entity.MacCode, ref errorinfo); // 当机台的上一个状态是待机程序上传的并且该状态还未结束时,应等待待机程序解除状态, // 未解除时从队列上获取到的新状态不再插入数据库 //if (laststatus != null && laststatus.ETime.ToString("yyyy-MM-dd HH:mm:ss") == "0001-01-01 00:00:00" // && (laststatus.ProgramName == "待机程序" || laststatus.ProgramName == "EAPWeb程序") && (laststatus.StatusID == 10 || // laststatus.StatusID > 200000) && entity.ProgramName != "待机程序" // && entity.ProgramName != "EAPWeb程序") if (laststatus != null && laststatus.IsCover == -1 && entity.ProgramName != "待机程序" && entity.ProgramName != "EAPWeb程序") { errorinfo = $"当前机台【{laststatus.MacCode}】的前一状态为【{laststatus.StatusFName}】且该状态未解除," + $"该状态已被配置为不可覆盖," + $"不再插入队列中的新状态"; return null; } if (laststatus != null && laststatus.StatusID == 204906 && entity.StatusID == 1) { errorinfo = $"当前机台【{laststatus.MacCode}】的前一状态为【{laststatus.StatusFName}】且该状态未解除," + $"且当前状态为离线," + $"不再插入队列中的新状态"; return null; } if (laststatus != null) { if (string.IsNullOrEmpty(entity.Remark)) { if (!string.IsNullOrEmpty(laststatus.Remark) && laststatus.Remark != "\0") { entity.Remark = laststatus.Remark; } else { var recipeS = CurrDb.FindListForCondition($" and a.Maccode='{entity.MacCode}' " + $"and a.remark is not null and a.remark !='\0'", ref errorinfo).FirstOrDefault(); if (recipeS != null) { entity.Remark = recipeS.Remark; } } } } //插入最后状态 int result = tempdal.AddMacStatus01(entity, usercode, ref errorinfo); if (result <= 0) { errorinfo = $"添加MacStatus01发生错误:{errorinfo}"; return null; } if (laststatus != null)//说明最后的状态与当前状态相同,直接返回 { if (laststatus.Remark != entity.Remark) { laststatus.Remark = entity.Remark; if (CurrDb.UpdateFor(laststatus, usercode) < 0) { errorinfo = $"机台【{laststatus.MacCode}】更新机种信息【{entity.Remark}】失败"; return null; } if (NeedUpdateRecipe(laststatus.Remark, entity.Remark)) { PushStatusData(channel, CurrDb, entity, errorinfo); } } if (laststatus.StatusID == entity.StatusID) { if (entity.StatusID == 6) { if (entity.AlarmCode == "SVID") { return entity; } else { int alarmTimeSpan = Convert.ToInt32(AppConfigurtaionServices.Configuration["SVIDTimeSpan"]); if (laststatus.AlarmCode == "0000") { if ((entity.STime - laststatus.STime).TotalSeconds <= alarmTimeSpan) { var res = tempdal.UpdateLastSvidAlarm(laststatus, entity, string.Empty, ref errorinfo); if (res == null) { CurrDb.Rollback(); return null; } } } else { entity = tempdal.IMacStatus(entity, usercode, ref errorinfo, true); if (entity == null) { CurrDb.Rollback(); return null; } PushStatusData(channel, CurrDb, entity, errorinfo); CurrDb.Commit(); return entity; } } } // 当上一个状态与当前状态间隔时间大于5分钟时 结束上个状态,插入当前状态 if ((entity.STime - laststatus.STime).TotalMinutes > 5) { entity = tempdal.IMacStatus(entity, usercode, ref errorinfo, false); if (entity == null) { CurrDb.Rollback(); return null; } } CurrDb.Commit(); return entity; } else { if (entity.AlarmCode == "SVID") { entity.AlarmCode = "0000"; entity.AlarmDescribe = "No Description Alarm"; } } } else { if (entity.AlarmCode == "SVID") { entity.AlarmCode = "0000"; entity.AlarmDescribe = "No Description Alarm"; } } entity = tempdal.IMacStatus(entity, usercode, ref errorinfo, true); if (entity == null) { CurrDb.Rollback(); return null; } PushStatusData(channel, CurrDb, entity, errorinfo); CurrDb.Commit(); // 调用蓝信接口发送断线通知给相关人员 if (entity.StatusID == 1 && AppConfigurtaionServices.Configuration["Client"] != null && AppConfigurtaionServices.Configuration["Client"] == "Ofilm") { var machine = CurrDb.FindListForCondition($" and a.fcode='{entity.MacCode}'", ref errorinfo).FirstOrDefault(); //if (machine.FactoryId == 8) //{ Task.Run(() => { string error = string.Empty; OfilmLanxinNoticeService.NoticeDisconn(machine, entity, error); }); //} } return entity; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return null; } finally { if (CurrDb != null) CurrDb.Close(); } } /// /// 程序参数比较 /// /// /// /// /// //public static int CompareParams(string maccode,string usercode, ref string errorinfo) //{ // IDatabase CurrDb = null; // try // { // CurrDb = DbFactory.Base(CurrDbCode); // CurrDb.BeginTrans(); // //读取机台信息 // string condition = $" and a.FCode='{maccode}'"; // Machine mac = CurrDb.FindListForCondition(condition, ref errorinfo).ToList()[0]; // if (mac.IsControl <= 0) // { // //说明此机台没有开启参数比对功能,无需比对 // CurrDb.Commit(); // return 1; // } // //string programname = (string)imputds["programname"]; // ParamsComMstDal comdal = new ParamsComMstDal(CurrDb); // //string programname = comdal.GetMacProgram(maccode, ref errorinfo); // //if (string.IsNullOrEmpty(programname)) // //{ // // errorinfo = $"未找到机台【{maccode}】对应的程序。{errorinfo}"; // // CurrDb.Rollback(); // // return -1; // //} // ProgramMst programmst = comdal.GetMacProgram(mac, ref errorinfo); // if (programmst==null) // { // errorinfo = $"未找到机台【{maccode}】对应的程序。{errorinfo}"; // CurrDb.Rollback(); // return -1; // } // //比较文件参数 // ParamsComMst mst = comdal.CompareParams(mac, programmst, ref errorinfo); // if (mst == null) // { // errorinfo = $"未找到机台【{maccode}】程序【{programmst.FName}】对应的比对主档。{errorinfo}"; // CurrDb.Rollback(); // return -1; // } // //插入比对记录 // mst = comdal.IUParamsComMst(mst, usercode, ref errorinfo); // if (mst == null) // { // errorinfo = $"插入比对结果发生错误:{errorinfo}"; // CurrDb.Rollback(); // return -1; // } // CurrDb.Commit(); // //如果参数不对,就发送停机指令 // if (mst.IsPass <= 0) // { // int result = comdal.SendStopMac(maccode, ref errorinfo); // if (result <= 0) // { // errorinfo = $"发送停机指令发生错误,错误信息为:{errorinfo}"; // return -1; // } // } // return 1; // } // catch (Exception ex) // { // errorinfo = ex.Message.ToString(); // CurrDb.Rollback(); // return -1; // } // finally // { // if (CurrDb != null) // CurrDb.Close(); // } //} //public static int CompareParams(string maccode, string usercode, ref string errorinfo) //{ // IDatabase CurrDb = null; // try // { // CurrDb = DbFactory.Base(CurrDbCode); // CurrDb.BeginTrans(); // MacOrderSendDal macdal = new MacOrderSendDal(CurrDb); // Machine mac = macdal.ReadMachine(maccode, ref errorinfo); // if (mac == null) // { // //string logerrorinfo = ""; // //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"读取机台错误:{errorinfo}", ref logerrorinfo); // CurrDb.Rollback(); // return -1; // } // if(mac.SupplierFCode.ToLower()=="kns") // { // List datas = macdal.SendOrder(mac, 2, 15, "s2f15", ref errorinfo); // } // string partcode = MesDal.GetProductCode(maccode, ref errorinfo); // if (!string.IsNullOrEmpty(errorinfo)) // { // errorinfo = $"从MES中获取产品发生错误,错误信息为:{errorinfo}"; // return -1; // } // //没有找到产品编号,说明没有正在进行的任务,直接返回 // if (string.IsNullOrEmpty(partcode)) // return 1; // ProgramDal programdal = new ProgramDal(CurrDb); // ProgramMst programmst = programdal.FindProgram(mac, partcode, mac.PCode, ref errorinfo); // if (programmst == null) // { // //string logerrorinfo = ""; // //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"查找程序错误:{errorinfo}", ref logerrorinfo); // CurrDb.Rollback(); // return -1; // } // ParamsComMst mst = null; // //比较机台程序名称 // ParamsComMstDal comdal = new ParamsComMstDal(CurrDb); // string programname = comdal.GetMacProgramName(mac, ref errorinfo); // if(programmst.FName!=programname) // { // //errorinfo = $"当前产品{partcode}使用的程序为{programmst.FName},而实际程序名称为{programname}"; // //CurrDb.Rollback(); // //return -1; // mst = new ParamsComMst(); // mst.MacID = mac.ID; // mst.ProgramID = programmst.ID; // mst.IsPass = -1; // mst.Remark = $"当前产品{partcode}使用的程序为{programmst.FName},而实际程序名称为{programname}"; // mst.CurrDetails = new List(); // } // else // { // //比对程序参数 // mst = comdal.CompareParams(mac, programmst, ref errorinfo); // if (mst == null) // { // errorinfo = $"未找到机台【{maccode}】程序【{programmst.FName}】对应的比对主档。{errorinfo}"; // CurrDb.Rollback(); // return -1; // } // } // //插入比对记录 // mst = comdal.IUParamsComMst(mst, usercode, ref errorinfo); // if (mst == null) // { // errorinfo = $"插入比对结果发生错误:{errorinfo}"; // CurrDb.Rollback(); // return -1; // } // CurrDb.Commit(); // //如果参数不对,就发送停机指令 // if (mst.IsPass <= 0) // { // MacOrderDal macorderdal = new MacOrderDal(CurrDb); // int result = macorderdal.SendStopMac(maccode, ref errorinfo); // if (result <= 0) // { // errorinfo = $"发送停机指令发生错误,错误信息为:{errorinfo}"; // return -1; // } // } // return 1; // } // catch (Exception ex) // { // errorinfo =ex.Message.ToString(); // CurrDb.Rollback(); // return -1; // } // finally // { // if (CurrDb != null) // CurrDb.Close(); // } //} // 判断是否需要推送更新机种信息给BI private static bool NeedUpdateRecipe(string lastRemark, string currentRemark) { if (string.IsNullOrEmpty(currentRemark)) return false; if (string.IsNullOrEmpty(lastRemark)) return true; var separators = new char[] { ' ', '-', '_', '.' }; var oldRecipe = lastRemark.Split(separators).FirstOrDefault(); var newRecipe = lastRemark.Split(separators).FirstOrDefault(); return oldRecipe != newRecipe; } private static void PushStatusData(IModel channel, IDatabase db, MacStatus entity, string errorinfo) { if (AppConfigurtaionServices.Configuration["CallMesInterface"] != null && Convert.ToBoolean(AppConfigurtaionServices.Configuration["CallMesInterface"])) { channel.QueueDeclare("BIStatus", false, false, false, null); byte[] queuedata = EntityHelper.SerializeBytes(entity); channel.BasicPublish("", "BIStatus", null, queuedata); //var biDal = new BICollectDal(db); //biDal.PushStatusToBI(new List() { entity }, errorinfo); } } public static int CompareParams(string maccode, string usercode, ref string errorinfo) { IDatabase CurrDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); CurrDb.BeginTrans(); #region 注销代码 // MacOrderSendDal macdal = new MacOrderSendDal(CurrDb); // Machine mac = macdal.ReadMachine(maccode, ref errorinfo); // if (mac == null) // { // //string logerrorinfo = ""; // //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"读取机台错误:{errorinfo}", ref logerrorinfo); // CurrDb.Rollback(); // return -1; // } // if(mac.IsControl<=0) // { // CurrDb.Rollback(); // return 1; // } //if(mac.MModeCode.ToLower()=="dad3350") // { // Dad3350ProgramDal dal = new Dad3350ProgramDal(CurrDb); // int result = dal.CompareParams(mac, "", ref errorinfo); // if(result<=0) // { // CurrDb.Commit(); // return -1; // } // } // if (mac.MModeCode.ToLower() == "dfd6341") // { // Dfd6341ProgramDal dal = new Dfd6341ProgramDal(CurrDb); // int result = dal.CompareParams(mac, "", ref errorinfo); // if (result <= 0) // { // CurrDb.Commit(); // return -1; // } // } #endregion string logerrorinfo = ""; WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"开始比对参数", ref logerrorinfo); int result = CompareParamsFor(CurrDb, maccode, usercode, ref errorinfo); CurrDb.Commit(); WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"比对参数结束:{errorinfo}", ref logerrorinfo); if (result <= 0) { WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"比对参数失败001:{errorinfo}", ref logerrorinfo); string temperrorinfo = ""; MacOrderSendDal macorderdal = new MacOrderSendDal(CurrDb); #region 台湾亿光停机 if (AppConfigurtaionServices.Configuration["Client"] != null && AppConfigurtaionServices.Configuration["Client"].ToLower() == "everlight") { Machine mac = macorderdal.ReadMachine(maccode, ref temperrorinfo); EverLightStopMac stopMac = new EverLightStopMac(); stopMac.StopMac(maccode, mac.IPAddress); result = macorderdal.SendS10F3(maccode, "Parameter comparison failed", ref temperrorinfo); if (result <= 0) { //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"给机台发送消息失败:{errorinfo}", ref logerrorinfo); errorinfo = $"{errorinfo},{temperrorinfo}"; } } #endregion else { result = macorderdal.SendStopMac(maccode, ref temperrorinfo); if (result <= 0) { errorinfo = $"发送停机指令发生错误,错误信息为:{errorinfo},{temperrorinfo}"; //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"发送停止指令失败:{errorinfo}", ref logerrorinfo); return -1; } result = macorderdal.SendS10F3(maccode, "Parameter comparison failed", ref temperrorinfo); if (result <= 0) { //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"给机台发送消息失败:{errorinfo}", ref logerrorinfo); errorinfo = $"{errorinfo},{temperrorinfo}"; } //string client = AppConfigurtaionServices.Configuration["Client"]; string resume = AppConfigurtaionServices.Configuration["Resume"]; if (int.Parse(resume) > 0) { //发送resume指令 macorderdal.SendResumeMac(maccode, ref temperrorinfo); } } return -1; } WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"参数比对完成", ref logerrorinfo); return 1; } catch (Exception ex) { errorinfo = $"比对参数发生异常:{ex.Message.ToString()}"; return -1; } finally { if (CurrDb != null) CurrDb.Close(); } } public static int CompareParamsForOfilm(string maccode, string usercode, ref string errorinfo) { var callMesInterface = AppConfigurtaionServices.Configuration["CallMesInterface"]; if (callMesInterface == null || !Convert.ToBoolean(callMesInterface)) { return 1; } try { //调用欧菲MES运行接口 string url = $"{mesApiPrefix}equipmentStartUp"; var paras = new Dictionary(); paras.Add("equipmentID", maccode); var response = HttpRequestHelper.Get(url, paras, ref errorinfo); errorinfo = $"调用欧非MES设备运行接口equipmentStartUp,传入的参数:{JsonConvert.SerializeObject(paras)}," + $"接收到的值为:{JsonConvert.SerializeObject(response)}"; return 1; } catch (Exception ex) { errorinfo = $"比对参数发生异常:{ex.Message.ToString()}"; return -1; } finally { } } public static int CompareParamsFor(IDatabase CurrDb, string maccode, string usercode, ref string errorinfo) { try { MacOrderSendDal macdal = new MacOrderSendDal(CurrDb); Machine mac = macdal.ReadMachine(maccode, ref errorinfo); if (mac == null) { //string logerrorinfo = ""; //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"读取机台错误:{errorinfo}", ref logerrorinfo); return -1; } if (mac.IsControl <= 0) { return 1; } int result = 0; switch (mac.MModeCode.ToLower()) { case "dad3350": Dad3350ProgramDal dal = new Dad3350ProgramDal(CurrDb); result = dal.CompareParams(mac, "", ref errorinfo); if (result <= 0) { return -1; } return 1; case "dfd6341": Dfd6341ProgramDal dal6341 = new Dfd6341ProgramDal(CurrDb); result = dal6341.CompareParams(mac, "", ref errorinfo); if (result <= 0) { return -1; } return 1; case "dad3650": case "dfd6362": Dad3650ProgramDal dal3650 = new Dad3650ProgramDal(CurrDb); result = dal3650.CompareParams(mac, "", ref errorinfo); if (result <= 0) { return -1; } return 1; case "dfg8540": BgProgramDal bgdal = new BgProgramDal(CurrDb); result = bgdal.CompareParams(mac, "", ref errorinfo); if (result <= 0) { return -1; } return 1; default: string logerrorinfo = ""; WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"开始比对ASM参数......", ref logerrorinfo); Ad830PlusProgramDal tempdal = new Ad830PlusProgramDal(CurrDb); result = tempdal.CompareParams(mac, "", ref errorinfo); if (result <= 0) { WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"ASM参数比对失败{errorinfo}", ref logerrorinfo); return -1; } return 1; } } catch (Exception ex) { errorinfo = ex.Message.ToString(); return -1; } } //public static int CompareParams(string maccode, string usercode, ref string errorinfo) //{ // IDatabase CurrDb = null; // try // { // CurrDb = DbFactory.Base(CurrDbCode); // CurrDb.BeginTrans(); // MacOrderSendDal macdal = new MacOrderSendDal(CurrDb); // Machine mac = macdal.ReadMachine(maccode, ref errorinfo); // if (mac == null) // { // //string logerrorinfo = ""; // //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"读取机台错误:{errorinfo}", ref logerrorinfo); // CurrDb.Rollback(); // return -1; // } // if (mac.IsControl <= 0) // { // CurrDb.Rollback(); // return 1; // } // if (mac.MModeCode.ToLower() == "dad3350") // { // Dad3350ProgramDal dal = new Dad3350ProgramDal(CurrDb); // int result = dal.CompareParams(mac, "", ref errorinfo); // if (result <= 0) // { // CurrDb.Commit(); // return -1; // } // } // if (mac.MModeCode.ToLower() == "dfd6341") // { // Dfd6341ProgramDal dal = new Dfd6341ProgramDal(CurrDb); // int result = dal.CompareParams(mac, "", ref errorinfo); // if (result <= 0) // { // CurrDb.Commit(); // return -1; // } // } // return 1; // } // catch (Exception ex) // { // errorinfo = ex.Message.ToString(); // CurrDb.Rollback(); // return -1; // } // finally // { // if (CurrDb != null) // CurrDb.Close(); // } //} /// /// /// 文件参数比较 /// /// /// /// /// public static int CompareFileParams(string maccode, string usercode, ref string errorinfo) { IDatabase CurrDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); CurrDb.BeginTrans(); //读取机台信息 string condition = $" and a.FCode='{maccode}'"; Machine mac = CurrDb.FindListForCondition(condition, ref errorinfo).ToList()[0]; if (mac.IsControl <= 0) { //说明此机台没有开启参数比对功能,无需比对 CurrDb.Commit(); return 1; } if (mac.SupplierFCode != "KNS") { //只有KNS机台才开启文件比对 CurrDb.Commit(); return 1; } //string programname = (string)imputds["programname"]; ParamsComMstDal comdal = new ParamsComMstDal(CurrDb); ProgramMst programmst = comdal.GetMacProgram(mac, ref errorinfo); if (programmst == null) { errorinfo = $"未找到机台【{maccode}】对应的程序。{errorinfo}"; CurrDb.Rollback(); return -1; } //从机台上读取文件并保存 string programdir = AppConfigurtaionServices.Configuration["ProgramDir"]; KnsProgramDal knsdal = new KnsProgramDal(CurrDb); MacProgram macprogram = knsdal.SaveProgramFromMac(mac, programmst.FName, programdir, ref errorinfo); if (macprogram == null) { CurrDb.Rollback(); return -1; } CurrDb.Commit();//先提交保存程序文件记录 CurrDb.BeginTrans(); //比较文件参数 FileParamsComMst mst = comdal.CompareFileParams(mac, programmst, macprogram, ref errorinfo); if (mst == null) { errorinfo = $"未找到机台【{maccode}】程序【{programmst.FName}】对应的比对主档。{errorinfo}"; CurrDb.Rollback(); return -1; } //插入比对记录 mst = comdal.IUFileParamsComMst(mst, usercode, ref errorinfo); if (mst == null) { errorinfo = $"插入比对结果发生错误:{errorinfo}"; CurrDb.Rollback(); return -1; } CurrDb.Commit(); //如果参数不对,就发送停机指令 if (mst.IsPass <= 0) { MacOrderDal macorderdal = new MacOrderDal(CurrDb); int result = macorderdal.SendStopMac(maccode, ref errorinfo); if (result <= 0) { errorinfo = $"发送停机指令发生错误,错误信息为:{errorinfo}"; return -1; } } return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); CurrDb.Rollback(); return -1; } finally { if (CurrDb != null) CurrDb.Close(); } } public static int UpProgram(OrderBlock entitys, string filedir, string usercode, ref string errorinfo) { IDatabase CurrDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); CurrDb.BeginTrans(); string temperrorinfo1 = ""; MacOrderSendDal senddal1 = new MacOrderSendDal(CurrDb); //上传文件 string programname = ""; int result = UpProgram(CurrDb, entitys, filedir, usercode, ref programname, ref errorinfo); if (result == -100) { //提示机台只能上传当前运行的程序 senddal1.SendS10F3(entitys.MainMsg.McaCode, $"Upload recipe fail,Please check Loading again.", ref temperrorinfo1); CurrDb.Rollback(); return result; } if (result <= 0) { senddal1.SendS10F3(entitys.MainMsg.McaCode, $" Recipe upload fail {programname}", ref temperrorinfo1); CurrDb.Rollback(); return result; } //调MES上传程序接口 //string actionName = "uploadRecipe"; //string fullUrl = mesApiPrefix + actionName; //IDictionary dic = new Dictionary(); //dic.Add("equipmentID", entitys.MainMsg.McaCode); //dic.Add("recipeName", programname); //dic.Add("version", result.ToString()); //var response = HttpRequestHelper.Get(fullUrl, dic, ref errorinfo); //errorinfo = $"调用MES上传程序接口:uploadRecipe,传入的参数:{JsonConvert.SerializeObject(dic)}," + // $"接收到的值为:{JsonConvert.SerializeObject(response)}"; senddal1.SendS10F3(entitys.MainMsg.McaCode, $" Recipe upload success {programname}", ref temperrorinfo1); CurrDb.Commit(); CallMesuploadRecipe(entitys.MainMsg.McaCode, programname, result, ref errorinfo); return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); CurrDb.Rollback(); return -1; } finally { if (CurrDb != null) CurrDb.Close(); } } /// /// 文件方式上传程序 /// /// /// /// /// /// public static int UpProgramForFile(OrderBlock entitys, string filedir, string usercode, ref string errorinfo) { IDatabase CurrDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); CurrDb.BeginTrans(); string temperrorinfo1 = ""; MacOrderSendDal senddal1 = new MacOrderSendDal(CurrDb); //剔除WB机型 string checkMachineForWB = string.Format($"SELECT COUNT(1) from machine WHERE MModeID in('14','184','187') and FCode='{entitys.MainMsg.McaCode}' "); int resultCheck = CurrDb.ExecuteBySql(checkMachineForWB); if (resultCheck > 0) return 1; //上传文件 string programname = ""; int result = UpProgramForFile(CurrDb, entitys, filedir, usercode, ref programname, ref errorinfo); //CallMesuploadRecipe(entitys.MainMsg.McaCode, programname, result, ref errorinfo); if (result == -100) { //提示机台只能上传当前运行的程序 senddal1.SendS10F3(entitys.MainMsg.McaCode, $"Upload recipe fail,Please check Loading again.", ref temperrorinfo1); CurrDb.Rollback(); return result; } if (result <= 0) { senddal1.SendS10F3(entitys.MainMsg.McaCode, $" Recipe upload fail {programname}", ref temperrorinfo1); CurrDb.Rollback(); return result; } senddal1.SendS10F3(entitys.MainMsg.McaCode, $" Recipe upload success {programname}", ref temperrorinfo1); CurrDb.Commit(); //调MES上传程序接口 //string actionName = "uploadRecipe"; //string fullUrl = mesApiPrefix + actionName; //IDictionary dic = new Dictionary(); //dic.Add("equipmentID", entitys.MainMsg.McaCode); //dic.Add("recipeName", programname); //dic.Add("version", result.ToString()); //var response = HttpRequestHelper.Get(fullUrl, dic, ref errorinfo); //errorinfo = $"调用MES上传程序接口:uploadRecipe,传入的参数:{JsonConvert.SerializeObject(dic)}," + // $"接收到的值为:{JsonConvert.SerializeObject(response)}"; CallMesuploadRecipe(entitys.MainMsg.McaCode, programname, result, ref errorinfo); return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); CurrDb.Rollback(); return -1; } finally { if (CurrDb != null) CurrDb.Close(); } } private static int CallMesuploadRecipe(string maccode, string programname, int version, ref string errorinfo) { var callMesInterface = AppConfigurtaionServices.Configuration["CallMesInterface"]; if (callMesInterface == null || !Convert.ToBoolean(callMesInterface)) { return 1; } try { //处理程序名称,传给MES的程序名称不能含.RCP扩展名称 if (programname.Length > 4) { string extname = programname.Substring(programname.Length - 4, 4); if (extname == ".rcp") programname = programname.Substring(0, programname.Length - 4); } string actionName = "uploadRecipe"; string fullUrl = mesApiPrefix + actionName; IDictionary dic = new Dictionary(); dic.Add("equipmentID", maccode); dic.Add("recipeName", programname); dic.Add("version", version.ToString()); var response = HttpRequestHelper.Get(fullUrl, dic, ref errorinfo); errorinfo = $"调用MES上传程序接口:{fullUrl},传入的参数:{JsonConvert.SerializeObject(dic)}," + $"接收到的值为:{JsonConvert.SerializeObject(response)}"; return 1; } catch (Exception ex) { errorinfo = ex.ToString(); return -1; } } public static int ClearProgram(OrderBlock entitys, string usercode, ref string errorinfo) { IDatabase CurrDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); CurrDb.BeginTrans(); string condition = $" and a.FCode='{entitys.MainMsg.McaCode}'"; List macs = CurrDb.FindListForCondition(condition, ref errorinfo).ToList(); if (macs[0].IsRemoveProgram <= 0) { errorinfo = $"机台【{entitys.MainMsg.McaCode}】设置为不清除程序。"; return -1; } int result = 0; switch (macs[0].MModeCode.ToLower()) { case "dad3350"://未测试 case "dfd6340-wash": case "dfd6341-wash": case "dfd6341": case "dfd6340": Dad3350ProgramDal dad3350 = new Dad3350ProgramDal(CurrDb); if (AppConfigurtaionServices.Configuration["Client"] == "Onsemi") { result = dad3350.ClearProgramAutoDir(entitys.MainMsg.McaCode, ref errorinfo); } else { result = dad3350.ClearProgram(entitys.MainMsg.McaCode, ref errorinfo); } if (result <= 0) { CurrDb.Rollback(); return -1; } break; default: MacProgramDal dal = new MacProgramDal(CurrDb); result = dal.ClearProgram(entitys.MainMsg.McaCode, ref errorinfo); if (result <= 0) { CurrDb.Rollback(); return -1; } break; } CurrDb.Commit(); return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); CurrDb.Rollback(); return -1; } finally { if (CurrDb != null) CurrDb.Close(); } } private static int UpProgram(IDatabase db, OrderBlock entity, string filedir, string usercode, ref string programname, ref string errorinfo) { try { List datas = entity.Datalists.Where(t => t.ParentID == 0).OrderBy(t => t.FNum).ToList(); int parentid = datas[0].ID;//获取L的ID值 datas = entity.Datalists.Where(t => t.ParentID == parentid).OrderBy(t => t.FNum).ToList(); programname = datas[0].FContent; string remark = programname; byte[] filedatas = datas[1].OrgDatas; string condition = $" and a.fcode='{entity.MainMsg.McaCode}'"; List macs = db.FindListForCondition(condition, ref errorinfo).ToList(); if (macs.Count <= 0) { errorinfo = $"未找到机台编号{entity.MainMsg.McaCode}的信息。"; return -1; } if (macs[0].MModeCode == "ADT7900DUO") { // ADT 设备没有上传程序按钮,也没法通过共享文件的形式上传。故不响应上传事件,全部使用WEP-Web端业务进行处理。 return 1; } if (AppConfigurtaionServices.Configuration["CallMesInterface"] != null && Convert.ToBoolean(AppConfigurtaionServices.Configuration["CallMesInterface"])) { string currprogramname = CallFunction.GetProgramName(macs[0].FCode, ref errorinfo); if (currprogramname == "") { return -1; } if (programname != currprogramname) { errorinfo = $"当前程序名称={currprogramname},上传程序名称={programname},只能上传当前运行的程序......"; return -100; } } string logerrorinfo = ""; WriteLog.WriteLogStr(macs[0].FCode, "", DateTime.Now, $"机台型号={macs[0].MModeCode.Trim().ToLower()}", ref logerrorinfo); switch (macs[0].MModeCode.Trim().ToLower()) { case "dad3350": case "dad3650": case "dfd6362": case "dfd6341": case "dfd6340": case "dfd6340-001": WriteLog.WriteLogStr(macs[0].FCode, "", DateTime.Now, $"开始解析disco程序名称", ref logerrorinfo); programname = DiodesProgramFileHelper.GetProgramName01(filedatas, ref errorinfo); if (errorinfo != "") { errorinfo = $"分析文件名称发生错误:{errorinfo}"; return -1; } WriteLog.WriteLogStr(macs[0].FCode, "", DateTime.Now, $"解析程序名称完成,解析后程序名称={programname}", ref logerrorinfo); break; case "dfg8540": programname = Bg8761ProgramFileHelper.GetProgramName01(filedatas, ref errorinfo); if (errorinfo != "") { errorinfo = $"分析文件名称发生错误:{errorinfo}"; return -1; } break; } BusinessFileDal dal = new BusinessFileDal(db); BusinessFile busifile = dal.UpdownFile(filedatas, filedir, programname, macs[0], remark, usercode, ref errorinfo); if (busifile == null) { errorinfo = $"处理文件发生错误:{errorinfo}"; return -1; } //添加程序,用于参数比对 ProgramMstDal pmdal = new ProgramMstDal(db); pmdal.IUProgramMst(macs[0], programname, ref errorinfo); return busifile.Version; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return -1; } } private static int UpProgramForFile(IDatabase db, OrderBlock entity, string filedir, string usercode, ref string programname, ref string errorinfo) { try { List datas = entity.Datalists.Where(t => t.ParentID == 0).OrderBy(t => t.FNum).ToList(); int parentid = datas[0].ID;//获取L的ID值 datas = entity.Datalists.Where(t => t.ParentID == parentid).OrderBy(t => t.FNum).ToList(); programname = datas[0].FContent; string remark = programname; string condition = $" and a.fcode='{entity.MainMsg.McaCode}'"; List macs = db.FindListForCondition(condition, ref errorinfo).ToList(); if (macs.Count <= 0) { errorinfo = $"未找到机台编号{entity.MainMsg.McaCode}的信息。"; return -1; } string currprogramname = CallFunction.GetProgramName(macs[0].FCode, ref errorinfo); currprogramname = $"{currprogramname}.rcp"; if (currprogramname == "") { return -1; } //if (programname != currprogramname) //{ // errorinfo = $"当前程序名称={currprogramname},上传程序名称={programname},只能上传当前运行的程序......"; // return -100; //} //调用文件上传模式 SocketFile dal = new SocketFile(); BusinessFile busifile = dal.UploadFile(macs[0], programname, ref errorinfo); if (busifile == null) { errorinfo = $"处理文件发生错误:{errorinfo}"; return -1; } //添加程序,用于参数比对 ProgramMstDal pmdal = new ProgramMstDal(db); pmdal.IUProgramMst(macs[0], programname, ref errorinfo); return busifile.Version; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return -1; } } private static int UpProgram001(IDatabase db, OrderBlock entity, string usercode, ref string errorinfo) { try { List datas = entity.Datalists.Where(t => t.ParentID == 0).OrderBy(t => t.FNum).ToList(); int parentid = datas[0].ID;//获取L的ID值 datas = entity.Datalists.Where(t => t.ParentID == parentid).OrderBy(t => t.FNum).ToList(); string programname = datas[0].FContent; //string filepath = datas[1].FContent; //查找程序表,是否存在此程序名称的记录 string condition = $" and {EntityAttribute.GetPropertyCondition(nameof(ProgramMst.FName))}='{programname}'"; List programmst = db.FindListForCondition(condition, ref errorinfo).ToList(); ProgramMst programentity = null; if (programmst.Count <= 0) { //添加程序记录 programentity = new ProgramMst(); errorinfo = $"未找到程序【{programname}】,请先配置程序及其比对的参数。"; return -1; } else { programentity = programmst[0]; } //读取机台 condition = $" and a.FCode='{entity.MainMsg.McaCode}'"; Machine mac = db.FindListForCondition(condition, ref errorinfo).ToList()[0]; if (mac == null) { //说明此机台没有开启参数比对功能,无需比对 errorinfo = $"未找到机台【{entity.MainMsg.McaCode}】"; return -1; } //比对参数,并保存比对结果 ParamsComMstDal comparedal = new ParamsComMstDal(db); ParamsComMst commst = comparedal.CompareParams(mac, programentity, ref errorinfo); if (commst == null) return -1; commst = comparedal.IUParamsComMst(commst, usercode, ref errorinfo); if (commst == null) return -1; if (commst.IsPass <= 0) { errorinfo = "参数比对没有通过。"; return -100; } //programentity.ServerPath = filepath; ////更新服务器程序路径 //int result = db.UpdateFor(programentity, usercode); //if (result <= 0) // return -1; return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return -1; } } //private static int UpProgram(IDatabase db, OrderBlock entity, string usercode, ref string errorinfo) //{ // try // { // string filedir = AppConfigurtaionServices.Configuration["ProgramDir"]; // List datas = entity.Datalists.Where(t => t.ParentID == 0).OrderBy(t => t.FNum).ToList(); // int parentid = datas[0].ID;//获取L的ID值 // datas = entity.Datalists.Where(t => t.ParentID == parentid).OrderBy(t => t.FNum).ToList(); // string programname = datas[0].FContent; // string programdata = datas[1].FContent; // byte[] filedatas = datas[1].OrgDatas; // //查找程序表,是否存在此程序名称的记录 // string condition = $" and {EntityAttribute.GetPropertyCondition(nameof(ProgramMst.FName))}='{programname}'"; // List programmst = db.FindListForCondition(condition, ref errorinfo).ToList(); // ProgramMst programentity = null; // if (programmst.Count <= 0) // { // //添加程序记录 // programentity = new ProgramMst(); // errorinfo = $"未找到程序【{programname}】,请先配置程序及其比对的参数。"; // return -1; // } // else // { // programentity = programmst[0]; // } // //比对参数,并保存比对结果 // ParamsComMstDal comparedal = new ParamsComMstDal(db); // ParamsComMst commst = comparedal.CompareParams(entity.MainMsg.McaCode, programentity.ID, ref errorinfo); // if (commst == null) // return -1; // //if(commst.IsPass<=0) // //{ // // errorinfo = "参数比对没有通过。"; // // return -100; // //} // commst = comparedal.IUParamsComMst(commst, usercode, ref errorinfo); // if (commst == null) // return -1; // if (commst.IsPass <= 0) // { // errorinfo = "参数比对没有通过。"; // return -100; // } // programentity.ServerPath = filedir + $"\\{programentity.ID}"; // int result = UnityHelper.WriteFile(programentity.ServerPath, filedatas, ref errorinfo); // if (result <= 0) // return -1; // //更新服务器程序路径 // result = db.UpdateFor(programentity, usercode); // if (result <= 0) // return -1; // return 1; // } // catch (Exception ex) // { // errorinfo = ex.Message.ToString(); // return -1; // } //} /// /// 计算机台产量 /// /// /// /// /// public static int AccountMacCount(string maccode, string usercode, ref string errorinfo) { IDatabase CurrDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); CurrDb.BeginTrans(); MacCountDal dal = new MacCountDal(CurrDb); List macs = CurrDb.FindListForCondition($" and a.fcode='{maccode}'", ref errorinfo).ToList(); int result = dal.IMacCount(macs[0], usercode, ref errorinfo); if (result < 0) { CurrDb.Rollback(); return -1; } CurrDb.Commit(); return result; } catch (Exception ex) { errorinfo = ex.Message.ToString(); CurrDb.Rollback(); return -1; } finally { if (CurrDb != null) CurrDb.Close(); } } /// /// 保存机台程序 /// /// /// /// /// public static int SaveProgram(string maccode, string usercode, ref string errorinfo) { IDatabase CurrDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); CurrDb.BeginTrans(); //读取机台信息 string condition = $" and a.FCode='{maccode}'"; Machine mac = CurrDb.FindListForCondition(condition, ref errorinfo).ToList()[0]; if (mac == null) { CurrDb.Rollback(); return -1; } //从机台上读取文件并保存 string programdir = AppConfigurtaionServices.Configuration["ProgramDir"]; if (mac.SupplierFCode == "KNS") { KnsProgramDal knsdal = new KnsProgramDal(CurrDb); MacProgram macprogram = knsdal.SaveProgram(maccode, usercode, ref errorinfo); if (macprogram == null) { CurrDb.Rollback(); return -1; } } else { AsmProgramDal knsdal = new AsmProgramDal(CurrDb); MacProgram macprogram = knsdal.SaveProgram(maccode, usercode, ref errorinfo); if (macprogram == null) { CurrDb.Rollback(); return -1; } } CurrDb.Commit();//先提交保存程序文件记录 return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); CurrDb.Rollback(); return -1; } finally { if (CurrDb != null) CurrDb.Close(); } } public static MacOrder GetMacOrder(string maccode, ref string errorinfo) { IDatabase CurrDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); CurrDb.BeginTrans(); //读取机台信息 string condition = $" and b.FCode='{maccode}'"; List mac = CurrDb.FindListForCondition(condition, ref errorinfo).ToList(); if (mac.Count <= 0) { errorinfo = $"未找到机台【{maccode}】对应的指令信息。"; return null; } CurrDb.Commit(); return mac[0]; } catch (Exception ex) { errorinfo = $"读取机台【{maccode}】指令发生错误,错误信息为【{ex.Message.ToString()}】"; CurrDb.Rollback(); return null; } finally { if (CurrDb != null) CurrDb.Close(); } } public static Machine GetMachine(string maccode, ref string errorinfo) { IDatabase CurrDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); CurrDb.BeginTrans(); //读取机台信息 string condition = $" and a.FCode='{maccode}'"; List mac = CurrDb.FindListForCondition(condition, ref errorinfo).ToList(); if (mac.Count <= 0) { errorinfo = $"未找到机台【{maccode}】。"; return null; } CurrDb.Commit(); return mac[0]; } catch (Exception ex) { errorinfo = $"读取机台【{maccode}】指令发生错误,错误信息为【{ex.Message.ToString()}】"; CurrDb.Rollback(); return null; } finally { if (CurrDb != null) CurrDb.Close(); } } public static List GetOrderStatus(int orderid, ref string errorinfo) { IDatabase CurrDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); CurrDb.BeginTrans(); //读取机台信息 string condition = $" and a.PreID={orderid}"; List entitys = CurrDb.FindListForCondition(condition, ref errorinfo).ToList(); if (entitys == null) { CurrDb.Rollback(); return null; } CurrDb.Commit(); return entitys; } catch (Exception ex) { errorinfo = $"读取指令状态发生错误,错误信息为【{ex.Message.ToString()}】"; CurrDb.Rollback(); return null; } finally { if (CurrDb != null) CurrDb.Close(); } } public static int AutoTrackOut(OrderBlock entitys, ref string errorinfo) { IDatabase CurrDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); CurrDb.BeginTrans(); string condition = $" and a.FCode='{entitys.MainMsg.McaCode}'"; List macs = CurrDb.FindListForCondition(condition, ref errorinfo).ToList(); StepTrackDal dal = new StepTrackDal(CurrDb); int result = dal.AutoTrackOut(macs[0], ref errorinfo); if (result <= 0) { CurrDb.Rollback(); return -1; } CurrDb.Commit(); return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); CurrDb.Rollback(); return -1; } finally { if (CurrDb != null) CurrDb.Close(); } } public static string GetProgramName(string maccode, ref string errorinfo) { IDatabase CurrDb = null; try { CurrDb = DbFactory.Base(ReadDbCode); //读取机台信息 string condition = $" and a.FCode='{maccode}'"; List mac = CurrDb.FindListForCondition(condition, ref errorinfo).ToList(); if (mac.Count <= 0) { errorinfo = $"未找到机台【{maccode}】。"; return null; } switch (mac[0].MModeCode.ToLower()) { case "dad3650": case "dfd6362": Dad3650ProgramDal dal3650 = new Dad3650ProgramDal(CurrDb); return dal3650.GetProgramName(mac[0], ref errorinfo); case "dfg8540": BgProgramDal bgdal = new BgProgramDal(CurrDb); return bgdal.GetProgramName(mac[0], ref errorinfo); default: Ad830PlusProgramDal dal = new Ad830PlusProgramDal(CurrDb); return dal.GetProgramName(mac[0], ref errorinfo); } } catch (Exception ex) { errorinfo = $"读取机台【{maccode}】程序名称发生错误,错误信息为【{ex.Message.ToString()}】"; return null; } finally { if (CurrDb != null) CurrDb.Close(); } } public static int RequestProgram(OrderBlock entitys, ILogger loger, ref string errorinfo) { IDatabase CurrDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); CurrDb.BeginTrans(); string programname = entitys.Datalists[0].FContent.Trim(); //根据程序名称获取程序数据 ProgramDal dal = new ProgramDal(CurrDb, loger); //int result = dal.DownloadProgramS7F6(entitys.MainMsg.McaCode, programname, ref errorinfo); int result = dal.DownloadProgram(entitys.MainMsg.McaCode, programname, ref errorinfo); return result; } catch (Exception ex) { errorinfo = ex.StackTrace + ex.Message.ToString(); CurrDb.Rollback(); return -1; } finally { if (CurrDb != null) CurrDb.Close(); } } /// /// 请求strip map /// /// /// /// public static int RequestStripmap(OrderBlock entitys, ref string errorinfo) { IDatabase CurrDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); CurrDb.BeginTrans(); StripMapDal dal = new StripMapDal(CurrDb); int result = dal.RequestStripmapE142(entitys, ref errorinfo); if (result <= 0) { CurrDb.Rollback(); return -1; } CurrDb.Commit(); return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); CurrDb.Rollback(); return -1; } finally { if (CurrDb != null) CurrDb.Close(); } } public static int RequestUploadStripMap(OrderBlock entities, List reportDetails, ref string errorinfo) { IDatabase CurrDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); CurrDb.BeginTrans(); StripMapDal dal = new StripMapDal(CurrDb); int result = dal.RequestUploadStripMapE142(entities, reportDetails, ref errorinfo); if (result <= 0) { CurrDb.Rollback(); return -1; } CurrDb.Commit(); return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); CurrDb.Rollback(); return -1; } finally { if (CurrDb != null) CurrDb.Close(); } } } }