Commit 617684ee by 钟博

补充

parent 03eef406
...@@ -858,14 +858,14 @@ public ApiResponse CopyDropDown() ...@@ -858,14 +858,14 @@ public ApiResponse CopyDropDown()
/// <param name="request"></param> /// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("customheads")] [HttpPost("customheads")]
public ApiResponse CustomHeads([FromBody] CustomRequest request) public ApiResponse CustomHeads([FromBody] CustomPagingRequest request)
{ {
if (string.IsNullOrEmpty(request.TableName)) if (string.IsNullOrEmpty(request.TableName))
return new ApiResponse(ResponseType.ParameterError, "表名为空"); return new ApiResponse(ResponseType.ParameterError, "表名为空");
var result = _configService.QueryHandsCustom(request.TableName); var result = _configService.QueryHandsCustom(request);
if (result == null) if (result == null)
return new ApiResponse(ResponseType.ParameterError, "不符合规范"); return new ApiResponse(ResponseType.ParameterError, "表不符合规范,请补全注释或修改重复注释");
else else
return new ApiResponse(ResponseType.OK, result); return new ApiResponse(ResponseType.OK, result);
} }
...@@ -882,11 +882,7 @@ public ApiResponse GetCustomList([FromBody] CustomPagingRequest request) ...@@ -882,11 +882,7 @@ public ApiResponse GetCustomList([FromBody] CustomPagingRequest request)
if (allot == null) if (allot == null)
return new ApiResponse(ResponseType.ParameterError, "AllotID错误"); return new ApiResponse(ResponseType.ParameterError, "AllotID错误");
var result = _configService.QueryCustom(request); return _configService.QueryCustom(request);
if (result.isNorm)
return new ApiResponse(ResponseType.OK, result);
else
return new ApiResponse(ResponseType.ParameterError, "不符合规范");
} }
/// <summary> /// <summary>
...@@ -904,11 +900,8 @@ public ApiResponse BatchSaveCustom([FromBody] SaveCustomData request) ...@@ -904,11 +900,8 @@ public ApiResponse BatchSaveCustom([FromBody] SaveCustomData request)
else if (string.IsNullOrEmpty(request.TableName)) else if (string.IsNullOrEmpty(request.TableName))
return new ApiResponse(ResponseType.ParameterError, "表名为空"); return new ApiResponse(ResponseType.ParameterError, "表名为空");
var result = _configService.SaveCustomTable(request);
if (result) return _configService.SaveCustomTable(request);
return new ApiResponse(ResponseType.OK);
else
return new ApiResponse(ResponseType.Error);
} }
} }
} }
\ No newline at end of file
...@@ -857,7 +857,7 @@ ...@@ -857,7 +857,7 @@
<param name="request"></param> <param name="request"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Performance.Api.Controllers.ConfigController.CustomHeads(Performance.DtoModels.CustomRequest)"> <member name="M:Performance.Api.Controllers.ConfigController.CustomHeads(Performance.DtoModels.CustomPagingRequest)">
<summary> <summary>
自定义表Heads表头 自定义表Heads表头
</summary> </summary>
......
...@@ -9,6 +9,8 @@ public class CustomRequest ...@@ -9,6 +9,8 @@ public class CustomRequest
public int AllotId { get; set; } public int AllotId { get; set; }
public string TableName { get; set; } public string TableName { get; set; }
public string QuerySearch{ get; set; }
} }
public class CustomPagingRequest : CustomRequest public class CustomPagingRequest : CustomRequest
...@@ -27,7 +29,6 @@ public class CustomResponse ...@@ -27,7 +29,6 @@ public class CustomResponse
{ {
public List<Heads> Heads { get; set; } public List<Heads> Heads { get; set; }
public CustonPagingData Datas { get; set; } public CustonPagingData Datas { get; set; }
public bool isNorm { get; set; } = true;
} }
public class Heads public class Heads
......
...@@ -397,23 +397,36 @@ public List<dynamic> QueryCompute(int allotId, string viewName) ...@@ -397,23 +397,36 @@ 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) public CustonPagingData QueryCustom(CustomPagingRequest request, bool IsHead)
{ {
var result = new CustonPagingData(); var result = new CustonPagingData();
var sql = $@"SELECT * FROM {request.TableName} WHERE AllotId = @AllotId LIMIT {(request.PageIndex - 1) * request.PageSize},{request.PageSize} "; string sql, Query;
result.DataList= DapperQuery<dynamic>(sql, new { request.AllotId })?.ToList();
sql = $@"SELECT COUNT(*) FROM {request.TableName} WHERE AllotId = @AllotId "; 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; result.TotalCount = DapperQuery<int>(sql, new { request.AllotId })?.FirstOrDefault() ?? 0;
return result; return result;
} }
public bool QueryIsAllotId(string tableName) public bool QueryIsAllotId(string tableName)
{ {
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='allotId';"; WHERE table_name = @table_name AND TABLE_SCHEMA = @database AND (column_name='allotId' or column_name='AccountingUnit' or column_name='UnitType');";
var isExist = DapperQuery<string>(sql, new { database = database, table_name = tableName })?.Count()>0; var result = DapperQuery<string>(sql, new { database = database, table_name = tableName });
var isExist=result ?.Count() == 3;
return isExist; return isExist;
...@@ -433,6 +446,8 @@ public bool CreatCustom(int AllotId, string tableName, List<dynamic> datas) ...@@ -433,6 +446,8 @@ public bool CreatCustom(int AllotId, string tableName, List<dynamic> datas)
{ {
var sql = $@"DELETE FROM {tableName} WHERE allotId=@AllotId "; var sql = $@"DELETE FROM {tableName} WHERE allotId=@AllotId ";
Execute(sql, new { AllotId }); Execute(sql, new { AllotId });
if (datas == null)
return true;
var database = context.Database.GetDbConnection().Database; var database = context.Database.GetDbConnection().Database;
sql = $@"SELECT column_name FROM information_schema.COLUMNS s sql = $@"SELECT column_name FROM information_schema.COLUMNS s
...@@ -447,5 +462,14 @@ public bool CreatCustom(int AllotId, string tableName, List<dynamic> datas) ...@@ -447,5 +462,14 @@ public bool CreatCustom(int AllotId, string tableName, List<dynamic> datas)
else else
return false; 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;
}
} }
} }
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
using System.Text; using System.Text;
using Performance.Repository.Repository; using Performance.Repository.Repository;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Text.RegularExpressions;
namespace Performance.Services namespace Performance.Services
{ {
...@@ -1435,7 +1436,7 @@ public void SaveSecondaryAlias(SaveCollectData request) ...@@ -1435,7 +1436,7 @@ public void SaveSecondaryAlias(SaveCollectData request)
{ {
// 创建固定数据列 // 创建固定数据列
Dictionary<string, string> baseData = CreateBaseData(request, config, r); Dictionary<string, string> baseData = CreateBaseData(request, config, r);
baseData.Add(nameof(cof_hrp_department.HospitalId), hospitalId.ToString()); baseData.Add(nameof(cof_hrp_department.HospitalId), hospitalId.ToString());
allData.Add(baseData); allData.Add(baseData);
...@@ -1777,79 +1778,168 @@ public void SaveDrugtypeFactor(DrugtypeFactorRequest request) ...@@ -1777,79 +1778,168 @@ public void SaveDrugtypeFactor(DrugtypeFactorRequest request)
#region 自定义表 #region 自定义表
public HandsonTable QueryHandsCustom(string tableName) public HandsonTable QueryHandsCustom(CustomPagingRequest request)
{ {
var custom = perforReport.QueryCustomColumn(tableName); var custom = perforReport.QueryCustomColumn(request.TableName);
var isExist = perforReport.QueryIsAllotId(tableName); var isExist = perforReport.QueryIsAllotId(request.TableName);
if (custom == null || isExist == false) if (custom == null || isExist == false)
return null; return null;
var dicCustom = new List<string>(); var dicCustom = new Dictionary<string, string>();
for (int i = 0; i < custom.Count(); i++) for (int i = 0; i < custom.Count(); i++)
{ {
var dic = ((IDictionary<string, object>)custom.ElementAt(i)).Values; var dic = ((IDictionary<string, object>)custom.ElementAt(i)).Values;
if (dic.ElementAt(0).ToString().ToLower() == "allotid") if (dic.ElementAt(0).ToString().ToLower() == "allotid")
continue; continue;
dicCustom.Add(dic.ElementAt(1).ToString()); dicCustom.Add(dic.ElementAt(0).ToString(), dic.ElementAt(1).ToString());
} }
var result = new HandsonTable((int)SheetType.Unidentifiable, dicCustom.ToArray(), dicCustom.Select(t => new collect_permission var customGroup = dicCustom.GroupBy(x => x.Value).Where(x => x.Count() > 1);
if (customGroup.Any())
return null;
var result = new HandsonTable((int)SheetType.Unidentifiable, new string[] { }, new List<collect_permission>());
var jsonData = JsonHelper.Serialize(perforReport.QueryCustom(request,true).DataList);
var data = JsonHelper.Deserialize<List<Dictionary<string, string>>>(jsonData);
var headDic = new List<Dictionary<string, object>>();
foreach (var item in data)
{ {
HeadName = t, var head = new Dictionary<string, object>();
Visible = 1 foreach (var dic in dicCustom)
}).ToList()); {
if (item.ContainsKey(dic.Key.ToLower()))
head.Add(dic.Value, item.FirstOrDefault(t => t.Key == dic.Key.ToLower()).Value);
}
headDic.Add(head);
}
if (result.Columns != null && result.Columns.Any()) var Columns = dicCustom.Values.Select(t => new HandsonColumn(t, false, DataFormat.普通格式)).ToList();
//表类型
var columnType = perforReport.QueryType(request.TableName);
if (Columns != null && Columns.Any())
{ {
foreach (var column in result.Columns) foreach (var column in Columns)
{ {
column.Type = "text"; if (dicCustom.FirstOrDefault(t => t.Value.Contains(column.Data)).Key.ToLower() == "unittype")
{
{
column.Type = "autocomplete";
column.Source = EnumHelper.GetItems<UnitType>().Select(w => w.Description.Replace("行政后勤", "行政工勤")).ToArray();
column.Strict = true;
}
}
for (int i = 0; i < columnType.Count(); i++)
{
var type = ((IDictionary<string, object>)columnType.ElementAt(i)).Values;
var itemDic = column.Data.ToUpper() == type.ElementAt(0).ToString().ToUpper();
var dic = dicCustom.FirstOrDefault(t => t.Value == column.Data);
if (dic.Key.ToUpper() == type.ElementAt(0).ToString().ToUpper() && type.ElementAt(1).ToString() == "int")
{
column.Type = "numeric";
column.NumericFormat = new NumericFormat { Pattern = "0,00" };
}
if (dic.Key.ToUpper() == type.ElementAt(0).ToString().ToUpper() && type.ElementAt(1).ToString() == "decimal")
{
column.Type = "numeric";
column.NumericFormat = new NumericFormat { Pattern = "0,00.00" };
}
}
} }
} }
result.Data = headDic;
result.ColHeaders = dicCustom.Values.ToList();
result.Columns = Columns;
return result; return result;
} }
public bool SaveCustomTable(SaveCustomData request) public ApiResponse SaveCustomTable(SaveCustomData request)
{ {
if (!request.Data.Any())
perforReport.CreatCustom(request.AllotId, request.TableName, null);
var custom = perforReport.QueryCustomColumn(request.TableName); var custom = perforReport.QueryCustomColumn(request.TableName);
if(custom.Count>50)
return new ApiResponse(ResponseType.ParameterError, "最多支持50列数据!");
var dicCustom = new Dictionary<string, object>(); var dicCustom = new Dictionary<string, object>();
for (int i = 0; i < custom.Count(); i++) for (int i = 0; i < custom.Count(); i++)
{ {
var dic = ((IDictionary<string, object>)custom.ElementAt(i)).Values; var dic = ((IDictionary<string, object>)custom.ElementAt(i)).Values;
if (dic.ElementAt(0).ToString().ToLower() == "allotid")
continue;
dicCustom.Add(dic.ElementAt(0).ToString(), dic.ElementAt(1).ToString()); dicCustom.Add(dic.ElementAt(0).ToString(), dic.ElementAt(1).ToString());
} }
//重复表头
var customGroup = dicCustom.GroupBy(x => x.Value).Where(x => x.Count() > 1);
if (customGroup.Any())
return new ApiResponse(ResponseType.ParameterError, "表不符合规范,请补全注释或修改重复注释!");
var dicData = CreateCustomRow(request.AllotId, request, dicCustom); var dicData = CreateCustomRow(request.AllotId, request, dicCustom);
//字段类型
var typeColumn = perforReport.QueryType(request.TableName);
var datas = new List<dynamic>(); var datas = new List<dynamic>();
foreach (var item in dicData) foreach (var item in dicData)
{ {
var json = JsonHelper.Serialize(item); for (int i = 0; i < typeColumn.Count(); i++)
var data = JsonHelper.Deserialize<dynamic>(json); {
var convertData = JsonHelper.Deserialize<Dictionary<string, object>>(JsonHelper.Serialize(data)); var type = ((IDictionary<string, object>)typeColumn.ElementAt(i)).Values.ElementAt(0).ToString();
datas.Add(convertData); var itemDic = item.FirstOrDefault(t => t.Key.ToUpper() == type.ToUpper());
var value=((IDictionary<string, object>)typeColumn.ElementAt(i)).Values.ElementAt(1).ToString();
if (string.IsNullOrEmpty(itemDic.Value.ToString()) && value.Contains("date"))
item.AddOrUpdate(itemDic.Key,null);
else if(!string.IsNullOrEmpty(itemDic.Value.ToString()) && value.Contains("date"))
{
try
{
var s = DateTime.Parse(itemDic.Value.ToString());
}
catch (FormatException)
{
return new ApiResponse(ResponseType.ParameterError, "请输入正确的日期格式");
}
}
if (string.IsNullOrEmpty(itemDic.Value.ToString()) && !value.Contains("date"))
item.AddOrUpdate(itemDic.Key, 0);
if (!string.IsNullOrEmpty(itemDic.Value.ToString()) && !Regex.IsMatch(itemDic.Value.ToString(), @"^(\-|\+)?\d+(\.\d+)?$") && !value.Contains("date"))
return new ApiResponse(ResponseType.ParameterError, "保存失败,请修改红色输入内容!");
}
datas.Add(item);
} }
if (datas.Any()) if (datas.Any())
perforReport.CreatCustom(request.AllotId, request.TableName, datas); perforReport.CreatCustom(request.AllotId, request.TableName, datas);
return true; return new ApiResponse(ResponseType.OK);
} }
public CustomResponse QueryCustom(CustomPagingRequest request) public ApiResponse QueryCustom(CustomPagingRequest request)
{ {
var result = new CustomResponse(); var result = new CustomResponse();
var heads = perforReport.QueryCustomColumn(request.TableName); var heads = perforReport.QueryCustomColumn(request.TableName);
var isExist = perforReport.QueryIsAllotId(request.TableName); var isExist = perforReport.QueryIsAllotId(request.TableName);
if (isExist == false || heads == null) if (isExist == false || heads == null)
{ return new ApiResponse(ResponseType.ParameterError, "表不符合规范,请补全注释或修改重复注释");
result.isNorm = false; if(heads.Count>50)
return result; return new ApiResponse(ResponseType.ParameterError, "最多支持50列数据");
}
var headList = new List<Heads>(); var headList = new List<Heads>();
for (int i = 0; i < heads.Count(); i++) for (int i = 0; i < heads.Count(); i++)
...@@ -1863,35 +1953,39 @@ public CustomResponse QueryCustom(CustomPagingRequest request) ...@@ -1863,35 +1953,39 @@ public CustomResponse QueryCustom(CustomPagingRequest request)
headList.Add(head); headList.Add(head);
} }
var customGroup = headList.GroupBy(x => x.Name).Where(x => x.Count() > 1);
if (customGroup.Any())
return new ApiResponse(ResponseType.ParameterError, "表不符合规范,请补全注释或修改重复注释");
result.Heads = headList; result.Heads = headList;
result.Datas = perforReport.QueryCustom(request); result.Datas = perforReport.QueryCustom(request,false);
return result; return new ApiResponse(ResponseType.OK, result);
} }
private List<Dictionary<string, string>> CreateCustomRow(int allotId, SaveCustomData request, Dictionary<string, object> config) private List<Dictionary<string, object>> CreateCustomRow(int allotId, SaveCustomData request, Dictionary<string, object> config)
{ {
List<Dictionary<string, string>> allData = new List<Dictionary<string, string>>(); List<Dictionary<string, object>> allData = new List<Dictionary<string, object>>();
for (int r = 0; r < request.Data.Length; r++) for (int r = 0; r < request.Data.Length; r++)
{ {
// 创建固定数据列 // 创建固定数据列
Dictionary<string, string> baseData = CreateCustomData(request, config, r); Dictionary<string, object> baseData = CreateCustomData(request, config, r);
baseData.Add(nameof(cof_hrp_department.AllotId), allotId.ToString()); baseData.Add(nameof(cof_hrp_department.AllotId), allotId);
allData.Add(baseData); allData.Add(baseData);
} }
return allData; return allData;
} }
private Dictionary<string, string> CreateCustomData(SaveCustomData request, Dictionary<string, object> config, int rownumber) private Dictionary<string, object> CreateCustomData(SaveCustomData request, Dictionary<string, object> config, int rownumber)
{ {
Dictionary<string, string> result = new Dictionary<string, string>(); Dictionary<string, object> result = new Dictionary<string, object>();
for (int c = 0; c < request.ColHeaders.Length; c++) for (int c = 0; c < request.ColHeaders.Length; c++)
{ {
var header = request.ColHeaders[c]; var header = request.ColHeaders[c];
var first = config.FirstOrDefault(w => w.Value.ToString() == header); var first = config.FirstOrDefault(w => w.Value.ToString().ToUpper() == header);
if (!default(KeyValuePair<string, string>).Equals(first) if (!default(KeyValuePair<string, object>).Equals(first)
&& !result.ContainsKey(header) && !result.ContainsKey(header)
&& request.Data[rownumber].Length > c) && request.Data[rownumber].Length > c)
{ {
......
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