package com.bc.exam.modules.tjhxxb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bc.exam.core.api.dto.PagingReqDTO;
import com.bc.exam.core.utils.StringUtils;
import com.bc.exam.modules.tjhxxb.entity.TJhxxb;
import com.bc.exam.modules.tjhxxb.mapper.TJhxxbMapper;
import com.bc.exam.modules.tjhxxb.service.TJhxxbService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @Description 描述:借还信息表实现
 * @Author A贾宇婷034244310
 * @Date 20260615
 */
@Service
public class TJhxxbServiceImpl extends ServiceImpl<TJhxxbMapper, TJhxxb> implements TJhxxbService {

    @Override
    public IPage<TJhxxb> paging(PagingReqDTO<TJhxxb> reqDTO) {
        //创建分页对象
        Page<TJhxxb> query = new Page<>(reqDTO.getCurrent(), reqDTO.getSize());

        //查询条件
        QueryWrapper<TJhxxb> wrapper = new QueryWrapper<>();

        TJhxxb params = reqDTO.getParams();
        if(!StringUtils.isBlank(params.getId())){
            wrapper.eq("a.id", params.getId());
        }
        if(!StringUtils.isBlank(params.getState())){
            wrapper.eq("a.state", params.getState());
        }
        wrapper.eq("a.user_id", reqDTO.getUserId());

        wrapper.like(!StringUtils.isBlank(params.getIsbn()),"b.isbn", params.getIsbn());
        wrapper.like(!StringUtils.isBlank(params.getBName()),"b.b_name", params.getBName());
        wrapper.like(!StringUtils.isBlank(params.getBAuthor()),"b.b_author", params.getBAuthor());
        wrapper.like(!StringUtils.isBlank(params.getBType()),"b.b_type", params.getBType());

        //获得数据
        IPage<TJhxxb> page = baseMapper.paging(query, wrapper);
        return page;
    }
}
