change - 添加分表存储

main
Wen JY 2 months ago
parent 62f64d03d8
commit ac6199ec7a

@ -104,7 +104,7 @@ namespace Sln.Iot.Business
f_tempreture = 0;
}
iotEnvInstant.tempreture = (decimal) f_tempreture;
iotEnvInstant.temperature = (decimal) f_tempreture;
break;
case CommParams.Humidity: //湿度
@ -202,7 +202,7 @@ namespace Sln.Iot.Business
if (result.Count > 0)
{
//var inRes = _service.Insert(result);
var inRes = _service.SplitInsert(result,out List<long> insertIds);
/*Task.Run(() => //保存至TD引擎
{
@ -211,7 +211,7 @@ namespace Sln.Iot.Business
this.RefreshMonitorInfo(result);
});*/
//_logger.Info($"{amount}个物联网数据解析处理完成,数据保存{(inRes ? "成功" : "失败")}");
_logger.Info($"{amount}个物联网数据解析处理完成,数据保存{(inRes ? "" : "")}");
}
else
{

@ -28,13 +28,14 @@ using SqlSugar;
namespace Sln.Iot.Model.dao
{
[SugarTable("record_iotenv_instant"), TenantAttribute("tao_iot")]
[SplitTable(SplitType.Day)]
[SugarTable("record_iotenv_instant_{year}{month}{day}"), TenantAttribute("tao_iot")]
public class RecordIotEnvInstant
{
/// <summary>
/// 编号
/// 编号 ,IsIdentity = true
///</summary>
[SugarColumn(ColumnName="objid" ,IsPrimaryKey = true ,IsIdentity = true )]
[SugarColumn(ColumnName="objid" ,IsPrimaryKey = true )]
public long objid { get; set; }
/// <summary>
@ -46,8 +47,8 @@ namespace Sln.Iot.Model.dao
/// <summary>
/// 温度
/// </summary>
[SugarColumn(ColumnName="tempreture" )]
public decimal tempreture { get; set; }
[SugarColumn(ColumnName="temperature" )]
public decimal temperature { get; set; }
/// <summary>
/// 湿度
@ -108,6 +109,7 @@ namespace Sln.Iot.Model.dao
/// <summary>
/// 记录时间
///</summary>
[SplitField]
[SugarColumn(ColumnName="recodeTime" )]
public DateTime? recordTime { get; set; }
}

@ -23,6 +23,7 @@
#endregion << 版 本 注 释 >>
using System.Collections.Generic;
using Sln.Iot.Model.dao;
using Sln.Iot.Repository.service.@base;
@ -30,6 +31,12 @@ namespace Sln.Iot.Repository.service
{
public interface IRecordIotEnvInstantService:IBaseService<RecordIotEnvInstant>
{
/// <summary>
/// 分表保存
/// </summary>
/// <param name="list"></param>
/// <param name="insertIds"></param>
/// <returns></returns>
bool SplitInsert(List<RecordIotEnvInstant> list,out List<long> insertIds);
}
}

@ -23,6 +23,8 @@
#endregion << 版 本 注 释 >>
using System;
using System.Collections.Generic;
using Sln.Iot.Model.dao;
using Sln.Iot.Repository.service.@base;
@ -33,5 +35,34 @@ namespace Sln.Iot.Repository.service.Impl
public RecordIotEnvInstantServiceImpl(Repository<RecordIotEnvInstant> rep) : base(rep)
{
}
/// <summary>
/// 分表保存
/// </summary>
/// <param name="list"></param>
/// <param name="insertIds"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="InvalidOperationException"></exception>
public bool SplitInsert(List<RecordIotEnvInstant> list,out List<long> insertIds)
{
if (list == null)
{
throw new ArgumentNullException($"参数为空");
}
try
{
// _rep.AsTenant().BeginTran();
insertIds = _rep.Context.Insertable(list).SplitTable().ExecuteReturnSnowflakeIdList();
// _rep.AsTenant().CommitTran();
return true;
}
catch (Exception ex)
{
// _rep.AsTenant().RollbackTran();
throw new InvalidOperationException($"物联网数据分表保存异常:{ex.Message}");
}
}
}
}

@ -12,9 +12,9 @@
},
{
"configId": "tao_iot", //tao:
"dbType": 20, //tidb
"dbType": 0, //tidb mysql
"isFlag": true,
"connStr": "server=10.42.0.1;Database=tao_iot;Uid=root;Pwd=haiwei@123;"
"connStr": "server=127.0.0.1;Port=4000;Database=tao_iot;Uid=root;" //Pwd=haiwei@123;
}
],
"redisConfig": "175.27.215.92:6379,password=redis@2023"

@ -11,10 +11,10 @@
"connStr": "Host=175.27.215.92;Port=6030;Username=root;Password=taosdata;Database=db_hwmes"
},
{
"configId": "tao_iot", //tao:
"dbType": 1,
"configId": "tao_iot", //tao:
"dbType": 0, //tidb mysql
"isFlag": true,
"connStr": "server=119.45.202.115;Database=jdap_ems;Uid=sa;Pwd=haiwei@123;Encrypt=True;TrustServerCertificate=True"
"connStr": "server=127.0.0.1;Port=4000;Database=tao_iot;Uid=root;" //Pwd=haiwei@123;
}
],
"redisConfig": "175.27.215.92:6379,password=redis@2023"

Loading…
Cancel
Save