Commit 64d01c52 by 钟博

Merge branch 'feature/自定义功能' into develop

parents 483449cd 617684ee
...@@ -852,5 +852,57 @@ public ApiResponse CopyDropDown() ...@@ -852,5 +852,57 @@ public ApiResponse CopyDropDown()
}; ; }; ;
return new ApiResponse(ResponseType.OK, result); return new ApiResponse(ResponseType.OK, result);
} }
/// <summary>
/// 自定义表Heads表头
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost("customheads")]
public ApiResponse CustomHeads([FromBody] CustomPagingRequest request)
{
if (string.IsNullOrEmpty(request.TableName))
return new ApiResponse(ResponseType.ParameterError, "表名为空");
var result = _configService.QueryHandsCustom(request);
if (result == null)
return new ApiResponse(ResponseType.ParameterError, "表不符合规范,请补全注释或修改重复注释");
else
return new ApiResponse(ResponseType.OK, result);
}
/// <summary>
/// 自定义表显示
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost("getcustomlist")]
public ApiResponse GetCustomList([FromBody] CustomPagingRequest request)
{
var allot = _allotService.GetAllot(request.AllotId);
if (allot == null)
return new ApiResponse(ResponseType.ParameterError, "AllotID错误");
return _configService.QueryCustom(request);
}
/// <summary>
/// 保存自定义表数据
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("savecustom")]
[HttpPost]
public ApiResponse BatchSaveCustom([FromBody] SaveCustomData request)
{
var allot = _allotService.GetAllot(request.AllotId);
if (allot == null)
return new ApiResponse(ResponseType.ParameterError, "AllotID错误");
else if (string.IsNullOrEmpty(request.TableName))
return new ApiResponse(ResponseType.ParameterError, "表名为空");
return _configService.SaveCustomTable(request);
}
} }
} }
\ No newline at end of file
...@@ -857,6 +857,27 @@ ...@@ -857,6 +857,27 @@
<param name="request"></param> <param name="request"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Performance.Api.Controllers.ConfigController.CustomHeads(Performance.DtoModels.CustomPagingRequest)">
<summary>
自定义表Heads表头
</summary>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ConfigController.GetCustomList(Performance.DtoModels.CustomPagingRequest)">
<summary>
自定义表显示
</summary>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ConfigController.BatchSaveCustom(Performance.DtoModels.SaveCustomData)">
<summary>
保存自定义表数据
</summary>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.CostTransferController.SubmitApplications(Performance.DtoModels.CostTransferRequest)"> <member name="M:Performance.Api.Controllers.CostTransferController.SubmitApplications(Performance.DtoModels.CostTransferRequest)">
<summary> <summary>
申请划拨 申请划拨
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.DtoModels
{
public class CustomRequest
{
public int AllotId { get; set; }
public string TableName { get; set; }
public string QuerySearch{ get; set; }
}
public class CustomPagingRequest : CustomRequest
{
public int PageIndex { get; set; } = 1;
public int PageSize { get; set; } = 20;
}
public class CustonPagingData
{
public List<dynamic> DataList { get; set; }
public int TotalCount { get; set; }
}
public class CustomResponse
{
public List<Heads> Heads { get; set; }
public CustonPagingData Datas { get; set; }
}
public class Heads
{
public string Cloumn { get; set; }
public string Name { get; set; }
}
}
...@@ -22,5 +22,11 @@ public class UserCollectData ...@@ -22,5 +22,11 @@ public class UserCollectData
public new string[][] Data { get; set; } public new string[][] Data { get; set; }
} }
public class SaveCustomData
{
public int AllotId { get; set; }
public string TableName { get; set; }
public string[] ColHeaders { get; set; }
public new string[][] Data { get; set; }
}
} }
using Performance.DtoModels; using Microsoft.EntityFrameworkCore;
using Performance.DtoModels;
using Performance.EntityModels; using Performance.EntityModels;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -395,5 +396,80 @@ public List<dynamic> QueryCompute(int allotId, string viewName) ...@@ -395,5 +396,80 @@ public List<dynamic> QueryCompute(int allotId, string viewName)
return DapperQuery<dynamic>(sql, new { allotId })?.ToList(); return DapperQuery<dynamic>(sql, new { allotId })?.ToList();
} }
public CustonPagingData QueryCustom(CustomPagingRequest request, bool IsHead)
{
var result = new CustonPagingData();
string sql, Query;
if (string.IsNullOrEmpty(request.QuerySearch))
Query = " and 1=1 ";
else
Query = $@" and (AccountingUnit like '%{request.QuerySearch}%' or UnitType like '%{request.QuerySearch}%') ";
if (IsHead)
sql = $@"SELECT * FROM {request.TableName} WHERE AllotId = @AllotId ";
else
sql = $@"SELECT * FROM {request.TableName} WHERE AllotId = @AllotId {Query} order by UnitType,AccountingUnit LIMIT {(request.PageIndex - 1) * request.PageSize},{request.PageSize} ";
result.DataList = DapperQuery<dynamic>(sql, new { request.AllotId })?.ToList();
sql = $@"SELECT COUNT(*) FROM {request.TableName} WHERE AllotId = @AllotId {Query} ";
result.TotalCount = DapperQuery<int>(sql, new { request.AllotId })?.FirstOrDefault() ?? 0;
return result;
}
public bool QueryIsAllotId(string tableName)
{
var database = context.Database.GetDbConnection().Database;
var sql = $@"SELECT column_name FROM information_schema.COLUMNS s
WHERE table_name = @table_name AND TABLE_SCHEMA = @database AND (column_name='allotId' or column_name='AccountingUnit' or column_name='UnitType');";
var result = DapperQuery<string>(sql, new { database = database, table_name = tableName });
var isExist=result ?.Count() == 3;
return isExist;
}
public List<dynamic> QueryCustomColumn(string tableName)
{
var database = context.Database.GetDbConnection().Database;
var sql = $@"SELECT column_name,column_comment FROM information_schema.`COLUMNS` WHERE table_schema = @table_schema AND table_name = @table_name AND COLUMN_KEY <> 'PRI' ";
var result = DapperQuery<dynamic>(sql, new { table_schema = database, table_name = tableName })?.ToList();
return result;
}
public bool CreatCustom(int AllotId, string tableName, List<dynamic> datas)
{
var sql = $@"DELETE FROM {tableName} WHERE allotId=@AllotId ";
Execute(sql, new { AllotId });
if (datas == null)
return true;
var database = context.Database.GetDbConnection().Database;
sql = $@"SELECT column_name FROM information_schema.COLUMNS s
WHERE table_name = @table_name AND TABLE_SCHEMA = @database AND COLUMN_KEY <> 'PRI';";
var columns = DapperQuery<string>(sql, new { database = database, table_name = tableName })?.ToList();
sql = $"INSERT INTO {tableName}({string.Join(",", columns.ToArray())}) VALUES({string.Join(",", columns.Select(t => "@" + t))});";
var success = Execute(sql, datas);
if (success > 0)
return true;
else
return false;
}
public List<dynamic> QueryType(string tableName)
{
var database = context.Database.GetDbConnection().Database;
var sql = $@"select column_name,data_type from information_schema.columns where table_name=@table_name and table_schema=@table_schema AND (data_type like '%int%' or data_type like '%decimal%' or data_type like '%date%') AND COLUMN_KEY <> 'PRI' ";
var result = DapperQuery<dynamic>(sql, new { table_schema = database, table_name = tableName })?.ToList();
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