package com.njzscloud.supervisory.route.service.impl;

import cn.hutool.core.util.StrUtil;
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.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.supervisory.route.mapper.RouteDetailMapper;
import com.njzscloud.supervisory.route.pojo.RouteDetailEntity;
import com.njzscloud.supervisory.route.service.RouteDetailService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 路线详情管理
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class RouteDetailServiceImpl extends ServiceImpl<RouteDetailMapper, RouteDetailEntity> implements RouteDetailService {

    /**
     * 新增
     */
    @Override
    public void add(RouteDetailEntity detailEntity) {
        this.save(detailEntity);
    }

    /**
     * 修改
     */
    @Override
    public void modify(RouteDetailEntity detailEntity) {
        this.updateById(detailEntity);
    }

    /**
     * 删除
     */
    @Override
    public void del(List<Long> ids) {
        this.removeBatchByIds(ids);
    }

    /**
     * 详情
     */
    @Override
    public RouteDetailEntity detail(Long id) {
        return this.getById(id);
    }

    /**
     * 分页查询
     */
    @Override
    public PageResult<RouteDetailEntity> paging(PageParam pageParam, RouteDetailEntity detailEntity) {
        Page<RouteDetailEntity> page = this.page(pageParam.toPage(), Wrappers.<RouteDetailEntity>lambdaQuery()
                .eq(StrUtil.isNotBlank(detailEntity.getName()), RouteDetailEntity::getName, detailEntity.getName())
                .eq(RouteDetailEntity::getDeleted, Boolean.FALSE)
                .orderByDesc(RouteDetailEntity::getCreateTime));
        return PageResult.of(page);
    }

}

