INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(4,'UDzGSkeZ','insert into tcode_device(tid,fid,fname,wid,wname,grpid,grpname,gid,gname,did,dname,knumb,kcnt,sort,halt,htime,ctime,mtime)\nSELECT \nt.tid,t.fid,t.fname,t.wid,t.wname,t.grpid,t.grpname,t.gid,t.gname,\nt.did,t.dname,count(1) as key_cnt ,\nsum(t.volume_on_day) as keyval_cnt,\n\'1000\' as sort,\n\'F\' as halt,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP\nfrom vcode_key_detail t \nGROUP BY t.tid,t.fid,t.fname,t.wid,t.wname,t.grpid,t.grpname,t.gid,t.gname,t.did,t.dname\nORDER BY t.dname desc \nON conflict(tid,did)\ndo update set \nfid = EXCLUDED.fid,\nfname = EXCLUDED.fname,\nwid = EXCLUDED.wid,\nwname = EXCLUDED.wname,\ngrpid = EXCLUDED.grpid,\ngrpname = EXCLUDED.grpname,\ngid = EXCLUDED.gid,\ngname = EXCLUDED.gname,\ndname = EXCLUDED.dname,\nknumb = EXCLUDED.knumb,\nkcnt = EXCLUDED.kcnt,\nmtime = CURRENT_TIMESTAMP;',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(48,'9xFhax2y','INSERT into trep_hkey_detail(tid,did,key,bdate,hours,val,ctime,mtime)\nSELECT t.tid,t.did, \n case when t.key = \'gas\' then \'蒸汽\'\n when t.key = \'正向累积数值整数部分\' then \'碱用量\'\n else t.key \n end as key ,\n current_date as bdate,\ndate_part(\'hour\', CURRENT_TIME) as hours,t.val_ex ,\nCURRENT_TIMESTAMP ,CURRENT_TIMESTAMP\nfrom \n(\n SELECT \n to_number(a.val,\'999999999.999999999\') + to_number(b.val,\'999999999.999999999\') as val_ex,\n a.* from \n (\n SELECT t.* from vcode_key_detail t \n where t.key = \'正向累积数值整数部分\'\n\n ) a,\n (\n SELECT t.* from vcode_key_detail t \n WHERE t.key = \'正向累积数值小数部分\'\n ) b\n where a.tid = b.tid and \n a.did = b.did and \n a.tid = \'22eed190-39af-11ed-8d4e-1d9073a615c6\'\n union all \n SELECT to_number(t.val,\'999999999.999999999\') as val_ex,t.* from vcode_key_detail t \n where t.tid = \'22eed190-39af-11ed-8d4e-1d9073a615c6\' and \n t.key = \'gas\'\n) t\nON CONFLICT (tid,did,key,bdate,hours)\nDO UPDATE SET \nval = EXCLUDED.val,\nmtime = CURRENT_TIMESTAMP;\n\n\n\n ',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(50,'bw6ULlLe','begin;\nSELECT func05(\'cur_open\');\nfetch all in cur_open;\nend; ',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(72,'K4QZT40A','SELECT t.* from trep_dkey_detail t \nwhere t.bdate = #{bdate} and \n t.tid = \'22eed190-39af-11ed-8d4e-1d9073a615c6\'',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(77,'EnFpExkx','SELECT t.key,\njsonb_agg(b) as arr\nfrom tcode_model_detail_ex t\n left JOIN \n (select concat(bdate,\'\',hours,\':00:00\')::TIMESTAMP::VARCHAR as time ,tid,key as nkey,val as value \n from trep_hkey_detail \n where ctime >= (CURRENT_TIMESTAMP - interval \'24 hour\')) b \non t.tid = b.tid and \n t.key = b.nkey \nwhere t.tid = \'22eed190-39af-11ed-8d4e-1d9073a615c6\' and \n t.code = \'all\' and \n substr(t.ex_s1,1,1) = \'1\'\nGROUP BY t.key;\n',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(151,'kU15HMrE','SELECT case when t.key = \'蒸汽\' then \'vapor\'\n when t.key = \'碱用量\' then \'alkali\'\n else t.key end as key,t.sort,jsonb_agg(b ORDER BY b.bdate,to_number(b.hours, \'99\')) as arr\n from tcode_model_detail_ex t\n left JOIN \n (select concat(bdate,\'\',hours,\':00:00\')::TIMESTAMP::VARCHAR as time,tid,\n case when key = \'蒸汽\' then \'vapor\'\n when key = \'碱用量\' then \'alkali\'\n else key end as nkey,val as value ,bdate,hours\n from trep_hkey_detail \n where bdate = CURRENT_DATE and \n did::varchar = #{did}\n ) b \n on t.tid = b.tid and \n t.key = b.nkey \n where t.tid = \'22eed190-39af-11ed-8d4e-1d9073a615c6\' and \n t.code = \'all\' and \n t.key in (\'vapor\',\'alkali\',\'electric\',\'gas\',\'water\')\n GROUP BY t.key,t.sort\n ORDER BY t.sort',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(153,'wFz52Yb1','SELECT case when t.key = \'蒸汽\' then \'vapor\'\n when t.key = \'碱用量\' then \'alkali\'\n else t.key end as key,t.sort,jsonb_agg(b ORDER BY b.bdate,to_number(b.hours, \'99\')) as arr\n from tcode_model_detail_ex t\n left JOIN \n (select concat(bdate,\'\',hours,\':00:00\')::TIMESTAMP::VARCHAR as time,tid,\n case when key = \'蒸汽\' then \'vapor\'\n when key = \'碱用量\' then \'alkali\'\n else key end as nkey,val as value ,bdate,hours\n from trep_hkey_detail \n where bdate = CURRENT_DATE and \n did::varchar = #{did}\n ) b \n on t.tid = b.tid and \n t.key = b.nkey \n where t.tid = \'22eed190-39af-11ed-8d4e-1d9073a615c6\' and \n t.code = \'all\' and \n t.key in (\'vapor\',\'alkali\',\'electric\',\'gas\',\'water\')\n GROUP BY t.key,t.sort\n ORDER BY t.sort',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(193,'N8sgjOWD','SELECT b.* from (\n SELECT case when a.key = \'alkali\' then \'碱用量\'\n when a.key = \'vapor\' then \'蒸汽\'\n else a.key \n end as name ,\n a.val as value,\n case when a.key = \'alkali\' then \'1020\'\n when a.key = \'vapor\' then \'1010\'\n else a.key \n end as sort \n from (\n SELECT t.key,\n sum(to_number(val_dep, \'9999999999999999999.99\'))-sum(to_number(val_arr, \'9999999999999999999.99\')) as val\n from trep_hkey_detail t,vcode_key_detail b \n where t.tid = b.tid and \n t.did = b.did and \n t.key = b.key and \n (t.tid::VARCHAR = #{tid}) AND\n (\'\'=#{grpid} or b.grpid::VARCHAR= #{grpid}) and \n t.key in (\'vapor\',\'alkali\') and \n t.bdate = CURRENT_DATE \n group by t.key \n ) a \n) b \norder by b.sort\n',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(194,'N8sgjOWD','SELECT \'蒸汽\' as name,sum(value) as value from (\n SELECT \n concat(a.bdate,\'\',a.hours,\':00:00\')::timestamp as time,\n (a.cval - b.cval) as value,\n a.key,a.hours,a.did\nfrom \n(SELECT to_number(t.val,\'999999999.99\') as cval,t.*,\n b.dname,b.id\n from trep_hkey_detail t,tcode_device b \n where t.tid = b.id and \n t.tid::character varying= #{tid} and \n (\'\' = \'\' or b.gid::character varying = \'\') and \n t.did = b.did and \n t.bdate = CURRENT_DATE - 1\n) a,\n(SELECT to_number(t.val,\'999999999.99\') as cval,t.*,\n b.dname,b.id\n from trep_hkey_detail t,tcode_device b \n where t.tid = b.id and \n t.tid::character varying= #{tid} and \n (\'\' = \'\' or b.gid::character varying = \'\') and \n t.did = b.did and \n t.bdate = CURRENT_DATE - 1\n) b \nwhere a.tid = b.id and \n a.did = b.did and \n a.key = b.key and \n a.key = \'蒸汽\' and \n a.bdate = b.bdate and \n to_number(a.hours,\'999999999\') - 1 = to_number(b.hours, \'999999999\')\n) t \nunion all \nSELECT \'碱用量\' as name,sum(value) as value from (\n SELECT \n concat(a.bdate,\'\',a.hours,\':00:00\')::timestamp as time,\n (a.cval - b.cval) as value,\n a.key,a.hours,a.did\nfrom \n(SELECT to_number(t.val,\'999999999.99\') as cval,t.*,\n b.dname,b.id\n from trep_hkey_detail t,tcode_device b \n where t.tid = b.id and \n t.tid::character varying= #{tid} and \n (\'\' = \'\' or b.gid::character varying = \'\') and \n t.did = b.did and \n t.bdate = CURRENT_DATE - 1\n) a,\n(SELECT to_number(t.val,\'999999999.99\') as cval,t.*,\n b.dname,b.id\n from trep_hkey_detail t,tcode_device b \n where t.tid = b.id and \n t.tid::character varying= #{tid} and \n (\'\' = \'\' or b.gid::character varying = \'\') and \n t.did = b.did and \n t.bdate = CURRENT_DATE -1 \n) b \nwhere a.tid = b.id and \n a.did = b.did and \n a.key = b.key and \n a.key = \'碱用量\' and \n a.bdate = b.bdate and \n to_number(a.hours,\'999999999\') - 1 = to_number(b.hours, \'999999999\')\n) t \n\n',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(202,'HYORZYyI','SELECT name, sum(value) as value \nfrom \n( \n SELECT to_number(t.val_dep,\'9999999999999999999.99\') - to_number(t.val_arr, \'9999999999999999999.99\') as value,\n b.name,t.key,c.descript,d.dname,d.grpname,\n t.bdate,to_char(t.ctime,\'yyyy-mm-dd hh24:mi:ss\') as ctime,to_char(t.mtime,\'yyyy-mm-dd hh24:mi:ss\') as mtime \n from trep_group_detail t,tcode_model_detail_ex b,tcode_group c ,vcode_key_detail d \n where t.tid = b.tid and \n t.tid = c.tid and \n t.tid = d.tid and \n t.did = d.did and \n t.key = d.key and \n t.grpcode = c.code and \n t.bdate = CURRENT_DATE-1 and \n t.key in (\'vapor\',\'alkali\') and \n (t.tid::VARCHAR = #{tid}) AND\n (\'\'=#{grpid} or d.grpid::VARCHAR= #{grpid}) and \n b.code = \'all\' and \n d.grpname != \'\' and \n t.key = b.key and \n substr(b.ex_s1,3,1) = \'1\'\n) a\ngroup by a.name \nORDER BY a.name desc \n',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(203,'HYORZYyI','SELECT b.* from (\n SELECT case when a.key = \'alkali\' then \'碱用量\'\n when a.key = \'vapor\' then \'蒸汽\'\n else a.key \n end as name ,\n a.val as value,\n case when a.key = \'alkali\' then \'1020\'\n when a.key = \'vapor\' then \'1010\'\n else a.key \n end as sort \n from (\n SELECT t.key,\n sum(to_number(val_dep, \'9999999999999999999.99\'))-sum(to_number(val_arr, \'9999999999999999999.99\')) as val\n from trep_hkey_detail t,vcode_key_detail b \n where t.tid = b.tid and \n t.did = b.did and \n t.key = b.key and \n (t.tid::VARCHAR = #{tid}) AND\n (\'\'=#{grpid} or b.grpid::VARCHAR= #{grpid}) and \n t.key in (\'vapor\',\'alkali\') and \n t.bdate = CURRENT_DATE \n group by t.key \n ) a \n) b \norder by b.sort\n',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(205,'VyCtYO0f','SELECT case when t.key = \'蒸汽\' then \'vapor\'\n when t.key = \'碱用量\' then \'alkali\'\n else t.key end as key,t.sort,jsonb_agg(b ORDER BY b.bdate,to_number(b.hours, \'99\')) as arr\n from tcode_model_detail_ex t\n left JOIN \n (select concat(bdate,\'\',hours,\':00:00\')::TIMESTAMP::VARCHAR as time,tid,\n case when key = \'蒸汽\' then \'vapor\'\n when key = \'碱用量\' then \'alkali\'\n else key end as nkey,val as value ,bdate,hours\n from trep_hkey_detail \n where bdate = CURRENT_DATE -1 and \n did::varchar = #{did}\n ) b \n on t.tid = b.tid and \n t.key = b.nkey \n where t.tid = \'22eed190-39af-11ed-8d4e-1d9073a615c6\' and \n t.code = \'all\' and \n t.key in (\'vapor\',\'alkali\',\'electric\',\'gas\',\'water\')\n GROUP BY t.key,t.sort\n ORDER BY t.sort',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(210,'IHQJLVtr','SELECT name, sum(value) as value \nfrom \n( \n SELECT to_number(t.val_dep,\'9999999999999999999.99\') - to_number(t.val_arr, \'9999999999999999999.99\') as value,\n b.name,t.key,c.descript,d.dname,d.grpname,\n t.bdate,to_char(t.ctime,\'yyyy-mm-dd hh24:mi:ss\') as ctime,to_char(t.mtime,\'yyyy-mm-dd hh24:mi:ss\') as mtime \n from trep_group_detail t,tcode_model_detail_ex b,(\n SELECT a.* from\n (\n SELECT CONCAT((CURRENT_DATE)::TEXT,\'\',t.arr)::TIMESTAMP as tarr,\n CONCAT((CURRENT_DATE)::TEXT,\'\',t.dep)::TIMESTAMP as tdep,\n t.* from tcode_group t\n where t.dep >= t.arr\n union\n SELECT CONCAT((CURRENT_DATE)::TEXT,\'\',t.arr)::TIMESTAMP as tarr,\n CONCAT((CURRENT_DATE+1)::TEXT,\'\',t.dep)::TIMESTAMP as tdep,\n t.* from tcode_group t\n where t.dep < t.arr\n union\n SELECT CONCAT((CURRENT_DATE-1)::TEXT,\'\',t.arr)::TIMESTAMP as tarr,\n CONCAT((CURRENT_DATE)::TEXT,\'\',t.dep)::TIMESTAMP as tdep,\n t.* from tcode_group t\n where t.dep < t.arr\n ) a\n where CURRENT_TIMESTAMP > a.tarr and\n CURRENT_TIMESTAMP <= a.tdep\n limit 1\n ) c ,vcode_key_detail d \n where t.tid = b.tid and \n t.tid = c.tid and \n t.tid = d.tid and \n t.did = d.did and \n t.key = d.key and \n t.grpcode = c.code and \n (t.ctime BETWEEN c.tarr and c.tdep) and \n t.key in (\'vapor\',\'alkali\') and \n (t.tid::VARCHAR = #{tid}) AND\n (\'\'=#{grpid} or d.grpid::VARCHAR= #{grpid}) and \n b.code = \'all\' and \n d.grpname != \'\' and \n t.key = b.key and \n substr(b.ex_s1,3,1) = \'1\'\n) a\ngroup by a.name \nORDER BY a.name desc \n',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(211,'IHQJLVtr','SELECT b.* from (\n SELECT case when a.key = \'alkali\' then \'碱用量\'\n when a.key = \'vapor\' then \'蒸汽\'\n else a.key \n end as name ,\n a.val as value,\n case when a.key = \'alkali\' then \'1020\'\n when a.key = \'vapor\' then \'1010\'\n else a.key \n end as sort \n from (\n SELECT t.key,\n sum(to_number(val_dep, \'9999999999999999999.99\'))-sum(to_number(val_arr, \'9999999999999999999.99\')) as val\n from trep_hkey_detail t,vcode_key_detail b \n where t.tid = b.tid and \n t.did = b.did and \n t.key = b.key and \n (t.tid::VARCHAR = #{tid}) AND\n (\'\'=#{grpid} or b.grpid::VARCHAR= #{grpid}) and \n t.key in (\'vapor\',\'alkali\') and \n t.bdate = CURRENT_DATE \n group by t.key \n ) a \n) b \norder by b.sort\n',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(215,'5SeUCRJy','SELECT case when t.key = \'蒸汽\' then \'vapor\'\n when t.key = \'碱用量\' then \'alkali\'\n else t.key end as key,t.sort,jsonb_agg(b ORDER BY b.bdate,to_number(b.hours, \'99\')) as arr\n from tcode_model_detail_ex t\n left JOIN \n (select concat(bdate,\'\',hours,\':00:00\')::TIMESTAMP::VARCHAR as time,tid,\n case when key = \'蒸汽\' then \'vapor\'\n when key = \'碱用量\' then \'alkali\'\n else key end as nkey,val as value ,bdate,hours\n from trep_hkey_detail \n where DATE_PART(\'Day\',CURRENT_DATE::timestamp - ctime::timestamp) < 1 and \n DATE_PART(\'hour\',ctime) <= 24 and \n did::varchar = #{did}\n ) b \n on t.tid = b.tid and \n t.key = b.nkey \n where t.tid = \'22eed190-39af-11ed-8d4e-1d9073a615c6\' and \n t.code = \'all\' and \n t.key in (\'vapor\',\'alkali\',\'electric\',\'gas\',\'water\')\n GROUP BY t.key,t.sort\n ORDER BY t.sort',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(216,'CQ9VkAr9','SELECT a.time,a.key,sum(value) as value \nfrom (\nSELECT \n concat(t.bdate,\'\',t.hours,\':00:00\')::timestamp as time,\n t.key,\n (to_number(t.val_dep, \'9999999999999999.99\'))-(to_number(t.val_arr, \'9999999999999999.99\')) as value\nfrom trep_hkey_detail t,vcode_key_detail b \nwhere \n (\'\' = #{tid} or t.tid::VARCHAR = #{tid}) and\n (\'\' = #{grpid} or b.grpid::varchar = #{grpid}) and \n t.key in (\'vapor\') and \n t.tid = b.tid and \n t.did = b.did and \n t.key = b.key and \n DATE_PART(\'Day\',CURRENT_DATE::timestamp - t.ctime::timestamp) < 1 and \n DATE_PART(\'hour\',t.ctime) <= 24 \n order by t.bdate,right(concat(\'00\',t.hours),2)\n) a\nGROUP BY a.time,a.key \nORDER BY a.time,a.key',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(217,'CQ9VkAr9','SELECT a.time,a.key,sum(value) as value \nfrom (\nSELECT \n concat(t.bdate,\'\',t.hours,\':00:00\')::timestamp as time,\n t.key,\n (to_number(t.val_dep, \'9999999999999999.99\'))-(to_number(t.val_arr, \'9999999999999999.99\')) as value\nfrom trep_hkey_detail t,vcode_key_detail b \nwhere \n (\'\' = #{tid} or t.tid::VARCHAR = #{tid}) and\n (\'\' = #{grpid} or b.grpid::varchar = #{grpid}) and \n t.key in (\'alkali\') and \n t.tid = b.tid and \n t.did = b.did and \n t.key = b.key and \n t.ctime > CURRENT_DATE - 1\n order by t.bdate,right(concat(\'00\',t.hours),2)\n) a\nGROUP BY a.time,a.key \nORDER BY a.time,a.key;',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(225,'EeBkndxU','insert into trep_hours_sta_detail as thsd (tid,did,key,bdate,hours,cron,len,val,time,ctime,mtime,created_time,updated_time)\nSELECT a.tid,a.did,a.key,CURRENT_DATE,\n date_part(\'hour\', CURRENT_TIME) as hours,\n 20 as cron,1 as len ,\n a.val,20*1,\n CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,\n (extract(epoch from CURRENT_TIMESTAMP) * 1000)::int8,\n (extract(epoch from CURRENT_TIMESTAMP) * 1000)::int8\nfrom \n(\n SELECT t.tid,t.did,t.key,\n case when round(date_part(\'epoch\', now()::timestamp - t.update_time::timestamp)::NUMERIC / 60) >= 5 then \'9\'\n else t.val \n end as val\n from vcode_key_detail t ,tcode_model_detail b \n where t.tid = b.tenant_id and \n t.key = b.key and \n b.code = \'default\' and \n b.change = true\n) a\nON CONFLICT (tid,did,key,bdate,hours,val)\nDO UPDATE SET \nlen = thsd.len + EXCLUDED.len,\ntime = (thsd.len + EXCLUDED.len) * 20,\nmtime = CURRENT_TIMESTAMP,\nupdated_time = (extract(epoch from CURRENT_TIMESTAMP) * 1000)::int8;\n',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(226,'FNMVwfcu','\ninsert into trep_group_sta_detail as trep \n (tid,did,bdate,grpcode,key,val,cron,len,time,ctime,mtime,created_time,updated_time)\nSELECT a.tid,a.did,a.tarr::date as bdate,a.code,a.key,\n a.val,\n 20 as cron,1 as len ,\n 20*1 as time,\n CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,\n (extract(epoch from CURRENT_TIMESTAMP) * 1000)::int8,\n (extract(epoch from CURRENT_TIMESTAMP) * 1000)::int8 \nfrom \n(\n SELECT t.tid,t.did,t.key,\n case when round(date_part(\'epoch\', now()::timestamp - t.update_time::timestamp)::NUMERIC / 60) >= 5 then \'9\'\n else t.val \n end as val,c.code,c.descript,c.tarr,c.tdep\n from vcode_key_detail t ,tcode_model_detail b,(\n SELECT a.* from\n (\n SELECT CONCAT((CURRENT_DATE)::TEXT,\'\',t.arr)::TIMESTAMP as tarr,\n CONCAT((CURRENT_DATE+tdays)::TEXT,\'\',t.dep)::TIMESTAMP as tdep,\n t.* from tcode_group t\n UNION\n SELECT CONCAT((CURRENT_DATE-tdays)::TEXT,\'\',t.arr)::TIMESTAMP as tarr,\n CONCAT((CURRENT_DATE)::TEXT,\'\',t.dep)::TIMESTAMP as tdep,\n t.* from tcode_group t\n where t.tdays > 0\n\n ) a \n where (CURRENT_TIMESTAMP BETWEEN a.tarr and a.tdep) \n ) c\n where t.tid = b.tenant_id and \n t.tid = c.tid and \n t.key = b.key and \n b.code = \'default\' and \n b.change = true\n) a\nON CONFLICT (tid,did,bdate,grpcode,key,val)\nDO UPDATE SET \nlen = trep.len + EXCLUDED.len,\ntime = (trep.len + EXCLUDED.len) * 20,\nmtime = CURRENT_TIMESTAMP,\nupdated_time = (extract(epoch from CURRENT_TIMESTAMP) * 1000)::int8;\n',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(227,'RSuNGzhs','insert into trep_day_sta_detail as trep \n (tid,did,bdate,key,val,cron,len,time,ctime,mtime,created_time,updated_time)\nSELECT a.tid,a.did,a.tarr::date as bdate,a.key,\n a.val,\n 20 as cron,1 as len ,\n 20*1 as time,\n CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,\n (extract(epoch from CURRENT_TIMESTAMP) * 1000)::int8,\n (extract(epoch from CURRENT_TIMESTAMP) * 1000)::int8 \nfrom \n(\n SELECT t.tid,t.did,t.key,\n case when round(date_part(\'epoch\', now()::timestamp - t.update_time::timestamp)::NUMERIC / 60) >= 5 then \'9\'\n else t.val \n end as val,c.tarr,c.tdep\n from vcode_key_detail t ,tcode_model_detail b,(\n SELECT a.* from\n (\n SELECT CONCAT((CURRENT_DATE)::TEXT,\'\',t.arr)::TIMESTAMP as tarr,\n CONCAT((CURRENT_DATE+tdays)::TEXT,\'\',t.dep)::TIMESTAMP as tdep,\n t.* from tcode_group_days t\n UNION\n SELECT CONCAT((CURRENT_DATE-tdays)::TEXT,\'\',t.arr)::TIMESTAMP as tarr,\n CONCAT((CURRENT_DATE)::TEXT,\'\',t.dep)::TIMESTAMP as tdep,\n t.* from tcode_group_days t\n where t.tdays > 0\n\n ) a \n where (CURRENT_TIMESTAMP BETWEEN a.tarr and a.tdep) \n ) c\n where t.tid = b.tenant_id and \n t.tid = c.tid and \n t.key = b.key and \n b.code = \'default\' and \n b.change = true\n) a\nON CONFLICT (tid,did,bdate,key,val)\nDO UPDATE SET \nlen = trep.len + EXCLUDED.len,\ntime = (trep.len + EXCLUDED.len) * 20,\nmtime = CURRENT_TIMESTAMP,\nupdated_time = (extract(epoch from CURRENT_TIMESTAMP) * 1000)::int8;\n',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(235,'0qLjHowN','SELECT t.*,\n d.fid,d.fname,d.wid,d.wname,d.grpid,d.grpname,d.gid,d.gname,d.dname,d.volume_on_day \n from trep_group_sta_detail t,tcode_group c ,vcode_key_detail d \n where t.tid = d.tid and \n t.tid = \'22eed190-39af-11ed-8d4e-1d9073a615c6\' and \n t.tid = c.tid and \n t.tid = d.tid and \n t.key = d.key and \n t.grpcode = c.code and \n t.bdate::varchar = #{date}::varchar and \n (d.dname like concat(#{deviceName},\'%\') or \'\' = #{deviceName}) and \n (c.code = #{grpcode} or \'\' = #{grpcode}) and \n (d.grpname like concat(#{grptype},\'%\') or \'\' = #{grptype}) and \n d.grpname != \'\' ;',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(237,'v7p2AAqp','SELECT t.* \nfrom vcode_key_detail t \nwhere t.tid = \'22eed190-39af-11ed-8d4e-1d9073a615c6\' and \n (t.dname like concat(#{deviceName},\'%\') or \'\' = #{deviceName}) and \n (t.key = #{key} or \'\' = #{key}) and \n (t.grpname like concat(#{grptype},\'%\') or \'\' = #{grptype}) and \n t.grpname != \'\' ;',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(240,'hGLKRYiu','SELECT to_number(t.val_dep,\'9999999999999999999.9999\') - to_number(t.val_arr, \'9999999999999999999.9999\') as value,\n b.name,d.dname,d.key,d.grpname,\n t.bdate,to_char(t.ctime,\'yyyy-mm-dd hh24:mi:ss\') as ctime,to_char(t.mtime,\'yyyy-mm-dd hh24:mi:ss\') as mtime \n from trep_dkey_detail t,tcode_model_detail_ex b,vcode_key_detail d\n where t.tid = b.tid and \n t.tid = d.tid and \n t.did = d.did and \n t.key = d.key and \n (t.bdate BETWEEN concat(to_char(date_trunc(\'month\', concat(#{year},\'-\',#{month},\'-01\')::DATE - interval \'1\' month),\'yyyy-mm\'),\'-26\')::DATE and \n concat(#{year},\'-\',#{month},\'-25\')::DATE) and \n (d.dname like concat(#{deviceName},\'%\') or \'\' = #{deviceName}) and \n (b.name like concat(#{propName},\'%\') or \'\' = #{propName}) and \n (d.grpname like concat(#{grptype},\'%\') or \'\' = #{grptype}) and \n b.code = \'all\' and \n t.key = b.key and \n d.grpname != \'\' and \n substr(b.ex_s1,3,1) = \'1\'\n ORDER BY bdate desc,grpname,dname,key asc ;\n ',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(247,'3qxDmpBG','INSERT into trep_dkey_detail(tid,did,key,bdate,ctime,mtime,val,val_dep,val_arr)\nselect a.tid,a.did,a.key,a.bdate,\nmin(a.ctime),max(a.mtime),\n(to_number(min(val_arr), \'999999999999999.99\') + sum(a.value))::varchar as val,\n(to_number(min(val_arr), \'999999999999999.99\') + sum(a.value))::varchar as val_dep,\nmin(val_arr) as val_arr\nfrom \n(\nSELECT t.*,to_number(t.val_dep, \'999999999999999.9999\') - to_number(t.val_arr, \'999999999999999.9999\') as value \nfrom trep_group_detail t\nwhere t.bdate = CURRENT_DATE\n) a\ngroup by a.tid,a.did,a.key,a.bdate\nON CONFLICT (tid,did,key,bdate)\nDO UPDATE SET \nval = EXCLUDED.val,\nval_dep = EXCLUDED.val_dep,\nmtime = CURRENT_TIMESTAMP;',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(248,'tCoVivD8','INSERT into trep_hkey_detail(tid,did,key,bdate,hours,val,ctime,mtime,val_arr,val_dep)\nSELECT t.tid,t.did, t.key,current_date as bdate,\ndate_part(\'hour\', CURRENT_TIME) as hours,t.val ,\nCURRENT_TIMESTAMP ,CURRENT_TIMESTAMP,\nt.val,t.val\n from vcode_key_detail t,tcode_model_detail b\nwhere t.tid = b.tenant_id and \n t.key = b.key and \n b.code = \'default\' and \n b.halt = \'F\' and \n b.hour = true \n ON CONFLICT (tid,did,key,bdate,hours)\nDO UPDATE SET \nval = EXCLUDED.val,\nval_dep = EXCLUDED.val_dep,\nmtime = CURRENT_TIMESTAMP;',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(249,'tCoVivD8','update trep_hkey_detail \n set peak = case when c.switch = 1 then \n (to_number(val_dep,\'9999999999999999999.99\') - to_number(val_arr, \'9999999999999999999.99\'))::varchar else \n\'0.00\' end ,\n valley = case when c.switch = 0 then \n (to_number(val_dep,\'9999999999999999999.99\') - to_number(val_arr, \'9999999999999999999.99\'))::varchar else \n\'0.00\' end \n from \n (SELECT case when CURRENT_TIME >= \'08:00\'::time then 1\n else 0 end \n as switch) c\nwhere bdate = CURRENT_DATE and \n hours = date_part(\'hour\', CURRENT_TIME)::varchar and \n key = \'electric\';',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(250,'7TVjkWPy','INSERT into trep_dkey_detail(tid,did,key,bdate,val_arr,val_dep,val,ctime,mtime) \nSELECT t.tid,t.did,t.key,c.tarr::date as bdate,\n t.val,t.val,t.val,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP\n from vcode_key_detail t ,tcode_model_detail b,\n (\n SELECT a.* from\n (\n SELECT CONCAT((CURRENT_DATE)::TEXT,\'\',t.arr)::TIMESTAMP as tarr,\n CONCAT((CURRENT_DATE+tdays)::TEXT,\'\',t.dep)::TIMESTAMP as tdep,\n t.* from tcode_group_days t\n UNION\n SELECT CONCAT((CURRENT_DATE-tdays)::TEXT,\'\',t.arr)::TIMESTAMP as tarr,\n CONCAT((CURRENT_DATE)::TEXT,\'\',t.dep)::TIMESTAMP as tdep,\n t.* from tcode_group_days t\n where t.tdays > 0\n\n ) a \n where (CURRENT_TIMESTAMP BETWEEN a.tarr and a.tdep) \n ) c\n where \n t.tid = b.tenant_id and \n t.tid = c.tid and \n t.key = b.key and \n b.code = \'default\' and \n b.day = true\nON CONFLICT (tid,did,key,bdate)\nDO UPDATE SET \nval_dep = EXCLUDED.val_dep,\nmtime = CURRENT_TIMESTAMP;',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(251,'7TVjkWPy','update trep_dkey_detail \n set peak = (to_number(val_dep,\'9999999999999999999.99\') - to_number(val_arr, \'9999999999999999999.99\'))::varchar,\n valley = \'0.00\'\nwhere bdate = CURRENT_DATE and \n key = \'electric\';',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(262,'B1ANmtET','insert into trep_sta_detail(tid,did,key,val_arr,val_dep)\nSELECT a.tid,a.did,a.key,a.val as val_arr,a.val as val_dep\nfrom \n(\n SELECT t.tid,t.did,t.key,\n min(case when round(date_part(\'epoch\', now()::timestamp - \n (select max(update_time)\n from vcode_key_detail x \n where x.tid = t.tid and \n x.did = t.did and \n x.key = t.key \n )::timestamp\n )::NUMERIC / 60) >= 5 then \'9\'\n else t.val \n end ) as val\n from vcode_key_detail t ,tcode_model_detail b \n where t.tid = b.tenant_id and \n t.key = b.key and \n b.code = \'default\' and \n b.change = true \n GROUP BY t.tid,t.did,t.key\n) a\nON CONFLICT (tid,did,key)\nDO UPDATE SET \nval_dep = EXCLUDED.val_dep,\nmtime = CURRENT_TIMESTAMP;\n\n',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(263,'B1ANmtET','INSERT into trep_hsta_detail(tid,did,key,val,arr,dep)\nSELECT t.tid,t.did,t.key,t.val_arr,t.ctime,t.mtime\n from trep_sta_detail t \n where t.val_arr != t.val_dep ;',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(264,'B1ANmtET','UPDATE trep_sta_detail \n set val_arr = val_dep,ctime = CURRENT_TIMESTAMP \n where val_arr != val_dep;',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(265,'xfXpHIg0','SELECT to_number(t.val_dep,\'9999999999999999999.9999\') - to_number(t.val_arr, \'9999999999999999999.9999\') as value,\n b.name,c.descript,d.dname,d.grpname,\n t.bdate,to_char(t.ctime,\'yyyy-mm-dd hh24:mi:ss\') as ctime,to_char(t.mtime,\'yyyy-mm-dd hh24:mi:ss\') as mtime \n from trep_group_detail t,tcode_model_detail_ex b,tcode_group c ,vcode_key_detail d \n where t.tid = b.tid and \n t.tid = c.tid and \n t.tid = d.tid and \n t.did = d.did and \n t.key = d.key and \n t.grpcode = c.code and \n t.bdate::varchar = #{date}::varchar and \n (d.dname like concat(\'%\',#{deviceName},\'%\') or \'\' = #{deviceName}) and \n (b.name like concat(#{propName},\'%\') or \'\' = #{propName}) and \n (c.code = #{grpcode} or \'\' = #{grpcode}) and \n (d.grpname like concat(#{grptype},\'%\') or \'\' = #{grptype}) and \n b.code = \'all\' and \n d.grpname != \'\' and \n t.key = b.key and \n substr(b.ex_s1,3,1) = \'1\'',NULL,NULL);
INSERTINTO`api_sql`(`id`,`api_id`,`sql_text`,`transform_plugin`,`transform_plugin_params`)VALUES(266,'cD4sCi7I','SELECT to_number(t.val_dep,\'9999999999999999999.9999\') - to_number(t.val_arr, \'9999999999999999999.9999\') as value,\n b.name,c.descript,d.dname,d.grpname,\n t.bdate,to_char(t.ctime,\'yyyy-mm-dd hh24:mi:ss\') as ctime,to_char(t.mtime,\'yyyy-mm-dd hh24:mi:ss\') as mtime \n from trep_group_detail t,tcode_model_detail_ex b,tcode_group c ,vcode_key_detail d \n where t.tid = b.tid and \n t.tid = \'22eed190-39af-11ed-8d4e-1d9073a615c6\' and \n t.tid = c.tid and \n t.tid = d.tid and \n t.did = d.did and \n t.key = d.key and \n t.grpcode = c.code and \n (t.bdate BETWEEN #{arr}::date and #{dep}::date ) and \n (d.dname like concat(\'%\',#{deviceName},\'%\') or \'\' = #{deviceName}) and \n (b.name like concat(#{propName},\'%\') or \'\' = #{propName}) and \n (c.code = #{grpcode} or \'\' = #{grpcode}) and \n (d.grpname like concat(#{grptype},\'%\') or \'\' = #{grptype}) and \n b.code = \'all\' and \n d.grpname != \'\' and \n t.key = b.key and \n substr(b.ex_s1,3,1) = \'1\'\n order by t.did,t.key,t.bdate,t.grpcode;\n\n\n ',NULL,NULL);
COMMIT;
-- ----------------------------
-- Table structure for datasource
-- ----------------------------
DROPTABLEIFEXISTS`datasource`;
CREATETABLE`datasource`(
`id`varchar(255)NOTNULL,
`name`varchar(255)DEFAULTNULL,
`note`varchar(255)DEFAULTNULL,
`type`varchar(255)DEFAULTNULL,
`url`varchar(255)DEFAULTNULL,
`username`varchar(255)DEFAULTNULL,
`password`varchar(255)DEFAULTNULL,
`driver`varchar(100)DEFAULTNULL,
`table_sql`varchar(255)DEFAULTNULL,
`create_time`varchar(20)DEFAULTNULL,
`update_time`varchar(20)DEFAULTNULL,
PRIMARYKEY(`id`)
)ENGINE=InnoDBDEFAULTCHARSET=utf8mb3;
-- ----------------------------
-- Records of datasource
-- ----------------------------
BEGIN;
INSERTINTO`datasource`(`id`,`name`,`note`,`type`,`url`,`username`,`password`,`driver`,`table_sql`,`create_time`,`update_time`)VALUES('EhgozRdv','V3-测试环境','','postgresql','jdbc:postgresql://121.199.175.235:30433/hsiotdb','postgres','ZeDk5+VSpaKseaGVpkfEcA==','org.postgresql.Driver','SELECT table_name FROM information_schema.tables WHERE table_schema = \'public\' ORDER BY table_name','2022-09-24 23:19:12','2022-09-24 23:19:12');
INSERTINTO`datasource`(`id`,`name`,`note`,`type`,`url`,`username`,`password`,`driver`,`table_sql`,`create_time`,`update_time`)VALUES('kSC2Qziy','物联平台V3生产','','postgresql','jdbc:postgresql://47.99.83.75:30433/hsiotdb','postgres','ZeDk5+VSpaKseaGVpkfEcA==','org.postgresql.Driver','SELECT table_name FROM information_schema.tables WHERE table_schema = \'public\' ORDER BY table_name','2022-09-23 12:30:22','2022-09-23 13:13:59');