task_payment_byonlinedown

本文介绍了一个使用MySQL存储过程实现的在线还款任务处理流程。该流程通过定义游标逐条处理待还款记录,并根据是否为部分还款更新业务状态。此外,还包括了账单状态更新、还款记录插入等操作。

CREATE DEFINER=`root`@`%` PROCEDURE `vir`.`task_payment_byonlinedown`()
begin
declare _mobile varchar(12) ;
declare _amount decimal(18,4) default 0;
declare _reduce_amount decimal(18,4) default 0;
declare _is_part varchar(12) ;
declare _excute_status varchar(12) ;
declare stop_flag int DEFAULT 0;
declare _app_id varchar(100);
declare _bill_status varchar(12);
declare _app_status varchar(12);
declare _REDUCE_AMOUNT_temp decimal(18,4) default 0;
declare cur1 cursor for select mobile,amount,reduce_amount,is_part,excute_status from task_payment_byonlinedown where excute_status=1;
declare CONTINUE HANDLER FOR SQLSTATE '02000' SET stop_flag=1;
open cur1;
fetch cur1 into _mobile,_amount,_reduce_amount,_is_part,_excute_status;#读取数据到游标
while stop_flag<>1 DO#若游标有下一条记录,循环
select apply_id,REDUCE_AMOUNT into _app_id,_REDUCE_AMOUNT_temp from vir.biz_bill where mobile=_mobile order by create_date desc limit 1;

#部分还款
if(_is_part='0') then
set _app_status =11 ;
set _bill_status=3;
end if;
#全部还款
if(_is_part='1') then
set _app_status =8;
set _bill_status=1;
end if;

#1 biz_apply
UPDATE biz_apply set APPLY_STATUS=_app_status WHERE id = _app_id;

#2 biz_bill
UPDATE biz_bill set
LATE_REPAYMENT_DATE=sysdate(),
LATE_REPQYMENT_AMOUNT=_amount,
REAL_TOTAL_AMOUNT=_amount,
BILL_STATUS=_bill_status,
SETTLE_DATE=sysdate(),
REDUCE_AMOUNT = _REDUCE_AMOUNT_temp+_reduce_amount,
DEMO2 = concat('appid','_',_app_id,'_对公还款_支付宝_还款金额_',_amount,'_减免金额_',_reduce_amount,'_还款时间_',sysdate())
WHERE APPLY_ID = _app_id;

#3biz_bill_detail
update biz_bill_details set
STAGING_STATUS=_bill_status,
UPDATE_DATE=sysdate()
where APPLY_ID=_app_id;

#4 BIZ_REDUCE
insert into BIZ_REDUCE (id,APPLY_ID,REDUCE_TOTAL_AMOUNT,CREATE_DATE) values
( CONVERT(substring(CAST(rand() as char),3, length(CAST(rand() as char))) ,SIGNED),_app_id ,_amount ,sysdate());


update task_payment_byonlinedown set excute_status=0 where excute_status=1 and mobile=_mobile;
fetch cur1 into _mobile,_amount,_reduce_amount,_is_part,_excute_status;
end while;
close cur1;
END

------------------------- -- 付款单信息 select * from omp_fp_task_payment_t where payment_num = 'AP202205100002'; -- 验收结果 select * from omp_fp_task_category_t where (payment_num, fp_task_id) in ( select payment_num, id from omp_fp_task_payment_t where payment_num = 'AP202205100002' ); -- 需求条目 select * from omp_reqitem_check_t where (fp_task_no, fp_task_id) in ( select payment_num, id from omp_fp_task_payment_t where payment_num = 'AP202205100002' ); -- 分摊信息:方案 select * from omp_po_allocation_solution_t where type = 'FP_TASK_PAYMENT' and (po_num) in ( select po_num from omp_fp_task_payment_t where payment_num = 'AP202205100002' ); select * from omp_po_allocation_solution_t where type = 'FP_TASK_PAYMENT' and (po_num, milestone_id) in ( select po_num, milestone_id from omp_fp_task_payment_t where payment_num = 'AP202205100002' ); select * from omp_po_allocation_solution_t where businesskey = 'AP202205100002'; -- 分摊信息:调账 select * from omp_profit_share_t where target_id in ( select project_id from omp_fp_task_payment_t where payment_num = 'AP202205100002' ); select * from omp_profit_share_t where target_id in ( select id from omp_fp_task_payment_t where payment_num = 'AP202205100002' ); -- 扣款信息 select * from omp_fp_task_payment_check_t where payment_num = 'AP202205100002'; -- 项目评价 select * from omp_tm_month_evaluation_t where (po_num, month_pay_num) in ( select po_num, payment_num from omp_fp_task_payment_t where payment_num = 'AP202205100002' ); -- 自定义评价 select * from omp_customize_evaluation_t where (po_num, month_pay_num) in ( select po_num, payment_num from omp_fp_task_payment_t where payment_num = 'AP202205100002' ); 帮我把这个SQL中的表,提取为下面的这种格式 select * from 表名; – 表中文说明
最新发布
09-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值