package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.SelfTakeMapper;
import com.gxwebsoft.shop.service.SelfTakeService;
import com.gxwebsoft.shop.entity.SelfTake;
import com.gxwebsoft.shop.param.SelfTakeParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 自提点Service实现
 *
 * @author 科技小王子
 * @since 2025-12-03 14:22:38
 */
@Service
public class SelfTakeServiceImpl extends ServiceImpl<SelfTakeMapper, SelfTake> implements SelfTakeService {

    @Override
    public PageResult<SelfTake> pageRel(SelfTakeParam param) {
        PageParam<SelfTake, SelfTakeParam> page = new PageParam<>(param);
        page.setDefaultOrder("create_time desc");
        List<SelfTake> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<SelfTake> listRel(SelfTakeParam param) {
        List<SelfTake> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<SelfTake, SelfTakeParam> page = new PageParam<>();
        page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public SelfTake getByIdRel(Integer id) {
        SelfTakeParam param = new SelfTakeParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
