WorkOrderController.cs 8.81 KB
using Hh.Mes.Common.Request;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.WebEntity.bus;
using Hh.Mes.Service.Configure;
using Hh.Mes.Service.Wo;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using System;
using System.Collections.Generic;
using System.Linq;
using WebMvc.Aop;
using Hh.Mes.Service.SystemAuth;
using WebMvc.Common;
using Autofac.Core;


namespace WebMvc.Areas.wo.Controllers
{
    /// <summary>
    /// 工序工单
    /// </summary>
    [Area("wo")]
    public class WorkOrderController : BaseController
    {
        private readonly WorkOrderService workOrderService;
        private readonly LineService lineService;

        public WorkOrderController(IAuth authUtil, WorkOrderService service, LineService lineService) : base(authUtil)
        {
            workOrderService = service;
            this.lineService = lineService;
            workOrderService.sysWebUser = authUtil.GetCurrentUser().User;
        }

        #region 视图功能
        public IActionResult Index( string sysWhereLineSelect)
        {
            var lineList = lineService.GetLineList();
            var listItem = lineList.FirstOrDefault(x => x.Value == sysWhereLineSelect);
            if (listItem != null) listItem.Selected = true;
            return View(lineList);
        }

        /// <summary>
        /// 报检页面
        /// </summary>
        /// <returns></returns>
        public IActionResult Inspection()
        {
            return View();
        }

        /// <summary>
        /// 工序任务明细物料页面
        /// </summary>
        /// <param name="headKey">工序任务明细HeadKey</param>
        /// <param name="bodyKey">工序任务明细BodyKey</param>
        /// <returns></returns>
        public IActionResult MaterDetail(Guid headKey, Guid bodyKey)
        {
            var data = ValueTuple.Create(headKey, bodyKey);
            return View(data);
        }

        /// <summary>
        /// 收货
        /// </summary>
        /// <param name="headKey">工序任务HeadKey</param>
        /// <returns></returns>

        public IActionResult Receipt(Guid headKey)
        {
            TempData["workOrderHeadKey"] = headKey;
            return View();
        }

        /// <summary>
        /// 收货统计
        /// </summary>
        /// <param name="headKey">工序任务Id</param>
        /// <returns></returns>
        public IActionResult ReceiptStatistics(Guid headKey)
        {
            TempData["workOrderHeadKeyByStatistics"] = headKey;
            ViewBag.headKey = headKey;
            return View();
        }

        /// <summary>
        /// 报检页面 适合车间扫码使用
        /// </summary>
        /// <returns></returns>
        public IActionResult InspectionExt()
        {
            return View();
        }

        #endregion

        #region 获取数据
        /// <summary>
        /// 加载及分页查询
        /// </summary>
        /// <param name="pageRequest">表单请求信息</param>
        /// <param name="entity">请求条件实例</param>
        /// <returns></returns>
        [HttpPost]
        public string Load(PageReq pageRequest, bus_workOrder_head entity)
        {
            return Serialize(workOrderService.Load(pageRequest, entity));
        }

        /// <summary>
        /// 加载及分页查询
        /// </summary>
        /// <param name="pageRequest">表单请求信息</param>
        /// <param name="entity">请求条件实例</param>
        /// <returns></returns>
        [HttpPost]
        public string LoadDesc(PageReq pageRequest, bus_workOrder_detail entity)
        {
            return Serialize(workOrderService.LoadDesc(pageRequest, entity));
        }

        [HttpGet, HttpPost]
        public string LoadMaterDetail(PageReq pageReq, bus_workOrder_detail_material entity)
        {
            return Serialize(workOrderService.LoadMaterDetail(pageReq, entity));
        }

