using CMS.Extensions.Abp.AspNetCore.Mvc.Filters;
|
using CMS.Framework.AspNetCore.Users;
|
using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.WorkTask;
|
using CMS.Plugin.PipeLineLems.Application.Contracts.Services;
|
using CmsQueryExtensions.Entitys;
|
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Mvc;
|
using MiniExcelLibs;
|
using System.Reflection;
|
using Volo.Abp;
|
using Volo.Abp.Application.Dtos;
|
|
namespace CMS.Plugin.PipeLineLems.Controller
|
{
|
/// <summary>
|
/// 作业任务表服务
|
/// </summary>
|
[ApiController]
|
[TypeFilter(typeof(CMSLanguageFilter))]
|
[TypeFilter(typeof(CMSUowActionFilter))]
|
[TypeFilter(typeof(CMSAuditActionFilter))]
|
[TypeFilter(typeof(CMSExceptionFilter))]
|
[Route("api/v{version:apiVersion}/PipeLineLems/[controller]")]
|
public class WorkTaskController : ControllerBase
|
{
|
private readonly IWorkTaskAppService _workTaskAppService;
|
private readonly ICurrentUser _currentUser;
|
|
/// <summary>
|
/// Initializes a new instance of the <see cref="WorkTaskController"/> class.
|
/// </summary>
|
/// <param name="workTaskAppService">The workTask application service.</param>
|
public WorkTaskController(IWorkTaskAppService workTaskAppService, ICurrentUser currentUser)
|
{
|
_workTaskAppService = workTaskAppService;
|
_currentUser = currentUser;
|
}
|
|
/// <summary>
|
/// 获取作业任务表
|
/// </summary>
|
/// <param name="id">主键ID</param>
|
/// <returns></returns>
|
[HttpGet]
|
[Route("{id}")]
|
public virtual Task<WorkTaskDto> GetAsync(Guid id)
|
{
|
return _workTaskAppService.GetAsync(id);
|
}
|
|
/// <summary>
|
/// 分页获取作业任务表的列表.
|
/// </summary>
|
/// <param name="input">查询参数</param>
|
/// <returns></returns>
|
[HttpGet]
|
[Route("Page")]
|
public virtual Task<PagedResultDto<WorkTaskDto>> GetListAsync([FromQuery] GetWorkTaskInput input)
|
{
|
return _workTaskAppService.GetListAsync(input);
|
}
|
|
/// <summary>
|
/// 根据条件获取作业任务表
|
/// </summary>
|
/// <param name="input">查询参数</param>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("FindListByFilter")]
|
public virtual async Task<List<WorkTaskDto>> FindListByFilterAsync([FromBody]GetWorkTaskInput input)
|
{
|
return await _workTaskAppService.FindListByFilterAsync(input);
|
}
|
/// <summary>
|
/// 根据条件获取单个作业任务表
|
/// </summary>
|
/// <param name="input">查询参数</param>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("FindSingleByFilter")]
|
public virtual async Task<WorkTaskDto> FindSingleByFilterAsync([FromBody]GetWorkTaskInput input)
|
{
|
|
return await _workTaskAppService.FindSingleByFilterAsync(input);
|
}
|
|
/// <summary>
|
/// 创建作业任务表
|
/// </summary>
|
/// <param name="input">创建参数</param>
|
/// <returns></returns>
|
[Authorize]
|
[HttpPost]
|
public virtual Task<WorkTaskDto> CreateAsync(WorkTaskCreateDto input)
|
{
|
input.CreatorName = _currentUser.UserAccount;//创建人
|
return _workTaskAppService.CreateAsync(input);
|
}
|
|
/// <summary>
|
/// 更新作业任务表
|
/// </summary>
|
/// <param name="id">主键ID</param>
|
/// <param name="input">更新参数</param>
|
/// <returns></returns>
|
[Authorize]
|
[HttpPut]
|
[Route("{id}")]
|
public virtual Task<WorkTaskDto> UpdateAsync(Guid id, WorkTaskUpdateDto input)
|
{
|
input.LastModifierName = _currentUser.UserAccount;//修改人
|
return _workTaskAppService.UpdateAsync(id, input);
|
}
|
|
/// <summary>
|
/// 克隆作业任务表
|
/// </summary>
|
/// <param name="ids">Id集合</param>
|
/// <returns></returns>
|
[Authorize]
|
[HttpPost]
|
[Route("Clone")]
|
public virtual Task<List<WorkTaskDto>> CloneAsync([FromBody] IEnumerable<Guid> ids)
|
{
|
MyCurrentUser myCurrentUser = new MyCurrentUser()
|
{
|
UserAccount = _currentUser.UserAccount,
|
UserId = _currentUser.UserId
|
};
|
return _workTaskAppService.CloneAsync(ids, myCurrentUser);
|
}
|
|
/// <summary>
|
/// 删除作业任务表
|
/// </summary>
|
/// <param name="id">主键ID</param>
|
/// <returns></returns>
|
[Authorize]
|
[HttpDelete]
|
[Route("{id}")]
|
public virtual Task DeleteAsync(Guid id)
|
{
|
MyCurrentUser myCurrentUser = new MyCurrentUser()
|
{
|
UserAccount = _currentUser.UserAccount,
|
UserId = _currentUser.UserId
|
};
|
//return _wmsMaterialAppService.DeleteAsync(id,myCurrentUser);//逻辑删除
|
return _workTaskAppService.DeletePermanentlyAsync(id, myCurrentUser);//物理删除
|
}
|
|
/// <summary>
|
/// 批量删除作业任务表
|
/// </summary>
|
/// <param name="ids">主键ID集合</param>
|
/// <returns></returns>
|
[Authorize]
|
[HttpDelete]
|
public virtual Task DeleteAsync([FromBody] IEnumerable<Guid> ids)
|
{
|
MyCurrentUser myCurrentUser = new MyCurrentUser()
|
{
|
UserAccount = _currentUser.UserAccount,
|
UserId = _currentUser.UserId
|
};
|
// return _wmsMaterialAppService.DeleteManyAsync(ids,myCurrentUser);//逻辑删除
|
return _workTaskAppService.BatchDeletePermanentlyAsync(ids, myCurrentUser);//物理删除
|
}
|
|
/// <summary>
|
/// 调整排序作业任务表
|
/// </summary>
|
/// <param name="id">主键ID</param>
|
/// <returns></returns>
|
[HttpPut]
|
[Route("{id}/AdjustSort/{sort}")]
|
public virtual Task AdjustSortAsync(Guid id, int sort)
|
{
|
return _workTaskAppService.AdjustSortAsync(id, sort);
|
}
|
|
/// <summary>
|
/// 导入作业任务表
|
/// </summary>
|
/// <returns></returns>
|
[Authorize]
|
[HttpPost]
|
[Route("Import")]
|
public virtual async Task<IActionResult> ImportAsync(IFormFile file)
|
{
|
using var stream = new MemoryStream();
|
await file.CopyToAsync(stream);
|
stream.Seek(0L, SeekOrigin.Begin);
|
|
var sheetNames = stream.GetSheetNames();
|
var workTaskRows = sheetNames.Contains("配置") ? MiniExcel.Query<WorkTasksImportModel.WorkTaskImportModel>(stream, sheetName: "配置").ToList() : new();
|
|
if (!workTaskRows.Any())
|
{
|
throw new UserFriendlyException("请检查导入的表格");
|
}
|
|
MyCurrentUser myCurrentUser = new MyCurrentUser()
|
{
|
UserAccount = _currentUser.UserAccount,
|
UserId = _currentUser.UserId
|
};
|
await _workTaskAppService.ImportAsync(new WorkTasksImportModel
|
{
|
WorkTasks = workTaskRows,
|
},myCurrentUser);
|
|
return Ok();
|
}
|
|
/// <summary>
|
/// 导出作业任务表
|
/// </summary>
|
/// <returns></returns>
|
[HttpGet]
|
[Route("Export")]
|
public virtual async Task<IActionResult> ExportAsync([FromQuery] GetWorkTaskInput input)
|
{
|
input.MaxResultCount = int.MaxValue;
|
var exportData = await _workTaskAppService.ExportAsync(input);
|
var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Resources/Templates/WorkTask导出模板.xlsx");
|
if (!System.IO.File.Exists(templatePath))
|
{
|
templatePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty, $"Resources/Templates/WorkTask导出模板.xlsx");
|
}
|
|
var memoryStream = new MemoryStream();
|
await memoryStream.SaveAsByTemplateAsync(templatePath, exportData.Sheets);
|
memoryStream.Seek(0L, SeekOrigin.Begin);
|
return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileDownloadName = $"{exportData.FileName}_{DateTime.Now:yyyyMMddhhmmss}.xlsx" };
|
}
|
}
|
}
|