Files
zy-jjdj/DAL/CheckDAL.cs
2025-07-11 14:12:47 +08:00

294 lines
13 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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();
/// <summary>
/// 抓取模式功率值取平均值
/// </summary>
/// <param name="initestModel"></param>
/// <param name="initestModel2"></param>
/// <param name="initestModel3"></param>
/// <returns></returns>
public List<IniModel> getendinitest(List<IniModel> initestModel, List<IniModel> initestModel2, List<IniModel> initestModel3)
{
List<IniModel> Ini = new List<IniModel>();
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<IniModel>();
}
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;
}
/// <summary>
/// 计算三个数的平均值,保留小数点后两位
/// </summary>
/// <param name="lTE_BAND_RX_LOW_LOSS1"></param>
/// <param name="lTE_BAND_RX_LOW_LOSS2"></param>
/// <param name="lTE_BAND_RX_LOW_LOSS3"></param>
/// <returns></returns>
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();
}
/// <summary>
/// 计算抓取模式下线损的平均值
/// </summary>
/// <param name="exclModel"></param>
/// <param name="exclModel2"></param>
/// <param name="exclModel3"></param>
/// <returns></returns>
public List<ExclModel> getendtest(List<ExclModel> exclModel, List<ExclModel> exclModel2, List<ExclModel> exclModel3)
{
List<ExclModel> Excl = new List<ExclModel>();
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<ExclModel>();
}
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;
}
/// <summary>
/// 从数据库读取金机与机型的关系
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public string[] Getimei(string type)
{
string[] Jinjiimei;
string imei = "";
List<SqlHelper.t_CMCC_Jinji> lS = sql.db3.Queryable<SqlHelper.t_CMCC_Jinji>().
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;
}
/// <summary>
/// 抓取作为标准的功率值
/// </summary>
/// <param name="devcode1"></param>
/// <param name="type"></param>
/// <param name="snimei"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public List<ExclModel> GetStandardExcl(string devcode1, string type, string snimei)
{
try
{
List<ExclModel> exciset = new List<ExclModel>();
SqlHelper.t_CMCC_JinjiPower LinExc = sql.db3.Queryable<SqlHelper.t_CMCC_JinjiPower>().
Where(it => it.Devcode == devcode1 && it.snimei == snimei && it.kind == "标准").
OrderBy(it => it.PowerTime, SqlSugar.OrderByType.Desc).First();
if (LinExc != null)
{
List<SqlHelper.t_CMCC_JinjiPower> lsitpower = sql.db3.Queryable<SqlHelper.t_CMCC_JinjiPower>().
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;
}
}
/// <summary>
/// 抓取作为标准的线损值
/// </summary>
/// <param name="devcode1"></param>
/// <param name="type"></param>
/// <param name="snimei"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public List<IniModel> GetStandardIni(string devcode1, string type, string snimei)
{
try
{
List<IniModel> linliset = new List<IniModel>();
SqlHelper.t_CMCC_JinjiLine Lin = sql.db3.Queryable<SqlHelper.t_CMCC_JinjiLine>().
Where(it => it.Devcode == devcode1&&it.snimei == snimei && it.kind == "标准").
OrderBy(it => it.LineTime, SqlSugar.OrderByType.Desc).First();
if (Lin != null)
{
List<SqlHelper.t_CMCC_JinjiLine> lsitline = sql.db3.Queryable<SqlHelper.t_CMCC_JinjiLine>().
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;
}
}
/// <summary>
/// 上传合格的功率值和线损值
/// </summary>
/// <param name="initestModel"></param>
/// <param name="exclModel"></param>
/// <param name="classify"></param>
/// <returns></returns>
public string updata(List<IniModel> initestModel, List<ExclModel> exclModel,string classify,string devcode,string type,string snimei,string name)
{
try {
DateTime dt = sql.db3.GetDate();
List<SqlHelper.t_CMCC_JinjiPower> powelist = new List<SqlHelper.t_CMCC_JinjiPower>();
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<SqlHelper.t_CMCC_JinjiLine> Linelist = new List<SqlHelper.t_CMCC_JinjiLine>();
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";
}
}
}