-- 创建存储过程开始-----------
DELIMITER //
CREATE PROCEDURE `InsertL_WH_GOODS` (IN p_WAREHOUSE_FLOW_ID BIGINT,IN p_WAREHOUSE_ID BIGINT,IN p_WH_GOODS_RECORD_ID BIGINT,IN p_RECORD_TYPE SMALLINT,IN p_WAREHOUSE_NAME VARCHAR (100),IN p_COST_TYPE SMALLINT,IN p_BASE_GOODS_TEMPLATE_ID BIGINT,IN p_GOODS_TEMPLATE_NAME VARCHAR (200),IN p_BASE_GOODS_MODELS_ID BIGINT,IN p_BASE_GOODS_MODELS_NAME VARCHAR (200),IN p_SUPPLIER VARCHAR (200),IN p_BUY_TYPE SMALLINT,IN p_UNIT VARCHAR (10),IN p_PRICE BIGINT,IN p_PROCURE_DATE BIGINT,IN p_STATES INT,IN p_DEAL_TIME BIGINT,IN p_times INT) BEGIN DECLARE i INT DEFAULT 1; DECLARE v_WH_GOODS_ID BIGINT; DECLARE CONTINUE
HANDLER FOR SQLEXCEPTION BEGIN-- An error occurred, rollback the transaction
ROLLBACK; END;-- Start the transaction
START TRANSACTION; WHILE i<=p_times
DO
INSERT INTO L_WH_GOODS (WAREHOUSE_ID,WAREHOUSE_NAME,COST_TYPE,BASE_GOODS_TEMPLATE_ID,GOODS_TEMPLATE_NAME,BASE_GOODS_MODELS_ID,BASE_GOODS_MODELS_NAME,SUPPLIER,BUY_TYPE,UNIT,PRICE,PROCURE_DATE,STATES) VALUES (p_WAREHOUSE_ID,p_WAREHOUSE_NAME,p_COST_TYPE,p_BASE_GOODS_TEMPLATE_ID,p_GOODS_TEMPLATE_NAME,p_BASE_GOODS_MODELS_ID,p_BASE_GOODS_MODELS_NAME,p_SUPPLIER,p_BUY_TYPE,p_UNIT,p_PRICE,p_PROCURE_DATE,p_STATES);
SET v_WH_GOODS_ID=LAST_INSERT_ID();-- 插入后获取ID并存入L_WH_GOODS_RECORD_DETAILS表
INSERT INTO L_WH_GOODS_RECORD_DETAILS (WH_GOODS_RECORD_ID,WH_GOODS_ID,THIS_TYPE) VALUES (p_WH_GOODS_RECORD_ID,v_WH_GOODS_ID,p_RECORD_TYPE);-- 插入到L_GOODS_WH_RECORD表
INSERT INTO L_GOODS_WH_RECORD (WAREHOUSE_FLOW_ID,WH_GOODS_ID,WAREHOUSE_ID,DEAL_TIME) VALUES (p_WAREHOUSE_FLOW_ID,v_WH_GOODS_ID,p_WAREHOUSE_ID,p_DEAL_TIME);
SET i=i+1; END WHILE;-- If no errors, commit the transaction
COMMIT; END
-- 创建存储过程结束  -----------
