123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653 |
- 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
- {
- /// <summary>
- /// 测试用
- /// </summary>
- [AllowAnonymous]
- [ApiController]
- [Route("/eap/api/[controller]/[action]")]
- public class TestController : ControllerBase
- {
- private ILogger loger = null;
- public TestController(ILogger<TestController> loger)
- {
- this.loger = loger;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="macCode"></param>
- /// <param name="proName"></param>
- /// <returns></returns>
- [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();
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="macCode"></param>
- /// <param name="proName"></param>
- /// <returns></returns>
- [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();
- }
- }
- /// <summary>
- /// ASE程序测试
- /// </summary>
- /// <param name="lotId"></param>
- /// <param name="macCode"></param>
- /// <returns></returns>
- [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;
- }
- }
- /// <summary>
- /// 共享文件测试
- /// </summary>
- /// <returns></returns>
- [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;
- }
- }
- /// <summary>
- /// 测试欧非调用MES接口
- /// </summary>
- /// <param name="actionName"></param>
- /// <param name="macId"></param>
- /// <param name="recipe"></param>
- /// <param name="lotId"></param>
- /// <param name="version"></param>
- /// <returns></returns>
- [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<string, string> paras = new Dictionary<string, string>();
- paras.Add("equipmentID", macId);
- paras.Add("lotId", lotId);
- paras.Add("recipeName", recipe);
- paras.Add("version", version);
- var obj = HttpRequestHelper<OfilmMesApiResponse>.Get(url, paras, ref errorinfo);
- return obj;
- }
- /// <summary>
- /// 获取机台参数
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public EapApiResponse<string> 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<EapApiResponse<string>>.Post(url,
- JsonConvert.SerializeObject(obj), ref errorinfo);
- }
- /// <summary>
- /// 测试获取机台制程
- /// </summary>
- /// <param name="maccode"></param>
- /// <returns></returns>
- [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<Machine> mac = CurrDb.FindListForCondition<Machine>(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();
- }
- }
- ///// <summary>
- ///// 下载LOT
- ///// </summary>
- ///// <param name="macCode"></param>
- ///// <param name="handlerdown"></param>
- ///// <param name="programname"></param>
- ///// <returns></returns>
- //[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<string, string> dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(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<Machine>($" 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<Machine>($" 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<int> 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();
- // }
- //}
- /// <summary>
- ///
- /// </summary>
- /// <param name="macCode"></param>
- /// <param name="programname"></param>
- /// <returns></returns>
- [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<Machine>($" 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();
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="macCode"></param>
- /// <param name="programname"></param>
- /// <param name="lotid"></param>
- /// <returns></returns>
- [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<Machine>($" 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();
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="macCode"></param>
- /// <param name="programname"></param>
- /// <param name="lotid"></param>
- /// <param name="userid"></param>
- /// <param name="stationid"></param>
- /// <returns></returns>
- [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<Machine>($" 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();
- }
- }
- ///// <summary>
- /////
- ///// </summary>
- ///// <param name="testmarkmac"></param>
- ///// <param name="programname"></param>
- ///// <param name="lotid"></param>
- ///// <param name="userid"></param>
- ///// <param name="stationid"></param>
- ///// <param name="errorinfo"></param>
- ///// <returns></returns>
- //[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<Machine>($" 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;
- // }
- //}
- /// <summary>
- /// 测试停机
- /// </summary>
- /// <returns></returns>
- [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<string> 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);
- }
- }
- }
- }
- }
|