package com.tuoheng.service.information.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tuoheng.enums.MarkTypeEnum;
import com.tuoheng.mapper.information.ReportMapper;
import com.tuoheng.model.entity.Report;
import com.tuoheng.model.query.ReportQuery;
import com.tuoheng.service.information.ReportService;
import com.tuoheng.until.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 小影
 * @description 针对表【t_report(巡检报告表)】的数据库操作Service实现
 * @createDate 2023-04-24 09:14:07
 */
@Service
public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report>
        implements ReportService {

    @Autowired
    private ReportMapper reportMapper;


    /**
     * 查询报告列表
     *
     * @param query
     * @return
     */
    @Override
    public JsonResult index(ReportQuery query) {
        //分页校验
        query.checkParam();
        //分页
        IPage<Report> page = new Page<>(query.getPage(), query.getLimit());

        IPage<Report> pageDate = reportMapper.selectPage(page, Wrappers.<Report>lambdaQuery()
                .like(ObjectUtil.isNotEmpty(query.getReportNo()), Report::getReportNo, query.getReportNo())
                .eq(ObjectUtil.isNotEmpty(query.getClientId()), Report::getClientId, query.getClientId())
                .eq(Report::getMark, MarkTypeEnum.VALID.getCode())
                .orderByDesc(Report::getCreateTime));
        return JsonResult.success(pageDate);
    }
}




