250 lines
8.7 KiB
C#
250 lines
8.7 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using MiniExcelLibs;
|
|
using Model.DBModel;
|
|
using ZR.Admin.WebApi.Extensions;
|
|
using ZR.Model.MES.pro.DTO;
|
|
using ZR.Service.mes.pro.IService;
|
|
|
|
namespace ZR.Admin.WebApi.Controllers.mes.pro
|
|
{
|
|
[Route("mes/pro/workplan_v2")]
|
|
public class ProWorkplanV2Controller : BaseController
|
|
{
|
|
|
|
private readonly IProWorkplanServiceV2 proWorkplanService;
|
|
|
|
public ProWorkplanV2Controller(IProWorkplanServiceV2 proWorkplanService)
|
|
{
|
|
this.proWorkplanService = proWorkplanService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取生产计划列表
|
|
/// </summary>
|
|
/// <param name="pageNum">页编号</param>
|
|
/// <param name="pageSize">页大小</param>
|
|
/// <param name="year">年份</param>
|
|
/// <param name="week">周数</param>
|
|
/// <param name="partNumber">零件号</param>
|
|
/// <param name="color">颜色</param>
|
|
/// <returns></returns>
|
|
[HttpGet("list")]
|
|
public IActionResult List(int pageNum, int pageSize, int year = -1, int week = -1, string partNumber = "", string color = "")
|
|
{
|
|
(List<ProWorklplanDto>, int) data = proWorkplanService.GetAllData(pageNum, pageSize, year, week, partNumber, color);
|
|
return ToResponse(new ApiResult(200, "success", data));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 新增生产计划
|
|
/// </summary>
|
|
/// <param name="proWorkplan">生产计划对象</param>
|
|
/// <returns></returns>
|
|
[HttpPost("addworkplan")]
|
|
public IActionResult AddWorkPlan([FromBody] ProWorklplan_v2 proWorkplan)
|
|
{
|
|
int data = 0;
|
|
if (proWorkplan != null)
|
|
{
|
|
proWorkplan.ToCreate(HttpContext);
|
|
data = proWorkplanService.AddWorkPlan(proWorkplan);
|
|
}
|
|
|
|
return ToResponse(new ApiResult(200, "success", data));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 删除生产计划
|
|
/// </summary>
|
|
/// <param name="id">计划ID</param>
|
|
/// <returns></returns>
|
|
[HttpGet("deleteitem/{id}")]
|
|
public IActionResult DeleteItem(string id)
|
|
{
|
|
int data = 0;
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
data = proWorkplanService.DeleteWorkPlan(id);
|
|
}
|
|
|
|
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>
|
|
/// 更新生产计划
|
|
/// </summary>
|
|
/// <param name="proWorkplan">生产计划对象</param>
|
|
/// <returns></returns>
|
|
[HttpPost("updateworkplan")]
|
|
public IActionResult UpdateWorkPlan([FromBody] ProWorklplan_v2 proWorkplan)
|
|
{
|
|
int data = 0;
|
|
if (proWorkplan != null)
|
|
{
|
|
proWorkplan.ToUpdate(HttpContext);
|
|
data = proWorkplanService.UpdateWorkPlan(proWorkplan);
|
|
|
|
}
|
|
|
|
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);
|
|
if (!Directory.Exists(Path.Combine(webHostEnvironment.WebRootPath, "workplan")))
|
|
{
|
|
Directory.CreateDirectory(Path.Combine(webHostEnvironment.WebRootPath, "workplan"));
|
|
}
|
|
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);
|
|
}
|
|
|
|
|
|
|
|
|
|
//读取列表数据
|
|
try
|
|
{
|
|
//2.0 解析excel
|
|
//读取第一行 解析 年和月
|
|
var row = stream.Query().Take(1).First();
|
|
year = Convert.ToInt32(row.A);
|
|
week = Convert.ToInt32(row.B);
|
|
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;
|
|
it.NoSchedule = it.RequireNum;
|
|
|
|
});
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生产计划检查
|
|
/// </summary>
|
|
/// <param name="proWorkplan">生产计划对象</param>
|
|
/// <returns></returns>
|
|
[HttpPost("checkWorkPlan")]
|
|
public IActionResult CheckWorkPlan([FromBody] ProWorklplan_v2 proWorkplan)
|
|
{
|
|
try
|
|
{
|
|
int result = proWorkplanService.CheckWorkPlan(proWorkplan);
|
|
return ToResponse(new ApiResult(200, "success", result));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ToResponse(new ApiResult(500, ex.Message, 0));
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|