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

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.museuminfo.vo.MuseumInfoPageReqVO;
import cn.iocoder.yudao.module.museum.controller.admin.museuminfo.vo.MuseumInfoRespVO;
import cn.iocoder.yudao.module.museum.dal.database.museumflow.MuseumFlowDO;
import cn.iocoder.yudao.module.museum.dal.database.museuminfo.MuseumInfoDO;
import org.apache.ibatis.annotations.Mapper;
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.List;
import java.util.Map;

@Mapper
public interface MuseumInfoMapper extends BaseMapperX<MuseumInfoDO> {
    /**
     * 更新标本
     * */
    @Update("UPDATE museum_info SET sample_type=#{sampleType}, place=#{place},chinese_name=#{chineseName} WHERE id =#{id}")
    void updateMuseumInfo(MuseumInfoDO museumInfoDO);
    /**
     * 删除标本
     * */
    @Update("UPDATE museum_info SET deleted=1,reason=#{reason}  WHERE id =#{id}")
    void deleteMuseumInfo(Integer id,String reason);
    /**
     * 查询标本
     * */
    @Select("SELECT * FROM museum_info WHERE id =#{id} AND deleted =0 ")
    MuseumInfoDO selectMuseumInfoById(@Param("id") Integer id);
    /**
     * 查询标本编号
     * */
    @Select("SELECT * FROM museum_info WHERE sample_id =#{sampleId} AND deleted =0")
    MuseumInfoDO getMuseumInfoBySampleId(@Param("sampleId") String sampleId);
    /**
     * 查询标本类型
     */
    @Select("SELECT * FROM museum_info WHERE sample_type  =#{sampleType} AND deleted =0")
    List<MuseumInfoDO> selectMuseumInfoListBySampleType(@Param("sampleType") Integer sampleType);
    /**
     * 标本类型计数
     * */
    @Select("SELECT COUNT(*)  FROM museum_info WHERE sample_type =#{sampleType} AND deleted =0 AND save =1")
    Map<MuseumInfoRespVO,Integer> countMuseumInfoBySampleType(@Param("sampleType") Integer sampleType);
    /**
     * 标本出入库状态计数
     * */
    @Select("SELECT COUNT(*)  FROM museum_info  WHERE save =#{save} AND deleted =0")
    Map<String,Integer> countMuseumInfoBySave(@Param("save") Integer save);

    default PageResult<MuseumInfoDO> selectPage(MuseumInfoPageReqVO pageReqVO) {
        LambdaQueryWrapperX<MuseumInfoDO> queryWrapper = new LambdaQueryWrapperX<>();
        queryWrapper.likeIfPresent(MuseumInfoDO::getSampleId, pageReqVO.getSampleId())
                .eqIfPresent(MuseumInfoDO::getSampleType, pageReqVO.getSampleType())
                .likeIfPresent(MuseumInfoDO::getPlace, pageReqVO.getPlace())
                .orderByDesc(MuseumInfoDO::getId);
        return selectPage(pageReqVO, queryWrapper);
    }

//    default PageResult<MuseumInfoDO> selectPage1(MuseumInfoPageReqVO reqVO) {
//        return selectPage(reqVO, new LambdaQueryWrapperX<MuseumInfoDO>()
//                .likeIfPresent(MuseumInfoDO::getSampleId,reqVO.getSampleId())
//                .eqIfPresent(MuseumInfoDO::getSampleType,reqVO.getSampleType())
//                .likeIfPresent(MuseumInfoDO::getPlace,reqVO.getPlace())
//                .orderByDesc(reqVO.getId() != null,MuseumInfoDO::getId)); // 按照 id 倒序
//    }
//
//    default PageResult<MuseumInfoDO> selectPage2(MuseumInfoPageReqVO reqVO) {
//        return selectPage(reqVO, new LambdaQueryWrapperX<MuseumInfoDO>()
//                .likeIfPresent(MuseumInfoDO::getPlace, reqVO.getPlace())
//        );
//    }


    }