create procedure proc_contract_Making(IN proId varchar(32), IN contractId varchar(32), IN contractNo varchar(32), IN carNumber varchar(50), IN carColor varchar(50), IN carNo varchar(50))
BEGIN
	DECLARE result_code INTEGER DEFAULT 0; -- 定义返回结果并赋初值0
        DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET result_code=1; -- 在执行过程中出任何异常设置result_code为1
        DECLARE CONTINUE HANDLER FOR NOT FOUND SET result_code = 2; -- 如果表中没有下一条数据则置为2
-- 从项目层到合同层的sql
INSERT INTO lb_contract_info (distributor_id,ID,contract_no,CONTRACT_NUMBER,CONTRACT_STATUS,PRODUCT_NAME,product_id,PROJECT_ID,PROJECT_DATE,PROJECT_TYPE,PROJECT_NAME,RENT_METHOD,LEAS_FORM,PROJECT_DEPT,PROJECT_MANAGE,END_DATE,INPUTUSERID,INPUTORGID,INPUTTIME,IS_PRINT,CONTRACT_INVOICE_STATUS,BUSINESSTYPE,CAR_TYPE,inputName,inputTel,HaveCommission,IS_NETCAR)
(SELECT lpi.distributor_id,contractId,contractNo,contractNo,'21',lpi.PRODUCT_NAME,lpi.product_id,lpi.id,DATE_FORMAT(NOW(),'%Y/%m/%d %H:%i:%s'),lpi.PROJECT_TYPE,lpi.PROJECT_NAME,'010',lpi.LEAS_FORM,lpi.PROJECT_DEPT,lpi.PROJECT_MANAGE,lpi.END_DATE,lpi.INPUTUSERID,lpi.INPUTORGID,DATE_FORMAT(NOW(),'%Y/%m/%d %H:%i:%s'),'noprint','cistatus01',
lpi.BUSINESSTYPE,lpi.CAR_TYPE,lpi.inputName,lpi.inputTel,lpi.HaveCommission,lpi.IS_NETCAR  FROM lb_project_info lpi WHERE lpi.id=proId);
-- 修改租赁物的 车架号、颜色、发动机号,合同号
UPDATE LB_EQUIPMENT_CAR SET FRAME_NUMBER=carNumber,CAR_COLOUR=carColor,ENGINE_NUMBER=carNo,CONTRACT_ID=contractId WHERE PROJECT_ID=proId;
-- 向LB_UNION_LESSEE添加合同ID
UPDATE LB_UNION_LESSEE SET contract_id=contractId WHERE project_id=proId;
-- 想共同申请人或者配偶添加contracID字段
UPDATE CUSTOMER_FAMILY SET contract_id=contractId WHERE project_id=proId;
-- 向担保人信息表中
UPDATE LB_GUARANTEE_UNIT SET contract_id=contractId WHERE project_id=proId;
-- 向扣款卡信息表中
UPDATE CUSTOMER_ACCOUNT SET contract_id=contractId WHERE project_id=proId;
-- 更新项目进度表
INSERT INTO BUSINESS_STATUS (id,contract_number,business_status) (SELECT REPLACE(UUID(),'-','') AS id,contractNo,'11');
 SELECT result_code;
END;

