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.InspectionMapper;
import com.tuoheng.model.entity.Inspection;
import com.tuoheng.model.entity.InspectionFile;
import com.tuoheng.model.query.InformationQuery;
import com.tuoheng.service.information.InspectionService;
import com.tuoheng.until.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 小影
 * @description 针对表【t_inspection】的数据库操作Service实现
 * @createDate 2023-04-24 09:00:07
 */
@Service
public class InspectionServiceImpl extends ServiceImpl<InspectionMapper, Inspection>
        implements InspectionService {

    @Autowired
    private InspectionMapper inspectionMapper;


    /**
     * 查询任务列表
     *
     * @param query
     * @return
     */
    @Override
    public JsonResult index(InformationQuery query) {

        //分页校验
        query.checkParam();
        //分页
        IPage<Inspection> page = new Page <>(query.getPage(), query.getLimit());

        IPage<Inspection> pageDate = inspectionMapper.selectPage(page, Wrappers.<Inspection>lambdaQuery()
                .like(ObjectUtil.isNotEmpty(query.getName()), Inspection::getName, query.getName())
                .eq(ObjectUtil.isNotNull(query.getInspectionType()), Inspection::getInspectionType, query.getInspectionType())
                .eq(ObjectUtil.isNotEmpty(query.getClientId()), Inspection::getClientId, query.getClientId())
                .eq(Inspection::getMark, MarkTypeEnum.VALID.getCode())
                .orderByDesc(Inspection::getCreateTime));

        return JsonResult.success(pageDate);
    }
}




