42 lines
1.0 KiB
SQL
42 lines
1.0 KiB
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_setProblemRisk`(
|
|
vSelf INT
|
|
)
|
|
BEGIN
|
|
/**
|
|
* Update the risk problem for a specific ticket
|
|
*
|
|
* @param vSelf Id ticket
|
|
*/
|
|
DECLARE vHasRisk BOOL;
|
|
DECLARE vHasHighRisk BOOL;
|
|
DECLARE vIsProblemCalcNeeded BOOL;
|
|
|
|
SELECT t.risk > (c.credit + 10),
|
|
(t.risk - cc.riskTolerance) > (c.credit + 10),
|
|
ticket_isProblemCalcNeeded(t.id)
|
|
INTO vHasRisk, vHasHighRisk, vIsProblemCalcNeeded
|
|
FROM client c
|
|
JOIN ticket t ON t.clientFk = c.id
|
|
JOIN clientConfig cc
|
|
WHERE t.id = vSelf;
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
|
ENGINE = MEMORY
|
|
SELECT vSelf ticketFk,
|
|
vHasRisk hasProblem,
|
|
vIsProblemCalcNeeded isProblemCalcNeeded;
|
|
|
|
CALL ticket_setProblem('hasRisk');
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
|
ENGINE = MEMORY
|
|
SELECT vSelf ticketFk,
|
|
vHasHighRisk hasProblem,
|
|
vIsProblemCalcNeeded isProblemCalcNeeded;
|
|
|
|
CALL ticket_setProblem('hasHighRisk');
|
|
|
|
DROP TEMPORARY TABLE tmp.ticket;
|
|
END$$
|
|
DELIMITER ; |