|
|
@@ -357,46 +357,61 @@ class tools {
|
|
|
$operate = utils::_get('operate');
|
|
|
$operate = strtolower($operate);
|
|
|
|
|
|
- if ($operate == "notifications"){
|
|
|
- $rules_type = common::check_input($_POST ['rules_type']);
|
|
|
+ if ($operate == "notifications_init"){
|
|
|
+ $rules_type = common::check_input($_REQUEST['rules_type']);
|
|
|
+ $milestoneData = array();
|
|
|
+ $containerData = array();
|
|
|
+ $delayData = array();
|
|
|
+ $changeData = array();
|
|
|
if ($rules_type == "all"){
|
|
|
- $sql = "select *,
|
|
|
- (select o.h_bol from public.kln_ocean o where o.serial_no = ni.serial_no limit 1)
|
|
|
- from public.kln_notifiation_info ni
|
|
|
- where lower(ni.user_login) = '"._getLoginName()."'
|
|
|
- and (ni.frequency_type = 'Instant'
|
|
|
- or (ni.frequency_type = 'Daily' and timezone(ni.daily_time_zone, NOW()::time) > ni.daily_time::time)
|
|
|
- or (ni.frequency_type = 'Weekly' and timezone(ni.weekly_time_zone, NOW()::time) > ni.weekly_time::time
|
|
|
- and ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%'))
|
|
|
- and ni.notifications_method = true and ni.is_send_message = false order by ni.insert_date desc";
|
|
|
- }else{
|
|
|
- $sql = "select case when COALESCE(ni.milestone_code,'') <> '' and ni.milestone_transport_mode = 'sea'
|
|
|
- then (select description from public.customer_service_milestone_sno where type = 'sea' and code = ni.milestone_code)
|
|
|
- else (select description from public.customer_service_milestone_sno where type = 'air' and code = ni.milestone_code) end as milestone_desc,
|
|
|
- ni.milestone_code,*
|
|
|
- (select o.h_bol from public.kln_ocean o where o.serial_no = ni.serial_no limit 1)
|
|
|
- from public.kln_notifiation_info ni
|
|
|
- where lower(ni.user_login) = '"._getLoginName()."'
|
|
|
- and ni.rules_type = '".$rules_type."'
|
|
|
- and (ni.frequency_type = 'Instant'
|
|
|
- or (ni.frequency_type = 'Daily' and timezone(ni.daily_time_zone, NOW()::time) > ni.daily_time::time)
|
|
|
- or (ni.frequency_type = 'Weekly' and timezone(ni.weekly_time_zone, NOW()::time) > ni.weekly_time::time
|
|
|
- and ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%'))
|
|
|
- and ni.notifications_method = true and ni.is_send_message = false order by ni.insert_date desc";
|
|
|
+ $milestoneData = $this->getNotifications("Milestone_Update","all");
|
|
|
+ $containerData = $this->getNotifications("Container_Status_Update","all");
|
|
|
+ $delayData = $this->getNotifications("Departure/Arrival_Delay","all");
|
|
|
+ $changeData = $this->getNotifications("ETD/ETA_Change","all");
|
|
|
+ } else {
|
|
|
+ $data = $this->getNotifications($rules_type,"all");
|
|
|
+ if($rules_type == "Milestone_Update"){
|
|
|
+ $milestoneData = $data;
|
|
|
+ }elseif($rules_type == "Container_Status_Update"){
|
|
|
+ $containerData = $data;
|
|
|
+ }elseif($rules_type == "Departure/Arrival_Delay"){
|
|
|
+ $delayData = $data;
|
|
|
+ }elseif($rules_type == "ETD/ETA_Change"){
|
|
|
+ $changeData = $data;
|
|
|
+ }
|
|
|
}
|
|
|
- $notifications = common::excuteListSql($sql);
|
|
|
|
|
|
- $all_rules = array("Milestone_Update","Container_Status_Update","Departure/Arrival_Delay","ETD/ETA_Change");
|
|
|
-
|
|
|
- foreach($notifications as $notification){
|
|
|
- if($notification["notifiation_type"] == "Milestone_Update"){
|
|
|
- if ($notification["frequency_type"] == "Instant"){
|
|
|
- $milestoneInstantMessage[] = array("mode"=>$notification["milestone_transport_mode"],"HBOL"=>$notification["milestone_transport_mode"],
|
|
|
- "HBOL"=>$notification["milestone_transport_mode"]);
|
|
|
+ $data = array("milestoneData"=>$milestoneData,"containerData"=>$containerData,"delayData"=>$delayData,"changeData"=>$changeData);
|
|
|
+ $instant_sum = array();
|
|
|
+ foreach($data as $v){
|
|
|
+ if(!empty($v['instant'])){
|
|
|
+ foreach($v['instant'] as $instant){
|
|
|
+ $instant_sum[] = $instant;
|
|
|
}
|
|
|
-
|
|
|
+ }
|
|
|
+ if(!empty($v['daily'])){
|
|
|
+ //取第一个显示
|
|
|
+ $v['daily'][0]['numericRecords'] = count($v['daily']);
|
|
|
+ $instant_sum[]= $v['daily'][0];
|
|
|
+ }
|
|
|
+ if(!empty($milestoneData['weekly'])){
|
|
|
+ $v['weekly'][0]['numericRecords'] = count($v['weekly']);
|
|
|
+ $instant_sum[]= $v['weekly'][0];
|
|
|
}
|
|
|
}
|
|
|
+ //根据时间顺序排序
|
|
|
+ $insert_dates = array_column($instant_sum, 'insert_date');
|
|
|
+ array_multisort($insert_dates, SORT_ASC, $instant_sum);
|
|
|
+
|
|
|
+ $info = array();
|
|
|
+ foreach($instant_sum as $mInfo){
|
|
|
+ $eventCard = $this->getEventCard($mInfo,"Milestone_Update");
|
|
|
+ $Info[] = $eventCard;
|
|
|
+ }
|
|
|
+
|
|
|
+ $returnData = array("notificationType"=>"event","info" =>$info);
|
|
|
+ common::echo_json_encode(200,$returnData);
|
|
|
+ exit();
|
|
|
|
|
|
}
|
|
|
}
|
|
|
@@ -821,30 +836,108 @@ class tools {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public function getNotifications($rules_type){
|
|
|
-
|
|
|
- //$all_rules = array("Milestone_Update","Container_Status_Update","Departure/Arrival_Delay","ETD/ETA_Change");
|
|
|
- if($rules_type == "Milestone_Update"){
|
|
|
- $sql = "select case when COALESCE(ni.milestone_code,'') <> '' and ni.milestone_transport_mode = 'sea'
|
|
|
- then (select description from public.customer_service_milestone_sno where type = 'sea' and code = ni.milestone_code)
|
|
|
- else (select description from public.customer_service_milestone_sno where type = 'air' and code = ni.milestone_code)
|
|
|
- end as milestone_desc,
|
|
|
- case when ni.milestone_code in ('IFFBCF','IFFBCR','IFFSIL','IFFEDO','IFFECC')
|
|
|
- then ''
|
|
|
- when ni.milestone_code in ('IFFREC','IFFECP')
|
|
|
- then ''
|
|
|
- ni.milestone_date,ni.milestone_time,
|
|
|
- (select o.h_bol from public.kln_ocean o where o.serial_no = ni.serial_no limit 1)
|
|
|
- from public.kln_notifiation_info ni
|
|
|
- where lower(ni.user_login) = '"._getLoginName()."'
|
|
|
- and ni.rules_type = '".$rules_type."'
|
|
|
- and (ni.frequency_type = 'Instant'
|
|
|
+ public function getNotifications($notifiation_type,$frequency_type){
|
|
|
+ if ($frequency_type == "all"){
|
|
|
+ $sql_where = " and (ni.frequency_type = 'Instant'
|
|
|
or (ni.frequency_type = 'Daily' and timezone(ni.daily_time_zone, NOW()::time) > ni.daily_time::time)
|
|
|
or (ni.frequency_type = 'Weekly' and timezone(ni.weekly_time_zone, NOW()::time) > ni.weekly_time::time
|
|
|
- and ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%'))
|
|
|
- and ni.notifications_method = true and ni.is_send_message = false order by ni.insert_date desc";
|
|
|
+ and ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%'))";
|
|
|
+ } elseif($frequency_type == "Daily"){
|
|
|
+ $sql_where = " and (ni.frequency_type = 'Daily' and timezone(ni.daily_time_zone, NOW()::time) > ni.daily_time::time)";
|
|
|
+ } elseif($frequency_type == "Weekly"){
|
|
|
+ $sql_where = " and (ni.frequency_type = 'Weekly' and timezone(ni.weekly_time_zone, NOW()::time) > ni.weekly_time::time
|
|
|
+ and ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%')";
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($notifiation_type == "Milestone_Update"){
|
|
|
+ $sql = "select ni.*,
|
|
|
+ case when COALESCE(ni.frequency_type,'') = 'Daily'
|
|
|
+ then to_char(timezone(ni.daily_time_zone, insert_date),'Mon DD, YYYY')
|
|
|
+ when COALESCE(ni.frequency_type,'') = 'Weekly'
|
|
|
+ then to_char(timezone(ni.weekly_time_zone, insert_date),'Mon DD, YYYY')
|
|
|
+ else ''
|
|
|
+ end as insert_date_format,
|
|
|
+ ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.milestone_desc
|
|
|
+ from public.kln_notifiation_info ni
|
|
|
+ left join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,
|
|
|
+ case when COALESCE(ni.milestone_code,'') <> '' and oo.transport_mode = 'sea'
|
|
|
+ then (select description from public.customer_service_milestone_sno where type = 'sea' and code = ni.milestone_code)
|
|
|
+ else (select description from public.customer_service_milestone_sno where type = 'air' and code = ni.milestone_code)
|
|
|
+ end as milestone_desc
|
|
|
+ from public.kln_ocean oo
|
|
|
+ where oo.serial_no = ni.serial_no limit 1) ccc on true
|
|
|
+ where lower(ni.user_login) = '"._getLoginName()."'
|
|
|
+ and ni.notifiation_type = '".$notifiation_type."'
|
|
|
+ ".$sql_where." and ni.notifications_method = true and ni.is_send_message = false order by ni.insert_date desc";
|
|
|
+ }
|
|
|
+ if ($notifiation_type == "Milestone_Update"){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ error_log($sql);
|
|
|
+ $data = common::excuteListSql($sql);
|
|
|
+ //统一处理数据Instant Daily weekly_week 先分开在处理
|
|
|
+ $instant = array();
|
|
|
+ $daily = array();
|
|
|
+ $daily_uniqe = array();
|
|
|
+ $weekly = array();
|
|
|
+ $weekly_uniqe = array();
|
|
|
+ foreach($data as $d){
|
|
|
+ if ($d['frequency_type'] == "Instant"){
|
|
|
+ $instant[] = $d;
|
|
|
+ }
|
|
|
+ if ($d['frequency_type'] == "Daily"){
|
|
|
+ if(utils::in_array($d['serial_no'],$daily_uniqe)){
|
|
|
+ $temp = $daily[$d['serial_no']];
|
|
|
+ $temp[] = $d;
|
|
|
+ $daily[$d['serial_no']] = $temp;
|
|
|
+ } else {
|
|
|
+ $daily[$d['serial_no']] = $d['serial_no'];
|
|
|
+ $daily_uniqe[] = $d;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($d['frequency_type'] == "Weekly"){
|
|
|
+ if(utils::in_array($d['serial_no'],$weekly_uniqe)){
|
|
|
+ $temp = $weekly[$d['serial_no']];
|
|
|
+ $temp[] = $d;
|
|
|
+ $weekly[$d['serial_no']] = $temp;
|
|
|
+ } else {
|
|
|
+ $weekly[$d['serial_no']] = $d;
|
|
|
+ $weekly_uniqe[] = $d['serial_no'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return array("instant" =>$instant,"daily" =>utils::arrayKeyToInt($daily),"weekly"=>utils::arrayKeyToInt($weekly));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getEventCard($mInfo,$notifiation_type){
|
|
|
+ if($notifiation_type == "Milestone_Update"){
|
|
|
+ $timeAndlocations = common::getMilestoneTimeAndlocations($mInfo["milestone_code"],$mInfo["transport_mode"],$mInfo["serial_no"],$mInfo["order_from"]);
|
|
|
+ $eventCard = array("type" =>'milestone',
|
|
|
+ "numericRecords"=>0,
|
|
|
+ "isRead"=>false,
|
|
|
+ "title"=>"Milestone Update",
|
|
|
+ "mode"=>$mInfo["transport_mode"],
|
|
|
+ "no"=>$mInfo["h_bol"],
|
|
|
+ "tag"=>$mInfo["milestone_desc"],
|
|
|
+ "location"=>$timeAndlocations["locations"],
|
|
|
+ "timezone"=>$timeAndlocations["timezone"],
|
|
|
+ "time"=>$mInfo["milestone_date"]." ".$mInfo["milestone_time"],
|
|
|
+ "previous"=>"",
|
|
|
+ "frequency_type"=>$mInfo["frequency_type"],
|
|
|
+ "delayInfo"=>array(),"changeInfo"=>array());
|
|
|
+
|
|
|
+ if ($mInfo["frequency_type"] == "Daily"){
|
|
|
+ $eventCard["numericRecords"] = $mInfo["numericRecords"];
|
|
|
+ $eventCard["title"] = "Milestone Update Daily Summary(".$mInfo["insert_date_format"].")";
|
|
|
+ } else if($mInfo["frequency_type"] == "Weekly"){
|
|
|
+ $eventCard["numericRecords"] = $mInfo["numericRecords"];
|
|
|
+ $eventCard["title"] = "Milestone Update Weekly Summary(".$mInfo["insert_date_format"].")";
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ return $eventCard;
|
|
|
}
|
|
|
}
|
|
|
|