        /// <summary>
        /// 收货
        /// </summary>
        /// <param name="pageReq"></param>
        /// <param name="materialCode">物料编码</param>
        /// <param name="materialName">物料名称</param>
        /// <returns></returns>
        [HttpPost]
        public string LoadReceipt(PageReq pageReq, string materialCode = "", string materialName = "")
        {
            TempData.Keep("workOrderHeadKey");
            var headKey = Guid.Parse(TempData["workOrderHeadKey"].ToString());
            return Serialize(workOrderService.LoadReceipt(pageReq, headKey, materialCode, materialName));
        }

        /// <summary>
        /// 更新收货数量
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public string UpdReceipt(List<base_inventory> model)
        {
            model.ForEach((item) =>
            {
                //库存数量 = 收货数量 - 消耗数量
                item.qty = item.quantityReceived - item.consumedQuantity;
                item.updateTime = DateTime.Now;
                item.updateBy = workOrderService.sysWebUser?.Account;
            });
            return Serialize(workOrderService.UpdReceipt(model));
        }

        /// <summary>
        /// 收货统计--根据物料编码分组统计
        /// </summary>
        /// <param name="pageReq"></param>
        /// <returns></returns>
        [HttpGet, HttpPost]
        public string LoadReceiptStatistics(PageReq pageReq)
        {
           
            return Serialize("");
        }

        /// <summary>
        /// 根据条码获取工序信息、物料信息、设备工艺参数信息
        /// </summary>
        /// <param name="barCode"></param>
        /// <returns></returns>
        [HttpPost]
        public string InspectionExt(string barCode)
        {
            return Serialize(workOrderService.GetWorkOrderInfoByPlanCode(barCode));
        }

        #endregion

        #region 处理数据
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        [ServiceFilter(typeof(OperLogFilter))]
        public string DelByKeys(Guid[] ids)
        {
            return Serialize(workOrderService.DelByKeys(ids));
        }
        #endregion

        #region 导出数据
        /// <summary>
        /// 导出数据
        /// </summary>
        /// <param name="entity">请求条件实例</param>
        /// <returns></returns>
        [HttpPost]
        public string Export(bus_workOrder_head entity)
        {
            return Serialize(workOrderService.Export(entity));
        }
        #endregion

        #region 自定义方法

        /// <summary>
        /// 报工
        /// </summary>
        /// <param name="headKey"></param>
        /// <returns></returns>
        [HttpPost]
        public string WorkReport(Guid headKey, bool IsValdate = true)
        {
            var user = workOrderService.sysWebUser?.Account;
            return Serialize("");
        }

        /// <summary>
        /// 获取当前工序任务明细设备工艺参数
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public string GetEquipmentInfo(bus_workOrder_detail entity)
        {
            return Serialize(workOrderService.GetEquipmentInfo(entity));
        }

        /// <summary>
        /// 获取当前工序任务明细物料消耗
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public string GetMaterialInfo(bus_workOrder_detail entity)
        {
            return Serialize(workOrderService.GetMaterialInfo(entity));
        }

        /// <summary>
        /// 数据录入、开工
        /// </summary>
        /// <param name="headKeys"></param>
        /// <param name="bodyKeys"></param>
        /// <param name="id"></param>
        /// <param name="actualStartTime"></param>
        /// <param name="Material"></param>
        /// <param name="Equipment"></param>
        /// <returns></returns>
        public string UpdateProcess(Guid headKeys, Guid bodyKeys, int id, DateTime actualStartTime, List<bus_workOrder_material_use_log> Material, List<bus_equipment_process_template> Equipment, string stationCode)
        {
            return Serialize(workOrderService.UpdateProcess(headKeys, bodyKeys, id, actualStartTime, Material, Equipment, stationCode));
        }

        /// <summary>
        /// 完工
        /// </summary>
        /// <param name="headKeys"></param>
        /// <param name="id"></param>
        /// <param name="actualEndTime"></param>
        /// <returns></returns>
        [HttpPost]
        public string WorkComplete(Guid headKeys, int id, DateTime actualEndTime)
        {
            return Serialize(workOrderService.WorkComplete(headKeys, id, actualEndTime));
        }
        #endregion
    }
}