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

import ch.qos.logback.core.status.Status;
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.museummodel.vo.MuseummodelPageReqVO;
import cn.iocoder.yudao.module.museum.dal.database.museummodel.MuseummodelDO;
import cn.iocoder.yudao.module.museum.dal.database.museummodel.MuseummodelDetailDO;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface MuseummodelMapper extends BaseMapperX<MuseummodelDO> {

    @Update("UPDATE museum_model SET sample_type=#{sampleType}, place=#{place} WHERE id =#{id}")
    void updateMuseumModel(MuseummodelDO museumModelDO);

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

    @Select("SELECT * FROM museum_model WHERE id = #{id} AND deleted =0 ")
    MuseummodelDO selectMuseumModelById(@Param("id") Integer id);

    /*   PageResult<MuseummodelDO> selectPage(MuseummodelPageReqVO pageReqVO);
   }
   */
    //分页查询
    default PageResult<MuseummodelDO> selectPage(MuseummodelPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MuseummodelDO>()
                .likeIfPresent(MuseummodelDO::getSpecimenName, reqVO.getSpecimenName())// 如果 SpecimenName 不为空，则进行 like 查询
                .likeIfPresent(MuseummodelDO::getSpecimenType, reqVO.getSpecimenType())
                .likeIfPresent(MuseummodelDO::getModelWay, reqVO.getModelWay())
                .likeIfPresent(MuseummodelDO::getRemark, reqVO.getRemark())
                .eqIfPresent(MuseummodelDO::getSpecimenNumber, reqVO.getSpecimenNumber()) // 如果 SpecimenNumber 不为空，则进行 = 查询
                .betweenIfPresent(MuseummodelDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) // 如果 create 不为空，则进行 between 查询
                .orderByDesc(MuseummodelDO::getId)); // 按照 id 倒序
    }

    //联表查询
    default list<MuseummodelDetailDO> selectListByStatusAndDeptName(Integer status, String deptName) {
        return SelectJoinList(MuseummodelDO.class, new MPJLambdaWrapper<MuseummodelDO>()
                .selectAll(MuseummodelDO.class)// 查询 List
                .selectAs(DeptDO::getName, MuseummodelDetailDO::getDeptName)// 查询 system 表的 all 所有字段
                .eq(MuseummodelDO::getSpecimenNumber,Number)// 查询  表的 name 字段，使用  字段“部分”返回
                .leftJoin(DeptDO.class, DeptDO::getId, MuseummodelDO::getId)// 联表 WHERE system_users.dept_id = system_dept.id
                .eq(DeptDO.getName, deptName) // WHERE system_dept.name = ? 【用户状态为开启】
        );


    }
}





