Mysql存储过程跳过插入

时间:2015-10-29 17:45:25

标签: mysql

我有一个我开发并经过充分测试的程序。现在它已经商业化部署,它无法插入一些记录但仍然返回预期结果。不会抛出任何错误或警告。

每150次通话可能会错过3次插入。

我能错过什么?

2 个答案:

答案 0 :(得分:0)

MySQL会继续执行您的查询,直到发生任何错误。但是如果错误,如果他们有正确的声明继续执行。我认为在错误中跳过了三个记录。

答案 1 :(得分:0)

问题是,它被一个java服务调用,它捕获任何抛出的mysql错误,但它没有抛出一个。甚至没有警告。

以下是代码:

    DELIMITER $$

USE `parkinglot`$$

DROP PROCEDURE IF EXISTS `process_acard`$$

CREATE DEFINER=`jeremiah`@`localhost` PROCEDURE `process_acard`(_station INT(4),_cardno VARCHAR(10),_baloncard DOUBLE,_transam FLOAT,_lane VARCHAR(50),_lpn VARCHAR(8),_vehcat INT(4),_fimagepath VARCHAR(100))
BEGIN
   DECLARE bool_code VARCHAR(6);
   DECLARE error_code VARCHAR(6);
   DECLARE info_msg VARCHAR(6);
   DECLARE message_string VARCHAR(255);
   DECLARE return_value FLOAT DEFAULT 0;
   DECLARE master_or_blocked INTEGER(2);
   DECLARE is_blacklisted INT(2);
   DECLARE stn_name VARCHAR(50);
   DECLARE stn_type VARCHAR(20);
   DECLARE mysite VARCHAR (4);
   DECLARE myzone INTEGER (4);
   DECLARE entry_zone INTEGER (4);
   DECLARE merch_agent VARCHAR(11);
   DECLARE sea_reg_lpn INTEGER(2) DEFAULT 0;
   DECLARE sea_ent_lpn INTEGER(2) DEFAULT 0;
   DECLARE sea_lpn VARCHAR(10);
   DECLARE ent_lpn VARCHAR(10);
   DECLARE sea_validfrom DATETIME;
   DECLARE sea_validto DATETIME;
   DECLARE op_date DATE;
   DECLARE sea_block_status INT(2);
   DECLARE sea_exists INT(10);
   DECLARE tea_exists INT(10);
   DECLARE location INT(4);
   DECLARE ta_rif INT(4);
   DECLARE ent_device VARCHAR(50);
   DECLARE error_sev VARCHAR(50);
   DECLARE _limagepath VARCHAR(50);
   DECLARE time_in DATETIME;
   DECLARE time_now DATETIME;
   DECLARE raw_duration TINYINT;
   DECLARE days_spent TINYINT DEFAULT 0;
   DECLARE fd_fee FLOAT DEFAULT 0;
   DECLARE fee1 FLOAT DEFAULT 0;
   DECLARE fee2 FLOAT DEFAULT 0;
   DECLARE dow1 TINYINT;
   DECLARE dow2 TINYINT;
   DECLARE total_fee FLOAT;
   DECLARE cardrec INT;
   DECLARE shift_string VARCHAR(100);
   DECLARE myshift VARCHAR(100);
   DECLARE pass_key VARCHAR(5);
   DECLARE amount_charged DOUBLE;
   DECLARE pay_state INT(4);
   DECLARE lipa_activity INT(4);
   DECLARE ent_dex VARCHAR(200);
   DECLARE exit_dex VARCHAR(200);
   DECLARE acq_entry_dex VARCHAR(200);
   DECLARE acq_trans_dex VARCHAR(200);
   DECLARE pending_value INTEGER(10);
   DECLARE pending INT(1) DEFAULT 0;
   DECLARE pending_id INT(10) UNSIGNED;
   DECLARE use_entry_zone INT;
   DECLARE sarit_apb INT(1);
   DECLARE char_amount VARCHAR(100);
   DECLARE useful_transtype INT(1);
   DECLARE sarit_avg_amt DOUBLE DEFAULT 0;
   DECLARE card_trans_type INT(2);
   DECLARE confirm_insert INT(2);
   DECLARE newest_record_id INT(8);
   DECLARE event VARCHAR(50) DEFAULT '';
   DECLARE story VARCHAR(100) DEFAULT '';
   DECLARE lastinsert BIGINT;
   DECLARE check_entry_bal INT(1);
   DECLARE min_entry_bal INT(8);



