diff --git a/Common/Const/EquipmentType.cs b/Common/Const/EquipmentType.cs new file mode 100644 index 0000000..7f6f2f4 --- /dev/null +++ b/Common/Const/EquipmentType.cs @@ -0,0 +1,9 @@ +namespace Common.Const; + +public enum EquipmentType +{ + Charger, + Ammeter, + WaterCool, + Plc +} diff --git a/ConsoleStarter/ExportDb.cs b/ConsoleStarter/ExportDb.cs index fdcfd7f..fb7bd08 100644 --- a/ConsoleStarter/ExportDb.cs +++ b/ConsoleStarter/ExportDb.cs @@ -9,35 +9,15 @@ public class ExportDb private static readonly string[] UsedTable = { - "t_bs_charging_bin_info", - "t_bs_cloud_charge_model_recv_record", - "t_bs_cloud_elec_price_recv_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" + "equip_alarm_define", + "equip_alarm_record", + "equip_alarm_process_record" }; private readonly SqlSugarClient Db = new(new ConnectionConfig { ConnectionString = - //"server=106.12.36.89;Database=chassis_track_swap0;Uid=remote_user;Pwd=Rszn123;Charset=utf8;", - "server=127.0.0.1;Port=3306;Database=huanneng_dev;Uid=root;Pwd=anyixing2023!@#;Charset=utf8;", + "server=180.76.133.253;Port=16306;Database=huanneng_dev;Uid=root;Pwd=Rszn123;Charset=utf8;", DbType = DbType.MySql, IsAutoCloseConnection = true, InitKeyType = InitKeyType.Attribute @@ -55,5 +35,30 @@ public class ExportDb foreach (var columnInfo in columnInfos) 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; } -} \ No newline at end of file +} diff --git a/ConsoleStarter/Program.cs b/ConsoleStarter/Program.cs index e6508fb..fa08bc8 100644 --- a/ConsoleStarter/Program.cs +++ b/ConsoleStarter/Program.cs @@ -13,7 +13,8 @@ internal class Program { 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(); } -} \ No newline at end of file +} diff --git a/Entity/Api/Req/QueryAlarmReq.cs b/Entity/Api/Req/QueryAlarmReq.cs new file mode 100644 index 0000000..d45a92b --- /dev/null +++ b/Entity/Api/Req/QueryAlarmReq.cs @@ -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; } +} diff --git a/Entity/DbModel/Station/EquipAlarmDefine.cs b/Entity/DbModel/Station/EquipAlarmDefine.cs new file mode 100644 index 0000000..63ca115 --- /dev/null +++ b/Entity/DbModel/Station/EquipAlarmDefine.cs @@ -0,0 +1,103 @@ +using SqlSugar; + +namespace Entity.DbModel.Station +{ + /// + ///设备报警记录 + /// + [SugarTable("equip_alarm_define")] + public partial class EquipAlarmDefine + { + public EquipAlarmDefine() + { + } + + /// + /// Desc:id + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")] + public int Id { get; set; } + + /// + /// Desc:设备类型编码 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "equip_type_code")] + public int EquipTypeCode { get; set; } + + /// + /// Desc:设备编码 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "equip_code")] + public string EquipCode { get; set; } + + /// + /// Desc:报警编码 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "error_code")] + public string ErrorCode { get; set; } + + /// + /// Desc:报警等级 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "error_level")] + public string ErrorLevel { get; set; } + + /// + /// Desc:报警描述 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "error_msg")] + public string ErrorMsg { get; set; } + + /// + /// Desc:处理方法 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "process_method")] + public string ProcessMethod { get; set; } + + /// + /// Desc:创建人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "created_by")] + public string CreatedBy { get; set; } + + /// + /// Desc:创建时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "created_time")] + public DateTime? CreatedTime { get; set; } + + /// + /// Desc:更新人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "updated_by")] + public string UpdatedBy { get; set; } + + /// + /// Desc:更新时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "updated_time")] + public DateTime? UpdatedTime { get; set; } + } +} diff --git a/Entity/DbModel/Station/EquipAlarmLevel.cs b/Entity/DbModel/Station/EquipAlarmLevel.cs index ef22194..bc319c3 100644 --- a/Entity/DbModel/Station/EquipAlarmLevel.cs +++ b/Entity/DbModel/Station/EquipAlarmLevel.cs @@ -1,7 +1,4 @@ -using System; -using System.Linq; -using System.Text; -using SqlSugar; +using SqlSugar; namespace Entity.DbModel.Station { @@ -20,10 +17,6 @@ namespace Entity.DbModel.Station //TODO 数据库字段未设计完 - - - - /// /// Desc:创建人 /// Default: @@ -55,6 +48,5 @@ namespace Entity.DbModel.Station /// [SugarColumn(ColumnName = "updated_time")] public DateTime? UpdatedTime { get; set; } - } } diff --git a/Entity/DbModel/Station/EquipAlarmProcessRecord.cs b/Entity/DbModel/Station/EquipAlarmProcessRecord.cs index 4eb0b22..bba040a 100644 --- a/Entity/DbModel/Station/EquipAlarmProcessRecord.cs +++ b/Entity/DbModel/Station/EquipAlarmProcessRecord.cs @@ -1,7 +1,4 @@ -using System; -using System.Linq; -using System.Text; -using SqlSugar; +using SqlSugar; namespace Entity.DbModel.Station { @@ -11,41 +8,104 @@ namespace Entity.DbModel.Station [SugarTable("equip_alarm_process_record")] public partial class EquipAlarmProcessRecord { - public EquipAlarmProcessRecord(){ - - - } - /// - /// Desc:创建人 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="created_by")] - public string CreatedBy {get;set;} - - /// - /// Desc:创建时间 - /// Default:CURRENT_TIMESTAMP - /// Nullable:True - /// - [SugarColumn(ColumnName="created_time")] - public DateTime? CreatedTime {get;set;} - - /// - /// Desc:更新人 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="updated_by")] - public string UpdatedBy {get;set;} - - /// - /// Desc:更新时间 - /// Default:CURRENT_TIMESTAMP - /// Nullable:True - /// - [SugarColumn(ColumnName="updated_time")] - public DateTime? UpdatedTime {get;set;} + public EquipAlarmProcessRecord() + { + } + /// + /// Desc:id + /// Default: + /// Nullable:False + /// + [SugarColumn(ColumnName = "id")] + public int Id { get; set; } + + /// + /// Desc:设备类型编码 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "equip_type_code")] + public int EquipTypeCode { get; set; } + + /// + /// Desc:设备编码 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "equip_code")] + public string EquipCode { get; set; } + + /// + /// Desc:报警编码 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "error_code")] + public string ErrorCode { get; set; } + + /// + /// Desc:报警等级 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "error_level")] + public string ErrorLevel { get; set; } + + /// + /// Desc:报警描述 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "error_msg")] + public string ErrorMsg { get; set; } + + /// + /// Desc:处理方法 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "process_method")] + public string ProcessMethod { get; set; } + + /// + /// Desc:处理时间 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "process_time")] + public DateTime? ProcessTime { get; set; } + + /// + /// Desc:创建人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "created_by")] + public string CreatedBy { get; set; } + + /// + /// Desc:创建时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "created_time")] + public DateTime? CreatedTime { get; set; } + + /// + /// Desc:更新人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "updated_by")] + public string UpdatedBy { get; set; } + + /// + /// Desc:更新时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "updated_time")] + public DateTime? UpdatedTime { get; set; } } } diff --git a/Entity/DbModel/Station/EquipAlarmRecord.cs b/Entity/DbModel/Station/EquipAlarmRecord.cs index d2d6f4a..1a4a65f 100644 --- a/Entity/DbModel/Station/EquipAlarmRecord.cs +++ b/Entity/DbModel/Station/EquipAlarmRecord.cs @@ -1,7 +1,4 @@ -using System; -using System.Linq; -using System.Text; -using SqlSugar; +using SqlSugar; namespace Entity.DbModel.Station { @@ -11,41 +8,96 @@ namespace Entity.DbModel.Station [SugarTable("equip_alarm_record")] public partial class EquipAlarmRecord { - public EquipAlarmRecord(){ - - - } - /// - /// Desc:创建人 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="created_by")] - public string CreatedBy {get;set;} - - /// - /// Desc:创建时间 - /// Default:CURRENT_TIMESTAMP - /// Nullable:True - /// - [SugarColumn(ColumnName="created_time")] - public DateTime? CreatedTime {get;set;} - - /// - /// Desc:更新人 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="updated_by")] - public string UpdatedBy {get;set;} - - /// - /// Desc:更新时间 - /// Default:CURRENT_TIMESTAMP - /// Nullable:True - /// - [SugarColumn(ColumnName="updated_time")] - public DateTime? UpdatedTime {get;set;} + public EquipAlarmRecord() + { + } + /// + /// Desc:id + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")] + public int Id { get; set; } + + /// + /// Desc:设备类型编码 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "equip_type_code")] + public int EquipTypeCode { get; set; } + + /// + /// Desc:设备编码 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "equip_code")] + public string EquipCode { get; set; } + + /// + /// Desc:报警编码 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "error_code")] + public string ErrorCode { get; set; } + + /// + /// Desc:报警等级 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "error_level")] + public string ErrorLevel { get; set; } + + /// + /// Desc:报警描述 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "error_msg")] + public string ErrorMsg { get; set; } + + /// + /// Desc:处理方法 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "process_method")] + public string ProcessMethod { get; set; } + + /// + /// Desc:创建人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "created_by")] + public string CreatedBy { get; set; } + + /// + /// Desc:创建时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "created_time")] + public DateTime? CreatedTime { get; set; } + + /// + /// Desc:更新人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "updated_by")] + public string UpdatedBy { get; set; } + + /// + /// Desc:更新时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "updated_time")] + public DateTime? UpdatedTime { get; set; } } } diff --git a/HybirdFrameworkCore/Entity/IPage.cs b/HybirdFrameworkCore/Entity/IPage.cs index b9a8d4a..69bcb57 100644 --- a/HybirdFrameworkCore/Entity/IPage.cs +++ b/HybirdFrameworkCore/Entity/IPage.cs @@ -13,7 +13,7 @@ public class IPage public IPage(int total, QueryPageModel page, List? rows) { Total = total; - PageNum = page.Page; + PageNum = page.PageNum; PageSize = page.PageSize; Rows = rows; } diff --git a/HybirdFrameworkCore/Entity/QueryPageModel.cs b/HybirdFrameworkCore/Entity/QueryPageModel.cs index 986175c..48cc3b6 100644 --- a/HybirdFrameworkCore/Entity/QueryPageModel.cs +++ b/HybirdFrameworkCore/Entity/QueryPageModel.cs @@ -5,7 +5,7 @@ public class QueryPageModel /// ///页码 /// - public int Page { get; set; } = 1; + public int PageNum { get; set; } = 1; /// /// 页数 /// diff --git a/HybirdFrameworkCore/Entity/Result.cs b/HybirdFrameworkCore/Entity/Result.cs index 2593893..ef7d03e 100644 --- a/HybirdFrameworkCore/Entity/Result.cs +++ b/HybirdFrameworkCore/Entity/Result.cs @@ -8,12 +8,14 @@ /// /// 状态码 /// - + public int Status { get; set; } = 200; + /// /// 操作是否成功 /// public bool IsSuccess { get; set; } = false; + /// /// 返回信息 /// @@ -29,12 +31,11 @@ /// /// 消息 /// - public static Result Success(string msg = "成功") + public static Result Success(T t = default) { - return Message(true, msg, default); + return Message(true, "成功", t); } - - + /// /// 返回成功 @@ -46,9 +47,8 @@ { return Message(true, msg, data); } - - - + + /// /// 返回失败 /// @@ -58,8 +58,8 @@ { return Message(false, msg, default); } - - + + /// /// 返回失败 /// @@ -70,7 +70,7 @@ { return Message(false, msg, data); } - + /// /// 返回消息 /// @@ -82,7 +82,7 @@ { return new Result() { Msg = msg, Data = data, IsSuccess = success }; } - + /// /// 返回消息 /// @@ -90,15 +90,9 @@ /// 消息 /// 数据 /// - public static Result Message(bool success, T data) + public static Result Message(bool success, T data) { - return new Result() { Msg="查询成功", Data = data, IsSuccess = success }; + return new Result() { Msg = "查询成功", Data = data, IsSuccess = success }; } - - - } - - - } diff --git a/HybirdFrameworkDriver/ModbusTcpMaster/ModbusProperty.cs b/HybirdFrameworkDriver/ModbusTcpMaster/ModbusProperty.cs index c534cde..eb7c4c2 100644 --- a/HybirdFrameworkDriver/ModbusTcpMaster/ModbusProperty.cs +++ b/HybirdFrameworkDriver/ModbusTcpMaster/ModbusProperty.cs @@ -1,7 +1,7 @@ namespace HybirdFrameworkDriver.ModbusTcpMaster; /// -/// +/// /// /// public class ModbusProperty : IModbusProperty @@ -16,7 +16,7 @@ public class ModbusProperty : IModbusProperty /// 保留几位小数 /// 偏移量 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; Start = start; @@ -25,6 +25,7 @@ public class ModbusProperty : IModbusProperty Scale = scale; Round = round; Offset = offset; + Value = value; } /// @@ -63,4 +64,4 @@ public enum ModbusDataType { Bit, Register -} \ No newline at end of file +} diff --git a/Repository/BaseRepository.cs b/Repository/BaseRepository.cs index 770092e..97f2c93 100644 --- a/Repository/BaseRepository.cs +++ b/Repository/BaseRepository.cs @@ -29,6 +29,12 @@ public abstract class BaseRepository where T : class, new() .InSingle(pkValue); } + public ISugarQueryable Queryable(bool blUseNoLock = false) + { + return DbBaseClient + .Queryable().WithNoLockOrNot(blUseNoLock); + } + /// /// 根据主值查询单条数据 /// @@ -109,7 +115,7 @@ public abstract class BaseRepository where T : class, new() .Queryable() .Where(predicate) .WithNoLockOrNot(false) - .ToPageList(page.Page, page.PageSize, ref totalCount); + .ToPageList(page.PageNum, page.PageSize, ref totalCount); @@ -135,7 +141,7 @@ public abstract class BaseRepository where T : class, new() .Queryable() .Where(predicate) .WithNoLockOrNot(false) - .ToPageListAsync(page.Page, page.PageSize, totalCount); + .ToPageListAsync(page.PageNum, page.PageSize, totalCount); @@ -159,7 +165,7 @@ public abstract class BaseRepository where T : class, new() List pageList = DbBaseClient .Queryable() .WithNoLockOrNot(false) - .ToPageList(page.Page, page.PageSize, ref totalCount); + .ToPageList(page.PageNum, page.PageSize, ref totalCount); return new IPage(totalCount, page, pageList); } @@ -176,7 +182,7 @@ public abstract class BaseRepository where T : class, new() List pageList = await DbBaseClient .Queryable() .WithNoLockOrNot(false) - .ToPageListAsync(page.Page, page.PageSize, totalCount); + .ToPageListAsync(page.PageNum, page.PageSize, totalCount); return new IPage(totalCount, page, pageList); } @@ -725,7 +731,7 @@ public abstract class BaseRepository where T : class, new() .ToList(); } /// - /// + /// /// /// /// @@ -779,7 +785,7 @@ public abstract class BaseRepository where T : class, new() .Insertable(entity) .ExecuteReturnEntity(); } - + /// /// 写入或者更新实体数据 /// @@ -1704,4 +1710,4 @@ public abstract class BaseRepository where T : class, new() -} \ No newline at end of file +} diff --git a/Repository/Station/EquipAlarmDefineRepository.cs b/Repository/Station/EquipAlarmDefineRepository.cs new file mode 100644 index 0000000..1443567 --- /dev/null +++ b/Repository/Station/EquipAlarmDefineRepository.cs @@ -0,0 +1,27 @@ +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac.Attribute; +using SqlSugar; + +namespace Repository.Station; + +[Scope] +public class EquipAlarmDefineRepository : BaseRepository +{ + public EquipAlarmDefineRepository(ISqlSugarClient sqlSugar) : base(sqlSugar) + { + } + + + /// + /// + /// + /// 0-充电机;1-电表;2-水冷;3-plc; + /// + /// + /// + public EquipAlarmDefine? SelectByEquipCodeAndErrorCode(int equipTypeCode, string equipCode, string errorCode) + { + return this.QueryByClause(it => it.EquipTypeCode == equipTypeCode && + it.EquipCode == equipCode && it.ErrorCode == errorCode); + } +} diff --git a/Repository/Station/EquipAlarmProcessRecordRepository.cs b/Repository/Station/EquipAlarmProcessRecordRepository.cs new file mode 100644 index 0000000..999c0eb --- /dev/null +++ b/Repository/Station/EquipAlarmProcessRecordRepository.cs @@ -0,0 +1,13 @@ +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac.Attribute; +using SqlSugar; + +namespace Repository.Station; + +[Scope] +public class EquipAlarmProcessRecordRepository : BaseRepository +{ + public EquipAlarmProcessRecordRepository(ISqlSugarClient sqlSugar) : base(sqlSugar) + { + } +} diff --git a/Repository/Station/EquipAlarmRecordRepository.cs b/Repository/Station/EquipAlarmRecordRepository.cs new file mode 100644 index 0000000..93266e4 --- /dev/null +++ b/Repository/Station/EquipAlarmRecordRepository.cs @@ -0,0 +1,19 @@ +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac.Attribute; +using SqlSugar; + +namespace Repository.Station; + +[Scope] +public class EquipAlarmRecordRepository : BaseRepository +{ + 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); + } +} diff --git a/Service/Ammeter/EmeterDayEnergyService.cs b/Service/Ammeter/EmeterDayEnergyService.cs index c11f760..fac4052 100644 --- a/Service/Ammeter/EmeterDayEnergyService.cs +++ b/Service/Ammeter/EmeterDayEnergyService.cs @@ -20,7 +20,7 @@ namespace Service.Ammeter { QueryPageModel queryPageModel1 = new QueryPageModel { - Page = queryPageModel.Page, + PageNum = queryPageModel.Page, PageSize = queryPageModel.PageSize, }; if (!string.IsNullOrEmpty(queryPageModel.Code)) diff --git a/Service/Ammeter/EmeterHourEnergyService.cs b/Service/Ammeter/EmeterHourEnergyService.cs index c97e9ed..860fae7 100644 --- a/Service/Ammeter/EmeterHourEnergyService.cs +++ b/Service/Ammeter/EmeterHourEnergyService.cs @@ -21,7 +21,7 @@ namespace Service.Ammeter { QueryPageModel queryPageModel1 = new QueryPageModel { - Page = queryPageModel.Page, + PageNum = queryPageModel.Page, PageSize = queryPageModel.PageSize, }; if (!string.IsNullOrEmpty(queryPageModel.Code)) diff --git a/Service/Ammeter/EmeterMinutesEnergyChangeService.cs b/Service/Ammeter/EmeterMinutesEnergyChangeService.cs index 17fe17a..50f02b4 100644 --- a/Service/Ammeter/EmeterMinutesEnergyChangeService.cs +++ b/Service/Ammeter/EmeterMinutesEnergyChangeService.cs @@ -21,7 +21,7 @@ namespace Service.Ammeter { QueryPageModel queryPageModel1 = new QueryPageModel { - Page = queryPageModel.Page, + PageNum = queryPageModel.Page, PageSize = queryPageModel.PageSize, }; if (!string.IsNullOrEmpty(queryPageModel.Code)) diff --git a/Service/Ammeter/EmeterMinutesEnergyService.cs b/Service/Ammeter/EmeterMinutesEnergyService.cs index cb399e6..9682a9a 100644 --- a/Service/Ammeter/EmeterMinutesEnergyService.cs +++ b/Service/Ammeter/EmeterMinutesEnergyService.cs @@ -23,7 +23,7 @@ namespace Service.Ammeter { QueryPageModel queryPageModel1 = new QueryPageModel { - Page = queryPageModel.Page, + PageNum = queryPageModel.Page, PageSize = queryPageModel.PageSize, }; if (!string.IsNullOrEmpty(queryPageModel.Code)) diff --git a/Service/Plc/Client/PlcClient.cs b/Service/Plc/Client/PlcClient.cs index f686fb0..78b9dfc 100644 --- a/Service/Plc/Client/PlcClient.cs +++ b/Service/Plc/Client/PlcClient.cs @@ -1,28 +1,34 @@ -using Entity.DbModel.Station; +using Common.Const; +using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Const; using HybirdFrameworkDriver.ModbusTcpMaster; +using log4net; using Repository.Station; using Service.Plc.Msg; namespace Service.Plc.Client; /// -/// +/// /// [Scope] 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; Ip = "172.0.20.66"; Port = 502; Duration = 1000; AutoReConnect = true; - _binInfoRepository = binInfoRepository; ByteSeq = EndingConst.ByteSeq.BA; WordSeq= EndingConst.WordSeq.CD; } @@ -60,16 +66,73 @@ public class PlcClient : ModbusTcpMaster var bytes03 = master.BatchReadHolderRegister(701, 10); if (bytes03 != null) { + PlcMgr.LastPlcFaultData = PlcMgr.PlcFaultData; PlcMgr.DataValidityTime = DateTime.Now; ModbusDecoder.Decode(bytes03, PlcMgr.PlcFaultData, EndingConst.ByteSeq.AB, 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) { if (exists == 0) - _binInfoRepository.Update( + BinInfoRepository.Update( it => new BinInfo(){ Exists = 0, @@ -77,12 +140,12 @@ public class PlcClient : ModbusTcpMaster Soc = (decimal)-1, Soe = (decimal)-1, Soh = (decimal)-1, - }, + }, it => it.No == binNo); else - _binInfoRepository.Update(it => it.Exists == 1, + BinInfoRepository.Update(it => it.Exists == 1, it => it.No == binNo); } -} \ No newline at end of file +} diff --git a/Service/Plc/Client/PlcMgr.cs b/Service/Plc/Client/PlcMgr.cs index 73cf1a0..89b7edf 100644 --- a/Service/Plc/Client/PlcMgr.cs +++ b/Service/Plc/Client/PlcMgr.cs @@ -1,5 +1,4 @@ using Autofac; -using log4net; using HslCommunication; using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Utils; @@ -13,6 +12,7 @@ public class PlcMgr public static PlcClient? PlcClient; public static readonly HostToPlc HostToPlcData = new HostToPlc(); public static readonly PlcToHost PlcToHostData = new PlcToHost(); + public static PlcFault LastPlcFaultData = new PlcFault(); public static readonly PlcFault PlcFaultData = new PlcFault(); @@ -26,14 +26,14 @@ public class PlcMgr /// public static DateTime DataValidityTime = DateTime.Now; - public static bool Init() + public static void Init() { if (PlcClient == null) { PlcClient = AppInfo.Container.Resolve(); } - return PlcClient.Connect(); + Task.Run(() =>PlcClient.Connect()); } /// @@ -65,12 +65,12 @@ public class PlcMgr return false; } - + public static ushort BlowerStatus() { if (PlcClient != null) { - + return PlcToHostData.ExhaustFanStatus.Value; } @@ -373,4 +373,4 @@ public class PlcMgr return bResult; } -} \ No newline at end of file +} diff --git a/Service/Plc/Msg/PlcFault.cs b/Service/Plc/Msg/PlcFault.cs index ade3939..52d7df6 100644 --- a/Service/Plc/Msg/PlcFault.cs +++ b/Service/Plc/Msg/PlcFault.cs @@ -4,10 +4,10 @@ namespace Service.Plc.Msg { public class PlcFault { - public ModbusProperty ErrorCode01 { get; set; } = new(40701,length :2); // 错误码 - public ModbusProperty ErrorCode03 { get; set; } = new(40703,length :2); // 错误码 - public ModbusProperty ErrorCode05 { get; set; } = new(40705,length :2); // 错误码 - public ModbusProperty ErrorCode07 { get; set; } = new(40707,length :2); // 错误码 - public ModbusProperty ErrorCode09 { get; set; } = new(40709, length: 2); // 错误码 + public ModbusProperty ErrorCode01 { get; set; } = new(40701,length :2, value: 0); // 错误码 + public ModbusProperty ErrorCode03 { get; set; } = new(40703,length :2, value: 0); // 错误码 + public ModbusProperty ErrorCode05 { get; set; } = new(40705,length :2, value: 0); // 错误码 + public ModbusProperty ErrorCode07 { get; set; } = new(40707,length :2, value: 0); // 错误码 + public ModbusProperty ErrorCode09 { get; set; } = new(40709, length: 2, value: 0); // 错误码 } } diff --git a/Service/Station/ChargeOrderService.cs b/Service/Station/ChargeOrderService.cs index 65438d1..e6496a1 100644 --- a/Service/Station/ChargeOrderService.cs +++ b/Service/Station/ChargeOrderService.cs @@ -30,7 +30,7 @@ public class ChargeOrderService : BaseServices /// public PageResult QueryChargeOrder(QueryChargeOrderReq chargeOrder) { - + //创建一个空的表达式树 Expression> where = null; //// 定义参数表达式 @@ -125,7 +125,7 @@ public class ChargeOrderService : BaseServices } /// - /// + /// /// /// /// @@ -136,13 +136,13 @@ public class ChargeOrderService : BaseServices { return Result.Fail("数据不存在"); } - + if ( orders[0].CloudReportStatus == 1) { - return Result.Success("已经上传到云平台"); + return Result.Success(true, "已经上传到云平台"); } CloudClientMgr.CloudClient?.PublishChargeOrder(orders, 2); return Result.Success(); } -} \ No newline at end of file +} diff --git a/Service/Station/EquipAlarmLevelService.cs b/Service/Station/EquipAlarmLevelService.cs index 5341038..6fe4dd3 100644 --- a/Service/Station/EquipAlarmLevelService.cs +++ b/Service/Station/EquipAlarmLevelService.cs @@ -21,34 +21,34 @@ public class EquipAlarmLevelService : BaseServices /// - /// ѯϵȼϢҳ + /// 根据条件查询故障等级信息分页 /// /// /// public PageResult QueryEqmFaultInfo(QueryEquipAlarmLevelReq equipAlarmLevel) { - //һյıʽ + //创建一个空的表达式树 Expression> where = null; - //// ʽ + //// 定义参数表达式 ParameterExpression parameter = Expression.Parameter(typeof(EquipAlarmLevel), "u"); - //TODO ȱݿֶ + //TODO 缺少数据库字段先屏蔽 //if (!string.IsNullOrEmpty(quipAlarmLevel.Level)) //{ // Expression> condition1Expr = u => u.Level == quipAlarmLevel.Level; // where = condition1Expr; //} - //// ѯ + //// 构建查询条件 //if (!string.IsNullOrEmpty(quipAlarmLevel.LevelName)) //{ // Expression> condition2Expr = u => u.LevelName == quipAlarmLevel.LevelName; // where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); //} - //ѯ + //查询 return PageResult.ConvertPage(_equipAlarmLevelRepository.QueryIPageByCause(equipAlarmLevel, where)); } -} \ No newline at end of file +} diff --git a/Service/Station/EquipAlarmRecordService.cs b/Service/Station/EquipAlarmRecordService.cs new file mode 100644 index 0000000..80a606a --- /dev/null +++ b/Service/Station/EquipAlarmRecordService.cs @@ -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 +{ + public EquipAlarmProcessRecordRepository ProcessRecordRepository { get; set; } + + public EquipAlarmRecordService(EquipAlarmRecordRepository dal) + { + BaseDal = dal; + } + + /// + /// 查询未处理报警列表 + /// + /// 设备类型:-1-查询全部;0-充电机;1-电表;2-水冷机;3-plc< + /// 设备编码 + /// + public Result> QueryEquipAlarmPage(QueryAlarmReq req) + { + int totalCount = 0; + int reqTypeCode = req.TypeCode; + var equipCode = req.EquipCode; + List 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 result = new PageResult() + { + PageNum = req.PageNum, + PageSize = req.PageSize, + ToTal = totalCount, + Rows = list + }; + return Result>.Success(result); + } + + /// + /// 查询已处理报警列表 + /// + /// 设备类型:-1-查询全部;0-充电机;1-电表;2-水冷机;3-plc + /// 设备编码 + /// + public Result> QueryEquipAlarmProcessPage(QueryAlarmReq req) + { + int totalCount = 0; + int reqTypeCode = req.TypeCode; + var equipCode = req.EquipCode; + List 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 result = new PageResult() + { + PageNum = req.PageNum, + PageSize = req.PageSize, + ToTal = totalCount, + Rows = list + }; + + + return Result>.Success(result); + } +} diff --git a/WebStarter/Controllers/ChargeOrderController.cs b/WebStarter/Controllers/ChargeOrderController.cs index ad47539..8e122c8 100644 --- a/WebStarter/Controllers/ChargeOrderController.cs +++ b/WebStarter/Controllers/ChargeOrderController.cs @@ -47,13 +47,13 @@ public class ChargeOrderController : ControllerBase if (chargeOrderService.Update(chargeOrder)) { - return Result.Success("更改成功"); + return Result.Success(true,"更改成功"); } else { return Result.Fail("更改失败"); } - + } /// @@ -65,4 +65,4 @@ public class ChargeOrderController : ControllerBase { return chargeOrderService.Upload2Cloud(id); } -} \ No newline at end of file +} diff --git a/WebStarter/Controllers/EquipAlarmLevelController.cs b/WebStarter/Controllers/EquipAlarmLevelController.cs index 8b112bb..30bc1ff 100644 --- a/WebStarter/Controllers/EquipAlarmLevelController.cs +++ b/WebStarter/Controllers/EquipAlarmLevelController.cs @@ -63,7 +63,7 @@ public class EquipAlarmLevelController : ControllerBase // 更改 - return Result.Success("插入成功"); + return Result.Success(true, "插入成功"); } } @@ -83,7 +83,7 @@ public class EquipAlarmLevelController : ControllerBase if (equipAlarmLevelService.Update(baseEqmFaultLevel)) { - return Result.Success("更改成功"); + return Result.Success(true,"更改成功"); } else { @@ -102,11 +102,11 @@ public class EquipAlarmLevelController : ControllerBase { if (equipAlarmLevelService.DeleteByIds(ids)) { - return Result.Success("删除成功"); + return Result.Success(true,"删除成功"); } else { return Result.Fail("删除失败"); } } -} \ No newline at end of file +} diff --git a/WebStarter/Controllers/EquipAlarmRecordController.cs b/WebStarter/Controllers/EquipAlarmRecordController.cs new file mode 100644 index 0000000..a32b458 --- /dev/null +++ b/WebStarter/Controllers/EquipAlarmRecordController.cs @@ -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; + +/// +/// 换电设备报警 +/// +[ApiController] +[Route("api/[controller]")] +public class EquipAlarmRecordController : ControllerBase +{ + private readonly EquipAlarmRecordService equipAlarmRecordService; + + public EquipAlarmRecordController(EquipAlarmRecordService equipAlarmRecordService) + { + this.equipAlarmRecordService = equipAlarmRecordService; + } + + /// + /// 查询未处理报警列表 + /// + /// 设备类型:-1-查询全部;0-充电机;1-电表;2-水冷机;3-plc< + /// 设备编码 + /// + [HttpPost("/QueryEquipAlarmPage")] + public Result> QueryEquipAlarmPage([FromBody] QueryAlarmReq req) + { + return equipAlarmRecordService.QueryEquipAlarmPage(req); + } + + /// + /// 查询已处理报警列表 + /// + /// 设备类型:-1-查询全部;0-充电机;1-电表;2-水冷机;3-plc + /// 设备编码 + /// + [HttpPost("/QueryEquipAlarmProcessPage")] + public Result> QueryEquipAlarmProcessPage([FromBody] QueryAlarmReq req) + { + return equipAlarmRecordService.QueryEquipAlarmProcessPage(req); + } +} diff --git a/WebStarter/Controllers/SwapOrderController.cs b/WebStarter/Controllers/SwapOrderController.cs index acd358f..1d42082 100644 --- a/WebStarter/Controllers/SwapOrderController.cs +++ b/WebStarter/Controllers/SwapOrderController.cs @@ -4,9 +4,7 @@ using Entity.Api.Resp; using Entity.DbModel.Station; using HybirdFrameworkCore.Entity; using Microsoft.AspNetCore.Mvc; -using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; using Service.Station; -using System.Collections.Generic; namespace WebStarter.Controllers; @@ -99,7 +97,7 @@ public class SwapOrderController : ControllerBase else { swapOrderService.Insert(swapOrder); - return Result.Success("新增成功"); + return Result.Success(true,"新增成功"); } } @@ -118,7 +116,7 @@ public class SwapOrderController : ControllerBase if (swapOrderService.Update(swapOrder)) { - return Result.Success("更改成功"); + return Result.Success(true,"更改成功"); } else { @@ -136,7 +134,7 @@ public class SwapOrderController : ControllerBase { if (swapOrderService.DeleteByIds(ids)) { - return Result.Success("删除成功"); + return Result.Success(true,"删除成功"); } else { @@ -152,7 +150,7 @@ public class SwapOrderController : ControllerBase [HttpGet("UploadCloud/{id}")] public Result UploadCloud(int id) { - + return swapOrderService.UploadCloud(id); } -} \ No newline at end of file +} diff --git a/WebStarter/Controllers/SwapOrderStepController.cs b/WebStarter/Controllers/SwapOrderStepController.cs index 2dd6278..92cd2b7 100644 --- a/WebStarter/Controllers/SwapOrderStepController.cs +++ b/WebStarter/Controllers/SwapOrderStepController.cs @@ -1,7 +1,5 @@ -using AutoMapper; using Entity.Api.Req; using Entity.Api.Resp; -using Entity.DbModel.Station; using HybirdFrameworkCore.Entity; using Microsoft.AspNetCore.Mvc; using Service.Station; @@ -48,7 +46,7 @@ public class SwapOrderStepController : ControllerBase { if (swapOrderStepService.DeleteByIds(ids)) { - return Result.Success("删除成功"); + return Result.Success(true,"删除成功"); } else { @@ -56,4 +54,4 @@ public class SwapOrderStepController : ControllerBase } } -} \ No newline at end of file +}