package com.hfkj.service.impl;

import com.hfkj.dao.BsDevicePriceMapper;
import com.hfkj.entity.BsDevice;
import com.hfkj.entity.BsDevicePrice;
import com.hfkj.entity.BsDevicePriceExample;
import com.hfkj.service.BsDevicePriceService;
import com.hfkj.sysenum.DevicePriceTypeEnum;
import com.hfkj.sysenum.DeviceTypeEnum;
import org.springframework.stereotype.Service;

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

/**
 * @className: BsDevicePriceServiceImpl
 * @author: HuRui
 * @date: 2022/12/29
 **/
@Service("devicePriceService")
public class BsDevicePriceServiceImpl implements BsDevicePriceService {

    @Resource
    private BsDevicePriceMapper devicePriceMapper;

    @Override
    public BigDecimal getPriceByType(DevicePriceTypeEnum devicePriceType, DeviceTypeEnum deviceType) {
        BsDevicePriceExample example = new BsDevicePriceExample();
        example.createCriteria()
                .andPriceTypeEqualTo(devicePriceType.getNumber())
                .andDeviceTypeEqualTo(deviceType.getNumber());
        List<BsDevicePrice> list = devicePriceMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0).getPrice();
        }
        return new BigDecimal("0");
    }
}
