报警查询

master
rszn 6 months ago
parent 83244ba0d6
commit 9ef9d0811b

@ -0,0 +1,9 @@
namespace Common.Const;
public enum EquipmentType
{
Charger,
Ammeter,
WaterCool,
Plc
}

@ -9,35 +9,15 @@ public class ExportDb
private static readonly string[] UsedTable = private static readonly string[] UsedTable =
{ {
"t_bs_charging_bin_info", "equip_alarm_define",
"t_bs_cloud_charge_model_recv_record", "equip_alarm_record",
"t_bs_cloud_elec_price_recv_record", "equip_alarm_process_record"
"t_bs_eqm_fault_base_info",
"t_bs_net_cloud_param_info",
"t_bs_net_eqm_param_info",
"t_bs_station_config_info",
"t_bs_station_elec_price_info",
"t_bs_station_info",
"t_cb_amt_order_info",
"t_cb_station_order_batt_log_info",
"t_cb_station_order_sended_log",
"t_cb_station_order_state_log",
"t_fl_repaired_info",
"t_fl_un_repair_info",
"t_rm_charger_record_report",
"t_ss_authority_to_role",
"t_ss_button_info",
"t_ss_menu_info",
"t_ss_role_info",
"t_ss_user_info",
"t_ss_user_to_role"
}; };
private readonly SqlSugarClient Db = new(new ConnectionConfig private readonly SqlSugarClient Db = new(new ConnectionConfig
{ {
ConnectionString = ConnectionString =
//"server=106.12.36.89;Database=chassis_track_swap0;Uid=remote_user;Pwd=Rszn123;Charset=utf8;", "server=180.76.133.253;Port=16306;Database=huanneng_dev;Uid=root;Pwd=Rszn123;Charset=utf8;",
"server=127.0.0.1;Port=3306;Database=huanneng_dev;Uid=root;Pwd=anyixing2023!@#;Charset=utf8;",
DbType = DbType.MySql, DbType = DbType.MySql,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute InitKeyType = InitKeyType.Attribute
@ -55,5 +35,30 @@ public class ExportDb
foreach (var columnInfo in columnInfos) foreach (var columnInfo in columnInfos)
Log.Info($" {columnInfo.DbColumnName}:{columnInfo.ColumnDescription}"); Log.Info($" {columnInfo.DbColumnName}:{columnInfo.ColumnDescription}");
} }
Db.DbFirst
.Where(it => UsedTable.Contains(it))
.IsCreateAttribute() //创建sqlsugar自带特性
.FormatFileName(ToPascalCase) //格式化文件名(文件名和表名不一样情况)
.FormatClassName(ToPascalCase) //格式化类名 (类名和表名不一样的情况)
.FormatPropertyName(ToPascalCase) //格式化属性名 (属性名和字段名不一样情况)
.CreateClassFile("D:\\RiderProjects\\hn_back_main\\Entity\\DbModel\\Station",
"Entity.DbModel.Station");
}
static string ToPascalCase(string input)
{
if (string.IsNullOrEmpty(input))
return input;
string[] strings = input.Split("_");
string res = "";
foreach (var s in strings)
{
string first = s.First().ToString().ToUpper();
string te = first + s.Substring(1);
res += te;
}
return res;
} }
} }

@ -13,7 +13,8 @@ internal class Program
{ {
XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\log4net.xml")); XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\log4net.xml"));
string str = "{\n\"header\":{\n\"cmd\":\"amtBat\",\n\"id\":1,\n\"sid\":\"xxxx\"\n},\n\"body\":{\n\"sn\": \"xxxx\",\n\"cn\": \"xxxx\",\n\"bn\": \"xxxx\",\n\"bm\": \"xxxx\",\n\"at\": \"2020-11-20 18:23:06\",\n\"am\": 30\n}\n}";
Log.Info(str); ExportDb exportDb = new ExportDb();
exportDb.Export();
} }
} }

@ -0,0 +1,9 @@
using HybirdFrameworkCore.Entity;
namespace Entity.Api.Req;
public class QueryAlarmReq : QueryPageModel
{
public int TypeCode { get; set; } = -1;
public string? EquipCode { get; set; }
}

@ -0,0 +1,103 @@
using SqlSugar;
namespace Entity.DbModel.Station
{
///<summary>
///设备报警记录
///</summary>
[SugarTable("equip_alarm_define")]
public partial class EquipAlarmDefine
{
public EquipAlarmDefine()
{
}
/// <summary>
/// Desc:id
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")]
public int Id { get; set; }
/// <summary>
/// Desc:设备类型编码
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "equip_type_code")]
public int EquipTypeCode { get; set; }
/// <summary>
/// Desc:设备编码
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "equip_code")]
public string EquipCode { get; set; }
/// <summary>
/// Desc:报警编码
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "error_code")]
public string ErrorCode { get; set; }
/// <summary>
/// Desc:报警等级
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "error_level")]
public string ErrorLevel { get; set; }
/// <summary>
/// Desc:报警描述
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "error_msg")]
public string ErrorMsg { get; set; }
/// <summary>
/// Desc:处理方法
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "process_method")]
public string ProcessMethod { get; set; }
/// <summary>
/// Desc:创建人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "created_by")]
public string CreatedBy { get; set; }
/// <summary>
/// Desc:创建时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "created_time")]
public DateTime? CreatedTime { get; set; }
/// <summary>
/// Desc:更新人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "updated_by")]
public string UpdatedBy { get; set; }
/// <summary>
/// Desc:更新时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "updated_time")]
public DateTime? UpdatedTime { get; set; }
}
}

