using DOAN.Admin.WebApi.Filters;
using DOAN.Model;
using DOAN.Model.MES.base_.Dto;
using DOAN.Model.MES.product;
using DOAN.Model.MES.product.Dto;
using DOAN.Service.MES.product.IService;
using Infrastructure.Converter;
using Microsoft.AspNetCore.Mvc;
//创建时间:2024-07-16
namespace DOAN.Admin.WebApi.Controllers
{
///
/// 生产工单
///
[Verify]
[Route("mes/productManagement/ProWorkorder")]
public class ProWorkorderController : BaseController
{
///
/// 生产工单接口
///
private readonly IProWorkorderService _ProWorkorderService;
///
/// 工单物料接口
///
private readonly IProWorkorderMaterialService _ProWorkorderMaterialService;
public ProWorkorderController(
IProWorkorderService ProWorkorderService,
IProWorkorderMaterialService ProWorkorderMaterialService
)
{
_ProWorkorderService = ProWorkorderService;
_ProWorkorderMaterialService = ProWorkorderMaterialService;
}
///
/// 查询生产工单列表 启用(9/14)
///
///
///
[HttpPost("list")]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:list")]
public IActionResult QueryProWorkorder([FromBody] ProWorkorderQueryDto parm)
{
var response = _ProWorkorderService.GetList(parm);
return SUCCESS(response);
}
///
/// 查询生产工单列表 启用(9/14) 没有校验
///
///
///
[HttpPost("list_nocheck")]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:list")]
public IActionResult QueryProWorkorder_NOCheck([FromBody] ProWorkorderQueryDto parm)
{
parm.WorkorderDate[0] = DOANConvertDate.ConvertLocalDate(parm.WorkorderDate[0]);
parm.WorkorderDate[1] = DOANConvertDate.ConvertLocalDate(parm.WorkorderDate[1]);
var response = _ProWorkorderService.GetList_NOCheck(parm);
return SUCCESS(response);
}
///
/// 查询生产工单详情
///
///
///
[HttpGet("{Id}")]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:query")]
public IActionResult GetProWorkorder(string Id)
{
var response = _ProWorkorderService.GetInfo(Id);
var info = response.Adapt();
return SUCCESS(info);
}
///
/// 添加生产工单
///
///
[HttpPost]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:add")]
[Log(Title = "生产工单", BusinessType = BusinessType.INSERT)]
public IActionResult AddProWorkorder([FromBody] ProWorkorderDto parm)
{
var modal = parm.Adapt().ToCreate(HttpContext);
var response = _ProWorkorderService.AddProWorkorder(modal);
return SUCCESS(response);
}
///
/// 更新生产工单 启用(9/14)
///
///
[HttpPut]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:edit")]
[Log(Title = "修改工单", BusinessType = BusinessType.UPDATE)]
public IActionResult UpdateProWorkorder([FromBody] ProWorkorderDto parm)
{
var modal = parm.Adapt().ToUpdate(HttpContext);
var response = _ProWorkorderService.UpdateProWorkorder(modal);
return ToResponse(response);
}
///
/// 删除生产工单 启用(9/14)
///
///
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:delete")]
[Log(Title = "删除工单", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteProWorkorder(string ids)
{
string[] idsArr = Tools.SpitStrArrary(ids);
if (idsArr.Length <= 0)
{
return ToResponse(ApiResult.Error($"删除失败Id 不能为空"));
}
var response = _ProWorkorderService.Delete(idsArr);
return ToResponse(response);
}
/////
///// 生成工单号
/////
/////
///// 生成工单号 数量
//[HttpPost("Generate_workorder")]
//public IActionResult Generate_workorder([FromBody] ProWorkorderQueryDto2 parm)
//{
// if (parm.WorkorderDate <= DateTime.MinValue)
// {
// SUCCESS(null);
// }
// var response = _ProWorkorderService.Generate_workorder(parm);
// return SUCCESS(response);
//}
///
/// 插入工单/或者新增工单 启用(9/14)
///
///
/// 1成功 0失败
[HttpPost("insert_workorder")]
[Log(Title = "插入工单/或者新增工单", BusinessType = BusinessType.INSERT)]
public IActionResult Insert_workOrder([FromBody] ProWorkorderDto2 parm)
{
if (parm == null)
{
return SUCCESS(null);
}
ProWorkorder newparm = parm.Adapt().ToCreate(HttpContext);
var response = _ProWorkorderService.Insert_workOrder(newparm, parm.next_id);
return SUCCESS(response);
}
///
/// 移动工单
///
/// 1上 2下
///
///
[HttpGet("move_workorder")]
[Log(Title = "移动工单", BusinessType = BusinessType.INSERT)]
public IActionResult MoveWorkorder(string id, int type)
{
if (string.IsNullOrEmpty(id))
{
return SUCCESS(null);
}
var response = _ProWorkorderService.MoveWorkorder(id, type);
return SUCCESS(response);
}
///
/// 生产工单导入模板下载 workorder 启用(9/14)
///
///
[HttpGet("importTemplate")]
[Log(
Title = "生产工单导入模板",
BusinessType = BusinessType.EXPORT,
IsSaveRequestData = true,
IsSaveResponseData = false
)]
[AllowAnonymous]
public IActionResult ImportTemplateExcel()
{
(string, string) result = DownloadImportTemplate("workorder");
return ExportExcel(result.Item2, result.Item1);
}
///
/// 导入 启用(9/14)
///
/// 使用IFromFile必须使用name属性否则获取不到文件
/// 导入成功数 若-1 则excel读取异常
[HttpPost("importData")]
[Log(
Title = "生产工单导入",
BusinessType = BusinessType.IMPORT,
IsSaveRequestData = false,
IsSaveResponseData = true
)]
[AllowAnonymous]
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
{
try
{
if (formFile == null)
{
return SUCCESS(null);
}
int response = _ProWorkorderService.ImportData(formFile, HttpContext.GetName());
return SUCCESS(response);
}
catch (Exception ex)
{
return ToResponse(new ApiResult(500, ex.Message));
}
}
//TODO 分批导入工单,追加工单
[HttpPost("importData_append")]
[Log(
Title = "生产工单导入",
BusinessType = BusinessType.IMPORT,
IsSaveRequestData = false,
IsSaveResponseData = true
)]
[AllowAnonymous]
public IActionResult ImportDataAppend([FromForm(Name = "file")] IFormFile formFile)
{
try
{
if (formFile == null)
{
return SUCCESS(null);
}
int response = _ProWorkorderService.ImportDataAppend(
formFile,
HttpContext.GetName()
);
return SUCCESS(response);
}
catch (Exception ex)
{
return ToResponse(new ApiResult(500, ex.Message));
}
}
///
/// 工单导出 启用(9/14)
///
///
///
[HttpGet("export")]
[Log(Title = "工单导出", BusinessType = BusinessType.EXPORT)]
[AllowAnonymous]
public IActionResult WorkOrderExport([FromQuery] DateTime extportDate)
{
if (extportDate == DateTime.MinValue)
{
return SUCCESS(null);
}
var list = _ProWorkorderService.WorkOrderExport(extportDate);
var result = ExportExcelMini(list, "workorder", "工单列表");
return ExportExcel(result.Item2, result.Item1);
}
//TODO 获取物料
[HttpPost("get_material")]
public IActionResult GetMaterialInfo([FromBody] BaseMaterialListQueryDto5 query)
{
if (query == null)
{
return SUCCESS(null);
}
var response = _ProWorkorderService.GetMaterialInfo(query);
return SUCCESS(response);
}
//TODO 获取客户
[HttpPost("get_custom")]
public IActionResult GetCustomInfo([FromBody] BaseCustomQueryDto2 parm)
{
if (parm == null)
{
return SUCCESS(null);
}
var response = _ProWorkorderService.GetCustomInfo(parm);
return SUCCESS(response);
}
//TODO 获取指定日期工艺路线
[HttpGet("get_process_route")]
public IActionResult GetProcessRoute(DateTime dateTime)
{
if (dateTime == DateTime.MinValue)
{
return SUCCESS(null);
}
var response = _ProWorkorderService.GetProcessRoute(dateTime);
return SUCCESS(response);
}
//TODO 获取全部工艺路线 启用(9/14)
[HttpGet("get_all_route")]
public IActionResult GetAllRoute()
{
var response = _ProWorkorderService.GetAllRoute();
return SUCCESS(response);
}
//TODO 获取组
//[HttpGet("get_groups")]
//public IActionResult GetGroupList(string route_code,DateTime dateTime)
//{
// if (string.IsNullOrEmpty(route_code)) { return SUCCESS(null); }
// if (dateTime == DateTime.MinValue)
// {
// return SUCCESS(null);
// }
// var response = _ProWorkorderService.GetGroupList(route_code, dateTime);
// return SUCCESS(response);
//}
// 启用(9/14)
[HttpGet("get_groups")]
public IActionResult GetGroupList()
{
var response = _ProWorkorderService.GetGroupList();
return SUCCESS(response);
}
//TODO 查询BOM 及其所需数量
///
/// 查询BOM 及其所需数量
///
/// 工单号
///
[HttpGet("search_BOM_num")]
public IActionResult SearchBOMNum(string workorder_num)
{
if (string.IsNullOrEmpty(workorder_num))
{
return SUCCESS(null);
}
var response = _ProWorkorderService.SearchBOMNum(workorder_num);
return SUCCESS(response);
}
//TODO 工单变更日志
[HttpGet("workorder_log")]
public IActionResult WorkOrderLog(string workorder)
{
if (string.IsNullOrEmpty(workorder))
{
return SUCCESS(null);
}
var response = _ProWorkorderService.WorkOrderLog(workorder);
return SUCCESS(response);
}
//TODO 获取工单进度追溯
[HttpPost("get_workorder_trace_progress")]
public IActionResult GetWorkorderTraceProgressList([FromBody] ProWorkorderQueryDto query)
{
query.WorkorderDate[0] = DOANConvertDate.ConvertLocalDate(query.WorkorderDate[0]);
query.WorkorderDate[1] = DOANConvertDate.ConvertLocalDate(query.WorkorderDate[1]);
if (query == null)
{
throw new Exception("query为空");
}
var response = _ProWorkorderService.GetWorkorderTraceProgressList(query);
return SUCCESS(response);
}
//TODO 打印机打印工单
[HttpPost("print")]
[AllowAnonymous]
public IActionResult ExportWorkorderPDF([FromBody] ProWorkorderExportDto param)
{
try
{
if (param.WorkorderArray == null || param.WorkorderArray.Length < 1)
{
return ToResponse(500, "工单列表为空");
}
param.Path = "D:/mes/Label/Trace.btw";
//Task<(string, Stream)> conntext = _ProWorkorderService.ExportPDFByQuestPDFDemo(workorderArray);
var result = _ProWorkorderService.PrintTicketsByTemplate(param);
if (result == "ok")
{
return ToResponse(new ApiResult(200, result));
}
else
{
return ToResponse(new ApiResult(500, result));
}
//return File(conntext.Result.Item2, "application/pdf", HttpUtility.UrlEncode(conntext.Result.Item1));
}
catch (Exception ex)
{
return ToResponse(new ApiResult(500, ex.Message));
}
}
///
/// 获取工单生产进度
///
/// 工单号
///
[HttpGet("getWorkorderWithProgress/{workorder}")]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:query")]
public IActionResult GetWorkorderWithProgress(string workorder)
{
try
{
var response = _ProWorkorderService.GetWorkorderWithProgress(workorder);
return SUCCESS(response);
}
catch (Exception ex)
{
return ToResponse(new ApiResult(500, ex.Message));
}
}
///
/// 根据工单号查询领料清单
///
/// 工单号
/// 领料清单数据
[HttpGet("GetMaterialTakeList/{workorder}")]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:query")]
public IActionResult GetMaterialTakeList(string workorder)
{
try
{
if (string.IsNullOrEmpty(workorder))
{
return ToResponse(ApiResult.Error($"工单号不能为空"));
}
var response = _ProWorkorderMaterialService.GetMaterialTakeList(workorder);
return SUCCESS(response);
}
catch (Exception ex)
{
return ToResponse(new ApiResult(500, ex.Message));
}
}
///
/// 根据工单号查询成品入库清单
///
/// 工单号
/// 成品入库清单数据
[HttpGet("GetProductStorageList/{workorder}")]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:query")]
public IActionResult GetProductStorageList(string workorder)
{
try
{
if (string.IsNullOrEmpty(workorder))
{
return ToResponse(ApiResult.Error($"工单号不能为空"));
}
var response = _ProWorkorderMaterialService.GetProductStorageList(workorder);
return SUCCESS(response);
}
catch (Exception ex)
{
return ToResponse(new ApiResult(500, ex.Message));
}
}
///
/// 根据工单号查询出货清单
///
/// 工单号
/// 出货清单数据
[HttpGet("GetShipmentList/{workorder}")]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:query")]
public IActionResult GetShipmentList(string workorder)
{
try
{
if (string.IsNullOrEmpty(workorder))
{
return ToResponse(ApiResult.Error($"工单号不能为空"));
}
var response = _ProWorkorderMaterialService.GetShipmentList(workorder);
return SUCCESS(response);
}
catch (Exception ex)
{
return ToResponse(new ApiResult(500, ex.Message));
}
}
///
/// 根据工单号查询物料库存
///
/// 工单号
/// 物料库存信息列表
[HttpGet("GetMaterialInventoryList/{workorder}")]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:query")]
public IActionResult GetMaterialInventoryList(string workorder)
{
try
{
if (string.IsNullOrEmpty(workorder))
{
return ToResponse(ApiResult.Error($"工单号不能为空"));
}
var response = _ProWorkorderMaterialService.GetMaterialInventoryList(workorder);
return SUCCESS(response);
}
catch (Exception ex)
{
return ToResponse(new ApiResult(500, ex.Message));
}
}
///
/// 领料接口
///
/// 领料请求参数
/// 操作结果
[HttpPost("TakeMaterial")]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:edit")]
[Log(Title = "领料操作", BusinessType = BusinessType.UPDATE)]
public IActionResult TakeMaterial([FromBody] MaterialTakeRequestDto request)
{
try
{
if (request == null)
{
return ToResponse(ApiResult.Error($"领料请求参数不能为空"));
}
var response = _ProWorkorderMaterialService.TakeMaterial(request);
return SUCCESS(response);
}
catch (Exception ex)
{
return ToResponse(new ApiResult(500, ex.Message));
}
}
///
/// 成品入库接口
///
/// 成品入库请求参数
/// 操作结果
[HttpPost("StoreProduct")]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:edit")]
[Log(Title = "成品入库操作", BusinessType = BusinessType.UPDATE)]
public IActionResult StoreProduct([FromBody] ProductStorageRequestDto request)
{
try
{
if (request == null)
{
return ToResponse(ApiResult.Error($"成品入库请求参数不能为空"));
}
var response = _ProWorkorderMaterialService.StoreProduct(request);
return SUCCESS(response);
}
catch (Exception ex)
{
return ToResponse(new ApiResult(500, ex.Message));
}
}
///
/// 出货接口
///
/// 出货请求参数
/// 操作结果
[HttpPost("ShipProduct")]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:edit")]
[Log(Title = "出货操作", BusinessType = BusinessType.UPDATE)]
public IActionResult ShipProduct([FromBody] ShipmentRequestDto request)
{
try
{
if (request == null)
{
return ToResponse(ApiResult.Error($"出货请求参数不能为空"));
}
var response = _ProWorkorderMaterialService.ShipProduct(request);
if (!response)
{
return ToResponse(new ApiResult(500, "出货失败!"));
}
return SUCCESS(response);
}
catch (Exception ex)
{
return ToResponse(new ApiResult(500, ex.Message));
}
}
///
/// 根据工单号获取可领料工单清单
///
/// 工单号
/// 可领料工单清单
[HttpGet("GetPickableWorkordersByWorkorder/{workorder}")]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:query")]
public IActionResult GetPickableWorkordersByWorkorder(string workorder)
{
try
{
if (string.IsNullOrEmpty(workorder))
{
return ToResponse(ApiResult.Error($"工单号不能为空"));
}
var response = _ProWorkorderMaterialService.GetPickableWorkordersByWorkorder(
workorder
);
return SUCCESS(response);
}
catch (Exception ex)
{
return ToResponse(new ApiResult(500, ex.Message));
}
}
///
/// 根据工单号获取可出货订单清单
///
/// 工单号
/// 可出货订单清单
[HttpGet("GetShippableOrdersByWorkorder/{workorder}")]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:query")]
public IActionResult GetShippableOrdersByWorkorder(string workorder)
{
try
{
if (string.IsNullOrEmpty(workorder))
{
return ToResponse(ApiResult.Error($"工单号不能为空"));
}
var response = _ProWorkorderMaterialService.GetShippableOrdersByWorkorder(
workorder
);
return SUCCESS(response);
}
catch (Exception ex)
{
return ToResponse(new ApiResult(500, ex.Message));
}
}
///
/// 根据工单号查询成品库存
///
/// 工单号
/// 成品库存信息列表
[HttpGet("GetProductInventoryList/{workorder}")]
[ActionPermissionFilter(Permission = "productManagement:proworkorder:query")]
public IActionResult GetProductInventoryList(string workorder)
{
try
{
if (string.IsNullOrEmpty(workorder))
{
return ToResponse(ApiResult.Error($"工单号不能为空"));
}
var response = _ProWorkorderMaterialService.GetProductInventoryList(workorder);
return SUCCESS(response);
}
catch (Exception ex)
{
return ToResponse(new ApiResult(500, ex.Message));
}
}
}
}