355 lines
12 KiB
C#
355 lines
12 KiB
C#
using Infrastructure.Extensions;
|
|
using JinianNet.JNTemplate;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
using MiniExcelLibs;
|
|
using Model.DBModel;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using SqlSugar;
|
|
using System.Text.Json;
|
|
using ZR.Admin.WebApi.Extensions;
|
|
using ZR.Admin.WebApi.Filters;
|
|
|
|
using ZR.Model.MES.pro;
|
|
using ZR.Model.MES.pro.DTO;
|
|
using ZR.Service.mes.pro;
|
|
using ZR.Service.mes.pro.IService;
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
|
|
namespace ZR.Admin.WebApi.Controllers.mes.pro
|
|
{
|
|
[Route("mes/pro/workorder_v2")]
|
|
public class ProWorkorderV2Controller : BaseController
|
|
{
|
|
|
|
|
|
private readonly IProWorkorderServiceV2 proWorkorderService;
|
|
|
|
|
|
|
|
public ProWorkorderV2Controller(IProWorkorderServiceV2 proWorkorderService)
|
|
{
|
|
this.proWorkorderService = proWorkorderService;
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("getWorkoderList")]
|
|
public IActionResult GetWorkorderList(int pageNum, int pageSize, int year = -1, int week = -1, int date = -1)
|
|
{
|
|
(List<ProWorkOrder>, int) data = proWorkorderService.GetWorkorderList(pageNum, pageSize, year, week, date, 0);
|
|
|
|
return ToResponse(new ApiResult(200, "success", data));
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("getWorkoderList_piliang")]
|
|
public IActionResult GetWorkorderList_Piliang(int pageNum, int pageSize, int year = -1, int week = -1, int date = -1)
|
|
{
|
|
(List<ProWorkorder_v2>, int) data = proWorkorderService.GetWorkorderList_Piliang(pageNum, pageSize, year, week, date, 0);
|
|
|
|
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="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, "workorder", sFileName);
|
|
int year = 0;
|
|
int week = 0;
|
|
int date = 0;
|
|
if (!Directory.Exists(Path.Combine(webHostEnvironment.WebRootPath, "workorder")))
|
|
{
|
|
// 如果目录不存在就创建
|
|
Directory.CreateDirectory(Path.Combine(webHostEnvironment.WebRootPath, "workorder"));
|
|
|
|
}
|
|
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().Skip(1).First();
|
|
year = Convert.ToInt32(row.A);
|
|
week = Convert.ToInt32(row.B);
|
|
date = Convert.ToInt32(row.C);
|
|
var list = stream.Query<ProWorkorder_v2>(sheetName: "Sheet1", startCell: "A3").ToList(); ;
|
|
|
|
|
|
foreach (ProWorkorder_v2 item in list)
|
|
{
|
|
if (item.BlankNumber == null)
|
|
item.BlankNumber = "";
|
|
if (item.FinishedPartNumber == null)
|
|
item.FinishedPartNumber = "";
|
|
if (item.ProductDescription == null)
|
|
item.ProductDescription = "";
|
|
if (item.Colour == null)
|
|
item.Colour = "";
|
|
|
|
if (item.Specifications == null)
|
|
item.Specifications = "";
|
|
if (item.CylinderNumber == null)
|
|
item.CylinderNumber = "";
|
|
if (item.Remark1 == null)
|
|
item.Remark1 = "";
|
|
if (item.Remark2 == null)
|
|
item.Remark2 = "";
|
|
if (item.Remark3 == null)
|
|
item.Remark3 = "";
|
|
if (item.Remark4 == null)
|
|
item.Remark4 = "";
|
|
if (item.ClientWorkorder == null)
|
|
item.ClientWorkorder = "";
|
|
item.ToCreate(HttpContext);
|
|
item.Year = year;
|
|
item.Week = week;
|
|
item.Date = date;
|
|
}
|
|
var final_list = list.Where(it => !it.BlankNumber.Contains("圈数"))
|
|
.Where(it => !(it.BlankNumber == "" && it.FinishedPartNumber == "" && it.ProductDescription == "" && it.Specifications == "" && it.CylinderNumber == "" && it.Remark1 == "" && it.Remark2== "" && it.Remark3 == "" && it.Remark4== ""&&it.ClientWorkorder==""))
|
|
.ToList();
|
|
|
|
string result = proWorkorderService.ImportExceldata(final_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("downloadWorkorder")]
|
|
[Log(Title = "下载生产工单", BusinessType = BusinessType.EXPORT)]
|
|
public IActionResult UserExport(int? year, int? week, int? date)
|
|
{
|
|
if (year == null || week == null || date == null)
|
|
{
|
|
return SUCCESS(0);
|
|
}
|
|
var result = proWorkorderService.ExportExceldata((int)year, (int)week, (int)date);
|
|
|
|
|
|
return ExportExcel(result.Item2, result.Item1);
|
|
}
|
|
/// <summary>
|
|
/// 删除本周所有计划
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("deleteAll")]
|
|
public IActionResult DeleteAllItem(int? year, int? week, int? date)
|
|
{
|
|
int data = 0;
|
|
if (week != null && week > 0)
|
|
{
|
|
if (year != null && year > 0)
|
|
data = proWorkorderService.DeleteAllWorkorder((int)year, (int)week, (int)date);
|
|
}
|
|
|
|
return ToResponse(new ApiResult(200, "success", data));
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 新增生产工单
|
|
/// </summary>
|
|
/// <param name="proWorkplan">生产工单对象</param>
|
|
/// <returns></returns>
|
|
[HttpPost("addworkorder")]
|
|
public IActionResult AddWorkOrder([FromBody] ProWorkorder_v2 proWorkorder)
|
|
{
|
|
int data = 0;
|
|
if (proWorkorder != null)
|
|
{
|
|
proWorkorder.ToCreate(HttpContext);
|
|
data = proWorkorderService.AddWorkOrder(proWorkorder);
|
|
}
|
|
|
|
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 = proWorkorderService.DeleteWorkOrder(id);
|
|
}
|
|
|
|
return ToResponse(new ApiResult(200, "success", data));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 更新生产计划
|
|
/// </summary>
|
|
/// <param name="proWorkplan">生产计划对象</param>
|
|
/// <returns></returns>
|
|
[HttpPost("updateworkorder")]
|
|
public IActionResult UpdateWorkOrder([FromBody] ProWorkorder_v2 proWorkorder)
|
|
{
|
|
int data = 0;
|
|
if (proWorkorder != null)
|
|
{
|
|
proWorkorder.ToUpdate(HttpContext);
|
|
data = proWorkorderService.UpdateWorkOrder(proWorkorder);
|
|
|
|
}
|
|
|
|
return ToResponse(new ApiResult(200, "success", data));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 根据工单顺序 排序
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("updateSort")]
|
|
public IActionResult UpdateSort(string id, int? sort)
|
|
{
|
|
int data = 0;
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
|
|
data = proWorkorderService.UpdateworkorderSort(id, (int)sort);
|
|
|
|
|
|
}
|
|
|
|
return ToResponse(new ApiResult(200, "success", data));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据工单顺序 排序(排序掉转)
|
|
/// </summary>
|
|
/// <param name="oldId">初始序号</param>
|
|
/// <param name="oldSort">初始排序</param>
|
|
/// <param name="newId">放入序号</param>
|
|
/// <param name="newSort">放入排序</param>
|
|
/// <returns></returns>
|
|
[HttpGet("updateSort2")]
|
|
public IActionResult UpdateSort2(string oldId, int oldSort, string newId, int newSort)
|
|
{
|
|
int result = 0;
|
|
if (string.IsNullOrEmpty(oldId)&& string.IsNullOrEmpty(newId))
|
|
{
|
|
return ToResponse(new ApiResult(400, "updateSortError", "排序参数异常"));
|
|
}
|
|
result = proWorkorderService.UpdateworkorderSort2(oldId, oldSort, newId, newSort);
|
|
return ToResponse(new ApiResult(200, "success", result));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 工单开始上线
|
|
/// </summary>
|
|
/// <param name="id">工单ID</param>
|
|
/// <returns></returns>
|
|
[HttpGet("startOnline/{id}")]
|
|
public IActionResult StartOnline(string id)
|
|
{
|
|
int data = 0;
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
data = proWorkorderService.StartWorkOrder(id);
|
|
}
|
|
|
|
return ToResponse(new ApiResult(200, "success", data));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 工单下线
|
|
/// </summary>
|
|
/// <param name="id">工单ID</param>
|
|
/// <returns></returns>
|
|
[HttpGet("cancelOnline/{id}")]
|
|
public IActionResult CancelOnline(string id)
|
|
{
|
|
int data = 0;
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
data = proWorkorderService.CancelWorkOrder(id);
|
|
}
|
|
|
|
return ToResponse(new ApiResult(200, "success", data));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 生成工单号
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("generateWorkorder")]
|
|
public IActionResult GenerateWorkorder(int? year, int? week, int? date)
|
|
{
|
|
int data = 0;
|
|
data = proWorkorderService.GenerateWorkorder((int)year, (int)week, (int)date);
|
|
return ToResponse(new ApiResult(200, "success", data));
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|