diff --git a/OpenAuth.App/BaseApp/FormScheme/FormHelpers/FormHelper.cs b/OpenAuth.App/BaseApp/FormScheme/FormHelpers/FormHelper.cs index e0c6443..ace07d1 100644 --- a/OpenAuth.App/BaseApp/FormScheme/FormHelpers/FormHelper.cs +++ b/OpenAuth.App/BaseApp/FormScheme/FormHelpers/FormHelper.cs @@ -190,10 +190,10 @@ namespace OpenAuth.App.FormScheme.FormHelpers { //girdTableMap[component.ComponentProps.DataTable].children.AddRange(column.children); } - else - { - girdTableMap.Add(component.ComponentProps.DataTable, component); - } + //else + //{ + // girdTableMap.Add(component.ComponentProps.DataTable, component); + //} } } @@ -217,7 +217,8 @@ namespace OpenAuth.App.FormScheme.FormHelpers { if (tableMap.ContainsKey(childTable.Name)) { - var rComponent = tableMap[childTable.RelationName].Find(t => t.ComponentProps.FieldName == childTable.RelationField); + //var rComponent = tableMap[childTable.RelationName].Find(t => t.ComponentProps.FieldName == childTable.RelationField); + var rComponent = tableMap[childTable.Name].Find(t => t.ComponentProps.FieldName == childTable.RelationField); if (girdTableMap.ContainsKey(childTable.Name)) { list.Add(GetDeleteSqlNew(childTable, dataJson, rComponent)); @@ -250,7 +251,8 @@ namespace OpenAuth.App.FormScheme.FormHelpers } else { - list.Add(GetUpDateSqlNew(childTable, tableMap, dataJson, childTable.Field, dataJson[rComponent.Field].ToString())); + //list.Add(GetUpDateSqlNew(childTable, tableMap, dataJson, childTable.Field, dataJson[rComponent.Field].ToString())); + list.Add(GetUpDateSqlNew(childTable, tableMap, dataJson, childTable.RelationField, dataJson[rComponent.Field].ToString())); } } @@ -262,6 +264,7 @@ namespace OpenAuth.App.FormScheme.FormHelpers foreach (var childTable in childrenTables) { var rComponent = tableMap[childTable.RelationName].Find(t => t.ComponentProps.FieldName == childTable.RelationField); + //var rComponent = tableMap[childTable.Name].Find(t => t.ComponentProps.FieldName == childTable.RelationField); FormComponentNewModel newComponent = new FormComponentNewModel() { }; newComponent.Field = rComponent.Field; newComponent.ComponentProps = new ComponentPropsModel(); @@ -659,8 +662,7 @@ namespace OpenAuth.App.FormScheme.FormHelpers return res; } private static FormDbTable GetUpDateSqlNew(FormDbTableInfo table, Dictionary> tableMap, JObject dataJson, string pkey, string pkeyValue) - { - string[] noNull = { "_input_39", "_input_51b5805f379942debe4224511f3e5ebe" }; + { FormDbTable res = new FormDbTable(); res.DbParameter = new List(); res.TableName = table.Name; @@ -689,18 +691,22 @@ namespace OpenAuth.App.FormScheme.FormHelpers //if (dataJson[component.Field] != null && dataJson[component.Field].ToString() == "" && component.CsType == "string" && component.itemProps.required == true) //{ // throw new Exception("必填数据不能为空"); + ////} + //if (dataJson[component.Field] != null && noNull.Contains(component.Field) && dataJson[component.Field].ToString() == "") + //{ + // throw new Exception("请在数据加载完再进行操作"); //} - if (dataJson[component.Field] != null && noNull.Contains(component.Field) && dataJson[component.Field].ToString() == "") - { - throw new Exception("请在数据加载完再进行操作"); - } //如果传过来的值为"",需要判断下字符类型 if (dataJson[component.Field] != null && dataJson[component.Field].ToString() == "" && component.CsType == "string") { res.DbParameter.Add(GetMyDbParameter(component.ComponentProps.FieldName, dataJson[component.Field].ToString(), component.CsType)); } - //只更新上传的数据,表单其他的不更新 - //res.DbParameter.Add(new SugarParameter(component.ComponentProps.FieldName, null)); + else + { + //只更新上传的数据,表单其他的不更新 + //res.DbParameter.Add(new SugarParameter(component.ComponentProps.FieldName, null)); + } + } if (component.ComponentProps.FieldName == pkey) diff --git a/OpenAuth.App/BaseApp/FormScheme/FormSchemeApp.cs b/OpenAuth.App/BaseApp/FormScheme/FormSchemeApp.cs index 02cfc13..fa6f21b 100644 --- a/OpenAuth.App/BaseApp/FormScheme/FormSchemeApp.cs +++ b/OpenAuth.App/BaseApp/FormScheme/FormSchemeApp.cs @@ -36,6 +36,10 @@ using OpenAuth.App.FormModule; using Microsoft.Extensions.Logging; using OpenAuth.App.BaseApp.Base; using Castle.Core.Internal; +using OpenAuth.App.BaseApp.FormScheme.Request; +using OpenAuth.App.BaseApp.FormScheme.Response; +using System.Dynamic; +using System.Security.Cryptography.Xml; namespace OpenAuth.App.FormScheme { @@ -51,7 +55,7 @@ namespace OpenAuth.App.FormScheme ISqlSugarClient sqlSugarClient, ILogger logger, CommonDataManager dataManager, - ISimpleClient repository, + ISimpleClient repository, BaseDataAuthorizeApp dataAuthorizeApp) : base(unitWork, repository, null) { @@ -1788,5 +1792,116 @@ namespace OpenAuth.App.FormScheme } #endregion + + #region 获取历史数据 + //public (List Headers, List Data) GetFormDataHistory(FormDataHistoryReq req) + //{ + // // 获取字段说明 + // var tableDec = GetTableColumnsWithDescriptions(req.table); + // //获取表单信息 + // // 表单 + // Repository.Domain.FormScheme schemeEntity = GetScheme(req.schemeId).Result; + // FormSchemeNewModel formSchemeModel = schemeEntity.Scheme.ToObject(); + // var chilTable = formSchemeModel.Db.Find(t => t.Type == "chlid"); + // var reqkey = chilTable.Field; + // // 构建字段 SQL + // string fieldSql = string.Join(",", req.field); + + // // 构建 SQL 查询语句(参数化,防注入) + // var sql = $"SELECT {fieldSql} FROM {req.table} WHERE {reqkey} = @p0"; + + // DataTable dt; + // using (var db = UnitWork.CreateContext()) + // { + // dt = db.Db.Ado.GetDataTable(sql, new List{ + // new SugarParameter("@p0", req.pkeyValue) + // }); + // } + // // 字段中文表头 + // var headers = req.field.Select(f => + // { + // var desc = tableDec.FirstOrDefault(t => t.FieldName == f).Description; + // return string.IsNullOrEmpty(desc) ? f : desc; + // }).ToList(); + + // // 转换 DataTable 为 List + // var data = dt.AsEnumerable() + // .Select(row => + // { + // dynamic obj = new ExpandoObject(); + // var dict = (IDictionary)obj; + // foreach (DataColumn col in dt.Columns) + // { + // dict[col.ColumnName] = row[col]; + // } + // return obj; + // }).ToList(); + + // return (headers, data); + //} + public (List Headers, List Data) GetFormDataHistory( + FormDataHistoryReq req) + { + // ① 取到整张表的列名+中文描述 + var allColumns = GetTableColumnsWithDescriptions(req.table); // [(FieldName,Description)] + // 表单 + Repository.Domain.FormScheme schemeEntity = GetScheme(req.schemeId).Result; + FormSchemeNewModel formSchemeModel = schemeEntity.Scheme.ToObject(); + var chilTable = formSchemeModel.Db.Find(t => t.Type == "chlid"); + var reqkey = chilTable.Field; + + // ② 先执行查询,拿到数据 + string fieldSql = string.Join(",", req.field.Select(f => $"\"{f}\"")); + string sql = $"SELECT {fieldSql} FROM \"{req.table}\" WHERE \"{reqkey}\" = @p0"; + + DataTable dt; + using (var db = UnitWork.CreateContext()) + { + dt = db.Db.Ado.GetDataTable(sql, new List + { + new SugarParameter("@p0",req.pkeyValue) + }); + } + + // ③ 生成 item1:{title , dataIndex} + var item1 = req.field + .Select(f => + { + var desc = allColumns.FirstOrDefault(c => c.FieldName == f).Description ?? f; + // 返回匿名对象,也可以建 DTO + return new { title = desc, dataIndex = f }; + }) + .ToList(); + + // ④ 把 DataTable → List (item2) + var item2 = dt.AsEnumerable() + .Select(r => + { + dynamic obj = new ExpandoObject(); + var dict = (IDictionary)obj; + foreach (DataColumn col in dt.Columns) + { + dict[col.ColumnName] = r[col]; + } + return obj; + }) + .ToList(); + + return (item1, item2); + } + public List<(string FieldName, string Description)> GetTableColumnsWithDescriptions(string tableName) + { + var list = new List<(string FieldName, string Description)>(); + using (var db = UnitWork.CreateContext()) + { + var columns = db.Db.DbMaintenance.GetColumnInfosByTableName(tableName, false); + foreach (var col in columns) + { + list.Add((col.DbColumnName, col.ColumnDescription)); + } + return list; + } + } + #endregion } } \ No newline at end of file diff --git a/OpenAuth.App/BaseApp/FormScheme/Request/FormDataHistoryReq.cs b/OpenAuth.App/BaseApp/FormScheme/Request/FormDataHistoryReq.cs new file mode 100644 index 0000000..4d96b86 --- /dev/null +++ b/OpenAuth.App/BaseApp/FormScheme/Request/FormDataHistoryReq.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenAuth.App.BaseApp.FormScheme.Request +{ + public class FormDataHistoryReq + { + public string table { get; set; } + public List field { get; set; } + public string pkey { get; set; } + public string pkeyValue { get; set; } + public string schemeId { get; set; } + } +} diff --git a/OpenAuth.App/BaseApp/FormScheme/Response/ColumnHeader.cs b/OpenAuth.App/BaseApp/FormScheme/Response/ColumnHeader.cs new file mode 100644 index 0000000..c10e3d0 --- /dev/null +++ b/OpenAuth.App/BaseApp/FormScheme/Response/ColumnHeader.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenAuth.App.BaseApp.FormScheme.Response +{ + public class ColumnHeader + { + public string FieldName { get; set; } // 列名 + public string Description { get; set; } // 中文描述 + } +} diff --git a/OpenAuth.App/BaseApp/FormScheme/Response/FormDataHistoryRes.cs b/OpenAuth.App/BaseApp/FormScheme/Response/FormDataHistoryRes.cs new file mode 100644 index 0000000..35f7901 --- /dev/null +++ b/OpenAuth.App/BaseApp/FormScheme/Response/FormDataHistoryRes.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenAuth.App.BaseApp.FormScheme.Response +{ + public class FormDataHistoryRes + { + public List Headers { get; set; } // 表头(含中文) + public List Rows { get; set; } // 数据行 + } +} diff --git a/OpenAuth.App/OpenAuth.App.csproj b/OpenAuth.App/OpenAuth.App.csproj index e24eb84..19a5995 100644 --- a/OpenAuth.App/OpenAuth.App.csproj +++ b/OpenAuth.App/OpenAuth.App.csproj @@ -52,7 +52,6 @@ - diff --git a/OpenAuth.App/ServiceApp/DroneSsnydManage/DroneSsnyApp.cs b/OpenAuth.App/ServiceApp/DroneSsnydManage/DroneSsnyApp.cs index de13946..aa14970 100644 --- a/OpenAuth.App/ServiceApp/DroneSsnydManage/DroneSsnyApp.cs +++ b/OpenAuth.App/ServiceApp/DroneSsnydManage/DroneSsnyApp.cs @@ -1,12 +1,9 @@ -using OpenAuth.App.BaseApp.Base; -using OpenAuth.Repository.Domain; -using OpenAuth.Repository; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Infrastructure; +using OpenAuth.App.BaseApp.Base; using OpenAuth.App.Interface; +using OpenAuth.App.ServiceApp.DroneSsnydManage.Request; +using OpenAuth.Repository; +using OpenAuth.Repository.Domain; using SqlSugar; using Infrastructure; using DocumentFormat.OpenXml.Spreadsheet; @@ -16,13 +13,13 @@ namespace OpenAuth.App.ServiceApp.DroneSsnydManage { public class DroneSsnyApp : SqlSugarBaseApp { - public DroneSsnyApp(ISugarUnitOfWork unitWork, ISimpleClient repository, IAuth auth) : base(unitWork, repository, auth) + public DroneSsnyApp(ISugarUnitOfWork unitWork, ISimpleClient repository, IAuth auth) + : base(unitWork, repository, auth) { - } /// - /// 超期预警 + /// 到期预警 /// /// /// @@ -72,5 +69,48 @@ namespace OpenAuth.App.ServiceApp.DroneSsnydManage Total = totalCount }; } + + /// + /// 历史项目 + /// + /// + /// + /// + public PageInfo> HistoryProject(DroneSnnyAppPageReq req) + { + var totalCount = 0; + var list = Repository.AsQueryable() + .Where(a => a.handle_status_id == 99) + .WhereIF(!string.IsNullOrEmpty(req.xiangmu_no), a => a.xiangmu_no.Contains(req.xiangmu_no)) + .WhereIF(!string.IsNullOrEmpty(req.xiangmumc), a => a.xiangmumc.Contains(req.xiangmumc)) + .OrderBy(a => a.end_time, OrderByType.Desc) + .ToPageList(req.page, req.limit, ref totalCount); + return new PageInfo> + { + Items = list, + Total = totalCount + }; + } + + /// + /// 项目变更 + /// + /// + /// + public PageInfo> ProjectChange(DroneSnnyAppPageReq req) + { + var totalCount = 0; + var list = Repository.AsQueryable() + .Where(a => a.handle_status_id != 99) + .WhereIF(!string.IsNullOrEmpty(req.xiangmu_no), a => a.xiangmu_no.Contains(req.xiangmu_no)) + .WhereIF(!string.IsNullOrEmpty(req.xiangmumc), a => a.xiangmumc.Contains(req.xiangmumc)) + .OrderBy(a => a.end_time, OrderByType.Desc) + .ToPageList(req.page, req.limit, ref totalCount); + return new PageInfo> + { + Items = list, + Total = totalCount + }; + } } -} +} \ No newline at end of file diff --git a/OpenAuth.App/ServiceApp/DroneSsnydManage/Request/DroneSnnyAppPageReq.cs b/OpenAuth.App/ServiceApp/DroneSsnydManage/Request/DroneSnnyAppPageReq.cs new file mode 100644 index 0000000..85fd605 --- /dev/null +++ b/OpenAuth.App/ServiceApp/DroneSsnydManage/Request/DroneSnnyAppPageReq.cs @@ -0,0 +1,15 @@ +using OpenAuth.App.Request; + +namespace OpenAuth.App.ServiceApp.DroneSsnydManage.Request; + +public class DroneSnnyAppPageReq : PageReq +{ + /// + /// 项目名称 + /// + public string xiangmumc { get; set; } + /// + /// 项目编号 + /// + public string xiangmu_no { get; set; } +} diff --git a/OpenAuth.WebApi/Controllers/BaseControllers/FormSchemeController.cs b/OpenAuth.WebApi/Controllers/BaseControllers/FormSchemeController.cs index 7233012..a506aa9 100644 --- a/OpenAuth.WebApi/Controllers/BaseControllers/FormSchemeController.cs +++ b/OpenAuth.WebApi/Controllers/BaseControllers/FormSchemeController.cs @@ -5,6 +5,7 @@ using Infrastructure.Helpers.Excel.Model; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; +using OpenAuth.App.BaseApp.FormScheme.Request; using OpenAuth.App.FormScheme; using OpenAuth.App.FormScheme.Request; using OpenAuth.App.FormScheme.Response; @@ -449,7 +450,7 @@ namespace OpenAuth.WebApi.Controllers result.Result = data; return result; } - catch (Exception ex) + catch (Exception ex) { result.Result = false; result.Message = ex.Message.ToString(); @@ -509,5 +510,27 @@ namespace OpenAuth.WebApi.Controllers return File(ExcelHelper.ExportMemoryStream(dt, excelconfig), "application/ms-excel", excelconfig.FileName); } #endregion + + #region 获取历史数据 + /// + /// 获取子表历史数据 + /// + /// + /// + /// + [HttpPost] + public (List Headers, List Data) GetFormDataHistory(FormDataHistoryReq req) + { + try + { + return _app.GetFormDataHistory(req); + } + catch (Exception ex) + { + throw new Exception("获取数据失败"); + } + + } + #endregion } } diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/DroneSsnyController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/DroneSsnyController.cs index 1fa4ab0..404952a 100644 --- a/OpenAuth.WebApi/Controllers/ServiceControllers/DroneSsnyController.cs +++ b/OpenAuth.WebApi/Controllers/ServiceControllers/DroneSsnyController.cs @@ -1,8 +1,7 @@ using Infrastructure; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using OpenAuth.App; using OpenAuth.App.ServiceApp.DroneSsnydManage; +using OpenAuth.App.ServiceApp.DroneSsnydManage.Request; using OpenAuth.Repository.Domain; namespace OpenAuth.WebApi.Controllers.ServiceControllers @@ -15,13 +14,14 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers public class DroneSsnyController : ControllerBase { DroneSsnyApp droneSsnyApp; + public DroneSsnyController(DroneSsnyApp droneSsnyApp) { this.droneSsnyApp = droneSsnyApp; } /// - /// 超期预警 + /// 到期预警 /// /// 项目名称 /// 县 @@ -42,6 +42,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } + return response; } @@ -67,7 +68,52 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } + + return response; + } + + /// + /// 历史项目 + /// + /// + /// + [HttpGet] + public Response>> HistoryProject(DroneSnnyAppPageReq req) + { + var response = new Response>>(); + try + { + response.Result = droneSsnyApp.HistoryProject(req); + } + catch (Exception ex) + { + response.Code = 500; + response.Message = ex.InnerException?.Message ?? ex.Message; + } + + return response; + } + + /// + /// 项目变更列表 + /// + /// + /// + [HttpGet] + public Response>> ProjectChange(DroneSnnyAppPageReq req) + { + var response = new Response>>(); + try + { + response.Result = droneSsnyApp.ProjectChange(req); + } + catch (Exception ex) + { + response.Code = 500; + response.Message = ex.InnerException?.Message ?? ex.Message; + } + return response; } } -} +} \ No newline at end of file