package com.community.huiju.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.beust.jcommander.internal.Maps;
import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.common.hk.HKOpenApi;
import com.community.huiju.service.IVisualIntercomService;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 可视对讲的业务实现
 * @author weiximei
 */
@Service
public class VisualIntercomServiceImpl implements IVisualIntercomService {


    @Override
    public ResponseBean syncControl(UserElement userElement) {
        ResponseBean responseBean = new ResponseBean();

        // TODO 这里应该根据 小区期楼栋号查询出这个楼栋下面的门口机, 然后发送开门

        Map<String,Object> parMap = Maps.newHashMap();
        // TODO 只有一个设备, 临时固定的编号
        parMap.put("longNums", "10010100000");
        String data = HKOpenApi.syncControl(parMap);
        JSONObject jsonObject = JSONObject.parseObject(data);
        int errorCode = jsonObject.getInteger("errorCode");
        if (errorCode == 0) {
            responseBean.addSuccess("操作成功!");
            return responseBean;
        }
        responseBean.addError("操作失败!");
        return responseBean;
    }
}
