PDAController.cs 11.9 KB
using System;
using System.Collections.Generic;
using System.Linq;
using Hh.Mes.Api.Controllers;
using Hh.Mes.Common.Json;
using Hh.Mes.Common.log;
using Hh.Mes.POJO.ApiEntity;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Response;
using Hh.Mes.Service;
using Hh.Mes.Service.WebService.Planned;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Headers;
using Microsoft.AspNetCore.Mvc;

namespace Hh.Mes.Api.Controllers
{
    /// <summary>
    /// pda 查询接口
    /// ps:新增方法需要在SystemVariable 注册 APIList、EnumLog 新增枚举 ,方便接口日志定位查询
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PDAController : BaseController
    {
        private readonly PDAService service;

        public PDAController(PDAService pdaService, IHttpContextAccessor accessor)
        {

            service = pdaService;
            context = accessor.HttpContext;

            var sysUserApi = base.GetUser(context);
            this.service.sysUserApi = sysUserApi;
        }


        /// <summary>
        /// PDA物料追溯查询
        /// 1:使用动态类型、或者使用实体类
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionName("Mes/V1/GetMaterialByPDABarCode")]
        public string GetMaterialInfoByBarCode(dynamic requestData)
        {
            var result = service.GetMaterialInfoByBarCode(requestData);
            return Serialize(result);
        }

        #region 组对、焊接

        /// <summary>
        /// 获取匹配的组对信息
        /// </summary>
        /// <param name="station">工位码</param>
        /// <param name="pipe">管段码</param>
        /// <param name="batch">批次码</param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("Mes/V1/GetMatchTeamList")]
        public string GetMatchTeamList(string station, string pipe, string batch)
        {
            var result = service.GetMatchTeamList(station,pipe, batch);
            return JsonHelper.Instance.Serialize(result);
        }

        /// <summary>
        /// 获取组对开始列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [ActionName("Mes/V1/GetTeamStartList")]
        public string GetTeamStartList()
        {
            var result = service.GetTeamStartList();
            return JsonHelper.Instance.Serialize(result);
        }


        /// <summary>
        /// 保存组对开始列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionName("Mes/V1/SaveTeamStartList")]
        public string SaveTeamStartList(List<bus_workOrder_detail> details)
        {
            var result = service.SaveTeamStartList(details);
            return JsonHelper.Instance.Serialize(result);
        }


        /// <summary>
        /// 保存组对结束列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionName("Mes/V1/SaveTeamEndList")]
        public string SaveTeamEndList(List<bus_workOrder_detail> details)
        {
            var result = service.SaveTeamEndList(details);
            return JsonHelper.Instance.Serialize(result);
        }

        /// <summary>
        /// 获取匹配的焊接信息
        /// </summary>
        /// <param name="station">工位码</param>
        /// <param name="batch">批次码</param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("Mes/V1/GetMatchWeldList")]
        public string GetMatchWeldList(string station, string pipe)
        {
            var result = service.GetMatchWeldList(station,pipe);
            return JsonHelper.Instance.Serialize(result);
        }

        /// <summary>
        /// 获取焊接开始列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [ActionName("Mes/V1/GetWeldStartList")]
        public string GetWeldStartList()
        {
            var result = service.GetWeldStartList();
            return JsonHelper.Instance.Serialize(result);
        }


        /// <summary>
        /// 保存焊接开始列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionName("Mes/V1/SaveWeldStartList")]
        public string SaveWeldStartList(List<bus_workOrder_detail> details)
        {
            var result = service.SaveWeldStartList(details);
            return JsonHelper.Instance.Serialize(result);
        }


        /// <summary>
        /// 保存焊接结束列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionName("Mes/V1/SaveWeldEndList")]
        public string SaveWeldEndList(List<bus_workOrder_detail> details)
        {
            var result = service.SaveWeldEndList(details);
            return JsonHelper.Instance.Serialize(result);
        }


        /// <summary>
        /// 焊接工艺下发保存
        /// </summary>
        /// <param name="equipmentCode">设备编码</param>
        /// <param name="barCode">管段码</param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("Mes/V1/SaveWeldTechnology")]
        public string SaveWeldTechnology(string equipmentCode, string barCode)
        {
            var result = service.SaveWeldTechnology(equipmentCode, barCode);
            return JsonHelper.Instance.Serialize(result);
        }

        /// <summary>
        /// 批次码获取物料信息
        /// </summary>
        /// <param name="lotNo">批次码</param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("Mes/V1/GetMaterialBylotNo")]
        public string GetMaterialBylotNo(string lotNo)
        {
            var result = service.GetMaterialBylotNo(lotNo);
            return JsonHelper.Instance.Serialize(result);
        }

        /// <summary>
        /// 设备编码获取设备信息
        /// </summary>
        /// <param name="equipmentCode">设备编码</param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("Mes/V1/GetEquipmentByCode")]
        public string GetEquipmentByCode(string equipmentCode)
        {
            var result = service.GetEquipmentByCode(equipmentCode);
            return JsonHelper.Instance.Serialize(result);
        }

