Commit 5ce797a9 by jianshuqin

优化:组件功能

parent c23b2b82
......@@ -74,7 +74,6 @@ namespace Bailun.DC.Models.Component.DTO
/// <summary>
/// 列值
/// </summary>
[JsonIgnore]
public string ColumnValue { get; set; }
/// <summary>
......@@ -100,19 +99,16 @@ namespace Bailun.DC.Models.Component.DTO
/// <summary>
/// 数据值
/// </summary>
[JsonIgnore]
public string DataValue { get; set; }
/// <summary>
/// 数据库:1: 数据中心, 2: 交易流水
/// </summary>
[JsonIgnore]
public DBEnum? DataDB { get; set; }
/// <summary>
/// 数据默认排序SQL
/// </summary>
[JsonIgnore]
public string DataSortSql { get; set; }
/// <summary>
......
......@@ -21,24 +21,27 @@ namespace Bailun.DC.Services.Component
/// 获取查询组件
/// </summary>
/// <param name="code">编码</param>
/// <param name="id">ID</param>
/// <returns></returns>
public TableDTO Get(string code)
public TableDTO Get(string code = null, string id = null)
{
TableDTO dto = default(TableDTO);
if (!string.IsNullOrWhiteSpace(code))
if (!string.IsNullOrWhiteSpace(code) || !string.IsNullOrWhiteSpace(id))
{
dc_component_table entity = default(dc_component_table);
using (var db = DB)
{
DynamicParameters sqlparam = new DynamicParameters();
sqlparam.Add("id", id);
sqlparam.Add("code", code);
entity = db.QueryFirstOrDefault<dc_component_table>("select * from dc_component_table where is_delete = 0 and code = @code", sqlparam);
entity = db.QueryFirstOrDefault<dc_component_table>("select * from dc_component_table where is_delete = 0 and (id = @id or code = @code)", sqlparam);
}
if (entity != null)
{
dto = new TableDTO
{
Id = entity.id,
Code = entity.code,
Name = entity.name,
MenuCode = entity.menu_code,
......@@ -69,6 +72,7 @@ namespace Bailun.DC.Services.Component
//列
if (dto.ColumnType == ColumnTypeEnum.Config && !string.IsNullOrWhiteSpace(entity.column_value))
{
dto.ColumnValue = null;
dto.ListColumn = DeserializeCollection<dynamic>(entity.column_value);
}
if (dto.ListOperateControl?.Count() > 0)
......@@ -481,7 +485,7 @@ namespace Bailun.DC.Services.Component
if (listColumn != null)
{
//数据类型
DataTypeEnum?[] dataTypes = { DataTypeEnum.Table, DataTypeEnum.Sql };
DataTypeEnum?[] dataTypes = { DataTypeEnum.Table, DataTypeEnum.Sql };
//全部数据导出
queryFilter.CurrentPage = null;
queryFilter.pageSize = null;
......@@ -537,7 +541,7 @@ namespace Bailun.DC.Services.Component
is_show_sequence_column = dto.IsShowSequenceColumn,
is_show_column_search = dto.IsShowColumnSearch,
column_type = dto.ColumnType,
column_value = dto.ColumnValue,
column_value = dto.ColumnType == ColumnTypeEnum.Config && dto.ListColumn?.Count() > 0 ? JsonConvert.SerializeObject(dto.ListColumn) : dto.ColumnValue,
data_type = dto.DataType,
data_value = dto.DataValue,
data_db = dto.DataDB,
......@@ -733,16 +737,16 @@ namespace Bailun.DC.Services.Component
}
else
{
IList<dynamic> listColumn = default(IList<dynamic>);
IEnumerable<dynamic> listColumn = default(IList<dynamic>);
if (entity.ColumnType == ColumnTypeEnum.Config)
{
listColumn = DeserializeCollection<dynamic>(entity.ColumnValue).ToList();
listColumn = entity.ListColumn;
}
else
{
listColumn = this.GetListColumn(queryFilter);
listColumn = this.GetListColumn(queryFilter, entity);
}
if (listColumn?.Count > 0 && listColumn.Any(l => !string.IsNullOrWhiteSpace(l.Code) && l.OrderSort > 0))
if (listColumn?.Count() > 0 && listColumn.Any(l => !string.IsNullOrWhiteSpace(l.Code) && l.OrderSort > 0))
{
sql = string.Join(",", listColumn.Where(l => !string.IsNullOrWhiteSpace(l.Code) && l.OrderSort > 0).OrderBy(l => l.OrderSort).Select(l => $"`{l.Code}` {(l.Descending == true ? "desc" : "asc")}"));
}
......
using Bailun.DC.Models.Component.DTO;
using Bailun.DC.Services.Component;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Linq;
using System.Collections.Generic;
namespace Bailun.DC.Web.Areas.Component.Controllers
{
......@@ -15,12 +19,12 @@ namespace Bailun.DC.Web.Areas.Component.Controllers
[HttpGet]
public JsonResult Get(string code = null)
public JsonResult Get(string id = null, string code = null)
{
ResultDTO result = new ResultDTO();
try
{
result.Data = new TableService().Get(code);
result.Data = new TableService().Get(code, id);
result.Result = true;
}
catch (Exception ex)
......@@ -28,7 +32,7 @@ namespace Bailun.DC.Web.Areas.Component.Controllers
result.Message = ex.Message;
}
return Json(result);
return Json(result, new JsonSerializerSettings() { ContractResolver = new IgnoreJsonAttributesResolver(id), DefaultValueHandling = DefaultValueHandling.Include });
}
[HttpPost]
......@@ -143,5 +147,30 @@ namespace Bailun.DC.Web.Areas.Component.Controllers
return Json(result);
}
private class IgnoreJsonAttributesResolver : DefaultContractResolver
{
private string Id { get; set; }
public IgnoreJsonAttributesResolver(string id)
{
this.Id = id;
}
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
this.NamingStrategy = new CamelCaseNamingStrategy();
IList<JsonProperty> props = base.CreateProperties(type, memberSerialization);
foreach (var prop in props)
{
string[] ignorePropertys = { "ColumnValue", "DataValue", "DataDB", "DataSortSql" };
if (string.IsNullOrWhiteSpace(this.Id) && ignorePropertys.Contains(prop.UnderlyingName))
{
prop.Ignored = true;
}
}
return props;
}
}
}
}
......@@ -77,3 +77,7 @@
.el-form-control .mt59 {
margin-left: 59px;
}
.el-form-control .el-textarea.el-input--small span {
height: 25px;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment