package com.community.huiju.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.community.huiju.common.base.ResponseBean;
import com.community.huiju.model.TpEquipment;
import com.community.huiju.dao.TpEquipmentMapper;
import com.community.huiju.service.ITpEquipmentService;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 设备表 服务实现类
 * </p>
 *
 * @author jobob
 * @since 2019-05-16
 */
@Service
public class TpEquipmentServiceImpl extends ServiceImpl<TpEquipmentMapper, TpEquipment> implements ITpEquipmentService {

    @Autowired
    private TpEquipmentMapper tpEquipmentMapper;

    @Override
    public ResponseBean getMonitoringByCommunityId(Integer communityId, Integer pageNum, Integer pageSize) {
        ResponseBean responseBean = new ResponseBean();
        IPage<TpEquipment> page = new Page<>();
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        IPage<TpEquipment> equipmentIPage = tpEquipmentMapper.selectMonitoringByCommunityId(page,communityId);

        Map<String, Object> map = Maps.newHashMap();
        map.put("pageNum", equipmentIPage.getCurrent());
        map.put("pageSize", equipmentIPage.getSize());
        map.put("total", equipmentIPage.getTotal());
        map.put("list", equipmentIPage.getRecords());
        responseBean.addSuccess(map);
        return responseBean;
    }
}
