using Model; using NPOI.HSSF.UserModel; using NPOI.SS.Formula.Functions; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Tool; namespace DAL { public class CheckDAL { private SqlHelper sql = new SqlHelper(); /// /// 抓取模式功率值取平均值 /// /// /// /// /// public List getendinitest(List initestModel, List initestModel2, List initestModel3) { List Ini = new List(); foreach (var item1 in initestModel) { IniModel ind = new IniModel(); var itme2 = initestModel2.Find(m => m.several_line_loss == item1.several_line_loss); var itme3 = initestModel3.Find(m => m.several_line_loss == item1.several_line_loss); if (itme2==null|| itme3 == null) { return new List(); } ind.several_line_loss = item1.several_line_loss; ind.LTE_BAND_TX_LOW_LOSS = getendini3(item1.LTE_BAND_TX_LOW_LOSS, itme2.LTE_BAND_TX_LOW_LOSS, itme3.LTE_BAND_TX_LOW_LOSS); ind.LTE_BAND_TX_MID_LOSS = getendini3(item1.LTE_BAND_TX_MID_LOSS, itme2.LTE_BAND_TX_MID_LOSS, itme3.LTE_BAND_TX_MID_LOSS); ind.LTE_BAND_TX_HIGH_LOSS = getendini3(item1.LTE_BAND_TX_HIGH_LOSS, itme2.LTE_BAND_TX_HIGH_LOSS, itme3.LTE_BAND_TX_HIGH_LOSS); ind.LTE_BAND_RX_LOW_LOSS = getendini3(item1.LTE_BAND_RX_LOW_LOSS, itme2.LTE_BAND_RX_LOW_LOSS, itme3.LTE_BAND_RX_LOW_LOSS); ind.LTE_BAND_RX_MID_LOSS = getendini3(item1.LTE_BAND_RX_MID_LOSS, itme2.LTE_BAND_RX_MID_LOSS, itme3.LTE_BAND_RX_MID_LOSS); ind.LTE_BAND_RX_HIGH_LOSS = getendini3(item1.LTE_BAND_RX_HIGH_LOSS, itme2.LTE_BAND_RX_HIGH_LOSS, itme3.LTE_BAND_RX_HIGH_LOSS); Ini.Add(ind); } return Ini; } /// /// 计算三个数的平均值,保留小数点后两位 /// /// /// /// /// public string getendini3(string lTE_BAND_RX_LOW_LOSS1, string lTE_BAND_RX_LOW_LOSS2, string lTE_BAND_RX_LOW_LOSS3) { double value1 = double.Parse(lTE_BAND_RX_LOW_LOSS1); double value2 = double.Parse(lTE_BAND_RX_LOW_LOSS2); double value3 = double.Parse(lTE_BAND_RX_LOW_LOSS3); double difference = Math.Round((value1 + value2+ value3)/3,2); return difference.ToString(); } /// /// 计算抓取模式下线损的平均值 /// /// /// /// /// public List getendtest(List exclModel, List exclModel2, List exclModel3) { List Excl = new List(); foreach (var item in exclModel) { ExclModel excd = new ExclModel(); var itme2 = exclModel2.Find(m => m.Channel == item.Channel&& m.Band == item.Band); var itme3 = exclModel3.Find(m => m.Channel == item.Channel&&m.Band == item.Band); if (itme2 == null || itme3 == null) { return new List(); } excd.Band = item.Band; excd.Channel = item.Channel; excd.Result = getendini3(item.Result.Replace("dBm", ""), itme2.Result.Replace("dBm", ""), itme3.Result.Replace("dBm", "")) + "dBm"; Excl.Add(excd); } return Excl; } /// /// 从数据库读取金机与机型的关系 /// /// /// public string[] Getimei(string type) { string[] Jinjiimei; string imei = ""; List lS = sql.db3.Queryable(). Where(it => it.type == type).ToList(); if (lS.Count>0) { foreach (var yj in lS) { if (imei == "") { imei = yj.snimei; } else { imei = imei+";"+ yj.snimei; } } } Jinjiimei= imei.Split(';'); return Jinjiimei; } /// /// 抓取作为标准的功率值 /// /// /// /// /// /// public List GetStandardExcl(string devcode1, string type, string snimei) { try { List exciset = new List(); SqlHelper.t_CMCC_JinjiPower LinExc = sql.db3.Queryable(). Where(it => it.Devcode == devcode1 && it.snimei == snimei && it.kind == "标准"). OrderBy(it => it.PowerTime, SqlSugar.OrderByType.Desc).First(); if (LinExc != null) { List lsitpower = sql.db3.Queryable(). Where(it => it.PowerTime == LinExc.PowerTime && it.Devcode == devcode1 && it.snimei == snimei && it.kind == "标准").ToList(); foreach (var item in lsitpower) { ExclModel excModel = new ExclModel(); excModel.Band = item.Band; excModel.Result = item.Result; excModel.Channel = item.Channel; exciset.Add(excModel); } return exciset; } else { LogHelper.WriteLog("数据库为空"); return null; } } catch (Exception ee) { LogHelper.WriteLog(ee.ToString()); return null; } } /// /// 抓取作为标准的线损值 /// /// /// /// /// /// public List GetStandardIni(string devcode1, string type, string snimei) { try { List linliset = new List(); SqlHelper.t_CMCC_JinjiLine Lin = sql.db3.Queryable(). Where(it => it.Devcode == devcode1&&it.snimei == snimei && it.kind == "标准"). OrderBy(it => it.LineTime, SqlSugar.OrderByType.Desc).First(); if (Lin != null) { List lsitline = sql.db3.Queryable(). Where(it => it.LineTime== Lin.LineTime&& it.Devcode == devcode1 && it.snimei == snimei&&it.kind=="标准").ToList(); foreach (var item in lsitline) { IniModel lineModel = new IniModel(); lineModel.several_line_loss = item.several_line_loss; lineModel.LTE_BAND_TX_LOW_LOSS = item.LTE_BAND_TX_LOW_LOSS; lineModel.LTE_BAND_TX_MID_LOSS = item.LTE_BAND_TX_MID_LOSS; lineModel.LTE_BAND_TX_HIGH_LOSS = item.LTE_BAND_TX_HIGH_LOSS; lineModel.LTE_BAND_RX_LOW_LOSS = item.LTE_BAND_RX_LOW_LOSS; lineModel.LTE_BAND_RX_MID_LOSS = item.LTE_BAND_RX_MID_LOSS; lineModel.LTE_BAND_RX_HIGH_LOSS = item.LTE_BAND_RX_HIGH_LOSS; linliset.Add(lineModel); } return linliset; } else { LogHelper.WriteLog("数据库为空"); return null; } } catch (Exception ee) { LogHelper.WriteLog(ee.ToString()); return null; } } /// /// 上传合格的功率值和线损值 /// /// /// /// /// public string updata(List initestModel, List exclModel,string classify,string devcode,string type,string snimei,string name) { try { DateTime dt = sql.db3.GetDate(); List powelist = new List(); foreach (var item in exclModel) { SqlHelper.t_CMCC_JinjiPower powerone = new SqlHelper.t_CMCC_JinjiPower(); powerone.Band = item.Band; powerone.Channel = item.Channel; powerone.Result = item.Result; powerone.PowerTime = dt; powerone.Powername = name; powerone.kind = classify; powerone.textname = item.textname; powerone.Devcode = devcode; powerone.type = type; powerone.snimei = snimei; powelist.Add(powerone); } int result = sql.db3.Insertable(powelist).ExecuteCommand(); if (result != powelist.Count) { return "功率数据上传异常!"; } List Linelist = new List(); foreach (var item in initestModel) { SqlHelper.t_CMCC_JinjiLine lineone = new SqlHelper.t_CMCC_JinjiLine(); lineone.LTE_BAND_TX_LOW_LOSS = item.LTE_BAND_TX_LOW_LOSS; lineone.LTE_BAND_TX_MID_LOSS = item.LTE_BAND_TX_MID_LOSS; lineone.LTE_BAND_TX_HIGH_LOSS = item.LTE_BAND_TX_HIGH_LOSS; lineone.LTE_BAND_RX_LOW_LOSS = item.LTE_BAND_RX_LOW_LOSS; lineone.LTE_BAND_RX_MID_LOSS = item.LTE_BAND_RX_MID_LOSS; lineone.LTE_BAND_RX_HIGH_LOSS = item.LTE_BAND_RX_HIGH_LOSS; lineone.several_line_loss = item.several_line_loss; lineone.kind = classify; lineone.LineTime = dt; lineone.Linename = name; lineone.textname = item.textname; lineone.Devcode = devcode; lineone.type = type; lineone.snimei = snimei; Linelist.Add(lineone); } result = sql.db3.Insertable(Linelist).ExecuteCommand(); if (result != Linelist.Count) { return "功率数据上传异常!"; } return "OK"; } catch (Exception ee) { LogHelper.WriteLog(ee.ToString()); return "MES连接异常!"; } } public string checkdist(string devcode1, string type, string snimei, string name) { if(devcode1==""|| devcode1==null) { return "对应的夹具号为空"; } if (type =="" || type == null) { return "机型为空"; } if (snimei=="" || snimei == null) { return "对应的金机编号为空"; } if (name=="" || name == null) { return "未登录"; } return "OK"; } } }