培训模块Excel导出检核

master
xiaochanghai 10 months ago
parent e1b7625621
commit 45b5ea36fb
  1. 170
      Tiobon.Core.Api/Controllers/Base/BaseController.cs
  2. 138
      Tiobon.Core.Api/Controllers/Ghre/Ghre_CreditPointController.cs
  3. 2
      Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamPaperController.cs
  4. 8
      Tiobon.Core.Api/Tiobon.Core.xml
  5. 5
      Tiobon.Core.Common/DB/Dapper/Utilities/DbAccess.cs
  6. 107
      Tiobon.Core.Common/Helper/NPOIHelper.cs
  7. 2
      Tiobon.Core.IServices/BASE/IBaseServices.cs
  8. 2
      Tiobon.Core.IServices/Ghre/IGhre_CreditPointServices.cs
  9. 2
      Tiobon.Core.IServices/Ghre/IGhre_ExamPaperServices.cs
  10. 10
      Tiobon.Core.Services/BASE/BaseServices.cs
  11. 9
      Tiobon.Core.Services/Ghre/Ghre_CertificateRuleServices.cs
  12. 8
      Tiobon.Core.Services/Ghre/Ghre_CreditPointServices.cs
  13. 7
      Tiobon.Core.Services/Ghre/Ghre_ExamPaperServices.cs
  14. 3
      Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs
  15. 2
      Tiobon.Core.Services/Ghre/Ghre_RequiredCourseServices.cs
  16. 25
      Tiobon.Core.Services/Ghre/Ghre_SchoolServices.cs
  17. 8
      Tiobon.Core/Tiobon.Core.xml

