BulletinBoardController.cs 9.98 KB
using System;
using Hh.Mes.Common.log;
using Hh.Mes.Pojo.System;
using Hh.Mes.Service;
using Hh.Mes.Service.WebService.Equipment;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Hh.Mes.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ServiceFilter(typeof(ValidateUserAttribute))]
    public class BulletinBoardController : BaseController
    {
        private readonly BulletinBoardService service;
        private readonly BaseInfoCacheService baseInfo;
        private readonly EquipmentVisualService equipmentVisual;

        /// <summary>
        /// 用户信息
        /// </summary>
        private UserAuthSession UserInfo { get; set; }

        public BulletinBoardController(BulletinBoardService service, BaseInfoCacheService baseInfo, EquipmentVisualService equipmentVisual, IHttpContextAccessor accessor)
        {
            this.service = service;
            this.baseInfo = baseInfo;
            this.equipmentVisual = equipmentVisual;
            this.context = accessor.HttpContext;
        }

        #region 故障相关接口

        #region 故障报告
        [HttpGet]
        public string GetFaultReport(string yyyyMonth, string projectCode, string equipmentTypeCode)
        {
            this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
            var result = service.GetFaultReport(yyyyMonth, projectCode, equipmentTypeCode);
            return Serialize(result);
        }
        #endregion

        #region 故障分析
        /// <summary>
        /// 故障分析查询
        /// </summary>
        /// <param name="begin">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="projectCode">项目编码</param>
        /// <param name="equipmentCode">设备编码</param>
        /// <returns></returns>
        [HttpGet]
        public string FaultStatistics(string begin, string end, string projectCode, string equipmentCode)
        {
            this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
            var result = service.FaultStatistics(begin, end, projectCode, equipmentCode);
            return Serialize(result);
        }
        #endregion

        #region 妥善率
        /// <summary>
        /// 妥善率趋势图
        /// </summary>
        [HttpGet]
        public string GetProperRate(string startTime, string endTime, string yearOrdaySelectVal, string timeFlag, string projectCode, string equipmentCode)
        {
            this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
            var result = service.GetProperRate(startTime, endTime, yearOrdaySelectVal, timeFlag, projectCode, equipmentCode);
            return Serialize(result);
        }

        #endregion

        #region 故障月份对比
        [HttpGet]
        public string FailureMonthCompare(int year, int month, string projectCode, string equipmentTypeCode)
        {
            this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
            var result = service.GetFailureMonthCompare(year, month, projectCode, equipmentTypeCode);
            return Serialize(result);
        }
        #endregion

        #region 获取基础数据
        [HttpGet]
        public string GetBaseInfoByKeyExtend(string key, string falg)
        {
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
                var isRemore = falg == "1";
                var result = baseInfo.GetOneBaseInfo(key, isRemore);
                if (string.IsNullOrEmpty(result))
                {
                    return "{\"code\":500,\"status\":false,\"message\":\"ok\",\"data\":null}";
                }
                return "{\"code\":200,\"status\":true,\"message\":\"ok\",\"data\":" + result + "}";
            });
        }

        /// <summary>
        /// 获取所有项目(如果是AGV报表则只查询有AGV设备的项目)
        /// </summary>
        /// <param name="agvTag"></param>
        /// <returns></returns>
        [HttpGet]
        public string GetProjects(bool agvTag = false)
        {
            this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
            var result = service.GetProjects(agvTag);
            return Serialize(result);
        }


        /// <summary>
        /// 获取项目下的所有设备
        /// </summary>
        /// <param name="projectCode"></param>
        /// <returns></returns>
        [HttpGet]
        public string GetEquipmentsByProject(string projectCode, bool agvTag = false)
        {
            this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
            var result = service.GetEquipmentsByProject(projectCode, agvTag);
            return Serialize(result);
        }
        #endregion

        #region 月每周故障次数、时间
        [HttpGet]
        public string FailureMonthWeekCountAndTime(string projectCode, DateTime currentDate)
        {
            this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
            var result = service.GetFailureMonthWeekCountAndTime(projectCode, currentDate);
            return Serialize(result);
        }
        #endregion

        #region 项目某设备某天每小时故障次数
        [HttpGet]
        public string FailureEveryHourCount(string projectCode, string equipmentCode, DateTime currentDate)
        {
            this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
            var result = service.GetFailureEveryHourCount(projectCode, equipmentCode, currentDate);
            return Serialize(result);
        }
        #endregion

        #region 故障重复次数
        /// <summary>
        /// 故障次数
        /// </summary>
        /// <param name="projectCode"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        [HttpGet]
        public string FailureAlarmCount(string projectCode, DateTime startTime, DateTime endTime)
        {
            this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
            var result = service.GetFailureAlarmCount(projectCode, startTime, endTime);
            return Serialize(result);
        }
        #endregion

        #endregion

        #region AGV报表接口

        #region 获取AGV异常故障内容下拉框数据源

        public string GetAGVAlarmList(string projectCode, string equipmentCode)
        {
            this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
            var result = service.GetAGVAlarmList(projectCode, equipmentCode);
            return Serialize(result);
        }
        #endregion

        #region 获取AGV异常分析(点位维度)
        [HttpGet]
        public string GetAGVCodePointAlarmRecord(string startTime, string endTime, string projectCode, string equipmentCode, string alarmMsg)
        {
            this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
            var result = service.GetAGVCodePointAlarmRecord(startTime, endTime, projectCode, equipmentCode, alarmMsg);
            return Serialize(result);
        }
        #endregion

        #region 获取AGV异常分析(时间维度)
        [HttpGet]
        public string GetAGVAbnormalRecord(string startTime, string endTime, string projectCode, string equipmentCode, string alarmMsg)
        {
            this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
            var result = service.GetAGVAbnormalRecord(startTime, endTime, projectCode, equipmentCode, alarmMsg);
            return Serialize(result);
        }
        #endregion

        #region 获取AGV故障任务妥善率(故障次数/任务数)
        [HttpGet]
        public string GetAGVProperRate(string startTime, string endTime, string yearOrdaySelectVal, string timeFlag, string projectCode, string equipmentCode)
        {
            this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
            var result = service.GetAGVProperRate(startTime, endTime, yearOrdaySelectVal, timeFlag, projectCode, equipmentCode);
            return Serialize(result);
        }
        #endregion

        #endregion

        #region 设备保养模块接口
        /// <summary>
        /// 设备保养报告
        /// </summary>
        /// <param name="projectKeys"></param>
        /// <param name="equipmentCode"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        [HttpGet]
        public string GetEqMaintainReport(string projectCode, string equipmentCode, string yearMonth, bool thisMonth = false)
        {
            this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
            var result = service.GetEqMaintainReport(projectCode, equipmentCode, yearMonth, thisMonth);
            return Serialize(result);
        }

        /// <summary>
        /// 设备保养次数趋势图 接口
        /// </summary>
        /// <param name="projectKeys"></param>
        /// <param name="yearMonth"></param>
        /// <returns></returns>
        [HttpGet]
        public string GetEqMaintainCount(string projectCode, string yearMonth)
        {
            this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
            var result = service.GetEqMaintainCount(projectCode, yearMonth);
            return Serialize(result);
        }
        #endregion

        #region 设备健康分析接口
        public string GetEquipmentMaintainStatus(string projectCode, DateTime date, string equipmentCode)
        {
            this.service.sysUserApiAccount = HttpContext.Items["Account"] as string;
            var result = service.GetEquipmentMaintainStatus(projectCode, date, equipmentCode, equipmentVisual);
            return Serialize(result);
        }
        #endregion
    }
}