TTaskSimulationController.cs 2.92 KB
using Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using WebApp;
using WebRepository;

namespace WebMvc
{
    /// <summary>
	/// TTaskSimulation
	/// </summary>
    [Area("task")]
    public class TTaskSimulationController : BaseController
    {
        public TTaskSimulationController(IAuth authUtil) : base(authUtil)
        {
        }

        #region 视图功能
        /// <summary>
        /// 默认视图Action
        /// </summary>
        /// <returns></returns>
        [Authenticate]
        [ServiceFilter(typeof(OperLogFilter))]
        public ActionResult Index()
        {
            return View();
        }
        #endregion

        #region 自定义方法
        /// <summary>
        /// 单步控制(连接AGV)
        /// </summary>
        /// <param name="agvNo">AGV编号</param>
        /// <param name="link">开启/关闭</param>
        /// <returns></returns>
        [HttpPost]
        [ServiceFilter(typeof(OperLogFilter))]
        public string LinkAgv(string agvNo, bool link)
        {
            try
            {
                ApiRequest apiRequest = new ApiRequest("RCS");
                string parameter = JsonHelper.Instance.Serialize(new LinkAgvModel
                {
                    agvNo = agvNo,
                    link = link,
                });
                Response response = apiRequest.Post<Response>(parameter, "LinkAgv", "RCS");
                if (response.Code != 0)
                {
                    throw new Exception(response.Message);
                }
            }
            catch (Exception ex)
            {
                Result.Status = false;
                Result.Message = ex.Message;
            }
            return JsonHelper.Instance.Serialize(Result);
        }

        /// <summary>
        /// 单步控制(操纵AGV动作)
        /// </summary>
        /// <param name="agvNo">AGV编号</param>
        /// <param name="action">action</param>
        /// <returns></returns>
        [HttpPost]
        [ServiceFilter(typeof(OperLogFilter))]
        public string ControlAgv(string agvNo, int action)
        {
            try
            {
                ApiRequest apiRequest = new ApiRequest("RCS");
                string parameter = JsonHelper.Instance.Serialize(new ControlAgvModel
                {
                    agvNo = agvNo,
                    action = action,
                });
                Response response = apiRequest.Post<Response>(parameter, "ControlAgv", "RCS");
                if (response.Code != 0)
                {
                    throw new Exception(response.Message);
                }
            }
            catch (Exception ex)
            {
                Result.Status = false;
                Result.Message = ex.Message;
            }
            return JsonHelper.Instance.Serialize(Result);
        }

        #endregion
    }
}