package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.ShopCommunityMapper;
import com.gxwebsoft.shop.service.ShopCommunityService;
import com.gxwebsoft.shop.entity.ShopCommunity;
import com.gxwebsoft.shop.param.ShopCommunityParam;
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 2026-01-29 20:48:32
 */
@Service
public class ShopCommunityServiceImpl extends ServiceImpl<ShopCommunityMapper, ShopCommunity> implements ShopCommunityService {

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

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

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

}