@ -1,4 +1,8 @@
using System.Reflection; using System.Collections;
using System.Data;
using System.Reflection;
using SqlSugar;
using Tiobon.Core.Common.DB.Dapper;
namespace Tiobon.Core.Controllers; namespace Tiobon.Core.Controllers;
@ -76,7 +80,7 @@ public class BaseController<IServiceBase, TEntity, TEntityDto, TInsertDto, TEdit
[HttpPost("Query/{Id}")] [HttpPost("Query/{Id}")]
public virtual async Task<ServiceResult<TEntityDto>> QueryById(long Id) public virtual async Task<ServiceResult<TEntityDto>> QueryById(long Id)
{ {
var entity = await InvokeServiceAsync("QueryById", [Id]); var entity = await InvokeServiceAsync("QueryById", [Id]);
if (entity is null) if (entity is null)
return Failed<TEntityDto>("获取失败"); return Failed<TEntityDto>("获取失败");
else else
@ -209,11 +213,167 @@ public class BaseController<IServiceBase, TEntity, TEntityDto, TInsertDto, TEdit
/// </summary> /// </summary>
/// <param name="body"></param> /// <param name="body"></param>
/// <returns></returns> /// <returns></returns>
//[HttpPost, Route("ExportExcel")]
//public async Task<ServiceResult<ExcelData>> ExportExcel([FromBody] QueryExport body)
//{
// var data = (await InvokeServiceAsync("ExportExcel", [body])) as ServiceResult<ExcelData>;
// return data;
//}
[HttpPost, Route("ExportExcel")] [HttpPost, Route("ExportExcel")]
public async Task<ServiceResult<string>> ExportExcel([FromBody] QueryExport body) public virtual async Task<ServiceResult<ExcelData>> ExportExcel([FromBody] QueryExport body)
{ {
var data = (await InvokeServiceAsync("ExportExcel", [body])) as ServiceResult<string>; QueryBody filter = new QueryBody();
return data; filter.pageNum = 1;
filter.pageSize = 1000000;
filter.langId = body.langId;
var condition = "1=1";
if (body.exportSet.SelectRowKeys != null && body.exportSet.SelectRowKeys.Any())
condition += $" AND Id IN({string.Join(",", body.exportSet.SelectRowKeys)})";
var data = (await InvokeServiceAsync("QueryFilterPage", [filter, condition, true])) as ServicePageResult<TEntityDto>;
string sql = $@"SELECT *
FROM Ghrs_PageSettingQuery
WHERE IsEnable = 1
AND PageNo = '{body.menuName}'
AND (defaultHidden = 'false' OR defaultHidden is null)
ORDER BY SortNo ASC";
var columns = DbAccess.QueryList<QueryExportColumn>(sql);
var fieldDescs = new Dictionary<string, string>();
if (body.exportSet.ExFields.Any())
body.exportSet.ExFields.ForEach(x =>
{
if (columns.Any(o => o.field == x))
fieldDescs.Add(x, columns.FirstOrDefault(o => o.field == x)?.label);
});
else
fieldDescs = columns.ToDictionary(item => item.field, item => item.label);
var dt = ToDataTable(data.result.DT_TableDataT1, fieldDescs, null);
// 获取所有列名
var dtColumns = dt.Columns;
var id = SnowFlakeSingle.instance.getID();
var physicsPath = $"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot";
var path = $"{$"{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}export{Path.DirectorySeparatorChar}{id}{Path.DirectorySeparatorChar}"}";
if (!Directory.Exists(physicsPath + path))
Directory.CreateDirectory(physicsPath + path);
path = path + body.exportSet.TitleName + ".xlsx";
NPOIHelper.ExportExcel(dt, body.exportSet.TitleName, "sheet1", physicsPath + path);
var result = new ExcelData();
result.filePath = path;
result.fileName = body.exportSet.TitleName + ".xlsx";
return ServiceResult<ExcelData>.OprateSuccess("导出成功", result);
}
/// <summary>
/// 列名按照前端显示顺序导出
/// </summary>
/// <param name="columns"></param>
/// <param name="ExportFields"></param>
/// <returns></returns>
public static (List<string>, List<string>) Sort(Dictionary<string, string> columns, List<string> ExportFields)
{
List<string> fields = new List<string>();
List<string> colunms = new List<string>();
if (ExportFields == null || ExportFields.Count == 0)
{
return (columns.Keys.ToList(), columns.Values.ToList());
}
foreach (var field in ExportFields)
{
foreach (var item in columns)
{
if (item.Key == field)
{
fields.Add(item.Key);
colunms.Add(item.Value);
}
}
}
return (fields, colunms);
}
public static DataTable ToDataTable(List<TEntityDto> list, Dictionary<string, string> fieldDescs = null, params string[] propertyName)
{
var (fields, colunms) = Sort(fieldDescs, null);
List<string> propertyNameList = new List<string>();
if (propertyName != null)
{
propertyNameList.AddRange(propertyName);
}
DataTable result = new DataTable();
if (list.Count > 0)
{
PropertyInfo[] propertys = list[0].GetType().GetProperties();
for (int i = 0; i < fields.Count; i++)
{
foreach (PropertyInfo pi in propertys)
{
if (propertyNameList.Count == 0)
{
//if (DBNull.Value.Equals(pi.PropertyType))
//{
// // pi.PropertyType = DateTime;
//}
Type colType = pi.PropertyType;
if (colType.IsGenericType && colType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
colType = colType.GetGenericArguments()[0];
}
if (fields[i] == pi.Name)
{
result.Columns.Add(colunms[i], colType);
}
//result.Columns.Add(pi.Name, pi.PropertyType);
}
else
{
if (propertyNameList.Contains(pi.Name))
{
if (fields[i] == pi.Name)
result.Columns.Add(fields[i], pi.PropertyType);
}
}
}
}
for (int i = 0; i < list.Count; i++)
{
ArrayList tempList = new ArrayList();
for (int j = 0; j < fields.Count; j++)
{
foreach (PropertyInfo pi in propertys)
{
if (fields[j] == pi.Name)
{
if (propertyNameList.Count == 0)
{
object obj = pi.GetValue(list[i], null);
tempList.Add(obj);
}
else
{
if (propertyNameList.Contains(pi.Name))
{
object obj = pi.GetValue(list[i], null);
tempList.Add(obj);
}
}
}
}
}
object[] array = tempList.ToArray();
result.LoadDataRow(array, true);
}
}
return result;
} }
#endregion #endregion

@ -1,4 +1,10 @@
namespace Tiobon.Core.Api.Controllers; using System.Collections;
using System.Data;
using System.Reflection;
using SqlSugar;
using Tiobon.Core.Common.DB.Dapper;
namespace Tiobon.Core.Api.Controllers;
/// <summary> /// <summary>
/// 学分记录(Controller) /// 学分记录(Controller)
@ -21,7 +27,7 @@ public class Ghre_CreditPointController : BaseController<IGhre_CreditPointServic
[HttpPost, Route("QueryTotal")] [HttpPost, Route("QueryTotal")]
public async Task<ServicePageResult<Ghre_CreditPointTotal>> QueryTotal([FromBody] QueryBody body) public async Task<ServicePageResult<Ghre_CreditPointTotal>> QueryTotal([FromBody] QueryBody body)
{ {
return await _service.QueryTotal(body); return await _service.QueryTotal(body, null);
} }
@ -41,4 +47,132 @@ public class Ghre_CreditPointController : BaseController<IGhre_CreditPointServic
return await _service.QueryDetail(body, staffId); return await _service.QueryDetail(body, staffId);
} }
#endregion #endregion
[HttpPost, Route("ExportExcel")]
public override async Task<ServiceResult<ExcelData>> ExportExcel([FromBody] QueryExport body)
{
QueryBody filter = new QueryBody();
filter.pageNum = 1;
filter.pageSize = 1000000;
filter.langId = body.langId;
var condition = "1=1";
if (body.exportSet.SelectRowKeys != null && body.exportSet.SelectRowKeys.Any())
condition += $" AND Id IN({string.Join(",", body.exportSet.SelectRowKeys)})";
var data = await _service.QueryTotal(filter, condition);
string sql = $@"SELECT *
FROM Ghrs_PageSettingQuery
WHERE IsEnable = 1
AND PageNo = '{body.menuName}'
AND (defaultHidden = 'false' OR defaultHidden is null)
ORDER BY SortNo ASC";
var columns = DbAccess.QueryList<QueryExportColumn>(sql);
var fieldDescs = new Dictionary<string, string>();
if (body.exportSet.ExFields.Any())
body.exportSet.ExFields.ForEach(x =>
{
if (columns.Any(o => o.field == x))
fieldDescs.Add(x, columns.FirstOrDefault(o => o.field == x)?.label);
});
else
fieldDescs = columns.ToDictionary(item => item.field, item => item.label);
var dt = ToDataTable1(data.result.DT_TableDataT1, fieldDescs, null);
// 获取所有列名
var dtColumns = dt.Columns;
var id = SnowFlakeSingle.instance.getID();
var physicsPath = $"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot";
var path = $"{$"{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}export{Path.DirectorySeparatorChar}{id}{Path.DirectorySeparatorChar}"}";
if (!Directory.Exists(physicsPath + path))
Directory.CreateDirectory(physicsPath + path);
path = path + body.exportSet.TitleName + ".xlsx";
NPOIHelper.ExportExcel(dt, body.exportSet.TitleName, "sheet1", physicsPath + path);
var result = new ExcelData();
result.filePath = path;
result.fileName = body.exportSet.TitleName + ".xlsx";
return ServiceResult<ExcelData>.OprateSuccess("导出成功", result);
}
public static DataTable ToDataTable1(List<Ghre_CreditPointTotal> list, Dictionary<string, string> fieldDescs = null, params string[] propertyName)
{
var (fields, colunms) = Sort(fieldDescs, null);
List<string> propertyNameList = new List<string>();
if (propertyName != null)
{
propertyNameList.AddRange(propertyName);
}
DataTable result = new DataTable();
if (list.Count > 0)
{
PropertyInfo[] propertys = list[0].GetType().GetProperties();
for (int i = 0; i < fields.Count; i++)
{
foreach (PropertyInfo pi in propertys)
{
if (propertyNameList.Count == 0)
{
//if (DBNull.Value.Equals(pi.PropertyType))
//{
// // pi.PropertyType = DateTime;
//}
Type colType = pi.PropertyType;
if (colType.IsGenericType && colType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
colType = colType.GetGenericArguments()[0];
}
if (fields[i] == pi.Name)
{
result.Columns.Add(colunms[i], colType);
}
//result.Columns.Add(pi.Name, pi.PropertyType);
}
else
{
if (propertyNameList.Contains(pi.Name))
{
if (fields[i] == pi.Name)
result.Columns.Add(fields[i], pi.PropertyType);
}
}
}
}
for (int i = 0; i < list.Count; i++)
{
ArrayList tempList = new ArrayList();
for (int j = 0; j < fields.Count; j++)
{
foreach (PropertyInfo pi in propertys)
{
if (fields[j] == pi.Name)
{
if (propertyNameList.Count == 0)
{
object obj = pi.GetValue(list[i], null);
tempList.Add(obj);
}
else
{
if (propertyNameList.Contains(pi.Name))
{
object obj = pi.GetValue(list[i], null);
tempList.Add(obj);
}
}
}
}
}
object[] array = tempList.ToArray();
result.LoadDataRow(array, true);
}
}
return result;
}
} }

