package com.community.huiju.service.impl;

import com.community.commom.mode.ResponseBean;
import com.community.huiju.dao.MqMessageMapper;
import com.community.huiju.service.IMqMessageService;
import com.google.common.collect.Lists;
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;

/**
 * 订阅事件
 * @author weiximei
 */
@Service("iMqMessageService")
public class MqMessageService implements IMqMessageService {

    @Autowired
    private MqMessageMapper mqMessageMapper;

    @Override
    public ResponseBean selectOpenDoorCount() {
        ResponseBean responseBean = new ResponseBean();

        Map<String,Object> communityMap = Maps.newHashMap();
        Integer result = mqMessageMapper.selectCommunityOpenDoorCount();
        communityMap.put("message","小区开门次数");
        communityMap.put("count",result);

        // 刷卡开门次数
        Integer brushCardUnitsOpenDoorCount = mqMessageMapper.selectUnitsOpenDoorCount(983299);
        // 刷脸开门次数
        Integer brushFaceUunitsOpenDoorCount = mqMessageMapper.selectUnitsOpenDoorCount(983309);

        Integer openCount = brushCardUnitsOpenDoorCount + brushFaceUunitsOpenDoorCount;

        Map<String,Object> uunitsMap = Maps.newHashMap();
        uunitsMap.put("message","单元门开门次数");
        uunitsMap.put("count",openCount);

        List<Map<String,Object>> mapList = Lists.newArrayList();
        mapList.add(communityMap);
        mapList.add(uunitsMap);

        responseBean.addSuccess(mapList);
        return responseBean;
    }
    
    /**
     * 是否需要返回数据
     *
     * @return
     */
    @Override
    public String getConnectionByName() {
        return mqMessageMapper.getConnectionByName();
    }
    
    /**
     * 更新长连接的状态
     *
     * @return
     */
    @Override
    public int updateConnectionByName() {
        return mqMessageMapper.updateConnectionByName();
    }
}
