INSERT INTO tbl_location_data_real(card_id,
id,
lon,
lat,
speed,
source,
data_time,
is_delete,
`out`,
out_volumes,
`in`,
in_volumes,
in_loading,
out_unloading,
volume_datum,
course,
heading,
depth_avg,
water_depth_info,
shipSandFence,
sandFenceType
)
SELECT card_id,
id,
lon,
lat,
speed,
source,
data_time,
is_delete,
`out`,
out_volumes,
`in`,
in_volumes,
in_loading,
out_unloading,
volume_datum,
course,
heading,
depth_avg,
water_depth_info, getShipSandFence(lon,lat,card_id),getShipSandFenceInOrOut(lon,lat,card_id)
from tbl_location_data_2022_11 WHERE data_time in(
SELECT max(data_time) from tbl_location_data_2022_11 WHERE card_id in ('08a010d1-5e7b-11ed-a216-00163e146705',
'08a4db83-5e7b-11ed-a216-00163e146705',
'08a96fba-5e7b-11ed-a216-00163e146705',
'08ade4ea-5e7b-11ed-a216-00163e146705',
'08b23db3-5e7b-11ed-a216-00163e146705',
'08b6ee27-5e7b-11ed-a216-00163e146705',
'08bbbdfd-5e7b-11ed-a216-00163e146705',
'08c03329-5e7b-11ed-a216-00163e146705',
'08c4a742-5e7b-11ed-a216-00163e146705',
'08c935b0-5e7b-11ed-a216-00163e146705',
'08cdd5a9-5e7b-11ed-a216-00163e146705') group by card_id) and card_id in ('08a010d1-5e7b-11ed-a216-00163e146705',
'08a4db83-5e7b-11ed-a216-00163e146705',
'08a96fba-5e7b-11ed-a216-00163e146705',
'08ade4ea-5e7b-11ed-a216-00163e146705',
'08b23db3-5e7b-11ed-a216-00163e146705',
'08b6ee27-5e7b-11ed-a216-00163e146705',
'08bbbdfd-5e7b-11ed-a216-00163e146705',
'08c03329-5e7b-11ed-a216-00163e146705',
'08c4a742-5e7b-11ed-a216-00163e146705',
'08c935b0-5e7b-11ed-a216-00163e146705',
'08cdd5a9-5e7b-11ed-a216-00163e146705')
ON DUPLICATE KEY UPDATE
card_id = VALUES(card_id),
id= VALUES(id),
lon= VALUES(lon),
lat= VALUES(lat),
speed= VALUES(speed),
source= VALUES(source),
data_time= VALUES(data_time),
is_delete= VALUES(is_delete),
out_volumes= VALUES(out_volumes),
`out`= VALUES(`out`),
`in`= VALUES(`in`),
in_volumes= VALUES(in_volumes),
in_loading= VALUES(in_loading),
out_unloading= VALUES(out_unloading),
volume_datum= VALUES(volume_datum),
course= VALUES(course),
heading= VALUES(heading),
depth_avg= VALUES(depth_avg),
water_depth_info= VALUES(water_depth_info),
shipSandFence=getShipSandFence(values(lon),values(lat),values(card_id)),
sandFenceType=getShipSandFenceInOrOut(values(lon),values(lat),values(card_id))
;
create EVENT oneMinutesLocationReal
ON SCHEDULE EVERY 1 MINUTE STARTS '2022-01-01 00:00:00'
ON COMPLETION NOT PRESERVE ENABLE
DO
BEGIN
call insert_location_real();
END