| @@ -0,0 +1,96 @@ | |||
| DELIMITER $$ | |||
| DROP PROCEDURE IF EXISTS `contract_update`$$ | |||
| CREATE PROCEDURE `contract_update`() | |||
| LANGUAGE SQL | |||
| NOT DETERMINISTIC | |||
| CONTAINS SQL | |||
| SQL SECURITY DEFINER | |||
| COMMENT '' | |||
| begin | |||
| #定义一个循环结束的标记 | |||
| declare done int default false; | |||
| #定义一个循环总条数 | |||
| declare total int; | |||
| #定义一个循环开始值 | |||
| declare i int; | |||
| #定义商铺相关字段 | |||
| declare _shop_id varchar(100); | |||
| declare _shop_number varchar(100); | |||
| declare _build_area varchar(100); | |||
| declare _operation_area varchar(100); | |||
| declare _floor varchar(100); | |||
| declare _img_url varchar(1024); | |||
| declare _addr varchar(100); | |||
| declare _type smallint(2); | |||
| declare _status smallint(2); | |||
| declare _manager varchar(100); | |||
| declare _manager_phone varchar(100); | |||
| declare _building varchar(100); | |||
| #租赁合同相关信息 | |||
| declare _rent_id bigint(64); | |||
| declare _rent_area varchar(100); | |||
| declare _adjust_ratio json; | |||
| declare _price decimal(10,2); | |||
| declare _deposit decimal(10,2); | |||
| declare _adjust_ratio_new json; | |||
| declare _adjust_ratio_value decimal(10,2); | |||
| declare rent_cursor cursor for select id,shop_id from wx_rent_contract where rent_shop_type=1; | |||
| declare rent_total_cursor cursor for select count(*) total from wx_rent_contract where rent_shop_type=1; | |||
| declare continue handler for not found set done = true; | |||
| set i=1; | |||
| open rent_cursor; | |||
| open rent_total_cursor; | |||
| fetch rent_cursor into _rent_id,_shop_id; | |||
| fetch rent_total_cursor into total; | |||
| repeat | |||
| if not done then | |||
| #查询商铺信息 | |||
| select s.shop_number,s.build_area,s.img_url,s.operation_area,s.status,b.building_name,f.floor_name, | |||
| s.manager,s.manager_phone,type,s.addr | |||
| into _shop_number,_build_area,_img_url,_operation_area,_status,_building,_floor,_manager,_manager_phone,_type,_addr | |||
| from wx_shop s left join wx_mall_building b on s.building=b.id left join wx_mall_floor f on s.floor=f.id | |||
| where s.id=_shop_id; | |||
| #查询合同信息 | |||
| select rent_area,adjust_ratio,truncate(price/100,2),truncate(deposit/100,2) into _rent_area,_adjust_ratio,_price,_deposit | |||
| from wx_rent_contract where id=_rent_id; | |||
| #解析年调整比例 | |||
| set @j=0; | |||
| set _adjust_ratio_new = json_array(); | |||
| while (select json_length(_adjust_ratio))>0 and @j<>(select json_length(_adjust_ratio)) do | |||
| set @ratio_index=concat("$[",@j,"]"); | |||
| select truncate(json_extract(_adjust_ratio,@ratio_index)/100,2) into _adjust_ratio_value; | |||
| select json_array_insert(_adjust_ratio_new,@ratio_index,_adjust_ratio_value) into _adjust_ratio_new; | |||
| set @j=@j+1; | |||
| end while; | |||
| #更新租赁合同信息 | |||
| update wx_rent_contract set rent_info=json_array(JSON_OBJECT('shopId',_shop_id,'id',_shop_id,'shopNumber',_shop_number, | |||
| 'price',_price,'deposit',_deposit,'adjustRatio',_adjust_ratio_new,'addr',_addr,'buildArea',_build_area,'imgUrl',_img_url, | |||
| 'operationArea',_operation_area,'building',_building,'floor',_floor,'manager',_manager,'managerPhone',_manager_phone, | |||
| 'type',_type,'status',_status,'rentArea',_rent_area)) | |||
| where id=_rent_id; | |||
| #更新物业信息 | |||
| update wx_property_contract set rent_info=json_array(JSON_OBJECT('shopId',_shop_id,'id',_shop_id,'shopNumber',_shop_number, | |||
| 'price',_price,'deposit',_deposit,'adjustRatio',_adjust_ratio_new,'addr',_addr,'buildArea',_build_area,'imgUrl',_img_url, | |||
| 'operationArea',_operation_area,'building',_building,'floor',_floor,'manager',_manager,'managerPhone',_manager_phone, | |||
| 'type',_type,'status',_status,'rentArea',_rent_area)) | |||
| where rent_contract_id=_rent_id; | |||
| fetch rent_cursor into _rent_id,_shop_id; | |||
| end if; | |||
| IF i<>total then | |||
| set done =false; | |||
| set i=i+1; | |||
| else | |||
| set done = true; | |||
| end if; | |||
| until done | |||
| end repeat; | |||
| close rent_cursor; | |||
| close rent_total_cursor; | |||
| end $$ | |||
| DELIMITER ; | |||
| ### call contract_update(); | |||