Commit efa9935fed3477d5a023c462298657f32f9f3095

Authored by 陈杰
2 parents 210a1ae5 d7030105
Exists in master

Merge remote-tracking branch 'origin/master'

cloud/dahua/src/main/java/com/example/dahua/lib/CompressPic.java
... ... @@ -17,7 +17,7 @@ import java.io.InputStream;
17 17 public class CompressPic {
18 18  
19 19 public static String CompressPic(String srcPath, String targetPath, String studentcode) throws Exception {
20   - double cutPercent = 0.5;
  20 + double cutPercent = 0.2;
21 21 File file = new File(srcPath.trim());
22 22 FileInputStream fileInputStream = new FileInputStream(file);
23 23 BufferedImage bufferedImage = ImageIO.read(fileInputStream);
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java
... ... @@ -525,8 +525,8 @@ public class CMSServer implements ApplicationRunner {
525 525 * @Param picUrl 原图
526 526 */
527 527 public boolean sendInfo(String srcFile, String url, String card, String startTime, String endTime, int validTimeEnabled, String name, String deviceId, String userType, String employeeNo) {
528   - deleteCard(deviceId, card);
529   - editCard(startTime, endTime, 0, name, card, deviceId, employeeNo);
  528 +// deleteCard(deviceId, card);
  529 +// editCard(startTime, endTime, 0, name, card, deviceId, employeeNo);
530 530 editCard(startTime, endTime, 1, name, card, deviceId, employeeNo);
531 531 String strRequest = "/ISAPI/AccessControl/SetFaceParamCfg";
532 532 String strConfigXML = "<SetFaceParamCfg version=\"2.0\" xmlns=\"http://www.isapi.org/ver20/XMLSchema\">\n" +
... ... @@ -757,7 +757,7 @@ public class CMSServer implements ApplicationRunner {
757 757 if (type == 1) {//下发人脸
758 758 if (!hCEhomeCMS.NET_ECMS_PostPTXMLConfig(map.get(deviceId), struISAPXML)) {
759 759 int iErr = hCEhomeCMS.NET_ECMS_GetLastError();
760   - System.err.println(content + "失败,错误号:" + iErr);
  760 + System.err.println(content + "失败,错误号:" + iErr+"---"+strConfigXML+"\n");
761 761 sendRecoderUtils.sendFail(sendRecordDao, card, srcFile, deviceId, userDao, content + "失败,错误号:" + iErr, userType);
762 762 } else {
763 763 stringXMLOut.read();
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/async/SendUserAsync.java
... ... @@ -49,7 +49,7 @@ public class SendUserAsync {
49 49 }
50 50 //根据设备是5603 还是新设备
51 51 String employeeNo = "";
52   - if (deviceId.contains("ymzx")||deviceId.contains("5607")||deviceId.contains("5671")){
  52 + if (deviceId.contains("ymzx")||deviceId.contains("5607")||deviceId.contains("5671")||deviceId.contains("5604")){
53 53 employeeNo = System.currentTimeMillis()+"";
54 54 cmsServer.SetCardWeekPlan(deviceId, HKXmlUtils.getInstance().SetCardTemplate(), "设置卡权限计划模板");
55 55 cmsServer.SetCardWeekPlan(deviceId, HKXmlUtils.getInstance().SetCardWeekPlan(), "卡权限周计划");
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/dao/UserDao.java
... ... @@ -159,9 +159,9 @@ public interface UserDao {
159 159 @Param("userId") String userId, @Param("targetUrl") String targetUrl, @Param("clicks") int clicks, @Param("userList") String userList, @Param("isShare") int isShare,
160 160 @Param("charpId1") int charpId1, @Param("knowledgeId") int knowledgeId);
161 161  
162   - @Select("select * from SZ_V_School_Student where school_id = 1066 and student_type = 1 and user_id not in (select DISTINCT user_id from DBlan27.xiaoanhxy.dbo.Face_Recoder where deviceId in ('840153205671', '840153965671', '840153485671', '840153325671', '840154005671',\n" +
163   - " '840153105671', '840153165671', '840153835671') and time > '2019-12-10' )")
164   - List<StudentBean> getAllStudentsWithSchoolId(@Param("school_id") String school_id);
  162 + @Select("select *\n" +
  163 + "from SZ_V_School_Student where name = #{name} and school_id = #{school_id}")
  164 + List<StudentBean> getAllStudentsWithSchoolId(@Param("school_id") String school_id,@Param("name")String name);
165 165  
166 166 @Select("select * from SZ_V_School_Student where school_id = #{school_id} and student_type = 2")
167 167 List<StudentBean> getAllStuWithSchoolId(@Param("school_id") String school_id);
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/utils/CompressPic.java
... ... @@ -16,13 +16,14 @@ import java.io.InputStream;
16 16 public class CompressPic {
17 17  
18 18 public static String CompressPic(String srcPath, String targetPath) throws Exception {
19   - double cutPercent = 0.5;
  19 + double cutPercent = 0.1;
20 20 File file = new File(srcPath.trim());
21 21 FileInputStream fileInputStreamSrc = new FileInputStream(file);
22 22 BufferedImage bufferedImage = ImageIO.read(fileInputStreamSrc);
23 23 int width = bufferedImage.getWidth(null);
24 24 int height = bufferedImage.getHeight(null);
25 25 long fileLength = file.length();
  26 + System.out.println("fileLength:"+fileLength);
26 27 if ((fileLength / 1024) < 200) {
27 28 writeImgToFile(bufferedImage, width, height, targetPath);
28 29 } else
... ...
cloud/haikangface/src/test/java/com/sincere/haikangface/HaikangfaceApplicationTests.java
... ... @@ -14,6 +14,7 @@ import com.sincere.haikangface.bean.xiaoan.CreditCardRecordsSS;
14 14 import com.sincere.haikangface.dao.DeviceDao;
15 15 import com.sincere.haikangface.dao.UserDao;
16 16 import com.sincere.haikangface.dao.ZuoYeDao;
  17 +import com.sincere.haikangface.utils.ApiUtil;
17 18 import com.sincere.haikangface.xiananDao.SendRecordDao;
18 19 import org.bouncycastle.asn1.cms.MetaData;
19 20 import org.hibernate.validator.constraints.LuhnCheck;
... ... @@ -54,31 +55,6 @@ public class HaikangfaceApplicationTests {
54 55 @Test
55 56 public void contextLoads() {
56 57  
57   - /*
58   - List<SendRecordBean> sendRecordBeanList = sendRecordDao.getSuccessAndFail();
59   - System.out.println("sendRecordBeanList:" + sendRecordBeanList.size());
60   - for (int i = 0; i < sendRecordBeanList.size(); i++) {
61   - SendRecordBean sendRecordBean = sendRecordBeanList.get(i);
62   - sendRecordDao.deleteFaceFail(sendRecordBean.getNum(), sendRecordBean.getDeviceID());
63   - }
64   - //4278190095 最小值
65   -
66   - for (long i = 694535; i <1048577 ; i++) {
67   -
68   - System.out.println("十六进制:FF"+splicingZero(Long.toHexString(i),5)+"F");
69   - String CardNum = "FF"+splicingZero(Long.toHexString(i),5)+"F";
70   -
71   - long intCardNum = Long.parseLong(CardNum,16);
72   -
73   - System.out.println("intCardNum:"+intCardNum);
74   - userDao.addVirtual_Card(intCardNum,0,CardNum);
75   -// try {
76   -// Thread.sleep(500);
77   -// } catch (InterruptedException e) {
78   -// e.printStackTrace();
79   -// }
80   -
81   - }*/
82 58  
83 59 }
84 60  
... ... @@ -98,10 +74,11 @@ public class HaikangfaceApplicationTests {
98 74 /*RestTemplate restTemplate = new RestTemplate();
99 75 //失败人脸补发
100 76 int userType = 2;
101   - List<SendRecordBean> sendRecordBeanList = sendRecordDao.getSenFail("110",userType);
  77 + List<SendRecordBean> sendRecordBeanList = sendRecordDao.getSenFail("1066",userType);
102 78 int idnex = 0;
103 79 for (int i = 0; i < sendRecordBeanList.size(); i++) {
104 80 SendRecordBean sendRecordBean = sendRecordBeanList.get(i);
  81 +
105 82 String url =String.format( "http://114.55.30.100:8089/facereco/sendStuCardAndImg?card=%s&deviceId=%s&endTime=%s&filePath=%s&name=%s&userType=%s&validTimeEnabled=%s&startTime=%s"
106 83 ,sendRecordBean.getNum(),sendRecordBean.getDeviceID(),"2023-10-01 10:00:00",sendRecordBean.getImgPath(),sendRecordBean.getName(),userType+"","1","2019-10-01 10:00:00");
107 84 String result1 = restTemplate.getForObject(url, String.class);
... ... @@ -109,19 +86,19 @@ public class HaikangfaceApplicationTests {
109 86  
110 87 }*/
111 88  
112   - /*RestTemplate restTemplate = new RestTemplate();
  89 + /* RestTemplate restTemplate = new RestTemplate();
113 90 //失败人脸补发
114 91 int userType = 2;
115   - List<StudentBean> studentBeans = userDao.getAllStudentsWithSchoolId("1066");
  92 + List<StudentBean> studentBeans = userDao.getAllStudentsWithSchoolId("1066","张文晶");
116 93 List<String> list = new ArrayList<>();
117   -// list.add("840153205671");
118   -// list.add("840153965671");
119   -// list.add("840153485671");
120   -// list.add("840153325671");
121   -// list.add("840154005671");
122   -// list.add("840153105671");
  94 + list.add("840153205671");
  95 + list.add("840153965671");
  96 + list.add("840153485671");
  97 + list.add("840153325671");
  98 + list.add("840154005671");
  99 + list.add("840153105671");
123 100 list.add("840153165671");
124   -// list.add("840153835671");
  101 + list.add("840153835671");
125 102 int idnex = 0;
126 103 for (int i = 0; i < studentBeans.size(); i++) {
127 104 StudentBean sendRecordBean = studentBeans.get(i);
... ... @@ -129,9 +106,12 @@ public class HaikangfaceApplicationTests {
129 106 // http://campus.myjxt.com//face17e50/School1066/Student/st20190101.png
130 107 for (int j = 0; j < list.size(); j++) {
131 108 String imgUrl = sendRecordBean.getPhoto().replace("http://campus.myjxt.com","E:\\wwwhtdocs\\smartcampus");
  109 +// imgUrl="E:\\wwwhtdocs\\smartcampus//face17e50/School1066/Student/st20170632.jpg";
  110 + System.out.println("imgUrl:"+imgUrl);
132 111 String url =String.format( "http://114.55.30.100:8089/facereco/sendStuCardAndImg?card=%s&deviceId=%s&endTime=%s&filePath=%s&name=%s&userType=%s&validTimeEnabled=%s&startTime=%s"
133 112 ,sendRecordBean.getStudent_num(),list.get(j),"2023-10-01 10:00:00",imgUrl,sendRecordBean.getName(),userType+"","1","2019-10-01 10:00:00");
134 113 String result1 = restTemplate.getForObject(url, String.class);
  114 + System.out.println("imgUrl:"+url);
135 115 System.out.println("下发人脸:" + result1+" idnex:"+idnex++);
136 116 }
137 117  
... ...
cloud/mypulsar/pom.xml
... ... @@ -142,6 +142,15 @@
142 142 <artifactId>spring-boot-maven-plugin</artifactId>
143 143 <configuration>
144 144 <includeSystemScope>true</includeSystemScope>
  145 + <!--
  146 + <layout>ZIP</layout>
  147 + <includes>
  148 + <include>
  149 + &lt;!&ndash; 排除所有Jar &ndash;&gt;
  150 + <groupId>nothing</groupId>
  151 + <artifactId>nothing</artifactId>
  152 + </include>
  153 + </includes>-->
145 154 </configuration>
146 155 </plugin>
147 156 </plugins>
... ...
cloud/mypulsar/src/main/java/com/example/mypulsar/MyRunnerableInt.java
1 1 package com.example.mypulsar;
2 2  
3 3 import com.alibaba.fastjson.JSON;
  4 +import com.example.mypulsar.bean.CalDevContrl;
4 5 import com.example.mypulsar.bean.DeviceBean;
5 6 import com.example.mypulsar.bean.TuYaReceiverBean;
6 7 import com.example.mypulsar.bean.TuYaReceiverBeanStatus;
... ... @@ -9,6 +10,7 @@ import com.example.mypulsar.message.MessageVO;
9 10 import com.example.mypulsar.mq.AESBase64Utils;
10 11 import com.example.mypulsar.mq.MessageHandlerTask;
11 12 import com.example.mypulsar.mq.MqConsumer;
  13 +import com.example.mypulsar.utils.ControlUtils;
12 14 import com.example.mypulsar.utils.PulsarConsumerPoolFactory;
13 15 import com.example.mypulsar.utils.ThreadPoolFactory;
14 16 import org.apache.pulsar.client.api.Consumer;
... ... @@ -38,6 +40,11 @@ public class MyRunnerableInt implements ApplicationRunner {
38 40 @Override
39 41 public void run(ApplicationArguments args) throws Exception {
40 42  
  43 +// DeviceBean deviceBean = new DeviceBean();
  44 +// deviceBean.setValue("30");
  45 +// deviceBean.setDevId("6c5c38c2e431d01eeei3to");
  46 +// calOpenOrCloseDevWithtemper(deviceBean);
  47 +
41 48 // System.out.println("running");
42 49 // initPool();
43 50 initMqConsumer();
... ... @@ -88,7 +95,7 @@ public class MyRunnerableInt implements ApplicationRunner {
88 95 * @param tuYaReceiverBean
89 96 */
90 97 private void detealData(TuYaReceiverBean tuYaReceiverBean) {
91   - System.out.println("tuYaReceiverBean:" + tuYaReceiverBean.toString());
  98 +// System.out.println("tuYaReceiverBean:" + tuYaReceiverBean.toString());
92 99 //数据对象
93 100 DeviceBean deviceBean = new DeviceBean();
94 101 deviceBean.setDataId(tuYaReceiverBean.getDataId());
... ... @@ -148,7 +155,7 @@ public class MyRunnerableInt implements ApplicationRunner {
148 155  
149 156 // String clintId = deviceDao.selectAttendance(devId);
150 157 // if (clintId.equals(devId)) {
151   - deviceDao.updateStatus(devId, isConnection);
  158 + deviceDao.updateStatus(devId, isConnection,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
152 159 // } else {
153 160 // deviceDao.insert(devId, "-2", isConnection);
154 161 // }
... ... @@ -156,7 +163,7 @@ public class MyRunnerableInt implements ApplicationRunner {
156 163 }
157 164  
158 165 private void updateDevStatus(DeviceBean deviceBean) {
159   - System.out.println("插入数据:" + deviceBean.toString());
  166 +// System.out.println("插入数据:" + deviceBean.toString());
160 167 deviceBean.setDpId("");
161 168 deviceBean.setName("");
162 169 deviceBean.setUid("");
... ... @@ -165,7 +172,6 @@ public class MyRunnerableInt implements ApplicationRunner {
165 172 if (deviceBean.getDataId() == null) deviceBean.setDataId("");
166 173 if (deviceBean.getCode() == null) deviceBean.setCode("");
167 174 if (deviceBean.getProductKey() == null) deviceBean.setProductKey("");
168   -
169 175 int index = deviceDao.addDevice(deviceBean.getDataId(), deviceBean.getDevId(), deviceBean.getProductKey(), deviceBean.getCode(), deviceBean.getValue()
170 176 , deviceBean.getBizCode(), deviceBean.getTime(), deviceBean.getName(), deviceBean.getDpId(), deviceBean.getUid(), deviceBean.getDev_status(), deviceBean.getDev_type());
171 177 updateStatus(deviceBean.getDevId(), "1");
... ... @@ -192,12 +198,16 @@ public class MyRunnerableInt implements ApplicationRunner {
192 198 deviceBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
193 199 String value = statue.getValue();
194 200 deviceBean.setValue(value);
  201 +
  202 + System.out.println("插入数据:" +value);
195 203 switch (code) {
196 204 case "va_temperature"://温度
  205 + deviceBean.setValue(Integer.parseInt(value)/100+"");
197 206 calOpenOrCloseDevWithtemper(deviceBean);//计算开启或关闭设备
198 207 log("温度:" + value);
199 208 break;
200 209 case "va_humidity"://湿度
  210 + deviceBean.setValue(Integer.parseInt(value)/100+"");
201 211 log("湿度:" + value);
202 212 break;
203 213 case "temper_alarm"://防拆报警
... ... @@ -251,8 +261,9 @@ public class MyRunnerableInt implements ApplicationRunner {
251 261  
252 262 break;
253 263 case "pir"://人体感应
254   - value = (value.equals("pir") ? "有人" : "无人");
255 264 log("人体感应:" + (value.equals("pir") ? "有人" : "无人"));
  265 + value = (value.equals("pir") ? "有人" : "无人");
  266 + deviceBean.setValue(value);
256 267 calOpenOrCloseDevWithPir(deviceBean);
257 268 break;
258 269 case "cur_voltage"://当前电压
... ... @@ -273,22 +284,31 @@ public class MyRunnerableInt implements ApplicationRunner {
273 284  
274 285 /**
275 286 * 根据是否有人控制设备
  287 + *
276 288 * @param deviceBean
277 289 */
278 290 private void calOpenOrCloseDevWithPir(DeviceBean deviceBean) {
279 291  
  292 + List<CalDevContrl> calDevContrls = deviceDao.getCalDevContrlWidthDevId(deviceBean.getDevId());
  293 + if (null != calDevContrls && calDevContrls.size() > 0) {
  294 + if (deviceBean.getValue().equals("有人")) deviceBean.setValue("1");
  295 + else deviceBean.setValue("0");
280 296  
281   -
  297 + ControlUtils.getInstance().conTemper(calDevContrls, deviceBean);
  298 + }
282 299 }
283 300  
284 301  
285 302 /**
286 303 * 根据温度变化控制设备
  304 + *
287 305 * @param deviceBean
288 306 */
289 307 private void calOpenOrCloseDevWithtemper(DeviceBean deviceBean) {
290 308  
291   -
  309 + List<CalDevContrl> calDevContrls = deviceDao.getCalDevContrlWidthDevId(deviceBean.getDevId());
  310 + if (null != calDevContrls && calDevContrls.size() > 0)
  311 + ControlUtils.getInstance().conTemper(calDevContrls, deviceBean);
292 312  
293 313 }
294 314  
... ...
cloud/mypulsar/src/main/java/com/example/mypulsar/Test.java
... ... @@ -2,11 +2,23 @@ package com.example.mypulsar;
2 2  
3 3 import com.example.mypulsar.utils.HttpUtil;
4 4  
  5 +import java.text.ParseException;
  6 +import java.text.SimpleDateFormat;
  7 +import java.util.Date;
  8 +
5 9 public class Test {
6 10  
7 11 public static void main(String[] args){
8   -
9   - HttpUtil.controlDev("6cb748ca397c2f03b1nqbh","switch_1","false");
  12 +// 3307102084f3eb3547e7
  13 +// HttpUtil.controlDev("6cb748ca397c2f03b1nqbh","switch_1","false");
  14 + /*HttpUtil.addAirCode("{\n" +
  15 + "\"remote_index\":\"null\",\n" +
  16 + "\"remote_id\":\"null\",\n" +
  17 + "\"power\":\"1\",\n" +
  18 + "\"mode\":\"null\",\n" +
  19 + "\"temp\":\"null\",\n" +
  20 + "\"wind\":\"null\"\n" +
  21 + "}\n","45424060b4e62d2183ec");*/
10 22  
11 23 }
12 24  
... ...
cloud/mypulsar/src/main/java/com/example/mypulsar/bean/CalDevContrl.java 0 → 100644
... ... @@ -0,0 +1,134 @@
  1 +package com.example.mypulsar.bean;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +public class CalDevContrl implements Serializable {
  6 +
  7 + private String Devid;
  8 +
  9 + private int ModelType;
  10 +
  11 + private int ComPre;
  12 +
  13 + private int CompreType;
  14 +
  15 + private String ThreValue;
  16 +
  17 + private String ConDevId;
  18 +
  19 + private String ConCode;
  20 +
  21 + private String ConValue;
  22 +
  23 + private String CreateTime;
  24 +
  25 + private String CreateUserId;
  26 +
  27 + private String InUseTime;
  28 +
  29 + public String getDevid() {
  30 + return Devid;
  31 + }
  32 +
  33 + public void setDevid(String devid) {
  34 + Devid = devid;
  35 + }
  36 +
  37 + public int getModelType() {
  38 + return ModelType;
  39 + }
  40 +
  41 + public void setModelType(int modelType) {
  42 + ModelType = modelType;
  43 + }
  44 +
  45 + public int getComPre() {
  46 + return ComPre;
  47 + }
  48 +
  49 + public void setComPre(int comPre) {
  50 + ComPre = comPre;
  51 + }
  52 +
  53 + public int getCompreType() {
  54 + return CompreType;
  55 + }
  56 +
  57 + public void setCompreType(int compreType) {
  58 + CompreType = compreType;
  59 + }
  60 +
  61 + public String getThresholdValue() {
  62 + return ThreValue;
  63 + }
  64 +
  65 + public void setThresholdValue(String thresholdValue) {
  66 + ThreValue = thresholdValue;
  67 + }
  68 +
  69 + public String getConDevId() {
  70 + return ConDevId;
  71 + }
  72 +
  73 + public void setConDevId(String conDevId) {
  74 + ConDevId = conDevId;
  75 + }
  76 +
  77 + public String getConCode() {
  78 + return ConCode;
  79 + }
  80 +
  81 + public void setConCode(String conCode) {
  82 + ConCode = conCode;
  83 + }
  84 +
  85 + public String getConValue() {
  86 + return ConValue;
  87 + }
  88 +
  89 + public void setConValue(String conValue) {
  90 + ConValue = conValue;
  91 + }
  92 +
  93 + public String getCreateTime() {
  94 + return CreateTime;
  95 + }
  96 +
  97 + public void setCreateTime(String createTime) {
  98 + CreateTime = createTime;
  99 + }
  100 +
  101 + public String getCreateUserId() {
  102 + return CreateUserId;
  103 + }
  104 +
  105 + public void setCreateUserId(String createUserId) {
  106 + CreateUserId = createUserId;
  107 + }
  108 +
  109 + public String getInUseTime() {
  110 + return InUseTime;
  111 + }
  112 +
  113 + public void setInUseTime(String inUseTime) {
  114 + InUseTime = inUseTime;
  115 + }
  116 +
  117 +
  118 + @Override
  119 + public String toString() {
  120 + return "CalDevContrl{" +
  121 + "Devid='" + Devid + '\'' +
  122 + ", ModelType=" + ModelType +
  123 + ", ComPre=" + ComPre +
  124 + ", CompreType=" + CompreType +
  125 + ", ThresholdValue='" + ThreValue + '\'' +
  126 + ", ConDevId='" + ConDevId + '\'' +
  127 + ", ConCode='" + ConCode + '\'' +
  128 + ", ConValue='" + ConValue + '\'' +
  129 + ", CreateTime='" + CreateTime + '\'' +
  130 + ", CreateUserId='" + CreateUserId + '\'' +
  131 + ", InUseTime='" + InUseTime + '\'' +
  132 + '}';
  133 + }
  134 +}
... ...
cloud/mypulsar/src/main/java/com/example/mypulsar/bean/Command.java
... ... @@ -21,4 +21,11 @@ public class Command{
21 21  
22 22 private String value;
23 23  
  24 + @Override
  25 + public String toString() {
  26 + return "Command{" +
  27 + "code='" + code + '\'' +
  28 + ", value='" + value + '\'' +
  29 + '}';
  30 + }
24 31 }
... ...
cloud/mypulsar/src/main/java/com/example/mypulsar/bean/TuYaAirCondition.java 0 → 100644
... ... @@ -0,0 +1,104 @@
  1 +package com.example.mypulsar.bean;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonInclude;
  4 +import io.swagger.annotations.ApiModel;
  5 +import io.swagger.annotations.ApiModelProperty;
  6 +
  7 +public class TuYaAirCondition {
  8 +
  9 + private String remote_index;
  10 + private String remote_id;
  11 +
  12 + /**
  13 + * 开关(1:开,0:关)
  14 + */
  15 + private String power;
  16 + /**
  17 + * 模式(0:制冷,1:制热,2:自动,3:送风,4:除湿)
  18 + */
  19 + private String mode;
  20 +
  21 + /**
  22 + * 温度(16-30)
  23 + */
  24 + private String temp;
  25 +
  26 + /**
  27 + * 风速(0:自动,1:低,2:中,3:高)
  28 + */
  29 + private String wind;
  30 +
  31 + public String getRemote_index() {
  32 + return remote_index;
  33 + }
  34 +
  35 + public void setRemote_index(String remote_index) {
  36 + this.remote_index = remote_index;
  37 + }
  38 +
  39 + public String getRemote_id() {
  40 + return remote_id;
  41 + }
  42 +
  43 + public void setRemote_id(String remote_id) {
  44 + this.remote_id = remote_id;
  45 + }
  46 +
  47 + public String getPower() {
  48 + return power;
  49 + }
  50 +
  51 + public void setPower(String power) {
  52 + this.power = power;
  53 + }
  54 +
  55 + public String getMode() {
  56 + return mode;
  57 + }
  58 +
  59 + public void setMode(String mode) {
  60 + this.mode = mode;
  61 + }
  62 +
  63 + public String getTemp() {
  64 + return temp;
  65 + }
  66 +
  67 + public void setTemp(String temp) {
  68 + this.temp = temp;
  69 + }
  70 +
  71 + public String getWind() {
  72 + return wind;
  73 + }
  74 +
  75 + public void setWind(String wind) {
  76 + this.wind = wind;
  77 + }
  78 +
  79 + public String getSwing() {
  80 + return swing;
  81 + }
  82 +
  83 + public void setSwing(String swing) {
  84 + this.swing = swing;
  85 + }
  86 +
  87 + /**
  88 + * 风向(暂时不支持)
  89 + */
  90 + private String swing;
  91 +
  92 + @Override
  93 + public String toString() {
  94 + return "TuYaAirCondition{" +
  95 + "remote_index='" + remote_index + '\'' +
  96 + ", remote_id='" + remote_id + '\'' +
  97 + ", power='" + power + '\'' +
  98 + ", mode='" + mode + '\'' +
  99 + ", temp='" + temp + '\'' +
  100 + ", wind='" + wind + '\'' +
  101 + ", swing='" + swing + '\'' +
  102 + '}';
  103 + }
  104 +}
... ...
cloud/mypulsar/src/main/java/com/example/mypulsar/bean/TuYaCommand.java
... ... @@ -17,5 +17,11 @@ public class TuYaCommand {
17 17  
18 18 private List<Command> commands;
19 19  
  20 + @Override
  21 + public String toString() {
  22 + return "TuYaCommand{" +
  23 + "commands=" + commands +
  24 + '}';
  25 + }
20 26 }
21 27  
... ...
cloud/mypulsar/src/main/java/com/example/mypulsar/dao/DeviceDao.java
1 1 package com.example.mypulsar.dao;
2 2  
  3 +import com.example.mypulsar.bean.CalDevContrl;
3 4 import com.example.mypulsar.bean.DeviceBean;
4 5 import org.apache.ibatis.annotations.*;
5 6 import org.springframework.stereotype.Repository;
... ... @@ -22,8 +23,8 @@ public interface DeviceDao {
22 23 int insert(@Param("clint_id")String clint_id,@Param("school_id")String school_id,
23 24 @Param("isConnection")String isConnection);
24 25  
25   - @Update("update WL_Attendance set isConnection = #{isConnection} where clint_id = #{clint_id}")
26   - int updateStatus(@Param("clint_id")String clint_id,@Param("isConnection")String isConnection);
  26 + @Update("update WL_Attendance set isConnection = #{isConnection},OnlineTime = #{OnlineTime} where clint_id = #{clint_id}")
  27 + int updateStatus(@Param("clint_id")String clint_id,@Param("isConnection")String isConnection,@Param("OnlineTime")String OnlineTime);
27 28  
28 29  
29 30  
... ... @@ -35,6 +36,8 @@ public interface DeviceDao {
35 36  
36 37 //获取联动控制模板
37 38 @Select("select * from CalDevContrl")
38   - List<String> getCalDevContrl();
  39 + List<CalDevContrl> getCalDevContrl();
39 40  
  41 + @Select("select * from CalDevContrl where Devid = #{Devid}")
  42 + List<CalDevContrl> getCalDevContrlWidthDevId(@Param("Devid") String devId);
40 43 }
... ...
cloud/mypulsar/src/main/java/com/example/mypulsar/utils/ControlUtils.java
1 1 package com.example.mypulsar.utils;
2 2  
  3 +import com.example.mypulsar.bean.CalDevContrl;
  4 +import com.example.mypulsar.bean.DeviceBean;
  5 +
  6 +import java.text.ParseException;
  7 +import java.text.SimpleDateFormat;
  8 +import java.util.Date;
  9 +import java.util.List;
  10 +
3 11 public class ControlUtils {
4 12  
  13 + private static ControlUtils controlUtils;
  14 +
  15 + public static ControlUtils getInstance(){
  16 + if (null==controlUtils){
  17 + synchronized (ControlUtils.class){
  18 + if (null==controlUtils)controlUtils = new ControlUtils();
  19 + }
  20 + }
  21 + return controlUtils;
  22 + }
  23 +
  24 + /**
  25 + * 根据温度变化操纵
  26 + * @param calDevContrls 联动模板
  27 + * @param deviceBean 温度传感器对象
  28 + */
  29 + public void conTemper(List<CalDevContrl> calDevContrls, DeviceBean deviceBean){
  30 +
  31 + for (CalDevContrl cal :
  32 + calDevContrls) {
  33 +
  34 + String inUseTime = cal.getInUseTime();//联动的时间范围,8:00-18:00
  35 +
  36 + String[] inUseTimes = inUseTime.split("-");
  37 +
  38 + String startTime = inUseTimes[0];
  39 +
  40 + String endTime = inUseTimes[1];
  41 +
  42 + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
  43 +
  44 + try {
  45 +
  46 + Date startDate = simpleDateFormat.parse(startTime);
  47 + Date endDate = simpleDateFormat.parse(endTime);
  48 + Date date = simpleDateFormat.parse(new Date().getHours()+":"+new Date().getMinutes());
  49 +
  50 + long starTime = startDate.getTime();
  51 +
  52 + if (date.getTime()<endDate.getTime()&&date.getTime()>starTime){
  53 + //比较器类型
  54 + int compreType = cal.getCompreType();
  55 +
  56 + switch (compreType){
  57 + case 1://固定值
  58 + calCompre(cal,deviceBean);
  59 + break;
  60 + case 2://当天日期
  61 +
  62 + break;
  63 + }
  64 + }
  65 +
  66 + } catch (ParseException e) {
  67 + e.printStackTrace();
  68 + }
  69 +
  70 +
  71 + }
  72 +
  73 + }
  74 +
  75 + /**
  76 + *
  77 + * @param cal 联动模板
  78 + * @param deviceBean 控制设备
  79 + */
  80 + private void calCompre(CalDevContrl cal, DeviceBean deviceBean) {
  81 + int thrsoldValue = Integer.parseInt(cal.getThresholdValue());//设定的阈值
  82 + int value = Integer.parseInt(deviceBean.getValue());//实际的值
  83 + System.out.println("thrsoldValue:"+thrsoldValue+" value:"+value+" cal:"+cal.toString());
  84 + switch (cal.getComPre()){
  85 + case 1://大于
  86 + if (value>thrsoldValue)//启动触发条件
  87 + startDevice(cal);//开启联动的设备
  88 + break;
  89 + case 2://等于
  90 +
  91 + if(value == thrsoldValue)
  92 + startDevice(cal);//开启联动的设备
  93 +
  94 + break;
  95 + case 3://小于
  96 +
  97 + if(value < thrsoldValue)
  98 + startDevice(cal);//开启联动的设备
  99 +
  100 + break;
  101 + }
  102 +
  103 + }
  104 +
  105 + /**
  106 + * 执行计划
  107 + * @param cal
  108 + */
  109 + private void startDevice(CalDevContrl cal) {
  110 +
  111 + int modelType = cal.getModelType();
  112 + String conDevId = cal.getConDevId();//被控制的设备id
  113 + String conValue =cal.getConValue();
  114 + String conCode = cal.getConCode();
  115 + switch (modelType){
  116 + case 1://开关
  117 + HttpUtil.controlDev(conDevId,conCode,conValue);
  118 + break;
  119 + case 2://插座
  120 + HttpUtil.controlDev(conDevId,conCode,conValue);
  121 + break;
  122 + case 3://排插
  123 + HttpUtil.controlDev(conDevId,conCode,conValue);
  124 + break;
  125 + case 7://空调伴侣
  126 + HttpUtil.addAirCode(conValue,conDevId);
  127 + break;
  128 + case 10://开关
  129 + HttpUtil.controlDev(conDevId,conCode,conValue);
  130 + break;
  131 + case 12://万能遥控器
  132 + HttpUtil.addAirCode(conValue,conDevId);
  133 + break;
  134 + }
  135 +
  136 +
  137 + }
5 138  
6 139  
7 140 }
... ...
cloud/mypulsar/src/main/java/com/example/mypulsar/utils/HttpUtil.java
1 1 package com.example.mypulsar.utils;
2 2  
3   -import com.alibaba.fastjson.JSONArray;
4   -import com.alibaba.fastjson.JSONObject;
5 3 import com.example.mypulsar.bean.Command;
  4 +import com.example.mypulsar.bean.TuYaAirCondition;
6 5 import com.example.mypulsar.bean.TuYaCommand;
7 6 import org.apache.pulsar.shade.com.google.gson.Gson;
  7 +import org.springframework.boot.configurationprocessor.json.JSONException;
  8 +import org.springframework.boot.configurationprocessor.json.JSONObject;
8 9 import org.springframework.core.io.FileSystemResource;
9 10 import org.springframework.http.HttpEntity;
10 11 import org.springframework.http.HttpHeaders;
... ... @@ -92,9 +93,9 @@ public class HttpUtil {
92 93 return result;
93 94 }
94 95  
95   - public static boolean controlDev(String deviceId, String code,String value ){
  96 + public static boolean controlDev(String deviceId, String code, String value) {
96 97  
97   - String url = "http://120.26.116.253:5555/TuYa/sendDeviceCommandsFun?deviceId="+deviceId;
  98 + String url = "http://120.26.116.253:5555/TuYa/sendDeviceCommandsFun?deviceId=" + deviceId;
98 99  
99 100 RestTemplate restTemplate = new RestTemplate();
100 101  
... ... @@ -110,25 +111,55 @@ public class HttpUtil {
110 111  
111 112 tuYaCommand.setCommands(commandList);
112 113  
113   - String responseEntity = restTemplate.postForObject(url,tuYaCommand, String.class);
  114 + String responseEntity = restTemplate.postForObject(url, tuYaCommand, String.class);
114 115  
115   - System.out.println("responseEntity:"+responseEntity);
  116 + System.out.println("tuYaCommand:" + tuYaCommand.toString());
  117 + System.out.println("responseEntity:" + responseEntity);
116 118 return responseEntity.equals("1");
117 119 }
118 120  
119 121  
120   - public static boolean IsDeviceOnline(String deviceId){
  122 + public static boolean IsDeviceOnline(String deviceId) {
121 123  
122 124 String url = "http://121.40.109.21:8089/file/getCard";
123 125  
124 126 RestTemplate restTemplate = new RestTemplate();
125 127  
126   - Map<String,Object> map = new HashMap<>();
  128 + Map<String, Object> map = new HashMap<>();
127 129  
128   - map.put("deviceId",deviceId);
  130 + map.put("deviceId", deviceId);
129 131  
130   - String res = restTemplate.getForObject(url,String.class,map);
  132 + String res = restTemplate.getForObject(url, String.class, map);
131 133 return res.equals("1");
132 134 }
133 135  
  136 +
  137 + public static String addAirCode(String conValue, String conDevId) {
  138 +
  139 +
  140 + String url = String.format("http://120.26.116.253:5555/TuYa/%s/addAirCode", conDevId);
  141 + RestTemplate restTemplate = new RestTemplate();
  142 +
  143 + TuYaAirCondition tuYaAirCondition = new TuYaAirCondition();
  144 + try {
  145 + JSONObject jsonObject = new JSONObject(conValue);
  146 + tuYaAirCondition.setMode(jsonObject.getString("mode"));
  147 + tuYaAirCondition.setPower(jsonObject.getString("power"));
  148 + tuYaAirCondition.setRemote_id(jsonObject.getString("remote_index"));
  149 + tuYaAirCondition.setWind(jsonObject.getString("wind"));
  150 + tuYaAirCondition.setTemp(jsonObject.getString("temp"));
  151 + tuYaAirCondition.setRemote_index(jsonObject.getString("remote_index"));
  152 +
  153 + } catch (JSONException e) {
  154 + e.printStackTrace();
  155 + }
  156 +
  157 + System.out.println("url-------------------------------:" + url+" conValue:"+tuYaAirCondition.toString());
  158 + String response = restTemplate.postForObject(url, tuYaAirCondition, String.class);
  159 +
  160 + System.out.println("response----------------------------------:" + response);
  161 + return response;
  162 +
  163 + }
  164 +
134 165 }
... ...