package com.jeesharp.business.modules.food.service.impl;

import com.jeesharp.business.modules.food.entity.FoodCompanyRecharge;
import com.jeesharp.business.modules.food.mapper.FoodCompanyRechargeMapper;
import com.jeesharp.business.modules.food.service.FoodCompanyRechargeService;
import com.jeesharp.framework.mybatis.core.service.CrudService;
import com.jeesharp.framework.pojo.query.PaginationVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
public class FoodCompanyRechargeServiceImpl extends CrudService<FoodCompanyRechargeMapper, FoodCompanyRecharge, PaginationVO> implements FoodCompanyRechargeService {

    @Override
    public FoodCompanyRecharge lockById(String id, String tenantCode) {
        return getBaseMapper().selectByIdForUpdate(id, tenantCode);
    }

    @Override
    public FoodCompanyRecharge lockByPayOrderId(String payOrderId) {
        return getBaseMapper().selectByPayOrderIdForUpdate(payOrderId);
    }

    @Override
    public FoodCompanyRecharge lockByPayOrderNo(String payOrderNo) {
        return getBaseMapper().selectByPayOrderNoForUpdate(payOrderNo);
    }

    @Override
    @Transactional(readOnly = false)
    public void insertRecharge(FoodCompanyRecharge recharge) {
        recharge.setIsNewRecord(true);
        recharge.preInsert();
        getBaseMapper().insert(recharge);
    }

    @Override
    @Transactional(readOnly = false)
    public void updateRecharge(FoodCompanyRecharge recharge) {
        recharge.preUpdate();
        getBaseMapper().updateById(recharge);
    }
}
