using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using DllEapDal; using Cksoft.Data; using Cksoft.Data.Repository; using Cksoft.Unity; using Microsoft.Extensions.Logging; using DllEapDal.Onsemi; using DllEapEntity; using System.Linq; using DllEapEntity.Onsemi; using DllEapEntity.OFILM; using Newtonsoft.Json; using DllSocketFile; using DllEapCommon; using Microsoft.AspNetCore.Authorization; using System.Threading.Tasks; using DllEapDal.OFILM; using System.Threading; namespace DllEapBll.Controllers { /// /// 测试用 /// [AllowAnonymous] [ApiController] [Route("/eap/api/[controller]/[action]")] public class TestController : ControllerBase { private ILogger loger = null; public TestController(ILogger loger) { this.loger = loger; } /// /// /// /// /// /// [HttpGet] public EapResponse Test(string macCode, string proName) { var res = new EapResponse { Code = 1, Msg = string.Empty }; IDatabase db = null; try { db = DbFactory.Base("eap"); db.BeginTrans(); var dal = new ProgramDal(db, loger); string errorinfo = string.Empty; loger.LogError($"机台={macCode},程序名称={proName} 开始下载"); //macCode = "DIBD0034"; //proName = "18-038"; //proName = "DMP3099L-7-CU-AD0806AL796CXX-BN"; var r = dal.DownloadProgram(macCode, proName, ref errorinfo); if (r < 0) { loger.LogError(errorinfo); db.Rollback(); res.Code = -1; res.Msg = errorinfo; return res; } db.Commit(); return res; } catch (Exception e) { res.Code = -1; res.Msg = e.Message; return res; } finally { if (db != null) db.Close(); } } /// /// /// /// /// /// [HttpGet] public EapResponse Test02(string macCode, string proName) { var res = new EapResponse { Code = 1, Msg = string.Empty }; IDatabase db = null; try { db = DbFactory.Base("eap"); db.BeginTrans(); var dal = new ProgramDal(db); string errorinfo = string.Empty; loger.LogError($"机台={macCode},程序名称={proName} 开始下载"); //macCode = "DIBD0034"; //proName = "18-038"; //proName = "DMP3099L-7-CU-AD0806AL796CXX-BN"; var r = dal.DownloadProgram(macCode, proName, ref errorinfo); if (r < 0) { loger.LogError(errorinfo); db.Rollback(); res.Code = -1; res.Msg = errorinfo; return res; } db.Commit(); return res; } catch (Exception e) { res.Code = -1; res.Msg = e.Message; return res; } finally { if (db != null) db.Close(); } } /// /// ASE程序测试 /// /// /// /// [HttpGet] public EapResponse TestProgramForAsesh(string lotId, string macCode) { var res = new EapResponse { Code = 1, Msg = string.Empty }; try { var dal = new MesDal(); string errorinfo = string.Empty; //lotId = "BLD010S008"; //macCode = "A2220-0019"; var r = dal.DownloadProgram(lotId, macCode, ref errorinfo); // 加入测试代码 if (r < 0) { WriteLog.WriteLogStr("", "", DateTime.Now, errorinfo, ref errorinfo); res.Code = -1; res.Msg = errorinfo; return res; } return res; } catch (Exception e) { res.Code = -1; res.Msg = e.Message; return res; } } /// /// 共享文件测试 /// /// [HttpGet] public EapResponse TestShareFile() { var res = new EapResponse { Code = 1, Msg = string.Empty }; try { string errorinfo = ""; byte[] datas = UnityHelper.ReadFile(@"d:\test.txt", ref errorinfo); UnityHelper.WriteFile(@"\\192.168.51.244\ShareFileDir", "wwwww", datas, ref errorinfo); loger.LogError($"写入完成{errorinfo}"); return res; } catch (Exception e) { loger.LogError(e.Message.ToString()); res.Code = -1; res.Msg = e.Message; return res; } } /// /// 测试欧非调用MES接口 /// /// /// /// /// /// /// [HttpGet] public OfilmMesApiResponse TestCallMesApi(string actionName, string macId, string recipe, string lotId, string version) { string errorinfo = string.Empty; var url = "http://192.168.51.100:8080/ofilm/eap/" + actionName; IDictionary paras = new Dictionary(); paras.Add("equipmentID", macId); paras.Add("lotId", lotId); paras.Add("recipeName", recipe); paras.Add("version", version); var obj = HttpRequestHelper.Get(url, paras, ref errorinfo); return obj; } /// /// 获取机台参数 /// /// [HttpGet] public EapApiResponse TestEapApi() { string errorinfo = string.Empty; var url = "http://192.168.124.93:8606/eap/api/equipment/getEquipmentParams"; var obj = new { equipmentID = "LHA-001", ParamsList = new string[] { "S00001", "S00002" } }; return HttpRequestHelper>.Post(url, JsonConvert.SerializeObject(obj), ref errorinfo); } /// /// 测试获取机台制程 /// /// /// [HttpGet] public EapResponse TestGetProgressName(string maccode) { var res = new EapResponse { Code = 1, Msg = string.Empty }; string errorinfo = ""; IDatabase CurrDb = null; try { CurrDb = DbFactory.Base("eap"); //读取机台信息 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); res.Data = dal3650.GetProgramName(mac[0], ref errorinfo); break; case "dfg8540": BgProgramDal bgdal = new BgProgramDal(CurrDb); res.Data = bgdal.GetProgramName(mac[0], ref errorinfo); break; default: Ad830PlusProgramDal dal = new Ad830PlusProgramDal(CurrDb); res.Data = dal.GetProgramName(mac[0], ref errorinfo); break; } return res; } catch (Exception ex) { //errorinfo = $"读取机台【{maccode}】程序名称发生错误,错误信息为【{ex.Message.ToString()}】"; res.Code = -1; res.Msg = ex.Message; loger.LogError(res.Msg); return res; } finally { if (CurrDb != null) CurrDb.Close(); } } ///// ///// 下载LOT ///// ///// ///// ///// ///// //[HttpGet] //public string DownLotload(string macCode, string handlerdown, string programname) //{ // int ver = 1; // var res = new EapResponse { Code = 1, Msg = string.Empty }; // IDatabase db = null; // try // { // loger.LogError("programname参数值的内容为:" + programname); // Dictionary dic = JsonConvert.DeserializeObject>(programname); // string PartID = dic["PartID"].ToString(); // string FolProgram = dic["FolProgram"].ToString() + ".zip"; // string MarkProgram = dic["MarkProgram"].ToString(); // string TestProgram = dic["TestProgram"].ToString(); // string ProcessFlow = dic["ProcessFlow"].ToString().Trim().ToLower(); // string lotID = dic["lotID"].ToString(); // db = DbFactory.Base("eap"); // db.BeginTrans(); // string errorinfo = string.Empty; // string outstr = ""; // //var dal = new StepTrackDal(db); // Machine mac = db.FindListForCondition($" and a.FCode='{macCode}'", ref errorinfo).FirstOrDefault(); // int result = -1; // Dad3350ProgramDal dal1 = new Dad3350ProgramDal(db); // AsmProgramDal apdal = new AsmProgramDal(db); // if (handlerdown == "on") // { // //机台下载程序文件 // result = dal1.DownloadProgramForFile(mac, FolProgram, ver, ref errorinfo); // if (result <= 0) // { // errorinfo = $"机台[{mac.FCode}]下载程序文件[{FolProgram}]发生错误:{errorinfo}"; // loger.LogError(errorinfo); // return errorinfo; // } // else // { // outstr += $"机台[{mac.FCode}]下载程序文件[{FolProgram}]成功!\r\n"; // loger.LogError($"机台[{mac.FCode}]下载程序文件[{FolProgram}]成功!"); // } // db.Commit(); // //机台装载程序 // FolProgram = FolProgram.Substring(0, FolProgram.Length - 4); // //AsmProgramDal apdal = new AsmProgramDal(db); // result = apdal.SelProgram(mac, FolProgram, ref errorinfo); // if (result < 0) // { // errorinfo = $"机台[{mac.FCode}]装载程序[{FolProgram}]异常:" + errorinfo; // loger.LogError(errorinfo); // return errorinfo; // } // else // { // outstr += $"机台[{mac.FCode}]装载程序[{FolProgram}]成功!\r\n"; // loger.LogError($"机台[{mac.FCode}]装载程序[{FolProgram}]成功!"); // } // } // //test、marking装载程序 // var testmarkdal = new MachinetestmarkingDal(db); // string filter2 = $" and b.FCode='{mac.FCode}'"; // var roles2 = testmarkdal.Get(1, 10, "desc", "a.MacID", filter2, errorinfo); // if (roles2 != null && roles2.Count() > 0) // { // foreach (var item in roles2) // { // string getname = string.Empty; // bool ismark = ProcessFlow.ToUpper() == "3-IN-1" ? true : false; // Machine testmarkmac = db.FindListForCondition($" and a.ID='{item.parentID}'", ref errorinfo).FirstOrDefault(); // if (testmarkmac.MModeCode == "QuickMark") // { // if (ismark) // { // getname = MarkProgram; // result = apdal.SelProgramQuickMark(testmarkmac, getname, ref errorinfo); // } // else // { // continue; // } // } // if (testmarkmac.MModeCode == "SineTest") // { // getname = TestProgram; // result = apdal.SelProgramSineTest(testmarkmac, getname, lotID, ref errorinfo); // } // if (testmarkmac.MModeCode == "QTTest") // { // string userid = string.Empty; // var partMachinedal = new PartMachineDal(db); // string filter = $" and b.partCode='{PartID}' and a.machineID='{testmarkmac.ID}'"; // var roles = partMachinedal.Get(1, 10000, "desc", "a.partID", filter, errorinfo); // if (roles != null && roles.Count() > 0) // { // var qttest = roles.FirstOrDefault(); // string qtp = qttest.qtype.ToUpper(); // qtp = "CJ-" + qtp; // userid = qttest.employNum; // if (qttest.programName.Trim().Length > 0) // { // getname = qttest.programName; // result = apdal.SelProgramQTTest(testmarkmac, qttest.programName, lotID, qttest.employNum, qtp, ref errorinfo); // if (result < 0) // { // errorinfo = $"机台[{testmarkmac.FCode}]装载程序[{getname}]异常:" + errorinfo; // loger.LogError(errorinfo); // outstr += errorinfo + "\r\n"; // } // else // { // outstr += $"机台[{testmarkmac.FCode}]装载程序[{getname}]成功!\r\n"; // } // } // } // getname = TestProgram; // result = LoadQTTest(testmarkmac, TestProgram, lotID, userid, "FT-FT", ref errorinfo); // } // if (result < 0) // { // errorinfo = $"机台[{testmarkmac.FCode}]装载程序[{getname}]异常:" + errorinfo; // loger.LogError(errorinfo); // outstr += errorinfo + "\r\n"; // } // else // { // outstr += $"机台[{testmarkmac.FCode}]装载程序[{getname}]成功!\r\n"; // } // } // } // else // { // return $"找不到机台[{mac.FCode}]关联的Test、Marking配置信息!"; // } // //var partdal = new PartInfoDal(db); // //string filter = $" and a.partCode='{PartID}'"; // //var roles = partdal.Get(1, 10000, "desc", "a.partCode", filter, errorinfo).Select(x=>x.machineID); // //if (roles!=null && roles.Count()>0) // //{ // // List lstmac = roles.ToList(); // // var lstMachine = lstmac.Where((x, i) => lstmac.FindIndex(z => z == x) == i); // // foreach (var itemMac in lstMachine) // // { // // } // // //return $"[{lotID}]lot调程成功!"; // // return outstr; // //} // //else // //{ // // return $"找不到产品编号[{PartID}]关联的机台配置信息!"; // //} // return outstr; // } // catch (Exception e) // { // res.Code = -1; // res.Msg = e.Message; // loger.LogError(res.Msg); // return res.Msg; // } // finally // { // if (db != null) // db.Close(); // } //} /// /// /// /// /// /// [HttpGet] public string LoadTest(string macCode, string programname) { string errorinfo = string.Empty; IDatabase db = null; try { db = DbFactory.Base("eap"); AsmProgramDal apdal = new AsmProgramDal(db); Machine testmarkmac = db.FindListForCondition($" and a.FCode='{macCode}'", ref errorinfo).FirstOrDefault(); int result = apdal.SelProgramQuickMark(testmarkmac, programname, ref errorinfo); if (result < 0) { loger.LogError($"机台{testmarkmac.FCode}装载程序异常:" + errorinfo); return errorinfo; } return "成功"; } catch (Exception ex) { return ex.Message.ToString(); } } /// /// /// /// /// /// /// [HttpGet] public string LoadTest2(string macCode, string programname, string lotid) { string errorinfo = string.Empty; IDatabase db = null; try { db = DbFactory.Base("eap"); AsmProgramDal apdal = new AsmProgramDal(db); Machine testmarkmac = db.FindListForCondition($" and a.FCode='{macCode}'", ref errorinfo).FirstOrDefault(); int result = apdal.SelProgramSineTest(testmarkmac, programname, lotid, ref errorinfo); if (result < 0) { loger.LogError($"机台{testmarkmac.FCode}装载程序异常:" + errorinfo); return errorinfo; } return "成功!"; } catch (Exception ex) { return ex.Message.ToString(); } } /// /// /// /// /// /// /// /// /// [HttpGet] public string LoadTest3(string macCode, string programname, string lotid, string userid, string stationid) { string errorinfo = string.Empty; IDatabase db = null; try { db = DbFactory.Base("eap"); AsmProgramDal apdal = new AsmProgramDal(db); Machine testmarkmac = db.FindListForCondition($" and a.FCode='{macCode}'", ref errorinfo).FirstOrDefault(); int result = apdal.SelProgramQTTest(testmarkmac, programname, lotid, userid, stationid, ref errorinfo); if (result < 0) { loger.LogError($"机台{testmarkmac.FCode}装载程序异常:" + errorinfo); return errorinfo; } return "成功!"; } catch (Exception ex) { return ex.Message.ToString(); } } ///// ///// ///// ///// ///// ///// ///// ///// ///// ///// //[HttpGet] //public int LoadQTTest(Machine testmarkmac, string programname, string lotid, string userid, string stationid, ref string errorinfo) //{ // IDatabase db = null; // try // { // db = DbFactory.Base("eap"); // AsmProgramDal apdal = new AsmProgramDal(db); // //Machine testmarkmac = db.FindListForCondition($" and a.FCode='{macCode}'", ref errorinfo).FirstOrDefault(); // int result = apdal.SelProgramQTTest(testmarkmac, programname, lotid, userid, stationid, ref errorinfo); // if (result < 0) // { // //errorinfo = $"机台[{testmarkmac.FCode}]装载程序[{programname}]异常:" + errorinfo; // loger.LogError(errorinfo); // return result; // } // return 1; // } // catch (Exception ex) // { // errorinfo = ex.Message.ToString(); // return -1; // } //} /// /// 测试停机 /// /// [HttpGet] public EapResponse TestStopMachine() { var res = new EapResponse { Code = 1, Msg = string.Empty }; IDatabase db = null; try { db = DbFactory.Base("eap"); db.BeginTrans(); AppserverHelper dal = new AppserverHelper(); string maccode = "DA00004"; int a = 18765; string errorinfo = ""; int result = dal.StopMachine(db, new Machine() { ID = 768, FCode = "DA00004" }, ref errorinfo); db.Commit(); return res; } catch (Exception e) { res.Code = -1; res.Msg = e.Message; return res; } finally { if (db != null) db.Close(); } } [HttpGet] public async Task TestDashboard() { string errorinfo = string.Empty; int count = 0; while (true) { if (count > 100) { return "执行完毕"; } using (IDatabase db = DbFactory.Base("eapslave")) { var dal = new MacStatusTotalDal(db); dal.GetTotalInfo($" and f.id=8", null, "2022-01-19", "1", ref errorinfo); count++; Thread.Sleep(2 * 1000); } } } } }