@ -1,7 +1,4 @@
using System; using SqlSugar;
using System.Linq;
using System.Text;
using SqlSugar;
namespace Entity.DbModel.Station namespace Entity.DbModel.Station
{ {
@ -20,10 +17,6 @@ namespace Entity.DbModel.Station
//TODO 数据库字段未设计完 //TODO 数据库字段未设计完
/// <summary> /// <summary>
/// Desc:创建人 /// Desc:创建人
/// Default: /// Default:
@ -55,6 +48,5 @@ namespace Entity.DbModel.Station
/// </summary> /// </summary>
[SugarColumn(ColumnName = "updated_time")] [SugarColumn(ColumnName = "updated_time")]
public DateTime? UpdatedTime { get; set; } public DateTime? UpdatedTime { get; set; }
} }
} }

@ -1,7 +1,4 @@
using System; using SqlSugar;
using System.Linq;
using System.Text;
using SqlSugar;
namespace Entity.DbModel.Station namespace Entity.DbModel.Station
{ {
@ -11,41 +8,104 @@ namespace Entity.DbModel.Station
[SugarTable("equip_alarm_process_record")] [SugarTable("equip_alarm_process_record")]
public partial class EquipAlarmProcessRecord public partial class EquipAlarmProcessRecord
{ {
public EquipAlarmProcessRecord(){ public EquipAlarmProcessRecord()
{
}
}
/// <summary>
/// Desc:创建人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="created_by")]
public string CreatedBy {get;set;}
/// <summary>
/// Desc:创建时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="created_time")]
public DateTime? CreatedTime {get;set;}
/// <summary>
/// Desc:更新人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="updated_by")]
public string UpdatedBy {get;set;}
/// <summary>
/// Desc:更新时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="updated_time")]
public DateTime? UpdatedTime {get;set;}
/// <summary>
/// Desc:id
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(ColumnName = "id")]
public int Id { get; set; }
/// <summary>
/// Desc:设备类型编码
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "equip_type_code")]
public int EquipTypeCode { get; set; }
/// <summary>
/// Desc:设备编码
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "equip_code")]
public string EquipCode { get; set; }
/// <summary>
/// Desc:报警编码
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "error_code")]
public string ErrorCode { get; set; }
/// <summary>
/// Desc:报警等级
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "error_level")]
public string ErrorLevel { get; set; }
/// <summary>
/// Desc:报警描述
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "error_msg")]
public string ErrorMsg { get; set; }
/// <summary>
/// Desc:处理方法
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "process_method")]
public string ProcessMethod { get; set; }
/// <summary>
/// Desc:处理时间
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "process_time")]
public DateTime? ProcessTime { get; set; }
/// <summary>
/// Desc:创建人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "created_by")]
public string CreatedBy { get; set; }
/// <summary>
/// Desc:创建时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "created_time")]
public DateTime? CreatedTime { get; set; }
/// <summary>
/// Desc:更新人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "updated_by")]
public string UpdatedBy { get; set; }
/// <summary>
/// Desc:更新时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "updated_time")]
public DateTime? UpdatedTime { get; set; }
} }
} }

@ -1,7 +1,4 @@
using System; using SqlSugar;
using System.Linq;
using System.Text;
using SqlSugar;
namespace Entity.DbModel.Station namespace Entity.DbModel.Station
{ {
@ -11,41 +8,96 @@ namespace Entity.DbModel.Station
[SugarTable("equip_alarm_record")] [SugarTable("equip_alarm_record")]
public partial class EquipAlarmRecord public partial class EquipAlarmRecord
{ {
public EquipAlarmRecord(){ public EquipAlarmRecord()
{
}
}
/// <summary>
/// Desc:创建人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="created_by")]
public string CreatedBy {get;set;}
/// <summary>
/// Desc:创建时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="created_time")]
public DateTime? CreatedTime {get;set;}
/// <summary>
/// Desc:更新人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="updated_by")]
public string UpdatedBy {get;set;}
/// <summary>
/// Desc:更新时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="updated_time")]
public DateTime? UpdatedTime {get;set;}
/// <summary>
/// Desc:id
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")]
public int Id { get; set; }
/// <summary>
/// Desc:设备类型编码
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "equip_type_code")]
public int EquipTypeCode { get; set; }
/// <summary>
/// Desc:设备编码
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "equip_code")]
public string EquipCode { get; set; }
/// <summary>
/// Desc:报警编码
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "error_code")]
public string ErrorCode { get; set; }
/// <summary>
/// Desc:报警等级
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "error_level")]
public string ErrorLevel { get; set; }
/// <summary>
/// Desc:报警描述
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "error_msg")]
public string ErrorMsg { get; set; }
/// <summary>
/// Desc:处理方法
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "process_method")]
public string ProcessMethod { get; set; }
/// <summary>
/// Desc:创建人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "created_by")]
public string CreatedBy { get; set; }
/// <summary>
/// Desc:创建时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "created_time")]
public DateTime? CreatedTime { get; set; }
/// <summary>
/// Desc:更新人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "updated_by")]
public string UpdatedBy { get; set; }
/// <summary>
/// Desc:更新时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "updated_time")]
public DateTime? UpdatedTime { get; set; }
} }
} }

