shgx_tz_mom/ZR.Admin.WebApi/Controllers/mes/pro/ProWorkplanV2Controller.cs

250 lines
8.7 KiB
C#
Raw Normal View History

2024-06-07 11:04:26 +08:00
using Microsoft.AspNetCore.Mvc;
2024-01-20 14:37:32 +08:00
using MiniExcelLibs;
2024-01-13 16:14:34 +08:00
using Model.DBModel;
2024-01-15 20:04:50 +08:00
using ZR.Admin.WebApi.Extensions;
2024-01-20 14:37:32 +08:00
using ZR.Model.MES.pro.DTO;
2024-01-13 16:14:34 +08:00
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 = "")
{
2024-05-31 13:22:07 +08:00
(List<ProWorklplanDto>, int) data = proWorkplanService.GetAllData(pageNum, pageSize, year, week, partNumber, color);
2024-01-13 16:14:34 +08:00
return ToResponse(new ApiResult(200, "success", data));
}
2024-01-15 20:04:50 +08:00
/// <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));
}
2024-01-20 14:37:32 +08:00
/// <summary>
/// 删除本周所有计划
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("deleteAll")]
2024-06-07 11:04:26 +08:00
public IActionResult DeleteAllItem(int? year, int? week)
2024-01-20 14:37:32 +08:00
{
int data = 0;
2024-06-07 11:04:26 +08:00
if (week != null && week > 0)
2024-01-20 14:37:32 +08:00
{
if (year != null && year > 0)
2024-06-07 11:04:26 +08:00
data = proWorkplanService.DeleteAllWorkPlan((int)year, (int)week);
2024-01-20 14:37:32 +08:00
}
2024-01-15 20:04:50 +08:00
2024-01-20 14:37:32 +08:00
return ToResponse(new ApiResult(200, "success", data));
}
2024-01-15 20:04:50 +08:00
/// <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));
}
2024-01-20 14:37:32 +08:00
/// <summary>
/// 生产计划模板下载
/// </summary>
/// <returns></returns>
[HttpGet("importTemplate")]
[Log(Title = "生产计划模板模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)]
[AllowAnonymous] //不需要授权 就可以访问
public IActionResult ImportTemplateExcel()
{
2024-01-24 16:15:23 +08:00
(string, string) result = DownloadImportTemplate("周计划标准模板");//返回文件名和路径
2024-01-20 14:37:32 +08:00
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);
2024-01-31 17:51:45 +08:00
if (!Directory.Exists(Path.Combine(webHostEnvironment.WebRootPath, "workplan")))
2024-01-26 16:59:00 +08:00
{
2024-01-31 17:51:45 +08:00
Directory.CreateDirectory(Path.Combine(webHostEnvironment.WebRootPath, "workplan"));
2024-01-26 16:59:00 +08:00
}
2024-01-20 14:37:32 +08:00
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);
}
2024-06-07 11:04:26 +08:00
2024-01-20 14:37:32 +08:00
//读取列表数据
try
{
2024-01-26 16:59:00 +08:00
//2.0 解析excel
//读取第一行 解析 年和月
var row = stream.Query().Take(1).First();
year = Convert.ToInt32(row.A);
week = Convert.ToInt32(row.B);
2024-01-20 14:37:32 +08:00
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;
2024-01-26 16:59:00 +08:00
it.NoSchedule = it.RequireNum;
2024-01-20 14:37:32 +08:00
});
string result = proWorkplanService.ImportExceldata(list);
return SUCCESS(result);
}
catch (Exception ex)
{
2024-06-07 11:04:26 +08:00
return ToResponse(ResultCode.GLOBAL_ERROR, "内容错误,请仔细检测格式,并联系管理员" + ex.Message);
2024-01-20 14:37:32 +08:00
}
}
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);
}
2024-05-31 13:22:07 +08:00
/// <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));
}
}
2024-01-20 14:37:32 +08:00
2024-01-13 16:14:34 +08:00
}
}