DashboardService.cs 10.7 KB
using NCC.Common.Core.Manager;
using NCC.Common.Helper;
using NCC.Dependency;
using NCC.DynamicApiController;
using NCC.Message.Interfaces.Message;
using NCC.System.Interfaces.System;
using NCC.VisualDev.Entitys.Dto.Dashboard;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NCC.VisualDev
{
    /// <summary>
    ///  业务实现:主页显示
    /// </summary>
    [ApiDescriptionSettings(Tag = "VisualDev", Name = "Dashboard", Order = 174)]
    [Route("api/visualdev/[controller]")]
    public class DashboardService : IDynamicApiController, ITransient
    {
        private readonly IMessageService _messageService;
        private readonly IUserManager _userManager;
        private readonly IDictionaryDataService _dictionaryDataService;

        /// <summary>
        /// 初始化一个<see cref="DashboardService"/>类型的新实例
        /// </summary>
        public DashboardService(
            IMessageService messageService,
            IUserManager userManager,

            IDictionaryDataService dictionaryDataService)
        {
            _messageService = messageService;
            _userManager = userManager;

            _dictionaryDataService = dictionaryDataService;

        }


        #region Get

        /// <summary>
        /// 获取我的待办
        /// </summary>
        [HttpGet("FlowTodoCount")]
        public async Task<dynamic> GetFlowTodoCount()
        {
            var userId = _userManager.UserId;
            var waitList = new List<object>();//  await _flowTaskRepository.GetWaitList();
            var flowList = new List<object>();//  await _flowDelegateService.GetList(userId);
            var trialList = new List<object>();//   await _flowTaskRepository.GetTrialList();
            var data = new FlowTodoCountOutput()
            {
                toBeReviewed = waitList.Count(),
                entrust = flowList.Count(),
                flowDone = trialList.Count()
            };
            return data;
        }

        /// <summary>
        /// 获取通知公告
        /// </summary>
        [HttpGet("Notice")]
        public async Task<dynamic> GetNotice()
        {
            List<NoticeOutput> list = new List<NoticeOutput>();
            (await _messageService.GetList(1)).ForEach(l =>
            {
                list.Add(new NoticeOutput()
                {
                    id = l.Id,
                    fullName = l.Title,
                    creatorTime = l.CreatorTime
                });
            });
            return new { list = list };
        }

        /// <summary>
        /// 获取待办事项
        /// </summary>
        [HttpGet("FlowTodo")]
        public async Task<dynamic> GetFlowTodo()
        {
            List<FlowTodoOutput> list = new List<FlowTodoOutput>();
            return new { list = list };
        }

        /// <summary>
        /// 获取我的待办事项
        /// </summary>
        [HttpGet("MyFlowTodo")]
        public async Task<dynamic> GetMyFlowTodo()
        {
            List<FlowTodoOutput> list = new List<FlowTodoOutput>();

            return new { list = list };
        }

        /// <summary>
        /// 获取未读邮件
        /// </summary>
        [HttpGet("Email")]
        public async Task<dynamic> GetEmail()
        {
            List<EmailOutput> list = new List<EmailOutput>();
            return new { list = list };
        }

        /// <summary>
        /// 获取横幅计算数据
        /// </summary>
        /// <returns></returns>
        [HttpGet("CountData")]
        public async Task<dynamic> GetCountData()
        {

            var data = new
            {
                list = new List<object>()
            };
            return data;
        }

        /// <summary>
        /// 获取新闻信息
        /// </summary>
        [HttpGet("Article")]
        public async Task<dynamic> GetArticle()
        {
            List<NoticeOutput> list = new List<NoticeOutput>();

            return new { list = list };
        }

        [HttpGet("ProjectMonthLine")]
        public async Task<dynamic> ProjectMonthLine()
        {
            //StringBuilder sb = new StringBuilder();
            //sb.AppendLine("{");
            //sb.AppendLine("  \"color\": [");
            //sb.AppendLine("    \"#1890ff\"");
            //sb.AppendLine("  ],");
            //sb.AppendLine("  \"title\": {");
            //sb.AppendLine("    \"text\": \"\",");
            //sb.AppendLine("    \"subtext\": \"\"");
            //sb.AppendLine("  },");
            //sb.AppendLine("  \"tooltip\": {");
            //sb.AppendLine("    \"trigger\": \"axis\",");
            //sb.AppendLine("    \"axisPointer\": {");
            //sb.AppendLine("      \"type\": \"shadow\"");
            //sb.AppendLine("    }");
            //sb.AppendLine("  },");
            //sb.AppendLine("  \"grid\": {");
            //sb.AppendLine("    \"left\": \"3%\",");
            //sb.AppendLine("    \"right\": \"4%\",");
            //sb.AppendLine("    \"bottom\": \"3%\",");
            //sb.AppendLine("    \"containLabel\": true");
            //sb.AppendLine("  },");
            //sb.AppendLine("  \"xAxis\": [");
            //sb.AppendLine("    {");
            //sb.AppendLine("      \"type\": \"category\",");
            //sb.AppendLine("      \"data\": [");
            //for (int i = 1; i <= DateTime.Now.Month; i++)
            //{
            //    if (i < DateTime.Now.Month)
            //        sb.AppendLine("        \"" + i + "月\",");
            //    else
            //        sb.AppendLine("        \"" + i + "月\"");
            //}
            ////sb.AppendLine("        \"1月\",");
            ////sb.AppendLine("        \"2月\",");
            ////sb.AppendLine("        \"3月\",");
            ////sb.AppendLine("        \"4月\",");
            ////sb.AppendLine("        \"5月\",");
            ////sb.AppendLine("        \"6月\"");
            //sb.AppendLine("      ],");
            //sb.AppendLine("      \"axisTick\": {");
            //sb.AppendLine("        \"alignWithLabel\": true");
            //sb.AppendLine("      }");
            //sb.AppendLine("    }");
            //sb.AppendLine("  ],");
            //sb.AppendLine("  \"yAxis\": [");
            //sb.AppendLine("    {");
            //sb.AppendLine("      \"type\": \"value\"");
            //sb.AppendLine("    }");
            //sb.AppendLine("  ],");
            //sb.AppendLine("  \"series\": [");
            //sb.AppendLine("    {");
            //sb.AppendLine("      \"name\": \"项目数量(个)\",");
            //sb.AppendLine("      \"type\": \"bar\",");
            //sb.AppendLine("      \"barWidth\": \"60%\",");
            //sb.AppendLine("      \"data\": [");
            //for (int i = 1; i <= DateTime.Now.Month; i++)
            //{
            //    if (i < DateTime.Now.Month)
            //        sb.AppendLine("        \"" + await _zyZbwfProjectitemService.GetProAmountMonth(i) + "\",");
            //    else
            //        sb.AppendLine("        \"" + await _zyZbwfProjectitemService.GetProAmountMonth(i) + "\"");
            //}
            ////sb.AppendLine("        1012,");
            ////sb.AppendLine("        2000,");
            ////sb.AppendLine("        800,");
            ////sb.AppendLine("        1500,");
            ////sb.AppendLine("        1600,");
            ////sb.AppendLine("        1103");
            //sb.AppendLine("      ]");
            //sb.AppendLine("    }");
            //sb.AppendLine("  ]");
            //sb.AppendLine("}");
            var data = new
            {
                chartdata = JsonHelper.ToObject("{}")
            };
            return data;
        }


        [HttpGet("VipShopPie")]
        public async Task<dynamic> VipShopPie()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("{");
            sb.AppendLine("  \"title\": {");
            sb.AppendLine("    \"text\": \"会员情况统计\",");
            sb.AppendLine("    \"subtext\": \"实时数据\",");
            sb.AppendLine("    \"left\": \"center\"");
            sb.AppendLine("  },");
            sb.AppendLine("  \"tooltip\": {");
            sb.AppendLine("    \"trigger\": \"item\",");
            sb.AppendLine("    \"formatter\": \"{a} <br/>{b} : {c} ({d}%)\"");
            sb.AppendLine("  },");
            sb.AppendLine("  \"legend\": {");
            sb.AppendLine("    \"bottom\": 10,");
            sb.AppendLine("    \"left\": \"center\",");
            sb.AppendLine("    \"data\": [");
            sb.AppendLine("      \"春凡大药房\",");
            sb.AppendLine("      \"春国大药房\"");
            sb.AppendLine("    ]");
            sb.AppendLine("  },");
            sb.AppendLine("  \"series\": [");
            sb.AppendLine("    {");
            sb.AppendLine("      \"type\": \"pie\",");
            sb.AppendLine("      \"radius\": \"65%\",");
            sb.AppendLine("      \"center\": [");
            sb.AppendLine("        \"50%\",");
            sb.AppendLine("        \"50%\"");
            sb.AppendLine("      ],");
            sb.AppendLine("      \"selectedMode\": \"single\",");
            sb.AppendLine("      \"data\": [");
            sb.AppendLine("        {");
            //    sb.AppendLine("          \"value\": " + await vipbll.GetShopVipCount("CF") + ",");
            sb.AppendLine("          \"name\": \"春凡大药房\",");
            sb.AppendLine("          \"itemStyle\": {");
            sb.AppendLine("            \"color\": \"#1890ff\"");
            sb.AppendLine("          }");
            sb.AppendLine("        },");
            sb.AppendLine("        {");
            //     sb.AppendLine("          \"value\": " + await vipbll.GetShopVipCount("CG1") + ",");
            sb.AppendLine("          \"name\": \"春国大药房\",");
            sb.AppendLine("          \"itemStyle\": {");
            sb.AppendLine("            \"color\": \"#ff3b3b\"");
            sb.AppendLine("          }");
            sb.AppendLine("        }");
            sb.AppendLine("      ],");
            sb.AppendLine("      \"emphasis\": {");
            sb.AppendLine("        \"itemStyle\": {");
            sb.AppendLine("          \"shadowBlur\": 10,");
            sb.AppendLine("          \"shadowOffsetX\": 0,");
            sb.AppendLine("          \"shadowColor\": \"rgba(0, 0, 0, 0.5)\"");
            sb.AppendLine("        }");
            sb.AppendLine("      }");
            sb.AppendLine("    }");
            sb.AppendLine("  ]");
            sb.AppendLine("}");

            var data = new
            {
                piedata = JsonHelper.ToObject(sb.ToString())
            };
            return data;
        }
        #endregion
    }
}