2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`energyMeter_record`(vInput INT, vActiveTime INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
DECLARE vConsumption INT;
|
|
|
|
|
|
|
|
SELECT consumption INTO vConsumption
|
|
|
|
FROM energyInput
|
|
|
|
WHERE input = vInput;
|
|
|
|
|
|
|
|
INSERT INTO vn.energyMeter
|
|
|
|
SET
|
|
|
|
`input` = vInput,
|
|
|
|
`period` = DATE_FORMAT(util.VN_NOW(), '%Y-%m-%d %H:00:00'),
|
|
|
|
`activeTime` = vActiveTime,
|
|
|
|
`consumption` = CAST(IFNULL((vConsumption / 3600) * vActiveTime, 0) AS DECIMAL(10,2))
|
|
|
|
ON DUPLICATE KEY UPDATE
|
|
|
|
`activeTime` = `activeTime` + vActiveTime,
|
|
|
|
`consumption` = `consumption` + CAST(VALUES(`consumption`) AS DECIMAL(10,2));
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|