@ -13,7 +13,7 @@ public class IPage<T>
public IPage(int total, QueryPageModel page, List<T>? rows) public IPage(int total, QueryPageModel page, List<T>? rows)
{ {
Total = total; Total = total;
PageNum = page.Page; PageNum = page.PageNum;
PageSize = page.PageSize; PageSize = page.PageSize;
Rows = rows; Rows = rows;
} }

@ -5,7 +5,7 @@ public class QueryPageModel
/// <summary> /// <summary>
///页码 ///页码
/// </summary> /// </summary>
public int Page { get; set; } = 1; public int PageNum { get; set; } = 1;
/// <summary> /// <summary>
/// 页数 /// 页数
/// </summary> /// </summary>

@ -8,12 +8,14 @@
/// <summary> /// <summary>
/// 状态码 /// 状态码
/// </summary> /// </summary>
public int Status { get; set; } = 200; public int Status { get; set; } = 200;
/// <summary> /// <summary>
/// 操作是否成功 /// 操作是否成功
/// </summary> /// </summary>
public bool IsSuccess { get; set; } = false; public bool IsSuccess { get; set; } = false;
/// <summary> /// <summary>
/// 返回信息 /// 返回信息
/// </summary> /// </summary>
@ -29,12 +31,11 @@
/// </summary> /// </summary>
/// <param name="msg">消息</param> /// <param name="msg">消息</param>
/// <returns></returns> /// <returns></returns>
public static Result<T> Success(string msg = "成功") public static Result<T> Success(T t = default)
{ {
return Message(true, msg, default); return Message(true, "成功", t);
} }
/// <summary> /// <summary>
/// 返回成功 /// 返回成功
@ -46,9 +47,8 @@
{ {
return Message(true, msg, data); return Message(true, msg, data);
} }
/// <summary> /// <summary>
/// 返回失败 /// 返回失败
/// </summary> /// </summary>
@ -58,8 +58,8 @@
{ {
return Message(false, msg, default); return Message(false, msg, default);
} }
/// <summary> /// <summary>
/// 返回失败 /// 返回失败
/// </summary> /// </summary>
@ -70,7 +70,7 @@
{ {
return Message(false, msg, data); return Message(false, msg, data);
} }
/// <summary> /// <summary>
/// 返回消息 /// 返回消息
/// </summary> /// </summary>
@ -82,7 +82,7 @@
{ {
return new Result<T>() { Msg = msg, Data = data, IsSuccess = success }; return new Result<T>() { Msg = msg, Data = data, IsSuccess = success };
} }
/// <summary> /// <summary>
/// 返回消息 /// 返回消息
/// </summary> /// </summary>
@ -90,15 +90,9 @@
/// <param name="msg">消息</param> /// <param name="msg">消息</param>
/// <param name="data">数据</param> /// <param name="data">数据</param>
/// <returns></returns> /// <returns></returns>
public static Result<T> Message(bool success, T data) public static Result<T> Message(bool success, T data)
{ {
return new Result<T>() { Msg="查询成功", Data = data, IsSuccess = success }; return new Result<T>() { Msg = "查询成功", Data = data, IsSuccess = success };
} }
} }
} }

@ -1,7 +1,7 @@
namespace HybirdFrameworkDriver.ModbusTcpMaster; namespace HybirdFrameworkDriver.ModbusTcpMaster;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
public class ModbusProperty<T> : IModbusProperty public class ModbusProperty<T> : IModbusProperty
@ -16,7 +16,7 @@ public class ModbusProperty<T> : IModbusProperty
/// <param name="round">保留几位小数</param> /// <param name="round">保留几位小数</param>
/// <param name="offset">偏移量</param> /// <param name="offset">偏移量</param>
public ModbusProperty(int registerNo, int start = 0, int length = 1, ModbusDataType type = ModbusDataType.Register, public ModbusProperty(int registerNo, int start = 0, int length = 1, ModbusDataType type = ModbusDataType.Register,
double scale = 1, int round = 0, double offset = 0) double scale = 1, int round = 0, double offset = 0, T value=default)
{ {
RegisterNo = registerNo; RegisterNo = registerNo;
Start = start; Start = start;
@ -25,6 +25,7 @@ public class ModbusProperty<T> : IModbusProperty
Scale = scale; Scale = scale;
Round = round; Round = round;
Offset = offset; Offset = offset;
Value = value;
} }
/// <summary> /// <summary>
@ -63,4 +64,4 @@ public enum ModbusDataType
{ {
Bit, Bit,
Register Register
} }

