package cn.iocoder.yudao.module.system.api.cashregisterinfo;

import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.module.system.dal.dataobject.cashregisterinfo.CashRegisterInfoDO;
import cn.iocoder.yudao.module.system.dal.mysql.carteen.CarteenMapper;
import cn.iocoder.yudao.module.system.dal.mysql.cashregisterinfo.CashRegisterInfoMapper;
import cn.iocoder.yudao.module.system.dal.mysql.dishes.DishesMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CashregisterinfoApiImpl implements CashregisterinfoApi{

    @Resource
    private CarteenMapper carteenMapper;

    @Resource
    private CashRegisterInfoMapper cashRegisterInfoMapper;

    @Override
    public String getStoreName(String equipmentCode) {
        List<CashRegisterInfoDO> cashRegisterInfoDOS = cashRegisterInfoMapper.selectList(Wrappers.<CashRegisterInfoDO>lambdaQuery().eq(CashRegisterInfoDO::getEquipmentCode, equipmentCode));
        if(CollectionUtil.isNotEmpty(cashRegisterInfoDOS)){
            CashRegisterInfoDO cashRegisterInfoDO = cashRegisterInfoDOS.get(0);
            return carteenMapper.selectById(cashRegisterInfoDO.getCarteenId()).getStoresName();
        }
        return "";
    }

    @Override
    public Long getStoreId(String equipmentCode) {
        List<CashRegisterInfoDO> cashRegisterInfoDOS = cashRegisterInfoMapper.selectList(Wrappers.<CashRegisterInfoDO>lambdaQuery().eq(CashRegisterInfoDO::getEquipmentCode, equipmentCode));
        if(CollectionUtil.isNotEmpty(cashRegisterInfoDOS)){
            CashRegisterInfoDO cashRegisterInfoDO = cashRegisterInfoDOS.get(0);
            return cashRegisterInfoDO.getCarteenId();
        }
        return null;
    }
}
