[後端] 前台修改sql

This commit is contained in:
dev02 2023-05-02 10:05:49 +08:00
parent ce792c2a5c
commit 412a8ec909
4 changed files with 55 additions and 55 deletions

View File

@ -17,8 +17,8 @@
"Server": "FYlY+w0XDIz+jmF2rlZWJw==", //0.201 "Server": "FYlY+w0XDIz+jmF2rlZWJw==", //0.201
"Port": "js2LutKe+rdjzdxMPQUrvQ==", "Port": "js2LutKe+rdjzdxMPQUrvQ==",
//"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30 //"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30
//"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp "Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp
"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome //"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome
//"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel //"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel
"Root": "SzdxEgaJJ7tcTCrUl2zKsA==", "Root": "SzdxEgaJJ7tcTCrUl2zKsA==",
"Password": "FVAPxztxpY4gJJKQ/se4bQ==" "Password": "FVAPxztxpY4gJJKQ/se4bQ=="

View File

@ -44,25 +44,29 @@ namespace FrontendWebApi.ApiControllers
var sql = $@" var sql = $@"
SELECT SELECT
( (
SELECT TOP(1) w.get_value SELECT w.get_value
FROM api_weateher w FROM api_weateher w
WHERE w.weather_type = 'Wx' AND @DateNow BETWEEN w.start_time AND w.end_time ORDER BY created_at DESC WHERE w.weather_type = 'Wx' AND @DateNow BETWEEN w.start_time AND w.end_time ORDER BY created_at DESC
limit 1
) AS WxText, ) AS WxText,
( (
SELECT TOP(1) wd.WeatherKey SELECT wd.WeatherKey
FROM api_weateher w FROM api_weateher w
LEFT JOIN weather_description wd ON w.get_value = wd.WeatherValue LEFT JOIN weather_description wd ON w.get_value = wd.WeatherValue
WHERE w.weather_type = 'WxV' AND @DateNow BETWEEN w.start_time AND w.end_time ORDER BY created_at DESC WHERE w.weather_type = 'WxV' AND @DateNow BETWEEN w.start_time AND w.end_time ORDER BY created_at DESC
limit 1
) AS Wx, ) AS Wx,
( (
SELECT TOP(1) w.get_value SELECT w.get_value
FROM api_weateher w FROM api_weateher w
WHERE w.weather_type = 'T' AND @DateNow < w.start_time WHERE w.weather_type = 'T' AND @DateNow < w.start_time
limit 1
) AS Temp, ) AS Temp,
( (
SELECT TOP(1) w.get_value SELECT w.get_value
FROM api_weateher w FROM api_weateher w
WHERE w.weather_type = 'RH' AND @DateNow < w.start_time WHERE w.weather_type = 'RH' AND @DateNow < w.start_time
limit 1
) AS RH ) AS RH
"; ";
var dateNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm:00"); var dateNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm:00");
@ -166,78 +170,77 @@ namespace FrontendWebApi.ApiControllers
var buildmenusql = await backendRepository.GetAllAsync<BuildMenuSql>(@$" var buildmenusql = await backendRepository.GetAllAsync<BuildMenuSql>(@$"
select select
me.* , me.* ,
b.full_name bfull_name, b.full_name bfull_name,
b.ip_address, b.ip_address,
b.priority bpriority, b.priority bpriority,
ma.full_name mafull_name, v1.system_key mafull_name,
ma.priority mapriority, v1.system_priority mapriority,
ma.code, v1.system_value,
sub.full_name subfull_name, v2.system_key subfull_name,
sub.priority subpriority v2.system_priority subpriority
from building_menu me from building_menu me
left join building b on b.building_guid = me.building_guid left join building b on b.building_tag = me.building_tag
left join main_system ma on ma.main_system_guid = me.main_system_guid left join variable v1 on me.main_system_tag = v1.system_value and v1.deleted = 0 and v1.system_type = 'device_system_category_layer2'
left join sub_system sub on sub.sub_system_guid = me.sub_system_guid left join variable v2 on me.sub_system_tag = v2.system_value and v2.deleted = 0 and v2.system_type = 'device_system_category_layer3'
inner join ( inner join (
SELECT SELECT
ap.building_guid, ap.building_tag,
ap.ShowView ap.ShowView
FROM FROM
( (
SELECT * SELECT *
FROM role_auth ra FROM role_auth ra
WHERE ra.role_guid = (SELECT ui.role_guid from userinfo ui where account = @Account) WHERE ra.role_guid = (SELECT ui.role_guid from userinfo ui where account = '@Account')
) ra ) ra
left join auth_page ap on ra.AuthCode = ap.AuthCode left join auth_page ap on ra.AuthCode = ap.AuthCode
where ap.AuthType = 1 where ap.AuthType = 1
) shower on shower.building_guid = me.building_guid and shower.ShowView = me.sub_system_guid ) shower on shower.building_tag = me.building_tag and shower.ShowView = v2.id
order by b.priority, ma.priority,sub.priority, sub.created_at DESC", new { Account = account }); order by b.priority, v1.system_priority, v2.system_priority, v2.created_at DESC", new { Account = account });
var floorsql = await backendRepository.GetAllAsync<Floorsql>(@" var floorsql = await backendRepository.GetAllAsync<Floorsql>(@"
select * from (select * from sub_system_floor ssf where ssf.deleted = 0 and ssf.status = 0) a select * from (select * from sub_system_floor ssf where ssf.deleted = 0 and ssf.status = 0) a
left join floor on floor.floor_guid = a.floor_guid order by floor.priority"); left join floor on floor.full_name = a.floor_tag order by floor.priority;");
var common = await backendRepository.GetAllAsync<KeyValue>($@"select ap.building_guid Name,ap.ShowView Value from auth_page ap var common = await backendRepository.GetAllAsync<KeyValue>($@"select ap.building_tag Name,ap.ShowView Value from auth_page ap
left join role_auth ra on ra.AuthCode = ap.AuthCode left join role_auth ra on ra.AuthCode = ap.AuthCode
right join userinfo ui on ui.role_guid = ra.role_guid right join userinfo ui on ui.role_guid = ra.role_guid
where SUBSTRING(ap.AuthCode,1,1) = 'C' and ui.account = '{account}' where SUBSTRING(ap.AuthCode,1,1) = 'C' and ui.account = '{account}'
"); ");
var building = buildmenusql.GroupBy(a => a.building_guid).ToList(); var building = buildmenusql.GroupBy(a => a.main_system_tag).ToList();
List<Building> buildingMenus = new List<Building>(); List<Building> buildingMenus = new List<Building>();
foreach (var menu in building) foreach (var menu in building)
{ {
Building building1 = new Building() Building building1 = new Building()
{ {
building_guid = menu.Select(a => a.building_guid).FirstOrDefault(),
full_name = menu.Select(a => a.bfull_name).FirstOrDefault(), full_name = menu.Select(a => a.bfull_name).FirstOrDefault(),
ip_address = menu.Select(a => a.ip_address).FirstOrDefault(), ip_address = menu.Select(a => a.ip_address).FirstOrDefault(),
priority = menu.Select(a => a.bpriority).FirstOrDefault(), priority = menu.Select(a => a.bpriority).FirstOrDefault(),
device_building_tag = menu.Select(a => a.device_building_tag).FirstOrDefault(), building_tag = menu.Select(a => a.device_building_tag).FirstOrDefault(),
main_system = new List<Main_system>(), main_system = new List<Main_system>(),
common = new List<string>() common = new List<string>()
}; };
var commonlist = common.Where(a => a.Name == building1.building_guid).Select(a => a.Value).ToList(); var commonlist = common.Where(a => a.Name == building1.building_tag).Select(a => a.Value).ToList();
building1.common = commonlist; building1.common = commonlist;
var mainsystem = menu.GroupBy(a => a.main_system_guid).ToList(); var mainsystem = menu.GroupBy(a => a.main_system_tag).ToList();
foreach (var ma in mainsystem) foreach (var ma in mainsystem)
{ {
Main_system main_System = new Main_system() Main_system main_System = new Main_system()
{ {
code = ma.Select(a => a.code).FirstOrDefault(), code = ma.Select(a => a.code).FirstOrDefault(),
main_system_guid = ma.Select(a => a.main_system_guid).FirstOrDefault(), main_system_tag = ma.Select(a => a.main_system_tag).FirstOrDefault(),
full_name = ma.Select(a => a.mafull_name).FirstOrDefault(), full_name = ma.Select(a => a.mafull_name).FirstOrDefault(),
priority = ma.Select(a => a.mapriority).FirstOrDefault(), priority = ma.Select(a => a.mapriority).FirstOrDefault(),
Sub_system = new List<Sub_systemGuid>() Sub_system = new List<Sub_systemGuid>()
}; };
var subsystem = ma.GroupBy(a => a.sub_system_guid).ToList(); var subsystem = ma.GroupBy(a => a.sub_system_tag).ToList();
foreach (var sub in subsystem) foreach (var sub in subsystem)
{ {
Sub_systemGuid sub_System = new Sub_systemGuid() Sub_systemGuid sub_System = new Sub_systemGuid()
{ {
sub_system_guid = sub.Select(a => a.sub_system_guid).FirstOrDefault(), sub_system_tag = sub.Select(a => a.sub_system_tag).FirstOrDefault(),
full_name = sub.Select(a => a.subfull_name).FirstOrDefault(), full_name = sub.Select(a => a.subfull_name).FirstOrDefault(),
priority = sub.Select(a => a.subpriority).FirstOrDefault(), priority = sub.Select(a => a.subpriority).FirstOrDefault(),
device_system_tag = sub.Select(a => a.device_system_tag).FirstOrDefault(), device_system_tag = sub.Select(a => a.device_system_tag).FirstOrDefault(),
@ -289,7 +292,7 @@ namespace FrontendWebApi.ApiControllers
left join floor on floor.floor_guid = a.floor_guid order by floor.priority"); left join floor on floor.floor_guid = a.floor_guid order by floor.priority");
Sub_system sub_System = new Sub_system() Sub_system sub_System = new Sub_system()
{ {
sub_system_guid = sub_system.sub_system_guid, sub_system_guid = sub_system.sub_system_tag,
system_url = sub_system.system_url, system_url = sub_system.system_url,
drawing = sub_system.drawing, drawing = sub_system.drawing,
Floors = new List<Floor>(), Floors = new List<Floor>(),

View File

@ -206,7 +206,7 @@ namespace FrontendWebApi.ApiControllers
join variable v1 on v1.id = v2.system_parent_id and v1.system_type = @main_system_type join variable v1 on v1.id = v2.system_parent_id and v1.system_type = @main_system_type
join device d on v1.system_value = d.device_system_tag and v2.system_value = d.device_name_tag and d.deleted = 0 and d.visible = 1 join device d on v1.system_value = d.device_system_tag and v2.system_value = d.device_name_tag and d.deleted = 0 and d.visible = 1
join device_item di on d.device_system_tag=di.device_system_tag and d.device_name_tag=di.device_name_tag join device_item di on d.device_system_tag=di.device_system_tag and d.device_name_tag=di.device_name_tag
and di.is_link = 1 and di.is_link = 1 and di.is_show_history = 1
where c.account = @account where c.account = @account
order by v1.system_priority, v2.system_priority", new { @account = myUser.account, @sub_system_type = sub_system_type, @main_system_type = main_system_type }); order by v1.system_priority, v2.system_priority", new { @account = myUser.account, @sub_system_type = sub_system_type, @main_system_type = main_system_type });
var dbbuilding = await frontendRepository.GetAllAsync<History_Build>( var dbbuilding = await frontendRepository.GetAllAsync<History_Build>(

View File

@ -21,15 +21,15 @@ namespace FrontendWebApi.Models
public class Buildingsql public class Buildingsql
{ {
public string building_guid { get; set; } public string building_tag { get; set; }
public string bfull_name { get; set; } public string bfull_name { get; set; }
public string ip_address { get; set; } public string ip_address { get; set; }
public int bpriority { get; set; } public int bpriority { get; set; }
} }
public class BuildMenuSql : Buildingsql public class BuildMenuSql : Buildingsql
{ {
public string main_system_guid { get; set; } public string main_system_tag { get; set; }
public string sub_system_guid { get; set; } public string sub_system_tag { get; set; }
public byte drawing { get; set; } public byte drawing { get; set; }
public byte icon_click { get; set; } public byte icon_click { get; set; }
public string icon_click_url { get; set; } public string icon_click_url { get; set; }
@ -48,9 +48,8 @@ namespace FrontendWebApi.Models
} }
public class Floorsql : Floor public class Floorsql : Floor
{ {
public string main_system_guid { get; set; } public string main_system_tag { get; set; }
public string sub_system_guid { get; set; } public string sub_system_tag { get; set; }
public string building_guid { get; set; }
} }
public class Devicesql : Device public class Devicesql : Device
{ {
@ -72,17 +71,16 @@ namespace FrontendWebApi.Models
public class Building public class Building
{ {
public string building_guid { get; set; } public string building_tag { get; set; }
public string full_name { get; set; } public string full_name { get; set; }
public string ip_address { get; set; } public string ip_address { get; set; }
public int priority { get; set; } public int priority { get; set; }
public string device_building_tag { get; set; }
public List<Main_system> main_system { get; set; } public List<Main_system> main_system { get; set; }
public List<string> common { get; set; } public List<string> common { get; set; }
} }
public class Main_system public class Main_system
{ {
public string main_system_guid { get; set; } public string main_system_tag { get; set; }
public string full_name { get; set; } public string full_name { get; set; }
public int priority { get; set; } public int priority { get; set; }
public string code { get; set; } public string code { get; set; }
@ -90,7 +88,7 @@ namespace FrontendWebApi.Models
} }
public class Sub_systemGuid public class Sub_systemGuid
{ {
public string sub_system_guid { get; set; } public string sub_system_tag { get; set; }
public string full_name { get; set; } public string full_name { get; set; }
public int priority { get; set; } public int priority { get; set; }
public string device_system_tag { get; set; } public string device_system_tag { get; set; }
@ -115,7 +113,6 @@ namespace FrontendWebApi.Models
public class Floor public class Floor
{ {
public string floor_guid { get; set; } public string floor_guid { get; set; }
public string building_tag { get; set; } public string building_tag { get; set; }
public string full_name { get; set; } public string full_name { get; set; }
public string InitMapName { get; set; } public string InitMapName { get; set; }