From 9dc5b17cf39f04097d9240db490e27d35d9dd3b2 Mon Sep 17 00:00:00 2001 From: liuwf Date: Wed, 19 Feb 2025 16:05:18 +0800 Subject: [PATCH] =?UTF-8?q?add-=E5=BC=95=E5=85=A5=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E5=8F=8A=E5=AE=9E=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.RfidUpload.Model/UploadRecord.cs | 47 +++++++ .../SlnMesnac.RfidUpload.UI.csproj | 2 + slnmesnac.rfidupload.Repository/Repository.cs | 2 +- .../SqlSugarHelper.cs | 124 +++++++++++++----- 4 files changed, 138 insertions(+), 37 deletions(-) create mode 100644 SlnMesnac.RfidUpload.Model/UploadRecord.cs diff --git a/SlnMesnac.RfidUpload.Model/UploadRecord.cs b/SlnMesnac.RfidUpload.Model/UploadRecord.cs new file mode 100644 index 0000000..31bc428 --- /dev/null +++ b/SlnMesnac.RfidUpload.Model/UploadRecord.cs @@ -0,0 +1,47 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Security.Principal; +using System.Text; + +namespace SlnMesnac.RfidUpload.Model +{ + [SugarTable("UPLOAD_RECORD")] + public class UploadRecord + { + // 该特性指定此属性对应数据库表中的 id 列 + // IsIdentity = true 表示该列是自增列 + // IsPrimaryKey = true 表示该列是主键 + [SugarColumn(ColumnName = "id", IsIdentity = true, IsPrimaryKey = true)] + public int Id { get; set; } + + // 该特性指定此属性对应数据库表中的 ffjhNo 列,用于存储封发计划编号 + [SugarColumn(ColumnName = "ffjhNo")] + public string FfjhNo { get; set; } + + // 该特性指定此属性对应数据库表中的 opBatch 列,用于存储封发计划使用序号 + [SugarColumn(ColumnName = "opBatch")] + public string OpBatch { get; set; } + + // 该特性指定此属性对应数据库表中的 ffjhscrq 列,用于存储封发计划生成日期 + [SugarColumn(ColumnName = "ffjhscrq")] + public string Ffjhscrq { get; set; } + + // 该特性指定此属性对应数据库表中的 stationOrgCode 列,用于存储机构代码 + [SugarColumn(ColumnName = "stationOrgCode")] + public string StationOrgCode { get; set; } + + // 该特性指定此属性对应数据库表中的 stationOrgName 列,用于存储机构名称 + [SugarColumn(ColumnName = "stationOrgName")] + public string StationOrgName { get; set; } + + // 该特性指定此属性对应数据库表中的 strList 列,用于存储 RFID 列表(以 JSON 字符串形式存储) + [SugarColumn(ColumnName = "strList")] + public string StrList { get; set; } + + // 该特性指定此属性对应数据库表中的 isSuccess 列,用于表示上传状态 + // DefaultValue = "0" 表示该列的默认值为 0,0 代表上传失败,1 代表上传成功 + [SugarColumn(ColumnName = "isSuccess", DefaultValue = "0")] + public int IsSuccess { get; set; } + } +} diff --git a/SlnMesnac.RfidUpload.UI/SlnMesnac.RfidUpload.UI.csproj b/SlnMesnac.RfidUpload.UI/SlnMesnac.RfidUpload.UI.csproj index 4668703..ad30f98 100644 --- a/SlnMesnac.RfidUpload.UI/SlnMesnac.RfidUpload.UI.csproj +++ b/SlnMesnac.RfidUpload.UI/SlnMesnac.RfidUpload.UI.csproj @@ -13,12 +13,14 @@ + + diff --git a/slnmesnac.rfidupload.Repository/Repository.cs b/slnmesnac.rfidupload.Repository/Repository.cs index 74101da..91df720 100644 --- a/slnmesnac.rfidupload.Repository/Repository.cs +++ b/slnmesnac.rfidupload.Repository/Repository.cs @@ -11,7 +11,7 @@ namespace slnmesnac.rfidupload.Repository /** * 根据configId动态获取数据源 */ - base.Context = SqlSugarHelper.Db.GetConnectionScope(configId); + base.Context = SqlSugarHelper.db.GetConnectionScope(configId); //.NET自带IOC: base.Context = 你存储的Services.GetService(); //Furion: base.Context=App.GetService(); diff --git a/slnmesnac.rfidupload.Repository/SqlSugarHelper.cs b/slnmesnac.rfidupload.Repository/SqlSugarHelper.cs index 12bb226..83d1bb0 100644 --- a/slnmesnac.rfidupload.Repository/SqlSugarHelper.cs +++ b/slnmesnac.rfidupload.Repository/SqlSugarHelper.cs @@ -1,4 +1,5 @@  +using SlnMesnac.RfidUpload.Model; using SlnMesnac.RfidUpload.NLog; using SqlSugar; using System; @@ -29,49 +30,100 @@ using System.Text; #endregion << 版 本 注 释 >> namespace slnmesnac.rfidupload.Repository { - internal class SqlSugarHelper + public class SqlSugarHelper { - #region 连接字符串 - /** - * Sqlite:获取debug路径下的数据库文件,不建议直接写死路径 - * private static string sqliteConnStr = $"Data Source={Path.GetFullPath("data\\data.db")};Version=3"; - */ - private static string sqliteConnStr = "Data Source=Z:\\Desktop\\日常代码\\HighWayIot\\HighWayIot\\bin\\Debug\\data\\data.db;Version=3"; + private static SqlSugarHelper instance = null; + private static readonly object padlock = new object(); - /** - * Mysql - */ - private static string mysqlConnStr = "Data Source=124.70.63.37;Port=6000;Initial Catalog=ry-cloud;uid=root;pwd=haiwei@123;Charset=utf8mb4;SslMode=none"; + private SqlSugarHelper() { } + public static SqlSugarHelper Instance + { + get + { + lock (padlock) + { + if (instance == null) + instance = new SqlSugarHelper(); + return instance; + } + } + } - private static string oracleConnStr = "Data Source=175.27.215.92/helowin;User ID=aucma_mes;Password=aucma"; - #endregion - private static LogHelper logHelper = LogHelper.Instance; + + public static string url = System.Environment.CurrentDirectory + "/db/"; + static string ConnectionString1 = $"Data Source={url}/hw.db"; + + public static SqlSugarClient db + { - //如果是固定多库可以传 new SqlSugarScope(List,db=>{}) 文档:多租户 - //如果是不固定多库 可以看文档Saas分库 + get => new SqlSugarClient(new ConnectionConfig() + { + ConnectionString = $"Data Source={url}/hw.db", + DbType = SqlSugar.DbType.Sqlite, //必填, 数据库类型 + IsAutoCloseConnection = true, //默认false, 时候知道关闭数据库连接, 设置为true无需使用using或者Close操作 + InitKeyType = InitKeyType.SystemTable //默认SystemTable, codefist需要使用Attribute + }); + } - //用单例模式 - public static SqlSugarScope Db = new SqlSugarScope(new List() + /// + /// 插入记录 + /// + /// + /// + public int InsertRecord(UploadRecord record) { - new ConnectionConfig() - { - ConfigId = "sqlite", - ConnectionString = sqliteConnStr, - DbType = DbType.Sqlite, - InitKeyType = InitKeyType.Attribute, - IsAutoCloseConnection = true - } - }, - db => - { - //(A)全局生效配置点 - //调试SQL事件,可以删掉 - db.Aop.OnLogExecuting = (sql, pars) => - { - //logHelper.SqlLog($"{sql};参数:{jsonChange.ModeToJson(pars)}"); - }; - }); + int result = db.Insertable(record).ExecuteCommand(); + return result; + } + + /// + /// 查询记录列表--不包含strList字段 + /// + /// + /// + public List GetRecordList() + { + List list; + list = db.SqlQueryable("select id,UPLOAD_RECORD.ffjhNo,opBatch,ffjhscrq,stationOrgCode,stationOrgName,strList,isSuccess from UPLOAD_RECORD").ToList(); + return list; + } + + /// + /// 根据封发计划编号查询记录 + /// + /// + /// + public string GetRecordByFfjhNo(string ffjhNo) + { + string strList = db.Ado.GetString($"select * from UPLOAD_RECORD where ffjhNo='{ffjhNo}'"); + return strList; + } + + /// + /// 插入记录 + /// + /// + /// + public int InsertPrintCode(UploadRecord record) + { + int result = db.Insertable(record).ExecuteCommand(); + return result; + } + + + /// + /// 根据封发计划编号改变上传记录上传结果 + /// + /// + /// + public int DeletePrintCode(string ffjhNo,bool uploadResult) + { + int flag = uploadResult ? 1 : 0; + string sql = $"UPDATE UPLOAD_RECORD SET isSuccess = {flag} WHERE ffjhNo = {ffjhNo}"; + int result = db.Updateable(sql).ExecuteCommand(); + return result; + } } } \ No newline at end of file