189 lines
6.2 KiB
C#
189 lines
6.2 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using REPORT_API_ver6.Services;
|
|
using REPORT_API_ver6.Models;
|
|
using System;
|
|
using System.Net;
|
|
using System.Data;
|
|
|
|
namespace REPORT_API_ver6.Controllers
|
|
{
|
|
[Route("api/v1/export")]
|
|
[ApiController]
|
|
public class ExportAPI : ControllerBase
|
|
{
|
|
[Route("excel/table")]
|
|
[HttpPost]
|
|
[DisableRequestSizeLimit]
|
|
public IActionResult ExportExcelTable([FromHeader] string token, [FromBody] ExportExcelParam excelParam)
|
|
{
|
|
UserInfo userInfo = Security.ValidateToken(token);
|
|
if (userInfo != null && String.IsNullOrEmpty(excelParam.ExportTable) == false && excelParam.ExportTable != "[]")
|
|
{
|
|
MakeExcel makeExcel = new MakeExcel();
|
|
string fileName = token + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
|
string fileType = "application/vnd.ms-excel";
|
|
|
|
byte[] excelFile = makeExcel.getTableExcel(excelParam.ExportTable, excelParam.Turn);
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.OK;
|
|
return File(excelFile, fileType, fileName);
|
|
}
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
|
return Content(null);
|
|
}
|
|
|
|
[Route("excel/quota")]
|
|
[HttpPost]
|
|
[DisableRequestSizeLimit]
|
|
public IActionResult ExportExcelQuota([FromHeader] string token, [FromBody] ExportExcelParam excelParam)
|
|
{
|
|
UserInfo userInfo = Security.ValidateToken(token);
|
|
if (userInfo != null && String.IsNullOrEmpty(excelParam.ExportTable) == false && excelParam.ExportTable != "[]")
|
|
{
|
|
MakeExcel makeExcel = new MakeExcel();
|
|
string fileName = token + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
|
string fileType = "application/vnd.ms-excel";
|
|
|
|
byte[] excelFile = makeExcel.getQuotaExcel(excelParam.ExportTable);
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.OK;
|
|
return File(excelFile, fileType, fileName);
|
|
}
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
|
return Content(null);
|
|
}
|
|
|
|
[Route("form/data")]
|
|
[HttpGet]
|
|
public IActionResult ExportDataForm([FromHeader] string token, [FromHeader] string skey)
|
|
{
|
|
UserInfo userInfo = Security.ValidateToken(token);
|
|
if (userInfo != null)
|
|
{
|
|
Project project = new Project();
|
|
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
|
|
|
DataTable headerTable = project.getExportHeader(pkeyInfo.Pkey, pkeyInfo.isKiwi, userInfo.IsAdmin);
|
|
DataTable exportTable = project.makeExportTable(headerTable);
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.OK;
|
|
string fileName = "[Header]" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
|
byte[] fileByteArray = Common.DataTableToExcel(exportTable);
|
|
return File(fileByteArray, "application/octet-stream", fileName);
|
|
}
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
|
return Content(null);
|
|
}
|
|
|
|
[Route("form/question")]
|
|
[HttpGet]
|
|
public IActionResult ExportQuestionForm([FromHeader] string token)
|
|
{
|
|
UserInfo userInfo = Security.ValidateToken(token);
|
|
if (userInfo != null)
|
|
{
|
|
Response.StatusCode = (int)HttpStatusCode.OK;
|
|
byte[] fileByteArray = System.IO.File.ReadAllBytes(Common.MapPath("file_forms/KON 문항 등록 양식.xlsx"));
|
|
return File(fileByteArray, "application/octet-stream", "KON 문항 등록 양식.xlsx");
|
|
}
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
|
return Content(null);
|
|
}
|
|
|
|
[Route("form/title")]
|
|
[HttpGet]
|
|
[DisableRequestSizeLimit]
|
|
public IActionResult ExportTitleForm([FromHeader] string token, [FromHeader] string skey)
|
|
{
|
|
UserInfo userInfo = Security.ValidateToken(token);
|
|
if (userInfo != null)
|
|
{
|
|
Project project = new Project();
|
|
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
|
|
|
DataTable titleTable = project.getExportExplain(pkeyInfo.Pkey, pkeyInfo.isKiwi);
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.OK;
|
|
string fileName = "[Explain]" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
|
byte[] fileByteArray = Common.DataTableToExcel(titleTable);
|
|
return File(fileByteArray, "application/octet-stream", fileName);
|
|
}
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
|
return Content(null);
|
|
}
|
|
|
|
[Route("data")]
|
|
[HttpGet]
|
|
public IActionResult ExportData([FromHeader] string token, [FromHeader] string skey, [FromHeader] string type)
|
|
{
|
|
UserInfo userInfo = Security.ValidateToken(token);
|
|
|
|
if (userInfo != null)
|
|
{
|
|
Project project = new Project();
|
|
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
|
|
|
string fileName = "[DATA]" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
|
byte[] fileByteArray = project.makeDataAndGuidFile(pkeyInfo, userInfo, type, "ALL");
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.OK;
|
|
return File(fileByteArray, "application/octet-stream", fileName);
|
|
}
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
|
return Content(null);
|
|
}
|
|
|
|
[Route("data/{start}/{end}")]
|
|
[HttpGet]
|
|
public IActionResult ExportDataWithDate(
|
|
[FromHeader] string token, [FromHeader] string skey, [FromHeader] string type
|
|
,[FromRoute] string start, [FromRoute] string end
|
|
)
|
|
{
|
|
UserInfo userInfo = Security.ValidateToken(token);
|
|
|
|
if (userInfo != null)
|
|
{
|
|
Project project = new Project();
|
|
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
|
|
|
string fileName = "[DATA]" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
|
byte[] fileByteArray = project.makeDataAndGuidFile(pkeyInfo, userInfo, type, "ALL", start, end);
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.OK;
|
|
return File(fileByteArray, "application/octet-stream", fileName);
|
|
}
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
|
return Content(null);
|
|
}
|
|
|
|
[Route("guide")]
|
|
[HttpGet]
|
|
public IActionResult ExportGuide([FromHeader] string token, [FromHeader] string skey)
|
|
{
|
|
UserInfo userInfo = Security.ValidateToken(token);
|
|
if (userInfo != null)
|
|
{
|
|
Project project = new Project();
|
|
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
|
|
|
string fileName = "[GUIDE]" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
|
byte[] fileByteArray = project.makeDataAndGuidFile(pkeyInfo, userInfo, "", "GUIDE");
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.OK;
|
|
return File(fileByteArray, "application/octet-stream", fileName);
|
|
}
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
|
return Content(null);
|
|
}
|
|
}
|
|
}
|