package cn.pluss.platform.deviceDetail;

import cn.pluss.platform.entity.DeviceDetail;
import cn.pluss.platform.mapper.DeviceDetailMapper;
import cn.pluss.platform.vo.DeviceDetailVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;

import java.util.List;

/**
 * <p>
 * [设备展示表] 服务类
 * </p>
 *
 * @author bzg
 * @since 2020-11-12
 */
public interface DeviceDetailService extends IService<DeviceDetail> {

    /**
     * 根据code获取有效的商品列表
     * @param codeList
     * @return
     */
    List<DeviceDetailVO> listByCode(List<String> codeList);

    /**
     * 根据code获取有效的商品列表
     * @param codeList
     * @return
     */
    List<DeviceDetailVO> listByCodeSimple(List<String> codeList);

    default DeviceDetail getByCodeAndSpec(String code, String spec) {
        QueryWrapper<DeviceDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dd.code", code);
        queryWrapper.eq("ds.spec", spec);
        queryWrapper.eq("status", 1);
        queryWrapper.orderByAsc("seq");

        List<DeviceDetail> deviceDetailList = ((DeviceDetailMapper) getBaseMapper()).selectListWithStock(queryWrapper);

        return deviceDetailList.get(0);
    }
}
