diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml
index 7a8e4863..60658e32 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml
@@ -102,6 +102,46 @@
+
+
+ Json To Sql 类比模式,通用模型
+
+
+
+
+
+ 主键查询
+
+
+
+
+
+
+ 全部列表查询
+
+
+
+
+
+ 添加
+
+
+
+
+
+
+ 修改
+
+
+
+
+
+
+ 列表删除
+
+
+
+
动态条件分页查询
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseCrudController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseCrudController.cs
index 0566c588..2f3114a2 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseCrudController.cs
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseCrudController.cs
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
+using Yi.Framework.Common.Helper;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Language;
@@ -15,7 +16,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
///
///
[ApiController]
- public class BaseCrudController : ControllerBase where T : class, IBaseModelEntity,new()
+ public class BaseCrudController : ControllerBase where T : class,new()
{
private readonly ILogger _logger;
private IBaseService _baseService;
@@ -95,7 +96,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
[HttpDelete]
public virtual async Task DeleteList(List ids)
{
- return Result.Success().SetStatus(await _repository.DeleteByLogicAsync(ids));
+ return Result.Success().SetStatus(await _repository.DeleteByIdAsync(ids.ToDynamicArray()));
}
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseSimpleCrudController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseSimpleCrudController.cs
new file mode 100644
index 00000000..a4acd206
--- /dev/null
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseSimpleCrudController.cs
@@ -0,0 +1,91 @@
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Localization;
+using Yi.Framework.Common.Helper;
+using Yi.Framework.Common.Models;
+using Yi.Framework.Interface;
+using Yi.Framework.Language;
+using Yi.Framework.Model.Models;
+using Yi.Framework.Model.Query;
+using Yi.Framework.Repository;
+using Yi.Framework.WebCore.AttributeExtend;
+
+namespace Yi.Framework.ApiMicroservice.Controllers
+{
+ ///
+ /// Json To Sql 类比模式,通用模型
+ ///
+ ///
+ [ApiController]
+ public class BaseSimpleCrudController : ControllerBase where T : class, new()
+ {
+ private readonly ILogger _logger;
+ private IBaseService _baseService;
+ private IRepository _repository;
+ public BaseSimpleCrudController(ILogger logger, IBaseService iBaseService)
+ {
+ _logger = logger;
+ _baseService = iBaseService;
+ _repository = iBaseService._repository;
+ }
+
+ ///
+ /// 主键查询
+ ///
+ ///
+ ///
+ [Permission($"{nameof(T)}:get")]
+ [HttpGet]
+ public virtual async Task GetById(long id)
+ {
+ return Result.Success().SetData(await _repository.GetByIdAsync(id));
+ }
+
+ ///
+ /// 全部列表查询
+ ///
+ ///
+ [Permission($"{nameof(T)}:get")]
+ [HttpPost]
+ public virtual async Task GetList()
+ {
+ return Result.Success().SetData(await _repository.GetListAsync());
+ }
+
+ ///
+ /// 添加
+ ///
+ ///
+ ///
+ [Permission($"{nameof(T)}:add")]
+ [HttpPost]
+ public virtual async Task Add(T entity)
+ {
+ return Result.Success().SetData(await _repository.InsertReturnSnowflakeIdAsync(entity));
+ }
+
+
+ ///
+ /// 修改
+ ///
+ ///
+ ///
+ [Permission($"{nameof(T)}:update")]
+ [HttpPut]
+ public virtual async Task Update(T entity)
+ {
+ return Result.Success().SetStatus(await _repository.UpdateIgnoreNullAsync(entity));
+ }
+
+ ///
+ /// 列表删除
+ ///
+ ///
+ ///
+ [Permission($"{nameof(T)}:del")]
+ [HttpDelete]
+ public virtual async Task DelList(List ids)
+ {
+ return Result.Success().SetStatus(await _repository.DeleteByIdsAsync(ids.ToDynamicArray()));
+ }
+ }
+}
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/DictionaryController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/DictionaryController.cs
index c5c38f6f..cb77be55 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/DictionaryController.cs
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/DictionaryController.cs
@@ -19,14 +19,12 @@ namespace Yi.Framework.ApiMicroservice.Controllers
{
[ApiController]
[Route("api/[controller]/[action]")]
- public class DictionaryController
+ public class DictionaryController :BaseSimpleCrudController
{
private IDictionaryService _iDictionaryService;
- private IDictionaryInfoService _iDictionaryInfoService;
- public DictionaryController(ILogger logger, IDictionaryService iDictionaryService, IDictionaryInfoService iDictionaryInfoService)
+ public DictionaryController(ILogger logger, IDictionaryService iDictionaryService):base(logger, iDictionaryService)
{
_iDictionaryService = iDictionaryService;
- _iDictionaryInfoService = iDictionaryInfoService;
}
///
@@ -40,63 +38,5 @@ namespace Yi.Framework.ApiMicroservice.Controllers
{
return Result.Success().SetData(await _iDictionaryService.SelctPageList(dic, page));
}
-
- ///
- /// 添加字典表
- ///
- ///
- ///
- [HttpPost]
- public async Task Add(DictionaryEntity dic)
- {
- return Result.Success().SetData(await _iDictionaryService._repository.InsertReturnSnowflakeIdAsync(dic));
- }
-
- ///
- /// 根据字典id获取字典表
- ///
- ///
- ///
- [HttpGet]
- [Route("{id}")]
- public async Task GetById(long id)
- {
- return Result.Success().SetData(await _iDictionaryService._repository.GetByIdAsync(id));
- }
-
-
- ///
- /// 获取全部字典表
- ///
- ///
- [HttpGet]
- public async Task GetList()
- {
- return Result.Success().SetData(await _iDictionaryService._repository.GetListAsync());
- }
-
-
- ///
- /// id范围删除
- ///
- ///
- ///
- [HttpDelete]
-
- public async Task DelList(List ids)
- {
- return Result.Success().SetStatus(await _iDictionaryService._repository.DeleteByIdsAsync(ids.ToDynamicArray()));
- }
-
- ///
- /// 更新
- ///
- ///
- ///
- [HttpPut]
- public async Task Update(DictionaryEntity dic)
- {
- return Result.Success().SetStatus(await _iDictionaryService._repository.UpdateIgnoreNullAsync(dic));
- }
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/DictionaryInfoController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/DictionaryInfoController.cs
index 2a41bb27..ac8fcec2 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/DictionaryInfoController.cs
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/DictionaryInfoController.cs
@@ -19,13 +19,11 @@ namespace Yi.Framework.ApiMicroservice.Controllers
{
[ApiController]
[Route("api/[controller]/[action]")]
- public class DictionaryInfoController
+ public class DictionaryInfoController:BaseSimpleCrudController
{
- private IDictionaryService _iDictionaryService;
private IDictionaryInfoService _iDictionaryInfoService;
- public DictionaryInfoController(ILogger logger, IDictionaryService iDictionaryService, IDictionaryInfoService iDictionaryInfoService)
+ public DictionaryInfoController(ILogger logger, IDictionaryInfoService iDictionaryInfoService):base(logger, iDictionaryInfoService)
{
- _iDictionaryService = iDictionaryService;
_iDictionaryInfoService = iDictionaryInfoService;
}
@@ -41,17 +39,6 @@ namespace Yi.Framework.ApiMicroservice.Controllers
return Result.Success().SetData(await _iDictionaryInfoService.SelctPageList(dicInfo, page));
}
- ///
- /// 添加字典信息表
- ///
- ///
- ///
- [HttpPost]
- public async Task Add(DictionaryInfoEntity dicInfo)
- {
- return Result.Success().SetData(await _iDictionaryInfoService._repository.InsertReturnSnowflakeIdAsync(dicInfo));
- }
-
///
/// 根据字典类别获取字典信息
///
@@ -63,42 +50,5 @@ namespace Yi.Framework.ApiMicroservice.Controllers
{
return Result.Success().SetData(await _iDictionaryInfoService._repository.GetListAsync(u=>u.DictType==type&&u.IsDeleted==false));
}
-
- ///
- /// id范围删除
- ///
- ///
- ///
- [HttpDelete]
-
- public async Task DelList(List ids)
- {
- return Result.Success().SetStatus(await _iDictionaryInfoService._repository.DeleteByIdsAsync(ids.ToDynamicArray()));
- }
-
-
- ///
- /// 更新
- ///
- ///
- ///
- [HttpPut]
- public async Task Update(DictionaryInfoEntity dicInfo)
- {
- return Result.Success().SetStatus(await _iDictionaryInfoService._repository.UpdateIgnoreNullAsync(dicInfo));
- }
-
-
- ///
- /// 根据字典id获取字典信息表
- ///
- ///
- ///
- [HttpGet]
- [Route("{id}")]
- public async Task GetById(long id)
- {
- return Result.Success().SetData(await _iDictionaryInfoService._repository.GetByIdAsync(id));
- }
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IBaseService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IBaseService.cs
index 93411ba5..c0611af0 100644
--- a/Yi.Framework.Net6/Yi.Framework.Interface/IBaseService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Interface/IBaseService.cs
@@ -8,7 +8,7 @@ using Yi.Framework.Repository;
namespace Yi.Framework.Interface
{
- public interface IBaseService where T: class, IBaseModelEntity,new()
+ public interface IBaseService where T: class,new()
{
public IRepository _repository { get; set; }
}
diff --git a/Yi.Framework.Net6/Yi.Framework.Model/Yi.Framework.Model.csproj b/Yi.Framework.Net6/Yi.Framework.Model/Yi.Framework.Model.csproj
index 31183d3e..5f6a7ce3 100644
--- a/Yi.Framework.Net6/Yi.Framework.Model/Yi.Framework.Model.csproj
+++ b/Yi.Framework.Net6/Yi.Framework.Model/Yi.Framework.Model.csproj
@@ -6,7 +6,7 @@
-
+
diff --git a/Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs b/Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs
index ec1d28a6..61adc0d3 100644
--- a/Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs
@@ -11,16 +11,16 @@ using Yi.Framework.Model.Query;
namespace Yi.Framework.Repository
{
- public interface IRepository : ISimpleClient where T : class, IBaseModelEntity, new()
+ public interface IRepository : ISimpleClient where T : class, new()
{
public ISugarQueryable _DbQueryable { get; set; }
public ISqlSugarClient _Db { get; set; }
public Task UseTranAsync(Func func);
- public Task InsertReturnEntityAsync(T entity);
+ //public Task InsertReturnEntityAsync(T entity);
public Task> StoreAsync(string storeName, object para);
public Task>> CommonPageAsync(QueryPageCondition pars);
public Task> GetListAsync(QueryCondition pars);
- public Task DeleteByLogicAsync(List ids);
+ //public Task DeleteByLogicAsync(List ids);
public Task UpdateIgnoreNullAsync(T entity);
public Task> UseSqlAsync(string sql, object parameters = null);
public Task UseSqlAsync(string sql, object parameters = null);
diff --git a/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs b/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs
index dcd810b8..bd689814 100644
--- a/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs
@@ -12,7 +12,7 @@ namespace Yi.Framework.Repository
/// 仓储模式
///
///
- public class Repository : SimpleClient, IRepository where T : class, IBaseModelEntity, new()
+ public class Repository : SimpleClient, IRepository where T : class, new()
{
public ISugarQueryable _DbQueryable { get { return base.Context.Queryable(); } set { } }
@@ -59,16 +59,16 @@ namespace Yi.Framework.Repository
return await _Db.Ado.ExecuteCommandAsync(sql, parameters) >0;
}
- ///
- /// 添加返回实体
- ///
- ///
- ///
- public async Task InsertReturnEntityAsync(T entity)
- {
- entity.Id =SnowFlakeSingle.instance.getID();
- return await _Db.Insertable(entity).ExecuteReturnEntityAsync();
- }
+ /////
+ ///// 添加返回实体
+ /////
+ /////
+ /////
+ //public async Task InsertReturnEntityAsync(T entity)
+ //{
+ // entity.Id =SnowFlakeSingle.instance.getID();
+ // return await _Db.Insertable(entity).ExecuteReturnEntityAsync();
+ //}
///
/// 更新忽略空值
@@ -81,16 +81,16 @@ namespace Yi.Framework.Repository
}
- ///
- /// 逻辑多删除
- ///
- ///
- public async Task DeleteByLogicAsync(List ids)
- {
- var entitys = await _Db.Queryable().Where(u => ids.Contains(u.Id)).ToListAsync();
- entitys.ForEach(u=>u.IsDeleted=true);
- return await _Db.Updateable(entitys).ExecuteCommandAsync()>0;
- }
+ /////
+ ///// 逻辑多删除
+ /////
+ /////
+ //public async Task DeleteByLogicAsync(List ids)
+ //{
+ // var entitys = await _Db.Queryable().Where(u => ids.Contains(u.Id)).ToListAsync();
+ // entitys.ForEach(u=>u.IsDeleted=true);
+ // return await _Db.Updateable(entitys).ExecuteCommandAsync()>0;
+ //}
///
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/BaseService.cs b/Yi.Framework.Net6/Yi.Framework.Service/BaseService.cs
index 603bab64..26f11ef6 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/BaseService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/BaseService.cs
@@ -9,7 +9,7 @@ using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
- public class BaseService:IBaseService where T:class, IBaseModelEntity,new()
+ public class BaseService:IBaseService where T:class,new()
{
public IRepository _repository { get; set; }
public BaseService(IRepository iRepository)
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs b/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs
index 3906b4e7..cef8cf52 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs
@@ -64,7 +64,13 @@ namespace Yi.Framework.Service
{
user.UserName = userEntity.UserName;
user.BuildPassword();
- userAction.Invoke(await _repository.InsertReturnEntityAsync(user));
+ //等待老杰哥更新,杰哥漏了雪花id呀,嘿嘿
+ //var entity = await _repository.InsertReturnSnowflakeEntityAsync(user);
+ //userAction.Invoke(await _repository.GetByIdAsync(entity));
+
+ //await _repository.InsertReturnSnowflakeEntityAsync(user);
+ //userAction.Invoke(await _repository.GetByIdAsync(user));
+
return true;
}
return false;