模板导出成功
This commit is contained in:
@@ -1,7 +1,21 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Aliyun.OSS;
|
||||
using AutoMapper.Configuration.Conventions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Hosting.Internal;
|
||||
using MimeKit;
|
||||
using MiniExcelLibs;
|
||||
using MiniExcelLibs.OpenXml;
|
||||
using Model.DBModel;
|
||||
using Org.BouncyCastle.Crypto.IO;
|
||||
using System.IO;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.mes.pro;
|
||||
using ZR.Model.MES.pro.DTO;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Service.mes.pro;
|
||||
using ZR.Service.mes.pro.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.mes.pro
|
||||
@@ -71,7 +85,23 @@ namespace ZR.Admin.WebApi.Controllers.mes.pro
|
||||
|
||||
return ToResponse(new ApiResult(200, "success", data));
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除本周所有计划
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("deleteAll")]
|
||||
public IActionResult DeleteAllItem(int? year,int? week)
|
||||
{
|
||||
int data = 0;
|
||||
if (week!=null&&week>0)
|
||||
{
|
||||
if (year != null && year > 0)
|
||||
data = proWorkplanService.DeleteAllWorkPlan((int)year,(int)week);
|
||||
}
|
||||
|
||||
return ToResponse(new ApiResult(200, "success", data));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -93,5 +123,131 @@ namespace ZR.Admin.WebApi.Controllers.mes.pro
|
||||
return ToResponse(new ApiResult(200, "success", data));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生产计划模板下载
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("importTemplate")]
|
||||
[Log(Title = "生产计划模板模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)]
|
||||
[AllowAnonymous] //不需要授权 就可以访问
|
||||
public IActionResult ImportTemplateExcel()
|
||||
{
|
||||
(string, string) result = DownloadImportTemplate("周生产计划模板");//返回文件名和路径
|
||||
return ExportExcel(result.Item2, result.Item1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取周汇总
|
||||
/// </summary>
|
||||
/// <param name="year"></param>
|
||||
/// <param name="week"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getWeekSummary")]
|
||||
public IActionResult GetWeekSummary(int? year, int? week)
|
||||
{
|
||||
if (year == null && week == null)
|
||||
{
|
||||
return SUCCESS(0);
|
||||
}
|
||||
WorkplanSummaryDto workplanSummaryDto = proWorkplanService.GetWeekSummary((int)year, (int)week);
|
||||
return SUCCESS(workplanSummaryDto);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <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, bool updateSupport)
|
||||
{
|
||||
//1.0 读取excel 文件 保存在指定位置
|
||||
IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
|
||||
string sFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + formFile.FileName;
|
||||
string target = Path.Combine(webHostEnvironment.WebRootPath, "workplan", sFileName);
|
||||
int year = 0;
|
||||
int week = 0;
|
||||
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
|
||||
//读取第一行 解析 年和月
|
||||
var row = stream.Query().Take(1).First();
|
||||
year = Convert.ToInt32(row.A);
|
||||
|
||||
week = Convert.ToInt32(row.B);
|
||||
|
||||
|
||||
//读取列表数据
|
||||
try
|
||||
{
|
||||
var list = stream.Query<ProWorklplan_v2>(sheetName: "Sheet1", startCell: "B3")
|
||||
.Where(it => it.Partnumber != null)
|
||||
.Where(it => !it.Partnumber.Contains("合计"))
|
||||
.Where(it => it.RequireNum > 0)
|
||||
.ToList();
|
||||
list.ForEach(it =>
|
||||
{
|
||||
it.ToCreate(HttpContext);
|
||||
it.Year = year;
|
||||
it.Week = week;
|
||||
|
||||
});
|
||||
string result = proWorkplanService.ImportExceldata(list);
|
||||
return SUCCESS(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ToResponse(ResultCode.GLOBAL_ERROR,"模板内容错误,请仔细检测格式,并联系管理员"+ex.Message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return SUCCESS(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 浏览器下载 生产计划
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("downloadWorkplan")]
|
||||
[Log(Title = "下载生产计划", BusinessType = BusinessType.EXPORT)]
|
||||
public IActionResult UserExport(int? year, int? week)
|
||||
{
|
||||
if (year == null || week == null)
|
||||
{
|
||||
return SUCCESS(0);
|
||||
}
|
||||
var result = proWorkplanService.ExportExceldata((int)year, (int)week);
|
||||
|
||||
|
||||
return ExportExcel(result.Item2, result.Item1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user