2023-11-14 11:29:05 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-11-15 08:46:54 +08:00
|
|
|
|
using ZR.Admin.WebApi.Extensions;
|
2023-11-14 11:29:05 +08:00
|
|
|
|
using ZR.Model.mes.md;
|
2023-11-14 14:30:14 +08:00
|
|
|
|
using ZR.Model.mes.pro;
|
|
|
|
|
|
using ZR.Service.mes.pro.IService;
|
2023-11-14 11:29:05 +08:00
|
|
|
|
using ZR.Service.MES.md;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ZR.Admin.WebApi.Controllers.MES.pro
|
|
|
|
|
|
{
|
2023-11-15 14:03:55 +08:00
|
|
|
|
//
|
|
|
|
|
|
//
|
2023-11-14 11:29:05 +08:00
|
|
|
|
|
|
|
|
|
|
[Route("mes/pro/workplan")]
|
|
|
|
|
|
public class ProWorkplanController : BaseController
|
|
|
|
|
|
{
|
2023-11-14 14:30:14 +08:00
|
|
|
|
private readonly IProWorkplanService proWorkplanService;
|
|
|
|
|
|
|
|
|
|
|
|
public ProWorkplanController(IProWorkplanService proWorkplanService)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.proWorkplanService = proWorkplanService;
|
|
|
|
|
|
}
|
2023-11-14 11:29:05 +08:00
|
|
|
|
|
2023-11-15 14:44:07 +08:00
|
|
|
|
/// <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>
|
2023-11-14 11:29:05 +08:00
|
|
|
|
[HttpGet("list")]
|
2023-11-14 18:12:27 +08:00
|
|
|
|
public IActionResult List(int pageNum, int pageSize, int year=-1, int week=-1, string partNumber = "", string color = "")
|
2023-11-14 11:29:05 +08:00
|
|
|
|
{
|
2023-11-14 14:30:14 +08:00
|
|
|
|
(List<ProWorkplan>,int) data = proWorkplanService.GetAllData(pageNum, pageSize, year, week, partNumber, color);
|
2023-11-14 11:29:05 +08:00
|
|
|
|
|
|
|
|
|
|
return ToResponse(new ApiResult(200, "success", data));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-15 14:44:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 新增生产计划
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="proWorkplan">生产计划对象</param>
|
|
|
|
|
|
/// <returns></returns>
|
2023-11-14 16:43:35 +08:00
|
|
|
|
[HttpPost("addworkplan")]
|
2023-11-14 17:02:14 +08:00
|
|
|
|
public IActionResult AddWorkPlan([FromBody] ProWorkplan proWorkplan)
|
2023-11-14 16:43:35 +08:00
|
|
|
|
{
|
|
|
|
|
|
int data = 0;
|
|
|
|
|
|
if (proWorkplan!=null)
|
|
|
|
|
|
{
|
2023-11-15 08:46:54 +08:00
|
|
|
|
proWorkplan.ToCreate(HttpContext);
|
2023-11-15 14:53:20 +08:00
|
|
|
|
data = proWorkplanService.AddWorkPlan(proWorkplan);
|
2023-11-14 16:43:35 +08:00
|
|
|
|
}
|
2023-11-14 11:29:05 +08:00
|
|
|
|
|
2023-11-14 16:43:35 +08:00
|
|
|
|
return ToResponse(new ApiResult(200, "success", data));
|
|
|
|
|
|
}
|
2023-11-14 11:29:05 +08:00
|
|
|
|
|
2023-11-15 14:44:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新生产计划
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="proWorkplan">生产计划对象</param>
|
|
|
|
|
|
/// <returns></returns>
|
2023-11-14 18:46:59 +08:00
|
|
|
|
[HttpPost("updateworkplan")]
|
|
|
|
|
|
public IActionResult UpdateWorkPlan([FromBody] ProWorkplan proWorkplan)
|
|
|
|
|
|
{
|
|
|
|
|
|
int data = 0;
|
|
|
|
|
|
if (proWorkplan != null)
|
|
|
|
|
|
{
|
2023-11-15 08:46:54 +08:00
|
|
|
|
proWorkplan.ToUpdate(HttpContext);
|
2023-11-15 14:53:20 +08:00
|
|
|
|
data = proWorkplanService.UpdateWorkPlan(proWorkplan);
|
|
|
|
|
|
|
2023-11-14 18:46:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ToResponse(new ApiResult(200, "success", data));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-15 14:44:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除生产计划
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id">计划ID</param>
|
|
|
|
|
|
/// <returns></returns>
|
2023-11-14 18:46:59 +08:00
|
|
|
|
[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));
|
|
|
|
|
|
}
|
2023-11-15 14:38:10 +08:00
|
|
|
|
|
2023-11-15 14:44:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取生产工单
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id">计划ID</param>
|
|
|
|
|
|
/// <returns></returns>
|
2023-11-15 14:38:10 +08:00
|
|
|
|
[HttpGet("getworkorderList/{id}")]
|
|
|
|
|
|
public IActionResult GetWorkorderList(string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<ProWorkorder> lst = new List<ProWorkorder>();
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(id))
|
|
|
|
|
|
{
|
|
|
|
|
|
lst = proWorkplanService.GetWorkorderList(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ToResponse(new ApiResult(200, "success", lst));
|
|
|
|
|
|
}
|
2023-11-15 14:53:20 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 新增生产工单
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="proWorkorder">生产工单对象</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost("addworkorder")]
|
|
|
|
|
|
public IActionResult AddWorkorder([FromBody] ProWorkorder proWorkorder)
|
|
|
|
|
|
{
|
2023-11-15 15:36:18 +08:00
|
|
|
|
// TODO 获取工单对象
|
|
|
|
|
|
// TODO 增加插入时间,插入人员:ToCreate
|
|
|
|
|
|
// TODO 根据工单对象里的计划ID,查询生产计划的数量,判断工单数和要小于等于计划数:能插入,正常返回,0或1;大于,2
|
|
|
|
|
|
|
2023-11-15 14:53:20 +08:00
|
|
|
|
int data = 0;
|
|
|
|
|
|
if (proWorkorder != null)
|
|
|
|
|
|
{
|
2023-11-15 17:04:36 +08:00
|
|
|
|
proWorkorder.Id = DateTime.Now.ToString("yyyyMMddHHmmss");
|
2023-11-15 15:36:18 +08:00
|
|
|
|
string workPlanId = proWorkorder.FkProPlanId;
|
|
|
|
|
|
string workorderId = proWorkorder.Id;
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(workPlanId) && !string.IsNullOrEmpty(workorderId))
|
|
|
|
|
|
{
|
|
|
|
|
|
// 查询生产计划对象
|
|
|
|
|
|
List<ProWorkplan> lstWorkplan = proWorkplanService.GetProWorkplanById(workPlanId);
|
|
|
|
|
|
|
|
|
|
|
|
// 查询所有生产工单
|
|
|
|
|
|
List<ProWorkorder> lstWorkorder = proWorkplanService.GetWorkorderList(workorderId);
|
|
|
|
|
|
|
|
|
|
|
|
// 计算所有工单的数量和,生产计划的数量:比较
|
|
|
|
|
|
if(lstWorkplan!=null && lstWorkplan.Count==1)
|
|
|
|
|
|
{
|
|
|
|
|
|
int countWorkplan = int.Parse(lstWorkplan[0].ActualplanNumber.Trim());
|
|
|
|
|
|
int countWorkorder = 0;
|
|
|
|
|
|
foreach (ProWorkorder item in lstWorkorder)
|
|
|
|
|
|
{
|
|
|
|
|
|
countWorkorder += item.Actualnumber.GetValueOrDefault();
|
|
|
|
|
|
}
|
|
|
|
|
|
countWorkorder += proWorkorder.Actualnumber.GetValueOrDefault();
|
|
|
|
|
|
|
|
|
|
|
|
// 计划数>0 计划数要大于等于当前工单总数
|
|
|
|
|
|
if(countWorkplan > 0 && (countWorkplan>= countWorkorder))
|
|
|
|
|
|
{
|
|
|
|
|
|
proWorkorder.ToCreate(HttpContext);
|
|
|
|
|
|
data = proWorkplanService.AddWorkorder(proWorkorder);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
data = 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-11-15 14:53:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ToResponse(new ApiResult(200, "success", data));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新生产工单
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="proWorkorder">生产工单对象</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost("updateworkplan")]
|
|
|
|
|
|
public IActionResult UpdateWorkorder([FromBody] ProWorkorder proWorkorder)
|
|
|
|
|
|
{
|
2023-11-15 15:36:18 +08:00
|
|
|
|
// TODO 判断更新的数量是否超过计划数
|
2023-11-15 14:53:20 +08:00
|
|
|
|
int data = 0;
|
|
|
|
|
|
if (proWorkorder != null)
|
|
|
|
|
|
{
|
2023-11-15 15:36:18 +08:00
|
|
|
|
string workPlanId = proWorkorder.FkProPlanId;
|
2023-11-15 15:47:23 +08:00
|
|
|
|
string workorderId = proWorkorder.Id;
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(workPlanId) && !string.IsNullOrEmpty(workorderId))
|
2023-11-15 15:36:18 +08:00
|
|
|
|
{
|
|
|
|
|
|
// 查询生产计划对象
|
2023-11-15 15:47:23 +08:00
|
|
|
|
List<ProWorkplan> lstWorkplan = proWorkplanService.GetProWorkplanById(workPlanId);
|
2023-11-15 15:36:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 查询所有生产工单
|
2023-11-15 15:47:23 +08:00
|
|
|
|
List<ProWorkorder> lstWorkorder = proWorkplanService.GetWorkorderList(workorderId);
|
2023-11-15 15:36:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 计算所有工单的数量和,生产计划的数量:比较
|
2023-11-15 15:47:23 +08:00
|
|
|
|
if (lstWorkplan != null && lstWorkplan.Count == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
int countWorkplan = int.Parse(lstWorkplan[0].ActualplanNumber.Trim());
|
|
|
|
|
|
int countWorkorder = 0;
|
|
|
|
|
|
foreach (ProWorkorder item in lstWorkorder)
|
|
|
|
|
|
{
|
|
|
|
|
|
countWorkorder += item.Actualnumber.GetValueOrDefault();
|
|
|
|
|
|
}
|
|
|
|
|
|
countWorkorder += proWorkorder.Actualnumber.GetValueOrDefault();
|
2023-11-15 15:36:18 +08:00
|
|
|
|
|
2023-11-15 15:47:23 +08:00
|
|
|
|
// 计划数>0 计划数要大于等于当前工单总数
|
|
|
|
|
|
if (countWorkplan > 0 && (countWorkplan >= countWorkorder))
|
|
|
|
|
|
{
|
|
|
|
|
|
proWorkorder.ToUpdate(HttpContext);
|
|
|
|
|
|
data = proWorkplanService.UpdateWorkorder(proWorkorder);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
data = 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-11-15 15:36:18 +08:00
|
|
|
|
}
|
2023-11-15 14:53:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ToResponse(new ApiResult(200, "success", data));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除生产工单
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id">工单ID</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet("deleteworkorder/{id}")]
|
|
|
|
|
|
public IActionResult DeleteWorkorder(string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
int data = 0;
|
|
|
|
|
|
if (!string.IsNullOrEmpty(id))
|
|
|
|
|
|
{
|
2023-11-15 17:25:46 +08:00
|
|
|
|
data = proWorkplanService.DeleteWorkorder(id);
|
2023-11-15 14:53:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ToResponse(new ApiResult(200, "success", data));
|
|
|
|
|
|
}
|
2023-11-14 11:29:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|