102 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			102 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			C#
		
	
	
	
using IceCoffee.Common.Templates;
 | 
						|
using langguanApi.Common.Proxy;
 | 
						|
using langguanApi.Extensions.AutoDI;
 | 
						|
using langguanApi.Model;
 | 
						|
using langguanApi.Model.Dto;
 | 
						|
using Microsoft.AspNetCore.Mvc.ApiExplorer;
 | 
						|
using Microsoft.OpenApi.Writers;
 | 
						|
 | 
						|
namespace langguanApi.Service
 | 
						|
{
 | 
						|
    /// <summary>
 | 
						|
    /// 环境治理页面Service
 | 
						|
    /// </summary>
 | 
						|
    [ServiceInjection(InjectionType.Transient)]
 | 
						|
    public class EnvGovService
 | 
						|
    {
 | 
						|
        private HttpProxy _httpProxy;
 | 
						|
        private readonly IConfiguration _configuration;
 | 
						|
 | 
						|
        public EnvGovService(HttpProxy httpProxy, IConfiguration configuration)
 | 
						|
        {
 | 
						|
            _httpProxy = httpProxy;
 | 
						|
            _configuration = configuration;
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 首页数据
 | 
						|
        /// </summary>
 | 
						|
        /// <returns></returns>
 | 
						|
        public async Task<ApiResult> IndexView()
 | 
						|
        {
 | 
						|
            var url = _configuration.GetValue<string>("Apis:DeviceList");
 | 
						|
            var deviceResp = await _httpProxy.Get<RespModel<devceList>>(null, url);
 | 
						|
            var deviceList = deviceResp.data.List.GroupBy(g => g.GroupID)
 | 
						|
                .Select(s => new
 | 
						|
                {
 | 
						|
                    group = s.Key,
 | 
						|
                    items = new
 | 
						|
                    {
 | 
						|
                        devices = s.ToList().GroupBy(m => m.DeviceType)
 | 
						|
                        .Select(o => new
 | 
						|
                        {
 | 
						|
                            devicetype = ConvertDeviceType(o.Key),
 | 
						|
                            items = o.ToList()
 | 
						|
                             .Select(d => new
 | 
						|
                             {
 | 
						|
                                 d.DeviceID,
 | 
						|
                                 d.DeviceName,
 | 
						|
                                 d.Lon,
 | 
						|
                                 d.Lat,
 | 
						|
                                 d.CurrentAngel,
 | 
						|
                                 d.RunLog
 | 
						|
                             })
 | 
						|
                        })
 | 
						|
                    }
 | 
						|
                });
 | 
						|
            return new ApiResult
 | 
						|
            {
 | 
						|
                code = deviceResp.code,
 | 
						|
                msg = deviceResp.msg,
 | 
						|
                data = deviceList
 | 
						|
            };
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 转换设备类型
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="deviceType"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        private string ConvertDeviceType(int deviceType)
 | 
						|
        {
 | 
						|
            switch (deviceType)
 | 
						|
            {
 | 
						|
                case 1:
 | 
						|
                    return "雾炮";
 | 
						|
                case 2:
 | 
						|
                    return "雾桩";
 | 
						|
                case 3:
 | 
						|
                    return "干雾";
 | 
						|
            }
 | 
						|
            return null;
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 获取设备状态
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="deviceId"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        public async Task<ApiResult> DeviceStatu(string deviceId)
 | 
						|
        {
 | 
						|
            var url = _configuration.GetValue<string>("Apis:DeviceStatu");
 | 
						|
            var deviceStatuResp = await _httpProxy.Get<RespModel<List<DeviceStatu>>>(null, url);
 | 
						|
            var result = deviceStatuResp.data.Where(s => s.DeviceID == deviceId).FirstOrDefault();
 | 
						|
            return new ApiResult
 | 
						|
            {
 | 
						|
                //接口返回错误,暂时注释
 | 
						|
                //  code = deviceStatuResp.code,
 | 
						|
                code = 0,
 | 
						|
                msg = deviceStatuResp.msg,
 | 
						|
                data = result
 | 
						|
            };
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |