Commit 8c88b37c by Licx

导入数据自定义列表,兼容视图自定义名称

parent 1c034c60
...@@ -10,7 +10,7 @@ public class CustomRequest ...@@ -10,7 +10,7 @@ public class CustomRequest
public string TableName { get; set; } public string TableName { get; set; }
public string QuerySearch{ get; set; } public string QuerySearch { get; set; }
} }
public class CustomPagingRequest : CustomRequest public class CustomPagingRequest : CustomRequest
......
using System; namespace Performance.EntityModels.Other
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Performance.EntityModels.Other
{ {
public class ColumnEntity public class ColumnEntity
{ {
public string Name { get; set; } public string Name { get; set; }
public string Comment { get; set; } public string Comment { get; set; }
public string TableType { get; set; }
} }
} }
...@@ -523,11 +523,20 @@ public List<dynamic> QueryCustom(string tableName, int allotId, string accountin ...@@ -523,11 +523,20 @@ public List<dynamic> QueryCustom(string tableName, int allotId, string accountin
/// <param name="pageIndex"></param> /// <param name="pageIndex"></param>
/// <param name="pageSize"></param> /// <param name="pageSize"></param>
/// <returns></returns> /// <returns></returns>
public CustonPagingData QueryCustom(string tableName, int allotId, string accountingUnit, string[] unitType, int pageIndex = 1, int pageSize = 20) public CustonPagingData QueryCustom(string tableName, int allotId, string accountingUnit, string[] unitType, int pageIndex = 1, int pageSize = 20, bool isView = false)
{ {
string dataQuery = $@"SELECT * FROM {tableName} WHERE AllotId = @AllotId and AccountingUnit = @accountingUnit and UnitType in @unitType order by UnitType,AccountingUnit LIMIT {(pageIndex - 1) * pageSize},{pageSize} "; string dataQuery;
string countQuery = $@"SELECT COUNT(*) FROM {tableName} WHERE AllotId = @AllotId and AccountingUnit = @accountingUnit and UnitType in @unitType "; string countQuery;
if (isView)
{
dataQuery = $@"SELECT * FROM {tableName} WHERE AllotId = @AllotId and `核算单元` = @accountingUnit and `核算单元类型` in @unitType order by `核算单元类型`,`核算单元` LIMIT {(pageIndex - 1) * pageSize},{pageSize} ";
countQuery = $@"SELECT COUNT(*) FROM {tableName} WHERE AllotId = @AllotId and `核算单元` = @accountingUnit and `核算单元类型` in @unitType ";
}
else
{
dataQuery = $@"SELECT * FROM {tableName} WHERE AllotId = @AllotId and AccountingUnit = @accountingUnit and UnitType in @unitType order by UnitType,AccountingUnit LIMIT {(pageIndex - 1) * pageSize},{pageSize} ";
countQuery = $@"SELECT COUNT(*) FROM {tableName} WHERE AllotId = @AllotId and AccountingUnit = @accountingUnit and UnitType in @unitType ";
}
var result = new CustonPagingData var result = new CustonPagingData
{ {
DataList = DapperQuery<dynamic>(dataQuery, new { allotId, unitType, accountingUnit }, commandTimeout: 60 * 10)?.ToList(), DataList = DapperQuery<dynamic>(dataQuery, new { allotId, unitType, accountingUnit }, commandTimeout: 60 * 10)?.ToList(),
...@@ -543,7 +552,7 @@ public CustonPagingData QueryCustom(string tableName, int allotId, string accoun ...@@ -543,7 +552,7 @@ public CustonPagingData QueryCustom(string tableName, int allotId, string accoun
/// <param name="request"></param> /// <param name="request"></param>
/// <param name="IsHead"></param> /// <param name="IsHead"></param>
/// <returns></returns> /// <returns></returns>
public CustonPagingData QueryCustom(CustomPagingRequest request, bool IsHead) public CustonPagingData QueryCustom(CustomPagingRequest request, bool IsHead, bool isView)
{ {
var result = new CustonPagingData(); var result = new CustonPagingData();
string sql, Query; string sql, Query;
...@@ -551,12 +560,15 @@ public CustonPagingData QueryCustom(CustomPagingRequest request, bool IsHead) ...@@ -551,12 +560,15 @@ public CustonPagingData QueryCustom(CustomPagingRequest request, bool IsHead)
if (string.IsNullOrEmpty(request.QuerySearch)) if (string.IsNullOrEmpty(request.QuerySearch))
Query = " and 1=1 "; Query = " and 1=1 ";
else else
Query = $@" and (AccountingUnit like '%{request.QuerySearch}%' or UnitType like '%{request.QuerySearch}%') "; Query = isView
? $@" and (`核算单元` like '%{request.QuerySearch}%' or `核算单元类型` like '%{request.QuerySearch}%') "
: $@" and (AccountingUnit like '%{request.QuerySearch}%' or UnitType like '%{request.QuerySearch}%') ";
string order = isView ? "`核算单元类型`,`核算单元`" : "UnitType,AccountingUnit";
if (IsHead) if (IsHead)
sql = $@"SELECT * FROM {request.TableName} WHERE AllotId = @AllotId "; sql = $@"SELECT * FROM {request.TableName} WHERE AllotId = @AllotId ";
else else
sql = $@"SELECT * FROM {request.TableName} WHERE AllotId = @AllotId {Query} order by UnitType,AccountingUnit LIMIT {(request.PageIndex - 1) * request.PageSize},{request.PageSize} "; sql = $@"SELECT * FROM {request.TableName} WHERE AllotId = @AllotId {Query} order by {order} LIMIT {(request.PageIndex - 1) * request.PageSize},{request.PageSize} ";
result.DataList = DapperQuery<dynamic>(sql, new { request.AllotId }, commandTimeout: 60 * 10)?.ToList(); result.DataList = DapperQuery<dynamic>(sql, new { request.AllotId }, commandTimeout: 60 * 10)?.ToList();
...@@ -570,9 +582,9 @@ public bool QueryIsAllotId(string tableName, params string[] columns) ...@@ -570,9 +582,9 @@ public bool QueryIsAllotId(string tableName, params string[] columns)
{ {
var database = context.Database.GetDbConnection().Database; var database = context.Database.GetDbConnection().Database;
var sql = $@"SELECT column_name FROM information_schema.COLUMNS s var sql = $@"SELECT column_name FROM information_schema.COLUMNS s
WHERE table_name = @table_name AND TABLE_SCHEMA = @database AND column_name in @columns;"; WHERE table_name = @table_name AND TABLE_SCHEMA = @database AND lower(column_name) in @columns;";
var result = DapperQuery<string>(sql, new { database = database, table_name = tableName, columns }, commandTimeout: 60 * 10); var result = DapperQuery<string>(sql, new { database = database, table_name = tableName, columns }, commandTimeout: 60 * 10);
var isExist = result?.Count() == 3; var isExist = result?.Count() == columns?.Count();
return isExist; return isExist;
...@@ -582,7 +594,7 @@ public bool QueryIsAllotId(string tableName, params string[] columns) ...@@ -582,7 +594,7 @@ public bool QueryIsAllotId(string tableName, params string[] columns)
public List<ColumnEntity> QueryCustomColumn(string tableName) public List<ColumnEntity> QueryCustomColumn(string tableName)
{ {
var database = context.Database.GetDbConnection().Database; var database = context.Database.GetDbConnection().Database;
var sql = $@"SELECT column_name as Name,ifnull(column_comment,column_name) as comment FROM information_schema.`COLUMNS` WHERE table_schema = @table_schema AND table_name = @table_name AND COLUMN_KEY <> 'PRI' "; var sql = $@"SELECT column_name AS NAME, IF(ifnull(column_comment, '')<> '', column_comment, column_name) AS COMMENT, TABLE_TYPE AS TABLETYPE FROM information_schema.`COLUMNS` t1 JOIN information_schema.`TABLES` t2 ON t1.table_schema = t2.table_schema AND t1.table_name = t2.table_name WHERE t1.table_schema = @table_schema AND t1.table_name = @table_name AND COLUMN_KEY <> 'PRI' ";
var result = DapperQuery<ColumnEntity>(sql, new { table_schema = database, table_name = tableName }, commandTimeout: 60 * 10)?.ToList(); var result = DapperQuery<ColumnEntity>(sql, new { table_schema = database, table_name = tableName }, commandTimeout: 60 * 10)?.ToList();
return result; return result;
......
...@@ -1301,10 +1301,13 @@ public void SaveDrugtypeFactor(DrugtypeFactorRequest request) ...@@ -1301,10 +1301,13 @@ public void SaveDrugtypeFactor(DrugtypeFactorRequest request)
public HandsonTableBase QueryHandsCustom(CustomPagingRequest request) public HandsonTableBase QueryHandsCustom(CustomPagingRequest request)
{ {
var custom = _perforReport.QueryCustomColumn(request.TableName); var custom = _perforReport.QueryCustomColumn(request.TableName);
if (custom == null || !custom.Any()) return null;
var isExist = _perforReport.QueryIsAllotId(request.TableName, "AllotId", "AccountingUnit", "UnitType"); var isView = custom.FirstOrDefault(w => !string.IsNullOrEmpty(w.TableType))?.TableType == "VIEW";
if (custom == null || isExist == false) if (isView) return new HandsonTableBase(); //如果是视图,不加载HandsonTable,则直接跳过
return null;
var isExist = _perforReport.QueryIsAllotId(request.TableName, "allotid", "accountingunit", "unittype");
if (isExist == false) return null;
var skip = new string[] { "allotid" }; var skip = new string[] { "allotid" };
...@@ -1321,7 +1324,7 @@ public HandsonTableBase QueryHandsCustom(CustomPagingRequest request) ...@@ -1321,7 +1324,7 @@ public HandsonTableBase QueryHandsCustom(CustomPagingRequest request)
ColHeaders = new List<string>(), ColHeaders = new List<string>(),
}; };
var jsonData = JsonHelper.Serialize(_perforReport.QueryCustom(request, true).DataList); var jsonData = JsonHelper.Serialize(_perforReport.QueryCustom(request, true, false).DataList);
var data = JsonHelper.Deserialize<List<Dictionary<string, string>>>(jsonData); var data = JsonHelper.Deserialize<List<Dictionary<string, string>>>(jsonData);
var headDic = new List<Dictionary<string, object>>(); var headDic = new List<Dictionary<string, object>>();
...@@ -1444,8 +1447,11 @@ public ApiResponse SaveCustomTable(SaveCustomData request) ...@@ -1444,8 +1447,11 @@ public ApiResponse SaveCustomTable(SaveCustomData request)
public ApiResponse QueryCustom(int userId, CustomPagingRequest request) public ApiResponse QueryCustom(int userId, CustomPagingRequest request)
{ {
var heads = _perforReport.QueryCustomColumn(request.TableName); var heads = _perforReport.QueryCustomColumn(request.TableName);
var isExist = _perforReport.QueryIsAllotId(request.TableName, "AllotId", "AccountingUnit", "UnitType"); if (heads == null || !heads.Any()) return null;
if (isExist == false || heads == null)
var isView = heads.FirstOrDefault(w => !string.IsNullOrEmpty(w.TableType))?.TableType == "VIEW";
var isExist = _perforReport.QueryIsAllotId(request.TableName, "allotid", "accountingunit", "unittype");
if (!isView && isExist == false)
return new ApiResponse(ResponseType.ParameterError, "表不符合规范,请补全注释或修改重复注释"); return new ApiResponse(ResponseType.ParameterError, "表不符合规范,请补全注释或修改重复注释");
if (heads.Count > 50) if (heads.Count > 50)
return new ApiResponse(ResponseType.ParameterError, "最多支持50列数据"); return new ApiResponse(ResponseType.ParameterError, "最多支持50列数据");
...@@ -1459,8 +1465,6 @@ public ApiResponse QueryCustom(int userId, CustomPagingRequest request) ...@@ -1459,8 +1465,6 @@ public ApiResponse QueryCustom(int userId, CustomPagingRequest request)
if (customGroup.Any()) if (customGroup.Any())
return new ApiResponse(ResponseType.ParameterError, "表不符合规范,请补全注释或修改重复注释"); return new ApiResponse(ResponseType.ParameterError, "表不符合规范,请补全注释或修改重复注释");
var user = _userService.GetUser(userId); var user = _userService.GetUser(userId);
var roleType = _roleService.GetUserRole(userId)?.FirstOrDefault()?.Type ?? 0; var roleType = _roleService.GetUserRole(userId)?.FirstOrDefault()?.Type ?? 0;
...@@ -1470,9 +1474,9 @@ public ApiResponse QueryCustom(int userId, CustomPagingRequest request) ...@@ -1470,9 +1474,9 @@ public ApiResponse QueryCustom(int userId, CustomPagingRequest request)
}; };
var unitTypes = UnitTypeUtil.GetMaps(roleType); var unitTypes = UnitTypeUtil.GetMaps(roleType);
if (unitTypes.Any()) if (unitTypes.Any())
result.Datas = _perforReport.QueryCustom(request.TableName, request.AllotId, user?.Department ?? "", unitTypes, request.PageIndex, request.PageSize); result.Datas = _perforReport.QueryCustom(request.TableName, request.AllotId, user?.Department ?? "", unitTypes, request.PageIndex, request.PageSize, isView);
else else
result.Datas = _perforReport.QueryCustom(request, false); result.Datas = _perforReport.QueryCustom(request, false, isView);
return new ApiResponse(ResponseType.OK, result); return new ApiResponse(ResponseType.OK, 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