初始化火情事件表

This commit is contained in:
liuchengqian 2022-03-04 17:29:00 +08:00
parent 39ea504f16
commit 36e9d31941
8 changed files with 176 additions and 62 deletions

View File

@ -1,9 +1,5 @@
package com.xkrs.controller;
import com.dahuatech.icc.event.model.v202011.EventSubscribeRequest;
import com.dahuatech.icc.event.model.v202011.EventSubscribeResponse;
import com.dahuatech.icc.oauth.http.DefaultClient;
import com.dahuatech.icc.oauth.http.IClient;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.EquipmentDao;
import com.xkrs.dao.FireDao;
@ -136,41 +132,4 @@ public class FireController {
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, map, locale);
}
/**
* 订阅火情事件
*/
@GetMapping("/subscribeFireEvent")
public void subscribeFireEvent() {
try {
//118.24.27.47:6820
String host = "111.53.13.180:4433";
String username = "system";
String password = "Admin@123";
String clientId = "xkrszhcx";
String clientSecret = "eac429df-950a-4cba-aa50-76e47b0a74d8";
System.out.println("----开始执行----{}------事件订阅");
IClient iClient = new DefaultClient(host, username, password, clientId, clientSecret);
EventSubscribeRequest subscribeRequest = new EventSubscribeRequest();
// 接收事件地址
String receiveUrl = "http://118.24.27.47:6820/receiveFireEvent";
String mqinfo = "{\"param\":{\"monitors\":[{\"monitor\":\"" + receiveUrl + "\",\"monitorType\":\"url\",\"events\":[{\"category\":\"business\",\"subscribeAll\":1,\"domainSubscribe\":2,\"authorities\":[{}]},{\"category\":\"alarm\",\"subscribeAll\":1,\"domainSubscribe\":2,\"authorities\":[{}]},{\"category\":\"state\",\"subscribeAll\":1,\"domainSubscribe\":2,\"authorities\":[{}]}]}],\"subsystem\":{\"subsystemType\":0,\"name\":\"118.24.27.47_6820\",\"magic\":\"118.24.27.47_6820\"}}}";
subscribeRequest.body(mqinfo);
EventSubscribeResponse subscribeResponse = iClient.doAction(subscribeRequest, subscribeRequest.getResponseClass());
System.out.println("----结束执行----{}------事件订阅" + subscribeResponse.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 接收火情事件
*/
@PostMapping("/receiveFireEvent")
public void receiveFireEvent(@RequestBody Object fireEvent) {
try {
System.out.println("----接收火情事件----{}------" + fireEvent.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,71 @@
package com.xkrs.controller;
import com.dahuatech.icc.event.model.v202011.EventSubscribeRequest;
import com.dahuatech.icc.event.model.v202011.EventSubscribeResponse;
import com.dahuatech.icc.oauth.http.DefaultClient;
import com.dahuatech.icc.oauth.http.IClient;
import com.xkrs.service.FireEventService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* @Author: XinYi Song
* @Date: 2022/2/11 9:03
*/
@RestController
public class FireEventController {
@Resource
private FireEventService fireEventService;
/**
* 订阅火情事件
*/
@GetMapping("/subscribeFireEvent")
public void subscribeFireEvent() {
try {
//118.24.27.47:6820
String host = "111.53.13.180:4433";
String username = "system";
String password = "Admin@123";
String clientId = "xkrszhcx";
String clientSecret = "eac429df-950a-4cba-aa50-76e47b0a74d8";
System.out.println("----开始执行----{}------事件订阅");
IClient iClient = new DefaultClient(host, username, password, clientId, clientSecret);
EventSubscribeRequest subscribeRequest = new EventSubscribeRequest();
// 接收事件地址
String receiveUrl = "http://118.24.27.47:6820/receiveFireEvent";
String mqinfo = "{\"param\":{\"monitors\":[{\"monitor\":\"" + receiveUrl + "\",\"monitorType\":\"url\",\"events\":[{\"category\":\"business\",\"subscribeAll\":1,\"domainSubscribe\":2,\"authorities\":[{}]},{\"category\":\"alarm\",\"subscribeAll\":1,\"domainSubscribe\":2,\"authorities\":[{}]},{\"category\":\"state\",\"subscribeAll\":1,\"domainSubscribe\":2,\"authorities\":[{}]}]}],\"subsystem\":{\"subsystemType\":0,\"name\":\"118.24.27.47_6820\",\"magic\":\"118.24.27.47_6820\"}}}";
subscribeRequest.body(mqinfo);
EventSubscribeResponse subscribeResponse = iClient.doAction(subscribeRequest, subscribeRequest.getResponseClass());
System.out.println("----结束执行----{}------事件订阅" + subscribeResponse.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 接收火情事件
*/
@PostMapping("/receiveFireEvent")
public void receiveFireEvent(@RequestBody Object fireEvent) {
try {
System.out.println("----接收火情事件----{}------" + fireEvent.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 查询火情事件
*/
@GetMapping("/selectFireEvent")
public String selectFireEvent() {
return fireEventService.selectFireEventList();
}
}

View File

@ -0,0 +1,15 @@
package com.xkrs.dao;
import com.xkrs.model.entity.FireEvent;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Component;
/**
* @Author: XinYi Song
* @Date: 2022/2/8 17:12
*/
@Component
public interface FireEventDao extends JpaRepository<FireEvent, Long>, JpaSpecificationExecutor<FireEvent> {
}

View File

@ -0,0 +1,23 @@
package com.xkrs.model.entity;
import javax.persistence.*;
/**
* 大华推送的火情事件
*/
@Entity
@Table(name = "fire_event")
public class FireEvent {
/**
* 主键id
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "fire_event_seq_gen")
@SequenceGenerator(name = "fire_event_seq_gen", sequenceName = "fire_event_id_seq", allocationSize = 1)
private Integer id;
@Column(length = 85, columnDefinition = "varchar(85)")
private String temp;
}

View File

@ -0,0 +1,11 @@
package com.xkrs.service;
/**
* @Author: XinYi Song
* @Date: 2022/2/11 8:51
*/
public interface FireEventService {
String selectFireEventList();
}

View File

@ -1,7 +1,5 @@
package com.xkrs.service;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @Author: XinYi Song
* @Date: 2022/2/11 8:51
@ -10,6 +8,7 @@ public interface FireService {
/**
* 根据设备编码获取火情信息
*
* @param code
* @return
*/
@ -17,6 +16,7 @@ public interface FireService {
/**
* 根据设备编码和时间段查询火情信息
*
* @param code
* @param startTime
* @param endTime
@ -26,12 +26,14 @@ public interface FireService {
/**
* 查询最新三百条火情信息
*
* @return
*/
String findThreeHundredData();
/**
* 修改火点状态
*
* @param alarmCode
* @return
*/

View File

@ -0,0 +1,30 @@
package com.xkrs.service.impl;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.FireEventDao;
import com.xkrs.model.entity.FireEvent;
import com.xkrs.service.FireEventService;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Locale;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@Service
public class FireEventServiceImpl implements FireEventService {
@Resource
private FireEventDao fireEventDao;
private Locale locale = LocaleContextHolder.getLocale();
@Override
public String selectFireEventList() {
List<FireEvent> fireEventList = fireEventDao.findAll();
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, fireEventList, locale);
}
}

View File

@ -34,9 +34,9 @@ public class FireServerImpl implements FireService {
Locale locale = LocaleContextHolder.getLocale();
/**
* 根据设备编码获取火情的信息
*
* @param code
* @return
*/
@ -52,6 +52,7 @@ public class FireServerImpl implements FireService {
/**
* 根据设备编码和时间段查询火情信息
*
* @param code
* @param startTime
* @param endTime
@ -69,6 +70,7 @@ public class FireServerImpl implements FireService {
/**
* 查询最新300条火情信息
*
* @return
*/
@Cacheable(keyGenerator = "keyGenerator", unless = "#result == null")
@ -84,6 +86,7 @@ public class FireServerImpl implements FireService {
/**
* 修改火点状态
*
* @param alarmCode
* @return
*/