@ -29,6 +29,12 @@ public abstract class BaseRepository<T> where T : class, new()
.InSingle(pkValue); .InSingle(pkValue);
} }
public ISugarQueryable<T> Queryable(bool blUseNoLock = false)
{
return DbBaseClient
.Queryable<T>().WithNoLockOrNot(blUseNoLock);
}
/// <summary> /// <summary>
/// 根据主值查询单条数据 /// 根据主值查询单条数据
/// </summary> /// </summary>
@ -109,7 +115,7 @@ public abstract class BaseRepository<T> where T : class, new()
.Queryable<T>() .Queryable<T>()
.Where(predicate) .Where(predicate)
.WithNoLockOrNot(false) .WithNoLockOrNot(false)
.ToPageList(page.Page, page.PageSize, ref totalCount); .ToPageList(page.PageNum, page.PageSize, ref totalCount);
@ -135,7 +141,7 @@ public abstract class BaseRepository<T> where T : class, new()
.Queryable<T>() .Queryable<T>()
.Where(predicate) .Where(predicate)
.WithNoLockOrNot(false) .WithNoLockOrNot(false)
.ToPageListAsync(page.Page, page.PageSize, totalCount); .ToPageListAsync(page.PageNum, page.PageSize, totalCount);
@ -159,7 +165,7 @@ public abstract class BaseRepository<T> where T : class, new()
List<T> pageList = DbBaseClient List<T> pageList = DbBaseClient
.Queryable<T>() .Queryable<T>()
.WithNoLockOrNot(false) .WithNoLockOrNot(false)
.ToPageList(page.Page, page.PageSize, ref totalCount); .ToPageList(page.PageNum, page.PageSize, ref totalCount);
return new IPage<T>(totalCount, page, pageList); return new IPage<T>(totalCount, page, pageList);
} }
@ -176,7 +182,7 @@ public abstract class BaseRepository<T> where T : class, new()
List<T> pageList = await DbBaseClient List<T> pageList = await DbBaseClient
.Queryable<T>() .Queryable<T>()
.WithNoLockOrNot(false) .WithNoLockOrNot(false)
.ToPageListAsync(page.Page, page.PageSize, totalCount); .ToPageListAsync(page.PageNum, page.PageSize, totalCount);
return new IPage<T>(totalCount, page, pageList); return new IPage<T>(totalCount, page, pageList);
} }
@ -725,7 +731,7 @@ public abstract class BaseRepository<T> where T : class, new()
.ToList(); .ToList();
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <typeparam name="T2"></typeparam> /// <typeparam name="T2"></typeparam>
@ -779,7 +785,7 @@ public abstract class BaseRepository<T> where T : class, new()
.Insertable(entity) .Insertable(entity)
.ExecuteReturnEntity(); .ExecuteReturnEntity();
} }
/// <summary> /// <summary>
/// 写入或者更新实体数据 /// 写入或者更新实体数据
/// </summary> /// </summary>
@ -1704,4 +1710,4 @@ public abstract class BaseRepository<T> where T : class, new()
} }

@ -0,0 +1,27 @@
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using SqlSugar;
namespace Repository.Station;
[Scope]
public class EquipAlarmDefineRepository : BaseRepository<EquipAlarmDefine>
{
public EquipAlarmDefineRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{
}
/// <summary>
///
/// </summary>
/// <param name="equipTypeCode">0-充电机;1-电表2-水冷3-plc</param>
/// <param name="equipCode"></param>
/// <param name="errorCode"></param>
/// <returns></returns>
public EquipAlarmDefine? SelectByEquipCodeAndErrorCode(int equipTypeCode, string equipCode, string errorCode)
{
return this.QueryByClause(it => it.EquipTypeCode == equipTypeCode &&
it.EquipCode == equipCode && it.ErrorCode == errorCode);
}
}

@ -0,0 +1,13 @@
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using SqlSugar;
namespace Repository.Station;
[Scope]
public class EquipAlarmProcessRecordRepository : BaseRepository<EquipAlarmProcessRecord>
{
public EquipAlarmProcessRecordRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{
}
}

@ -0,0 +1,19 @@
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using SqlSugar;
namespace Repository.Station;
[Scope]
public class EquipAlarmRecordRepository : BaseRepository<EquipAlarmRecord>
{
public EquipAlarmRecordRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{
}
public EquipAlarmRecord? SelectByEquipCodeAndErrorCode(int equipTypeCode, string equipCode, string errorCode)
{
return this.QueryByClause(it => it.EquipTypeCode == equipTypeCode &&
it.EquipCode == equipCode && it.ErrorCode == errorCode);
}
}

