package com.gxwebsoft.hjm.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.hjm.mapper.HjmFenceMapper;
import com.gxwebsoft.hjm.service.HjmFenceService;
import com.gxwebsoft.hjm.entity.HjmFence;
import com.gxwebsoft.hjm.param.HjmFenceParam;
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-06-03 02:08:03
 */
@Service
public class HjmFenceServiceImpl extends ServiceImpl<HjmFenceMapper, HjmFence> implements HjmFenceService {

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

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

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

}
