Commit 3bb39234 by jianshuqin

优化:组件功能

parent a0c2bea4
......@@ -17,4 +17,8 @@
<Folder Include="OrderExport\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bailun.DC.DB\Bailun.DC.DB.csproj" />
</ItemGroup>
</Project>
......@@ -79,6 +79,16 @@ namespace Bailun.DC.Models.Component.DTO
public dynamic DefaultValue { get; set; }
/// <summary>
/// element按钮类型
/// </summary>
public string ButtonType { get; set; }
/// <summary>
/// element图标
/// </summary>
public string Icon { get; set; }
/// <summary>
/// 选项
/// </summary>
public IEnumerable<OptionDTO> ListOption { get; set; }
......
using System.Collections.Generic;
namespace Bailun.DC.Models.Component.DTO
{
public class FormDTO
{
/// <summary>
/// 编码
/// </summary>
public string Code { get; set; }
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 宽度
/// </summary>
public int? Width { get; set; }
/// <summary>
/// 标签宽度
/// </summary>
public int? LabelWidth { get; set; }
/// <summary>
/// 是否显示边框
/// </summary>
public bool? IsShowBorder { get; set; }
/// <summary>
/// 是否显示保存按钮 (默认:是)
/// </summary>
public bool? IsShowSaveButton { get; set; }
/// <summary>
/// 保存按钮文本 (默认:保存)
/// </summary>
public string SaveButtonText { get; set; }
/// <summary>
/// 是否显示取消按钮 (默认:是)
/// </summary>
public bool? IsShowCancelButton { get; set; }
/// <summary>
/// 取消按钮文本 (默认:保存)
/// </summary>
public string CancelButtonText { get; set; }
/// <summary>
/// flex布局下的水平排列方式:(默认center)
/// </summary>
public string Justify { get; set; }
/// <summary>
/// 提交时验证表单:(默认验证)
/// </summary>
public bool? IsValidate { get; set; }
/// <summary>
/// 保存脚本
/// </summary>
public string SaveScript { get; set; }
/// <summary>
/// 自定义脚本
/// </summary>
public string javascript { get; set; }
/// <summary>
/// 操作列值
/// </summary>
public IEnumerable<dynamic> ListFormItem { get; set; }
/// <summary>
/// 操作列值
/// </summary>
public IEnumerable<dynamic> ListControl { get; set; }
/// <summary>
/// Scripts引用
/// </summary>
public IEnumerable<string> ListJavascriptSrc { get; set; }
}
}
......@@ -4,14 +4,24 @@ using System.Collections.Generic;
namespace Bailun.DC.Models.Component.DTO
{
public class QueryDTO
public class TableDTO
{
/// <summary>
/// 通用查询代码
/// ID
/// </summary>
public int Id { get; set; }
/// <summary>
/// 编码
/// </summary>
public string Code { get; set; }
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 菜单代码
/// </summary>
public string MenuCode { get; set; }
......@@ -22,29 +32,34 @@ namespace Bailun.DC.Models.Component.DTO
public string Javascript { get; set; }
/// <summary>
/// 是否显示查询按钮: 1:显示; 0:不显示
/// 是否显示查询按钮:(默认是)
/// </summary>
public bool IsShowSearchButton { get; set; }
public bool? IsShowSearchButton { get; set; }
/// <summary>
/// 是否显示重置按钮: 1:显示; 0:不显示
/// 是否显示重置按钮:(默认是)
/// </summary>
public bool IsShowResetButton { get; set; }
public bool? IsShowResetButton { get; set; }
/// <summary>
/// 是否显示导出按钮: 1:显示; 0:不显示
/// 是否显示导出按钮:(默认否)
/// </summary>
public bool IsShowExportButton { get; set; }
public bool? IsShowExportButton { get; set; }
/// <summary>
/// 是否显示导入按钮: 1:显示; 0:不显示
/// 是否显示导入按钮:(默认否)
/// </summary>
public bool IsShowImportButton { get; set; }
public bool? IsShowImportButton { get; set; }
/// <summary>
/// 是否显示顺序列: 1:显示; 0:不显示
/// 是否显示顺序列:(默认否)
/// </summary>
public bool IsShowSequenceColumn { get; set; }
public bool? IsShowSequenceColumn { get; set; }
/// <summary>
/// 操作控件位置:NULL/1:换行,2:同行
/// </summary>
public int? OperateControlsPosition { get; set; }
/// <summary>
/// 选择行方式:1: 单选, 2: 多选
......@@ -63,6 +78,11 @@ namespace Bailun.DC.Models.Component.DTO
public string ColumnValue { get; set; }
/// <summary>
/// 是否显示列查询:(默认否)
/// </summary>
public bool? IsShowColumnSearch { get; set; }
/// <summary>
/// 操作列名
/// </summary>
public string OperateColumnName { get; set; }
......@@ -96,9 +116,9 @@ namespace Bailun.DC.Models.Component.DTO
public string DataSortSql { get; set; }
/// <summary>
/// 是否自动查询: 1:是; 0:否
/// 是否自动查询:(默认是)
/// </summary>
public bool IsAutoSearch { get; set; }
public bool? IsAutoSearch { get; set; }
/// <summary>
/// 面包屑
......
using System;
namespace Bailun.DC.Models.Component.Entity
{
/// <summary>
/// 表单组件
/// </summary>
public class dc_component_form
{
/// <summary>
/// ID
/// </summary>
public int id { get; set; }
/// <summary>
/// 编码
/// </summary>
public string code { get; set; }
/// <summary>
/// 名称
/// </summary>
public string name { get; set; }
/// <summary>
/// 宽度
/// </summary>
public int? width { get; set; }
/// <summary>
/// 标签宽度
/// </summary>
public int? label_width { get; set; }
/// <summary>
/// 是否显示边框
/// </summary>
public bool? is_show_border { get; set; }
/// <summary>
/// 是否显示保存按钮 (默认:是)
/// </summary>
public bool? is_show_save_button { get; set; }
/// <summary>
/// 保存按钮文本 (默认:保存)
/// </summary>
public string save_button_text { get; set; }
/// <summary>
/// 是否显示取消按钮 (默认:是)
/// </summary>
public bool? is_show_cancel_button { get; set; }
/// <summary>
/// 取消按钮文本 (默认:保存)
/// </summary>
public string cancel_button_text { get; set; }
/// <summary>
/// flex布局下的水平排列方式:(默认center)
/// </summary>
public string justify { get; set; }
/// <summary>
/// 表单项
/// </summary>
public string form_item { get; set; }
/// <summary>
/// 提交时验证表单:(默认验证)
/// </summary>
public bool? is_validate { get; set; }
/// <summary>
/// 保存脚本
/// </summary>
public string save_script { get; set; }
/// <summary>
/// 自定义脚本
/// </summary>
public string javascript { get; set; }
/// <summary>
/// 引用脚本
/// </summary>
public string javascript_src { get; set; }
/// <summary>
/// 自定义控件
/// </summary>
public string controls { get; set; }
/// <summary>
/// 是否可以拉伸:(默认不可以)
/// </summary>
public bool? is_drag { get; set; }
/// <summary>
/// 是否删除: 1:是; 0:否
/// </summary>
public bool is_delete { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime gmt_create { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime gmt_modified { get; set; }
}
}
using Bailun.DC.Models.Component.Enum;
using Dapper;
using System;
namespace Bailun.DC.Models.Component.Entity
{
/// <summary>
/// 查询组件
/// 报表组件
/// </summary>
public class dc_component_query
public class dc_component_table
{
/// <summary>
/// ID
......@@ -14,14 +15,14 @@ namespace Bailun.DC.Models.Component.Entity
public int id { get; set; }
/// <summary>
/// 名称
/// 编码
/// </summary>
public string name { get; set; }
public string code { get; set; }
/// <summary>
/// 通用查询代码
/// 名称
/// </summary>
public string code { get; set; }
public string name { get; set; }
/// <summary>
/// 菜单代码
......@@ -49,24 +50,24 @@ namespace Bailun.DC.Models.Component.Entity
public string filter_controls { get; set; }
/// <summary>
/// 是否显示查询按钮: 1:显示; 0:不显示
/// 是否显示查询按钮:(默认是)
/// </summary>
public bool is_show_search_button { get; set; }
public bool? is_show_search_button { get; set; }
/// <summary>
/// 是否显示重置按钮: 1:显示; 0:不显示
/// 是否显示重置按钮:(默认是)
/// </summary>
public bool is_show_reset_button { get; set; }
public bool? is_show_reset_button { get; set; }
/// <summary>
/// 是否显示导出按钮: 1:显示; 0:不显示
/// 是否显示导出按钮:(默认否)
/// </summary>
public bool is_show_export_button { get; set; }
public bool? is_show_export_button { get; set; }
/// <summary>
/// 是否显示导入按钮: 1:显示; 0:不显示
/// 是否显示导入按钮:(默认否)
/// </summary>
public bool is_show_import_button { get; set; }
public bool? is_show_import_button { get; set; }
/// <summary>
/// 操作控件
......@@ -74,9 +75,14 @@ namespace Bailun.DC.Models.Component.Entity
public string operate_controls { get; set; }
/// <summary>
/// 是否显示顺序列: 1:显示; 0:不显示
/// 操作控件位置:NULL/1:换行,2:同行
/// </summary>
public bool is_show_sequence_column { get; set; }
public int? operate_controls_position { get; set; }
/// <summary>
/// 是否显示顺序列:(默认否)
/// </summary>
public bool? is_show_sequence_column { get; set; }
/// <summary>
/// 选择行方式:1: 单选, 2: 多选
......@@ -94,6 +100,11 @@ namespace Bailun.DC.Models.Component.Entity
public string column_value { get; set; }
/// <summary>
/// 是否显示列查询:(默认否)
/// </summary>
public bool? is_show_column_search { get; set; }
/// <summary>
/// 操作列名
/// </summary>
public string operate_column_name { get; set; }
......@@ -129,18 +140,19 @@ namespace Bailun.DC.Models.Component.Entity
public DBEnum? data_db { get; set; }
/// <summary>
/// 是否自动查询: 1:是; 0:否
/// 是否自动查询:(默认是)
/// </summary>
public bool is_auto_search { get; set; }
public bool? is_auto_search { get; set; }
/// <summary>
/// 是否删除: 1:是; 0:否
/// 是否删除
/// </summary>
public bool is_delete { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[IgnoreUpdate]
public DateTime gmt_create { get; set; }
/// <summary>
......
......@@ -3,7 +3,7 @@
namespace Bailun.DC.Models.Component.Enum
{
/// <summary>
/// 列名类型:1:API,2:SQL,3:本地配置
/// 列名类型:1:SQL(首次),2:SQL,3:配置,3:API
/// </summary>
public enum ColumnTypeEnum
{
......
using Bailun.DC.Models.Component.DTO;
using Bailun.DC.Models.Component.Entity;
using Dapper;
namespace Bailun.DC.Services.Component
{
/// <summary>
/// 表单组件
/// </summary>
public class FormService : BaseService
{
/// <summary>
/// 获取表单组件
/// </summary>
/// <param name="code">编码</param>
/// <returns></returns>
public FormDTO Get(string code)
{
FormDTO dto = default(FormDTO);
if (!string.IsNullOrWhiteSpace(code))
{
dc_component_form entity = default(dc_component_form);
using (var db = DB)
{
DynamicParameters sqlparam = new DynamicParameters();
sqlparam.Add("code", code);
entity = db.QueryFirstOrDefault<dc_component_form>("select * from dc_component_form where is_delete = 0 and code = @code", sqlparam);
}
if (entity != null)
{
dto = new FormDTO
{
Code = entity.code,
Name = entity.name,
Width = entity.width,
LabelWidth = entity.label_width,
IsShowBorder = entity.is_show_border,
IsShowSaveButton = entity.is_show_save_button,
SaveButtonText = entity.save_button_text,
IsShowCancelButton = entity.is_show_cancel_button,
CancelButtonText = entity.cancel_button_text,
Justify = entity.justify,
IsValidate = entity.is_validate,
SaveScript = entity.save_script,
javascript = entity.javascript,
ListFormItem = !string.IsNullOrWhiteSpace(entity.form_item) ? DeserializeCollection<dynamic>(entity.form_item) : null,
ListControl = !string.IsNullOrWhiteSpace(entity.controls) ? DeserializeCollection<dynamic>(entity.controls) : null,
ListJavascriptSrc = !string.IsNullOrWhiteSpace(entity.javascript_src) ? DeserializeCollection<string>(entity.javascript_src) : null,
};
}
}
return dto;
}
}
}
......@@ -2,6 +2,8 @@
using Bailun.DC.Models.Component.Entity;
using Bailun.DC.Models.Component.Enum;
using Dapper;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
......@@ -13,31 +15,32 @@ namespace Bailun.DC.Services.Component
/// <summary>
/// 查询组件
/// </summary>
public class QueryService : BaseService
public class TableService : BaseService
{
/// <summary>
/// 获取查询组件
/// </summary>
/// <param name="code">编码</param>
/// <returns></returns>
public QueryDTO Get(string code)
public TableDTO Get(string code)
{
QueryDTO dto = default(QueryDTO);
TableDTO dto = default(TableDTO);
if (!string.IsNullOrWhiteSpace(code))
{
dc_component_query entity = default(dc_component_query);
dc_component_table entity = default(dc_component_table);
using (var db = DB)
{
DynamicParameters sqlparam = new DynamicParameters();
sqlparam.Add("code", code);
entity = db.QueryFirstOrDefault<dc_component_query>("select * from dc_component_query where is_delete = 0 and code = @code", sqlparam);
entity = db.QueryFirstOrDefault<dc_component_table>("select * from dc_component_table where is_delete = 0 and code = @code", sqlparam);
}
if (entity != null)
{
dto = new QueryDTO
dto = new TableDTO
{
Code = entity.code,
Name = entity.name,
MenuCode = entity.menu_code,
Javascript = entity.javascript,
IsShowSearchButton = entity.is_show_search_button,
......@@ -45,6 +48,7 @@ namespace Bailun.DC.Services.Component
IsShowExportButton = entity.is_show_export_button,
IsShowImportButton = entity.is_show_import_button,
IsShowSequenceColumn = entity.is_show_sequence_column,
OperateControlsPosition = entity.operate_controls_position,
ColumnType = entity.column_type,
ColumnValue = entity.column_value,
DataType = entity.data_type,
......@@ -52,6 +56,7 @@ namespace Bailun.DC.Services.Component
DataDB = entity.data_db,
DataSortSql = entity.data_sort_sql,
IsAutoSearch = entity.is_auto_search,
IsShowColumnSearch = entity.is_show_column_search,
SelectRowMethod = entity.select_row_method,
OperateColumnName = entity.operate_column_name,
OperateColumnWidth = entity.operate_column_width,
......@@ -76,7 +81,7 @@ namespace Bailun.DC.Services.Component
return dto;
}
public IList<ColumnDTO> GetListColumn(QueryFilterDTO queryFilter = null, QueryDTO entity = null)
public IList<ColumnDTO> GetListColumn(QueryFilterDTO queryFilter = null, TableDTO entity = null)
{
IList<ColumnDTO> list = default(IList<ColumnDTO>);
......@@ -225,7 +230,7 @@ namespace Bailun.DC.Services.Component
return list;
}
public PageListDTO GetListData(QueryFilterDTO queryFilter, QueryDTO entity = null)
public PageListDTO GetListData(QueryFilterDTO queryFilter, TableDTO entity = null)
{
PageListDTO pageList = new PageListDTO();
if (queryFilter != null && !string.IsNullOrWhiteSpace(queryFilter.Code))
......@@ -466,7 +471,7 @@ namespace Bailun.DC.Services.Component
byte[] b = default(byte[]);
if (queryFilter != null)
{
QueryDTO entity = this.Get(queryFilter.Code);
TableDTO entity = this.Get(queryFilter.Code);
IList<ColumnDTO> listColumn = this.GetListColumn(queryFilter, entity);
if (listColumn != null)
{
......@@ -499,6 +504,122 @@ namespace Bailun.DC.Services.Component
return b;
}
/// <summary>
/// 保存报表组件
/// </summary>
/// <param name="dto">报表组件对象</param>
/// <returns>保存结果</returns>
public ResultDTO Save(TableDTO dto)
{
ResultDTO result = this.BeforeSave(dto);
if (result.Result)
{
dc_component_table entity = new dc_component_table()
{
id = dto.Id,
code = dto.Code,
name = dto.Name,
menu_code = dto.MenuCode,
javascript = dto.Javascript,
is_show_search_button = dto.IsShowSearchButton,
is_show_reset_button = dto.IsShowResetButton,
is_show_export_button = dto.IsShowExportButton,
is_show_import_button = dto.IsShowImportButton,
is_show_sequence_column = dto.IsShowSequenceColumn,
is_show_column_search = dto.IsShowColumnSearch,
column_type = dto.ColumnType,
column_value = dto.ColumnValue,
data_type = dto.DataType,
data_value = dto.DataValue,
data_db = dto.DataDB,
data_sort_sql = dto.DataSortSql,
is_auto_search = dto.IsAutoSearch,
select_row_method = dto.SelectRowMethod,
operate_column_name = dto.OperateColumnName,
operate_column_width = dto.OperateColumnWidth,
gmt_modified = DateTime.Now,
crumbs = JsonConvert.SerializeObject(dto.ListCrumb),
javascript_src = JsonConvert.SerializeObject(dto.ListJavascriptSrc),
filter_controls = JsonConvert.SerializeObject(dto.ListFilterControl),
operate_controls = JsonConvert.SerializeObject(dto.ListOperateControl),
operate_column_value = JsonConvert.SerializeObject(dto.ListOperateColumnControl),
};
using (var db = DB)
{
//开启事务
MySqlTransaction transaction = db.BeginTransaction();
try
{
int? resultCount = entity.id > 0 ? db.Update(entity) : db.Insert(entity);
if (resultCount == 0)
{
throw new Exception("保存失败");
}
else
{
//提交事务
transaction.Commit();
result.Message = "保存成功";
}
}
catch (Exception ex)
{
//回滚事务
transaction.Rollback();
result.Message = ex.Message;
result.Result = false;
}
}
}
return result;
}
/// <summary>
/// 保存报表组件
/// </summary>
/// <param name="id">ID</param>
/// <param name="is_delete">是否删除</param>
/// <returns>保存结果</returns>
public ResultDTO Save(int[] id, bool is_delete)
{
ResultDTO result = this.BeforeSave(id);
if (result.Result)
{
string sql = "update dc_component_table set is_delete = @is_delete, gmt_modified = @gmt_modified where id in @id";
using (var db = DB)
{
//开启事务
MySqlTransaction transaction = db.BeginTransaction();
try
{
int resultCount = db.Execute(sql, new { id = id, is_delete = is_delete, gmt_modified = DateTime.Now });
if (resultCount == 0)
{
throw new Exception("保存失败");
}
else
{
//提交事务
transaction.Commit();
result.Message = "保存成功";
}
}
catch (Exception ex)
{
//回滚事务
transaction.Rollback();
result.Message = ex.Message;
result.Result = false;
}
}
}
return result;
}
private string GetFilterSql(QueryFilterDTO queryFilter, ref DynamicParameters sqlparam, string sp = "", string sp2 = "", string sp3 = "")
{
StringBuilder sql = new StringBuilder("WHERE 1 = 1 ");
......@@ -510,6 +631,8 @@ namespace Bailun.DC.Services.Component
{
if (!string.IsNullOrWhiteSpace(fieldFilter.Value))
{
//去两边空格
fieldFilter.Value = fieldFilter.Value.Trim();
sql.Append("AND ");
//时间范围
if (fieldFilter.Operator.ToUpper().Equals("BETWEEN"))
......@@ -545,7 +668,7 @@ namespace Bailun.DC.Services.Component
//模糊匹配
if (fieldFilter.Operator.ToUpper().Equals("LIKE"))
{
sql.Append($"'{sp3}%'+@{fieldFilter.Field}+'%'{sp3} ");
sql.Append($"CONCAT('%',@{fieldFilter.Field},'%')");
sqlparam.Add($"@{fieldFilter.Field}", fieldFilter.Value);
}
//其他操作符
......@@ -586,7 +709,7 @@ namespace Bailun.DC.Services.Component
return sql.ToString();
}
private string GetOrderBySql(QueryFilterDTO queryFilter, QueryDTO entity = null)
private string GetOrderBySql(QueryFilterDTO queryFilter, TableDTO entity = null)
{
string sql = string.Empty;
......@@ -621,7 +744,7 @@ namespace Bailun.DC.Services.Component
return sql;
}
private (int, IDataReader) GetListDataReader(QueryFilterDTO queryFilter, QueryDTO entity)
private (int, IDataReader) GetListDataReader(QueryFilterDTO queryFilter, TableDTO entity)
{
(int, IDataReader) reader = (0, null);
DynamicParameters sqlparam = new DynamicParameters();
......@@ -639,5 +762,56 @@ namespace Bailun.DC.Services.Component
return reader;
}
/// <summary>
/// 保存报表组件
/// </summary>
/// <param name="dto">报表组件对象</param>
/// <returns>保存结果</returns>
private ResultDTO BeforeSave(TableDTO dto)
{
ResultDTO result = new ResultDTO();
if (dto == null)
{
result.Message = "参数有误";
}
else if (string.IsNullOrWhiteSpace(dto.Code))
{
result.Message = "编码不能为空";
}
else if (string.IsNullOrWhiteSpace(dto.Name))
{
result.Message = "名称不能为空";
}
else if (string.IsNullOrWhiteSpace(dto.Name))
{
result.Message = "名称不能为空";
}
else
{
result.Result = true;
}
return result;
}
/// <summary>
/// 保存报表组件
/// </summary>
/// <param name="id">ID</param>
/// <returns>保存结果</returns>
private ResultDTO BeforeSave(int[] id)
{
ResultDTO result = new ResultDTO();
if (id == null || id.Length == 0 || id.Contains(0))
{
result.Message = "ID不能为空";
}
else
{
result.Result = true;
}
return result;
}
}
}
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