@ -20,7 +20,7 @@ namespace Service.Ammeter
{ {
QueryPageModel queryPageModel1 = new QueryPageModel QueryPageModel queryPageModel1 = new QueryPageModel
{ {
Page = queryPageModel.Page, PageNum = queryPageModel.Page,
PageSize = queryPageModel.PageSize, PageSize = queryPageModel.PageSize,
}; };
if (!string.IsNullOrEmpty(queryPageModel.Code)) if (!string.IsNullOrEmpty(queryPageModel.Code))

@ -21,7 +21,7 @@ namespace Service.Ammeter
{ {
QueryPageModel queryPageModel1 = new QueryPageModel QueryPageModel queryPageModel1 = new QueryPageModel
{ {
Page = queryPageModel.Page, PageNum = queryPageModel.Page,
PageSize = queryPageModel.PageSize, PageSize = queryPageModel.PageSize,
}; };
if (!string.IsNullOrEmpty(queryPageModel.Code)) if (!string.IsNullOrEmpty(queryPageModel.Code))

@ -21,7 +21,7 @@ namespace Service.Ammeter
{ {
QueryPageModel queryPageModel1 = new QueryPageModel QueryPageModel queryPageModel1 = new QueryPageModel
{ {
Page = queryPageModel.Page, PageNum = queryPageModel.Page,
PageSize = queryPageModel.PageSize, PageSize = queryPageModel.PageSize,
}; };
if (!string.IsNullOrEmpty(queryPageModel.Code)) if (!string.IsNullOrEmpty(queryPageModel.Code))

@ -23,7 +23,7 @@ namespace Service.Ammeter
{ {
QueryPageModel queryPageModel1 = new QueryPageModel QueryPageModel queryPageModel1 = new QueryPageModel
{ {
Page = queryPageModel.Page, PageNum = queryPageModel.Page,
PageSize = queryPageModel.PageSize, PageSize = queryPageModel.PageSize,
}; };
if (!string.IsNullOrEmpty(queryPageModel.Code)) if (!string.IsNullOrEmpty(queryPageModel.Code))

@ -1,28 +1,34 @@
using Entity.DbModel.Station; using Common.Const;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Const; using HybirdFrameworkCore.Const;
using HybirdFrameworkDriver.ModbusTcpMaster; using HybirdFrameworkDriver.ModbusTcpMaster;
using log4net;
using Repository.Station; using Repository.Station;
using Service.Plc.Msg; using Service.Plc.Msg;
namespace Service.Plc.Client; namespace Service.Plc.Client;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[Scope] [Scope]
public class PlcClient : ModbusTcpMaster public class PlcClient : ModbusTcpMaster
{ {
private BinInfoRepository _binInfoRepository;
public PlcClient(BinInfoRepository binInfoRepository) private static readonly ILog Log = LogManager.GetLogger(typeof(PlcClient));
public BinInfoRepository BinInfoRepository { get; set; }
public EquipAlarmDefineRepository EquipAlarmDefineRepository { get; set; }
public EquipAlarmRecordRepository EquipAlarmRecordRepository { get; set; }
public EquipAlarmProcessRecordRepository EquipAlarmProcessRecordRepository { get; set; }
public PlcClient()
{ {
ReadAction = BatchRead; ReadAction = BatchRead;
Ip = "172.0.20.66"; Ip = "172.0.20.66";
Port = 502; Port = 502;
Duration = 1000; Duration = 1000;
AutoReConnect = true; AutoReConnect = true;
_binInfoRepository = binInfoRepository;
ByteSeq = EndingConst.ByteSeq.BA; ByteSeq = EndingConst.ByteSeq.BA;
WordSeq= EndingConst.WordSeq.CD; WordSeq= EndingConst.WordSeq.CD;
} }
@ -60,16 +66,73 @@ public class PlcClient : ModbusTcpMaster
var bytes03 = master.BatchReadHolderRegister(701, 10); var bytes03 = master.BatchReadHolderRegister(701, 10);
if (bytes03 != null) if (bytes03 != null)
{ {
PlcMgr.LastPlcFaultData = PlcMgr.PlcFaultData;
PlcMgr.DataValidityTime = DateTime.Now; PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData, EndingConst.ByteSeq.AB, ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData, EndingConst.ByteSeq.AB,
EndingConst.WordSeq.DC); EndingConst.WordSeq.DC);
SaveAlarmInfo(PlcMgr.LastPlcFaultData.ErrorCode01.Value, PlcMgr.PlcFaultData.ErrorCode01.Value);
SaveAlarmInfo(PlcMgr.LastPlcFaultData.ErrorCode03.Value, PlcMgr.PlcFaultData.ErrorCode03.Value);
SaveAlarmInfo(PlcMgr.LastPlcFaultData.ErrorCode05.Value, PlcMgr.PlcFaultData.ErrorCode05.Value);
SaveAlarmInfo(PlcMgr.LastPlcFaultData.ErrorCode07.Value, PlcMgr.PlcFaultData.ErrorCode07.Value);
SaveAlarmInfo(PlcMgr.LastPlcFaultData.ErrorCode09.Value, PlcMgr.PlcFaultData.ErrorCode09.Value);
}
}
private void SaveAlarmInfo(int lastErrorCode, int errorCode)
{
if (lastErrorCode == errorCode)
{
return;
} }
string plc = "plc";
if (errorCode != 0)
{
EquipAlarmDefine? alarmDefine = EquipAlarmDefineRepository.SelectByEquipCodeAndErrorCode((int)EquipmentType.Plc, plc, errorCode.ToString());
if (alarmDefine == null)
{
Log.Error($"error code {errorCode} has no define");
return;
}
EquipAlarmRecord record = new EquipAlarmRecord()
{
EquipTypeCode = alarmDefine.EquipTypeCode,
EquipCode = alarmDefine.EquipCode,
ErrorCode = alarmDefine.ErrorCode,
ErrorLevel = alarmDefine.ErrorLevel,
ErrorMsg = alarmDefine.ErrorMsg,
ProcessMethod = alarmDefine.ProcessMethod
};
EquipAlarmRecordRepository.Insert(record);
}
else
{
EquipAlarmRecord? alarmRecord = EquipAlarmRecordRepository.SelectByEquipCodeAndErrorCode((int)EquipmentType.Plc, plc, errorCode.ToString());
if (alarmRecord != null)
{
EquipAlarmProcessRecord processRecord = new EquipAlarmProcessRecord()
{
EquipTypeCode = alarmRecord.EquipTypeCode,
EquipCode = alarmRecord.EquipCode,
ErrorCode =alarmRecord.EquipCode,
ErrorLevel = alarmRecord.ErrorLevel,
ErrorMsg = alarmRecord.ErrorMsg,
ProcessMethod = alarmRecord.ProcessMethod,
ProcessTime = DateTime.Now
};
EquipAlarmProcessRecordRepository.Insert(processRecord);
EquipAlarmRecordRepository.DeleteById(alarmRecord.Id);
}
}
} }
private void UpdateBinInfo(int exists, string binNo) private void UpdateBinInfo(int exists, string binNo)
{ {
if (exists == 0) if (exists == 0)
_binInfoRepository.Update( BinInfoRepository.Update(
it => it =>
new BinInfo(){ new BinInfo(){
Exists = 0, Exists = 0,
@ -77,12 +140,12 @@ public class PlcClient : ModbusTcpMaster
Soc = (decimal)-1, Soc = (decimal)-1,
Soe = (decimal)-1, Soe = (decimal)-1,
Soh = (decimal)-1, Soh = (decimal)-1,
}, },
it => it.No == binNo); it => it.No == binNo);
else else
_binInfoRepository.Update(it => it.Exists == 1, BinInfoRepository.Update(it => it.Exists == 1,
it => it.No == binNo); it => it.No == binNo);
} }
} }

@ -1,5 +1,4 @@
using Autofac; using Autofac;
using log4net;
using HslCommunication; using HslCommunication;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Utils; using HybirdFrameworkCore.Utils;
@ -13,6 +12,7 @@ public class PlcMgr
public static PlcClient? PlcClient; public static PlcClient? PlcClient;
public static readonly HostToPlc HostToPlcData = new HostToPlc(); public static readonly HostToPlc HostToPlcData = new HostToPlc();
public static readonly PlcToHost PlcToHostData = new PlcToHost(); public static readonly PlcToHost PlcToHostData = new PlcToHost();
public static PlcFault LastPlcFaultData = new PlcFault();
public static readonly PlcFault PlcFaultData = new PlcFault(); public static readonly PlcFault PlcFaultData = new PlcFault();
@ -26,14 +26,14 @@ public class PlcMgr
/// </summary> /// </summary>
public static DateTime DataValidityTime = DateTime.Now; public static DateTime DataValidityTime = DateTime.Now;
public static bool Init() public static void Init()
{ {
if (PlcClient == null) if (PlcClient == null)
{ {
PlcClient = AppInfo.Container.Resolve<PlcClient>(); PlcClient = AppInfo.Container.Resolve<PlcClient>();
} }
return PlcClient.Connect(); Task.Run(() =>PlcClient.Connect());
} }
/// <summary> /// <summary>
@ -65,12 +65,12 @@ public class PlcMgr
return false; return false;
} }
public static ushort BlowerStatus() public static ushort BlowerStatus()
{ {
if (PlcClient != null) if (PlcClient != null)
{ {
return PlcToHostData.ExhaustFanStatus.Value; return PlcToHostData.ExhaustFanStatus.Value;
} }
@ -373,4 +373,4 @@ public class PlcMgr
return bResult; return bResult;
} }
} }

