package cn.iocoder.yudao.module.museum.dal.mysql.museumflow;

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.museum.controller.admin.museumflow.vo.MuseumFlowPageVO;
import cn.iocoder.yudao.module.museum.dal.database.museumflow.MuseumFlowDO;
import cn.iocoder.yudao.module.museum.dal.database.museuminfo.MuseumInfoDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Collection;
import java.util.List;

@Mapper
public interface MuseumFlowMapper extends BaseMapperX<MuseumFlowDO> {

    @Update("UPDATE museum_outbound SET sample_type=#{sampleType}, place=#{place} WHERE id =#{id}")
    void updateMuseumFlow(MuseumFlowDO museumFlowDO);

    @Update("UPDATE museum_outbound SET deleted=1  WHERE id =#{id}")
    void deleteMuseumFlow(Integer id);

    @Select("SELECT * FROM museum_outbound WHERE id = #{id} AND deleted =0 ")
    MuseumFlowDO selectMuseumFlowById(@Param("id") Integer id);

/**根据编号在总表中进行查找**/
    @Select("SELECT * FROM museum_info WHERE sample_id = #{sample_id} AND deleted =0 ")
    MuseumInfoDO selectMuseumFlowBySampleId(@Param("sample_id") String sample_id);

/**将样品状态更新为1**/
    @Update("UPDATE museum_outbound SET state=0  WHERE number =#{number}")
    void updateMuseumFlowState(MuseumFlowDO museumFlowDO);

///**将样品状态更新为4**/
    @Update("UPDATE museum_outbound SET state=4 WHERE number =#{number}")
    void updateMuseumFlowState4(MuseumFlowDO museumFlowDO);

///**将样品状态更新为4**/
    @Update("UPDATE museum_outbound SET state=3 WHERE number =#{number}")
    void updateMuseumFlowState3(MuseumFlowDO museumFlowDO);

/**分页**/
   default MuseumFlowDO selectPageMuseumFlowByPage(String number){return selectOne(MuseumFlowDO::getNumber,number);}

   default PageResult<MuseumFlowDO> selectPage1(MuseumFlowPageVO pageVO){
       LambdaQueryWrapperX<MuseumFlowDO> queryWrapper = new LambdaQueryWrapperX<>();
       queryWrapper .likeIfPresent(MuseumFlowDO::getNumber,pageVO.getNumber())
               .betweenIfPresent(MuseumFlowDO::getOutboundTime, pageVO.getOutboundTime())
               .eqIfPresent(MuseumFlowDO::getOutboundPerson,pageVO.getOutboundPerson())
               .orderByDesc(MuseumFlowDO::getId);

       return selectPage(pageVO, queryWrapper);

//       return selectPage(pageVO ,new LambdaQueryWrapperX<MuseumFlowDO>()
//               .likeIfPresent(MuseumFlowDO::getNumber,pageVO.getNumber())
//               .betweenIfPresent(MuseumFlowDO::getOutboundTime, pageVO.getOutboundTime())
//               .eqIfPresent(MuseumFlowDO::getOutboundPerson,pageVO.getOutboundPerson())
//               .inIfPresent(MuseumFlowDO::getId, id)
//               .orderByDesc(MuseumFlowDO::getId));
   }
    default List<MuseumFlowDO> selectPageMuseumFlowByOutboundPerson(MuseumFlowPageVO pageVO) {

       LambdaQueryWrapperX<MuseumFlowDO> queryWrapper = new LambdaQueryWrapperX<>();
        queryWrapper .likeIfPresent(MuseumFlowDO::getNumber,pageVO.getNumber())
                .betweenIfPresent(MuseumFlowDO::getOutboundTime, pageVO.getOutboundTime())
                .eqIfPresent(MuseumFlowDO::getOutboundPerson,pageVO.getOutboundPerson())
                .orderByDesc(MuseumFlowDO::getId);
        return selectList(queryWrapper);
    }


}
