From 87599e432a6432b342a6995d9b6ce8106e434e38 Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Fri, 7 Jun 2024 18:08:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Ghre/Ghre_CourseController.cs | 20 +- .../Ghre/IGhre_CourseServices.cs | 2 + .../Edit/Ghre/Ghre_Course.Dto.EditInput.cs | 4 +- .../Ghre/Ghre_Course.Dto.InsertInput.cs | 1 + .../View/Ghre/Ghre_Course.Dto.View.cs | 3 + Tiobon.Core.Services/CommonServices.cs | 2 - .../Ghre/Ghre_CourseServices.cs | 249 +++++++++++++++++- 7 files changed, 272 insertions(+), 9 deletions(-) diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseController.cs index 88875858..9457c572 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseController.cs @@ -22,16 +22,28 @@ public class Ghre_CourseController : BaseController> QueryList(string status, [FromBody] QueryBody body) { - var data = await _service.QueryList(body, status); - return data; + return await _service.QueryList(body, status); } [HttpPost, Route("QueryDeptID/{StaffID}")] public async Task> QueryDeptID(int StaffID) { - var data = await _service.QueryDeptID(StaffID); - return data; + return await _service.QueryDeptID(StaffID); + } + + [HttpPost, Route("GetSelect")] + public async Task> QueryTeacher(long? linkId) + { + return await _service.QueryTeacher(linkId); } #endregion + + #region 更新 + [HttpPost("UpdateStatus/{status}")] + public async Task UpdateStatus(string status, [FromBody] long[] ids) + { + return await _service.UpdateStatus(ids, status); + } + #endregion } \ No newline at end of file diff --git a/Tiobon.Core.IServices/Ghre/IGhre_CourseServices.cs b/Tiobon.Core.IServices/Ghre/IGhre_CourseServices.cs index 2b9edeed..cc782fad 100644 --- a/Tiobon.Core.IServices/Ghre/IGhre_CourseServices.cs +++ b/Tiobon.Core.IServices/Ghre/IGhre_CourseServices.cs @@ -14,5 +14,7 @@ namespace Tiobon.Core.IServices Task> QueryList(QueryBody filter, string status); Task> QueryDeptID(int StaffID); + Task> QueryTeacher(long? linkId); + Task UpdateStatus(long[] ids, string status); } } \ No newline at end of file diff --git a/Tiobon.Core.Model/Edit/Ghre/Ghre_Course.Dto.EditInput.cs b/Tiobon.Core.Model/Edit/Ghre/Ghre_Course.Dto.EditInput.cs index 53ad37e3..867ad0df 100644 --- a/Tiobon.Core.Model/Edit/Ghre/Ghre_Course.Dto.EditInput.cs +++ b/Tiobon.Core.Model/Edit/Ghre/Ghre_Course.Dto.EditInput.cs @@ -13,7 +13,7 @@ *│ 此技术信息为本公司机密信息,未经本公司书面同意禁止向第三方披露. │ *│ 作者:SimonHsiao │ *└──────────────────────────────────┘ -*/ +*/ namespace Tiobon.Core.Model.Models { @@ -23,5 +23,7 @@ namespace Tiobon.Core.Model.Models /// public class EditGhre_CourseInput : Ghre_CourseBase { + + public List ExamPaperIds { get; set; } } } diff --git a/Tiobon.Core.Model/Insert/Ghre/Ghre_Course.Dto.InsertInput.cs b/Tiobon.Core.Model/Insert/Ghre/Ghre_Course.Dto.InsertInput.cs index bef85376..54162df7 100644 --- a/Tiobon.Core.Model/Insert/Ghre/Ghre_Course.Dto.InsertInput.cs +++ b/Tiobon.Core.Model/Insert/Ghre/Ghre_Course.Dto.InsertInput.cs @@ -23,5 +23,6 @@ namespace Tiobon.Core.Model.Models /// public class InsertGhre_CourseInput : Ghre_CourseBase { + public List ExamPaperIds { get; set;} } } diff --git a/Tiobon.Core.Model/View/Ghre/Ghre_Course.Dto.View.cs b/Tiobon.Core.Model/View/Ghre/Ghre_Course.Dto.View.cs index 9f4bb2fb..81d3c567 100644 --- a/Tiobon.Core.Model/View/Ghre/Ghre_Course.Dto.View.cs +++ b/Tiobon.Core.Model/View/Ghre/Ghre_Course.Dto.View.cs @@ -47,4 +47,7 @@ public class Ghre_CourseDto : Ghre_Course /// 修改信息 /// public string UpdateDataInfo { get; set; } + + public List ExamPaperIds { get; set; } = new List(); + } diff --git a/Tiobon.Core.Services/CommonServices.cs b/Tiobon.Core.Services/CommonServices.cs index 81c6a4ee..60c2a9b1 100644 --- a/Tiobon.Core.Services/CommonServices.cs +++ b/Tiobon.Core.Services/CommonServices.cs @@ -845,8 +845,6 @@ public partial class CommonServices : BaseServices>, ICommon #endregion - - #region 特殊处理 var toolbar = new Toolbar(); var index = -1; diff --git a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs index a2c1f21b..3059f973 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs @@ -11,6 +11,12 @@ using SqlSugar; using Newtonsoft.Json; using MySqlX.XDevAPI.Common; using System.Data; +using System.Dynamic; +using Tiobon.Core.Common.DB.Dapper.Extensions; +using AgileObjects.AgileMapper; +using Microsoft.AspNetCore.Http; +using Tiobon.Core.Common.UserManager; +using Tiobon.Core.Common.Helper; namespace Tiobon.Core.Services; @@ -223,7 +229,7 @@ public class Ghre_CourseServices : BaseServices.OprateSuccess("查询成功!", id); } - public async Task> QueryTeacher(long schoolId) + public async Task> QueryTeacher(long? linkId) { var result = new CommonSelect(); JArray TableColumn = new JArray(); @@ -246,7 +252,10 @@ public class Ghre_CourseServices : BaseServices() { Success = true, Message = "查询成功", Data = result, }; } + + public override async Task QueryForm(QueryForm body) + { + var result = new ServiceFormResult(); + string sql = string.Empty; + var dt = new DataTable(); + + if (body.id != null) + { + Type entityType = typeof(Ghre_Course); + sql = @$"DECLARE @langId INT = '{body.langId}',@ID BIGINT = '{body.id}'; + + 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"; + + var list = await Db.Ado.SqlQueryAsync(sql); + + list.ForEach(x => + { + x.ExamPaperIds = JsonHelper.JsonToObj>(x.ExamPaperId); + }); + result.result.DT_TableDataT1 = list; + + } + else + { + var list = new List + { + new() + }; + + result.result.DT_TableDataT1 = Mapper.Map(list).ToANew>(); + } + #region JM_PageFormActionsT1 + dynamic JM_PageFormActionsT1 = new ExpandoObject(); + + var toolbars = await _caching.GetAsync>(body.menuName + "FormToolbar"); + if (toolbars == null || (toolbars != null && !toolbars.Any())) + { + sql = @$"SELECT field fnKey, [dbo].[FLangKeyToValue] (mkey, {body.langId}, label) fnTitle, icon + FROM Ghrs_PageSettingEdit + WHERE IsEnable = 1 AND pageNo = '{body.menuName}' AND elementType = 'FnKey'"; + toolbars = await Db.Ado.SqlQueryAsync(sql); + if (toolbars.Any()) + await _caching.SetAsync(body.menuName + "FormToolbar", toolbars); + } + + + JM_PageFormActionsT1.Toolbar = toolbars; + #endregion + + #region JM_TableColumnT1 + dynamic JM_TableColumnT1 = new ExpandoObject(); + var tableColumn = new JArray(); + sql = @$"SELECT field, + [dbo].[FLangKeyToValue] (mkey, {body.langId}, label) + label, + required, + editable, + rowNum, + colNum, + elementType, + dbo.FS_GetdataSourceBySet + (dataSource, APIDataSourceType, Ghrs_PageSettingEdit.APIDataSourceID) + dataSource, + defaultHidden, + isPrimaryKey, + isSingleColumn,multipleSelect + FROM Ghrs_PageSettingEdit + WHERE IsEnable = 1 + AND pageNo = '{body.menuName}' + AND elementType NOT IN ('FnKey', 'PageGroup');"; + dt = await Db.Ado.GetDataTableAsync(sql); + + for (int i = 0; i < dt.Rows.Count; i++) + { + string dataSource = dt.Rows[i]["dataSource"].ToString(); + string field = dt.Rows[i]["field"].ToString(); + if (field == "SchoolTeacherId") + dataSource = "api/Ghre_Course/GetSelect?FW=DOTNETCORE&linkId="; + JObject item = + [ + new JProperty("field",field), + new JProperty("label", dt.Rows[i]["label"].ToString()), + new JProperty("required",!string.IsNullOrWhiteSpace(dt.Rows[i]["required"].ToString())? Convert.ToBoolean(dt.Rows[i]["required"]):null), + new JProperty("editable",!string.IsNullOrWhiteSpace(dt.Rows[i]["editable"].ToString())? Convert.ToBoolean(dt.Rows[i]["editable"]):null), + new JProperty("rowNum",!string.IsNullOrWhiteSpace(dt.Rows[i]["rowNum"].ToString())? Convert.ToInt32(dt.Rows[i]["rowNum"]):null), + new JProperty("colNum",!string.IsNullOrWhiteSpace(dt.Rows[i]["colNum"].ToString())? Convert.ToInt32(dt.Rows[i]["colNum"]):null), + new JProperty("elementType", dt.Rows[i]["elementType"].ToString()), + new JProperty("dataSource", dataSource), + new JProperty("defaultHidden", dt.Rows[i]["defaultHidden"].ToString()), + new JProperty("isPrimaryKey", !string.IsNullOrWhiteSpace(dt.Rows[i]["isPrimaryKey"].ToString())? Convert.ToBoolean(dt.Rows[i]["isPrimaryKey"]):null), + new JProperty("isSingleColumn",!string.IsNullOrWhiteSpace(dt.Rows[i]["isSingleColumn"].ToString())? Convert.ToInt32(dt.Rows[i]["isSingleColumn"]):null), + new JProperty("multipleSelect",!string.IsNullOrWhiteSpace(dt.Rows[i]["multipleSelect"].ToString())? Convert.ToBoolean(dt.Rows[i]["multipleSelect"]):null), + ]; + tableColumn.Add(item); + } + JM_TableColumnT1.TableColumn = tableColumn; + #endregion + + #region JM_PageFormT1 + dynamic JM_PageFormT1 = new ExpandoObject(); + var pageForm = new JArray(); + JObject pageFormItem = + [ + new JProperty("disabled", false), + new JProperty("labelAlign", "right"), + new JProperty("labelCol", "{span: 6}"), + new JProperty("labelWidth",120), + new JProperty("layout", "horizontal") + ]; + + sql = $@"SELECT [dbo].[FLangKeyToValue] (MKey, {body.langId}, MenuName) pageTitle, + IUDProcedure apiName + FROM Ghrs_Menu + WHERE MenuNo = '{body.menuName}' AND IsEnable = 1"; + dt = await Db.Ado.GetDataTableAsync(sql); + if (dt.Rows.Count > 0) + { + pageFormItem.Add(new JProperty("pageTitle", dt.Rows[0]["pageTitle"].ToString())); + pageFormItem.Add(new JProperty("apiName", dt.Rows[0]["apiName"].ToString())); + } + pageForm.Add(pageFormItem); + JM_PageFormT1.PageForm = pageForm; + #endregion + + #region DT_PageMutiMsg + var DT_PageMutiMsg = await _caching.GetAsync>("DT_PageMutiMsg"); + if (DT_PageMutiMsg == null || (DT_PageMutiMsg != null && !DT_PageMutiMsg.Any())) + { + sql = $@"SELECT Langkey field, + CASE {body.langId} + WHEN 1 THEN isnull (Value01, LangValue) + WHEN 2 THEN isnull (Value02, LangValue) + WHEN 3 THEN isnull (Value03, LangValue) + WHEN 4 THEN isnull (Value04, LangValue) + WHEN 5 THEN isnull (Value05, LangValue) + WHEN 6 THEN isnull (Value06, LangValue) + WHEN 7 THEN isnull (Value07, LangValue) + WHEN 8 THEN isnull (Value08, LangValue) + WHEN 9 THEN isnull (Value09, LangValue) + WHEN 10 THEN isnull (Value10, LangValue) + END label + FROM Ghrs_LangKey + WHERE (LangKey LIKE 'GHR_Page%' OR LangKey LIKE 'GHR_Common%') + AND IsEnable = 1"; + DT_PageMutiMsg = Db.Ado.SqlQuery(sql); + if (DT_PageMutiMsg.Any()) + await _caching.SetAsync("DT_PageMutiMsg", DT_PageMutiMsg); + } + #endregion + + result.result.JM_PageFormActionsT1 = JM_PageFormActionsT1; + result.result.JM_TableColumnT1 = JM_TableColumnT1; + result.result.JM_PageFormT1 = JM_PageFormT1; + result.result.DT_PageMutiMsg = DT_PageMutiMsg; + return result; + } + + + public async Task UpdateStatus(long[] ids, string status) + { + if (status != "Released" && status != "Disabled" && status != "Draft") + throw new Exception("无效的状态"); + + HttpRequest request = UserContext.Context.Request; + var api = request.Path.ObjToString().TrimEnd('/').ToLower(); + var ip = GetUserIp(UserContext.Context); + + var entities = new List(); + foreach (var id in ids) + { + if (id == null || !BaseDal.Any(id)) + continue; + + var entity = await BaseDal.QueryById(id); + + BasePoco ent = entity; + ent.UpdateIP = ip; + ent.UpdateProg = api; + if (status == "Released" || status == "Disabled" || status == "Draft") + { + entity.Status = status; + entities.Add(entity); + } + } + + var result = await BaseDal.Update(entities); + if (status == "Released") + return ServiceResult.OprateSuccess("发布成功!"); + else if (status == "Draft") + return ServiceResult.OprateSuccess("取消发布成功!"); + else + return ServiceResult.OprateSuccess("停用成功!"); + + } + + public override async Task Add(InsertGhre_CourseInput entity) + { + entity.ExamPaperId = JsonHelper.ObjToJson(entity.ExamPaperIds); + entity.Status = "Draft"; + return await base.Add(entity); + } + + public override async Task Update(long Id, EditGhre_CourseInput editModel) + { + + editModel.ExamPaperId = JsonHelper.ObjToJson(editModel.ExamPaperIds); + return await base.Update(Id, editModel); + } } \ No newline at end of file