package cn.iocoder.yudao.module.pms.dal.mysql.iotsapstocklog;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.pms.controller.admin.iotsapstocklog.vo.IotSapStockLogPageReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.iotsapstocklog.IotSapStockLogDO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

/**
 * PMS SAP 库存(sap同步的原始数据日志) Mapper
 *
 * @author ruiqi
 */
@Mapper
public interface IotSapStockLogMapper extends BaseMapperX<IotSapStockLogDO> {

    default PageResult<IotSapStockLogDO> selectPage(IotSapStockLogPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<IotSapStockLogDO>()
                .eqIfPresent(IotSapStockLogDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(IotSapStockLogDO::getFactoryCode, reqVO.getFactoryCode())
                .eqIfPresent(IotSapStockLogDO::getFactoryId, reqVO.getFactoryId())
                .eqIfPresent(IotSapStockLogDO::getFactory, reqVO.getFactory())
                .eqIfPresent(IotSapStockLogDO::getStorageLocationCode, reqVO.getStorageLocationCode())
                .eqIfPresent(IotSapStockLogDO::getStorageLocationId, reqVO.getStorageLocationId())
                .eqIfPresent(IotSapStockLogDO::getProjectDepartment, reqVO.getProjectDepartment())
                .eqIfPresent(IotSapStockLogDO::getMaterialCode, reqVO.getMaterialCode())
                .likeIfPresent(IotSapStockLogDO::getMaterialName, reqVO.getMaterialName())
                .likeIfPresent(IotSapStockLogDO::getMaterialGroupName, reqVO.getMaterialGroupName())
                .eqIfPresent(IotSapStockLogDO::getMaterialGroupId, reqVO.getMaterialGroupId())
                .eqIfPresent(IotSapStockLogDO::getQuantity, reqVO.getQuantity())
                .eqIfPresent(IotSapStockLogDO::getUnitPrice, reqVO.getUnitPrice())
                .eqIfPresent(IotSapStockLogDO::getUnit, reqVO.getUnit())
                .eqIfPresent(IotSapStockLogDO::getSafetyStock, reqVO.getSafetyStock())
                .eqIfPresent(IotSapStockLogDO::getStorageAreaId, reqVO.getStorageAreaId())
                .eqIfPresent(IotSapStockLogDO::getShelvesId, reqVO.getShelvesId())
                .eqIfPresent(IotSapStockLogDO::getCargoLocationId, reqVO.getCargoLocationId())
                .eqIfPresent(IotSapStockLogDO::getType, reqVO.getType())
                .eqIfPresent(IotSapStockLogDO::getSyncStatus, reqVO.getSyncStatus())
                .betweenIfPresent(IotSapStockLogDO::getSyncTime, reqVO.getSyncTime())
                .eqIfPresent(IotSapStockLogDO::getSyncError, reqVO.getSyncError())
                .eqIfPresent(IotSapStockLogDO::getSort, reqVO.getSort())
                .eqIfPresent(IotSapStockLogDO::getStatus, reqVO.getStatus())
                .eqIfPresent(IotSapStockLogDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(IotSapStockLogDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(IotSapStockLogDO::getId));
    }

    /**
     * 物理删除 上次同步保存的SAP库存数据
     *
     * @return 删除条数
     */
    @Delete("DELETE FROM rq_iot_sap_stock_log WHERE 1=1")
    Integer deleteSapStockLogs(@Param("factoryCode") String factoryCode);

}