HomeController.cs 3.45 KB
using Hh.Mes.Common.config;
using Hh.Mes.Common.Json;
using Hh.Mes.Common.log;
using Hh.Mes.Service;
using Hh.Mes.Service.Configure;
using Hh.Mes.Service.SystemAuth;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Linq;

namespace WebMvc
{
    public class HomeController : BaseController
    {
        private readonly SysCompanyService SysCompanyService;
        private readonly BaseInfoCacheService baseInfo;

        public HomeController(IAuth authUtil, SysCompanyService sysCompanyService, BaseInfoCacheService baseInfo) : base(authUtil)
        {
            this.baseInfo = baseInfo;
            SysCompanyService = sysCompanyService;
        }

        [ResponseCache(Duration = 60)]
        public ActionResult Index()
        {
            var company = SysCompanyService.GetSysCompanyOne();
            var sysFile = SysCompanyService.GetSysFile(company.companyId);
            ViewBag.Url = sysFile.FirstOrDefault(x => x.position == "home")?.url;
            ViewBag.copyright = "Copyright © " + DateTime.Now.ToString("yyyy ") + AppSettings.GetAppSeting("copyright");
            ResponseEnumJosn();
          
            ViewBag.IsDevelopment = string.Format("let IsDevelopment={0}", ConfigRead.GetInstance.GetAppsetConnection().IsDevelopment.ToString().ToLower());
 
            var dt = baseInfo.GetMaterialList();
            ViewBag.material = dt.ToJson();
            return View();
        }

        public ActionResult Main()
        {
            return View();
        }

        public ActionResult Welcome()
        {
            return View();
        }


        /// <summary>
        /// 未完成工单信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string UnfinishedOrderInfo()
        {
            return Serialize(SysCompanyService.UnfinishedOrderInfo());
        }

        /// <summary>
        /// 统计错误信息
        /// </summary>
        /// <returns></returns>
        public string LogTips()
        {
            var result = SysCompanyService.LogTips();
            return Serialize(result);
        }

        /// <summary>
        /// 更新清空日志提示
        /// </summary>
        [HttpGet]
        public string UpdateLogTips(string flag)
        {
            return Serialize(SysCompanyService.UpdateLogTips(flag));
        }
    }

    public class HomeRedisController : Controller
    {
        private readonly BaseInfoCacheService baseInfo;

        public HomeRedisController(BaseInfoCacheService baseInfo)
        {
            this.baseInfo = baseInfo;
        }

        /// <summary>
        /// 读取数据,存在key 取缓存,没有数据 读取数据,并写入缓存
        /// </summary>
        /// <param name="key"></param>
        /// <param name="falg">1:重新取数据,写入缓存,其他默认读取缓存</param>
        /// <returns></returns>
        [HttpPost]
        public string GetBaseInfoByKey([FromQuery] string key, [FromQuery] string falg)
        {
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                var isRemore = falg == "1";
                var result = baseInfo.GetOneBaseInfo(key, isRemore);
                if (string.IsNullOrEmpty(result))
                {
                    return "{\"Code\":500,\"Status\":false,\"Message\":\"ok\",\"Result\":null}";
                }
                return "{\"Code\":200,\"Status\":true,\"Message\":\"ok\",\"Result\":" + result + "}";
            });
        }

    }

}