diff --git a/cloud/mypulsar/pom.xml b/cloud/mypulsar/pom.xml index 6c4d288..33ba41b 100644 --- a/cloud/mypulsar/pom.xml +++ b/cloud/mypulsar/pom.xml @@ -41,7 +41,11 @@ ${project.basedir}/libs/sqljdbc4-4.2-6.jar - + + dom4j + dom4j + 1.6.1 + io.springfox springfox-swagger2 @@ -140,13 +144,13 @@ true ZIP - - - - nothing - nothing - - + + + + + + + diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/MyRunnerableInt.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/MyRunnerableInt.java index 43bdbea..798cf11 100644 --- a/cloud/mypulsar/src/main/java/com/example/mypulsar/MyRunnerableInt.java +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/MyRunnerableInt.java @@ -1,10 +1,7 @@ package com.example.mypulsar; import com.alibaba.fastjson.JSON; -import com.example.mypulsar.bean.CalDevContrl; -import com.example.mypulsar.bean.DeviceBean; -import com.example.mypulsar.bean.TuYaReceiverBean; -import com.example.mypulsar.bean.TuYaReceiverBeanStatus; +import com.example.mypulsar.bean.*; import com.example.mypulsar.dao.DeviceDao; import com.example.mypulsar.message.MessageVO; import com.example.mypulsar.mq.AESBase64Utils; @@ -14,6 +11,7 @@ import com.example.mypulsar.task.SchduledTasks; import com.example.mypulsar.utils.ControlUtils; import com.example.mypulsar.utils.PulsarConsumerPoolFactory; import com.example.mypulsar.utils.ThreadPoolFactory; +import lombok.extern.slf4j.Slf4j; import org.apache.pulsar.client.api.Consumer; import org.apache.pulsar.client.impl.TopicMessageIdImpl; import org.slf4j.Logger; @@ -22,14 +20,17 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; import org.springframework.web.client.RestTemplate; import sun.rmi.runtime.Log; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.function.BiConsumer; +@Slf4j @Component public class MyRunnerableInt implements ApplicationRunner { @@ -63,7 +64,6 @@ public class MyRunnerableInt implements ApplicationRunner { * 第二种方式 */ private void initMqConsumer() { - MqConsumer mqConsumer = MqConsumer.build().serviceUrl(url).accessId(accessId).accessKey(accessKey) .maxRedeliverCount(3).messageListener(message -> { //消息内容 @@ -71,6 +71,7 @@ public class MyRunnerableInt implements ApplicationRunner { MessageVO vo = JSON.parseObject(jsonMessage, MessageVO.class); String data = AESBase64Utils.decrypt(vo.getData(), accessKey.substring(8, 24)); TuYaReceiverBean tuYaReceiverBean = JSON.parseObject(data, TuYaReceiverBean.class); + log.info("接收消息,消息内容:"+ JSON.toJSONString(tuYaReceiverBean)); //处理数据上报 detealData(tuYaReceiverBean); } @@ -79,8 +80,7 @@ public class MyRunnerableInt implements ApplicationRunner { try { mqConsumer.start(); } catch (Exception e) { - logger.error("start error:" + e.toString()); - e.printStackTrace(); + logger.error("start error:",e); } } @@ -90,7 +90,6 @@ public class MyRunnerableInt implements ApplicationRunner { * @param tuYaReceiverBean */ private void detealData(TuYaReceiverBean tuYaReceiverBean) { -// System.out.println("tuYaReceiverBean:" + tuYaReceiverBean.toString()); //涂鸦全局唯一ID String dataId = tuYaReceiverBean.getDataId(); //其他事件 @@ -106,42 +105,41 @@ public class MyRunnerableInt implements ApplicationRunner { deviceBean.setBizCode(bizCode); deviceBean.setDevId(devId); deviceBean.setProductKey(productKey); - - if (bizCode == null) {//数据上报事件 + //温度、人感、湿度数据上报事件 + if (bizCode == null) { deviceBean.setBizCode(""); + //在线状态:1在线0离线 deviceBean.setDev_status(1); + //设备上报事件:code:时间类型; 格式:"status":[{"code":"pir","t":1612283849564,"value":"pir"}] List status = tuYaReceiverBean.getStatus(); for (TuYaReceiverBeanStatus statue : status) { //事件上报处理 - initStatue(statue, devId, productKey, dataId, deviceBean); + initStatue(statue, deviceBean); } } else {//其他事件上报 deviceBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH::mm:ss").format(new Date())); + String name = deviceDao.selectAttendance(devId); switch (bizCode) { case "offline"://设备掉线 - log("设备掉线:" + devId); + log.info("设备: {},已掉线",name); deviceBean.setDev_type(1); deviceBean.setDev_status(0); updateDevStatus(deviceBean); updateStatus(devId, "0"); break; case "online"://设备上线 - log("设备上线:" + devId); + log.info("设备: {},已上线",name); deviceBean.setDev_status(1); deviceBean.setDev_type(2); updateDevStatus(deviceBean); break; case "nameUpdate"://设备名称修改 - break; case "dpNameUpdate"://功能点修改 - break; case "bindUser"://绑定用户 - break; case "delete"://删除设备 - break; } } @@ -149,7 +147,6 @@ public class MyRunnerableInt implements ApplicationRunner { } private void updateStatus(String devId, String isConnection) { - // String clintId = deviceDao.selectAttendance(devId); // if (clintId.equals(devId)) { deviceDao.updateStatus(devId, isConnection, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); @@ -160,7 +157,6 @@ public class MyRunnerableInt implements ApplicationRunner { } private void updateDevStatus(DeviceBean deviceBean) { -// System.out.println("插入数据:" + deviceBean.toString()); deviceBean.setDpId(""); deviceBean.setName(""); deviceBean.setUid(""); @@ -169,6 +165,7 @@ public class MyRunnerableInt implements ApplicationRunner { if (deviceBean.getDataId() == null) deviceBean.setDataId(""); if (deviceBean.getCode() == null) deviceBean.setCode(""); if (deviceBean.getProductKey() == null) deviceBean.setProductKey(""); + log("设备上线,更新历史记录: "+JSON.toJSONString(deviceBean)); int index = deviceDao.addDevice(deviceBean.getDataId(), deviceBean.getDevId(), deviceBean.getProductKey(), deviceBean.getCode(), deviceBean.getValue() , deviceBean.getBizCode(), deviceBean.getTime(), deviceBean.getName(), deviceBean.getDpId(), deviceBean.getUid(), deviceBean.getDev_status(), deviceBean.getDev_type()); updateStatus(deviceBean.getDevId(), "1"); @@ -178,43 +175,59 @@ public class MyRunnerableInt implements ApplicationRunner { * 数据上报事件处理 * * @param statue - * @param devId - * @param productKey - * @param dataId * @param deviceBean */ - private void initStatue(TuYaReceiverBeanStatus statue, String devId, String productKey, String dataId, DeviceBean deviceBean) { - String code = statue.getCode(); - deviceBean.setCode(code); - deviceBean.setProductKey(productKey); - deviceBean.setDataId(dataId); + private void initStatue(TuYaReceiverBeanStatus statue,DeviceBean deviceBean) { + //设备消息类型:1:掉线,2:上线,3:其他事件 deviceBean.setDev_type(3); + //事件时间 long t = statue.getT(); Date date = new Date(); date.setTime(t); deviceBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)); + //事件value值 String value = statue.getValue(); deviceBean.setValue(value); - -// System.out.println(devId+"-插入数据:" +value); + //事件类型:温度va_temperature、湿度va_humidity、人感pir + // 格式:"status":[{"code":"pir","t":1612283849564,"value":"pir"}],"status":[{"code":"va_temperature","t":1612283809697,"value":"1879"}] + String code = statue.getCode(); + deviceBean.setCode(code); switch (code) { case "va_temperature"://温度 deviceBean.setValue(Integer.parseInt(value) / 100 + ""); - calOpenOrCloseDevWithtemper(deviceBean);//计算开启或关闭设备 - log("温度:" + value); + //计算开启或关闭设备 +// calOpenOrCloseDevWithtemper(deviceBean); + log.info("温度:" + deviceBean.getValue()); + //存储 对应设备对应的温度记录 + ControlUtils.tempDevices.put(deviceBean.getDevId(),Integer.valueOf(deviceBean.getValue())); break; case "va_humidity"://湿度 deviceBean.setValue(Integer.parseInt(value) / 100 + ""); - log("湿度:" + value); + log.info("湿度:" + deviceBean.getValue()); + break; + case "pir": + //人体感应 + log.info("人体感应:" + value); + if(value.equals("pir")){ + deviceBean.setValue("有人"); + }else{ + deviceBean.setValue("无人"); + } + setClintTime(deviceBean.getDevId()); + try { + Thread.sleep(1000); + //根据场地是否有人控制空调设备 + calOpenOrCloseDevWithPir(deviceBean); + } catch (InterruptedException e) { + e.printStackTrace(); + } break; case "temper_alarm"://防拆报警 - break; case "battery_percentage"://电池电量百分比 - log("电池电量百分比:" + value); + log.info("电池电量百分比:" + value); break; case "battery_value"://电池电量值 - break; case "battery"://门磁电池电量值 log("电池电量值:" + value); @@ -230,48 +243,9 @@ public class MyRunnerableInt implements ApplicationRunner { value = (value.equals("true") ? "开门" : "关门"); log("开关状态:" + (value.equals("true") ? "开门" : "关门")); break; - case "va_battery"://电池电量值 - - break; - case "switch_1"://开关1 - - break; - case "switch_2"://开关2 - - break; - case "switch_3"://开关3 - - break; - case "switch_4"://开关4 - - break; - case "switch_5"://开关5 - - break; - case "switch_6"://开关6 - - break; - case "study_code": - - break; - case "control": - - break; - case "pir"://人体感应 - log("人体感应:" + value); - value = (value.equals("pir") ? "有人" : "无人"); - - deviceBean.setValue(value); - try { - Thread.sleep(1000); - calOpenOrCloseDevWithPir(deviceBean); - } catch (InterruptedException e) { - e.printStackTrace(); - } - break; case "cur_voltage"://当前电压 // value = Integer.parseInt(value) / 10 + "V"; - log(devId + " 当前电压:" + value); + log(deviceBean.getDevId() + " 当前电压:" + value); break; case "cur_power"://当前功率 // value = value.equals("0")?"0":Integer.parseInt(value) / 10 + "W"; @@ -282,7 +256,6 @@ public class MyRunnerableInt implements ApplicationRunner { // log(devId + " 当前电流:" + Integer.parseInt(value) / 10 + "A"); break; case "router_mgr"://网关路由 - break; } updateDevStatus(deviceBean); @@ -294,19 +267,71 @@ public class MyRunnerableInt implements ApplicationRunner { * @param deviceBean */ private void calOpenOrCloseDevWithPir(DeviceBean deviceBean) { - +// if (deviceBean.getValue().equals("有人")){ +// deviceBean.setValue("1"); +// } else{ +// deviceBean.setValue("0"); +// } + //获取人感设备控制 List calDevContrls = deviceDao.getCalDevContrlWidthDevId(deviceBean.getDevId()); -// System.out.println("calOpenOrCloseDevWithPir:"+calDevContrls.toString()); - if (null != calDevContrls && calDevContrls.size() > 0) { - if (deviceBean.getValue().equals("有人")) deviceBean.setValue("1"); - else deviceBean.setValue("0"); - - ControlUtils.getInstance(deviceDao).conTemper(calDevContrls, deviceBean); + if (CollectionUtils.isEmpty(calDevContrls)) { + log.info("未关联人感控制设备, 设备ID: "+ deviceBean.getDevId()); + return; } + ControlUtils.getInstance(deviceDao).conTemper(calDevContrls, deviceBean); + } + /** + * 设置更新上报时间 + * @param clintId + */ + private void setClintTime(String clintId){ + List calDevContrls = deviceDao.getCalDevContrlWidthDevId(clintId); + if(!CollectionUtils.isEmpty(calDevContrls)){ + CalDevContrl calDevContrl = calDevContrls.get(0); + String assDevice = calDevContrl.getAssDevice(); + //红外遥控器 + CalDevBeContrl hwClint = getCalDevBeCon(assDevice); + if(hwClint==null) { + log.info("未查询到控制红外遥控器"); + return; + } + //红外遥控设备id + String conDevId = hwClint.getConDevId(); + SchduledTasks.closeDevMap.put(conDevId,new Date()); + } + } + + private CalDevBeContrl getCalDevBeCon(String assDevice) { + String[] assDeviceIds = assDevice.split(","); + List devBeContrlList = new ArrayList<>(); + for (int i = 0; i < assDeviceIds.length; i++) { + String deviceId = assDeviceIds[i]; + //获取温感设备 + List calDevContrl = deviceDao.getTempCalWitdDevid(deviceId); + if(!CollectionUtils.isEmpty(calDevContrl)){ + for (int j = 0; j < calDevContrl.size(); j++) { + //温感设备 + CalDevContrl calDevContrl1 = calDevContrl.get(j); + if (!calDevContrl1.getDevBeId().equals("0")) { + String[] calDevBeIdStr = calDevContrl1.getDevBeId().split(","); + if (calDevBeIdStr != null) { + for (int k = 0; k < calDevBeIdStr.length; k++) { + //红外设备 + CalDevBeContrl calDevBeContrl = deviceDao.getCalDevBeControl(calDevBeIdStr[k]); + devBeContrlList.add(calDevBeContrl); + } + } + } + } + } + } + if(devBeContrlList.size()>0){ + return devBeContrlList.get(0); + } + return null; } - /** * 根据温度变化控制设备 * diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/CloseClintBean.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/CloseClintBean.java new file mode 100644 index 0000000..ecd7215 --- /dev/null +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/bean/CloseClintBean.java @@ -0,0 +1,31 @@ +package com.example.mypulsar.bean; + +import java.util.Date; + +/** + * 关闭设备实体 + * @author xuquan + * @date 2021/2/26 10:10 + */ + +public class CloseClintBean { + + private Date startTime; + private String hasPerson; + + public String getHasPerson() { + return hasPerson; + } + + public void setHasPerson(String hasPerson) { + this.hasPerson = hasPerson; + } + + public Date getStartTime() { + return startTime; + } + + public void setStartTime(Date startTime) { + this.startTime = startTime; + } +} diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/dao/DeviceDao.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/dao/DeviceDao.java index c5feb61..07a37b1 100644 --- a/cloud/mypulsar/src/main/java/com/example/mypulsar/dao/DeviceDao.java +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/dao/DeviceDao.java @@ -30,7 +30,7 @@ public interface DeviceDao { int updateStatus(@Param("clint_id") String clint_id, @Param("isConnection") String isConnection, @Param("OnlineTime") String OnlineTime); - @Select("select clint_id from WL_Attendance where clint_id = #{clint_id}") + @Select("select top 1 name from WL_Attendance where clint_id = #{clint_id}") String selectAttendance(@Param("clint_id") String clint_id); @Select("select * from Iot_Device where devId = #{devId}") @@ -41,7 +41,7 @@ public interface DeviceDao { List getCalDevContrl(); - @Select("select * from CalDevContrl where Devid = #{Devid} and Status = 1") + @Select("select * from CalDevContrl where Devid = #{Devid} and ModelType =10 and Status = 1") List getCalDevContrlWidthDevId(@Param("Devid") String devId); @Select("select * from CalDevBeContrl where State = 1 and Id = #{Id}") diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/task/SchduledTasks.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/task/SchduledTasks.java index 2715ccd..2c6cb7d 100644 --- a/cloud/mypulsar/src/main/java/com/example/mypulsar/task/SchduledTasks.java +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/task/SchduledTasks.java @@ -7,19 +7,22 @@ import com.example.mypulsar.bean.Wl_LinkModeBean; import com.example.mypulsar.campusDao.CampusDao; import com.example.mypulsar.dao.DeviceDao; import com.example.mypulsar.utils.HttpUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.configurationprocessor.json.JSONArray; import org.springframework.boot.configurationprocessor.json.JSONException; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import java.io.*; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; +@Slf4j @Component public class SchduledTasks { @@ -29,122 +32,150 @@ public class SchduledTasks { @Autowired CampusDao campusDao; - private Logger logger = LoggerFactory.getLogger(SchduledTasks.class); - public static Map conDevMap = new HashMap<>();//存储被控制的设备 - private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + public static Map closeDevMap = new HashMap<>(); - SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("HH:mm"); - SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("HH:mm"); + private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private String closeModel = "{\"mode\":\"0\",\"power\":\"0\",\"remote_id\":\"%s\",\"remote_index\":\"11272\",\"temp\":\"26\",\"wind\":\"0\"}"; boolean isClose = false; + boolean outClose= false; @Scheduled(fixedRate = 60000) public void closeAttend() { - - logger.error("定时任务执行中......" + conDevMap.size()); - - //遍历已经开启的空调设备 - Iterator iterator = conDevMap.entrySet().iterator(); - - while (iterator.hasNext()) { - - - Map.Entry entry = (Map.Entry) iterator.next(); - String conBeDeviceId = (String) entry.getKey(); - - logger.error("在线设备:" + conBeDeviceId + "---在线时间:" + simpleDateFormat.format(entry.getValue())); - - Date date = (Date) entry.getValue(); - System.out.println("更新设备时间差值:" + ((new Date().getTime()) - date.getTime())); - if (((new Date().getTime()) - date.getTime()) > 10 * 60 * 1000) {//大于十分钟后关闭设备 - - String conValue = getRemoteId(deviceDao.getConBeValue(conBeDeviceId)); - String name = deviceDao.getWLName(conBeDeviceId); - HttpUtil.addAirCode(String.format(closeModel, conValue), conBeDeviceId, name); - conDevMap.remove(conBeDeviceId); + log.info(".......定时任务执行设备关闭.......,有在线遥控设备数量" + closeDevMap.size()); + Iterator> it = closeDevMap.entrySet().iterator(); + while(it.hasNext()) { + Map.Entry entry = it.next(); + String conBeDeviceId = entry.getKey(); + if(conDevMap.containsKey(conBeDeviceId) && conDevMap.get(conBeDeviceId)!=null){ + Date openTime = entry.getValue(); + log.info("在线设备:" + conBeDeviceId + "---在线时间:" + simpleDateFormat.format(entry.getValue())+"当前时间:"+ simpleDateFormat.format(new Date())); + //大于十分钟后关闭设备 + if(((new Date().getTime()) - openTime.getTime()) > 5 * 60 * 1000) { + String conValue = getRemoteId(deviceDao.getConBeValue(conBeDeviceId)); + String name = deviceDao.getWLName(conBeDeviceId); + log.info("开始执行关闭命令, remote_id: {}",conValue); + String response = HttpUtil.addAirCode(String.format(closeModel, conValue), conBeDeviceId, name); + try{ + // 将字符串转为XML + Document doc = DocumentHelper.parseText(response); + // 获取根节点 + Element rootElt = doc.getRootElement(); + // 拿到head节点下的子节点title值 + String title = rootElt.elementTextTrim("code"); + log.info("请求结果:" + title); + if(title.equals("200")){ + conDevMap.remove(conBeDeviceId); + } + } catch (DocumentException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } } - } + if (!outClose){ + initWlModeOut(); + } + log.info("关闭成功 :" + JSON.toJSONString(conDevMap)); + } - int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); - if (!isClose && hour < 23 && hour > 5) + @Scheduled(cron = "0 0/30 * * * ?") + public void closeAttendOut() { + int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); + if (!isClose && hour < 23 && hour > 5){ initWlMode(); - - - - /* int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); - - - System.out.println("关闭设备:" + hour); - - String inuserTime = deviceDao.getInuserTime(); - JSONArray jsonArray = JSON.parseArray(inuserTime); - - if (null==jsonArray)return; - if (jsonArray!=null&&jsonArray.size()==0)return; - JSONObject jsonObject = jsonArray.getJSONObject(0); - - String startTime = jsonObject.getString("StartTime"); - String endTime = jsonObject.getString("EndTime"); - Date startDate = null; - try { - startDate = simpleDateFormat1.parse(startTime); - } catch (ParseException e) { - e.printStackTrace(); } - Date endDate = null; - try { - endDate = simpleDateFormat1.parse(endTime); - } catch (ParseException e) { - e.printStackTrace(); - } - Date date = null; - try { - date = simpleDateFormat2.parse(new Date().getHours() + ":" + new Date().getMinutes()); - } catch (ParseException e) { - e.printStackTrace(); - } - - long starTime = startDate.getTime(); - long indexTime = date.getTime(); - long entTime = endDate.getTime()+ 10 * 60 * 1000;//延迟十分钟 - - if (!isClose) { + } - if (indexTime < starTime || indexTime >= entTime) { - closeAllDevice(); + /** + * 根据物联模板判断是否关闭 + */ + private void initWlModeOut() { + try { + isClose = true; + //获取有效的模板 + List wl_linkModes = deviceDao.getWL_LinkMode("1085"); + if (null != wl_linkModes) { + for (int i = 0; i < wl_linkModes.size(); i++) { + Wl_LinkModeBean wl_linkModeBean = wl_linkModes.get(i); + String field = wl_linkModeBean.getField();//场地id + String[] fields = field.split(",");//所有场地 + String weekTime = wl_linkModeBean.getWeekTime();//时间 + try { + JSONArray jsonArray = new JSONArray(weekTime); + if (null != jsonArray) { + for (int j = 0; j < jsonArray.length(); j++) { + org.springframework.boot.configurationprocessor.json.JSONObject jsonObject = jsonArray.getJSONObject(j); + String weekStr = jsonObject.getString("Week"); + String[] weeks = weekStr.split(","); + String endTime = jsonObject.getString("EndTime"); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm"); + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("HH:mm:ss"); + int indexWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1; + for (int k = 0; k < weeks.length; k++) { + int week = Integer.parseInt(weeks[k]); + if (week == indexWeek) { + try { + Date endDate = simpleDateFormat.parse(endTime); + Date date = simpleDateFormat1.parse(new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds()); + Date endDate2 = getDateByTime(1,endDate); + long indexTime = date.getTime(); + long entTime = endDate.getTime(); + long entTime2 = endDate2.getTime(); + //当前时间等于结束时间触发一次指令 + if (indexTime > entTime && indexTime < entTime2) { + //关闭所有设备 + for (int l = 0; l < fields.length; l++) { + String fieldId = fields[l]; + //获取红外遥控器 + List clintIds = deviceDao.getHWAttsWithRoomId(fieldId); + closeAllDevice(clintIds); + } + } + } catch (ParseException e) { + log.info("关闭设备异常: ",e); + } + } + } + } + } + } catch (JSONException e) { + log.info("关闭设备异常: ",e); + } + } + } else { + //获取红外遥控器 + List clintIds = deviceDao.getHWIds(); + closeAllDevice(clintIds); } - - + } catch (Exception e) { + log.info("关闭设备异常: ",e); } + isClose = false;//保证条件一直在执行 + } - if (indexTime < entTime && indexTime >= starTime) { - isClose = false; - }*/ - - + public static Date getDateByTime(int length, Date date){ + Calendar cal = Calendar.getInstance(); + cal.setTime(date);//设置起时间 + cal.add(Calendar.MINUTE,length);//把日期往后增加 + return cal.getTime(); } /** * 根据物联模板判断是否关闭 */ private void initWlMode() { - try { - - isClose = true; - //获取有效的模板 List wl_linkModes = deviceDao.getWL_LinkMode("1085"); - if (null != wl_linkModes) { - for (int i = 0; i < wl_linkModes.size(); i++) { Wl_LinkModeBean wl_linkModeBean = wl_linkModes.get(i); @@ -188,10 +219,8 @@ public class SchduledTasks { long entTime = endDate.getTime(); if (indexTime < starTime || indexTime > entTime) {//在时间之外 - //关闭所有设备 for (int l = 0; l < fields.length; l++) { - String fieldId = fields[l]; //获取红外遥控器 List clintIds = deviceDao.getHWAttsWithRoomId(fieldId); @@ -199,21 +228,17 @@ public class SchduledTasks { } } - } catch (ParseException e) { - e.printStackTrace(); + log.info("关闭设备异常: ",e); } } } - } } - } catch (JSONException e) { - e.printStackTrace(); + log.info("关闭设备异常: ",e); } - } } else { //获取红外遥控器 @@ -221,26 +246,34 @@ public class SchduledTasks { closeAllDevice(clintIds); } } catch (Exception e) { - e.printStackTrace(); - logger.error(e.toString()); + log.info("关闭设备异常: ",e); } isClose = false;//保证条件一直在执行 - } private void closeAllDevice(List deviceIds) { - -// isClose = true; -// System.out.println("关闭设备" + deviceIds.toString()); for (int i = 0; i < deviceIds.size(); i++) { String deviceId = deviceIds.get(i).getClint_id(); String conValue = getRemoteId(deviceDao.getConBeValue(deviceId)); String devName = deviceIds.get(i).getName(); - - HttpUtil.addAirCode(String.format(closeModel, conValue), deviceId, devName); + String response = HttpUtil.addAirCode(String.format(closeModel, conValue), deviceId, devName); + try{ + // 将字符串转为XML + Document doc = DocumentHelper.parseText(response); + // 获取根节点 + Element rootElt = doc.getRootElement(); + // 拿到head节点下的子节点title值 + String title = rootElt.elementTextTrim("code"); + log.info("请求结果:" + title); + if(title.equals("200")){ + conDevMap.remove(deviceId); + } + } catch (DocumentException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } } - - } /** @@ -249,7 +282,6 @@ public class SchduledTasks { * @param conValue */ private String getRemoteId(String conValue) { - try { // System.out.println("conValue:" + conValue); JSONObject jsonObject = JSON.parseObject(conValue); diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/ControlUtils.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/ControlUtils.java index 958994a..e114e8a 100644 --- a/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/ControlUtils.java +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/ControlUtils.java @@ -1,18 +1,26 @@ package com.example.mypulsar.utils; -import com.example.mypulsar.bean.*; +import com.alibaba.fastjson.JSON; +import com.example.mypulsar.bean.CalDevBeContrl; +import com.example.mypulsar.bean.CalDevContrl; +import com.example.mypulsar.bean.CloseClintBean; +import com.example.mypulsar.bean.DeviceBean; import com.example.mypulsar.dao.DeviceDao; import com.example.mypulsar.task.SchduledTasks; -import org.apache.pulsar.shade.com.google.gson.Gson; +import io.micrometer.core.instrument.util.JsonUtils; +import lombok.extern.slf4j.Slf4j; import org.springframework.boot.configurationprocessor.json.JSONArray; import org.springframework.boot.configurationprocessor.json.JSONException; import org.springframework.boot.configurationprocessor.json.JSONObject; +import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; +import springfox.documentation.spring.web.json.Json; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; +@Slf4j public class ControlUtils { private Set deviceSet = new HashSet<>();//保存符合条件的传感器 @@ -26,6 +34,11 @@ public class ControlUtils { */ public static Map tempDevices = new HashMap<>(); + /** + * 存储人感 + */ + public static Map umanDevices = new HashMap<>(); + public static ControlUtils getInstance(DeviceDao deviceDao) { if (null == controlUtils) { synchronized (ControlUtils.class) { @@ -36,10 +49,7 @@ public class ControlUtils { } public ControlUtils(DeviceDao deviceDao) { - this.deviceDao = deviceDao; - - } /** @@ -49,74 +59,57 @@ public class ControlUtils { * @param deviceBean 温度传感器对象 */ public void conTemper(List calDevContrls, DeviceBean deviceBean) { -// System.out.println("传感器感应设备:deviceBean:" + deviceBean.toString()); - FileUtils.getInstance().writeLogs(deviceBean.toString() + "\r\n" + calDevContrls.toString(), FileUtils.mypulsar); - for (CalDevContrl cal : - calDevContrls) { - - String inUseTime = cal.getInUserTime();//联动的时间范围,[{"Week":"5","StartTime":"14:02","EndTime":"14:06"}] - - if (inUseTime == null) break; -// System.out.println("inUseTime:"+inUseTime); + for (CalDevContrl cal : calDevContrls) { try { + //联动的时间范围,[{"Week":"5","StartTime":"14:02","EndTime":"14:06"}] + if(StringUtils.isEmpty(cal.getInUserTime())){ + continue; + } + String inUseTime =cal.getInUserTime(); JSONArray jsonArray = new JSONArray(inUseTime); - FileUtils.getInstance().writeLogs(jsonArray.toString(), FileUtils.mypulsar); + log.info("控制设备ID: {}, 联动时间计划:{}",cal.getDevid(),jsonArray.toString()); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); - String weekStr = jsonObject.getString("Week"); + //周 String[] weeks = weekStr.split(","); - + //开始时间 String startTime = jsonObject.getString("StartTime"); - String endTime = jsonObject.getString("EndTime"); - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm"); SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("HH:mm:ss"); - int indexWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1; - FileUtils.getInstance().writeLogs(weekStr.toString() + "当前周:" + indexWeek, FileUtils.mypulsar); + log.info("周计划日:{},当前日期:周:{}",weekStr,indexWeek); for (int j = 0; j < weeks.length; j++) { int week = Integer.parseInt(weeks[j]); if (week == indexWeek) { - Date startDate = simpleDateFormat.parse(startTime); Date endDate = simpleDateFormat.parse(endTime); Date date = simpleDateFormat1.parse(new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds()); - long starTime = startDate.getTime(); - long indexTime = date.getTime(); long entTime = endDate.getTime(); -// System.out.println("时间比对:starTime:" + starTime + "-----indexTime:" + indexTime + "----entTime:" + entTime); - FileUtils.getInstance().writeLogs("开始时间:" + (indexTime < entTime) + "结束时间:" + (indexTime > starTime), FileUtils.mypulsar); + //当前系统时间 + long indexTime = date.getTime(); if (indexTime < entTime && indexTime > starTime) { - //比较器类型 + log.info("时间符合:继续执行开启设备"); int compreType = cal.getCompreType(); - switch (compreType) { case 1://固定值 calCompre(cal, deviceBean); break; case 2://当天日期 - break; } } - } } - -// System.out.println("jsonObject:" + jsonObject.toString()); } - } catch (JSONException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } - } - } /** @@ -124,55 +117,39 @@ public class ControlUtils { * @param deviceBean 控制设备 */ private void calCompre(CalDevContrl cal, DeviceBean deviceBean) { - - int thrsoldValue = 0; - - FileUtils.getInstance().writeLogs(cal.toString(), "caldevCntrol.txt"); - - if (cal.getModelType() == 10) {//人体感应 - if (cal.getThreValue().equals("有人")) thrsoldValue = 1; - else { - thrsoldValue = 0; - if (cal.getThreValue().equals("无人")) return; - //无人的时候不做处理 , 在定时服务中处理 -// return; - } - } else { - //温度传感器 不直接计算 -// thrsoldValue = Integer.parseInt(cal.getThreValue());//设定的阈值 + if (deviceBean.getValue().equals("无人")){ + return; } - - int value = Integer.parseInt(deviceBean.getValue());//实际的值 - System.out.println("thrsoldValue:" + thrsoldValue + " value:" + value + " cal:" + cal.toString()); - switch (cal.getComPre()) { - case 1://大于 - if (value > thrsoldValue)//启动触发条件 - startDevice(cal);//开启联动的设备 - break; - case 2://等于 - - if (value == thrsoldValue)//有人的时候会执行 - { - boolean temp = calTemp(cal.getAssDevice()); - System.out.println("--------------------温度是否达标:" + temp + "-------------"); - if (temp)//温度符合要求 - startDevice(cal);//开启联动的设备 + log.info("温度是否达标:,关联设备:{}",cal.getAssDevice()); +// //温度符合要求 + boolean isok = false; + //人感设备对应的关联联动设备 + if (!StringUtils.isEmpty(cal.getAssDevice())) { + String[] devices = cal.getAssDevice().split(","); + for (int i = 0; i < devices.length; i++) { + String device = devices[i]; + //取出湿度传感器设备 + List calDevContrls = deviceDao.getTempCalWitdDevid(device); + if(!CollectionUtils.isEmpty(calDevContrls)){ + for (int j = 0; j < calDevContrls.size(); j++) { + String tempDevId = calDevContrls.get(j).getDevid(); + if (tempDevices.containsKey(tempDevId)) { + //温度记录了 + int tempear = tempDevices.get(tempDevId); + log.info("有温度记录:"+tempear); + isok = tempIsOk(tempear, calDevContrls.get(j)); + } else { + //沒有记录溫度按照28度比较 + log.info("有温度记录:28"); + isok =tempIsOk(28, calDevContrls.get(j)); + } + } } - - break; - case 3://小于 - - if (value < thrsoldValue) - startDevice(cal);//开启联动的设备 - - break; - default://不触发条件 - - removeSet(cal); - - break; + } + if(isok){ + startDevice(cal,deviceBean.getValue()); + } } - } /** @@ -183,64 +160,50 @@ public class ControlUtils { private synchronized boolean calTemp(String assDevice) { if (!StringUtils.isEmpty(assDevice)) { String[] devices = assDevice.split(","); - FileUtils.getInstance().writeLogs(assDevice + "设备数量:" + devices.length, "tempisOk.txt"); for (int i = 0; i < devices.length; i++) { - String device = devices[i]; - FileUtils.getInstance().writeLogs(device, "tempisOk.txt"); - + //湿度传感器设备 List calDevContrls = deviceDao.getTempCalWitdDevid(device); - - for (int j = 0; j < calDevContrls.size(); j++) { - String tempDevId = calDevContrls.get(j).getDevid(); - if (tempDevices.containsKey(tempDevId)) {//温度记录了 - - int tempear = tempDevices.get(tempDevId); - - boolean temp = tempIsOk(tempear, calDevContrls.get(j)); - if (temp) return true; - - } else {//沒有記錄溫度按照30度 - boolean temp = tempIsOk(28, calDevContrls.get(j)); - if (temp) return true; + if(!CollectionUtils.isEmpty(calDevContrls)){ + for (int j = 0; j < calDevContrls.size(); j++) { + String tempDevId = calDevContrls.get(j).getDevid(); + if (tempDevices.containsKey(tempDevId)) { + //温度记录了 + int tempear = tempDevices.get(tempDevId); + log.info("有温度记录:"+tempear); + return tempIsOk(tempear, calDevContrls.get(j)); + } else { + //沒有记录溫度按照28度比较 + log.info("有温度记录:28"); + return tempIsOk(28, calDevContrls.get(j)); + } } - } - - } - } - return false; } + /** + * 温度比较 + * @param tempear + * @param calDevContrl + * @return + */ private boolean tempIsOk(int tempear, CalDevContrl calDevContrl) { - - FileUtils.getInstance().writeLogs(calDevContrl.toString(), "tempisOk.txt"); - if (calDevContrl.getComPre() != 2) { - System.out.println("溫度比較:" + tempear + " 比較的值:" + calDevContrl.getThreValue() + " 比较方式:" + calDevContrl.getComPre()); - - switch (calDevContrl.getComPre()) { - case 1://小于 - - if (tempear <= Integer.parseInt(calDevContrl.getThreValue())) { - return true; - } - - break; - case 3://大于 - - if (tempear >= Integer.parseInt(calDevContrl.getThreValue())) { - return true; - } - - break; - + log.info("温度比较,温感设备信息:"+ JSON.toJSONString(calDevContrl)); + if(calDevContrl.getComPre() ==1){ + if (tempear <= Integer.parseInt(calDevContrl.getThreValue())) { + log.info("温度比较: 实际温度:{},小于制热临界值:{},准备开启制热。",tempear,calDevContrl.getThreValue()); + return true; + } + } + if(calDevContrl.getComPre() ==3){ + if (tempear >= Integer.parseInt(calDevContrl.getThreValue())) { + log.info("温度比较: 实际温度:{},大于制制冷临界值:{},准备开启制冷。",tempear,calDevContrl.getThreValue()); + return true; } - } - return false; } @@ -268,101 +231,90 @@ public class ControlUtils { * * @param cal */ - private void startDevice(CalDevContrl cal) { - + private void startDevice(CalDevContrl cal,String value) { +// deviceSet.add(cal); + //设备类型 10:人感;9温感 int modelType = cal.getModelType(); - - deviceSet.add(cal); - - String assDevice = cal.getAssDevice();//联动的设备id - -// boolean isExit = isExist(assDevice.split(",")); - boolean isExit = true; - - System.out.println("是否符合联动条件:" + isExit); - - if (isExit) {//符合联动条件 - - List calDevBeContrlList = getCalDevBeCon(assDevice); - - for (int i = 0; i < calDevBeContrlList.size(); i++) { - CalDevBeContrl calDevBeContrl = calDevBeContrlList.get(i); -// System.out.println("控制对象:" + calDevBeContrl.toString()); - String conDevId = calDevBeContrl.getConDevId();//被控制的设备id - String conValue = calDevBeContrl.getConValue(); - String conCodes = calDevBeContrl.getConCode(); - - String[] conCodeStr = conCodes.split(","); - - for (int j = 0; j < conCodeStr.length; j++) { - String conCode = conCodeStr[j]; - switch (modelType) { - case 1://开关 - HttpUtil.controlDev(conDevId, conCode, conValue); - break; - case 2://插座 - HttpUtil.controlDev(conDevId, conCode, conValue); - break; - case 3://排插 - HttpUtil.controlDev(conDevId, conCode, conValue); - break; - case 9://温度传感器 - break; - case 10://人体感应触发空调开关 - case 12://万能遥控器 - if (SchduledTasks.conDevMap.containsKey(conDevId)) {//设备已开,更新时间 - SchduledTasks.conDevMap.put(conDevId, new Date()); - System.out.println("更新设备时间"); - } else {//开启设备 - SchduledTasks.conDevMap.put(conDevId, new Date()); - System.out.println("开启设备"); - String name = deviceDao.getWLName(conDevId); - HttpUtil.addAirCode(conValue, conDevId, name); - } - break; - } + //人感设备关联的遥控设备 + String assDevice = cal.getAssDevice(); + //取得红外遥控设备 + List calDevBeContrlList = getCalDevBeCon(assDevice); + if(CollectionUtils.isEmpty(calDevBeContrlList)){ + log.info("未查询到控制红外遥控器"); + return; + } + for (int i = 0; i < calDevBeContrlList.size(); i++) { + CalDevBeContrl calDevBeContrl = calDevBeContrlList.get(i); + //红外遥控设备id + String conDevId = calDevBeContrl.getConDevId(); + String conCodes = calDevBeContrl.getConCode(); + //遥控设备,执行命令 + String conValue = calDevBeContrl.getConValue(); + String[] conCodeStr = conCodes.split(","); + //设备名 + String name = deviceDao.getWLName(conDevId); + for (int j = 0; j < conCodeStr.length; j++) { + String conCode = conCodeStr[j]; + switch (modelType) { + case 1://开关 + HttpUtil.controlDev(conDevId, conCode, conValue); + break; + case 2://插座 + HttpUtil.controlDev(conDevId, conCode, conValue); + break; + case 3://排插 + HttpUtil.controlDev(conDevId, conCode, conValue); + break; + case 9://温度传感器 + break; + case 10://人体感应触发空调开关 + log.info("设备类型:"+modelType+"设备集合"+ JSON.toJSONString(SchduledTasks.conDevMap)); + if (!SchduledTasks.conDevMap.containsKey(conDevId)&&SchduledTasks.conDevMap.get(conDevId)==null) { + //设备已开,更新时间 + SchduledTasks.conDevMap.put(conDevId,new Date()); + HttpUtil.addAirCode(conValue, conDevId, name); + } + case 12://万能遥控器 + log.info("设备类型:"+modelType); + if (!SchduledTasks.conDevMap.containsKey(conDevId)&&SchduledTasks.conDevMap.get(conDevId)==null) {//设备已开,更新时间 + SchduledTasks.conDevMap.put(conDevId,new Date()); + HttpUtil.addAirCode(conValue, conDevId, name); + } + break; } - } - } - } /** - * 获取被控制的设备 - * + * 获取红外遥控控制的设备 * @param assDevice * @return */ private List getCalDevBeCon(String assDevice) { - String[] assDeviceIds = assDevice.split(","); - List devBeContrlList = new ArrayList<>(); - for (int i = 0; i < assDeviceIds.length; i++) { String deviceId = assDeviceIds[i]; - - List calDevContrl = deviceDao.getCalDevContrlWidthDevId(deviceId); - - for (int j = 0; j < calDevContrl.size(); j++) { - - CalDevContrl calDevContrl1 = calDevContrl.get(j); - - if (!calDevContrl1.getDevBeId().equals("0")) { - String[] calDevBeIdStr = calDevContrl1.getDevBeId().split(","); - if (calDevBeIdStr != null) { - for (int k = 0; k < calDevBeIdStr.length; k++) { - CalDevBeContrl calDevBeContrl = deviceDao.getCalDevBeControl(calDevBeIdStr[k]); - devBeContrlList.add(calDevBeContrl); + //获取温感设备 + List calDevContrl = deviceDao.getTempCalWitdDevid(deviceId); + if(!CollectionUtils.isEmpty(calDevContrl)){ + for (int j = 0; j < calDevContrl.size(); j++) { + //温感设备 + CalDevContrl calDevContrl1 = calDevContrl.get(j); + if (!calDevContrl1.getDevBeId().equals("0")) { + String[] calDevBeIdStr = calDevContrl1.getDevBeId().split(","); + if (calDevBeIdStr != null) { + for (int k = 0; k < calDevBeIdStr.length; k++) { + //红外设备 + CalDevBeContrl calDevBeContrl = deviceDao.getCalDevBeControl(calDevBeIdStr[k]); + devBeContrlList.add(calDevBeContrl); + } } } } } - } - return devBeContrlList; } diff --git a/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/HttpUtil.java b/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/HttpUtil.java index ee18a5d..db85c97 100644 --- a/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/HttpUtil.java +++ b/cloud/mypulsar/src/main/java/com/example/mypulsar/utils/HttpUtil.java @@ -3,6 +3,8 @@ package com.example.mypulsar.utils; import com.example.mypulsar.bean.Command; import com.example.mypulsar.bean.TuYaAirCondition; import com.example.mypulsar.bean.TuYaCommand; +import com.example.mypulsar.task.SchduledTasks; +import lombok.extern.slf4j.Slf4j; import org.springframework.boot.configurationprocessor.json.JSONException; import org.springframework.boot.configurationprocessor.json.JSONObject; import org.springframework.core.io.FileSystemResource; @@ -20,14 +22,12 @@ import java.io.File; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * http 工具类 */ +@Slf4j public class HttpUtil { public static String post(String requestUrl, String accessToken, String params) @@ -112,8 +112,8 @@ public class HttpUtil { String responseEntity = restTemplate.postForObject(url, tuYaCommand, String.class); - System.out.println("tuYaCommand:" + tuYaCommand.toString() + "----deviceId:" + deviceId); - System.out.println("responseEntity:" + responseEntity); + log.info("tuYaCommand:" + tuYaCommand.toString() + "----deviceId:" + deviceId); + log.info("responseEntity:" + responseEntity); return responseEntity.equals("1"); } @@ -142,35 +142,34 @@ public class HttpUtil { * @return */ public static String addAirCode(String conValue, String conDevId, String conDevName) { -// System.out.println("url-------------------------------conValue:" + conValue); - - String url = String.format("http://120.26.116.253:5555/TuYa/%s/addAirCode1", conDevId); - RestTemplate restTemplate = new RestTemplate(); - - TuYaAirCondition tuYaAirCondition = new TuYaAirCondition(); - String power = ""; try { - JSONObject jsonObject = new JSONObject(conValue); - power = jsonObject.getString("power"); - tuYaAirCondition.setMode(jsonObject.getString("mode")); - tuYaAirCondition.setPower(power); - tuYaAirCondition.setRemote_id(jsonObject.getString("remote_id")); - tuYaAirCondition.setWind(jsonObject.getString("wind")); - tuYaAirCondition.setTemp(jsonObject.getString("temp")); - tuYaAirCondition.setRemote_index(jsonObject.getString("remote_index")); - - - } catch (JSONException e) { - e.printStackTrace(); + String url = String.format("http://120.26.116.253:5555/TuYa/%s/addAirCode", conDevId); + RestTemplate restTemplate = new RestTemplate(); + TuYaAirCondition tuYaAirCondition = new TuYaAirCondition(); + String power = ""; + try { + JSONObject jsonObject = new JSONObject(conValue); + power = jsonObject.getString("power"); + tuYaAirCondition.setMode(jsonObject.getString("mode")); + tuYaAirCondition.setPower(power); + tuYaAirCondition.setRemote_id(jsonObject.getString("remote_id")); + tuYaAirCondition.setWind(jsonObject.getString("wind")); + tuYaAirCondition.setTemp(jsonObject.getString("temp")); + tuYaAirCondition.setRemote_index(jsonObject.getString("remote_index")); + } catch (JSONException e) { + log.info("控制失败:失败信息",e); + } + log.info("开始发送遥控命令至设备:请求地址: {},设备名称: {},设备ID: {},请求参数: {}",url,conDevName,conDevId,tuYaAirCondition.toString()); + String response = restTemplate.postForObject(url, tuYaAirCondition, String.class); + log.info("返回结果:{}",response); +// FileUtils.getInstance().writeLogs(String.format("%s设备%s--控制%s", power.equals("1") ? "成功" : "失败", conDevName + "-" + conDevId, response), FileUtils.addAirCode); + return response; + }catch (Exception e){ + log.info("请求红外控制指令失败:{}",e); + if(SchduledTasks.conDevMap.containsKey(conDevId)){ + SchduledTasks.conDevMap.remove(conDevId); + } } - - - System.out.println("url-------------------------------:" + url + " conValue:" + tuYaAirCondition.toString()); - String response = restTemplate.postForObject(url, tuYaAirCondition, String.class); - FileUtils.getInstance().writeLogs(String.format("%s设备%s--控制%s", power.equals("1") ? "成功" : "失败", conDevName + "-" + conDevId, response), FileUtils.addAirCode); - System.out.println("response----------------------------------:" + response); - return response; - + return null; } - } diff --git a/cloud/mypulsar/src/main/resources/application.yaml b/cloud/mypulsar/src/main/resources/application.yaml index 78e1cae..7821c07 100644 --- a/cloud/mypulsar/src/main/resources/application.yaml +++ b/cloud/mypulsar/src/main/resources/application.yaml @@ -2,6 +2,8 @@ server: port: 10009 spring: + profiles: + active: dev application: name: mypulsar datasource: diff --git a/cloud/mypulsar/src/main/resources/logback-spring.xml b/cloud/mypulsar/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..4158ed0 --- /dev/null +++ b/cloud/mypulsar/src/main/resources/logback-spring.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} \(L%line\) - %msg%n + + + + + + + ${LOG_PATH}/${BASE_FILE_NAME}.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} \(L%line\) - %msg%n + + + + + + ${LOG_PATH}/history/${BASE_FILE_NAME}.%d{yyyy-MM-dd}.%i.gz + + ${LOG_FILE_MAX_SIZE} + + ${LOG_FILE_MAX_HISTORY} + + + + + + + + + + + + \ No newline at end of file -- libgit2 0.21.0