        /// <summary>
        /// 呼叫Agv接料
        /// </summary>
        /// <param name="equipmentCode">设备编码</param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("Mes/V1/AgvCollectingStart")]
        public string AgvCollectingStart(string equipmentCode)
        {
            var result = service.AgvCollectingStart(equipmentCode);
            return JsonHelper.Instance.Serialize(result);
        }

        /// <summary>
        /// Agv接料完成
        /// </summary>
        /// <param name="equipmentCode">设备编码</param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("Mes/V1/AgvCollectingEnd")]
        public string AgvCollectingEnd(string equipmentCode)
        {
            var result = service.AgvCollectingEnd(equipmentCode);
            return JsonHelper.Instance.Serialize(result);
        }

        /// <summary>
        /// 托盘入库
        /// </summary>
        /// <param name="containerCode">托盘码</param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("Mes/V1/ContainerTransfer")]
        public string ContainerTransfer(string containerCode)
        {
            var result = service.ContainerTransfer(containerCode);
            return JsonHelper.Instance.Serialize(result);
        }

        /// <summary>
        /// 设备任务列表查询
        /// </summary>
        /// <param name="equipmentCode">设备编码</param>
        /// <param name="state">查询状态:0未完成,30进行中,100已经完成</param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("Mes/V1/GetEquipmentTaskList")]
        public string GetEquipmentTaskList(string equipmentCode, int state)
        {
            var result = service.GetEquipmentTaskList(equipmentCode, state);
            return JsonHelper.Instance.Serialize(result);
        }

        /// <summary>
        /// 设备任务下发
        /// </summary>
        /// <param name="equipmentCode">设备编码</param>
        /// <param name="taskNumber">任务号</param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("Mes/V1/EquipmentTaskDistribute")]
        public string EquipmentTaskDistribute(string equipmentCode, string taskNumber)
        {
            var result = service.EquipmentTaskDistribute(equipmentCode, taskNumber);
            return JsonHelper.Instance.Serialize(result);
        }

        [HttpGet]
        [ActionName("Mes/V1/robotDeviceStatus")]
        public string robotDeviceStatus()
        {
            var result = service.robotDeviceStatus();
            return result.ToString();
        }

        [HttpGet]
        [ActionName("Mes/V1/PipeInfo")]
        public string PipeInfo(string materialCode)
        {
            var result = service.PipeInfo(materialCode);
            return result;
        }

        /// <summary>
        /// 设备任务手动完成
        /// </summary>
        /// <param name="equipmentCode">设备编码</param>
        /// <param name="taskNumber">任务号</param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("Mes/V1/EquipmentTaskEnd")]
        public string EquipmentTaskEnd(string equipmentCode, string taskNumber)
        {
            var response = new Response(true);
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                CutWeldService cutService = new CutWeldService();
                cutService.SendTaskEnd(taskNumber, equipmentCode);
                return JsonHelper.Instance.Serialize(response);
            });
        }

        #endregion

        #region 工位任务

        /// <summary>
        /// 工位任务列表查询(自动线,组对与焊接)
        /// </summary>
        /// <param name="workCenterCode">工作中心</param>
        [HttpGet]
        [ActionName("Mes/V1/GetTaskList")]
        public string GetTaskList(string workCenterCode)
        {
            var result = service.GetTaskList(workCenterCode);
            return Serialize(result);
        }

        /// <summary>
        /// 获取扫码记录
        /// </summary>
        /// <param name="workCenterCode">工作中心</param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("Mes/V1/GetScanRecord")]
        public string GetScanRecord(string workCenterCode)
        {
            var result = service.GetScanRecord(workCenterCode);
            return Serialize(result);
        }

        #endregion

        #region 工序问题记录

        /// <summary>
        /// 工序问题记录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionName("Mes/V1/SetProblem")]
        public string SetProblem(dynamic requestData)
        {
            var result = service.SetProblem(requestData);
            return Serialize(result);
        }

        #endregion


        #region 物料到达

        /// <summary>
        /// PDA扫码物料到达
        /// </summary>
        /// <param name="workStationCode">工位码</param>
        /// <param name="pipeSN">管材SN</param>
        [HttpGet]
        [ActionName("Mes/V1/MaterialReach")]
        public string MaterialReach(string workStationCode, string pipeSN)
        {
            var result = service.MaterialReach(workStationCode, pipeSN);
            return Serialize(result);
        }

        /// <summary>
        /// 查询库存物料
        /// </summary>
        /// <param name="pipeSN">管材SN</param>
        [HttpGet]
        [ActionName("Mes/V1/GetInventoryByPipeSN")]
        public string GetInventoryByPipeSN(string pipeSN)
        {
            var result = service.GetInventoryByPipeSN(pipeSN);
            return Serialize(result);
        }

        #endregion
    }
}