@ -108,7 +108,7 @@ public class Ghre_ExamPaperController : BaseController<IGhre_ExamPaperServices,
[HttpPost, Route("ExportExcel/{status}")] [HttpPost, Route("ExportExcel/{status}")]
public async Task<ServiceResult<string>> ExportExcel([FromBody] QueryExport body, string status) public async Task<ServiceResult<ExcelData>> ExportExcel([FromBody] QueryExport body, string status)
{ {
return await _service.ExportExcel(body, status); return await _service.ExportExcel(body, status);
} }

@ -148,6 +148,14 @@
<param name="body"></param> <param name="body"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Tiobon.Core.Controllers.BaseController`5.Sort(System.Collections.Generic.Dictionary{System.String,System.String},System.Collections.Generic.List{System.String})">
<summary>
列名按照前端显示顺序导出
</summary>
<param name="columns"></param>
<param name="ExportFields"></param>
<returns></returns>
</member>
<member name="T:Tiobon.Core.Controllers.TiobonController"> <member name="T:Tiobon.Core.Controllers.TiobonController">
<summary> <summary>
博客管理 博客管理

@ -1,10 +1,7 @@
using System; using System.Data;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Text; using System.Text;
using System.Threading.Tasks;
using Tiobon.Core.Common.DB.Dapper.Const; using Tiobon.Core.Common.DB.Dapper.Const;
using Tiobon.Core.Common.DB.Dapper.DBManager; using Tiobon.Core.Common.DB.Dapper.DBManager;
using Tiobon.Core.Common.DB.Dapper.Enums; using Tiobon.Core.Common.DB.Dapper.Enums;

@ -195,7 +195,7 @@ public class NPOIHelper
style.BorderRight = BorderStyle.Thin; style.BorderRight = BorderStyle.Thin;
style.BorderTop = BorderStyle.Thin; style.BorderTop = BorderStyle.Thin;
// 字体 // 字体
var font1 = workbook.CreateFont(); var font1 = workbook.CreateFont();
font1.FontHeightInPoints = (short)10; font1.FontHeightInPoints = (short)10;
font1.FontName = "宋体"; font1.FontName = "宋体";
style.SetFont(font1); style.SetFont(font1);
@ -217,19 +217,28 @@ public class NPOIHelper
{ {
DateTime.TryParse(drValue, out dateV); DateTime.TryParse(drValue, out dateV);
//dateV = DateTimeHelper.ConvertToSecondString(dateV); //dateV = DateTimeHelper.ConvertToSecondString(dateV);
newCell.SetCellValue(dateV); newCell.SetCellValue(DateTimeHelper.ConvertToSecondString(dateV));
if (column.Caption == "renderDateTime") //if (column.Caption == "renderDateTime")
{ //{
newCell.CellStyle.DataFormat = format.GetFormat("yyyy-mm-dd hh:mm"); // newCell.CellStyle.DataFormat = format.GetFormat("yyyy-mm-dd hh:mm");
} //}
else if (column.Caption == "renderDate") //else if (column.Caption == "renderDate")
{ //{
newCell.CellStyle.DataFormat = format.GetFormat("yyyy-mm-dd"); // newCell.CellStyle.DataFormat = format.GetFormat("yyyy-mm-dd");
} //}
else //else
{ //{
newCell.CellStyle.DataFormat = format.GetFormat("yyyy-mm-dd hh:mm:ss"); //
} //}
//try
//{
// Convert.ToDateTime(drValue); newCell.CellStyle.DataFormat = format.GetFormat("yyyy-mm-dd hh:mm:ss");
//}
//catch (Exception)
//{
//}
} }
break; break;
case "System.Boolean"://布尔型 case "System.Boolean"://布尔型
@ -261,50 +270,52 @@ public class NPOIHelper
} }
#endregion #endregion
//获取当前列的宽度,然后对比本列的长度,取最大值
if (true)
for (int columnNum = 0; columnNum <= dtSource.Columns.Count; columnNum++)
{
sheet.AutoSizeColumn(columnNum);//先来个常规自适应
var columnWidth = sheet.GetColumnWidth(columnNum) / 256;
for (int rowNum = 1; rowNum <= sheet.LastRowNum; rowNum++) rowIndex++;
}
//获取当前列的宽度,然后对比本列的长度,取最大值
if (true)
for (int columnNum = 0; columnNum <= dtSource.Columns.Count; columnNum++)
{
sheet.AutoSizeColumn(columnNum);//先来个常规自适应
var columnWidth = sheet.GetColumnWidth(columnNum) / 256;
for (int rowNum = 1; rowNum <= sheet.LastRowNum; rowNum++)
{
IRow currentRow;
//当前行未被使用过
if (sheet.GetRow(rowNum) == null)
{ {
IRow currentRow; currentRow = sheet.CreateRow(rowNum);
//当前行未被使用过
if (sheet.GetRow(rowNum) == null)
{
currentRow = sheet.CreateRow(rowNum);
}
else
{
currentRow = sheet.GetRow(rowNum);
}
if (currentRow.GetCell(columnNum) != null)
{
ICell currentCell = currentRow.GetCell(columnNum);
int length = Encoding.Default.GetBytes(currentCell.ToString()).Length;
if (columnWidth < length)
{
columnWidth = length;
if (columnWidth > 30) columnWidth = 30;
}
}
} }
try else
{ {
sheet.SetColumnWidth(columnNum, columnWidth * 300); // 256 currentRow = sheet.GetRow(rowNum);
} }
catch (Exception e) if (currentRow.GetCell(columnNum) != null)
{ {
ICell currentCell = currentRow.GetCell(columnNum);
int length = Encoding.Default.GetBytes(currentCell.ToString()).Length;
if (columnWidth < length)
{
columnWidth = length;
if (columnWidth > 30) columnWidth = 30;
}
} }
}
try
{
sheet.SetColumnWidth(columnNum, columnWidth * 300); // 256
}
catch (Exception e)
{
} }
rowIndex++; }
}
using (MemoryStream ms = new MemoryStream()) using (MemoryStream ms = new MemoryStream())
{ {
workbook.Write(ms); workbook.Write(ms);

@ -152,7 +152,7 @@ namespace Tiobon.Core.IServices.BASE
Task<PageModel<TEntity>> QueryPage(Expression<Func<TEntity, bool>> whereExpression, int pageIndex = 1, int pageSize = 20, string orderByFields = null); Task<PageModel<TEntity>> QueryPage(Expression<Func<TEntity, bool>> whereExpression, int pageIndex = 1, int pageSize = 20, string orderByFields = null);
Task<ServicePageResult<TEntityDto>> QueryFilterPage([FromBody] QueryBody body); Task<ServicePageResult<TEntityDto>> QueryFilterPage([FromBody] QueryBody body);
Task<ServicePageResult<TEntityDto>> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true); Task<ServicePageResult<TEntityDto>> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true);
Task<ServiceResult<string>> ExportExcel([FromBody] QueryExport body); Task<ServiceResult<ExcelData>> ExportExcel([FromBody] QueryExport body);
Task<ServiceResult<ExcelData>> ImportExcel(IFormFile file); Task<ServiceResult<ExcelData>> ImportExcel(IFormFile file);

@ -10,7 +10,7 @@ namespace Tiobon.Core.IServices;
/// </summary> /// </summary>
public interface IGhre_CreditPointServices : IBaseServices<Ghre_CreditPoint, Ghre_CreditPointDto, InsertGhre_CreditPointInput, EditGhre_CreditPointInput> public interface IGhre_CreditPointServices : IBaseServices<Ghre_CreditPoint, Ghre_CreditPointDto, InsertGhre_CreditPointInput, EditGhre_CreditPointInput>
{ {
Task<ServicePageResult<Ghre_CreditPointTotal>> QueryTotal(QueryBody filter); Task<ServicePageResult<Ghre_CreditPointTotal>> QueryTotal(QueryBody filter, string condition);
Task<ServicePageResult<Ghre_CreditPointDetail>> QueryDetail(QueryBody filter, string staffId); Task<ServicePageResult<Ghre_CreditPointDetail>> QueryDetail(QueryBody filter, string staffId);
} }

@ -23,6 +23,6 @@ namespace Tiobon.Core.IServices
Task<ServiceResult<CommonSelect>> GetSelectAsync(long? linkId, string KeyWords); Task<ServiceResult<CommonSelect>> GetSelectAsync(long? linkId, string KeyWords);
Task<ServiceResult<string>> ExportExcel(QueryExport body, string status); Task<ServiceResult<ExcelData>> ExportExcel(QueryExport body, string status);
} }
} }

@ -781,7 +781,7 @@ public class BaseServices<TEntity, TEntityDto, TInsertDto, TEditDto> : IBaseServ
return new ServicePageResult<TEntityDto>(filter.pageNum, total, filter.pageSize, entitys); return new ServicePageResult<TEntityDto>(filter.pageNum, total, filter.pageSize, entitys);
} }
public async Task<ServiceResult<string>> ExportExcel(QueryExport body) public async Task<ServiceResult<ExcelData>> ExportExcel(QueryExport body)
{ {
QueryBody filter = new QueryBody(); QueryBody filter = new QueryBody();
filter.pageNum = 1; filter.pageNum = 1;
@ -810,8 +810,6 @@ public class BaseServices<TEntity, TEntityDto, TInsertDto, TEditDto> : IBaseServ
{ {
if (columns.Any(o => o.field == x)) if (columns.Any(o => o.field == x))
fieldDescs.Add(x, columns.FirstOrDefault(o => o.field == x)?.label); fieldDescs.Add(x, columns.FirstOrDefault(o => o.field == x)?.label);
}); });
else else
fieldDescs = columns.ToDictionary(item => item.field, item => item.label); fieldDescs = columns.ToDictionary(item => item.field, item => item.label);
@ -827,7 +825,11 @@ public class BaseServices<TEntity, TEntityDto, TInsertDto, TEditDto> : IBaseServ
path = path + body.exportSet.TitleName + ".xlsx"; path = path + body.exportSet.TitleName + ".xlsx";
NPOIHelper.ExportExcel(dt, null, "sheet1", physicsPath + path); NPOIHelper.ExportExcel(dt, null, "sheet1", physicsPath + path);
return ServiceResult<string>.OprateSuccess("导出成功", path);
var result = new ExcelData();
result.filePath = path;
result.fileName = body.exportSet.TitleName + ".xlsx";
return ServiceResult<ExcelData>.OprateSuccess("导出成功", result);
} }
/// <summary> /// <summary>
/// 列名按照前端显示顺序导出 /// 列名按照前端显示顺序导出

@ -33,6 +33,7 @@ public class Ghre_CertificateRuleServices : BaseServices<Ghre_CertificateRule, G
public override async Task<ServicePageResult<Ghre_CertificateRuleDto>> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) public override async Task<ServicePageResult<Ghre_CertificateRuleDto>> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true)
{ {
string condition1 = string.Empty;
if (filter.jsonParam != null) if (filter.jsonParam != null)
foreach (JProperty jProperty in filter.jsonParam.Properties()) foreach (JProperty jProperty in filter.jsonParam.Properties())
{ {
@ -45,16 +46,20 @@ public class Ghre_CertificateRuleServices : BaseServices<Ghre_CertificateRule, G
switch (jsonParam.operationKey) switch (jsonParam.operationKey)
{ {
case "Equal": case "Equal":
condition = $" ( CourseSceneId='{jsonParam.columnValue}' or CourseId='{jsonParam.columnValue}' )"; condition1 = $" ( CourseSceneId='{jsonParam.columnValue}' or CourseId='{jsonParam.columnValue}' )";
break; break;
case "NotEqual": case "NotEqual":
condition = $"( CourseSceneId!='{{jsonParam.columnValue}}' AND CourseId!='{{jsonParam.columnValue}}' )\";"; condition1 = $"( CourseSceneId!='{{jsonParam.columnValue}}' AND CourseId!='{{jsonParam.columnValue}}' )\";";
break; break;
default: default:
break; break;
} }
} }
} }
if (condition.IsNull())
condition = condition1;
else condition += " AND " + condition1;
var data = await base.QueryFilterPage(filter, condition, IsEnable); var data = await base.QueryFilterPage(filter, condition, IsEnable);
var courseIds = data.result.DT_TableDataT1.Where(x => x.CourseSceneId != null || x.CourseId != null).Select(x => x.CourseId ?? x.CourseSceneId).Distinct().ToList(); var courseIds = data.result.DT_TableDataT1.Where(x => x.CourseSceneId != null || x.CourseId != null).Select(x => x.CourseId ?? x.CourseSceneId).Distinct().ToList();

@ -9,6 +9,9 @@ using SqlSugar;
using Tiobon.Core.Common; using Tiobon.Core.Common;
using Tiobon.Core.Model; using Tiobon.Core.Model;
using Newtonsoft.Json; using Newtonsoft.Json;
using Microsoft.AspNetCore.Mvc;
using Tiobon.Core.Common.DB.Dapper;
using Tiobon.Core.Common.Helper;
namespace Tiobon.Core.Services; namespace Tiobon.Core.Services;
@ -25,7 +28,7 @@ public class Ghre_CreditPointServices : BaseServices<Ghre_CreditPoint, Ghre_Cred
base._caching = caching; base._caching = caching;
} }
public async Task<ServicePageResult<Ghre_CreditPointTotal>> QueryTotal(QueryBody filter) public async Task<ServicePageResult<Ghre_CreditPointTotal>> QueryTotal(QueryBody filter,string condition)
{ {
RefAsync<int> totalCount = 0; RefAsync<int> totalCount = 0;
string sql = @"SELECT * string sql = @"SELECT *
@ -128,7 +131,8 @@ public class Ghre_CreditPointServices : BaseServices<Ghre_CreditPoint, Ghre_Cred
//if (ids != null && ids.Any()) //if (ids != null && ids.Any())
// conditions += $" AND Id IN({string.Join(",", ids)})"; // conditions += $" AND Id IN({string.Join(",", ids)})";
if (!condition.IsNull())
conditions += " AND " + condition;
sql = string.Format(sql, conditions); sql = string.Format(sql, conditions);
if (filter.pageSize == 0) if (filter.pageSize == 0)
filter.pageSize = 10000; filter.pageSize = 10000;

@ -141,7 +141,7 @@ public class Ghre_ExamPaperServices : BaseServices<Ghre_ExamPaper, Ghre_ExamPape
return new ServicePageResult<Ghre_ExamPaperDto>(body.pageNum, data.result.DT_TablePageInfoT1.TotalCount, body.pageSize, data1); return new ServicePageResult<Ghre_ExamPaperDto>(body.pageNum, data.result.DT_TablePageInfoT1.TotalCount, body.pageSize, data1);
} }
public async Task<ServiceResult<string>> ExportExcel(QueryExport body, string status) public async Task<ServiceResult<ExcelData>> ExportExcel(QueryExport body, string status)
{ {
QueryBody filter = new QueryBody(); QueryBody filter = new QueryBody();
filter.pageNum = 1; filter.pageNum = 1;
@ -185,7 +185,10 @@ public class Ghre_ExamPaperServices : BaseServices<Ghre_ExamPaper, Ghre_ExamPape
path = path + body.exportSet.TitleName + ".xlsx"; path = path + body.exportSet.TitleName + ".xlsx";
NPOIHelper.ExportExcel(dt, null, "sheet1", physicsPath + path); NPOIHelper.ExportExcel(dt, null, "sheet1", physicsPath + path);
return ServiceResult<string>.OprateSuccess("导出成功", path); var result = new ExcelData();
result.filePath = path;
result.fileName = body.exportSet.TitleName + ".xlsx";
return ServiceResult<ExcelData>.OprateSuccess("导出成功", result);
} }
//public async Task<ServicePageResult<Ghre_ExamPaper>> QueryFilterPage1(QueryBody filter, string status = null) //public async Task<ServicePageResult<Ghre_ExamPaper>> QueryFilterPage1(QueryBody filter, string status = null)

@ -210,6 +210,9 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
if (filter.pageSize == 0) if (filter.pageSize == 0)
filter.pageSize = 10000; filter.pageSize = 10000;
sql += conditions; sql += conditions;
if (!string.IsNullOrWhiteSpace(condition))
sql += " AND " + condition;
var data = await Db.SqlQueryable<Ghre_QuestionDto>(sql) var data = await Db.SqlQueryable<Ghre_QuestionDto>(sql)
.OrderBy(filter.orderBy) .OrderBy(filter.orderBy)
.ToPageListAsync(filter.pageNum, filter.pageSize, totalCount); .ToPageListAsync(filter.pageNum, filter.pageSize, totalCount);

@ -25,7 +25,7 @@ public class Ghre_RequiredCourseServices : BaseServices<Ghre_RequiredCourse, Ghr
base._caching = caching; base._caching = caching;
} }
public override async Task<ServicePageResult<Ghre_RequiredCourseDto>> QueryFilterPage(QueryBody filter) public override async Task<ServicePageResult<Ghre_RequiredCourseDto>> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true)
{ {
if (string.IsNullOrWhiteSpace(filter.orderBy)) if (string.IsNullOrWhiteSpace(filter.orderBy))
filter.orderBy = "CreateTime1 DESC"; filter.orderBy = "CreateTime1 DESC";

@ -32,22 +32,25 @@ public class Ghre_SchoolServices : BaseServices<Ghre_School, Ghre_SchoolDto, Ins
_ghre_SchoolAttachmentServices = ghre_SchoolAttachmentServices; _ghre_SchoolAttachmentServices = ghre_SchoolAttachmentServices;
} }
public override async Task<ServicePageResult<Ghre_SchoolDto>> QueryFilterPage(QueryBody filter) public override async Task<ServicePageResult<Ghre_SchoolDto>> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true)
{ {
string schoolNo1 = string.Empty; string schoolNo1 = string.Empty;
foreach (JProperty jProperty in filter.jsonParam.Properties()) if (filter.jsonParam != null)
{ foreach (JProperty jProperty in filter.jsonParam.Properties())
var name = jProperty.Name;
var value = jProperty.Value.ToString();
if (name == "SchoolNo1")
{ {
var jsonParam = JsonConvert.DeserializeObject<JsonParam>(value); var name = jProperty.Name;
schoolNo1 = jsonParam?.columnValue?.ToString(); var value = jProperty.Value.ToString();
if (name == "SchoolNo1")
{
var jsonParam = JsonConvert.DeserializeObject<JsonParam>(value);
schoolNo1 = jsonParam?.columnValue?.ToString();
}
} }
}
var condition = string.Empty;
if (!string.IsNullOrWhiteSpace(schoolNo1)) if (!string.IsNullOrWhiteSpace(schoolNo1))
condition = $"(SchoolNo LIKE '%{schoolNo1}%' OR SchoolName LIKE '%{schoolNo1}%')"; if (condition.IsNull())
condition = $"(SchoolNo LIKE '%{schoolNo1}%' OR SchoolName LIKE '%{schoolNo1}%')";
else condition = $" AND (SchoolNo LIKE '%{schoolNo1}%' OR SchoolName LIKE '%{schoolNo1}%')";
var data = await base.QueryFilterPage(filter, condition); var data = await base.QueryFilterPage(filter, condition);
data.result.DT_TableDataT1.ForEach(x => data.result.DT_TableDataT1.ForEach(x =>
{ {

@ -148,6 +148,14 @@
<param name="body"></param> <param name="body"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Tiobon.Core.Controllers.BaseController`5.Sort(System.Collections.Generic.Dictionary{System.String,System.String},System.Collections.Generic.List{System.String})">
<summary>
列名按照前端显示顺序导出
</summary>
<param name="columns"></param>
<param name="ExportFields"></param>
<returns></returns>
</member>
<member name="T:Tiobon.Core.Controllers.TiobonController"> <member name="T:Tiobon.Core.Controllers.TiobonController">
<summary> <summary>
博客管理 博客管理

Loading…
Cancel
Save