diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseClassController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseClassController.cs index 3f058068..5cc4a7fe 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseClassController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseClassController.cs @@ -1,251 +1,267 @@ -using SqlSugar; -using Mapper = AgileObjects.AgileMapper.Mapper; + namespace Tiobon.Core.Api.Controllers; /// -/// 课程分类(Controller) +/// Ghre_CourseClass(Controller) /// [Route("api/[controller]")] [ApiController, GlobalActionFilter] [Authorize(Permissions.Name), ApiExplorerSettings(GroupName = Grouping.GroupName_Ghre)] -public class Ghre_CourseClassController : BaseApiController +public class Ghre_CourseClassController : BaseController { - protected IGhre_CourseClassServices _service; - - public Ghre_CourseClassController(IGhre_CourseClassServices service) + public Ghre_CourseClassController(IGhre_CourseClassServices service) : base(service) { - _service = service; } +} +//using SqlSugar; +//using Mapper = AgileObjects.AgileMapper.Mapper; - #region 基础接口 +//namespace Tiobon.Core.Api.Controllers; - #region 查询 - /// - /// 根据条件查询数据 - /// - /// 条件 - /// - [HttpGet] - public async Task> QueryByFilter([FromFilter] QueryFilter filter) - { - //var data = await _service.QueryFilterPage(); - RefAsync totalCount = 0; - var query = _service.Db.Queryable(); - if (!filter.Conditions.IsNullOrEmpty()) - query = query.Where(filter.Conditions); - var list = await query - .OrderByIF(!string.IsNullOrEmpty(filter.Sorting), filter.Sorting) - .ToPageListAsync(filter.PageIndex, filter.PageSize, totalCount); +///// +///// 课程分类(Controller) +///// +//[Route("api/[controller]")] +//[ApiController, GlobalActionFilter] +//[Authorize(Permissions.Name), ApiExplorerSettings(GroupName = Grouping.GroupName_Ghre)] +//public class Ghre_CourseClassController : BaseApiController +//{ +// protected IGhre_CourseClassServices _service; - return new ServicePageResult1(filter.PageIndex, totalCount, filter.PageSize, Mapper.Map(list).ToANew>()); +// public Ghre_CourseClassController(IGhre_CourseClassServices service) +// { +// _service = service; +// } - } +// #region 基础接口 - public static T ConvertTo(object input) - { - if (input == null) - { - throw new ArgumentNullException(nameof(input)); - } - - // 当T是Nullable类型时,需要获取其基础类型 - Type targetType = typeof(T); - Type nullableType = Nullable.GetUnderlyingType(targetType); - targetType = nullableType ?? targetType; - - // 检查input是否已经是T类型 - if (input is T) - { - return (T)input; - } - - // 尝试转换 - try - { - return (T)Convert.ChangeType(input, targetType); - } - catch (InvalidCastException) - { - throw new InvalidOperationException($"Cannot convert an instance of type {input.GetType().Name} to type {typeof(T).Name}."); - } - } +// #region 查询 +// /// +// /// 根据条件查询数据 +// /// +// /// 条件 +// /// +// [HttpGet] +// public async Task> QueryByFilter([FromFilter] QueryFilter filter) +// { +// //var data = await _service.QueryFilterPage(); +// RefAsync totalCount = 0; +// var query = _service.Db.Queryable(); +// if (!filter.Conditions.IsNullOrEmpty()) +// query = query.Where(filter.Conditions); +// var list = await query +// .OrderByIF(!string.IsNullOrEmpty(filter.Sorting), filter.Sorting) +// .ToPageListAsync(filter.PageIndex, filter.PageSize, totalCount); - /// - /// 根据Id查询数据 - /// - /// 主键ID - /// - [HttpGet("{Id}")] - public virtual async Task> QueryById(long Id) - { - var entity1 = await _service.QueryById(Id); - var entity = ConvertTo(entity1); - if (entity is null) - return new ServiceResult() { Success = false, Status = 500, Message = "获取失败", Data = default }; - else - return new ServiceResult() { Success = false, Message = "获取成功", Data = entity }; +// return new ServicePageResult1(filter.PageIndex, totalCount, filter.PageSize, Mapper.Map(list).ToANew>()); - } - #endregion - - #region 新增 - /// - /// 新增数据 - /// - /// - /// - [HttpPost] - public virtual async Task> Insert([FromBody] InsertGhre_CourseClassInput insertModel) - { - var data = new ServiceResult() { Success = true, Message = "新增成功", Data = null }; - - var id = await _service.Add(insertModel); - data.Success = id > 0; - if (data.Success) - data.Data = id.ObjToString(); - else - return new ServiceResult() { Success = false, Status = 500, Message = "新增失败", Data = default }; - return data; - } +// } - /// - /// 批量新增数据 - /// - /// - [HttpPost, Route("BulkInsert")] - public virtual async Task>> BulkInsert([FromBody] List insertModels) - { - var data = new ServiceResult>() { Success = true, Message = "新增成功", Data = null }; - var ids = await _service.Add(insertModels); - data.Success = ids.Any(); - if (data.Success) - data.Data = ids; - else - return new ServiceResult>() { Success = false, Status = 500, Message = "新增失败", Data = default }; - - return data; - } +// public static T ConvertTo(object input) +// { +// if (input == null) +// { +// throw new ArgumentNullException(nameof(input)); +// } - #endregion - - #region 更新 - /// - /// 更新数据 - /// - /// 主键ID - /// - /// - [HttpPut("{Id}")] - public virtual async Task Put(long Id, [FromBody] EditGhre_CourseClassInput editModel) - { - var data = new ServiceResult() { Success = true, Message = "更新成功", Data = null }; - var flag = await _service.Update(Id, editModel); - if (!flag) - return new ServiceResult() { Success = false, Status = 500, Message = "更新失败", Data = default }; - return data; - } - /// - /// 批量更新数据 - /// - /// - [HttpPut, Route("BulkUpdate")] - public virtual async Task BulkUpdate([FromBody] Dictionary editModels) - { - var data = new ServiceResult() { Success = true, Message = "更新成功", Data = null }; - var flag = await _service.Update(editModels); - if (!flag) - return new ServiceResult() { Success = false, Status = 500, Message = "更新失败", Data = default }; +// // 当T是Nullable类型时,需要获取其基础类型 +// Type targetType = typeof(T); +// Type nullableType = Nullable.GetUnderlyingType(targetType); +// targetType = nullableType ?? targetType; - return data; - } - #endregion - - #region 删除 - /// - /// 删除数据 - /// - /// 主键ID - /// - [HttpDelete("{Id}")] - public virtual async Task Delete(long Id) - { - var data = new ServiceResult() { Success = true, Message = "删除成功", Data = null }; - var isExist = await _service.AnyAsync(Id); - if (!isExist) - return new ServiceResult() { Success = false, Status = 500, Message = "无效的数据ID", Data = default }; - data.Success = await _service.DeleteById1(Id); ; - if (!data.Success) - return new ServiceResult() { Success = false, Status = 500, Message = "删除失败", Data = default }; - return data; - } +// // 检查input是否已经是T类型 +// if (input is T) +// { +// return (T)input; +// } - /// - /// 批量删除数据 - /// - /// 主键IDs - /// - [HttpDelete, Route("BulkDelete")] - public virtual async Task BulkDelete([FromBody] long[] Ids) - { - var data = new ServiceResult() { Success = true, Message = "删除成功", Data = null }; - data.Success = await _service.DeleteById1(Ids); - if (!data.Success) - return new ServiceResult() { Success = false, Status = 500, Message = "删除失败", Data = default }; - return data; - } - #endregion +// // 尝试转换 +// try +// { +// return (T)Convert.ChangeType(input, targetType); +// } +// catch (InvalidCastException) +// { +// throw new InvalidOperationException($"Cannot convert an instance of type {input.GetType().Name} to type {typeof(T).Name}."); +// } +// } - #endregion -} +// /// +// /// 根据Id查询数据 +// /// +// /// 主键ID +// /// +// [HttpGet("{Id}")] +// public virtual async Task> QueryById(long Id) +// { +// var entity1 = await _service.QueryById(Id); +// var entity = ConvertTo(entity1); +// if (entity is null) +// return new ServiceResult() { Success = false, Status = 500, Message = "获取失败", Data = default }; +// else +// return new ServiceResult() { Success = false, Message = "获取成功", Data = entity }; +// } +// #endregion -/// -/// 服务层分页响应实体(泛型) -/// -public class ServicePageResult1 -{ - /// - /// 状态码 - /// - public int Status { get; set; } = 200; - /// - /// 操作是否成功 - /// - public bool Success { get; set; } = false; - /// - /// 返回信息 - /// - public string Message { get; set; } = null; - /// - /// 当前页标 - /// - public int Page { get; set; } = 1; - /// - /// 总页数 - /// - public int PageCount => (int)Math.Ceiling((decimal)TotalCount / PageSize); - /// - /// 数据总数 - /// - public int TotalCount { get; set; } = 0; - /// - /// 每页大小 - /// - public int PageSize { set; get; } = 20; - /// - /// 返回数据 - /// - public List Data { get; set; } - - public ServicePageResult1() { } - - public ServicePageResult1(int page, int totalCount, int pageSize, List data) - { - Success = true; - this.Page = page; - this.TotalCount = totalCount; - PageSize = pageSize; - this.Data = data; - } -} \ No newline at end of file +// #region 新增 +// /// +// /// 新增数据 +// /// +// /// +// /// +// [HttpPost] +// public virtual async Task> Insert([FromBody] InsertGhre_CourseClassInput insertModel) +// { +// var data = new ServiceResult() { Success = true, Message = "新增成功", Data = null }; + +// var id = await _service.Add(insertModel); +// data.Success = id > 0; +// if (data.Success) +// data.Data = id.ObjToString(); +// else +// return new ServiceResult() { Success = false, Status = 500, Message = "新增失败", Data = default }; +// return data; +// } + +// /// +// /// 批量新增数据 +// /// +// /// +// [HttpPost, Route("BulkInsert")] +// public virtual async Task>> BulkInsert([FromBody] List insertModels) +// { +// var data = new ServiceResult>() { Success = true, Message = "新增成功", Data = null }; +// var ids = await _service.Add(insertModels); +// data.Success = ids.Any(); +// if (data.Success) +// data.Data = ids; +// else +// return new ServiceResult>() { Success = false, Status = 500, Message = "新增失败", Data = default }; + +// return data; +// } + +// #endregion + +// #region 更新 +// /// +// /// 更新数据 +// /// +// /// 主键ID +// /// +// /// +// [HttpPut("{Id}")] +// public virtual async Task Put(long Id, [FromBody] EditGhre_CourseClassInput editModel) +// { +// var data = new ServiceResult() { Success = true, Message = "更新成功", Data = null }; +// var flag = await _service.Update(Id, editModel); +// if (!flag) +// return new ServiceResult() { Success = false, Status = 500, Message = "更新失败", Data = default }; +// return data; +// } +// /// +// /// 批量更新数据 +// /// +// /// +// [HttpPut, Route("BulkUpdate")] +// public virtual async Task BulkUpdate([FromBody] Dictionary editModels) +// { +// var data = new ServiceResult() { Success = true, Message = "更新成功", Data = null }; +// var flag = await _service.Update(editModels); +// if (!flag) +// return new ServiceResult() { Success = false, Status = 500, Message = "更新失败", Data = default }; + +// return data; +// } +// #endregion + +// #region 删除 +// /// +// /// 删除数据 +// /// +// /// 主键ID +// /// +// [HttpDelete("{Id}")] +// public virtual async Task Delete(long Id) +// { +// var data = new ServiceResult() { Success = true, Message = "删除成功", Data = null }; +// var isExist = await _service.AnyAsync(Id); +// if (!isExist) +// return new ServiceResult() { Success = false, Status = 500, Message = "无效的数据ID", Data = default }; +// data.Success = await _service.DeleteById1(Id); ; +// if (!data.Success) +// return new ServiceResult() { Success = false, Status = 500, Message = "删除失败", Data = default }; +// return data; +// } + +// /// +// /// 批量删除数据 +// /// +// /// 主键IDs +// /// +// [HttpDelete, Route("BulkDelete")] +// public virtual async Task BulkDelete([FromBody] long[] Ids) +// { +// var data = new ServiceResult() { Success = true, Message = "删除成功", Data = null }; +// data.Success = await _service.DeleteById1(Ids); +// if (!data.Success) +// return new ServiceResult() { Success = false, Status = 500, Message = "删除失败", Data = default }; +// return data; +// } +// #endregion + +// #endregion +//} + + +///// +///// 服务层分页响应实体(泛型) +///// +//public class ServicePageResult1 +//{ +// /// +// /// 状态码 +// /// +// public int Status { get; set; } = 200; +// /// +// /// 操作是否成功 +// /// +// public bool Success { get; set; } = false; +// /// +// /// 返回信息 +// /// +// public string Message { get; set; } = null; +// /// +// /// 当前页标 +// /// +// public int Page { get; set; } = 1; +// /// +// /// 总页数 +// /// +// public int PageCount => (int)Math.Ceiling((decimal)TotalCount / PageSize); +// /// +// /// 数据总数 +// /// +// public int TotalCount { get; set; } = 0; +// /// +// /// 每页大小 +// /// +// public int PageSize { set; get; } = 20; +// /// +// /// 返回数据 +// /// +// public List Data { get; set; } + +// public ServicePageResult1() { } + +// public ServicePageResult1(int page, int totalCount, int pageSize, List data) +// { +// Success = true; +// this.Page = page; +// this.TotalCount = totalCount; +// PageSize = pageSize; +// this.Data = data; +// } +//} diff --git a/Tiobon.Core.Api/Tiobon.Core.Model.xml b/Tiobon.Core.Api/Tiobon.Core.Model.xml index 9046079d..04ec5aef 100644 --- a/Tiobon.Core.Api/Tiobon.Core.Model.xml +++ b/Tiobon.Core.Api/Tiobon.Core.Model.xml @@ -4041,6 +4041,16 @@ 课程分类(Dto.View) + + + 创建信息 + + + + + 修改信息 + + 课程场景(Dto.View) diff --git a/Tiobon.Core.Model/View/Ghre/Ghre_CourseClass.Dto.View.cs b/Tiobon.Core.Model/View/Ghre/Ghre_CourseClass.Dto.View.cs index 7c6eba03..6b310e98 100644 --- a/Tiobon.Core.Model/View/Ghre/Ghre_CourseClass.Dto.View.cs +++ b/Tiobon.Core.Model/View/Ghre/Ghre_CourseClass.Dto.View.cs @@ -23,5 +23,15 @@ namespace Tiobon.Core.Model.Models /// public class Ghre_CourseClassDto : Ghre_CourseClass { + + /// + /// 创建信息 + /// + public string CreateDataInfo { get; set; } + + /// + /// 修改信息 + /// + public string UpdateDataInfo { get; set; } } } diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index 83062ad1..23293855 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -4,6 +4,7 @@ using System.Dynamic; using System.Linq.Expressions; using AgileObjects.AgileMapper; using Microsoft.AspNetCore.Http; +using MySqlX.XDevAPI.Common; using Newtonsoft.Json.Linq; using NPOI.Util; using SqlSugar; @@ -58,50 +59,40 @@ public class BaseServices : IBaseServ public async Task QueryById(object objId) { - var data = await BaseDal.QueryById(objId); + var data = new TEntity(); var dto = Mapper.Map(data).ToANew(); - #region 系统信息 - var getType = typeof(TEntityDto).GetProperties(); - if (getType.Any(p => p.Name == "CreateDataInfo") && getType.Any(p => p.Name == "UpdateDataInfo")) - { - - var userIds = new List(); - var CreateDataInfo = getType.Where(p => p.Name == "CreateDataInfo").FirstOrDefault(); - var UpdateDataInfo = getType.Where(p => p.Name == "UpdateDataInfo").FirstOrDefault(); - var CreateBy = getType.Where(p => p.Name == "CreateBy").FirstOrDefault(); - var UpdateBy = getType.Where(p => p.Name == "UpdateBy").FirstOrDefault(); - var CreateTime = getType.Where(p => p.Name == "CreateTime").FirstOrDefault(); - var UpdateTime = getType.Where(p => p.Name == "UpdateTime").FirstOrDefault(); - var createBy = CreateBy.GetValue(dto, null); - var updateBy = UpdateBy.GetValue(dto, null); - DateTime? createTime = CreateTime.GetValue(dto, null) != null ? Convert.ToDateTime(CreateTime.GetValue(dto, null)) : null; - DateTime? updateTime = UpdateTime.GetValue(dto, null) != null ? Convert.ToDateTime(UpdateTime.GetValue(dto, null)) : null; - if (createBy != null) - { - var dt = await Db.Ado.GetDataTableAsync($"SELECT UserId, UserName FROM Ghrs_User WHERE UserId='{createBy}'"); - if (dt.Rows.Count > 0) - CreateDataInfo.SetValue(dto, $"创建信息 {dt.Rows[0]["UserName"]} 于 {(createTime != null ? createTime.Value.ToString(@"yyyy\/MM\/dd HH:mm") : null)} 创建"); - - } - if (updateBy != null) - { - var dt = await Db.Ado.GetDataTableAsync($"SELECT UserId, UserName FROM Ghrs_User WHERE UserId='{updateBy}'"); - UpdateDataInfo.SetValue(dto, $"修改信息 {dt.Rows[0]["UserName"]} 于 {(updateTime != null ? updateTime.Value.ToString(@"yyyy\/MM\/dd HH:mm") : null)} 最后修改"); - } - } - //if (exampaper.CreateBy != null) - // userIds.Add(Convert.ToInt32(exampaper.CreateBy.Value)); - //if (exampaper.UpdateBy != null) - // userIds.Add(Convert.ToInt32(exampaper.UpdateBy.Value)); - //var users = await _ghrs_UserServices.Query(x => userIds.Contains(x.UserId)); - //if (exampaper.CreateBy != null) - // input.CreateDataInfo = - //if (exampaper.UpdateBy != null) - // input.CreateDataInfo = ; - #endregion - - + Type entityType = typeof(TEntity); + string sql = @$"DECLARE @langId INT = 1,@ID BIGINT = '{objId}'; + SELECT *, + isnull + ((SELECT CASE WHEN @langId = 1 THEN UserName ELSE UserEname END + FROM Ghrs_User kk + WHERE kk.UserId = a.CreateBy), + '') + + ' ' + + [dbo].[FLangKeyToValue] ('GHR_Common_000078', @langId, '于 ') + + ' ' + + CONVERT (NVARCHAR (16), CreateTime, 121) + + ' ' + + [dbo].[FLangKeyToValue] ('GHR_Common_000079', @langId, ' 创建') + CreateDataInfo, + isnull + ((SELECT CASE WHEN @langId = 1 THEN UserName ELSE UserEname END + FROM Ghrs_User kk + WHERE kk.UserId = a.UpdateBy), + '') + + ' ' + + [dbo].[FLangKeyToValue] ('GHR_Common_000078', @langId, '于') + + ' ' + + CONVERT (NVARCHAR (16), UpdateTime, 121) + + ' ' + + [dbo].[FLangKeyToValue] + ('GHR_Common_000080', @langId, ' 最后修改') + UpdateDataInfo + FROM {entityType.GetEntityTableName()} a + WHERE a.Id = @ID"; + dto = await Db.Ado.SqlQuerySingleAsync(sql); return dto; } diff --git a/Tiobon.Core/Tiobon.Core.Model.xml b/Tiobon.Core/Tiobon.Core.Model.xml index 9046079d..04ec5aef 100644 --- a/Tiobon.Core/Tiobon.Core.Model.xml +++ b/Tiobon.Core/Tiobon.Core.Model.xml @@ -4041,6 +4041,16 @@ 课程分类(Dto.View) + + + 创建信息 + + + + + 修改信息 + + 课程场景(Dto.View) diff --git a/Tiobon.Core/Tiobon.Core.xml b/Tiobon.Core/Tiobon.Core.xml index 65010133..809b7994 100644 --- a/Tiobon.Core/Tiobon.Core.xml +++ b/Tiobon.Core/Tiobon.Core.xml @@ -539,107 +539,7 @@ - 课程分类(Controller) - - - - - 根据条件查询数据 - - 条件 - - - - - 根据Id查询数据 - - 主键ID - - - - - 新增数据 - - - - - - - 批量新增数据 - - - - - - 更新数据 - - 主键ID - - - - - - 批量更新数据 - - - - - - 删除数据 - - 主键ID - - - - - 批量删除数据 - - 主键IDs - - - - - 服务层分页响应实体(泛型) - - - - - 状态码 - - - - - 操作是否成功 - - - - - 返回信息 - - - - - 当前页标 - - - - - 总页数 - - - - - 数据总数 - - - - - 每页大小 - - - - - 返回数据 + Ghre_CourseClass(Controller)