|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
using Entity.Api.Req;
|
|
|
|
|
using Entity.DbModel.Station;
|
|
|
|
@ -8,6 +10,7 @@ using HybirdFrameworkCore.Utils;
|
|
|
|
|
using Magicodes.ExporterAndImporter.Excel;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using OfficeOpenXml;
|
|
|
|
|
using Repository.Station;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
@ -60,9 +63,9 @@ public class EquipAlarmDefineService: BaseServices<EquipAlarmDefine>
|
|
|
|
|
/// 导出
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IActionResult> ExportEquipAlarmRecord()
|
|
|
|
|
public async Task<IActionResult> ExportEquipAlarmRecord(EquipAlarmDefineReq req)
|
|
|
|
|
{
|
|
|
|
|
List<EquipAlarmDefine> equipAlarmRecords = await BaseDal.QueryAsync();
|
|
|
|
|
List<EquipAlarmDefine> equipAlarmRecords = await this.QueryEquipAlarmDefineListAsync(req);
|
|
|
|
|
|
|
|
|
|
var config = new MapperConfiguration(cfg =>
|
|
|
|
|
{
|
|
|
|
@ -96,7 +99,9 @@ public class EquipAlarmDefineService: BaseServices<EquipAlarmDefine>
|
|
|
|
|
{
|
|
|
|
|
return Result<string>.Fail("报警编码不能为空");
|
|
|
|
|
}
|
|
|
|
|
if (req.ErrorLevel == null)
|
|
|
|
|
|
|
|
|
|
bool bconvert = int.TryParse(req.ErrorLevel, out int result);
|
|
|
|
|
if (!bconvert)
|
|
|
|
|
{
|
|
|
|
|
return Result<string>.Fail("报警等级不能为空");
|
|
|
|
|
}
|
|
|
|
@ -217,4 +222,163 @@ public class EquipAlarmDefineService: BaseServices<EquipAlarmDefine>
|
|
|
|
|
|
|
|
|
|
return Result<string>.Fail("删除失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 文件导入
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="filePath">文件路径</param>
|
|
|
|
|
public string ImportDataFromExcel(string filePath)
|
|
|
|
|
{
|
|
|
|
|
var fileInfo = new FileInfo(filePath);
|
|
|
|
|
|
|
|
|
|
using (var package = new ExcelPackage(fileInfo))
|
|
|
|
|
{
|
|
|
|
|
// 操作第一个工作表
|
|
|
|
|
ExcelWorksheet worksheet = package.Workbook.Worksheets[0];
|
|
|
|
|
int rowCount = worksheet.Dimension.End.Row;
|
|
|
|
|
int colCount = worksheet.Dimension.End.Column;
|
|
|
|
|
DataTable dt = new DataTable();
|
|
|
|
|
List<EquipAlarmDefine> lstEquipAlarmDefine = new();
|
|
|
|
|
var lstEquipAlarmDefinesql = BaseDal.QueryListByClause(i=>i.Id>0);
|
|
|
|
|
// 初始化一个列表来存储第一行的所有名称
|
|
|
|
|
List<string> rowNames = new List<string>();
|
|
|
|
|
// 遍历第一行的所有单元格
|
|
|
|
|
// 注意:Excel的索引通常是从1开始的,所以第一行是1,第一列也是1
|
|
|
|
|
for (int col = 1; col <= worksheet.Dimension.End.Column; col++)
|
|
|
|
|
{
|
|
|
|
|
string cellValue = worksheet.Cells[1, col].Value?.ToString() ?? string.Empty;
|
|
|
|
|
rowNames.Add(cellValue);
|
|
|
|
|
}
|
|
|
|
|
for (int col = 1; col <= colCount; col++)
|
|
|
|
|
{
|
|
|
|
|
dt.Columns.Add(worksheet.Cells[1, col].Value.ToString());
|
|
|
|
|
}
|
|
|
|
|
// 跳过标题行,从第二行开始读取数据
|
|
|
|
|
for (int row = 2; row <= rowCount; row++)
|
|
|
|
|
{
|
|
|
|
|
DataRow dr = dt.NewRow();
|
|
|
|
|
|
|
|
|
|
for (int col = 1; col <= colCount; col++)
|
|
|
|
|
{
|
|
|
|
|
dr[col - 1] = worksheet.Cells[row, col].Value ?? DBNull.Value;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dt.Rows.Add(dr);
|
|
|
|
|
EquipAlarmDefine define = new();
|
|
|
|
|
int rows = row - 2;
|
|
|
|
|
define.EquipTypeCode = Convert.ToInt16(dt.Rows[rows]["设备类型编码"]);
|
|
|
|
|
define.EquipTypeCode = Convert.ToInt16(dt.Rows[rows]["设备类型编码"]);
|
|
|
|
|
define.EquipCode = dt.Rows[rows]["设备编码"] == null ? "" : dt.Rows[rows]["设备编码"].ToString();
|
|
|
|
|
define.ErrorCode= dt.Rows[rows]["报警编码"] == null ? "" : dt.Rows[rows]["报警编码"].ToString();
|
|
|
|
|
define.ErrorLevel= dt.Rows[rows]["报警编码"] == null ? "" : dt.Rows[rows]["报警编码"].ToString();
|
|
|
|
|
define.ErrorMsg= dt.Rows[rows]["报警等级"] == null ? "" : dt.Rows[rows]["报警等级"].ToString();
|
|
|
|
|
define.ProcessMethod= dt.Rows[rows]["报警描述"] == null ? "" : dt.Rows[rows]["报警描述"].ToString();
|
|
|
|
|
lstEquipAlarmDefine.Add(define);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 找出两个列表中的重复项
|
|
|
|
|
var duplicates = lstEquipAlarmDefine.Join(lstEquipAlarmDefinesql,
|
|
|
|
|
l1 => new { l1.EquipTypeCode, l1.EquipCode, l1.ErrorCode },
|
|
|
|
|
l2 => new { l2.EquipTypeCode, l2.EquipCode, l2.ErrorCode },
|
|
|
|
|
(l1, l2) => l1)
|
|
|
|
|
.Distinct() // 确保没有重复添加(理论上如果Join条件正确,这里不需要Distinct)
|
|
|
|
|
.ToList();
|
|
|
|
|
if (duplicates.Count <= 0)
|
|
|
|
|
{
|
|
|
|
|
BaseDal.Insert(lstEquipAlarmDefine);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return "内容中有重复项";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return "内容中有重复项";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "请选择导出的数据";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询需要导出换电订单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="swapOrder"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<List<EquipAlarmDefine>> QueryEquipAlarmDefineListAsync(EquipAlarmDefineReq req)
|
|
|
|
|
{
|
|
|
|
|
Expression<Func<EquipAlarmDefine, bool>> where = null;
|
|
|
|
|
ParameterExpression parameter = Expression.Parameter(typeof(EquipAlarmDefine), "u");
|
|
|
|
|
|
|
|
|
|
#region 构建动态查询树
|
|
|
|
|
|
|
|
|
|
where = queryTree(req, where, parameter);
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
// 查询需要导出充电订单 不分页
|
|
|
|
|
return await _elecPriceModelVersionRepository.QueryEquipAlarmDefineList(where);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Expression<Func<EquipAlarmDefine, bool>>? queryTree(EquipAlarmDefineReq req,
|
|
|
|
|
Expression<Func<EquipAlarmDefine, bool>>? where, ParameterExpression parameter)
|
|
|
|
|
{
|
|
|
|
|
if (req.Id!=null)
|
|
|
|
|
{
|
|
|
|
|
Expression<Func<EquipAlarmDefine, bool>> condition2Expr = u => u.Id == req.Id;
|
|
|
|
|
where = where == null
|
|
|
|
|
? condition2Expr
|
|
|
|
|
: Expression.Lambda<Func<EquipAlarmDefine, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
|
|
|
|
|
parameter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(req.EquipCode))
|
|
|
|
|
{
|
|
|
|
|
Expression<Func<EquipAlarmDefine, bool>> condition2Expr = u => u.EquipCode == req.EquipCode;
|
|
|
|
|
where = where == null
|
|
|
|
|
? condition2Expr
|
|
|
|
|
: Expression.Lambda<Func<EquipAlarmDefine, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
|
|
|
|
|
parameter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(req.ErrorCode))
|
|
|
|
|
{
|
|
|
|
|
Expression<Func<EquipAlarmDefine, bool>> condition2Expr = u => u.ErrorCode == req.ErrorCode;
|
|
|
|
|
where = where == null
|
|
|
|
|
? condition2Expr
|
|
|
|
|
: Expression.Lambda<Func<EquipAlarmDefine, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
|
|
|
|
|
parameter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(req.ErrorLevel))
|
|
|
|
|
{
|
|
|
|
|
Expression<Func<EquipAlarmDefine, bool>> condition2Expr = u => u.ErrorLevel == req.ErrorLevel;
|
|
|
|
|
where = where == null
|
|
|
|
|
? condition2Expr
|
|
|
|
|
: Expression.Lambda<Func<EquipAlarmDefine, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
|
|
|
|
|
parameter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (req.ErrorMsg != null)
|
|
|
|
|
{
|
|
|
|
|
Expression<Func<EquipAlarmDefine, bool>> condition2Expr = u => u.ErrorMsg == req.ErrorMsg;
|
|
|
|
|
where = where == null
|
|
|
|
|
? condition2Expr
|
|
|
|
|
: Expression.Lambda<Func<EquipAlarmDefine, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (req.ProcessMethod != null)
|
|
|
|
|
{
|
|
|
|
|
Expression<Func<EquipAlarmDefine, bool>> condition2Expr = u => u.ProcessMethod == req.ProcessMethod;
|
|
|
|
|
where = where == null
|
|
|
|
|
? condition2Expr
|
|
|
|
|
: Expression.Lambda<Func<EquipAlarmDefine, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
|
|
|
|
|
parameter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return where;
|
|
|
|
|
}
|
|
|
|
|
}
|