181 lines
6.5 KiB
C#
181 lines
6.5 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
||
using DOAN.Model.Dto;
|
||
using DOAN.Model.Business;
|
||
using DOAN.Service.Business.IBusinessService;
|
||
using DOAN.Admin.WebApi.Filters;
|
||
|
||
//创建时间:2025-11-03
|
||
namespace DOAN.Admin.WebApi.Controllers
|
||
{
|
||
/// <summary>
|
||
/// 产品项目表
|
||
/// </summary>
|
||
[Verify]
|
||
[Route("business/ProcessmodelProject")]
|
||
public class ProcessmodelProjectController : BaseController
|
||
{
|
||
/// <summary>
|
||
/// 产品项目表接口
|
||
/// </summary>
|
||
private readonly IProcessmodelProjectService _ProcessmodelProjectService;
|
||
|
||
public ProcessmodelProjectController(IProcessmodelProjectService ProcessmodelProjectService)
|
||
{
|
||
_ProcessmodelProjectService = ProcessmodelProjectService;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询产品项目表列表
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("list")]
|
||
[ActionPermissionFilter(Permission = "business:processmodelproject:list")]
|
||
public IActionResult QueryProcessmodelProject([FromQuery] ProcessmodelProjectQueryDto parm)
|
||
{
|
||
var response = _ProcessmodelProjectService.GetList(parm);
|
||
return SUCCESS(response);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 查询产品项目表详情
|
||
/// </summary>
|
||
/// <param name="Id"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("{Id}")]
|
||
[ActionPermissionFilter(Permission = "business:processmodelproject:query")]
|
||
public IActionResult GetProcessmodelProject(long Id)
|
||
{
|
||
var response = _ProcessmodelProjectService.GetInfo(Id);
|
||
|
||
var info = response.Adapt<ProcessmodelProject>();
|
||
return SUCCESS(info);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加产品项目表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[ActionPermissionFilter(Permission = "business:processmodelproject:add")]
|
||
[Log(Title = "产品项目表", BusinessType = BusinessType.INSERT)]
|
||
public IActionResult AddProcessmodelProject([FromBody] ProcessmodelProjectDto parm)
|
||
{
|
||
var modal = parm.Adapt<ProcessmodelProject>().ToCreate(HttpContext);
|
||
|
||
var response = _ProcessmodelProjectService.AddProcessmodelProject(modal);
|
||
|
||
return SUCCESS(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新产品项目表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPut]
|
||
[ActionPermissionFilter(Permission = "business:processmodelproject:edit")]
|
||
[Log(Title = "产品项目表", BusinessType = BusinessType.UPDATE)]
|
||
public IActionResult UpdateProcessmodelProject([FromBody] ProcessmodelProjectDto parm)
|
||
{
|
||
var modal = parm.Adapt<ProcessmodelProject>().ToUpdate(HttpContext);
|
||
var response = _ProcessmodelProjectService.UpdateProcessmodelProject(modal);
|
||
|
||
return ToResponse(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除产品项目表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpDelete("{ids}")]
|
||
[ActionPermissionFilter(Permission = "business:processmodelproject:delete")]
|
||
[Log(Title = "产品项目表", BusinessType = BusinessType.DELETE)]
|
||
public IActionResult DeleteProcessmodelProject(string ids)
|
||
{
|
||
int[] idsArr = Tools.SpitIntArrary(ids);
|
||
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
|
||
|
||
var response = _ProcessmodelProjectService.Delete(idsArr);
|
||
|
||
return ToResponse(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 新增导入Excel
|
||
/// </summary>
|
||
/// <param name="formFile">使用IFromFile必须使用name属性否则获取不到文件</param>
|
||
/// <returns>导入成功数 若-1 则Excel读取异常</returns>
|
||
[HttpPost("addImportProject")]
|
||
[Log(Title = "新增导入Excel", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)]
|
||
[AllowAnonymous]
|
||
public IActionResult AddImportData([FromForm(Name = "file")] IFormFile formFile)
|
||
{
|
||
if (formFile == null)
|
||
{
|
||
SUCCESS(null);
|
||
}
|
||
|
||
int result = _ProcessmodelProjectService.AddImportExcel(formFile, HttpContext.GetName());
|
||
return ToResponse(result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 覆盖导入Excel
|
||
/// </summary>
|
||
/// <param name="formFile">使用IFromFile必须使用name属性否则获取不到文件</param>
|
||
/// <returns>导入成功数 若-1 则Excel读取异常</returns>
|
||
[HttpPost("coverImportProject")]
|
||
[Log(Title = "覆盖导入Excel", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)]
|
||
[AllowAnonymous]
|
||
public IActionResult CoverImportData([FromForm(Name = "file")] IFormFile formFile)
|
||
{
|
||
if (formFile == null)
|
||
{
|
||
SUCCESS(null);
|
||
}
|
||
|
||
int result = _ProcessmodelProjectService.CoverImportExcel(formFile, HttpContext.GetName());
|
||
return ToResponse(result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 导出Excel模板
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpGet("exportTemplate")]
|
||
[Log(Title = "产品项目模板导出", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)]
|
||
[AllowAnonymous]
|
||
public IActionResult ExportTemplateExcel()
|
||
{
|
||
(string, string) result = DownloadImportTemplate("processmodel");
|
||
return ExportExcel(result.Item2, result.Item1);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 导出Excel
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpGet("exportProject")]
|
||
[AllowAnonymous]
|
||
public IActionResult ExportData()
|
||
{
|
||
try
|
||
{
|
||
// 调用Service层方法获取Excel字节数组和文件名
|
||
var (fileBytes, fileName) = _ProcessmodelProjectService.ExportProjectExcel();
|
||
|
||
// 在Controller中使用File方法返回文件下载响应
|
||
return File(
|
||
fileBytes,
|
||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||
fileName);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
// 错误处理
|
||
return BadRequest(ex.Message);
|
||
}
|
||
}
|
||
}
|
||
} |