Merge branch 'master' into net6.0
This commit is contained in:
commit
030db5b971
@ -1,9 +1,4 @@
|
|||||||
using System;
|
using System.ComponentModel;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Infrastructure.Enums
|
namespace Infrastructure.Enums
|
||||||
{
|
{
|
||||||
@ -30,5 +25,10 @@ namespace Infrastructure.Enums
|
|||||||
[Description("腾讯云")]
|
[Description("腾讯云")]
|
||||||
TENCENT = 3,
|
TENCENT = 3,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 七牛
|
||||||
|
/// </summary>
|
||||||
|
[Description("七牛云")]
|
||||||
|
QINIU = 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
* 后端采用Net5/Net6、Sqlsugar、MySQL。
|
* 后端采用Net5/Net6、Sqlsugar、MySQL。
|
||||||
* 权限认证使用Jwt,支持多终端认证系统。
|
* 权限认证使用Jwt,支持多终端认证系统。
|
||||||
* 支持加载动态权限菜单,多方式轻松权限控制
|
* 支持加载动态权限菜单,多方式轻松权限控制
|
||||||
|
* 提供了技术栈(Ant Design Vue)版[Ant Design Vue](https://gitee.com/billzh/mc-dull.git)
|
||||||
* 七牛云通用云产品优惠券:[点我进入](https://s.qiniu.com/FzEfay)。
|
* 七牛云通用云产品优惠券:[点我进入](https://s.qiniu.com/FzEfay)。
|
||||||
* 腾讯云秒杀场:[点我进入](https://curl.qcloud.com/4yEoRquq)。
|
* 腾讯云秒杀场:[点我进入](https://curl.qcloud.com/4yEoRquq)。
|
||||||
* 腾讯云优惠券:[点我领取](https://curl.qcloud.com/5J4nag8D)。
|
* 腾讯云优惠券:[点我领取](https://curl.qcloud.com/5J4nag8D)。
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using Infrastructure.Attribute;
|
using Infrastructure.Attribute;
|
||||||
|
using Infrastructure.Enums;
|
||||||
using Infrastructure.Extensions;
|
using Infrastructure.Extensions;
|
||||||
using Infrastructure.Model;
|
using Infrastructure.Model;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
@ -91,26 +92,60 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
/// <param name="formFile"></param>
|
/// <param name="formFile"></param>
|
||||||
/// <param name="fileDir">存储目录</param>
|
/// <param name="fileDir">存储目录</param>
|
||||||
/// <param name="fileName">自定义文件名</param>
|
/// <param name="fileName">自定义文件名</param>
|
||||||
/// <param name="uploadType">上传类型 1、发送邮件</param>
|
/// <param name="storeType">上传类型1、保存到本地 2、保存到阿里云</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost()]
|
[HttpPost()]
|
||||||
[Verify]
|
[Verify]
|
||||||
[ActionPermissionFilter(Permission = "common")]
|
[ActionPermissionFilter(Permission = "common")]
|
||||||
public async Task<IActionResult> UploadFile([FromForm(Name = "file")] IFormFile formFile, string fileName = "", string fileDir = "uploads", int uploadType = 0)
|
public async Task<IActionResult> UploadFile([FromForm(Name = "file")] IFormFile formFile, string fileName = "", string fileDir = "uploads", StoreType storeType = StoreType.LOCAL)
|
||||||
{
|
{
|
||||||
if (formFile == null) throw new CustomException(ResultCode.PARAM_ERROR, "上传文件不能为空");
|
if (formFile == null) throw new CustomException(ResultCode.PARAM_ERROR, "上传文件不能为空");
|
||||||
|
SysFile file = new();
|
||||||
|
string fileExt = Path.GetExtension(formFile.FileName);//文件后缀
|
||||||
|
double fileSize = Math.Round(formFile.Length / 1024.0, 2);//文件大小KB
|
||||||
|
string[] NotAllowedFileExtensions = new string[] { ".bat", ".exe", ".jar", ".js" };
|
||||||
|
int MaxContentLength = 15;
|
||||||
|
if (NotAllowedFileExtensions.Contains(fileExt))
|
||||||
|
{
|
||||||
|
return ToResponse(ResultCode.CUSTOM_ERROR, "上传失败,未经允许上传类型");
|
||||||
|
}
|
||||||
|
switch (storeType)
|
||||||
|
{
|
||||||
|
case StoreType.LOCAL:
|
||||||
|
file = await SysFileService.SaveFileToLocal(WebHostEnvironment.WebRootPath, fileName, fileDir, HttpContext.GetName(), formFile);
|
||||||
|
|
||||||
SysFile file = await SysFileService.SaveFileToLocal(WebHostEnvironment.WebRootPath, fileName, fileDir, HttpContext.GetName(), formFile);
|
break;
|
||||||
|
case StoreType.ALIYUN:
|
||||||
|
if ((fileSize / 1024) > MaxContentLength)
|
||||||
|
{
|
||||||
|
return ToResponse(ResultCode.CUSTOM_ERROR, "上传文件过大,不能超过 " + MaxContentLength + " MB");
|
||||||
|
}
|
||||||
|
file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", fileDir, HttpContext.GetName())
|
||||||
|
{
|
||||||
|
StoreType = (int)StoreType.ALIYUN,
|
||||||
|
FileType = formFile.ContentType
|
||||||
|
};
|
||||||
|
file = await SysFileService.SaveFileToAliyun(file, formFile);
|
||||||
|
|
||||||
|
if (file.Id <= 0) { return ToResponse(ApiResult.Error("阿里云连接失败")); }
|
||||||
|
break;
|
||||||
|
case StoreType.TENCENT:
|
||||||
|
break;
|
||||||
|
case StoreType.QINIU:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
return SUCCESS(new
|
return SUCCESS(new
|
||||||
{
|
{
|
||||||
url = uploadType == 1 ? file.FileUrl : file.AccessUrl,
|
url = file.AccessUrl,
|
||||||
fileName,
|
fileName,
|
||||||
fileId = file.Id.ToString()
|
fileId = file.Id.ToString()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 存储文件到阿里云
|
/// 存储文件到阿里云(已弃用)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="formFile"></param>
|
/// <param name="formFile"></param>
|
||||||
/// <param name="fileName">自定义文件名</param>
|
/// <param name="fileName">自定义文件名</param>
|
||||||
@ -134,7 +169,7 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
{
|
{
|
||||||
return ToResponse(ResultCode.CUSTOM_ERROR, "上传文件过大,不能超过 " + MaxContentLength + " MB");
|
return ToResponse(ResultCode.CUSTOM_ERROR, "上传文件过大,不能超过 " + MaxContentLength + " MB");
|
||||||
}
|
}
|
||||||
SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", fileDir, "", HttpContext.GetName())
|
SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", fileDir, HttpContext.GetName())
|
||||||
{
|
{
|
||||||
StoreType = (int)Infrastructure.Enums.StoreType.ALIYUN,
|
StoreType = (int)Infrastructure.Enums.StoreType.ALIYUN,
|
||||||
FileType = formFile.ContentType
|
FileType = formFile.ContentType
|
||||||
|
|||||||
@ -86,8 +86,8 @@ namespace ZR.Admin.WebApi.Controllers.System
|
|||||||
List<string> permissions = permissionService.GetMenuPermission(user);
|
List<string> permissions = permissionService.GetMenuPermission(user);
|
||||||
|
|
||||||
LoginUser loginUser = new(user, roles, permissions);
|
LoginUser loginUser = new(user, roles, permissions);
|
||||||
CacheHelper.SetCache(GlobalConstant.UserPermKEY + user.UserId, loginUser);
|
CacheHelper.SetCache(GlobalConstant.UserPermKEY + user.UserId, permissions);
|
||||||
return SUCCESS(JwtUtil.GenerateJwtToken(HttpContext.AddClaims(loginUser), jwtSettings.JwtSettings));
|
return SUCCESS(JwtUtil.GenerateJwtToken(JwtUtil.AddClaims(loginUser), jwtSettings.JwtSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -103,11 +103,11 @@ namespace ZR.Admin.WebApi.Controllers.System
|
|||||||
// //注销登录的用户,相当于ASP.NET中的FormsAuthentication.SignOut
|
// //注销登录的用户,相当于ASP.NET中的FormsAuthentication.SignOut
|
||||||
// await HttpContext.SignOutAsync();
|
// await HttpContext.SignOutAsync();
|
||||||
//}).Wait();
|
//}).Wait();
|
||||||
var id = HttpContext.GetUId();
|
var userid = HttpContext.GetUId();
|
||||||
var name = HttpContext.GetName();
|
var name = HttpContext.GetName();
|
||||||
|
|
||||||
CacheHelper.Remove(GlobalConstant.UserPermKEY + id);
|
CacheHelper.Remove(GlobalConstant.UserPermKEY + userid);
|
||||||
return SUCCESS(new { name , id});
|
return SUCCESS(new { name , id = userid });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using ZR.Admin.WebApi.Extensions;
|
||||||
using ZR.Admin.WebApi.Filters;
|
using ZR.Admin.WebApi.Filters;
|
||||||
using ZR.Common;
|
using ZR.Common;
|
||||||
using ZR.Model;
|
using ZR.Model;
|
||||||
@ -94,7 +95,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
|||||||
return ToResponse(ApiResult.Error($"新增用户 '{user.UserName}'失败,登录账号已存在"));
|
return ToResponse(ApiResult.Error($"新增用户 '{user.UserName}'失败,登录账号已存在"));
|
||||||
}
|
}
|
||||||
|
|
||||||
user.Create_by = User.Identity.Name;
|
user.Create_by = HttpContext.GetName();
|
||||||
user.Password = NETCore.Encrypt.EncryptProvider.Md5(user.Password);
|
user.Password = NETCore.Encrypt.EncryptProvider.Md5(user.Password);
|
||||||
|
|
||||||
return ToResponse(UserService.InsertUser(user));
|
return ToResponse(UserService.InsertUser(user));
|
||||||
@ -112,7 +113,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
|||||||
{
|
{
|
||||||
if (user == null || user.UserId <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); }
|
if (user == null || user.UserId <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); }
|
||||||
|
|
||||||
user.Update_by = User.Identity.Name;
|
user.Update_by = HttpContext.GetName();
|
||||||
int upResult = UserService.UpdateUser(user);
|
int upResult = UserService.UpdateUser(user);
|
||||||
|
|
||||||
return ToResponse(upResult);
|
return ToResponse(upResult);
|
||||||
|
|||||||
@ -130,27 +130,6 @@ namespace ZR.Admin.WebApi.Extensions
|
|||||||
return context != null ? context.Request.Path.Value : "";
|
return context != null ? context.Request.Path.Value : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///组装Claims
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context"></param>
|
|
||||||
/// <param name="user"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static List<Claim> AddClaims(this HttpContext context, LoginUser user)
|
|
||||||
{
|
|
||||||
//1、创建Cookie保存用户信息,使用claim
|
|
||||||
var claims = new List<Claim>()
|
|
||||||
{
|
|
||||||
new Claim(ClaimTypes.PrimarySid, user.UserId.ToString()),
|
|
||||||
new Claim(ClaimTypes.Name, user.UserName),
|
|
||||||
new Claim(ClaimTypes.UserData, JsonConvert.SerializeObject(user))
|
|
||||||
};
|
|
||||||
|
|
||||||
//写入Cookie
|
|
||||||
//WhiteCookie(context, claims);
|
|
||||||
return claims;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void WhiteCookie(HttpContext context, List<Claim> claims)
|
private static void WhiteCookie(HttpContext context, List<Claim> claims)
|
||||||
{
|
{
|
||||||
//2.创建声明主题 指定认证方式 这里使用cookie
|
//2.创建声明主题 指定认证方式 这里使用cookie
|
||||||
|
|||||||
@ -33,11 +33,12 @@ namespace ZR.Admin.WebApi.Extensions
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseAddTaskSchedulers(this IApplicationBuilder app)
|
public static IApplicationBuilder UseAddTaskSchedulers(this IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
var _tasksQzService = (ISysTasksQzService)App.GetRequiredService(typeof(ISysTasksQzService));
|
//var _tasksQzService = (ISysTasksQzService)App.GetRequiredService(typeof(ISysTasksQzService));
|
||||||
|
|
||||||
ITaskSchedulerServer _schedulerServer = App.GetRequiredService<ITaskSchedulerServer>();
|
ITaskSchedulerServer _schedulerServer = App.GetRequiredService<ITaskSchedulerServer>();
|
||||||
|
|
||||||
var tasks = _tasksQzService.GetList(m => m.IsStart);
|
//var tasks = _tasksQzService.GetList(m => m.IsStart);
|
||||||
|
var tasks = SqlSugar.IOC.DbScoped.SugarScope.Queryable<Model.System.SysTasksQz>().Where(m => m.IsStart).ToList();
|
||||||
|
|
||||||
//程序启动后注册所有定时任务
|
//程序启动后注册所有定时任务
|
||||||
foreach (var task in tasks)
|
foreach (var task in tasks)
|
||||||
|
|||||||
@ -6,6 +6,7 @@ using System.IdentityModel.Tokens.Jwt;
|
|||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using ZR.Admin.WebApi.Extensions;
|
using ZR.Admin.WebApi.Extensions;
|
||||||
|
using ZR.Common;
|
||||||
using ZR.Model.System;
|
using ZR.Model.System;
|
||||||
|
|
||||||
namespace ZR.Admin.WebApi.Framework
|
namespace ZR.Admin.WebApi.Framework
|
||||||
@ -124,9 +125,15 @@ namespace ZR.Admin.WebApi.Framework
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var userData = jwtToken.FirstOrDefault(x => x.Type == ClaimTypes.UserData);
|
var userData = jwtToken.FirstOrDefault(x => x.Type == ClaimTypes.UserData).Value;
|
||||||
|
var loginUser = JsonConvert.DeserializeObject<LoginUser>(userData);
|
||||||
LoginUser loginUser = JsonConvert.DeserializeObject<LoginUser>(value: userData?.Value);
|
var permissions = (List<string>)CacheHelper.GetCache(GlobalConstant.UserPermKEY + loginUser?.UserId);
|
||||||
|
if (loginUser?.UserName == "admin")
|
||||||
|
{
|
||||||
|
permissions = new List<string>() { GlobalConstant.AdminPerm };
|
||||||
|
}
|
||||||
|
if (permissions == null) return null;
|
||||||
|
loginUser.Permissions = permissions;
|
||||||
return loginUser;
|
return loginUser;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -135,5 +142,27 @@ namespace ZR.Admin.WebApi.Framework
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///组装Claims
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static List<Claim> AddClaims(LoginUser user)
|
||||||
|
{
|
||||||
|
if (user?.Permissions.Count > 50)
|
||||||
|
{
|
||||||
|
user.Permissions = new List<string>();
|
||||||
|
}
|
||||||
|
var claims = new List<Claim>()
|
||||||
|
{
|
||||||
|
new Claim(ClaimTypes.PrimarySid, user.UserId.ToString()),
|
||||||
|
new Claim(ClaimTypes.Name, user.UserName),
|
||||||
|
new Claim(ClaimTypes.UserData, JsonConvert.SerializeObject(user))
|
||||||
|
};
|
||||||
|
|
||||||
|
return claims;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -89,7 +89,7 @@ namespace ZR.CodeGenerator
|
|||||||
//图片
|
//图片
|
||||||
sb.AppendLine(" <el-col :lg=\"24\">");
|
sb.AppendLine(" <el-col :lg=\"24\">");
|
||||||
sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
|
sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
|
||||||
sb.AppendLine($@" <UploadImage v-model=""form.{columnName}"" column=""{columnName}"" @input=""handleUploadSuccess"" />");
|
sb.AppendLine($@" <UploadImage v-model=""form.{columnName}"" :data=""{{ 'storeType' : 1}}"" column=""{columnName}"" @input=""handleUploadSuccess"" />");
|
||||||
sb.AppendLine(" </el-form-item>");
|
sb.AppendLine(" </el-form-item>");
|
||||||
sb.AppendLine(" </el-col>");
|
sb.AppendLine(" </el-col>");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,5 +43,25 @@ namespace ZR.Common
|
|||||||
return System.Net.HttpStatusCode.BadRequest;
|
return System.Net.HttpStatusCode.BadRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除资源
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dirPath"></param>
|
||||||
|
/// <param name="bucketName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static System.Net.HttpStatusCode DeleteFile(string dirPath, string bucketName = "")
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(bucketName)) { bucketName = bucketName1; }
|
||||||
|
try
|
||||||
|
{
|
||||||
|
OssClient client = new(endpoint, accessKeyId, accessKeySecret);
|
||||||
|
DeleteObjectResult putObjectResult = client.DeleteObject(bucketName, dirPath);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
|
return System.Net.HttpStatusCode.BadRequest;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@ namespace ZR.Model.System
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 权限集合
|
/// 权限集合
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> Permissions { get; set; }
|
public List<string> Permissions { get; set; } = new List<string>();
|
||||||
public LoginUser()
|
public LoginUser()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,14 +72,13 @@ namespace ZR.Model.System
|
|||||||
public string AccessUrl { get; set; }
|
public string AccessUrl { get; set; }
|
||||||
|
|
||||||
public SysFile() { }
|
public SysFile() { }
|
||||||
public SysFile(string originFileName, string fileName, string ext, string fileSize, string storePath, string accessUrl,string create_by)
|
public SysFile(string originFileName, string fileName, string ext, string fileSize, string storePath, string create_by)
|
||||||
{
|
{
|
||||||
StorePath = storePath;
|
StorePath = storePath;
|
||||||
RealName = originFileName;
|
RealName = originFileName;
|
||||||
FileName = fileName;
|
FileName = fileName;
|
||||||
FileExt = ext;
|
FileExt = ext;
|
||||||
FileSize = fileSize;
|
FileSize = fileSize;
|
||||||
AccessUrl = accessUrl;
|
|
||||||
Create_by = create_by;
|
Create_by = create_by;
|
||||||
Create_time = DateTime.Now;
|
Create_time = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using ZR.Model.System;
|
using System.Threading.Tasks;
|
||||||
|
using ZR.Model.System;
|
||||||
using ZR.Repository;
|
using ZR.Repository;
|
||||||
|
|
||||||
namespace ZR.Service.System.IService
|
namespace ZR.Service.System.IService
|
||||||
@ -10,6 +11,6 @@ namespace ZR.Service.System.IService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
//public int AddTaskLog(string jobId);
|
//public int AddTaskLog(string jobId);
|
||||||
SysTasksLog AddTaskLog(string jobId, SysTasksLog tasksLog);
|
Task<SysTasksLog> AddTaskLog(string jobId, SysTasksLog tasksLog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,14 +51,15 @@ namespace ZR.Service.System
|
|||||||
|
|
||||||
using (var stream = new FileStream(finalFilePath, FileMode.Create))
|
using (var stream = new FileStream(finalFilePath, FileMode.Create))
|
||||||
{
|
{
|
||||||
await formFile.CopyToAsync(stream);
|
await formFile.CopyToAsync(stream);//await 不能少
|
||||||
}
|
}
|
||||||
string accessPath = string.Concat(OptionsSetting.Upload.UploadUrl, "/", filePath.Replace("\\", "/"), "/", fileName);
|
string accessPath = string.Concat(OptionsSetting.Upload.UploadUrl, "/", filePath.Replace("\\", "/"), "/", fileName);
|
||||||
SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", filePath, accessPath, userName)
|
SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", filePath, userName)
|
||||||
{
|
{
|
||||||
StoreType = (int)Infrastructure.Enums.StoreType.LOCAL,
|
StoreType = (int)Infrastructure.Enums.StoreType.LOCAL,
|
||||||
FileType = formFile.ContentType,
|
FileType = formFile.ContentType,
|
||||||
FileUrl = finalFilePath
|
FileUrl = finalFilePath,
|
||||||
|
AccessUrl = accessPath
|
||||||
};
|
};
|
||||||
file.Id = await InsertFile(file);
|
file.Id = await InsertFile(file);
|
||||||
return file;
|
return file;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using Infrastructure.Attribute;
|
using Infrastructure.Attribute;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using ZR.Model;
|
using ZR.Model;
|
||||||
using ZR.Model.System;
|
using ZR.Model.System;
|
||||||
using ZR.Repository;
|
using ZR.Repository;
|
||||||
@ -12,7 +13,7 @@ namespace ZR.Service.System
|
|||||||
/// 任务日志
|
/// 任务日志
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AppService(ServiceLifetime = LifeTime.Transient, ServiceType = typeof(ISysTasksLogService))]
|
[AppService(ServiceLifetime = LifeTime.Transient, ServiceType = typeof(ISysTasksLogService))]
|
||||||
public class SysTasksLogService : BaseRepository<SysTasksLog>, ISysTasksLogService
|
public class SysTasksLogService : BaseService<SysTasksLog>, ISysTasksLogService
|
||||||
{
|
{
|
||||||
private ISysTasksQzService _tasksQzService;
|
private ISysTasksQzService _tasksQzService;
|
||||||
public SysTasksLogService(ISysTasksQzService tasksQzService)
|
public SysTasksLogService(ISysTasksQzService tasksQzService)
|
||||||
@ -20,10 +21,10 @@ namespace ZR.Service.System
|
|||||||
_tasksQzService = tasksQzService;
|
_tasksQzService = tasksQzService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SysTasksLog AddTaskLog(string jobId, SysTasksLog logModel)
|
public async Task<SysTasksLog> AddTaskLog(string jobId, SysTasksLog logModel)
|
||||||
{
|
{
|
||||||
//获取任务信息
|
//获取任务信息
|
||||||
var model = _tasksQzService.GetId(jobId);
|
var model = await _tasksQzService.GetSingleAsync(f => f.ID == jobId);
|
||||||
|
|
||||||
if (model != null)
|
if (model != null)
|
||||||
{
|
{
|
||||||
@ -33,7 +34,7 @@ namespace ZR.Service.System
|
|||||||
logModel.CreateTime = DateTime.Now;
|
logModel.CreateTime = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
Add(logModel);
|
await InsertAsync(logModel);
|
||||||
return logModel;
|
return logModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -56,7 +56,7 @@ namespace ZR.Tasks
|
|||||||
JobMessage = logMsg
|
JobMessage = logMsg
|
||||||
};
|
};
|
||||||
|
|
||||||
RecordTaskLog(context, logModel);
|
await RecordTaskLog(context, logModel);
|
||||||
return logModel;
|
return logModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ namespace ZR.Tasks
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
/// <param name="logModel"></param>
|
/// <param name="logModel"></param>
|
||||||
protected void RecordTaskLog(IJobExecutionContext context, SysTasksLog logModel)
|
protected async Task RecordTaskLog(IJobExecutionContext context, SysTasksLog logModel)
|
||||||
{
|
{
|
||||||
var tasksLogService = (ISysTasksLogService)App.GetRequiredService(typeof(ISysTasksLogService));
|
var tasksLogService = (ISysTasksLogService)App.GetRequiredService(typeof(ISysTasksLogService));
|
||||||
var taskQzService = (ISysTasksQzService)App.GetRequiredService(typeof(ISysTasksQzService));
|
var taskQzService = (ISysTasksQzService)App.GetRequiredService(typeof(ISysTasksQzService));
|
||||||
@ -74,15 +74,15 @@ namespace ZR.Tasks
|
|||||||
IJobDetail job = context.JobDetail;
|
IJobDetail job = context.JobDetail;
|
||||||
|
|
||||||
logModel.InvokeTarget = job.JobType.FullName;
|
logModel.InvokeTarget = job.JobType.FullName;
|
||||||
logModel = tasksLogService.AddTaskLog(job.Key.Name, logModel);
|
logModel = await tasksLogService.AddTaskLog(job.Key.Name, logModel);
|
||||||
//成功后执行次数+1
|
//成功后执行次数+1
|
||||||
if (logModel.Status == "0")
|
if (logModel.Status == "0")
|
||||||
{
|
{
|
||||||
taskQzService.Update(f => f.ID == job.Key.Name, f => new SysTasksQz()
|
await taskQzService.UpdateAsync(f => new SysTasksQz()
|
||||||
{
|
{
|
||||||
RunTimes = f.RunTimes + 1,
|
RunTimes = f.RunTimes + 1,
|
||||||
LastRunTime = DateTime.Now
|
LastRunTime = DateTime.Now
|
||||||
});
|
}, f => f.ID == job.Key.Name);
|
||||||
}
|
}
|
||||||
logger.Info($"执行任务【{job.Key.Name}|{logModel.JobName}】结果={logModel.JobMessage}");
|
logger.Info($"执行任务【{job.Key.Name}|{logModel.JobName}】结果={logModel.JobMessage}");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -123,6 +123,10 @@ namespace ZR.Tasks
|
|||||||
{
|
{
|
||||||
return ApiResult.Error(500, $"该计划任务已经在执行:【{tasksQz.Name}】,请勿重复添加!");
|
return ApiResult.Error(500, $"该计划任务已经在执行:【{tasksQz.Name}】,请勿重复添加!");
|
||||||
}
|
}
|
||||||
|
if (tasksQz?.EndTime <= DateTime.Now)
|
||||||
|
{
|
||||||
|
return ApiResult.Error(500, $"结束时间小于当前时间计划将不会被执行");
|
||||||
|
}
|
||||||
#region 设置开始时间和结束时间
|
#region 设置开始时间和结束时间
|
||||||
|
|
||||||
tasksQz.BeginTime = tasksQz.BeginTime == null ? DateTime.Now : tasksQz.BeginTime;
|
tasksQz.BeginTime = tasksQz.BeginTime == null ? DateTime.Now : tasksQz.BeginTime;
|
||||||
@ -166,10 +170,12 @@ namespace ZR.Tasks
|
|||||||
// 5、将触发器和任务器绑定到调度器中
|
// 5、将触发器和任务器绑定到调度器中
|
||||||
await _scheduler.Result.ScheduleJob(job, trigger);
|
await _scheduler.Result.ScheduleJob(job, trigger);
|
||||||
//任务没有启动、暂停任务
|
//任务没有启动、暂停任务
|
||||||
if (!tasksQz.IsStart)
|
//if (!tasksQz.IsStart)
|
||||||
{
|
//{
|
||||||
_scheduler.Result.PauseJob(jobKey).Wait();
|
// _scheduler.Result.PauseJob(jobKey).Wait();
|
||||||
}
|
//}
|
||||||
|
//按新的trigger重新设置job执行
|
||||||
|
await _scheduler.Result.ResumeTrigger(trigger.Key);
|
||||||
return ApiResult.Success($"启动计划任务:【{tasksQz.Name}】成功!");
|
return ApiResult.Success($"启动计划任务:【{tasksQz.Name}】成功!");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@ -52,7 +52,7 @@ export default {
|
|||||||
// 文件类型, 例如['png', 'jpg', 'jpeg']
|
// 文件类型, 例如['png', 'jpg', 'jpeg']
|
||||||
fileType: {
|
fileType: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => ['doc', 'xls', 'ppt', 'txt', 'pdf', 'svga', 'json']
|
default: () => ['doc', 'xls', 'ppt', 'txt', 'pdf', 'json']
|
||||||
},
|
},
|
||||||
// 是否显示提示
|
// 是否显示提示
|
||||||
isShowTip: {
|
isShowTip: {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="component-upload-image">
|
<div class="component-upload-image">
|
||||||
<el-upload list-type="picture-card" :action="uploadImgUrl" :on-success="handleUploadSuccess" :before-upload="handleBeforeUpload"
|
<el-upload list-type="picture-card" :action="uploadImgUrl" :on-success="handleUploadSuccess" :before-upload="handleBeforeUpload"
|
||||||
:on-exceed="handleExceed" :on-remove="handleRemove" :on-error="handleUploadError" name="file" :show-file-list="true" :limit="limit"
|
:on-exceed="handleExceed" :on-remove="handleRemove" :on-error="handleUploadError" name="file" :show-file-list="true" :data="data" :limit="limit"
|
||||||
:file-list="fileList" :on-preview="handlePictureCardPreview" :on-progress="uploadProcess" :class="{hide: this.fileList.length >= this.limit}"
|
:file-list="fileList" :on-preview="handlePictureCardPreview" :on-progress="uploadProcess" :class="{hide: this.fileList.length >= this.limit}"
|
||||||
:headers="headers">
|
:headers="headers">
|
||||||
<i slot="default" class="el-icon-plus"></i>
|
<i slot="default" class="el-icon-plus"></i>
|
||||||
@ -20,7 +20,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getToken } from "@/utils/auth";
|
import { getToken } from '@/utils/auth'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
@ -28,158 +28,162 @@ export default {
|
|||||||
// 图片数量限制
|
// 图片数量限制
|
||||||
limit: {
|
limit: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 1,
|
default: 1
|
||||||
},
|
},
|
||||||
column: [String],
|
column: [String],
|
||||||
// 上传地址
|
// 上传地址
|
||||||
uploadUrl: {
|
uploadUrl: {
|
||||||
type: String,
|
type: String,
|
||||||
default: process.env.VUE_APP_UPLOAD_URL ?? "/Common/UploadFile",
|
default: process.env.VUE_APP_UPLOAD_URL ?? '/Common/UploadFile'
|
||||||
},
|
},
|
||||||
// 文件类型, 例如['png', 'jpg', 'jpeg']
|
// 文件类型, 例如['png', 'jpg', 'jpeg']
|
||||||
fileType: {
|
fileType: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => ["png", "jpg", "jpeg", "webp"],
|
default: () => ['png', 'jpg', 'jpeg', 'webp']
|
||||||
},
|
},
|
||||||
// 大小限制(MB)
|
// 大小限制(MB)
|
||||||
fileSize: {
|
fileSize: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 5,
|
default: 5
|
||||||
},
|
},
|
||||||
//显示手动输入地址
|
// 显示手动输入地址
|
||||||
showInput: false,
|
showInput: false,
|
||||||
// 是否显示提示
|
// 是否显示提示
|
||||||
isShowTip: {
|
isShowTip: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true
|
||||||
},
|
},
|
||||||
|
// 上传携带的参数
|
||||||
|
data: {
|
||||||
|
type: Object
|
||||||
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
dialogImageUrl: "",
|
dialogImageUrl: '',
|
||||||
dialogVisible: false,
|
dialogVisible: false,
|
||||||
hideUpload: false,
|
hideUpload: false,
|
||||||
uploadImgUrl: process.env.VUE_APP_BASE_API + this.uploadUrl, // 上传的图片服务器地址
|
uploadImgUrl: process.env.VUE_APP_BASE_API + this.uploadUrl, // 上传的图片服务器地址
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer " + getToken(),
|
Authorization: 'Bearer ' + getToken()
|
||||||
},
|
},
|
||||||
imageUrl: "",
|
imageUrl: '',
|
||||||
fileList: [],
|
fileList: []
|
||||||
};
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
//监听 v-model 的值
|
// 监听 v-model 的值
|
||||||
value: {
|
value: {
|
||||||
immediate: true,
|
immediate: true,
|
||||||
deep: true,
|
deep: true,
|
||||||
handler: function (val) {
|
handler: function(val) {
|
||||||
if (val) {
|
if (val) {
|
||||||
// 首先将值转为数组
|
// 首先将值转为数组
|
||||||
const list = Array.isArray(val) ? val : this.value.split(",");
|
const list = Array.isArray(val) ? val : this.value.split(',')
|
||||||
// 然后将数组转为对象数组
|
// 然后将数组转为对象数组
|
||||||
this.fileList = list.map((item) => {
|
this.fileList = list.map((item) => {
|
||||||
if (typeof item === "string") {
|
if (typeof item === 'string') {
|
||||||
// if (item.indexOf(this.baseUrl) === -1) {
|
// if (item.indexOf(this.baseUrl) === -1) {
|
||||||
// item = { name: this.baseUrl + item, url: this.baseUrl + item };
|
// item = { name: this.baseUrl + item, url: this.baseUrl + item };
|
||||||
// } else {
|
// } else {
|
||||||
item = { name: item, url: item };
|
item = { name: item, url: item }
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
return item;
|
return item
|
||||||
});
|
})
|
||||||
} else {
|
} else {
|
||||||
this.fileList = [];
|
this.fileList = []
|
||||||
return [];
|
return []
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
// 是否显示提示
|
// 是否显示提示
|
||||||
showTip() {
|
showTip() {
|
||||||
return this.isShowTip && (this.fileType || this.fileSize);
|
return this.isShowTip && (this.fileType || this.fileSize)
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 删除图片
|
// 删除图片
|
||||||
handleRemove(file, fileList) {
|
handleRemove(file, fileList) {
|
||||||
const findex = this.fileList.map((f) => f.name).indexOf(file.name);
|
const findex = this.fileList.map((f) => f.name).indexOf(file.name)
|
||||||
if (findex > -1) {
|
if (findex > -1) {
|
||||||
this.fileList.splice(findex, 1);
|
this.fileList.splice(findex, 1)
|
||||||
this.$emit("input", this.column, this.listToString(this.fileList));
|
this.$emit('input', this.column, this.listToString(this.fileList))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
//上传成功回调
|
// 上传成功回调
|
||||||
handleUploadSuccess(res) {
|
handleUploadSuccess(res) {
|
||||||
console.log(res);
|
console.log(res)
|
||||||
if (res.code != 200) {
|
if (res.code != 200) {
|
||||||
this.msgError(`上传失败,原因:${res.msg}!`);
|
this.msgError(`上传失败,原因:${res.msg}!`)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
this.fileList.push({ name: res.data.fileName, url: res.data.url });
|
this.fileList.push({ name: res.data.fileName, url: res.data.url })
|
||||||
this.$emit(`input`, this.column, this.listToString(this.fileList));
|
this.$emit(`input`, this.column, this.listToString(this.fileList))
|
||||||
},
|
},
|
||||||
// 上传前loading加载
|
// 上传前loading加载
|
||||||
handleBeforeUpload(file) {
|
handleBeforeUpload(file) {
|
||||||
let isImg = false;
|
let isImg = false
|
||||||
if (this.fileType.length) {
|
if (this.fileType.length) {
|
||||||
let fileExtension = "";
|
let fileExtension = ''
|
||||||
if (file.name.lastIndexOf(".") > -1) {
|
if (file.name.lastIndexOf('.') > -1) {
|
||||||
fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1);
|
fileExtension = file.name.slice(file.name.lastIndexOf('.') + 1)
|
||||||
}
|
}
|
||||||
isImg = this.fileType.some((type) => {
|
isImg = this.fileType.some((type) => {
|
||||||
if (file.type.indexOf(type) > -1) return true;
|
if (file.type.indexOf(type) > -1) return true
|
||||||
if (fileExtension && fileExtension.indexOf(type) > -1) return true;
|
if (fileExtension && fileExtension.indexOf(type) > -1) return true
|
||||||
return false;
|
return false
|
||||||
});
|
})
|
||||||
} else {
|
} else {
|
||||||
isImg = file.type.indexOf("image") > -1;
|
isImg = file.type.indexOf('image') > -1
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isImg) {
|
if (!isImg) {
|
||||||
this.msgError(
|
this.msgError(
|
||||||
`文件格式不正确, 请上传${this.fileType.join("/")}图片格式文件!`
|
`文件格式不正确, 请上传${this.fileType.join('/')}图片格式文件!`
|
||||||
);
|
)
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
if (this.fileSize) {
|
if (this.fileSize) {
|
||||||
const isLt = file.size / 1024 / 1024 < this.fileSize;
|
const isLt = file.size / 1024 / 1024 < this.fileSize
|
||||||
if (!isLt) {
|
if (!isLt) {
|
||||||
this.msgError(`上传头像图片大小不能超过 ${this.fileSize} MB!`);
|
this.msgError(`上传头像图片大小不能超过 ${this.fileSize} MB!`)
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 文件个数超出
|
// 文件个数超出
|
||||||
handleExceed() {
|
handleExceed() {
|
||||||
this.$message.error(`上传文件数量不能超过 ${this.limit} 个!`);
|
this.$message.error(`上传文件数量不能超过 ${this.limit} 个!`)
|
||||||
},
|
},
|
||||||
// 预览
|
// 预览
|
||||||
handlePictureCardPreview(file) {
|
handlePictureCardPreview(file) {
|
||||||
this.dialogImageUrl = file.url;
|
this.dialogImageUrl = file.url
|
||||||
this.dialogVisible = true;
|
this.dialogVisible = true
|
||||||
},
|
},
|
||||||
// 对象转成指定字符串分隔
|
// 对象转成指定字符串分隔
|
||||||
listToString(list, separator) {
|
listToString(list, separator) {
|
||||||
let strs = "";
|
let strs = ''
|
||||||
separator = separator || ",";
|
separator = separator || ','
|
||||||
for (let i in list) {
|
for (const i in list) {
|
||||||
strs += list[i].url.replace(this.baseUrl, "") + separator;
|
strs += list[i].url.replace(this.baseUrl, '') + separator
|
||||||
}
|
}
|
||||||
return strs != "" ? strs.substr(0, strs.length - 1) : "";
|
return strs != '' ? strs.substr(0, strs.length - 1) : ''
|
||||||
},
|
},
|
||||||
handleUploadError() {
|
handleUploadError() {
|
||||||
this.$message({
|
this.$message({
|
||||||
type: "error",
|
type: 'error',
|
||||||
message: "上传失败",
|
message: '上传失败'
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
// 上传进度
|
// 上传进度
|
||||||
uploadProcess(event, file, fileList) {
|
uploadProcess(event, file, fileList) {
|
||||||
console.log("上传进度" + file.percentage);
|
console.log('上传进度' + file.percentage)
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|||||||
@ -100,8 +100,8 @@
|
|||||||
</el-col>
|
</el-col>
|
||||||
<el-col :lg="24">
|
<el-col :lg="24">
|
||||||
<el-form-item prop="accessUrl">
|
<el-form-item prop="accessUrl">
|
||||||
<UploadFile ref="upload" v-model="form.accessUrl" :uploadUrl="uploadUrl" :fileType="[]" :limit="5" :fileSize="15" :drag="true"
|
<UploadFile ref="upload" v-model="form.accessUrl" :fileType="[]" :limit="5" :fileSize="15" :drag="true"
|
||||||
:data="{ 'fileDir' : form.storePath, 'fileName': form.fileName}" :autoUpload="false" column="accessUrl"
|
:data="{ 'fileDir' : form.storePath, 'fileName': form.fileName, 'storeType': form.storeType}" :autoUpload="false" column="accessUrl"
|
||||||
@input="handleUploadSuccess" />
|
@input="handleUploadSuccess" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
@ -208,8 +208,8 @@ export default {
|
|||||||
{ dictLabel: '本地存储', dictValue: 1 },
|
{ dictLabel: '本地存储', dictValue: 1 },
|
||||||
{ dictLabel: '阿里云存储', dictValue: 2 }
|
{ dictLabel: '阿里云存储', dictValue: 2 }
|
||||||
],
|
],
|
||||||
// 上传文件地址
|
// 存储类型 1、本地 2、阿里云
|
||||||
uploadUrl: '/common/uploadFile',
|
storeType: 0,
|
||||||
fileType: [],
|
fileType: [],
|
||||||
// 数据列表
|
// 数据列表
|
||||||
dataList: [],
|
dataList: [],
|
||||||
@ -240,17 +240,6 @@ export default {
|
|||||||
// 列表数据查询
|
// 列表数据查询
|
||||||
this.getList()
|
this.getList()
|
||||||
},
|
},
|
||||||
watch: {
|
|
||||||
'form.storeType': {
|
|
||||||
handler: function(val) {
|
|
||||||
if (val == 1) {
|
|
||||||
this.uploadUrl = '/common/uploadFile'
|
|
||||||
} else if (val == 2) {
|
|
||||||
this.uploadUrl = '/common/UploadFileAliyun'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
// 查询数据
|
// 查询数据
|
||||||
getList() {
|
getList() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user