287 lines
11 KiB
C#
287 lines
11 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.IdentityModel.Tokens;
|
||
using ZR.Admin.WebApi.Extensions;
|
||
using ZR.Model.mes.md;
|
||
using ZR.Model.mes.pro;
|
||
using ZR.Service.mes.pro.IService;
|
||
using ZR.Service.MES.md;
|
||
|
||
namespace ZR.Admin.WebApi.Controllers.MES.pro
|
||
{
|
||
|
||
[Route("mes/pro/workplan")]
|
||
public class ProWorkplanController : BaseController
|
||
{
|
||
private readonly IProWorkplanService proWorkplanService;
|
||
|
||
public ProWorkplanController(IProWorkplanService 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<ProWorkplan>,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] ProWorkplan 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="proWorkplan">生产计划对象</param>
|
||
/// <returns></returns>
|
||
[HttpPost("updateworkplan")]
|
||
public IActionResult UpdateWorkPlan([FromBody] ProWorkplan proWorkplan)
|
||
{
|
||
int data = 0;
|
||
if (proWorkplan != null)
|
||
{
|
||
proWorkplan.ToUpdate(HttpContext);
|
||
data = proWorkplanService.UpdateWorkPlan(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">计划ID</param>
|
||
/// <returns></returns>
|
||
[HttpGet("getworkorderList/{id}")]
|
||
public IActionResult GetWorkorderList(string id)
|
||
{
|
||
List<ProWorkorder> lst = new List<ProWorkorder>();
|
||
|
||
if (!string.IsNullOrEmpty(id))
|
||
{
|
||
lst = proWorkplanService.GetWorkorderListByPlanId(id);
|
||
}
|
||
|
||
return ToResponse(new ApiResult(200, "success", lst));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 新增生产工单
|
||
/// </summary>
|
||
/// <param name="proWorkorder">生产工单对象</param>
|
||
/// <returns></returns>
|
||
[HttpPost("addworkorder")]
|
||
public IActionResult AddWorkorder([FromBody] ProWorkorder proWorkorder)
|
||
{
|
||
// TODO 获取工单对象
|
||
// TODO 增加插入时间,插入人员:ToCreate
|
||
// TODO 根据工单对象里的计划ID,查询生产计划的数量,判断工单数和要小于等于计划数:能插入,正常返回,0或1;大于,2
|
||
|
||
int data = 0;
|
||
if (proWorkorder != null)
|
||
{
|
||
proWorkorder.Id = DateTime.Now.ToString("yyyyMMddHHmmss");
|
||
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.GetWorkorderListByPlanId(workPlanId);
|
||
|
||
// 计算所有工单的数量和,生产计划的数量:比较
|
||
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.Partnumber = lstWorkplan[0].Partnumber;
|
||
proWorkorder.ToCreate(HttpContext);
|
||
data = proWorkplanService.AddWorkorder(proWorkorder);
|
||
}
|
||
else
|
||
{
|
||
data = 2;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return ToResponse(new ApiResult(200, "success", data));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新生产工单
|
||
/// </summary>
|
||
/// <param name="proWorkorder">生产工单对象</param>
|
||
/// <returns></returns>
|
||
[HttpPost("updateworkorder")]
|
||
public IActionResult UpdateWorkorder([FromBody] ProWorkorder proWorkorder)
|
||
{
|
||
// TODO 判断更新的数量是否超过计划数
|
||
|
||
int data = 0;
|
||
if (proWorkorder != null) // 工单对象不为空
|
||
{
|
||
string workPlanId = proWorkorder.FkProPlanId;
|
||
string workorderId = proWorkorder.Id;
|
||
|
||
// 判断计划ID,工单ID要非空
|
||
if (!string.IsNullOrEmpty(workPlanId) && !string.IsNullOrEmpty(workorderId))
|
||
{
|
||
string isArrange = "0";
|
||
|
||
// 查询所有生产工单,根据生产计划ID
|
||
List<ProWorkorder> lstWorkorder = proWorkplanService.GetWorkorderListByPlanId(workPlanId);
|
||
|
||
// 找到要更新的工单,要判断当前工单状态
|
||
ProWorkorder currentWorkorder = null;
|
||
foreach (ProWorkorder item in lstWorkorder)
|
||
{
|
||
if(item.Id.Equals(workorderId)) // 找到当前工单ID的对象
|
||
{
|
||
//if(!string.IsNullOrEmpty(item.Wrokerorder_status)) isArrange = item.Isarrange;
|
||
isArrange = item.Wrokerorder_status.ToString();
|
||
currentWorkorder = item;
|
||
break;
|
||
}
|
||
}
|
||
|
||
// 状态为未排产状态,才能更新
|
||
if ("0".Equals(isArrange))
|
||
{
|
||
// 查询生产计划对象
|
||
List<ProWorkplan> lstWorkplan = proWorkplanService.GetProWorkplanById(workPlanId);
|
||
|
||
// 计算所有工单的数量和,生产计划的数量:比较
|
||
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();
|
||
}
|
||
if(currentWorkorder!=null) countWorkorder -= currentWorkorder.Actualnumber.GetValueOrDefault(); // 减去当前工单的数值
|
||
|
||
// 再加上要更新的值
|
||
countWorkorder += proWorkorder.Actualnumber.GetValueOrDefault();
|
||
|
||
// 计划数>0 计划数要大于等于当前工单总数
|
||
if (countWorkplan > 0 && (countWorkplan >= countWorkorder))
|
||
{
|
||
proWorkorder.ToUpdate(HttpContext);
|
||
data = proWorkplanService.UpdateWorkorder(proWorkorder);
|
||
}
|
||
else
|
||
{
|
||
data = 2;
|
||
}
|
||
}
|
||
}
|
||
else data = 3;
|
||
|
||
}
|
||
}
|
||
|
||
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))
|
||
{
|
||
// 查询所有生产工单,根据生产计划ID
|
||
List<ProWorkorder> lstWorkorder = proWorkplanService.GetWorkorderListById(id);
|
||
|
||
// 查询工单非空,数量必须为1个
|
||
if (lstWorkorder != null && lstWorkorder.Count == 1)
|
||
{
|
||
string isArrange = "0";
|
||
|
||
// 排产状态非空
|
||
isArrange = lstWorkorder[0].Wrokerorder_status.ToString();
|
||
|
||
// 排产状态为 0 ,可执行删除
|
||
if ("0".Equals(isArrange))
|
||
{
|
||
data = proWorkplanService.DeleteWorkorder(id);
|
||
}
|
||
else data = 3;
|
||
}
|
||
|
||
}
|
||
|
||
return ToResponse(new ApiResult(200, "success", data));
|
||
}
|
||
}
|
||
}
|