package com.wzj.soopin.transaction.business.impl;

import com.wzj.soopin.transaction.business.IChargeBusiness;
import com.wzj.soopin.transaction.convert.ChargeConvert;
import com.wzj.soopin.transaction.domain.bo.ChargeBO;
import com.wzj.soopin.transaction.domain.po.Charge;
import com.wzj.soopin.transaction.domain.vo.ChargeVO;
import com.wzj.soopin.transaction.enums.ChargeStatus;
import com.wzj.soopin.transaction.service.IChargeService;
import com.wzj.soopin.transaction.util.SnowFlake;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.domain.model.LoginUser;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.web.core.BusinessImpl;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@AllArgsConstructor
public class ChargeBusinessImpl extends BusinessImpl<IChargeService, ChargeConvert, ChargeVO, ChargeBO, Charge> implements IChargeBusiness {
    @Override
    public boolean charge(ChargeBO bo) {

        //先检查是否发起过，如果发起过则返回原订单
        Charge existCharge = service.getByCode(bo.getCode());
        if (existCharge!=null){
            return true;
        }
        Charge charge = converter.toPo(bo);
        service.charge(charge);
        bo.setCode(charge.getCode());
        return true;
    }
}
