package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.OrderAddressMapper;
import com.gxwebsoft.shop.service.OrderAddressService;
import com.gxwebsoft.shop.entity.OrderAddress;
import com.gxwebsoft.shop.param.OrderAddressParam;
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 2022-12-02 21:21:10
 */
@Service
public class OrderAddressServiceImpl extends ServiceImpl<OrderAddressMapper, OrderAddress> implements OrderAddressService {

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

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

    @Override
    public OrderAddress getByIdRel(Integer orderAddressId) {
        OrderAddressParam param = new OrderAddressParam();
        param.setOrderAddressId(orderAddressId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
