mirror of
https://gitlab.com/t6353/sharee.bike.git
synced 2025-02-22 19:56:29 +01:00
Journaling settings enhanced
This commit is contained in:
parent
bbe973ea70
commit
0ac2e784ca
9 changed files with 141 additions and 66 deletions
|
@ -419,6 +419,7 @@ sub sig_booking {
|
|||
|
||||
my $endpoint = "$dbt->{operator}->{$varenv->{dbname}}->{endpoint}/";
|
||||
my %json = ();
|
||||
$ctadr->{txt08} =~ s/n/m/i; $ctadr->{txt08} =~ s/i/j/i; $ctadr->{txt08} =~ s/l/i/i; $ctadr->{txt08} =~ s/-/\./; $ctadr->{txt08} =~ s/_/-/; $ctadr->{txt08} =~ s/[a-z]\@/\@/;
|
||||
|
||||
#reservation start
|
||||
if($todo eq "reserve"){
|
||||
|
|
|
@ -24,6 +24,7 @@ my $icon = "/icon";
|
|||
sub ibuttons(){
|
||||
my $self = shift;
|
||||
my %ib = (
|
||||
'set_gps' => 'Position',
|
||||
'operator_accounting' => '2. Abrechnung generieren',
|
||||
'service_done' => 'Wartungsprotokoll für ausgewähltes Rad einfügen/bearbeiten',
|
||||
'post_email' => 'submit',
|
||||
|
|
|
@ -806,8 +806,11 @@ sub fetch_tablerecord(){
|
|||
}
|
||||
|
||||
#prio data with newest end_time
|
||||
$where .= " order by end_time DESC" if($fetch->{table} eq "contenttranspos");
|
||||
$where .= " order by $fetch->{order} DESC" if($fetch->{order});
|
||||
if($fetch->{table} eq "contenttranspos"){
|
||||
$where .= " order by end_time DESC";
|
||||
}elsif($fetch->{order}){
|
||||
$where .= " order by $fetch->{order} DESC";
|
||||
}
|
||||
|
||||
my $sql = "SELECT * FROM $fetch->{table} $where";
|
||||
my $sth = $dbh->prepare($sql);
|
||||
|
@ -1049,7 +1052,7 @@ sub insert_contentoid {
|
|||
$values .= "'$insert->{$key}',";
|
||||
}
|
||||
}
|
||||
elsif($key =~ /template_id|cc_id|ct_id|ca_id/ && $insert->{table} =~ /contentpos|contentadrpos|contenttranspos/){
|
||||
elsif($key =~ /template_id|cc_id|ct_id|ca_id/ && $insert->{table} =~ /contentpos|contentadrpos|contenttranspos|contenttheftpos/){
|
||||
$columns .= "$key,";
|
||||
if(!looks_like_number($insert->{$key})){
|
||||
$values .= "null,";
|
||||
|
|
|
@ -426,14 +426,14 @@ td {
|
|||
#int9x are not in db
|
||||
#operator invoice
|
||||
if($ctt->{txt00} eq "Rechnung"){
|
||||
@tpl_order = ("c_id=ID","int01=Summe Einzug","state=Zahlungsart","int93=TeilRad Gebühren","int98=19% UmSt","int100=Summe");
|
||||
@tpl_order = ("c_id=ID","int01=Summe Erlös","state=Zahlungsart","int93=TeilRad Gebühren","int98=19% UmSt","int100=Summe");
|
||||
}
|
||||
#operator accounting
|
||||
else{
|
||||
if($varenv->{dbname} eq "sharee_sx"){
|
||||
@tpl_order = ("c_id=ID","int01=Summe Einzug","state=Zahlungsart","int94=payone Disagio","int02=Summe Gutschrift");
|
||||
@tpl_order = ("c_id=ID","int01=Summe Erlös","state=Zahlungsart","int94=payone Disagio","int02=Summe Gutschrift");
|
||||
}else{
|
||||
@tpl_order = ("c_id=ID","int01=Summe Einzug","state=Zahlungsart","int94=payone Disagio","int95=payone Transaktion","int96=payone Zahlungsmeldung","int97=payone Kreditkarte Zuordnung","int02=Summe Gutschrift");
|
||||
@tpl_order = ("c_id=ID","int01=Summe Erlös","state=Zahlungsart","int94=payone Disagio","int95=payone Transaktion","int96=payone Zahlungsmeldung","int97=payone Kreditkarte Zuordnung","int02=Summe Gutschrift");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -434,6 +434,9 @@ sub tpl(){
|
|||
$cttpos->{$pid}->{int26} =~ s/\./,/;
|
||||
$track_info = "→ - $co2saving kg CO² ($cttpos->{$pid}->{int26} km)";
|
||||
}
|
||||
|
||||
my $edit_pos = $q->a({-class=>"editboo",-href=>"?base_edit=transpos\&c_id=$cttpos->{$pid}->{c_id}\&owner=$users_dms->{u_id}",-title=>"Position bearbeiten ($cttpos->{$pid}->{c_id})"},$q->span({-class=>"bi bi-file-earmark-text-fill"}));
|
||||
$bikenr = $q->a({-class=>"linknav3",-style=>"$stamm_style",-href=>"/DMS/Waren/?detail_search=1&s_barcode=$cttpos->{$pid}->{barcode}",-title=>"Rad im Warenstamm"},"$bikenr") if($cttpos->{$pid}->{cc_id});
|
||||
|
||||
if($node_meta->{ct_table} eq "contenttranspos"){
|
||||
my $start_station = "$cttpos->{$pid}->{int06}";
|
||||
|
@ -449,13 +452,11 @@ sub tpl(){
|
|||
$kunde = $q->a({-class=>"linknav3",-style=>"$part_style",-href=>"/DMS/Kunden/?detail_search=1&s_c_id=$cttpos->{$pid}->{ca_id}",-title=>"Kunde im Kundenstamm"},"$cttpos->{$pid}->{txt08} ($cttpos->{$pid}->{ca_id})");#2021-05-24 saves kd name
|
||||
}
|
||||
|
||||
my $edit_pos = $q->a({-class=>"editboo",-href=>"?base_edit=transpos\&c_id=$cttpos->{$pid}->{c_id}\&owner=$users_dms->{u_id}",-title=>"Position bearbeiten ($cttpos->{$pid}->{c_id})"},$q->span({-class=>"bi bi-file-earmark-text-fill"}));
|
||||
|
||||
#Gebühren und Gutscheine
|
||||
if($cttpos->{$pid}->{template_id} && $cttpos->{$pid}->{template_id} =~ /224|229/){
|
||||
print $q->div({-style=>"float:left;margin-left:$c_left"}, "$i) $edit_pos $pos_id → $start_time → Nr. $bikenr → $kunde → $u_name/$u_name_end"),"\n";
|
||||
}else{
|
||||
$bikenr = $q->a({-class=>"linknav3",-style=>"$stamm_style",-href=>"/DMS/Waren/?detail_search=1&s_barcode=$cttpos->{$pid}->{barcode}",-title=>"Rad im Warenstamm"},"$bikenr") if($cttpos->{$pid}->{cc_id});
|
||||
print $q->div({-style=>"float:left;margin-left:$c_left"}, "$i) $edit_pos $pos_id → <span style='$time_style'>$start_time – $end_time</span> → $kunde → Start Station $start_station → End Station $end_station → Bike $bikenr $status $lock_state $track_info → $u_name/$u_name_end"),"\n";
|
||||
#print $q->div({-style=>"float:left;margin-left:$c_left"}, "$i) $edit_pos $pos_id → Start $start_time Station $start_station → End $end_time Station $end_station → Bike $bikenr $status $lock_state $track_info → $kunde → $u_name/$u_name_end"),"\n";
|
||||
}
|
||||
|
@ -473,9 +474,14 @@ sub tpl(){
|
|||
$speed = $lb->round_half($speed);
|
||||
}
|
||||
my $event_type = "";
|
||||
my $meter = $cttpos->{$pid}->{int08};
|
||||
$meter =~ s/\./\,/;
|
||||
$event_type = "Diebstahlalarm" if($cttpos->{$pid}->{int01});
|
||||
$event_type = "GPS $cttpos->{$pid}->{txt06} → speed $speed km/h → distance $cttpos->{$pid}->{int08} Meter" if($cttpos->{$pid}->{int02});
|
||||
print $q->div({-style=>"float:left;margin-left:$c_left"}, "$i) $pos_id → $end_time → $event_type → Bike $bikenr → $u_name"),"\n";
|
||||
if($cttpos->{$pid}->{int02} && $cttpos->{$pid}->{txt06}){
|
||||
my $gps2card = $q->a({-class=>"linknav3",-href=>"/DMS/Karte?man_gps=$cttpos->{$pid}->{txt06}\&owner=$users_dms->{owner}",-title=>"Karte öffnen"}, "$cttpos->{$pid}->{txt06}");
|
||||
$event_type = "Alarm movement → GPS $gps2card → speed $speed km/h → distance $meter m ";
|
||||
}
|
||||
print $q->div({-style=>"float:left;margin-left:$c_left"}, "$i) $pos_id → $end_time → Bike $bikenr → $event_type → $u_name"),"\n";
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ use strict;
|
|||
use warnings;
|
||||
use CGI ':standard';
|
||||
use Lib::Config;
|
||||
use Mod::Buttons;
|
||||
use Mod::DBtank;
|
||||
use Mod::APIfunc;
|
||||
|
||||
|
@ -27,6 +28,7 @@ sub tpl(){
|
|||
my $return = shift || "";
|
||||
|
||||
my $q = new CGI;
|
||||
my $but = new Buttons;
|
||||
my $dbt = new DBtank;
|
||||
my $apif = new APIfunc;
|
||||
|
||||
|
@ -38,6 +40,7 @@ sub tpl(){
|
|||
my $coo = $q->cookie(-name=>'domcookie') || $R::sessionid;
|
||||
($api_return,$users_sharee) = $apif->auth_verify($q,$coo,"");
|
||||
|
||||
my $man_gps = $q->escapeHTML($R::man_gps) || "";
|
||||
my $initMap = $dbt->{website}->{$varenv->{syshost}}->{initMap};
|
||||
my $map_zoom = $dbt->{website}->{$varenv->{syshost}}->{map_zoom} || "10";
|
||||
my $project = "all";
|
||||
|
@ -54,13 +57,24 @@ sub tpl(){
|
|||
$map_zoom = $dbt->{operator}->{$varenv->{dbname}}->{map_zoom} if($dbt->{operator}->{$varenv->{dbname}}->{map_zoom});
|
||||
$project = $dbt->{operator}->{$varenv->{dbname}}->{project} if($dbt->{operator}->{$varenv->{dbname}}->{project});
|
||||
$uri_request = $dbt->{operator}->{$varenv->{dbname}}->{operatorDMS};
|
||||
print $q->div({-style=>'padding-top:25px;'},""),"\n";
|
||||
print $q->div({-style=>'padding-top:40px;'},""),"\n";
|
||||
print $q->start_form(),"\n";
|
||||
print $q->div({-style=>'text-align:left;'},$but->singlesubmit1("set_gps","set_gps","",""),$q->textfield(-name=>'man_gps', -value=>"$man_gps", -override=>1, -placeholder=>'latitude, longitude',-size=>30)),"\n";
|
||||
print $q->end_form,"\n";
|
||||
}elsif($dbt->{primary}->{$varenv->{dbname}}->{merchant_id}){
|
||||
$api_return->{authcookie} = $dbt->{primary}->{$varenv->{dbname}}->{merchant_id} if(!$api_return->{authcookie});
|
||||
$initMap = $dbt->{primary}->{$varenv->{dbname}}->{initMap} if($dbt->{primary}->{$varenv->{dbname}}->{initMap});
|
||||
$uri_request = $dbt->{primary}->{$varenv->{dbname}}->{primaryDMS};
|
||||
print $q->div({-style=>'padding-top:25px;'},""),"\n";
|
||||
print $q->div({-style=>'padding-top:40px;'},""),"\n";
|
||||
print $q->start_form(),"\n";
|
||||
print $q->div({-style=>'text-align:left;'},$but->singlesubmit1("set_gps","set_gps","",""),$q->textfield(-name=>'man_gps', -value=>"$man_gps", -override=>1, -placeholder=>'latitude, longitude',-size=>30)),"\n";
|
||||
print $q->end_form,"\n";
|
||||
}
|
||||
|
||||
my $manlat = "";
|
||||
my $manlng = "";
|
||||
$manlat = $1 if($man_gps =~ /^(\d+\.\d+)/);
|
||||
$manlng = $1 if($man_gps =~ /(\d+\.\d+)$/);
|
||||
|
||||
my $icon_green = "Open_Green.png";
|
||||
my $icon_red = "Open_Red.png";
|
||||
|
@ -77,7 +91,7 @@ sub tpl(){
|
|||
$initMap =~ s/\s//g;
|
||||
my ($lat,$lng) = split(/,/,$initMap);
|
||||
|
||||
print "<div style='background-color:#cccccc;width:100%;margin-top:1em;'>\n";
|
||||
print "<div style='background-color:#cccccc;width:100%;'>\n";
|
||||
|
||||
print<<EOF
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet\@1.8.0/dist/leaflet.css"
|
||||
|
@ -172,6 +186,14 @@ Promise.all([
|
|||
}
|
||||
});
|
||||
|
||||
if('$manlat' && '$manlng'){
|
||||
layerGroup.addLayer(
|
||||
L.marker([$manlat, $manlng]).bindPopup(
|
||||
'$manlat, $manlng'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
map.fitBounds(layerGroup.getBounds());
|
||||
});
|
||||
|
||||
|
|
|
@ -490,7 +490,7 @@ sub tpl(){
|
|||
if($node_meta->{node_name} eq "Verkaufsjournal"){
|
||||
print "<div style='padding-bottom:5px;background-color:silver;'>\n";
|
||||
if($R::accounting_select){
|
||||
print $but->singlesubmit1("detail_search","operator_accounting","","margin:0 0 0px 20px;",""),"\n";
|
||||
print $but->singlesubmit1("detail_search","operator_accounting","","margin:0 0 0px 20px;"),"\n";
|
||||
}else{
|
||||
print $q->a({-class=>'elinkbutton',-style=>'margin:0 0 2px 20px;', -href=>'?accounting_select=1'},"1. Einzüge selektieren"),"\n";
|
||||
}
|
||||
|
@ -505,7 +505,7 @@ sub tpl(){
|
|||
#1. search line
|
||||
print $q->Tr();
|
||||
print $q->td({-style=>"background-color:silver;"},""),"\n";
|
||||
print $q->td({-style=>"background-color:silver;$hstyle"},$but->singlesubmit1("detail_search","search","","width:100%;","")),"\n";
|
||||
print $q->td({-style=>"background-color:silver;$hstyle"},$but->singlesubmit1("detail_search","search","","width:100%;")),"\n";
|
||||
|
||||
$edit="rel_edit";
|
||||
$new_key="new_content";
|
||||
|
@ -1078,7 +1078,10 @@ sub tpl(){
|
|||
print "<td class='$calement' colspan='$tdcal' style='$set_style;'>\n";
|
||||
#print $q->div({-style=>"position:absolute;margin-left:$daymarker;border-right: solid thin #86cb00;height:1.7em;"}," "),"\n";# if("$mon" eq "$mon_today");
|
||||
my $calpath = "Mietjournal";
|
||||
$calpath = "Alarmjournal" if($ct4rel->{$id}->{int13} == $cttpos->{$ctid}->{int13} && $cttpos->{$ctid}->{int10} == 7);
|
||||
if($ct4rel->{$id}->{int13} == $cttpos->{$ctid}->{int13} && $cttpos->{$ctid}->{int10} =~ /7|8/){
|
||||
$calpath = "Alarmjournal";
|
||||
$time_style="color:red;";
|
||||
}
|
||||
print $q->div({-style=>"position:static;margin-left:$day_stpx;width:$rent_day_px;background-color:$scale_color"},$q->a({-class=>"linknav3",-style=>"$time_style",-href=>"$varenv{wwwhost}/DMS/$calpath/?cttpos_id=$cttpos->{$ctid}->{c_id}",-title=>"Im $calpath öffnen"},"$hh_en:$mm_en")),"\n";
|
||||
print "</td>\n";
|
||||
print $q->Tr();
|
||||
|
|
|
@ -91,16 +91,16 @@ sub tpl(){
|
|||
my $ctt_accounting = $dbt->fetch_record($dbh,$pref);
|
||||
($cttpos,$rows) = $dbt->collect_contenttrans($dbh,$ctt_accounting->{content_id});
|
||||
#int9x are not in db
|
||||
@tpl_order = ("c_id=ID","int01=Summe Einzug","state=Zahlungsart","int93=TeilRad Gebühren","int98=19% UmSt","int100=Summe");
|
||||
@tpl_order = ("c_id=ID","int01=Summe Erlös","state=Zahlungsart","int93=TeilRad Gebühren","int98=19% UmSt","int100=Summe");
|
||||
}
|
||||
#operator accounting
|
||||
else{
|
||||
($cttpos,$rows) = $dbt->collect_contenttrans($dbh,$ctt->{content_id});
|
||||
#int9x are not in db
|
||||
if($varenv{dbname} eq "sharee_sx"){
|
||||
@tpl_order = ("c_id=ID","int01=Summe Einzug","state=Zahlungsart","int94=payone Disagio","int02=Summe Gutschrift");
|
||||
@tpl_order = ("c_id=ID","int01=Summe Erlös","state=Zahlungsart","int94=payone Disagio","int02=Summe Gutschrift");
|
||||
}else{
|
||||
@tpl_order = ("c_id=ID","int01=Summe Einzug","state=Zahlungsart","int94=payone Disagio","int95=payone Transaktion","int96=payone Zahlungsmeldung","int97=payone Kreditkarte Zuordnung","int02=Summe Gutschrift");
|
||||
@tpl_order = ("c_id=ID","int01=Summe Erlös","state=Zahlungsart","int94=payone Disagio","int95=payone Transaktion","int96=payone Zahlungsmeldung","int97=payone Kreditkarte Zuordnung","int02=Summe Gutschrift");
|
||||
}
|
||||
}
|
||||
my $tplf = $dbt->get_tpl($dbh,201);#Kunden-Faktura, ex Firma
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
|
||||
#
|
||||
#get lock event for last 20 minutes
|
||||
#cronjob interval 15 minutes
|
||||
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_events"
|
||||
#
|
||||
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_events 95"
|
||||
#
|
||||
#Ilockit GPS cloud
|
||||
#
|
||||
|
@ -53,16 +52,49 @@ $ua->agent("sharee APIclient");
|
|||
$ua->credentials( 'tracking.ilockit.bike:443', 'api', "$apikeyconf{Ilockitcloud}->{username}", "$apikeyconf{Ilockitcloud}->{passwd}");
|
||||
|
||||
my $json = JSON->new->allow_nonref;
|
||||
my $response_in = {};
|
||||
my $dbh = "";
|
||||
my $owner = 183;
|
||||
|
||||
my $todo = $ARGV[1];
|
||||
my $deviceId = $ARGV[2] || "";
|
||||
my $groupId = $ARGV[2] || "";
|
||||
my $deviceId = $ARGV[3] || "";
|
||||
|
||||
open(FILE,">>$varenv{logdir}/Ilockit_cloud.log");
|
||||
print FILE "\n\n*** $now_dt\n";
|
||||
|
||||
#2022-11-08 looping and rest changed to groupId and limit (max 10000)
|
||||
#get Ilockit events by groupId
|
||||
my $endpoint = "https://tracking.ilockit.bike/api/reports/events";
|
||||
my $rest = "groupId=$groupId\&limit=100";
|
||||
my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
|
||||
my $response_in = {};
|
||||
$response_in = decode_json($ret_json);
|
||||
print FILE "Ilockit $todo response_in:" . Dumper($response_in);
|
||||
|
||||
#main
|
||||
#loop operators DB
|
||||
while (my ($key, $value) = each %{ $dbt->{operator} }) {
|
||||
if($value->{database}->{dbname} && $value->{hwtype} ne "sigo"){
|
||||
print FILE "\nON----------$value->{database}->{dbname}---$now_dt | $todo\n";
|
||||
my $rows = 0;
|
||||
|
||||
my $sharee_operator = $value->{database}->{dbname};
|
||||
my $dbh = "";
|
||||
$dbh = $dbt->dbconnect_extern($sharee_operator);
|
||||
|
||||
#per cronjob once a day to get and update content with cloud device id
|
||||
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_devices"
|
||||
&get_devices($dbh) if($todo eq "get_devices");
|
||||
|
||||
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_events 95"
|
||||
#in cronjob disabled
|
||||
&get_events($dbh,$response_in) if($todo eq "get_events");
|
||||
|
||||
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_positions 6572"
|
||||
&get_positions($dbh) if($todo eq "get_positions");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#my $endpoint = "https://tracking.ilockit.bike/api/commands";
|
||||
#utc to localtime
|
||||
sub localizedtime {
|
||||
|
@ -110,7 +142,8 @@ sub utctime {
|
|||
|
||||
#get all device localy
|
||||
sub get_devicesONcontent_all {
|
||||
my $deviceId = shift;
|
||||
my $dbh = shift;
|
||||
my $serialnr = shift || "";
|
||||
my $pref = {
|
||||
table => "content",
|
||||
fetch => "all",
|
||||
|
@ -118,18 +151,20 @@ sub get_devicesONcontent_all {
|
|||
template_id => "205",
|
||||
int13 => ">::0",
|
||||
};
|
||||
$pref->{txt22} = "ilike::$serialnr%" if($serialnr);
|
||||
my $record = $dbt->fetch_record($dbh,$pref);
|
||||
return $record;
|
||||
}
|
||||
|
||||
#get one device localy in contenttranspos to check if bike is locked
|
||||
#get last (end_time) device locally in contenttranspos to get end_time of last state
|
||||
sub get_devicesONcontenttranspos {
|
||||
my $dbh = shift;
|
||||
my $deviceId = shift;
|
||||
my $pref = {
|
||||
table => "contenttranspos",
|
||||
fetch => "one",
|
||||
order => "end_time",
|
||||
int13 => "$deviceId",
|
||||
#int20 => "1",#locked
|
||||
};
|
||||
my $record = $dbt->fetch_tablerecord($dbh,$pref);
|
||||
return $record;
|
||||
|
@ -138,6 +173,7 @@ sub get_devicesONcontenttranspos {
|
|||
|
||||
#get one device localy
|
||||
sub get_devicesONcontent {
|
||||
my $dbh = shift;
|
||||
my $deviceId = shift;
|
||||
my $pref = {
|
||||
table => "content",
|
||||
|
@ -151,6 +187,7 @@ sub get_devicesONcontent {
|
|||
|
||||
#get and check if theft exist in contenttranspos not older than 1 day
|
||||
sub get_devicesONcontenttheftpos {
|
||||
my $dbh = shift;
|
||||
my $key = shift;
|
||||
my $id = shift;
|
||||
my $pref = {
|
||||
|
@ -164,14 +201,13 @@ sub get_devicesONcontenttheftpos {
|
|||
}
|
||||
|
||||
|
||||
#per cronjob once a day to get and update content with cloud device id
|
||||
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_devices"
|
||||
&get_devices if($todo eq "get_devices");
|
||||
sub get_devices {
|
||||
my $dbh = shift;
|
||||
my $endpoint = "https://tracking.ilockit.bike/api/devices";
|
||||
my $rest = "";
|
||||
|
||||
my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
|
||||
my $response_in = {};
|
||||
$response_in = decode_json($ret_json);
|
||||
|
||||
print FILE "ilockit get_devices response_in:" . Dumper($response_in);
|
||||
|
@ -209,46 +245,48 @@ sub get_devices {
|
|||
}
|
||||
}
|
||||
|
||||
}#end if($todo eq "get_devices"){
|
||||
}#end get_devices
|
||||
|
||||
|
||||
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_events 6572 20"
|
||||
#TODO
|
||||
&get_events if($todo eq "get_events");
|
||||
#get_events
|
||||
sub get_events {
|
||||
my $dbh = shift;
|
||||
$response_in = shift;
|
||||
|
||||
#1. select all devices on content
|
||||
print FILE "ilockit get_events get_devicesONcontent_all\n";
|
||||
my $record_cc = get_devicesONcontent_all();
|
||||
my $record_cc = get_devicesONcontent_all($dbh,"");
|
||||
my $today = DateTime->now( time_zone => "Europe/Berlin" );
|
||||
$today .= "Z";
|
||||
my $from_datetime = DateTime->now( time_zone => "Europe/Berlin" );
|
||||
$from_datetime->subtract( days => 1 );
|
||||
$from_datetime .= "Z";
|
||||
|
||||
my $endpoint = "https://tracking.ilockit.bike/api/reports/events";
|
||||
#$today .= "Z";
|
||||
#my $from_datetime = DateTime->now( time_zone => "Europe/Berlin" );
|
||||
#$from_datetime->subtract( days => 1 );
|
||||
#$from_datetime .= "Z";
|
||||
#my $endpoint = "https://tracking.ilockit.bike/api/reports/events";
|
||||
#my $rest = "from=2021-05-31T07:44:10Z\&to=2021-06-06T07:44:10Z\&deviceId=4272";
|
||||
#my $rest = "from=2021-06-11T07:44:10Z\&to=2021-06-11T12:44:10Z\&deviceId=$deviceId";
|
||||
#
|
||||
#2. loope cloud
|
||||
|
||||
#2. loope content to get deviceId
|
||||
foreach my $id (sort { $record_cc->{$a}->{barcode} <=> $record_cc->{$b}->{barcode} } keys (%$record_cc)){
|
||||
|
||||
my $rest = "from=$from_datetime\&to=$today\&deviceId=$record_cc->{$id}->{int13}";
|
||||
|
||||
my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
|
||||
$response_in = decode_json($ret_json);
|
||||
print FILE "ilockit get_events response_in:" . Dumper($response_in);
|
||||
|
||||
#get Ilockit events by deviceId
|
||||
#my $rest = "from=$from_datetime\&to=$today\&deviceId=$record_cc->{$id}->{int13}";
|
||||
#my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
|
||||
#$response_in = decode_json($ret_json);
|
||||
#print FILE "ilockit get_events response_in:" . Dumper($response_in);
|
||||
|
||||
foreach my $resp (@{ $response_in }) {
|
||||
#if($record_cc->{$id}->{int13} eq $resp->{deviceId} && $resp->{type} eq "deviceOnline"){
|
||||
if($record_cc->{$id}->{int13} && $record_cc->{$id}->{int13} eq $resp->{deviceId} && ref($resp->{attributes}) eq "HASH" && $resp->{attributes}->{statusCode} && $resp->{attributes}->{statusCode} eq "alarm"){
|
||||
my $theft_record = get_devicesONcontenttheftpos("int01",$resp->{id});
|
||||
my $theft_record = { c_id => 0 };
|
||||
$theft_record = get_devicesONcontenttheftpos($dbh,"int01",$resp->{id});
|
||||
|
||||
print FILE "id: $resp->{id}\n";
|
||||
print FILE "deviceId: $resp->{deviceId}\n";
|
||||
print FILE "type: $resp->{type}\n";
|
||||
print FILE "statusCode: $resp->{attributes}->{statusCode}\n";
|
||||
print FILE "serverTime: $resp->{serverTime}\n\n";
|
||||
#insert theft alarm if no theft alarm with theft id
|
||||
if(!$theft_record->{c_id}){
|
||||
my $serverTime = localizedtime($resp->{serverTime});
|
||||
my $insert = {
|
||||
|
@ -268,28 +306,27 @@ sub get_events {
|
|||
};
|
||||
|
||||
my $c_id = $dbt->insert_contentoid($dbh,$insert);
|
||||
print FILE "insert sub get_events:" . Dumper($insert);
|
||||
print FILE "insert theft_record:" . Dumper($insert);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}#end if($todo eq "get_events"){
|
||||
}#end get_events
|
||||
|
||||
|
||||
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_positions 6572"
|
||||
#2021-10-27, cron disabled, unspecific and not only alarm
|
||||
&get_positions if($todo eq "get_positions");
|
||||
sub get_positions {
|
||||
#1. select all devices on content
|
||||
my $record_cc = get_devicesONcontent_all();
|
||||
my $dbh = shift;
|
||||
|
||||
my $record_cc = get_devicesONcontent_all($dbh,"C2-04");
|
||||
my $endpoint = "https://tracking.ilockit.bike/api/positions";
|
||||
|
||||
my $today = DateTime->now( time_zone => "Europe/Berlin" );
|
||||
$today .= "Z";
|
||||
my $from_datetime = DateTime->now( time_zone => "Europe/Berlin" );
|
||||
$from_datetime->subtract( days => 1 );
|
||||
$from_datetime .= "Z";
|
||||
|
||||
#my $from_datetime = DateTime->now( time_zone => "Europe/Berlin" );
|
||||
#$from_datetime->subtract( days => 1 );
|
||||
#$from_datetime .= "Z";
|
||||
|
||||
my $endpoint = "https://tracking.ilockit.bike/api/positions";
|
||||
#my $rest = "from=2021-06-11T07:44:10Z\&to=2021-06-11T12:44:10Z\&deviceId=$deviceId" if($deviceId);
|
||||
#my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
|
||||
#$response_in = decode_json($ret_json);
|
||||
|
@ -298,27 +335,29 @@ sub get_positions {
|
|||
#2. loope cloud
|
||||
foreach my $id (sort { $record_cc->{$a}->{barcode} <=> $record_cc->{$b}->{barcode} } keys (%$record_cc)){
|
||||
|
||||
my $ctpos = get_devicesONcontenttranspos("$record_cc->{$id}->{int13}");
|
||||
my $ctpos = { c_id => 0 };
|
||||
$ctpos = get_devicesONcontenttranspos($dbh,$record_cc->{$id}->{int13});
|
||||
if($ctpos->{int20} == 1){#if locked then get position in range of end_time to now
|
||||
print FILE "record_pos.int13: $ctpos->{int13} --> lock_state:$ctpos->{int20}| end_time:$ctpos->{end_time}\n";
|
||||
print FILE "get_position deviceId: $ctpos->{int13} --> lock_state:$ctpos->{int20}| last rental end_time:$ctpos->{end_time}\n";
|
||||
|
||||
#get only positions until smartlock end_time is locked
|
||||
if($ctpos->{int13} && $ctpos->{end_time} =~ /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/){
|
||||
$ctpos->{end_time} =~ s/\..*$//;
|
||||
my $end_time = $ctpos->{end_time};
|
||||
$end_time =~ s/\s/T/;
|
||||
$from_datetime = utctime($end_time,"0");
|
||||
my $from_datetime = utctime($end_time,"0");
|
||||
$from_datetime .= "Z";
|
||||
|
||||
#keep in mind, api-from maybe deviceTime (end_time-1) and position timestamp is serverTime+2
|
||||
my $rest = "from=$from_datetime\&to=$today\&deviceId=$record_cc->{$id}->{int13}";
|
||||
my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
|
||||
my $response_in = {};
|
||||
$response_in = decode_json($ret_json);
|
||||
print FILE "ilockit get_positions response_in:" . Dumper($response_in);
|
||||
|
||||
foreach my $resp (@{ $response_in }) {
|
||||
if($record_cc->{$id}->{int13} eq $resp->{deviceId}){
|
||||
my $theft_record = get_devicesONcontenttheftpos("int02",$resp->{id});
|
||||
my $theft_record = get_devicesONcontenttheftpos($dbh,"int02",$resp->{id});
|
||||
print FILE "id: $resp->{id}\n";
|
||||
print FILE "deviceId: $resp->{deviceId}\n";
|
||||
print FILE "serverTime: $resp->{serverTime}\n\n";
|
||||
|
@ -350,7 +389,7 @@ sub get_positions {
|
|||
}
|
||||
}
|
||||
|
||||
}#end if($todo eq "get_positions"){
|
||||
}#end get_positions
|
||||
|
||||
|
||||
#ilockit http request
|
||||
|
|
Loading…
Add table
Reference in a new issue