ChartController.cs 9.37 KB
using Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using WebApp;
using WebRepository;

namespace WebMvc
{
    /// <summary>
	/// Chart
	/// </summary>
    [Area("chart")]
    public class ChartController : BaseController
    {
        private readonly ChartApp _app;
        
        public ChartController(IAuth authUtil, IUnitWork unitWork, IUnitWorkAcs unitWorkAcs, ACSDbContext aCSDbContex) : base(authUtil)
        {
            _app = new ChartApp(unitWork, unitWorkAcs, aCSDbContex);
        }

        #region 视图功能
        /// <summary>
        /// 里程
        /// </summary>
        /// <returns></returns>
        [Authenticate]
        [ServiceFilter(typeof(OperLogFilter))]
        public ActionResult ChartMileage()
        {
            return View();
        }

        /// <summary>
        /// 任务总览
        /// </summary>
        /// <returns></returns>
        [Authenticate]
        [ServiceFilter(typeof(OperLogFilter))]
        public ActionResult ChartTask()
        {
            return View();
        }

        /// <summary>
        /// 稼动率
        /// </summary>
        /// <returns></returns>
        [Authenticate]
        [ServiceFilter(typeof(OperLogFilter))]
        public ActionResult ChartUserate()
        {
            return View();
        }
        #endregion

        #region 自定义方法
        /// <summary>
        /// 获取里程
        /// </summary>
        /// <param name="startDate">起始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <param name="taskGroup">任务群组</param>
        /// <param name="chartType">图表类型(天、周、月)</param>
        /// <returns></returns>
        [HttpPost]
        public string GetMileage(DateTime startDate, DateTime endDate, string taskGroup, string chartType)
        {
            return JsonHelper.Instance.Serialize(_app.GetMileage(startDate, endDate, taskGroup, chartType));
        }

        /// <summary>
        /// 获取单位里程
        /// </summary>
        /// <param name="startDate">起始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <param name="taskGroup">任务群组</param>
        /// <param name="chartType">图表类型(天、周、月)</param>
        /// <returns></returns>
        [HttpPost]
        public string GetMileageUnit(DateTime startDate, DateTime endDate, string taskGroup, string chartType, string unitValue)
        {
            return JsonHelper.Instance.Serialize(_app.GetMileageUnit(startDate, endDate, taskGroup, chartType, unitValue));
        }

        /// <summary>
        /// 获取任务数
        /// </summary>
        /// <param name="startDate">起始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <param name="taskGroup">任务群组</param>
        /// <param name="chartType">图表类型(天、周、月)</param>
        /// <returns></returns>
        [HttpPost]
        public string GetTask(DateTime startDate, DateTime endDate, string taskGroup, string chartType)
        {
            return JsonHelper.Instance.Serialize(_app.GetTask(startDate, endDate, taskGroup, chartType));
        }

        /// <summary>
        /// 获取单位任务
        /// </summary>
        /// <param name="startDate">起始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <param name="taskGroup">任务群组</param>
        /// <param name="chartType">图表类型(天、周、月)</param>
        /// <returns></returns>
        [HttpPost]
        public string GetTaskUnit(DateTime startDate, DateTime endDate, string taskGroup, string chartType, string unitValue)
        {
            return JsonHelper.Instance.Serialize(_app.GetTaskUnit(startDate, endDate, taskGroup, chartType, unitValue));
        }

        /// <summary>
        /// 获取稼动率
        /// </summary>
        /// <param name="startDate">起始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <param name="chartType">图表类型(小时、天、周、月)</param>
        /// <returns></returns>
        [HttpPost]
        public string GetUserate(DateTime startDate, DateTime endDate, string chartType)
        {
            return JsonHelper.Instance.Serialize(_app.GetUserate(startDate, endDate, chartType));
        }

        /// <summary>
        /// 获取单位稼动率
        /// </summary>
        /// <param name="startDate">起始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <param name="chartType">图表类型(小时、天、周、月)</param>
        /// <returns></returns>
        [HttpPost]
        public string GetUserateUnit(DateTime startDate, DateTime endDate, string chartType, string unitValue)
        {
            return JsonHelper.Instance.Serialize(_app.GetUserateUnit(startDate, endDate, chartType, unitValue));
        }

