package cn.iocoder.yudao.module.smartfactory.dal.mysql.factorydata;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.smartfactory.controller.admin.factorydata.vo.FactoryDataInfoRespVO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.factorydata.FactoryDataSizeDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;

/**
 * 工厂出库入库规格数据 Mapper
 *
 * @author 符溶馨
 */
@Mapper
public interface FactoryDataSizeMapper extends BaseMapperX<FactoryDataSizeDO> {

    List<FactoryDataInfoRespVO> selectDetailList(@Param("factoryId") Long factoryId, @Param("date") LocalDate[] date);

    default void deleteByFactoryId(Long factoryId, String date) {

        delete(new LambdaQueryWrapperX<FactoryDataSizeDO>()
                .eq(FactoryDataSizeDO::getFactoryId, factoryId)
                .eq(FactoryDataSizeDO::getDate, date));
    }

    default Long selectCountByFactoryId(Long factoryId, String date, LocalDateTime[] dateTimes) {

        return selectCount(new LambdaQueryWrapperX<FactoryDataSizeDO>()
                .eq(FactoryDataSizeDO::getFactoryId, factoryId)
                .eq(FactoryDataSizeDO::getDate, date)
                .betweenIfPresent(FactoryDataSizeDO::getCreateTime, dateTimes));
    }

    default Long selectCountByType(Long factoryId, LocalDate date, Collection<Integer> types) {

        return selectCount(new LambdaQueryWrapperX<FactoryDataSizeDO>()
                .eq(FactoryDataSizeDO::getFactoryId, factoryId)
                .eq(FactoryDataSizeDO::getDate, date)
                .in(FactoryDataSizeDO::getType, types));
    }

    List<FactoryDataInfoRespVO> selectSUMByDateTimes(@Param("dateTime") LocalDateTime[] dateTimes);
}
