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

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bc.exam.core.api.dto.PagingReqDTO;
import com.bc.exam.core.utils.StringUtils;
import com.bc.exam.modules.liuyan.entity.TLiuyan;
import com.bc.exam.modules.liuyan.mapper.TLiuyanMapper;
import com.bc.exam.modules.liuyan.service.TLiuyanService;
import org.springframework.stereotype.Service;

/**
 * @Description 描述:留言信息表 服务实现类
 * @Author A贾宇婷034244310
 * @Date 20260615
 */
@Service
public class TLiuyanServiceImpl extends ServiceImpl<TLiuyanMapper, TLiuyan> implements TLiuyanService {

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

        //查询条件
        QueryWrapper<TLiuyan> wrapper = new QueryWrapper<>();
        TLiuyan params = reqDTO.getParams();
        if(!StringUtils.isBlank(params.getId())){
            wrapper.like(!StringUtils.isBlank(params.getId()),"id", params.getId());
        }
        if(!StringUtils.isBlank(params.getUserid())){
            wrapper.like(!StringUtils.isBlank(params.getUserid()),"userid", params.getUserid());
        }
        if(!StringUtils.isBlank(params.getItemname())){
            wrapper.like(!StringUtils.isBlank(params.getItemname()),"itemname", params.getItemname());
        }
        if(!StringUtils.isBlank(params.getText())){
            wrapper.like(!StringUtils.isBlank(params.getText()),"text", params.getText());
        }
        if(null!=params.getCreateTime()){
            wrapper.apply("create_time >= {0} ",params.getCreateTime());
        }
        if(null!=params.getUpdateTime()){
            wrapper.apply("create_time <= {0} ",params.getUpdateTime());
        }

        //获得数据
        IPage<TLiuyan> page = this.page(query, wrapper);
        //转换结果
        IPage<TLiuyan> pageData = JSON.parseObject(JSON.toJSONString(page), new TypeReference<Page<TLiuyan>>(){});

        return pageData;
    }
}
