Merge branch 'master' into net6.0

This commit is contained in:
不做码农
2022-04-04 08:27:47 +08:00
29 changed files with 1468 additions and 208 deletions
@@ -0,0 +1,167 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Infrastructure;
using Infrastructure.Attribute;
using Infrastructure.Enums;
using Infrastructure.Model;
using Mapster;
using ZR.Model.Dto;
using ZR.Model.Models;
using ZR.Service.Business.IBusinessService;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters;
using ZR.Common;
using Infrastructure.Extensions;
using System.Linq;
namespace ZR.Admin.WebApi.Controllers
{
/// <summary>
/// 演示Controller
///
/// @author zz
/// @date 2022-03-31
/// </summary>
[Verify]
[Route("business/GenDemo")]
public class GenDemoController : BaseController
{
/// <summary>
/// 演示接口
/// </summary>
private readonly IGenDemoService _GenDemoService;
public GenDemoController(IGenDemoService GenDemoService)
{
_GenDemoService = GenDemoService;
}
/// <summary>
/// 查询演示列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
[HttpGet("list")]
[ActionPermissionFilter(Permission = "business:gendemo:list")]
public IActionResult QueryGenDemo([FromQuery] GenDemoQueryDto parm)
{
var response = _GenDemoService.GetList(parm);
return SUCCESS(response);
}
/// <summary>
/// 查询演示详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
[HttpGet("{Id}")]
[ActionPermissionFilter(Permission = "business:gendemo:query")]
public IActionResult GetGenDemo(int Id)
{
var response = _GenDemoService.GetFirst(x => x.Id == Id);
return SUCCESS(response);
}
/// <summary>
/// 添加演示
/// </summary>
/// <returns></returns>
[HttpPost]
[ActionPermissionFilter(Permission = "business:gendemo:add")]
[Log(Title = "演示", BusinessType = BusinessType.INSERT)]
public IActionResult AddGenDemo([FromBody] GenDemoDto parm)
{
if (parm == null)
{
throw new CustomException("请求参数错误");
}
//从 Dto 映射到 实体
var modal = parm.Adapt<GenDemo>().ToCreate(HttpContext);
var response = _GenDemoService.Insert(modal, it => new
{
it.Name,
it.Icon,
it.ShowStatus,
it.Sex,
it.Sort,
it.Remark,
it.BeginTime,
it.EndTime,
it.Feature,
});
return ToResponse(response);
}
/// <summary>
/// 更新演示
/// </summary>
/// <returns></returns>
[HttpPut]
[ActionPermissionFilter(Permission = "business:gendemo:edit")]
[Log(Title = "演示", BusinessType = BusinessType.UPDATE)]
public IActionResult UpdateGenDemo([FromBody] GenDemoDto parm)
{
if (parm == null)
{
throw new CustomException("请求实体不能为空");
}
//从 Dto 映射到 实体
var modal = parm.Adapt<GenDemo>().ToUpdate(HttpContext);
var response = _GenDemoService.Update(w => w.Id == modal.Id, it => new GenDemo()
{
//Update 字段映射
Name = modal.Name,
Icon = modal.Icon,
ShowStatus = modal.ShowStatus,
Sex = modal.Sex,
Sort = modal.Sort,
Remark = modal.Remark,
BeginTime = modal.BeginTime,
EndTime = modal.EndTime,
Feature = modal.Feature,
});
return ToResponse(response);
}
/// <summary>
/// 删除演示
/// </summary>
/// <returns></returns>
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "business:gendemo:delete")]
[Log(Title = "演示", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteGenDemo(string ids)
{
int[] idsArr = Tools.SpitIntArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _GenDemoService.Delete(idsArr);
return ToResponse(response);
}
/// <summary>
/// 导出演示
/// </summary>
/// <returns></returns>
[Log(Title = "演示", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
[HttpGet("export")]
[ActionPermissionFilter(Permission = "business:gendemo:export")]
public IActionResult Export([FromQuery] GenDemoQueryDto parm)
{
parm.PageSize = 10000;
var list = _GenDemoService.GetList(parm).Result;
string sFileName = ExportExcel(list, "GenDemo", "演示");
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
}
}
}
@@ -139,7 +139,7 @@ namespace ZR.Admin.WebApi.Controllers
return SUCCESS(new
{
url = file.AccessUrl,
fileName,
fileName = file.FileName,
fileId = file.Id.ToString()
});
}
@@ -9,6 +9,7 @@ using Infrastructure.Attribute;
using Infrastructure.Enums;
using Infrastructure;
using ZR.Service.System.IService;
using ZR.Common;
namespace ZR.Admin.WebApi.Controllers.System
{
@@ -106,9 +107,10 @@ namespace ZR.Admin.WebApi.Controllers.System
[HttpDelete("{id}")]
[ActionPermissionFilter(Permission = "system:post:remove")]
[Log(Title = "岗位删除", BusinessType = BusinessType.DELETE)]
public IActionResult Delete(int id = 0)
public IActionResult Delete(string id)
{
return ToResponse(ToJson(PostService.Delete(id)));
int[] ids = Tools.SpitIntArrary(id);
return ToResponse(ToJson(PostService.Delete(ids)));
}
/// <summary>
@@ -15,6 +15,8 @@ using ZR.Common;
using ZR.Model.System.Dto;
using ZR.Model.System;
using ZR.Service.System.IService;
using Infrastructure.Extensions;
using System.Threading.Tasks;
namespace ZR.Admin.WebApi.Controllers.System
{
@@ -27,6 +29,7 @@ namespace ZR.Admin.WebApi.Controllers.System
private readonly ISysRoleService RoleService;
private readonly ISysUserPostService UserPostService;
private readonly ISysDeptService DeptService;
private readonly ISysFileService FileService;
private OptionsSetting OptionsSetting;
private IWebHostEnvironment hostEnvironment;
@@ -35,6 +38,7 @@ namespace ZR.Admin.WebApi.Controllers.System
ISysRoleService roleService,
ISysUserPostService postService,
ISysDeptService deptService,
ISysFileService sysFileService,
IOptions<OptionsSetting> options,
IWebHostEnvironment hostEnvironment)
{
@@ -42,6 +46,7 @@ namespace ZR.Admin.WebApi.Controllers.System
RoleService = roleService;
UserPostService = postService;
DeptService = deptService;
FileService = sysFileService;
OptionsSetting = options.Value;
this.hostEnvironment = hostEnvironment;
}
@@ -124,28 +129,17 @@ namespace ZR.Admin.WebApi.Controllers.System
[HttpPost("Avatar")]
[ActionPermissionFilter(Permission = "common")]
[Log(Title = "修改头像", BusinessType = BusinessType.UPDATE, IsSaveRequestData = false)]
public IActionResult Avatar([FromForm(Name = "picture")] IFormFile formFile)
public async Task<IActionResult> Avatar([FromForm(Name = "picture")] IFormFile formFile)
{
LoginUser loginUser = Framework.JwtUtil.GetLoginUser(HttpContext);
if (formFile == null) throw new CustomException("请选择文件");
string fileExt = Path.GetExtension(formFile.FileName);
string savePath = Path.Combine(hostEnvironment.WebRootPath, FileUtil.GetdirPath("uploads"));
string fileName = FileUtil.HashFileName() + (fileExt.IsEmpty() ? ".png" : fileExt);
SysFile file = await FileService.SaveFileToLocal(hostEnvironment.WebRootPath, fileName, "", HttpContext.GetName(), formFile);
if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); }
string fileName = FileUtil.HashFileName() + fileExt;
string finalFilePath = savePath + fileName;
using (var stream = new FileStream(finalFilePath, FileMode.Create))
{
formFile.CopyTo(stream);
}
string accessUrl = $"{OptionsSetting.Upload.UploadUrl}/{FileUtil.GetdirPath("uploads")}{fileName}";
UserService.UpdatePhoto(new SysUser() { Avatar = accessUrl, UserId = loginUser.UserId });
return SUCCESS(new { imgUrl = accessUrl });
UserService.UpdatePhoto(new SysUser() { Avatar = file.AccessUrl, UserId = loginUser.UserId });
return SUCCESS(new { imgUrl = file.AccessUrl });
}
}
}
@@ -15,6 +15,7 @@ using ZR.Model.System;
using ZR.Service.System.IService;
using ZR.Tasks;
using Snowflake.Core;
using Infrastructure.Extensions;
namespace ZR.Admin.WebApi.Controllers
{
@@ -62,14 +63,14 @@ namespace ZR.Admin.WebApi.Controllers
/// </summary>
/// <param name="id">编码</param>
/// <returns></returns>
[HttpGet("{id}")]
[HttpGet("get")]
public IActionResult Get(string id)
{
if (!string.IsNullOrEmpty(id))
{
return SUCCESS(_tasksQzService.GetId(id));
}
return SUCCESS(_tasksQzService.GetAll());
return SUCCESS(null);
}
/// <summary>
@@ -90,7 +91,10 @@ namespace ZR.Admin.WebApi.Controllers
{
throw new CustomException($"cron表达式不正确");
}
if (string.IsNullOrEmpty(parm.ApiUrl) && parm.TaskType == 2)
{
throw new CustomException($"地址不能为空");
}
//从 Dto 映射到 实体
var tasksQz = parm.Adapt<SysTasksQz>().ToCreate();
var worker = new IdWorker(1, 1);
@@ -98,7 +102,13 @@ namespace ZR.Admin.WebApi.Controllers
tasksQz.ID = worker.NextId().ToString();
tasksQz.IsStart = false;
tasksQz.Create_by = HttpContext.GetName();
tasksQz.TaskType = parm.TaskType;
tasksQz.ApiUrl = parm.ApiUrl;
if (parm.ApiUrl.IfNotEmpty() && parm.TaskType == 2)
{
tasksQz.AssemblyName = "ZR.Tasks";
tasksQz.ClassName = "TaskScheduler.HttpResultfulJob";
}
return SUCCESS(_tasksQzService.Add(tasksQz));
}
@@ -125,7 +135,15 @@ namespace ZR.Admin.WebApi.Controllers
throw new CustomException($"cron表达式不正确");
}
var tasksQz = _tasksQzService.GetFirst(m => m.ID == parm.ID);
if (string.IsNullOrEmpty(parm.ApiUrl) && parm.TaskType == 2)
{
throw new CustomException($"api地址不能为空");
}
if (parm.ApiUrl.IfNotEmpty() && parm.TaskType == 2)
{
parm.AssemblyName = "ZR.Tasks";
parm.ClassName = "TaskScheduler.HttpResultfulJob";
}
if (tasksQz.IsStart)
{
throw new CustomException($"该任务正在运行中,请先停止在更新");
@@ -142,10 +160,12 @@ namespace ZR.Admin.WebApi.Controllers
TriggerType = parm.TriggerType,
IntervalSecond = parm.IntervalSecond,
JobParams = parm.JobParams,
Update_by = User.Identity.Name,
Update_by = HttpContextExtension.GetName(HttpContext),
Update_time = DateTime.Now,
BeginTime = parm.BeginTime,
EndTime = parm.EndTime
EndTime = parm.EndTime,
TaskType = parm.TaskType,
ApiUrl = parm.ApiUrl,
});
if (response > 0)
{