package org.flume.alarm.resp; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.flume.alarm.base.AbstractResponse; import org.flume.alarm.base.DeviceTypeEnum; import org.flume.alarm.manager.BoxMonitorManager; import org.flume.alarm.manager.DeviceConfigManager; import org.flume.alarm.manager.ProcessManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; import java.io.IOException; /** * Created by lenovo on 2018/1/9. */ public class LampHouseResponse extends AbstractResponse { private final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); private static final String[] mType = {"Data", "Event", "SetResponse", "GetResponse"}; private static final String[] bType = {"LamphouseConfigSuccess", "LamphouseConfigFail"}; @Override public void process(String content) { ClassPathXmlApplicationContext ac = this.getAc(); BoxMonitorManager boxMonitorManager = ac.getBean(BoxMonitorManager.class); ProcessManager processManager = ac.getBean(ProcessManager.class); DeviceConfigManager deviceConfigManager = ac.getBean(DeviceConfigManager.class); JSONObject json = JSONObject.fromObject(content); String devCode = json.get("devCode").toString(); logger.info("--------RECEIVE:设备编号:" + devCode + ",上传数据:" + json.toString() + "-------"); JSONObject jsonObject = (JSONObject) json.get("mBody"); if (mType[0].equals(json.get("mType")) || mType[3].equals(json.get("mType"))) {//存储上报数据 JSONArray jsonArray = (JSONArray) jsonObject.get("datas"); boxMonitorManager.saveBoxMoitorData(devCode, jsonArray); } else if (mType[1].equals(json.get("mType"))) {//存储报警事件 try { processManager.saveLampRecord(json); } catch (IOException e) { e.printStackTrace(); logger.error("--------ERROR:设备编号:" + devCode + ",存储报警数据:" + json.toString() + "失败-------"); } } else if (mType[2].equals(json.get("mType"))) {//更新下发参数状态 try { if (DeviceTypeEnum.Lamphouse.name().equals(json.get("devType"))) { if (bType[0].equals(jsonObject.get("bType"))) { deviceConfigManager.updateStatus(devCode); } } } catch (Exception e) { e.printStackTrace(); logger.error("--------ERROR:设备地址:" + devCode + ",更新参数下发状态失败-------"); } } } }