|
@@ -159,6 +159,48 @@ class Home extends Base_Controller {
|
|
|
'TCE_reduction' => 0
|
|
|
);
|
|
|
|
|
|
+ $type = intval($this->input->post('type',true));
|
|
|
+
|
|
|
+ $projectIdArr = $this->get_project_id();
|
|
|
+ $role = $this->get_user_info('role');
|
|
|
+ $type = $this->input->post('type',true);
|
|
|
+ $where = array();
|
|
|
+ if ($role != SYSTEM_ADMIN){
|
|
|
+ $company = $this->get_user_info('company');
|
|
|
+ $where['P.company'] = $company;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($projectIdArr)) $where['L.projectid'] = $projectIdArr;
|
|
|
+
|
|
|
+ if ($type == 0) {
|
|
|
+ $join = [];
|
|
|
+ $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'left'];
|
|
|
+ $join[] = ['table'=>'(select w1.* from realtime_info_log as w1 join (select lampid,max(updatetime) as maxTime from realtime_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as RI','cond'=>'L.id = RI.lampid','type'=>'inner'];
|
|
|
+ $res = $this->Lamp_model->get_list_by_multi_join($where, 'sum(RI.dischargeday) as discharge,sum(RI.chargeday) as charge',NULL, NULL, $join, NULL, NUll, 'L', true);
|
|
|
+ }elseif ($type == 1) {
|
|
|
+ $join = [];
|
|
|
+ $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'left'];
|
|
|
+ $join[] = ['table'=>'(select w1.* from history_info_log as w1 join (select lampid,max(updatetime) as maxTime from history_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as RI','cond'=>'L.id = RI.lampid','type'=>'inner'];
|
|
|
+ $res = $this->Lamp_model->get_list_by_multi_join($where, 'sum(RI.weekdischarg) as discharge,sum(RI.weekchargeah) as charge',NULL, NULL, $join, NULL, NUll, 'L', true);
|
|
|
+ }elseif ($type == 2) {
|
|
|
+ $join = [];
|
|
|
+ $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'left'];
|
|
|
+ $join[] = ['table'=>'(select w1.* from history_info_log as w1 join (select lampid,max(updatetime) as maxTime from history_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as RI','cond'=>'L.id = RI.lampid','type'=>'inner'];
|
|
|
+ $res = $this->Lamp_model->get_list_by_multi_join($where, 'sum(RI.monthdischarge) as discharge,sum(RI.monthchargeah) as charge',NULL, NULL, $join, NULL, NUll, 'L', true);
|
|
|
+ }else{
|
|
|
+ $join = [];
|
|
|
+ $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'left'];
|
|
|
+ $join[] = ['table'=>'(select w1.* from history_info_log as w1 join (select lampid,max(updatetime) as maxTime from history_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as RI','cond'=>'L.id = RI.lampid','type'=>'inner'];
|
|
|
+ $res = $this->Lamp_model->get_list_by_multi_join($where, 'sum(RI.totaldischarah) as discharge,sum(RI.totalchargeah) as charge',NULL, NULL, $join, NULL, NUll, 'L', true);
|
|
|
+ }
|
|
|
+ $data['electricity'] = $res['discharge'];
|
|
|
+ $data['CO2_reduction'] = $res['discharge'];
|
|
|
+ $data['SO2_reduction'] = $res['discharge'];
|
|
|
+ $data['TCE_reduction'] = $res['discharge'];
|
|
|
+ $data['CO2_reduction'] = round($res['charge']*0.977, 3);
|
|
|
+ $data['SO2_reduction'] = round($res['charge']*0.977/2620*8.5*1000, 3);
|
|
|
+ $data['TCE_reduction'] = round($res['charge']*0.977/2620*1000, 3);
|
|
|
+
|
|
|
exit(json_result('0000',$this->response['0000'],$data));
|
|
|
}
|
|
|
|