2024-05-16 13:30:30 +08:00
|
|
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
using MiniExcelLibs;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2024-07-01 16:04:10 +08:00
|
|
|
|
using DOAN.Admin.WebApi.Extensions;
|
|
|
|
|
|
using DOAN.Admin.WebApi.Filters;
|
|
|
|
|
|
using DOAN.Model;
|
|
|
|
|
|
using DOAN.Model.MES.upload;
|
|
|
|
|
|
using DOAN.Model.System;
|
|
|
|
|
|
using DOAN.Service.quality.upload;
|
2024-05-16 13:30:30 +08:00
|
|
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DOAN.WebApi.Controllers.MES.quality.upload
|
|
|
|
|
|
{
|
|
|
|
|
|
[Verify]
|
|
|
|
|
|
[Route("mes/quality/upload")]
|
|
|
|
|
|
public class UploadController : BaseController
|
|
|
|
|
|
{
|
|
|
|
|
|
IUploadServive uploadservcie;
|
|
|
|
|
|
public UploadController(IUploadServive uploadservcie)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.uploadservcie = uploadservcie;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取上传数据列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="partnumber"></param>
|
|
|
|
|
|
/// <param name="workstation"></param>
|
|
|
|
|
|
/// <param name="paramter"></param>
|
|
|
|
|
|
/// <param name="pager"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet("list")]
|
|
|
|
|
|
public IActionResult List(string partnumber, string workstation, string paramter, [FromQuery] PagerInfo pager)
|
|
|
|
|
|
{
|
|
|
|
|
|
var list = uploadservcie.SelectExcelList(partnumber, workstation, paramter, pager);
|
|
|
|
|
|
return SUCCESS(list);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 导入
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="formFile">使用IFromFile必须使用name属性否则获取不到文件</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost("importData")]
|
|
|
|
|
|
[Log(Title = "云端数据导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)]
|
|
|
|
|
|
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
//1.0 读取excel 文件 保存在指定位置
|
|
|
|
|
|
IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
|
|
|
|
|
|
|
|
|
|
|
|
string target = Path.Combine(webHostEnvironment.WebRootPath, "cloudUpload");
|
|
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(target))
|
|
|
|
|
|
{
|
|
|
|
|
|
// 如果目录不存在就创建
|
|
|
|
|
|
Directory.CreateDirectory(target);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string sFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + formFile.FileName;
|
|
|
|
|
|
target = Path.Combine(target, sFileName);
|
|
|
|
|
|
using (var stream = formFile.OpenReadStream())
|
|
|
|
|
|
{
|
|
|
|
|
|
FileStream targetFileStream = new FileStream(target, FileMode.Create, FileAccess.Write);
|
|
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
|
|
int bytesRead;
|
|
|
|
|
|
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
targetFileStream.Write(buffer, 0, bytesRead);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//2.0 解析excel
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var uploadList = stream.Query<QcYidaExcel>(sheetName: "数据上传宜搭计划", startCell: "A3").ToList();
|
|
|
|
|
|
|
|
|
|
|
|
int data = uploadservcie.GOcloud(uploadList, HttpContext.GetName());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return SUCCESS(data);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ToResponse(ResultCode.GLOBAL_ERROR, "内容错误,请仔细检测格式,并联系管理员" + ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|