package com.bohuikeji.delivery.backstage.listener.settlement;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bohuikeji.delivery.backstage.entity.TCompanyFran;
import com.bohuikeji.delivery.backstage.entity.TOrder;
import com.bohuikeji.delivery.backstage.service.ITCompanyFranService;
import com.bohuikeji.delivery.backstage.service.ITOrderService;
import com.bohuikeji.frame.module.admin.base.MqListener;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;

/**
 * 加盟商结算审核通过
 * @author 孙劲辉
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class FranSuccessListener extends MqListener<Integer> {

    final ITCompanyFranService franService;
    final ITOrderService orderService;

    @Override
    public boolean onReceive(Integer id) {
        TCompanyFran companyFran=franService.getById(id);
        String[] ids=companyFran.getSettOrderDetail();
        if(!orderService.update(new UpdateWrapper<TOrder>().set("fran_sett_status","已结算").in("order_id",ids))){
            log.error("结算单：{}结算失败，更新订单失败！",id);
            return true;
        }



        /*companyFran.setSettOrderDetail(ids.toString().split(","));
        companyFran.setSettOrderNum(count);
        companyFran.setOrderPayAmount(price);
        companyFran.setSettStatus("审核中");
        franService.updateById(companyFran);*/
        return true;
    }

    @Override
    public void onError(Integer msg, Exception e) {
        log.error("消息队列出现错误：{}",msg);
    }
}
