数据模板导入、数据导出
This commit is contained in:
@@ -465,6 +465,18 @@
|
|||||||
用户管理
|
用户管理
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.Template">
|
||||||
|
<summary>
|
||||||
|
下载模板
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.Export">
|
||||||
|
<summary>
|
||||||
|
导出数据
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.PageList(Yi.Framework.Model.Models.UserEntity,Yi.Framework.Common.Models.PageParModel,System.Nullable{System.Int64})">
|
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.PageList(Yi.Framework.Model.Models.UserEntity,Yi.Framework.Common.Models.PageParModel,System.Nullable{System.Int64})">
|
||||||
<summary>
|
<summary>
|
||||||
动态条件分页查询
|
动态条件分页查询
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Yi.Framework.Common.Const;
|
||||||
|
using Yi.Framework.Common.Enum;
|
||||||
|
using Yi.Framework.Common.Helper;
|
||||||
using Yi.Framework.Common.Models;
|
using Yi.Framework.Common.Models;
|
||||||
using Yi.Framework.DTOModel;
|
using Yi.Framework.DTOModel;
|
||||||
using Yi.Framework.Interface;
|
using Yi.Framework.Interface;
|
||||||
@@ -25,11 +28,48 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
public class UserController : BaseSimpleRdController<UserEntity>
|
public class UserController : BaseSimpleRdController<UserEntity>
|
||||||
{
|
{
|
||||||
private IUserService _iUserService;
|
private IUserService _iUserService;
|
||||||
|
|
||||||
public UserController(ILogger<UserEntity> logger, IUserService iUserService) : base(logger, iUserService)
|
public UserController(ILogger<UserEntity> logger, IUserService iUserService) : base(logger, iUserService)
|
||||||
{
|
{
|
||||||
_iUserService = iUserService;
|
_iUserService = iUserService;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 下载模板
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public IActionResult Template()
|
||||||
|
{
|
||||||
|
List<UserEntity> users = new();
|
||||||
|
var fileName = nameof(UserEntity) + PathConst.DataTemplate;
|
||||||
|
var path = ExcelHelper.DownloadImportTemplate(users, fileName, Path.Combine(PathConst.wwwroot, PathEnum.Excel.ToString()));
|
||||||
|
var file = System.IO.File.OpenRead(path);
|
||||||
|
return File(file, "text/plain", $"{DateTime.Now.ToString("yyyyMMddHHmmssffff") + fileName }.xlsx");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 导出数据
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task<IActionResult> Export()
|
||||||
|
{
|
||||||
|
var users = await _iUserService._repository.GetListAsync();
|
||||||
|
var fileName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + nameof(UserEntity) + PathConst.DataExport;
|
||||||
|
var path = ExcelHelper.ExportExcel(users, fileName, Path.Combine(PathConst.wwwroot, PathEnum.Temp.ToString()));
|
||||||
|
var file = System.IO.File.OpenRead(path);
|
||||||
|
return File(file, "text/plain", $"{ fileName }.xlsx");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 动态条件分页查询
|
/// 动态条件分页查询
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -39,7 +79,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Permission("system:user:query")]
|
[Permission("system:user:query")]
|
||||||
public async Task<Result> PageList([FromQuery] UserEntity user, [FromQuery] PageParModel page,[FromQuery] long? deptId)
|
public async Task<Result> PageList([FromQuery] UserEntity user, [FromQuery] PageParModel page, [FromQuery] long? deptId)
|
||||||
{
|
{
|
||||||
return Result.Success().SetData(await _iUserService.SelctPageList(user, page, deptId));
|
return Result.Success().SetData(await _iUserService.SelctPageList(user, page, deptId));
|
||||||
}
|
}
|
||||||
@@ -93,7 +133,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
[Permission("system:user:edit")]
|
[Permission("system:user:edit")]
|
||||||
public async Task<Result> Update(UserInfoDto userDto)
|
public async Task<Result> Update(UserInfoDto userDto)
|
||||||
{
|
{
|
||||||
if (await _iUserService._repository.IsAnyAsync(u => userDto.User.UserName.Equals(u.UserName)&&!userDto.User.Id.Equals(u.Id)))
|
if (await _iUserService._repository.IsAnyAsync(u => userDto.User.UserName.Equals(u.UserName) && !userDto.User.Id.Equals(u.Id)))
|
||||||
{
|
{
|
||||||
return Result.Error("用户名已存在,修改失败!");
|
return Result.Error("用户名已存在,修改失败!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Folder Include="wwwroot\excel\" />
|
||||||
<Folder Include="wwwroot\file\" />
|
<Folder Include="wwwroot\file\" />
|
||||||
<Folder Include="wwwroot\image\" />
|
<Folder Include="wwwroot\image\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,14 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Yi.Framework.Common.Const
|
|
||||||
{
|
|
||||||
public class FileConst
|
|
||||||
{
|
|
||||||
public const string Image = "Image";
|
|
||||||
public const string File = "File";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
15
Yi.Framework.Net6/Yi.Framework.Common/Const/PathConst.cs
Normal file
15
Yi.Framework.Net6/Yi.Framework.Common/Const/PathConst.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Common.Const
|
||||||
|
{
|
||||||
|
public class PathConst
|
||||||
|
{
|
||||||
|
public const string wwwroot = "wwwroot";
|
||||||
|
public const string DataTemplate = "_DataTemplate";
|
||||||
|
public const string DataExport = "_DataExport";
|
||||||
|
}
|
||||||
|
}
|
||||||
16
Yi.Framework.Net6/Yi.Framework.Common/Enum/PathEnum.cs
Normal file
16
Yi.Framework.Net6/Yi.Framework.Common/Enum/PathEnum.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Common.Enum
|
||||||
|
{
|
||||||
|
public enum PathEnum
|
||||||
|
{
|
||||||
|
Excel,
|
||||||
|
File,
|
||||||
|
Image,
|
||||||
|
Temp
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,11 @@ using System.Reflection;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 此处来源于ZrAdmin
|
||||||
|
/// </summary>
|
||||||
namespace Yi.Framework.Common.Helper
|
namespace Yi.Framework.Common.Helper
|
||||||
{
|
{
|
||||||
public class ExcelHelper
|
public class ExcelHelper
|
||||||
@@ -18,7 +23,7 @@ namespace Yi.Framework.Common.Helper
|
|||||||
/// <param name="list"></param>
|
/// <param name="list"></param>
|
||||||
/// <param name="sheetName"></param>
|
/// <param name="sheetName"></param>
|
||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
public static string ExportExcel<T>(List<T> list, string sheetName, string fileName,string path)
|
public static string ExportExcel<T>(List<T> list, string fileName,string path,string sheetName= "default")
|
||||||
{
|
{
|
||||||
string sFileName = $"{fileName}.xlsx";
|
string sFileName = $"{fileName}.xlsx";
|
||||||
string newFileName = Path.Combine(path, sFileName);
|
string newFileName = Path.Combine(path, sFileName);
|
||||||
@@ -47,16 +52,25 @@ namespace Yi.Framework.Common.Helper
|
|||||||
/// <param name="stream"></param>
|
/// <param name="stream"></param>
|
||||||
/// <param name="fileName">下载文件名</param>
|
/// <param name="fileName">下载文件名</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
protected string DownloadImportTemplate<T>(List<T> list, Stream stream, string fileName,string path)
|
public static string DownloadImportTemplate<T>(List<T> list, string fileName,string path)
|
||||||
{
|
{
|
||||||
string sFileName = $"{fileName}.xlsx";
|
string sFileName = $"{fileName}.xlsx";
|
||||||
string newFileName = Path.Combine(path, sFileName);
|
string newFileName = Path.Combine(path, sFileName);
|
||||||
|
|
||||||
|
//如果文件存在,直接返回即可
|
||||||
|
if (File.Exists(newFileName))
|
||||||
|
{
|
||||||
|
return newFileName;
|
||||||
|
}
|
||||||
//调试模式需要加上
|
//调试模式需要加上
|
||||||
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
|
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
|
||||||
if (!Directory.Exists(newFileName))
|
if (!Directory.Exists(newFileName))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(newFileName)!);
|
Directory.CreateDirectory(Path.GetDirectoryName(newFileName)!);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Stream stream = new FileStream(newFileName, FileMode.OpenOrCreate);
|
||||||
using (ExcelPackage package = new(new FileInfo(newFileName)))
|
using (ExcelPackage package = new(new FileInfo(newFileName)))
|
||||||
{
|
{
|
||||||
// 添加worksheet
|
// 添加worksheet
|
||||||
@@ -67,8 +81,9 @@ namespace Yi.Framework.Common.Helper
|
|||||||
worksheet.Cells.LoadFromCollection(list, true, OfficeOpenXml.Table.TableStyles.Light13);
|
worksheet.Cells.LoadFromCollection(list, true, OfficeOpenXml.Table.TableStyles.Light13);
|
||||||
package.SaveAs(stream);
|
package.SaveAs(stream);
|
||||||
}
|
}
|
||||||
|
stream.Dispose();
|
||||||
return sFileName;
|
|
||||||
|
return newFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import directive from './directive' // directive
|
|||||||
|
|
||||||
// 注册指令
|
// 注册指令
|
||||||
import plugins from './plugins' // plugins
|
import plugins from './plugins' // plugins
|
||||||
import { download } from '@/utils/request'
|
import { download } from '@/utils/ruoyi.js'
|
||||||
|
|
||||||
// svg图标
|
// svg图标
|
||||||
import 'virtual:svg-icons-register'
|
import 'virtual:svg-icons-register'
|
||||||
|
|||||||
@@ -249,4 +249,11 @@ export async function blobValidate(data) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 通用下载方法
|
||||||
|
export function download(url) {
|
||||||
|
// window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true;
|
||||||
|
// window.open(baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true)
|
||||||
|
window.open(import.meta.env.VITE_APP_BASE_API + url)
|
||||||
}
|
}
|
||||||
@@ -370,9 +370,7 @@ function handleDelete(row) {
|
|||||||
};
|
};
|
||||||
/** 导出按钮操作 */
|
/** 导出按钮操作 */
|
||||||
function handleExport() {
|
function handleExport() {
|
||||||
proxy.download("system/user/export", {
|
proxy.download("user/export");
|
||||||
...queryParams.value,
|
|
||||||
}, `user_${new Date().getTime()}.xlsx`);
|
|
||||||
};
|
};
|
||||||
/** 用户状态修改 */
|
/** 用户状态修改 */
|
||||||
function handleStatusChange(row) {
|
function handleStatusChange(row) {
|
||||||
@@ -430,8 +428,7 @@ function handleImport() {
|
|||||||
};
|
};
|
||||||
/** 下载模板操作 */
|
/** 下载模板操作 */
|
||||||
function importTemplate() {
|
function importTemplate() {
|
||||||
proxy.download("system/user/importTemplate", {
|
proxy.download("user/template");
|
||||||
}, `user_template_${new Date().getTime()}.xlsx`);
|
|
||||||
};
|
};
|
||||||
/**文件上传中处理 */
|
/**文件上传中处理 */
|
||||||
const handleFileUploadProgress = (event, file, fileList) => {
|
const handleFileUploadProgress = (event, file, fileList) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user