IF(CHAR_LENGTH(_cardno)<9 OR CHAR_LENGTH(_station)<1)THEN
    SET bool_code='FALSE';
    SET error_code='ER225';
    SET info_msg='MS225';
ELSE
    IF (ISNULL(_vehcat) OR CHAR_LENGTH(_vehcat)<1) THEN SET _vehcat=1; END IF;

    SELECT get_lpn_path(_lpn,NOW()) INTO _limagepath;

    SELECT station_name,station_type,site_no,site_zone,commercial_id FROM site_config
    WHERE station_id=_station INTO stn_name,stn_type,mysite,myzone,merch_agent;

    INSERT INTO acard_temp_log(`card_no`,`card_event`) VALUES(_cardno,stn_type);/*Tell the real story*/

    SELECT card_status FROM special_acards WHERE card_no=_cardno LIMIT 1 INTO master_or_blocked;/*1-master,2-blocked*/

    IF(master_or_blocked=2)THEN

        SET event='SPECIAL';

        INSERT INTO bbc_attempts(`card_no`,`trans_date`,`station_name`,`lane_name`,`stationid`)VALUES
                    (_cardno,NOW(),stn_name,_lane,_station);

        SET bool_code='FALSE';
        SET error_code='ER244';
        SET info_msg='MS244';

    ELSEIF(master_or_blocked=1)THEN

        SET event='SPECIAL';

        INSERT INTO mastercard_transactions(`card_no`,`trans_date`,`station_name`,`lane_name`,`stationid`)VALUES
                    (_cardno,NOW(),stn_name,_lane,_station);

        SET bool_code='TRUE';
        SET error_code='ER000';
        SET info_msg='MS245';

    ELSE 
    /*we continue after realising card is neither blocked nor a mastercard.Now we check if it is globally blacklisted */
        SELECT blocked FROM acard_blacklist WHERE card_no=_cardno LIMIT 1 INTO is_blacklisted;



        IF(is_blacklisted=1)THEN

            SET event='SPECIAL';

            INSERT INTO bbc_attempts(`card_no`,`trans_date`,`station_name`,`lane_name`,`stationid`)VALUES
                        (_cardno,NOW(),stn_name,_lane,_station);

            SET bool_code='FALSE';
            SET error_code='ER229';
            SET info_msg='MS229';


        ELSE



        /*mhh.Not blacklist. Lets now check if it is a seasonal card with all checks*/

            SELECT `s_id`,`validfrom`,`validto`,`blocked`,car_reg FROM seasonal_cards WHERE card_no=_cardno AND site_no=mysite INTO sea_exists,sea_validfrom,sea_validto,sea_block_status,sea_lpn ;
            IF(sea_exists>=1)THEN/*this is a seasonlacard*/

                SELECT SQL_CACHE setting_validity FROM global_settings WHERE setting_name='seasonal_LPNI' AND site_applicable=mysite INTO sea_ent_lpn;
                SELECT SQL_CACHE setting_validity FROM global_settings WHERE setting_name='seasonal_reg_LPNI' AND site_applicable=mysite INTO sea_reg_lpn;

                IF(sea_block_status=1)THEN/*check if card is blocked by seasonal card manager*/
                    SET event='SPECIAL';

                    INSERT INTO bsc_attempts(`card_no`,`trans_date`,`station_name`,`lane_name`,`stationid`,bsc_description)VALUES
                    (_cardno,NOW(),stn_name,_lane,_station,'BLOCKED');

                    SET bool_code='FALSE';
                    SET error_code='ER244';
                    SET info_msg='MS246';               

                ELSE/*card not blocked by seasonal card manager*/
                    IF(NOW() > sea_validto)THEN/*is this card expired*/

                        INSERT INTO bsc_attempts(`card_no`,`trans_date`,`station_name`,`lane_name`,`stationid`,bsc_description)VALUES
                        (_cardno,NOW(),stn_name,_lane,_station,'EXPIRED');

                        SET bool_code='FALSE';
                        SET error_code='ER247';
                        SET info_msg='MS247';
                        SET event='SEASON';             

                    ELSE/*card not expired*/

                        IF(stn_type='ENTRY')THEN/*CHECK EVENT BY STATION TYPE*/
                            SET event='SEASON';


                            IF(ISNULL(sea_lpn))THEN SET sea_lpn='xxxx'; END IF;
                            #select sea_reg_lpn,sea_lpn,_lpn,CHAR_LENGTH(_lpn);                         


                            SELECT `trans_id`,`trans_date`,`in_out` FROM sea_card_transactions WHERE trans_id=(SELECT MAX(trans_id) FROM sea_card_transactions WHERE card_no=_cardno AND site_no=mysite) INTO tea_exists,op_date,location;
                            IF(CHAR_LENGTH(_lpn)>=7 && _lpn!= sea_lpn && sea_reg_lpn=1)THEN

                                    SET bool_code='FALSE';
                                    SET error_code='ER218';
                                    SET info_msg='MS218';

                                    INSERT INTO numberplate_mismatches(`token_number`,`token_type`,`entry_plates`,`exit_plates`,`ptrans_id`,action_description) VALUES
                                    (_cardno,'S-ACARD',ent_lpn,_lpn,tea_exists,'Seasonal Card mismatched and Blocked at Entry');




                            ELSE/*if that condition is not satisfied.tuendelee*/
                            #select tea_exists;
                                /*Lest check if there is a mismatch without blocking*/

                                SET event='SEASON';


                                IF(CHAR_LENGTH(_lpn)>=7 && _lpn!= sea_lpn)THEN

                                    INSERT INTO numberplate_mismatches(`token_number`,`token_type`,`entry_plates`,`exit_plates`,`ptrans_id`,action_description) VALUES
                                    (_cardno,'S-ACARD',ent_lpn,_lpn,tea_exists,'Seasonal Card mismatched but Allowed at Entry');                                

                                END IF;

                                /*end mismatch*/
                                IF(ISNULL(tea_exists) OR (location=0) OR (location=1 && DATE(NOW())>op_date))THEN/*allow entry*/

                                    IF(tea_exists>1 && location=1)THEN UPDATE sea_card_transactions SET in_out=0,exitdate=NOW() WHERE trans_id=tea_exists AND card_no=_cardno AND site_no=mysite; END IF;

                                    INSERT INTO sea_card_transactions(`card_no`,`trans_date`,`instation`,`entrygate`,`in_out`,`site_no`,entrydate,ass_lpn)VALUES
                                                    (_cardno,CURRENT_DATE,_station,stn_name,'1',mysite,NOW(),_lpn);

                                    SET bool_code='TRUE';
                                    SET error_code='ER000';
                                    SET info_msg='MS250';

                                ELSE

                                    SET bool_code='FALSE';
                                    SET error_code='ER249';
                                    SET info_msg='MS249';


                                END IF;                 


                            END IF;/*end chacking plates where plate chack setting is enforced*/

                        ELSEIF(stn_type='EXIT')THEN

                            SET event='SEASON';

                            IF(ISNULL(sea_lpn))THEN SET sea_lpn='xxxxxxx'; END IF;
                            #select sea_reg_lpn,sea_lpn,_lpn,CHAR_LENGTH(_lpn);                     
                            SELECT `trans_id`,`trans_date`,`in_out`,IFNULL(ass_lpn,'XXXXXX') FROM sea_card_transactions WHERE trans_id=(SELECT MAX(trans_id) FROM sea_card_transactions WHERE card_no=_cardno AND site_no=mysite) INTO tea_exists,op_date,location,ent_lpn;
                            #select sea_lpn;
                            IF(CHAR_LENGTH(_lpn)>=7 && (_lpn!= sea_lpn OR _lpn != ent_lpn) && (sea_reg_lpn=1 OR sea_ent_lpn=1))THEN/*is lnn check enforce*/

                                    SET bool_code='FALSE';
                                    SET error_code='ER218';
                                    SET info_msg='MS218';

                                    INSERT INTO numberplate_mismatches(`token_number`,`token_type`,`entry_plates`,`exit_plates`,`ptrans_id`,action_description) VALUES
                                        (_cardno,'S-ACARD',sea_lpn,_lpn,tea_exists,'Seasonal Card mismatched and Blocked at Exit');                             

                            ELSE

                                IF(CHAR_LENGTH(_lpn)>=7 && _lpn!= sea_lpn)THEN

                                    INSERT INTO numberplate_mismatches(`token_number`,`token_type`,`entry_plates`,`exit_plates`,`ptrans_id`,action_description) VALUES
                                    (_cardno,'S-ACARD',ent_lpn,_lpn,tea_exists,'Seasonal Card mismatched but allowed at Exit');                             

                                END IF;

                                IF(location=1)THEN

                                    UPDATE sea_card_transactions SET in_out=0,exitdate=NOW(),exitgate=stn_name,outstation=_station,ass_lpn=_lpn WHERE trans_id=tea_exists AND card_no=_cardno AND site_no=mysite;

                                    SET bool_code='TRUE';
                                    SET error_code='ER000';
                                    SET info_msg='MS220';        

                                ELSE

                                    SET bool_code='FALSE';
                                    SET error_code='ER221';
                                    SET info_msg='MS221';


                                END IF;                     

                            END IF;
                        ELSE            

                            SET bool_code='FALSE';
                            SET error_code='ER248';
                            SET info_msg='MS248';                       

                        END IF;                 

                    END IF;/*end expiry check*/             

                END IF;/*end check of seasonal blocked check*/

            ELSE/*normal card check */
                IF(stn_type='ENTRY')THEN                

                    SET event='ENTRY';

                    SELECT SQL_CACHE setting_validity FROM global_settings WHERE setting_name='sarit_apb_average' AND site_applicable=mysite LIMIT 1 INTO sarit_apb;
                    SELECT SQL_CACHE setting_validity FROM global_settings WHERE setting_name='confirm_acard_record' AND site_applicable=mysite LIMIT 1 INTO confirm_insert;
                    SELECT SQL_CACHE setting_value,setting_validity FROM global_settings WHERE setting_name='confirm_acard_balance' AND site_applicable=mysite LIMIT 1 INTO min_entry_bal,check_entry_bal;



                    #SELECT transid,in_out,entry_timestamp FROM parkingtrans WHERE transid=(SELECT MAX(transid) FROM parkingtrans WHERE card_no=_cardno AND transactiontype=(2,7)) INTO sea_exists,location,time_in;                            
                    #evans. 7:12 10/22/2015
                    SELECT transid,in_out,entry_timestamp FROM parkingtrans WHERE transid=(SELECT MAX(transid) FROM parkingtrans WHERE card_no=_cardno AND transactiontype IN(2,7)) INTO sea_exists,location,time_in;

                    IF check_entry_bal=1 &&  min_entry_bal> _baloncard  THEN

                            SET bool_code='FALSE';
                            SET error_code='ER243';
                            SET info_msg='MS243';



                    ELSEIF ISNULL(sea_exists) OR (sea_exists>=1 && location=0) OR (sea_exists>=1 && location=1 && sarit_apb=1 && DATE(time_in)< CURRENT_DATE) THEN/*card is good to enter*/
                        SET ent_dex="FULL ACARD ENTRY";
                        SET useful_transtype=2;
                        SELECT NOW() INTO time_in;

                        IF (sea_exists>=1 && location=1 && sarit_apb=1 && DATE(time_in)< CURRENT_DATE) THEN

                            SELECT IFNULL(crypt_key,'4545') FROM cryptonium WHERE site_no=mysite AND encrypt_start < NOW() AND (ISNULL(encrypt_end) OR encrypt_end > NOW()) INTO pass_key;
                            SELECT IFNULL(pass_key,'4545') INTO pass_key;

                            SELECT AES_ENCRYPT(0,pass_key) INTO char_amount;

                            SET useful_transtype=7;

                            UPDATE parkingtrans SET `transactiontype`=8,`in_out`=0,`bal_bf_exit`=_baloncard,`bal_af_exit`=_baloncard,
                            `trans_duration`=TIMESTAMPDIFF(MINUTE,time_in,CONCAT(time_in,':','23:59:59')),`amount_payable`=char_amount,`amount_paid`=char_amount,
                            `payment_status`=1,`pay_type`=1,`pay_activity`=0,`trans_year`=YEAR(NOW()),`trans_month`=MONTH(NOW()),`trans_date`=DATE(NOW()),`shift`='SHIFT1',
                            `paid_on`=NOW(),`pay_station`=_station,`site_no`=mysite,`exit_date`=DATE(NOW()),`exit_timestamp`=NOW() WHERE transid=sea_exists;

                        END IF;

                         SET ent_dex=ent_dex;

                        INSERT INTO `parkingtrans` (`entry_gate`, `entry_timestamp`, `datein`, `timein`, `hour_in`, `card_no`,`transactiontype`, `in_out`, `car_reg`, `face_capture`,lpn_capture, `device_no`, `veh_class`,`token_site_zone`,`site_no`,`bal_on_entry`,entry_description) VALUES
                                                   (stn_name,time_in,DATE(time_in),TIME(time_in),HOUR(time_in),_cardno,useful_transtype,1,_lpn,_fimagepath,_limagepath,ent_device,IFNULL(_vehcat,1),myzone,mysite,_baloncard,ent_dex);


                         SET ent_dex=ent_dex;

                         IF confirm_insert=1 THEN

                            SELECT transid FROM parkingtrans WHERE card_no=_cardno AND transactiontype=2 AND token_site_zone=myzone AND entry_timestamp=time_in LIMIT 1 INTO newest_record_id;
                            #select newest_record_id;
                            IF ISNULL(newest_record_id) THEN

                                SELECT CONCAT(ent_dex,' RETRY') INTO ent_dex; 

                                INSERT INTO `parkingtrans` (`entry_gate`, `entry_timestamp`, `datein`, `timein`, `hour_in`, `card_no`,`transactiontype`, `in_out`, `car_reg`, `face_capture`,lpn_capture, `device_no`, `veh_class`,`token_site_zone`,`site_no`,`bal_on_entry`,entry_description) VALUES
                                                    (stn_name,time_in,DATE(time_in),TIME(time_in),HOUR(time_in),_cardno,useful_transtype,1,_lpn,_fimagepath,_limagepath,ent_device,IFNULL(_vehcat,1),myzone,mysite,_baloncard,ent_dex);


                            END IF;                 


                        END IF;

                        SET lastinsert=LAST_INSERT_ID();                         

                        SET bool_code='TRUE';
                        SET error_code='ER000';
                        SET info_msg='MS250';

                    ELSE/*card has APB*/                    

                        SET bool_code='FALSE';
                        SET error_code='ER249';
                        SET info_msg='MS249';           


                    END IF;


                ELSEIF(stn_type='EXIT')THEN

                    SET event='EXIT';

                    SELECT SQL_CACHE setting_validity FROM global_settings WHERE setting_name='normal_LPNI' AND site_applicable=mysite INTO sea_ent_lpn;

                    SELECT SQL_CACHE setting_validity FROM global_settings WHERE setting_name='sarit_apb_average' AND site_applicable=mysite LIMIT 1 INTO sarit_apb;

                    SELECT SQL_CACHE setting_validity FROM global_settings WHERE setting_name='pay_by_entry_zone' AND site_applicable=mysite LIMIT 1 INTO use_entry_zone;       


                    SELECT NOW() INTO time_now;

                    #select sea_ent_lpn,sarit_apb,use_entry_zone;

                    SELECT get_current_shift(_station,time_now) INTO shift_string;              
                    SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(shift_string,'#',2),'#',-1) INTO myshift;

                    /*SELECT IFNULL(crypt_key,'4545') FROM cryptonium WHERE site_no=mysite AND encrypt_start < NOW() AND (ISNULL(encrypt_end) OR encrypt_end > NOW()) INTO pass_key;*/

                    SELECT transid,in_out,entry_timestamp,car_reg,`payment_status`,`pay_activity`,entry_description,trans_description,token_site_zone,transactiontype FROM parkingtrans WHERE transid=(SELECT MAX(transid) FROM parkingtrans
                    WHERE card_no=_cardno AND transactiontype IN(2,7)) INTO sea_exists,location,time_in,ent_lpn,pay_state,lipa_activity,acq_entry_dex,acq_trans_dex,entry_zone,card_trans_type; 

                    IF(ISNULL(sea_exists) OR location=0)THEN

                        SET return_value=0;                 
                        SET bool_code='FALSE';
                        SET error_code='ER221';
                        SET info_msg='MS221';           

                    ELSE
                        IF sea_ent_lpn=1 && ent_lpn>5 && ent_lpn != 'AIG400K' && CHAR_LENGTH(_lpn)>=7 && ent_lpn != _lpn THEN/*validate detected license plate at exit*/

                                SET return_value=0;                 
                                SET bool_code='FALSE';
                                SET error_code='ER218';
                                SET info_msg='MS218';

                                INSERT INTO numberplate_mismatches(`token_number`,`token_type`,`entry_plates`,`exit_plates`,`ptrans_id`,action_descritpion) VALUES
                                (_cardno,'N-ACARD',ent_lpn,_lpn,sea_exists,'Normal Card mismatched and Blocked at Exit');                           

                        ELSE

                            /*Lets log mismatches even if there is not blockage*/
                            IF ent_lpn>5 && ent_lpn != 'AIG400K' && CHAR_LENGTH(_lpn)>=7 && ent_lpn != _lpn THEN

                                INSERT INTO numberplate_mismatches(`token_number`,`token_type`,`entry_plates`,`exit_plates`,`ptrans_id`,action_descritpion) VALUES
                                (_cardno,'N-ACARD',ent_lpn,_lpn,sea_exists,'Normal Card mismatched but Allowed Out at Exit');


                            END IF;

                            /*Lets calculate a charge if sarit_apb is enacted*/

                            IF sarit_apb=1 AND card_trans_type=7 THEN                           

                                SELECT AVG(sarit.afrage) FROM  (SELECT trans_amount AS afrage FROM acardtransactions WHERE trans_type=2 AND card_no=_cardno  ORDER BY trans_id DESC LIMIT 2,5) AS sarit INTO sarit_avg_amt;

                                SELECT FLOOR(sarit_avg_amt) INTO sarit_avg_amt;

                            END IF;



                            /*enuf*/

                            /*Hallo*/
                            IF use_entry_zone=1 THEN

                                SET myzone=entry_zone;

                            END IF;
                            /*lets charge*/

                            SELECT FLOOR(TIMESTAMPDIFF(MINUTE,time_in,time_now)) INTO raw_duration;

                            IF raw_duration > 1440 THEN
                                SELECT FLOOR(TIMESTAMPDIFF(DAY,time_in,time_now)) INTO days_spent;

                                /*We check for the day rates aggressively*/
                                SELECT fullday_rate_sniffer(time_in,myzone,_vehcat,days_spent,mysite) INTO fd_fee;


                                SELECT DATE_ADD(time_in, INTERVAL days_spent DAY) INTO time_in;/*get our new time in*/                                          

                                SET fd_fee=fd_fee*days_spent;                               
                                IF ISNULL(fd_fee)THEN SET fd_fee=0; END IF;#safety
                            END IF;

                            /*Lets now calculate the amount time spent on a single day*/
                            SELECT DAYOFWEEK(time_in) INTO dow1;
                            SELECT DAYOFWEEK(time_now) INTO dow2;

                            IF(dow1 != dow2) THEN
                                #SELECT myzone,dow1,_vehcat,time_in,CONCAT(DATE(time_in),' ','23:59:59');
                                 SELECT rate_sniffer(myzone,dow1,_vehcat,time_in,CONCAT(DATE(time_in),' ','23:59:59'),'A') INTO fee1;

                                 #SELECT myzone,dow2,_vehcat,CONCAT(DATE(time_now),' ','00:00:00'),time_now;                   
                                 SELECT rate_sniffer(myzone,dow2,_vehcat,CONCAT(DATE(time_now),' ','00:00:00'),time_now,'B') INTO fee2;  

                            ELSE        
                                #SELECT myzone,dow1,_vehcat,time_in,time_now;
                                SELECT rate_sniffer(myzone,dow1,_vehcat,time_in,time_now,'A') INTO fee1;

                            END IF;



                            SET total_fee=IFNULL(fd_fee,0)+IFNULL(fee1,0)+IFNULL(fee2,0);



                            IF location=1 && pay_state>=1 THEN

                                SELECT `get_partial_total`(_cardno,'',mysite) INTO amount_charged;

                                SET total_fee=total_fee-IFNULL(amount_charged,0); 

                            END IF;

                            SET total_fee=total_fee+IFNULL(sarit_avg_amt,0);                        


                            IF total_fee > _baloncard THEN

                                SET return_value=total_fee;                 
                                SET bool_code='FALSE';
                                SET error_code='ER243';
                                SET info_msg='MS243';                           

                            ELSE

                                SELECT trans_id FROM acardtransactions WHERE parkingtrans_transid=sea_exists AND card_no=_cardno AND DATE(time_in)=DATE(time_in) LIMIT 0,1 INTO cardrec;

                                IF ISNULL(cardrec) THEN

                                    INSERT INTO `acardtransactions` (`parkingtrans_transid`, `card_no`, `trans_time`, `timein`, `timeout`, `amount_before`, `expected_amount`,`trans_station`, `merchant_id`, `site`, `trans_type`, `trans_desc`,logged) VALUES
                                                          (sea_exists,_cardno,time_now,time_in,time_now,_baloncard,total_fee,_station,merch_agent,mysite,2,'EXIT CHARGE',3);
                                 END IF;

                                SET return_value=total_fee;                 
                                SET bool_code='TRUE';
                                SET error_code='ER000';
                                SET info_msg='MS000';

                            END IF;                                                 

                        END IF ;                                            

                    END IF;             

                ELSE                

                    SET bool_code='FALSE';
                    SET error_code='ER248';
                    SET info_msg='MS248';               

                END IF;/*Normal Exit Event Check*/



            END IF;/*end of seasonal or normal check*/  

        END IF;/*end of blacklist check*/

    END IF;/*end of master or blocked check*/
END IF;/*end of parameter check*/
   /*lets check pending details*/
   SELECT floating_value,floating_status,fid FROM floating_acard WHERE card_no=_cardno AND floating_status=1 INTO pending_value,pending,pending_id;

    IF pending_id >=1 THEN

    SET pending_value=IFNULL(return_value,0)-IFNULL(pending_value,0);

    ELSE

    SET pending_value=return_value;

    END IF; 


   SELECT disp_msg(info_msg) INTO message_string;   

   SELECT CONCAT(_cardno,' @ ', NOW(),' @ ',stn_type,' last-record:',IFNULL(lastinsert,0)) INTO story;

   SELECT get_severity(error_code) INTO error_sev;

   SELECT bool_code,error_code,info_msg,message_string,IFNULL(return_value,0) AS return_value,stn_type,IFNULL(pending_value,0) AS pending_value,pending,IFNULL(pending_id,'') AS pending_id,event,story;





END$$

DELIMITER ;