-- 创建存储过程开始-----------
DELIMITER //
CREATE PROCEDURE `InsertL_WH_GOODS` (IN p_WAREHOUSE_FLOW_ID BIGINT,IN p_WAREHOUSE_TYPE SMALLINT,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_TYPE,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_TYPE,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表
        UPDATE L_GOODS_WH_RECORD SET LAST_RECORD=0 WHERE WH_GOODS_ID=v_WH_GOODS_ID AND WAREHOUSE_ID=p_WAREHOUSE_ID AND WAREHOUSE_TYPE=p_WAREHOUSE_TYPE AND LAST_RECORD=1;
        INSERT INTO L_GOODS_WH_RECORD (WAREHOUSE_FLOW_ID,WH_GOODS_ID,WAREHOUSE_TYPE,WAREHOUSE_ID,DEAL_TIME,LAST_RECORD) VALUES (p_WAREHOUSE_FLOW_ID,v_WH_GOODS_ID,p_WAREHOUSE_TYPE,p_WAREHOUSE_ID,p_DEAL_TIME,1);
        SET i=i+1; END WHILE;-- If no errors, commit the transaction
COMMIT; END
-- 创建存储过程结束  -----------

-- 创建存储过程开始-----------
DELIMITER //
CREATE PROCEDURE `insert_WH_GOODS_RECORD_DETAILS` (IN WHGOODSIDList TEXT,IN WH_GOODS_RECORD_ID BIGINT,IN THIS_TYPE INT) BEGIN DECLARE i INT DEFAULT 1; DECLARE n INT DEFAULT 0; DECLARE WH_GOODS_ID BIGINT;
SET n=LENGTH(WHGOODSIDList)-LENGTH(
        REPLACE (WHGOODSIDList,',',''))+1; WHILE i<=n
DO
SET WH_GOODS_ID=SUBSTRING_INDEX(SUBSTRING_INDEX(WHGOODSIDList,',',i),',',-1);
INSERT INTO L_WH_GOODS_RECORD_DETAILS (WH_GOODS_RECORD_ID,WH_GOODS_ID,THIS_TYPE) VALUES (WH_GOODS_RECORD_ID,WH_GOODS_ID,THIS_TYPE);
SET i=i+1; END WHILE; END
-- 创建存储过程结束  -----------

# 2023 12 07
alter table base_category modify d_user_id BIGINT(16);