@ -4,10 +4,10 @@ namespace Service.Plc.Msg
{ {
public class PlcFault public class PlcFault
{ {
public ModbusProperty<int> ErrorCode01 { get; set; } = new(40701,length :2); // 错误码 public ModbusProperty<int> ErrorCode01 { get; set; } = new(40701,length :2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode03 { get; set; } = new(40703,length :2); // 错误码 public ModbusProperty<int> ErrorCode03 { get; set; } = new(40703,length :2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode05 { get; set; } = new(40705,length :2); // 错误码 public ModbusProperty<int> ErrorCode05 { get; set; } = new(40705,length :2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode07 { get; set; } = new(40707,length :2); // 错误码 public ModbusProperty<int> ErrorCode07 { get; set; } = new(40707,length :2, value: 0); // 错误码
public ModbusProperty<int> ErrorCode09 { get; set; } = new(40709, length: 2); // 错误码 public ModbusProperty<int> ErrorCode09 { get; set; } = new(40709, length: 2, value: 0); // 错误码
} }
} }

@ -30,7 +30,7 @@ public class ChargeOrderService : BaseServices<ChargeOrder>
/// <returns></returns> /// <returns></returns>
public PageResult<ChargeOrderResp> QueryChargeOrder(QueryChargeOrderReq chargeOrder) public PageResult<ChargeOrderResp> QueryChargeOrder(QueryChargeOrderReq chargeOrder)
{ {
//创建一个空的表达式树 //创建一个空的表达式树
Expression<Func<ChargeOrder, bool>> where = null; Expression<Func<ChargeOrder, bool>> where = null;
//// 定义参数表达式 //// 定义参数表达式
@ -125,7 +125,7 @@ public class ChargeOrderService : BaseServices<ChargeOrder>
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
@ -136,13 +136,13 @@ public class ChargeOrderService : BaseServices<ChargeOrder>
{ {
return Result<bool>.Fail("数据不存在"); return Result<bool>.Fail("数据不存在");
} }
if ( orders[0].CloudReportStatus == 1) if ( orders[0].CloudReportStatus == 1)
{ {
return Result<bool>.Success("已经上传到云平台"); return Result<bool>.Success(true, "已经上传到云平台");
} }
CloudClientMgr.CloudClient?.PublishChargeOrder(orders, 2); CloudClientMgr.CloudClient?.PublishChargeOrder(orders, 2);
return Result<bool>.Success(); return Result<bool>.Success();
} }
} }

