mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-07 22:27:58 +08:00
89 lines
27 KiB
C#
89 lines
27 KiB
C#
![]() |
using Newtonsoft.Json;
|
|||
|
using SqlSugar;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System;
|
|||
|
|
|||
|
|
|||
|
namespace OrmTest
|
|||
|
{
|
|||
|
public class Unitadfafasfa1
|
|||
|
{
|
|||
|
|
|||
|
static string connStr =Config.ConnectionString;
|
|||
|
protected static SqlSugarScope db = new SqlSugarScope(new ConnectionConfig()
|
|||
|
{
|
|||
|
DbType = DbType.PostgreSQL,
|
|||
|
ConnectionString = connStr,
|
|||
|
IsAutoCloseConnection = true,
|
|||
|
ConfigId = "web",
|
|||
|
LanguageType = LanguageType.Default,//Set language
|
|||
|
|
|||
|
SlaveConnectionConfigs = new List<SlaveConnectionConfig>() {
|
|||
|
new SlaveConnectionConfig() { HitRate = 10, ConnectionString = connStr }
|
|||
|
},
|
|||
|
MoreSettings = new ConnMoreSettings()
|
|||
|
{
|
|||
|
PgSqlIsAutoToLower = false,
|
|||
|
PgSqlIsAutoToLowerCodeFirst = false,
|
|||
|
IsAutoRemoveDataCache = true
|
|||
|
},
|
|||
|
AopEvents = new AopEvents
|
|||
|
{
|
|||
|
OnLogExecuting = (sql, p) =>
|
|||
|
{
|
|||
|
Console.WriteLine(UtilMethods.GetNativeSql(sql, p));
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
public static void Init()
|
|||
|
{
|
|||
|
db.CodeFirst.InitTables<testModel>();
|
|||
|
|
|||
|
//# 2024-12-24 11:08:04
|
|||
|
var json = "[{\"channel\":1,\"day1\":[17377,2692,17415,2413,196,33,11,0,1,0,0,0,0],\"day2\":[17359,2683,17396,2408,194,33,10,0,1,0,0,0,0],\"day3\":[17342,2679,17379,2405,193,33,10,0,1,0,0,0,0],\"day4\":[17327,2678,17364,2404,193,33,10,0,1,0,0,0,0],\"day5\":[17313,2670,17350,2401,188,33,10,0,1,0,0,0,0],\"day6\":[17296,2664,17333,2397,186,33,10,0,1,0,0,0,0],\"day7\":[17287,2654,17324,2389,185,33,10,0,0,0,0,0,0],\"day15\":[17163,2610,17200,2354,177,32,10,0,0,0,0,0,0]},{\"channel\":2,\"day1\":[19695,2429,19731,2343,47,2,1,0,0,0,0,0,0],\"day2\":[19688,2429,19724,2343,47,2,1,0,0,0,0,0,0],\"day3\":[19676,2428,19712,2342,47,2,1,0,0,0,0,0,0],\"day4\":[19662,2428,19698,2342,47,2,1,0,0,0,0,0,0],\"day5\":[19659,2428,19695,2342,47,2,1,0,0,0,0,0,0],\"day6\":[19654,2428,19690,2342,47,2,1,0,0,0,0,0,0],\"day7\":[19651,2428,19687,2342,47,2,1,0,0,0,0,0,0],\"day15\":[19592,2424,19628,2339,46,2,1,0,0,0,0,0,0]},{\"channel\":3,\"day1\":[411,128,418,42,36,9,17,11,4,1,1,0,0],\"day2\":[409,127,416,42,35,9,17,11,4,1,1,0,0],\"day3\":[409,127,416,42,35,9,17,11,4,1,1,0,0],\"day4\":[409,127,416,42,35,9,17,11,4,1,1,0,0],\"day5\":[409,127,416,42,35,9,17,11,4,1,1,0,0],\"day6\":[409,126,416,42,35,9,17,10,4,1,1,0,0],\"day7\":[409,126,416,42,35,9,17,10,4,1,1,0,0],\"day15\":[406,125,413,42,35,8,17,10,4,1,1,0,0]},{\"channel\":4,\"day1\":[467579,24011,469243,20541,1010,426,244,80,30,7,6,3,0],\"day2\":[466881,23953,468543,20503,1004,422,239,77,30,7,6,3,0],\"day3\":[466222,23905,467882,20465,999,421,238,76,30,7,6,3,0],\"day4\":[465581,23857,467239,20428,997,417,236,75,30,7,6,3,0],\"day5\":[464882,23821,466537,20398,994,417,236,75,30,7,6,3,0],\"day6\":[463963,23754,465614,20346,989,415,235,74,28,7,6,3,0],\"day7\":[462977,23706,464622,20310,985,415,234,74,28,7,5,3,0],\"day15\":[442887,23146,444469,19891,942,404,221,67,24,7,5,3,0]},{\"channel\":5,\"day1\":[250238,12820,250740,11546,603,70,53,38,6,0,1,1,0],\"day2\":[250001,12797,250502,11526,602,70,53,37,6,0,1,1,0],\"day3\":[249784,12776,250283,11512,598,70,53,36,6,0,1,1,0],\"day4\":[249579,12761,250078,11499,597,70,53,36,5,0,1,1,0],\"day5\":[249357,12743,249856,11482,596,70,53,36,5,0,1,1,0],\"day6\":[249040,12714,249536,11458,594,70,53,36,5,0,1,1,0],\"day7\":[248749,12700,249244,11447,592,70,53,36,5,0,1,1,0],\"day15\":[242781,12509,243261,11288,576,70,53,36,5,0,1,0,0]},{\"channel\":6,\"day1\":[16855,736,16899,643,42,3,3,1,0,0,0,0,0],\"day2\":[16844,734,16888,643,41,2,3,1,0,0,0,0,0],\"day3\":[16836,734,16880,643,41,2,3,1,0,0,0,0,0],\"day4\":[16825,733,16869,642,41,2,3,1,0,0,0,0,0],\"day5\":[16812,733,16856,642,41,2,3,1,0,0,0,0,0],\"day6\":[16806,733,16850,642,41,2,3,1,0,0,0,0,0],\"day7\":[16797,730,16841,639,41,2,3,1,0,0,0,0,0],\"day15\":[16713,719,16757,629,40,2,3,1,0,0,0,0,0]},{\"channel\":7,\"day1\":[32702,1754,32744,1644,59,7,2,0,0,0,0,0,0],\"day2\":[32628,1750,32670,1641,58,7,2,0,0,0,0,0,0],\"day3\":[32598,1748,32640,1639,58,7,2,0,0,0,0,0,0],\"day4\":[32571,1748,32613,1639,58,7,2,0,0,0,0,0,0],\"day5\":[32528,1746,32570,1637,58,7,2,0,0,0,0,0,0],\"day6\":[32479,1742,32521,1633,58,7,2,0,0,0,0,0,0],\"day7\":[32387,1738,32429,1630,57,7,2,0,0,0,0,0,0],\"day15\":[31954,1720,31995,1614,56,7,2,0,0,0,0,0,0]},{\"channel\":8,\"day1\":[21602,2198,21645,2084,57,5,6,3,0,0,0,0,0],\"day2\":[21577,2196,21620,2082,57,5,6,3,0,0,0,0,0],\"day3\":[21551,2194,21594,2080,57,5,6,3,0,0,0,0,0],\"day4\":[21528,2192,21571,2078,57,5,6,3,0,0,0,0,0],\"day5\":[21502,2188,21545,2074,57,5,6,3,0,0,0,0,0],\"day6\":[21469,2185,21512,2072,56,5,6,3,0,0,0,0,0],\"day7\":[21437,2180,21480,2067,56,5,6,3,0,0,0,0,0],\"day15\":[21215,2158,21258,2046,55,5,6,3,0,0,0,0,0]},{\"channel\":9,\"day1\":[5025,133,5030,113,11,3,1,0,0,0,0,0,0],\"day2\":[5024,133,5029,113,11,3,1,0,0,0,0,0,0],\"day3\":[5024,133,5029,113,11,3,1,0,0,0,0,0,0],\"day4\":[5023,133,5028,113,11,3,1,0,0,0,0,0,0],\"day5\":[5022,133,5027,113,11,3,1,0,0,0,0,0,0],\"day6\":[5021,132,5025,113,11,3,1,0,0,0,0,0,0],\"day7\":[5021,132,5025,113,11,3,1,0,0,0,0,0,0],\"day15\":[5010,130,5014,111,11,3,1,0,0,0,0,0,0]},{\"channel\":10,\"day1\":[700,147,733,63,29,7,7,3,3,0,2,0,0],\"day2\":[698,147,731,
|
|||
|
|
|||
|
var list = JsonConvert.DeserializeObject<List<testModel>>(json);
|
|||
|
|
|||
|
|
|||
|
//# 清理历史数据
|
|||
|
db.Deleteable<testModel>().ExecuteCommand();
|
|||
|
|
|||
|
|
|||
|
db.Insertable(list).ExecuteCommand();
|
|||
|
|
|||
|
//# 写入完成之后请比对上面list变量和数据库
|
|||
|
var data = db.Queryable<testModel>()
|
|||
|
.OrderBy(it => it.channel).ToList();
|
|||
|
int i = 0;
|
|||
|
foreach (var item in data)
|
|||
|
{
|
|||
|
var tmpItem = list?.Find(x => x.channel == item.channel);
|
|||
|
if (tmpItem != null)
|
|||
|
{
|
|||
|
var str1 = JsonConvert.SerializeObject(tmpItem.day1);
|
|||
|
var str2 = JsonConvert.SerializeObject(item.day1);
|
|||
|
if (str1 != str2)
|
|||
|
{
|
|||
|
throw new Exception("unit error"+i);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[SugarTable("unitSq1ladfadsfa")]
|
|||
|
public class testModel
|
|||
|
{
|
|||
|
[SugarColumn(IsPrimaryKey = true)] public int channel { get; set; }
|
|||
|
[SugarColumn(IsArray = true, ColumnDataType = "int[]")] public int[] day1 { get; set; } = new int[13];
|
|||
|
[SugarColumn(IsArray = true, ColumnDataType = "int[]")] public int[] day2 { get; set; } = new int[13];
|
|||
|
[SugarColumn(IsArray = true, ColumnDataType = "int[]")] public int[] day3 { get; set; } = new int[13];
|
|||
|
[SugarColumn(IsArray = true, ColumnDataType = "int[]")] public int[] day4 { get; set; } = new int[13];
|
|||
|
[SugarColumn(IsArray = true, ColumnDataType = "int[]")] public int[] day5 { get; set; } = new int[13];
|
|||
|
[SugarColumn(IsArray = true, ColumnDataType = "int[]")] public int[] day6 { get; set; } = new int[13];
|
|||
|
[SugarColumn(IsArray = true, ColumnDataType = "int[]")] public int[] day7 { get; set; } = new int[13];
|
|||
|
[SugarColumn(IsArray = true, ColumnDataType = "int[]")] public int[] day15 { get; set; } = new int[13];
|
|||
|
}
|
|||
|
|
|||
|
}
|