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.OrderRouteDetailMapper;
import com.njzscloud.supervisory.route.pojo.OrderRouteDetailEntity;
import com.njzscloud.supervisory.route.service.OrderRouteDetailService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 订单路线详情管理
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class OrderRouteDetailServiceImpl extends ServiceImpl<OrderRouteDetailMapper, OrderRouteDetailEntity> implements OrderRouteDetailService {

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

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

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

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

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

}