@ -21,34 +21,34 @@ public class EquipAlarmLevelService : BaseServices<EquipAlarmLevel>
/// <summary> /// <summary>
/// 根据条件查询故障等级信息分页 /// 根据条件查询故障等级信息分页
/// </summary> /// </summary>
/// <param name="equipAlarmLevel"></param> /// <param name="equipAlarmLevel"></param>
/// <returns></returns> /// <returns></returns>
public PageResult<EquipAlarmLevelResp> QueryEqmFaultInfo(QueryEquipAlarmLevelReq equipAlarmLevel) public PageResult<EquipAlarmLevelResp> QueryEqmFaultInfo(QueryEquipAlarmLevelReq equipAlarmLevel)
{ {
//创建一个空的表达式树 //创建一个空的表达式树
Expression<Func<EquipAlarmLevel, bool>> where = null; Expression<Func<EquipAlarmLevel, bool>> where = null;
//// 定义参数表达式 //// 定义参数表达式
ParameterExpression parameter = Expression.Parameter(typeof(EquipAlarmLevel), "u"); ParameterExpression parameter = Expression.Parameter(typeof(EquipAlarmLevel), "u");
//TODO 缺少数据库字段先屏蔽 //TODO 缺少数据库字段先屏蔽
//if (!string.IsNullOrEmpty(quipAlarmLevel.Level)) //if (!string.IsNullOrEmpty(quipAlarmLevel.Level))
//{ //{
// Expression<Func<EquipAlarmLevel, bool>> condition1Expr = u => u.Level == quipAlarmLevel.Level; // Expression<Func<EquipAlarmLevel, bool>> condition1Expr = u => u.Level == quipAlarmLevel.Level;
// where = condition1Expr; // where = condition1Expr;
//} //}
//// 构建查询条件 //// 构建查询条件
//if (!string.IsNullOrEmpty(quipAlarmLevel.LevelName)) //if (!string.IsNullOrEmpty(quipAlarmLevel.LevelName))
//{ //{
// Expression<Func<EquipAlarmLevel, bool>> condition2Expr = u => u.LevelName == quipAlarmLevel.LevelName; // Expression<Func<EquipAlarmLevel, bool>> condition2Expr = u => u.LevelName == quipAlarmLevel.LevelName;
// where = where == null ? condition2Expr : Expression.Lambda<Func<EquipAlarmLevel, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); // where = where == null ? condition2Expr : Expression.Lambda<Func<EquipAlarmLevel, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
//} //}
//查询 //查询
return PageResult<EquipAlarmLevelResp>.ConvertPage(_equipAlarmLevelRepository.QueryIPageByCause(equipAlarmLevel, where)); return PageResult<EquipAlarmLevelResp>.ConvertPage(_equipAlarmLevelRepository.QueryIPageByCause(equipAlarmLevel, where));
} }
} }

@ -0,0 +1,71 @@
using Entity.Api.Req;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
using HybirdFrameworkCore.Utils;
using Repository.Station;
namespace Service.Station;
[Scope]
public class EquipAlarmRecordService : BaseServices<EquipAlarmRecord>
{
public EquipAlarmProcessRecordRepository ProcessRecordRepository { get; set; }
public EquipAlarmRecordService(EquipAlarmRecordRepository dal)
{
BaseDal = dal;
}
/// <summary>
/// 查询未处理报警列表
/// </summary>
/// <param name="typeCode">设备类型:-1-查询全部0-充电机1-电表2-水冷机3-plc<</param>
/// <param name="equipCode">设备编码</param>
/// <returns></returns>
public Result<PageResult<EquipAlarmRecord>> QueryEquipAlarmPage(QueryAlarmReq req)
{
int totalCount = 0;
int reqTypeCode = req.TypeCode;
var equipCode = req.EquipCode;
List<EquipAlarmRecord> list = BaseDal.Queryable().WhereIF(reqTypeCode != -1, it => it.EquipTypeCode == reqTypeCode)
.WhereIF(ObjUtils.IsNotNullOrWhiteSpace(equipCode), it => it.EquipCode == equipCode)
.ToPageList(req.PageNum, req.PageSize, ref totalCount);
PageResult<EquipAlarmRecord> result = new PageResult<EquipAlarmRecord>()
{
PageNum = req.PageNum,
PageSize = req.PageSize,
ToTal = totalCount,
Rows = list
};
return Result<PageResult<EquipAlarmRecord>>.Success(result);
}
/// <summary>
/// 查询已处理报警列表
/// </summary>
/// <param name="typeCode">设备类型:-1-查询全部0-充电机1-电表2-水冷机3-plc</param>
/// <param name="equipCode">设备编码</param>
/// <returns></returns>
public Result<PageResult<EquipAlarmProcessRecord>> QueryEquipAlarmProcessPage(QueryAlarmReq req)
{
int totalCount = 0;
int reqTypeCode = req.TypeCode;
var equipCode = req.EquipCode;
List<EquipAlarmProcessRecord> list = ProcessRecordRepository.Queryable().WhereIF(reqTypeCode != -1, it => it.EquipTypeCode == reqTypeCode)
.WhereIF(ObjUtils.IsNotNullOrWhiteSpace(equipCode), it => it.EquipCode == equipCode)
.ToPageList(req.PageNum, req.PageSize, ref totalCount);
PageResult<EquipAlarmProcessRecord> result = new PageResult<EquipAlarmProcessRecord>()
{
PageNum = req.PageNum,
PageSize = req.PageSize,
ToTal = totalCount,
Rows = list
};
return Result<PageResult<EquipAlarmProcessRecord>>.Success(result);
}
}

