package cn.iocoder.yudao.module.visit.dal.mysql.product;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.visit.dal.dataobject.product.ProductDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.visit.controller.admin.product.vo.*;

/**
 * 产品 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface ProductMapper extends BaseMapperX<ProductDO> {

    default ProductDO selectByProductParam(String productName, String specification, String packageName) {
        Long companyId = SecurityFrameworkUtils.getLoginUserDeptId();
        return selectOne(new LambdaQueryWrapperX<ProductDO>()
                .eqIfPresent(ProductDO::getProductName, productName)
                .eqIfPresent(ProductDO::getSpecification, specification)
                .eqIfPresent(ProductDO::getPackageName, packageName)
                .eqIfPresent(ProductDO::getCompanyId, companyId)

        );
    }

    default PageResult<ProductDO> selectPage(ProductPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProductDO>()
                .likeIfPresent(ProductDO::getProductName, reqVO.getProductName())
                .eqIfPresent(ProductDO::getPackageName, reqVO.getPackageName())
                .eqIfPresent(ProductDO::getSpecification, reqVO.getSpecification())
                .eqIfPresent(ProductDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ProductDO::getCompanyId, reqVO.getCompanyId())
                .betweenIfPresent(ProductDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ProductDO::getId));
    }

    default List<ProductDO> selectByIds(List<String> list, Long companyId){
        return selectList(new LambdaQueryWrapperX<ProductDO>()
                .eqIfPresent(ProductDO::getCompanyId, companyId)
                .inIfPresent(ProductDO::getId, list));
    }
}