using Microsoft.AspNetCore.Mvc;
|
using System.Net;
|
using System.Net.Http.Headers;
|
using Microsoft.Extensions.Hosting.Internal;
|
using Microsoft.AspNetCore.Http.Extensions;
|
using IStation.Untity;
|
using Furion.DynamicApiController;
|
using System.ComponentModel.DataAnnotations;
|
using Mapster;
|
|
|
namespace IStation.Application
|
{
|
/// <summary>
|
/// Station
|
/// </summary>
|
[Route("Main/Station/Mobile")]
|
[ApiDescriptionSettings("Main", Name = "泵站(手机)", Order = 899)]
|
public class Station_MobileController : IDynamicApiController
|
{
|
/// <summary>
|
/// 通过 CorpID 获取默认组列表(手机)
|
/// </summary>
|
[Route("GetDefaultGroupListByCorpID@V1.0")]
|
[HttpGet]
|
public List<StationGroupMobileDto> GetDefaultGroupListByCorpID([FromQuery][Required] CorpIDInput input)
|
{
|
var corpId = input.CorpID;
|
var cacheKey = $"Main_Station_Mobile_GetDefaultGroupListByCorpID_{corpId}";
|
var vm_list = MemoryCacheHelper.GetSet(cacheKey, () => {
|
//泵站列表
|
var stationList = new Service.Station().GetByCorpID(corpId);
|
if (stationList == null || stationList.Count < 1)
|
return default;
|
//第一个业务类别
|
var logicCatalog = new Service.LogicCatalog().GetFirstByCorpID(corpId);
|
if (logicCatalog == null)
|
return default;
|
//业务清单列表
|
var logicTreeList = new Service.LogicTree().GetByCatalogID(corpId,logicCatalog.ID);
|
if (logicTreeList == null || logicTreeList.Count < 1)
|
return default;
|
//业务区域列表
|
var logicAreaList = new Service.LogicArea().GetByCatalogID(corpId,logicCatalog.ID);
|
|
//遍历业务清单
|
var vmList = new List<StationGroupMobileDto>();
|
foreach (var logicTree in logicTreeList)
|
{
|
if (logicTree.LogicType == ObjectType.LogicArea)
|
{
|
if (logicTreeList.Exists(t => t.ParentIds.LastOrDefault() == logicTree.ID && t.LogicType == ObjectType.Station))
|
{
|
var logicArea = logicAreaList.Find(t => t.ID == logicTree.LogicID);
|
var vm = new StationGroupMobileDto();
|
vm.ID = logicArea.ID;
|
vm.Name = logicArea.Name;
|
vm.Description = logicArea.Description;
|
vm.Items = new List<StationItemMobileDto>();
|
vmList.Add(vm);
|
}
|
}
|
else if (logicTree.LogicType == ObjectType.Station)
|
{
|
var station = stationList.Find(t=>t.ID==logicTree.LogicID);
|
var item = new StationItemMobileDto();
|
item.ID = station.ID;
|
item.Name = station.Name;
|
item.Address = station.Address;
|
item.Description = station.Description;
|
|
var parent = logicTreeList.Find(t=>t.ID==logicTree.ParentIds.LastOrDefault());
|
|
if (parent == null)
|
{
|
var group = vmList.Find(t => t.ID == 0);
|
if (group == null)
|
{
|
group = new StationGroupMobileDto();
|
group.ID = 0;
|
group.Name = "未分组";
|
group.Description = string.Empty;
|
group.Items = new List<StationItemMobileDto>();
|
vmList.Add(group);
|
}
|
group.Items.Add(item);
|
}
|
else
|
{
|
var group = vmList.Find(t=>t.ID==parent.LogicID);
|
group.Items.Add(item);
|
}
|
}
|
}
|
return vmList;
|
|
},CacheHelper.CacheLevel1);
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 获取关注列表(手机)
|
/// </summary>
|
[Route("GetAttentionList@V1.0")]
|
[HttpGet]
|
public List<StationAttentionMobileDto> GetAttentionList()
|
{
|
var userId = UserManager.UserID;
|
var cacheKey = $"Main_Station_Mobile_GetAttentionList_{userId}";
|
var vmList = MemoryCacheHelper.GetSet(cacheKey, () => {
|
var attentionList = new Service.UserAttention().GetByUserIDAndObjectType(UserManager.UserID, IStation.ObjectType.Station);
|
if (attentionList == null || attentionList.Count < 1)
|
return default;
|
var stationService = new Service.Station();
|
var vmCacheList = new List<StationAttentionMobileDto>();
|
foreach (var attention in attentionList)
|
{
|
var station = stationService.GetByID(attention.CorpID,attention.ObjectID);
|
if (station != null && station.UseStatus == Model.eUseStatus.Enable)
|
{
|
var vmCache=new StationAttentionMobileDto(station);
|
vmCacheList.Add(vmCache);
|
}
|
}
|
return vmCacheList;
|
|
}, CacheHelper.CacheLevel1);
|
return vmList;
|
|
}
|
|
|
|
|
}
|
}
|