@ -47,13 +47,13 @@ public class ChargeOrderController : ControllerBase
if (chargeOrderService.Update(chargeOrder)) if (chargeOrderService.Update(chargeOrder))
{ {
return Result<bool>.Success("更改成功"); return Result<bool>.Success(true,"更改成功");
} }
else else
{ {
return Result<bool>.Fail("更改失败"); return Result<bool>.Fail("更改失败");
} }
} }
/// <summary> /// <summary>
@ -65,4 +65,4 @@ public class ChargeOrderController : ControllerBase
{ {
return chargeOrderService.Upload2Cloud(id); return chargeOrderService.Upload2Cloud(id);
} }
} }

@ -63,7 +63,7 @@ public class EquipAlarmLevelController : ControllerBase
// 更改 // 更改
return Result<bool>.Success("插入成功"); return Result<bool>.Success(true, "插入成功");
} }
} }
@ -83,7 +83,7 @@ public class EquipAlarmLevelController : ControllerBase
if (equipAlarmLevelService.Update(baseEqmFaultLevel)) if (equipAlarmLevelService.Update(baseEqmFaultLevel))
{ {
return Result<bool>.Success("更改成功"); return Result<bool>.Success(true,"更改成功");
} }
else else
{ {
@ -102,11 +102,11 @@ public class EquipAlarmLevelController : ControllerBase
{ {
if (equipAlarmLevelService.DeleteByIds(ids)) if (equipAlarmLevelService.DeleteByIds(ids))
{ {
return Result<bool>.Success("删除成功"); return Result<bool>.Success(true,"删除成功");
} }
else else
{ {
return Result<bool>.Fail("删除失败"); return Result<bool>.Fail("删除失败");
} }
} }
} }

@ -0,0 +1,46 @@
using Entity.Api.Req;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc;
using Service.Station;
namespace WebStarter.Controllers;
/// <summary>
/// 换电设备报警
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class EquipAlarmRecordController : ControllerBase
{
private readonly EquipAlarmRecordService equipAlarmRecordService;
public EquipAlarmRecordController(EquipAlarmRecordService equipAlarmRecordService)
{
this.equipAlarmRecordService = equipAlarmRecordService;
}
/// <summary>
/// 查询未处理报警列表
/// </summary>
/// <param name="typeCode">设备类型:-1-查询全部0-充电机1-电表2-水冷机3-plc<</param>
/// <param name="equipCode">设备编码</param>
/// <returns></returns>
[HttpPost("/QueryEquipAlarmPage")]
public Result<PageResult<EquipAlarmRecord>> QueryEquipAlarmPage([FromBody] QueryAlarmReq req)
{
return equipAlarmRecordService.QueryEquipAlarmPage(req);
}
/// <summary>
/// 查询已处理报警列表
/// </summary>
/// <param name="typeCode">设备类型:-1-查询全部0-充电机1-电表2-水冷机3-plc</param>
/// <param name="equipCode">设备编码</param>
/// <returns></returns>
[HttpPost("/QueryEquipAlarmProcessPage")]
public Result<PageResult<EquipAlarmProcessRecord>> QueryEquipAlarmProcessPage([FromBody] QueryAlarmReq req)
{
return equipAlarmRecordService.QueryEquipAlarmProcessPage(req);
}
}

@ -4,9 +4,7 @@ using Entity.Api.Resp;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using Service.Station; using Service.Station;
using System.Collections.Generic;
namespace WebStarter.Controllers; namespace WebStarter.Controllers;
@ -99,7 +97,7 @@ public class SwapOrderController : ControllerBase
else else
{ {
swapOrderService.Insert(swapOrder); swapOrderService.Insert(swapOrder);
return Result<bool>.Success("新增成功"); return Result<bool>.Success(true,"新增成功");
} }
} }
@ -118,7 +116,7 @@ public class SwapOrderController : ControllerBase
if (swapOrderService.Update(swapOrder)) if (swapOrderService.Update(swapOrder))
{ {
return Result<bool>.Success("更改成功"); return Result<bool>.Success(true,"更改成功");
} }
else else
{ {
@ -136,7 +134,7 @@ public class SwapOrderController : ControllerBase
{ {
if (swapOrderService.DeleteByIds(ids)) if (swapOrderService.DeleteByIds(ids))
{ {
return Result<bool>.Success("删除成功"); return Result<bool>.Success(true,"删除成功");
} }
else else
{ {
@ -152,7 +150,7 @@ public class SwapOrderController : ControllerBase
[HttpGet("UploadCloud/{id}")] [HttpGet("UploadCloud/{id}")]
public Result<bool> UploadCloud(int id) public Result<bool> UploadCloud(int id)
{ {
return swapOrderService.UploadCloud(id); return swapOrderService.UploadCloud(id);
} }
} }

@ -1,7 +1,5 @@
using AutoMapper;
using Entity.Api.Req; using Entity.Api.Req;
using Entity.Api.Resp; using Entity.Api.Resp;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Service.Station; using Service.Station;
@ -48,7 +46,7 @@ public class SwapOrderStepController : ControllerBase
{ {
if (swapOrderStepService.DeleteByIds(ids)) if (swapOrderStepService.DeleteByIds(ids))
{ {
return Result<bool>.Success("删除成功"); return Result<bool>.Success(true,"删除成功");
} }
else else
{ {
@ -56,4 +54,4 @@ public class SwapOrderStepController : ControllerBase
} }
} }
} }

Loading…
Cancel
Save