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

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.packagedata.vo.PackageDataPageReqVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.packagedata.vo.PackageDataRespVO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.factorydata.FactoryDataDO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.packagedata.PackageDataDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

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

/**
 * 打包线数据 Mapper
 *
 * @author 艾楷
 */
@Mapper
public interface PackageDataMapper extends BaseMapperX<PackageDataDO> {

    IPage<PackageDataRespVO> selectPackagePage(@Param("page") IPage<PackageDataRespVO> mpPage, @Param("reqVO") PackageDataPageReqVO pageReqVO);

    List<FactoryDataDO> selectDataListByDateTime(@Param("dateTime") LocalDateTime[] dateTimes);

    default List<PackageDataDO> selectListByFactoryIdAndDate(Long factoryId, String date) {

        return selectList(new LambdaQueryWrapperX<PackageDataDO>()
                .eq(PackageDataDO::getFactoryId, factoryId)
                .eq(PackageDataDO::getPackageDate, date));
    }

    default Long selectCountByDateTime(Long factoryId, LocalDate date, LocalDateTime[] dateTimes) {

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

    default void delectData(Long factoryId, String date) {

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