        /// <summary>
        /// 获取里程关键指标
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string GetMileageKeyValue()
        {
            TableData tableData = new TableData();
            try
            {
                TableData tableData_Daily = _app.GetMileageKeyValueByKey("Daily");
                TableData tableData_Weekly = _app.GetMileageKeyValueByKey("Weekly");
                TableData tableData_Monthly = _app.GetMileageKeyValueByKey("Monthly");

                var Dynamic_Daily = JsonConvert.DeserializeObject<dynamic>((string)tableData_Daily.data);
                var Dynamic_Weekly = JsonConvert.DeserializeObject<dynamic>((string)tableData_Weekly.data);
                var Dynamic_Monthly = JsonConvert.DeserializeObject<dynamic>((string)tableData_Monthly.data);

                dynamic dynamic = new
                {
                    DayName = Dynamic_Daily.Key,
                    DayValue = Dynamic_Daily.Value,
                    WeekName = Dynamic_Weekly.Key,
                    WeekValue = Dynamic_Weekly.Value,
                    MonthName = Dynamic_Monthly.Key,
                    MonthValue = Dynamic_Monthly.Value,
                };
                tableData.data = dynamic;
            }
            catch (Exception ex)
            {
                tableData.code = 500;
                tableData.msg = ex.Message;
            }

            return JsonHelper.Instance.Serialize(tableData);
        }

        /// <summary>
        /// 获取任务关键指标
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string GetTaskKeyValue()
        {
            TableData tableData = new TableData();
            try
            {
                TableData tableData_Daily = _app.GetTaskKeyValueByKey("Daily");
                TableData tableData_Weekly = _app.GetTaskKeyValueByKey("Weekly");
                TableData tableData_Monthly = _app.GetTaskKeyValueByKey("Monthly");

                var Dynamic_Daily = JsonConvert.DeserializeObject<dynamic>((string)tableData_Daily.data);
                var Dynamic_Weekly = JsonConvert.DeserializeObject<dynamic>((string)tableData_Weekly.data);
                var Dynamic_Monthly = JsonConvert.DeserializeObject<dynamic>((string)tableData_Monthly.data);

                dynamic dynamic = new
                {
                    DayName = Dynamic_Daily.Key,
                    DayValue = Dynamic_Daily.Value,
                    WeekName = Dynamic_Weekly.Key,
                    WeekValue = Dynamic_Weekly.Value,
                    MonthName = Dynamic_Monthly.Key,
                    MonthValue = Dynamic_Monthly.Value,
                };

                tableData.data = dynamic;
            }
            catch (Exception ex)
            {
                tableData.code = 500;
                tableData.msg = ex.Message;
            }

            return JsonHelper.Instance.Serialize(tableData);
        }

        /// <summary>
        /// 获取稼动率关键指标
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string GetUserateKeyValue()
        {
            TableData tableData = new TableData();
            try
            {
                TableData tableData_Daily = _app.GetUserateKeyValueByKey("Daily");
                TableData tableData_Weekly = _app.GetUserateKeyValueByKey("Weekly");
                TableData tableData_Monthly = _app.GetUserateKeyValueByKey("Monthly");

                var Dynamic_Daily = JsonConvert.DeserializeObject<dynamic>((string)tableData_Daily.data);
                var Dynamic_Weekly = JsonConvert.DeserializeObject<dynamic>((string)tableData_Weekly.data);
                var Dynamic_Monthly = JsonConvert.DeserializeObject<dynamic>((string)tableData_Monthly.data);

                dynamic dynamic = new
                {
                    DayName = Dynamic_Daily.Key,
                    DayValue = Dynamic_Daily.Value,
                    WeekName = Dynamic_Weekly.Key,
                    WeekValue = Dynamic_Weekly.Value,
                    MonthName = Dynamic_Monthly.Key,
                    MonthValue = Dynamic_Monthly.Value,
                };
                tableData.data = dynamic;
            }
            catch (Exception ex)
            {
                tableData.code = 500;
                tableData.msg = ex.Message;
            }

            return JsonHelper.Instance.Serialize(tableData);
        }
        #endregion
    }
}