using learun.iapplication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Threading.Tasks; namespace learun.webapi.Controllers { /// /// 版 本 Learun-ADMS-Core 力软管理后台 /// Copyright (c) 2019-present 力软信息技术(苏州)有限公司 /// 创建人:tobin /// 日 期:2020.04.22 /// 描 述:桌面配置接口 /// public class DesktopController : MvcControllerBase { private readonly DTTargetIBLL _dTTargetIBLL; private readonly DTListIBLL _dTListIBLL; private readonly DTChartIBLL _dTChartIBLL; private readonly DataSourceIBLL _dataSourceIBLL; private readonly DTImgIBLL _dTImgIBLL; private readonly ImgIBLL _imgIBLL; /// /// 初始化 /// /// 统计数据接口 /// 列表接口 /// 图标接口 /// 数据库连接接口 /// 桌面图片接口 /// 图片接口 public DesktopController(DTTargetIBLL dTTargetIBLL, DTListIBLL dTListIBLL, DTChartIBLL dTChartIBLL, DataSourceIBLL dataSourceIBLL, DTImgIBLL dTImgIBLL, ImgIBLL imgIBLL) { _dTTargetIBLL = dTTargetIBLL; _dTListIBLL = dTListIBLL; _dTChartIBLL = dTChartIBLL; _dataSourceIBLL = dataSourceIBLL; _dTImgIBLL = dTImgIBLL; _imgIBLL = imgIBLL; } /// /// 获取桌面配置信息 /// /// [HttpGet] public async Task Setting() { var target = await _dTTargetIBLL.GetList(); var list = await _dTListIBLL.GetList(); var chart = await _dTChartIBLL.GetList(); var data = new { target, list, chart }; return Success(data); } /// /// 获取数据 /// /// 类型 target,chart,list /// 主键ID /// [HttpGet] public async Task Data(string type, string id) { switch (type) { case "target": var data = await _dTTargetIBLL.GetEntity(id); if (data != null && !string.IsNullOrEmpty(data.F_Sql)) { var dt = await _dataSourceIBLL.GetDataTableBySql(data.F_DataSourceId, data.F_Sql); var jsonData2 = new { id, value = dt.Rows[0][0] }; return Success(dt); } else { var jsonData = new { id, value = "" }; return Success(jsonData); } case "chart": var chartData = await _dTChartIBLL.GetEntity(id); if (chartData != null && !string.IsNullOrEmpty(chartData.F_Sql)) { var dt = await _dataSourceIBLL.GetDataTableBySql(chartData.F_DataSourceId, chartData.F_Sql); var jsonData2 = new { id, value = dt }; return Success(jsonData2); } else { var jsonData = new { id }; return Success(jsonData); } case "list": var listdata = await _dTListIBLL.GetEntity(id); if (listdata != null && !string.IsNullOrEmpty(listdata.F_Sql)) { var dt = await _dataSourceIBLL.GetDataTableBySql(listdata.F_DataSourceId, listdata.F_Sql); var jsonData2 = new { id, value = dt }; return Success(jsonData2); } else { var jsonData = new { id }; return Success(jsonData); } } return Success(new { Id = id }); } /// /// 获取桌首页图片 /// /// [HttpGet] public async Task Imgid() { var list = await _dTImgIBLL.GetList(); List res = new List(); foreach (var item in list) { res.Add(item.F_Id); } return Success(res); } /// /// 获取图片 /// /// 主键 /// [HttpGet] [AllowAnonymous] public async Task Img(string id) { var stampEntity = await _dTImgIBLL.GetEntity(id); if (stampEntity != null && !string.IsNullOrEmpty(stampEntity.F_FileName)) { ImgEntity imgEntity = await _imgIBLL.GetEntity(stampEntity.F_FileName); if (imgEntity != null && !string.IsNullOrEmpty(imgEntity.F_Content)) { string imgContent = imgEntity.F_Content.Replace("data:image/" + imgEntity.F_ExName.Replace(".", "") + ";base64,", ""); byte[] arr = Convert.FromBase64String(imgContent); return File(arr, "application/octet-stream"); } else { return NotFound(); } } else { return NotFound(); } } } }