初始化火情事件表

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; 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.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.EquipmentDao; import com.xkrs.dao.EquipmentDao;
import com.xkrs.dao.FireDao; import com.xkrs.dao.FireDao;
@ -136,41 +132,4 @@ public class FireController {
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, map, locale); 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; package com.xkrs.service;
import org.springframework.web.bind.annotation.RequestParam;
/** /**
* @Author: XinYi Song * @Author: XinYi Song
* @Date: 2022/2/11 8:51 * @Date: 2022/2/11 8:51
@ -10,6 +8,7 @@ public interface FireService {
/** /**
* 根据设备编码获取火情信息 * 根据设备编码获取火情信息
*
* @param code * @param code
* @return * @return
*/ */
@ -17,6 +16,7 @@ public interface FireService {
/** /**
* 根据设备编码和时间段查询火情信息 * 根据设备编码和时间段查询火情信息
*
* @param code * @param code
* @param startTime * @param startTime
* @param endTime * @param endTime
@ -26,12 +26,14 @@ public interface FireService {
/** /**
* 查询最新三百条火情信息 * 查询最新三百条火情信息
*
* @return * @return
*/ */
String findThreeHundredData(); String findThreeHundredData();
/** /**
* 修改火点状态 * 修改火点状态
*
* @param alarmCode * @param alarmCode
* @return * @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,71 +34,74 @@ public class FireServerImpl implements FireService {
Locale locale = LocaleContextHolder.getLocale(); Locale locale = LocaleContextHolder.getLocale();
/** /**
* 根据设备编码获取火情的信息 * 根据设备编码获取火情的信息
*
* @param code * @param code
* @return * @return
*/ */
@Cacheable(keyGenerator = "keyGenerator",unless="#result == null") @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null")
@Override @Override
public String getFireInformation(String code) { public String getFireInformation(String code) {
List<Fire> byDeviceCode = fireDao.findByDeviceCode(code); List<Fire> byDeviceCode = fireDao.findByDeviceCode(code);
if(byDeviceCode == null || byDeviceCode.size() == 0){ if (byDeviceCode == null || byDeviceCode.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"暂时没有该设备的火情信息!",locale); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "暂时没有该设备的火情信息!", locale);
} }
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,byDeviceCode,locale); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, byDeviceCode, locale);
} }
/** /**
* 根据设备编码和时间段查询火情信息 * 根据设备编码和时间段查询火情信息
*
* @param code * @param code
* @param startTime * @param startTime
* @param endTime * @param endTime
* @return * @return
*/ */
@Cacheable(keyGenerator = "keyGenerator",unless="#result == null") @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null")
@Override @Override
public String selectFireBetweenTime(String code, String startTime, String endTime) { public String selectFireBetweenTime(String code, String startTime, String endTime) {
List<Fire> fires = query.selectFireBetweenTime(code, startTime, endTime); List<Fire> fires = query.selectFireBetweenTime(code, startTime, endTime);
if(fires == null || fires.size() == 0){ if (fires == null || fires.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时还没有该设备编号或时间段内的火情!",locale); return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有该设备编号或时间段内的火情!", locale);
} }
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,fires,locale); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, fires, locale);
} }
/** /**
* 查询最新300条火情信息 * 查询最新300条火情信息
*
* @return * @return
*/ */
@Cacheable(keyGenerator = "keyGenerator",unless="#result == null") @Cacheable(keyGenerator = "keyGenerator", unless = "#result == null")
@Override @Override
public String findThreeHundredData() { public String findThreeHundredData() {
List<Fire> threeHundredData = fireDao.findThreeHundredData(); List<Fire> threeHundredData = fireDao.findThreeHundredData();
if(threeHundredData == null || threeHundredData.size() == 0){ if (threeHundredData == null || threeHundredData.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有火情信息!",locale); return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有火情信息!", locale);
} }
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,threeHundredData,locale); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, threeHundredData, locale);
} }
/** /**
* 修改火点状态 * 修改火点状态
*
* @param alarmCode * @param alarmCode
* @return * @return
*/ */
@CacheEvict(value = "FireServiceCache",allEntries = true) @CacheEvict(value = "FireServiceCache", allEntries = true)
@Transactional(rollbackOn = Exception.class) @Transactional(rollbackOn = Exception.class)
@Override @Override
public String updateFireState(String alarmCode) { public String updateFireState(String alarmCode) {
Fire byAlarmCode = fireDao.findByAlarmCode(alarmCode); Fire byAlarmCode = fireDao.findByAlarmCode(alarmCode);
if(byAlarmCode == null){ if (byAlarmCode == null) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"火情编码错误,请检查!",locale); return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "火情编码错误,请检查!", locale);
} }
if("1".equals(byAlarmCode.getFireState())){ if ("1".equals(byAlarmCode.getFireState())) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"该火情已处理!",locale); return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "该火情已处理!", locale);
} }
fireDao.updateFireState(alarmCode); fireDao.updateFireState(alarmCode);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"修改成功!",locale); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功!", locale);
} }
} }