diff --git a/Tiobon.Core.Api/Controllers/Ghra_GradeController.cs b/Tiobon.Core.Api/Controllers/Ghra_GradeController.cs
index 0f042e3d..01913f34 100644
--- a/Tiobon.Core.Api/Controllers/Ghra_GradeController.cs
+++ b/Tiobon.Core.Api/Controllers/Ghra_GradeController.cs
@@ -38,17 +38,13 @@
///
/// Ghra_Grade -- 根据Id查询数据
///
- /// 主键ID
+ /// 主键ID
///
- [HttpGet("{id}")]
- public async Task> Get(string id)
+ [HttpGet("{Id}")]
+ public async Task> Get(string Id)
{
- return new MessageModel()
- {
- msg = "获取成功",
- success = true,
- response = await _ghra_GradeServices.QueryById(id)
- };
+ var response = await _ghra_GradeServices.QueryById(Id);
+ return new MessageModel() { msg = "获取成功", success = true, response = response };
}
#endregion
@@ -56,20 +52,17 @@
///
/// Ghra_Grade -- 新增数据
///
- ///
+ ///
///
[HttpPost]
- public async Task> Post([FromBody] Ghra_Grade request)
+ public async Task> Post([FromBody] InsertGhra_GradeInput insertModel)
{
- var data = new MessageModel();
+ var data = MessageModel.Success("获取成功", null);
- var id = await _ghra_GradeServices.Add(request);
+ var id = await _ghra_GradeServices.Add(insertModel);
data.success = id > 0;
if (data.success)
- {
data.response = id.ObjToString();
- data.msg = "添加成功";
- }
return data;
}
@@ -79,18 +72,16 @@
///
/// Ghra_Grade -- 更新数据
///
- ///
+ ///
+ ///
///
- [HttpPut]
- public async Task> Put([FromBody] Ghra_Grade request)
+ [HttpPut("{Id}")]
+ public async Task> Put(long Id, [FromBody] EditGhra_GradeInput editModel)
{
- var data = new MessageModel();
- data.success = await _ghra_GradeServices.Update(request);
- if (data.success)
- {
- data.msg = "更新成功";
- data.response = request?.Id.ObjToString();
- }
+ var data = MessageModel.Success("更新成功", null);
+ data.success = await _ghra_GradeServices.Update(Id, editModel);
+ if (!data.success)
+ data.msg = "更新失败";;
return data;
}
diff --git a/Tiobon.Core.Api/Tiobon.Core.Model.xml b/Tiobon.Core.Api/Tiobon.Core.Model.xml
index 9f7e8985..6a62b8fe 100644
--- a/Tiobon.Core.Api/Tiobon.Core.Model.xml
+++ b/Tiobon.Core.Api/Tiobon.Core.Model.xml
@@ -74,34 +74,84 @@
备注
-
+
- 无任何权限
+ Ghra_Grade
-
+
- 自定义权限
+ Reverse6
-
+
- 本部门
+ MKey
-
+
- 本部门及以下
+ Reverse9
-
+
- 仅自己
+ Reverse3
-
+
- 所有
+ Reverse4
+
+
+
+
+ ReverseI1
+
+
+
+
+ DataBelongID
+
+
+
+
+ Reverse7
+
+
+
+
+ GradeNo
+
+
+
+
+ Reverse1
+
+
+
+
+ Reverse2
+
+
+
+
+ Reverse5
+
+
+
+
+ GradeName
+
+
+
+
+ Reverse8
+
+
+
+
+ ReverseI2
@@ -1794,6 +1844,36 @@
Ghra_Grade
+
+
+ 无任何权限
+
+
+
+
+ 自定义权限
+
+
+
+
+ 本部门
+
+
+
+
+ 本部门及以下
+
+
+
+
+ 仅自己
+
+
+
+
+ 所有
+
+
真实表名(数据库表名,若没有填写默认实体为表名)
diff --git a/Tiobon.Core.Api/Tiobon.Core.xml b/Tiobon.Core.Api/Tiobon.Core.xml
index a483e5b2..ab2c830d 100644
--- a/Tiobon.Core.Api/Tiobon.Core.xml
+++ b/Tiobon.Core.Api/Tiobon.Core.xml
@@ -1237,21 +1237,22 @@
Ghra_Grade -- 根据Id查询数据
- 主键ID
+ 主键ID
-
+
Ghra_Grade -- 新增数据
-
+
-
+
Ghra_Grade -- 更新数据
-
+
+
diff --git a/Tiobon.Core.Common/Seed/FrameSeed.cs b/Tiobon.Core.Common/Seed/FrameSeed.cs
index 2323406f..d63d21c2 100644
--- a/Tiobon.Core.Common/Seed/FrameSeed.cs
+++ b/Tiobon.Core.Common/Seed/FrameSeed.cs
@@ -172,17 +172,13 @@ namespace Tiobon.Core.Common.Seed
///
/// {ClassName} -- 根据Id查询数据
///
- /// 主键ID
+ /// 主键ID
///
- [HttpGet(""{id}"")]
- public async Task> Get(string id)
+ [HttpGet(""{Id}"")]
+ public async Task> Get(string Id)
{
- return new MessageModel<{ClassName}>()
- {
- msg = ""获取成功"",
- success = true,
- response = await _{ClassName}Services.QueryById(id)
- };
+ var response = await _{ClassName}Services.QueryById(Id);
+ return new MessageModel<{ClassName}Dto>() { msg = ""获取成功"", success = true, response = response };
}
#endregion
@@ -190,20 +186,17 @@ namespace Tiobon.Core.Common.Seed
///
/// {ClassName} -- 新增数据
///
- ///
+ ///
///
[HttpPost]
- public async Task> Post([FromBody] {ClassName} request)
+ public async Task> Post([FromBody] Insert{ClassName}Input insertModel)
{
- var data = new MessageModel();
+ var data = MessageModel.Success(""获取成功"", null);
- var id = await _{ClassName}Services.Add(request);
+ var id = await _{ClassName}Services.Add(insertModel);
data.success = id > 0;
if (data.success)
- {
data.response = id.ObjToString();
- data.msg = ""添加成功"";
- }
return data;
}
@@ -213,18 +206,16 @@ namespace Tiobon.Core.Common.Seed
///
/// {ClassName} -- 更新数据
///
- ///
+ ///
+ ///
///
- [HttpPut]
- public async Task> Put([FromBody] {ClassName} request)
+ [HttpPut(""{Id}"")]
+ public async Task> Put(long Id, [FromBody] Edit{ClassName}Input editModel)
{
- var data = new MessageModel();
- data.success = await _{ClassName}Services.Update(request);
- if (data.success)
- {
- data.msg = ""更新成功"";
- data.response = request?.Id.ObjToString();
- }
+ var data = MessageModel.Success(""更新成功"", null);
+ data.success = await _{ClassName}Services.Update(Id, editModel);
+ if (!data.success)
+ data.msg = ""更新失败"";;
return data;
}
@@ -376,7 +367,7 @@ namespace " + strNameSpace + @"
build.Append(" /// \r\n");
build.Append(" /// " + tableName + "\r\n");
build.Append(" /// \r\n");
- build.Append(@" [SugarTable(" + "\"" + tableName + "\"" + ", " + "\"" + tableName + "\"" + ")]\r\n");
+ build.Append(@" [SugarTable(" + "\"" + tableName + "\"" + ", " + "\"" + tableName + "\"" + "), Entity(TableCnName = \"" + tableName + "\", TableName = \"" + tableName + "\")]\r\n");
build.Append(" public class " + tableName + " : BasePoco\r\n");
build.Append(" {\r\n");
@@ -486,6 +477,131 @@ namespace " + strNameSpace + @"
ls[tableName] = build.ToString();
CreateFilesByClassStringList(ls, strPath + @"\Models\" + groupName, "{0}");
+ #region Base
+ build = new StringBuilder();
+ ls = new Dictionary();
+ build.Append("/* 代码由框架生成,任何更改都可能导致被代码生成器覆盖,可自行修改。\r\n");
+ build.Append("* " + tableName + ".cs\r\n");
+ build.Append("*\r\n");
+ build.Append("*功 能: N / A\r\n");
+ build.Append("* 类 名: " + tableName + "\r\n");
+ build.Append("*\r\n");
+ build.Append("* Ver 变更日期 负责人 变更内容\r\n");
+ build.Append("* ───────────────────────────────────\r\n");
+ build.Append("*V0.01 " + DateTime.Now.ToString() + " SimonHsiao 初版\r\n");
+ build.Append("*\r\n");
+ build.Append("* Copyright(c) " + DateTime.Now.Year + " Tiobon Corporation. All Rights Reserved.\r\n");
+ build.Append("*┌──────────────────────────────────┐\r\n");
+ build.Append("*│ 此技术信息为本公司机密信息,未经本公司书面同意禁止向第三方披露. │\r\n");
+ build.Append("*│ 作者:SimonHsiao │\r\n");
+ build.Append("*└──────────────────────────────────┘\r\n");
+ build.Append("*/ \r\n");
+ build.Append("using System.ComponentModel;\r\n");
+ build.Append("using System.ComponentModel.DataAnnotations;\r\n");
+ build.Append("\r\n");
+ build.Append("namespace Tiobon.Core.Model.Models\r\n");
+ build.Append("{\r\n");
+ build.Append("\r\n");
+ build.Append(" /// \r\n");
+ build.Append(" /// " + tableName + "\r\n");
+ build.Append(" /// \r\n");
+ build.Append(" public class " + tableName + "Base\r\n");
+ build.Append(" {\r\n");
+
+ #region 属性
+ //build.Append("\r\n");
+
+ #region 处理表字段
+
+ for (int i = 0; i < dtColumn.Rows.Count; i++)
+ {
+ columnCode = dtColumn.Rows[i]["column_name"].ToString();
+ dataType = dtColumn.Rows[i]["data_type"].ToString();
+ column_description = dtColumn.Rows[i]["column_description"].ToString();
+ NUMERIC_PRECISION = dtColumn.Rows[i]["NUMERIC_PRECISION"].ToString();
+ NUMERIC_SCALE = dtColumn.Rows[i]["NUMERIC_SCALE"].ToString();
+ CHARACTER_MAXIMUM_LENGTH = dtColumn.Rows[i]["CHARACTER_MAXIMUM_LENGTH"].ToString();
+
+ if (string.IsNullOrWhiteSpace(column_description))
+ column_description = columnCode;
+
+ if (a.Contains(columnCode))
+ continue;
+
+ build.Append("\r\n");
+ build.Append(" /// \r\n");
+ build.Append(" /// " + column_description + "\r\n");
+ build.Append(" /// \r\n");
+ if (dataType == "decimal")
+ build.Append($" [Display(Name = \"" + columnCode + "\"), Description(\"" + column_description + "\"), Column(TypeName = \"decimal(" + NUMERIC_PRECISION + "," + NUMERIC_SCALE + ")\")]\r\n");
+ else if (dataType == "varchar" || dataType == "nvarchar" || dataType == "char" || dataType == "text")
+ build.Append(" [Display(Name = \"" + columnCode + "\"), Description(\"" + column_description + "\"), MaxLength(" + CHARACTER_MAXIMUM_LENGTH + ", ErrorMessage = \"" + column_description + " 不能超过 " + CHARACTER_MAXIMUM_LENGTH + " 个字符\")]\r\n");
+ else if (dataType == "decimal")
+ build.Append(" [Display(Name = \"" + columnCode + "\"), Description(\"" + column_description + "\")]\r\n");
+
+ switch (dataType)
+ {
+ #region 字符串
+ case "varchar":
+ case "nvarchar":
+ case "char":
+ case "text":
+ {
+ build.Append(" public string " + columnCode + " { get; set; }\r\n");
+ break;
+ }
+ #endregion
+
+ #region 日期
+ case "datetime":
+ case "date":
+ {
+ build.Append(" public DateTime? " + columnCode + " { get; set; }\r\n");
+ break;
+ }
+ #endregion
+
+ #region 数字
+ case "decimal":
+ {
+
+ build.Append(" public decimal? " + columnCode + " { get; set; }\r\n");
+ }
+ break;
+ case "int":
+ {
+
+ build.Append(" public int? " + columnCode + " { get; set; }\r\n");
+
+ break;
+ }
+ case "uniqueidentifier":
+ {
+
+ build.Append(" public Guid? " + columnCode + " { get; set; }\r\n");
+
+ break;
+ }
+ case "bit":
+ {
+
+ build.Append(" public bool? " + columnCode + " { get; set; }\r\n");
+
+ break;
+ }
+ #endregion
+ }
+ }
+ #endregion
+ #endregion
+
+
+ build.Append(" }\r\n");
+ build.Append("}\r\n");
+
+ ls.Add(tableName + ".Dto.Base", build.ToString());
+ CreateFilesByClassStringList(ls, strPath + @"\Base\" + groupName, "{0}");
+ #endregion
#region Insert
build = new StringBuilder();
@@ -514,7 +630,7 @@ namespace " + strNameSpace + @"
build.Append(" /// \r\n");
build.Append(" /// " + tableName + "\r\n");
build.Append(" /// \r\n");
- build.Append(" public class Insert" + tableName + "Input : " + tableName + "\r\n");
+ build.Append(" public class Insert" + tableName + "Input : " + tableName + "Base\r\n");
build.Append(" {\r\n");
build.Append(" }\r\n");
@@ -551,7 +667,7 @@ namespace " + strNameSpace + @"
build.Append(" /// \r\n");
build.Append(" /// " + tableName + "\r\n");
build.Append(" /// \r\n");
- build.Append(" public class Edit" + tableName + "Input : " + tableName + "\r\n");
+ build.Append(" public class Edit" + tableName + "Input : " + tableName + "Base\r\n");
build.Append(" {\r\n");
build.Append(" }\r\n");
diff --git a/Tiobon.Core.IServices/BASE/IBaseServices1.cs b/Tiobon.Core.IServices/BASE/IBaseServices1.cs
index 19036d60..31af230a 100644
--- a/Tiobon.Core.IServices/BASE/IBaseServices1.cs
+++ b/Tiobon.Core.IServices/BASE/IBaseServices1.cs
@@ -17,13 +17,13 @@ namespace Tiobon.Core.IServices.BASE
{
ISqlSugarClient Db { get; }
- Task QueryById(object objId);
- Task QueryById(object objId, bool blnUseCache = false);
- Task> QueryByIDs(object[] lstIds);
+ Task QueryById(object objId);
+ Task QueryById(object objId, bool blnUseCache = false);
+ Task> QueryByIDs(object[] lstIds);
- Task Add(TEntity model);
+ Task Add(TInsertDto model);
- Task> Add(List listEntity);
+ Task> Add(List listEntity);
Task DeleteById(object id);
@@ -31,7 +31,7 @@ namespace Tiobon.Core.IServices.BASE
Task DeleteByIds(object[] ids);
- Task Update(TEntity model);
+ Task Update(long Id, TEditDto model);
Task Update(List model);
Task Update(TEntity entity, string where);
diff --git a/Tiobon.Core.Model/Base/Ghra/Ghra_Grade.Dto.Base.cs b/Tiobon.Core.Model/Base/Ghra/Ghra_Grade.Dto.Base.cs
new file mode 100644
index 00000000..98e5cc33
--- /dev/null
+++ b/Tiobon.Core.Model/Base/Ghra/Ghra_Grade.Dto.Base.cs
@@ -0,0 +1,116 @@
+/* 代码由框架生成,任何更改都可能导致被代码生成器覆盖,可自行修改。
+* Ghra_Grade.cs
+*
+*功 能: N / A
+* 类 名: Ghra_Grade
+*
+* Ver 变更日期 负责人 变更内容
+* ───────────────────────────────────
+*V0.01 2024/4/15 14:57:43 SimonHsiao 初版
+*
+* Copyright(c) 2024 Tiobon Corporation. All Rights Reserved.
+*┌──────────────────────────────────┐
+*│ 此技术信息为本公司机密信息,未经本公司书面同意禁止向第三方披露. │
+*│ 作者:SimonHsiao │
+*└──────────────────────────────────┘
+*/
+using System.ComponentModel;
+using System.ComponentModel.DataAnnotations;
+
+namespace Tiobon.Core.Model.Models
+{
+
+ ///
+ /// Ghra_Grade
+ ///
+ public class Ghra_GradeBase
+ {
+
+ ///
+ /// Reverse6
+ ///
+ [Display(Name = "Reverse6"), Description("Reverse6"), MaxLength(1000, ErrorMessage = "Reverse6 不能超过 1000 个字符")]
+ public string Reverse6 { get; set; }
+
+ ///
+ /// MKey
+ ///
+ [Display(Name = "MKey"), Description("MKey"), MaxLength(200, ErrorMessage = "MKey 不能超过 200 个字符")]
+ public string MKey { get; set; }
+
+ ///
+ /// Reverse9
+ ///
+ [Display(Name = "Reverse9"), Description("Reverse9"), MaxLength(1000, ErrorMessage = "Reverse9 不能超过 1000 个字符")]
+ public string Reverse9 { get; set; }
+
+ ///
+ /// Reverse3
+ ///
+ [Display(Name = "Reverse3"), Description("Reverse3"), MaxLength(1000, ErrorMessage = "Reverse3 不能超过 1000 个字符")]
+ public string Reverse3 { get; set; }
+
+ ///
+ /// Reverse4
+ ///
+ [Display(Name = "Reverse4"), Description("Reverse4"), MaxLength(1000, ErrorMessage = "Reverse4 不能超过 1000 个字符")]
+ public string Reverse4 { get; set; }
+
+ ///
+ /// ReverseI1
+ ///
+ public int? ReverseI1 { get; set; }
+
+ ///
+ /// DataBelongID
+ ///
+ public int? DataBelongID { get; set; }
+
+ ///
+ /// Reverse7
+ ///
+ [Display(Name = "Reverse7"), Description("Reverse7"), MaxLength(1000, ErrorMessage = "Reverse7 不能超过 1000 个字符")]
+ public string Reverse7 { get; set; }
+
+ ///
+ /// GradeNo
+ ///
+ [Display(Name = "GradeNo"), Description("GradeNo"), MaxLength(100, ErrorMessage = "GradeNo 不能超过 100 个字符")]
+ public string GradeNo { get; set; }
+
+ ///
+ /// Reverse1
+ ///
+ [Display(Name = "Reverse1"), Description("Reverse1"), MaxLength(1000, ErrorMessage = "Reverse1 不能超过 1000 个字符")]
+ public string Reverse1 { get; set; }
+
+ ///
+ /// Reverse2
+ ///
+ [Display(Name = "Reverse2"), Description("Reverse2"), MaxLength(1000, ErrorMessage = "Reverse2 不能超过 1000 个字符")]
+ public string Reverse2 { get; set; }
+
+ ///
+ /// Reverse5
+ ///
+ [Display(Name = "Reverse5"), Description("Reverse5"), MaxLength(1000, ErrorMessage = "Reverse5 不能超过 1000 个字符")]
+ public string Reverse5 { get; set; }
+
+ ///
+ /// GradeName
+ ///
+ [Display(Name = "GradeName"), Description("GradeName"), MaxLength(1000, ErrorMessage = "GradeName 不能超过 1000 个字符")]
+ public string GradeName { get; set; }
+
+ ///
+ /// Reverse8
+ ///
+ [Display(Name = "Reverse8"), Description("Reverse8"), MaxLength(1000, ErrorMessage = "Reverse8 不能超过 1000 个字符")]
+ public string Reverse8 { get; set; }
+
+ ///
+ /// ReverseI2
+ ///
+ public int? ReverseI2 { get; set; }
+ }
+}
diff --git a/Tiobon.Core.Model/Edit/Ghra/Ghra_Grade.Dto.EditInput.cs b/Tiobon.Core.Model/Edit/Ghra/Ghra_Grade.Dto.EditInput.cs
index a533d5c5..884245aa 100644
--- a/Tiobon.Core.Model/Edit/Ghra/Ghra_Grade.Dto.EditInput.cs
+++ b/Tiobon.Core.Model/Edit/Ghra/Ghra_Grade.Dto.EditInput.cs
@@ -6,7 +6,7 @@
*
* Ver 变更日期 负责人 变更内容
* ───────────────────────────────────
-*V0.01 2024/4/12 18:49:06 SimonHsiao 初版
+*V0.01 2024/4/15 14:57:43 SimonHsiao 初版
*
* Copyright(c) 2024 Tiobon Corporation. All Rights Reserved.
*┌──────────────────────────────────┐
@@ -21,7 +21,7 @@ namespace Tiobon.Core.Model.Models
///
/// Ghra_Grade
///
- public class EditGhra_GradeInput : Ghra_Grade
+ public class EditGhra_GradeInput : Ghra_GradeBase
{
}
}
diff --git a/Tiobon.Core.Model/Insert/Ghra/Ghra_Grade.Dto.InsertInput.cs b/Tiobon.Core.Model/Insert/Ghra/Ghra_Grade.Dto.InsertInput.cs
index 6e2b86b1..ac154986 100644
--- a/Tiobon.Core.Model/Insert/Ghra/Ghra_Grade.Dto.InsertInput.cs
+++ b/Tiobon.Core.Model/Insert/Ghra/Ghra_Grade.Dto.InsertInput.cs
@@ -6,7 +6,7 @@
*
* Ver 变更日期 负责人 变更内容
* ───────────────────────────────────
-*V0.01 2024/4/12 18:49:06 SimonHsiao 初版
+*V0.01 2024/4/15 14:57:43 SimonHsiao 初版
*
* Copyright(c) 2024 Tiobon Corporation. All Rights Reserved.
*┌──────────────────────────────────┐
@@ -21,7 +21,7 @@ namespace Tiobon.Core.Model.Models
///
/// Ghra_Grade
///
- public class InsertGhra_GradeInput : Ghra_Grade
+ public class InsertGhra_GradeInput : Ghra_GradeBase
{
}
}
diff --git a/Tiobon.Core.Model/Models/Ghra/Ghra_Grade.cs b/Tiobon.Core.Model/Models/Ghra/Ghra_Grade.cs
index 45feea52..c11ba894 100644
--- a/Tiobon.Core.Model/Models/Ghra/Ghra_Grade.cs
+++ b/Tiobon.Core.Model/Models/Ghra/Ghra_Grade.cs
@@ -6,7 +6,7 @@
*
* Ver 变更日期 负责人 变更内容
* ───────────────────────────────────
-*V0.01 2024/4/12 18:49:06 SimonHsiao 初版
+*V0.01 2024/4/15 14:57:43 SimonHsiao 初版
*
* Copyright(c) 2024 Tiobon Corporation. All Rights Reserved.
*┌──────────────────────────────────┐
@@ -24,7 +24,7 @@ namespace Tiobon.Core.Model.Models
///
/// Ghra_Grade
///
- [SugarTable("Ghra_Grade", "Ghra_Grade"), Entity(TableCnName = "BOM", TableName = "PsBOM")]
+ [SugarTable("Ghra_Grade", "Ghra_Grade"), Entity(TableCnName = "Ghra_Grade", TableName = "Ghra_Grade")]
public class Ghra_Grade : BasePoco
{
diff --git a/Tiobon.Core.Model/View/Ghra/Ghra_Grade.Dto.View.cs b/Tiobon.Core.Model/View/Ghra/Ghra_Grade.Dto.View.cs
index 7d9cf784..57333a42 100644
--- a/Tiobon.Core.Model/View/Ghra/Ghra_Grade.Dto.View.cs
+++ b/Tiobon.Core.Model/View/Ghra/Ghra_Grade.Dto.View.cs
@@ -6,7 +6,7 @@
*
* Ver 变更日期 负责人 变更内容
* ───────────────────────────────────
-*V0.01 2024/4/12 18:49:06 SimonHsiao 初版
+*V0.01 2024/4/15 14:57:43 SimonHsiao 初版
*
* Copyright(c) 2024 Tiobon Corporation. All Rights Reserved.
*┌──────────────────────────────────┐
diff --git a/Tiobon.Core.Services/BASE/BaseServices1.cs b/Tiobon.Core.Services/BASE/BaseServices1.cs
index 3a5232cf..5a7a138c 100644
--- a/Tiobon.Core.Services/BASE/BaseServices1.cs
+++ b/Tiobon.Core.Services/BASE/BaseServices1.cs
@@ -1,14 +1,24 @@
using System.Collections.Generic;
using System.Data;
+using System.Diagnostics;
using System.Linq.Expressions;
+using System.Reflection;
using AgileObjects.AgileMapper;
+using Microsoft.AspNetCore.Http;
+using Microsoft.IdentityModel.Tokens;
+using MongoDB.Driver;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
+using SharpCompress.Common;
using SqlSugar;
using Tiobon.Core.Common;
+using Tiobon.Core.Common.Extensions;
using Tiobon.Core.Common.Helper;
+using Tiobon.Core.Common.HttpContextUser;
using Tiobon.Core.Common.UserManager;
using Tiobon.Core.IRepository.Base;
using Tiobon.Core.IServices.BASE;
using Tiobon.Core.Model;
+using Tiobon.Core.Repository.Base;
namespace Tiobon.Core.Services.BASE
{
@@ -31,9 +41,10 @@ namespace Tiobon.Core.Services.BASE
public ISqlSugarClient Db => BaseDal.Db;
- public async Task QueryById(object objId)
+ public async Task QueryById(object objId)
{
- return await BaseDal.QueryById(objId);
+ var data = await BaseDal.QueryById(objId);
+ return Mapper.Map(data).ToANew();
}
///
@@ -42,9 +53,10 @@ namespace Tiobon.Core.Services.BASE
/// id(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件
/// 是否使用缓存
/// 数据实体
- public async Task QueryById(object objId, bool blnUseCache = false)
+ public async Task QueryById(object objId, bool blnUseCache = false)
{
- return await BaseDal.QueryById(objId, blnUseCache);
+ var data = await BaseDal.QueryById(objId, blnUseCache);
+ return Mapper.Map(data).ToANew();
}
///
@@ -52,9 +64,10 @@ namespace Tiobon.Core.Services.BASE
///
/// id列表(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件
/// 数据实体列表
- public async Task> QueryByIDs(object[] lstIds)
+ public async Task> QueryByIDs(object[] lstIds)
{
- return await BaseDal.QueryByIDs(lstIds);
+ var data = await BaseDal.QueryByIDs(lstIds);
+ return Mapper.Map(data).ToANew>();
}
///
@@ -62,10 +75,22 @@ namespace Tiobon.Core.Services.BASE
///
/// 博文实体类
///
- public async Task Add(TEntity entity)
+ public async Task Add(TInsertDto entity)
{
var userId = UserContext.Current.User_Id;
- return await BaseDal.Add(entity);
+ HttpRequest request = UserContext.Context.Request;
+ var api = request.Path.ObjToString().TrimEnd('/').ToLower();
+ var ip = GetUserIp(UserContext.Context);
+
+ BasePoco ent = entity as BasePoco;
+ if (ent.CreateBy != null)
+ ent.CreateBy = userId;
+ ent.CreateTime = DateTime.Now;
+ ent.CreateIP = ip;
+ ent.CreateProg = api;
+
+ var entity1 = Mapper.Map(entity).ToANew();
+ return await BaseDal.Add(entity1);
}
///
@@ -73,9 +98,23 @@ namespace Tiobon.Core.Services.BASE
///
/// 实体集合
/// 影响行数
- public async Task> Add(List listEntity)
+ public async Task> Add(List listEntity)
{
- return await BaseDal.Add(listEntity);
+ var userId = UserContext.Current.User_Id;
+ HttpRequest request = UserContext.Context.Request;
+ var api = request.Path.ObjToString().TrimEnd('/').ToLower();
+ var ip = GetUserIp(UserContext.Context);
+ listEntity.ForEach(entity =>
+ {
+ BasePoco ent = entity as BasePoco;
+ if (ent.CreateBy != null)
+ ent.CreateBy = userId;
+ ent.CreateTime = DateTime.Now;
+ ent.CreateIP = ip;
+ ent.CreateProg = api;
+ });
+ var list = Mapper.Map(listEntity).ToANew>();
+ return await BaseDal.Add(list);
}
///
@@ -83,8 +122,23 @@ namespace Tiobon.Core.Services.BASE
///
/// 博文实体类
///
- public async Task Update(TEntity entity)
+ public async Task Update(long Id, TEditDto editModel)
{
+ var userId = UserContext.Current.User_Id;
+ HttpRequest request = UserContext.Context.Request;
+ var api = request.Path.ObjToString().TrimEnd('/').ToLower();
+ var ip = GetUserIp(UserContext.Context);
+
+ if (editModel == null || !await BaseDal.AnyAsync(Id))
+ return false;
+
+ var entity = await BaseDal.QueryById(Id);
+ ConvertTEditDto2TEntity(editModel, entity);
+ BasePoco ent = entity as BasePoco;
+ ent.UpdateBy = userId;
+ ent.UpdateTime = DateTime.Now;
+ ent.UpdateIP = ip;
+ ent.UpdateProg = api;
return await BaseDal.Update(entity);
}
///
@@ -92,13 +146,36 @@ namespace Tiobon.Core.Services.BASE
///
/// 博文实体类
///
- public async Task Update(List entity)
+ public async Task Update(List listEntity)
{
- return await BaseDal.Update(entity);
+ var userId = UserContext.Current.User_Id;
+ HttpRequest request = UserContext.Context.Request;
+ var api = request.Path.ObjToString().TrimEnd('/').ToLower();
+ var ip = GetUserIp(UserContext.Context);
+ listEntity.ForEach(entity =>
+ {
+ BasePoco ent = entity as BasePoco;
+ if (ent.UpdateBy != null)
+ ent.UpdateBy = userId;
+ ent.UpdateTime = DateTime.Now;
+ ent.UpdateIP = ip;
+ ent.UpdateProg = api;
+ });
+ return await BaseDal.Update(listEntity);
}
public async Task Update(TEntity entity, string where)
{
+ var userId = UserContext.Current.User_Id;
+ HttpRequest request = UserContext.Context.Request;
+ var api = request.Path.ObjToString().TrimEnd('/').ToLower();
+ var ip = GetUserIp(UserContext.Context);
+ BasePoco ent = entity as BasePoco;
+ if (ent.UpdateBy != null)
+ ent.UpdateBy = userId;
+ ent.UpdateTime = DateTime.Now;
+ ent.UpdateIP = ip;
+ ent.UpdateProg = api;
return await BaseDal.Update(entity, where);
}
@@ -381,5 +458,76 @@ namespace Tiobon.Core.Services.BASE
}
#endregion
+
+ public static string GetUserIp(HttpContext context)
+ {
+ string realIP = null;
+ string forwarded = null;
+ string remoteIpAddress = context.Connection.RemoteIpAddress.ToString();
+ if (context.Request.Headers.ContainsKey("X-Real-IP"))
+ {
+ realIP = context.Request.Headers["X-Real-IP"].ToString();
+ if (realIP != remoteIpAddress)
+ {
+ remoteIpAddress = realIP;
+ }
+ }
+ if (context.Request.Headers.ContainsKey("X-Forwarded-For"))
+ {
+ forwarded = context.Request.Headers["X-Forwarded-For"].ToString();
+ if (forwarded != remoteIpAddress)
+ {
+ remoteIpAddress = forwarded;
+ }
+ }
+ remoteIpAddress = remoteIpAddress.Replace("::ffff:", null);
+ return remoteIpAddress;
+ }
+
+
+ #region 辅助方法
+ ///
+ /// 转换TEditDto2TEntity
+ ///
+ ///
+ ///
+ ///
+ protected void ConvertTEditDto2TEntity(TEditDto source, TEntity dest)
+ {
+ foreach (PropertyInfo mItem in typeof(TEditDto).GetProperties())
+ {
+ if (dest.HasField(mItem.Name))
+ dest.SetValueForField(mItem.Name, mItem.GetValue(source, null));
+ }
+ //dest.SetValueForField(DbConsts.ColunmName_LastModificationTime, DateTimeHelper.Now());
+ //if (_currentUserId != default)
+ //{
+ // //dest.SetValueForField(DbConsts.ColunmName_LastModifierId, _currentUserId);
+ // dest.SetValueForField(DbConsts.ColunmName_LastModifier, _currentUserName);
+ //}
+
+ //if (_currentTenantId != null)
+ //{
+ // dest.SetValueForField(DbConsts.ColunmName_TenantId, _currentTenantId);
+ //}
+ }
+
+ ///
+ /// 获取根据ID查询的条件
+ ///
+ ///
+ ///
+ protected QueryFilter QueryFilterById(Guid id)
+ {
+ return new QueryFilter
+ {
+ PageIndex = 1,
+ PageSize = 1,
+ Sorting = string.Empty,
+ Predicate = "Id=@0",
+ PredicateValues = new object[] { id }
+ };
+ }
+ #endregion
}
}
\ No newline at end of file