Compare commits

...

3 Commits

Author SHA1 Message Date
6e1cf8aafb Merge branch 'master' into dev_fire 2022-03-04 20:30:21 +08:00
36e9d31941 初始化火情事件表 2022-03-04 17:29:00 +08:00
39ea504f16 订阅大华火情事件 2022-03-04 16:40:48 +08:00
10 changed files with 237 additions and 45 deletions

36
pom.xml
View File

@ -31,6 +31,8 @@
<dysmsapi20170525.version>2.0.4</dysmsapi20170525.version>
<hutool-all.version>4.4.3</hutool-all.version>
<tus-client.version>0.4.0</tus-client.version>
<!-- ICCSDK版本 -->
<icc.sdk.version>1.0.9</icc.sdk.version>
</properties>
<dependencies>
@ -94,8 +96,8 @@
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId> mysql</groupId>
<artifactId> mysql-connector-java</artifactId>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
@ -199,6 +201,36 @@
<artifactId>jedis</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- ICC鉴权 -->
<dependency>
<groupId>com.dahuatech.icc</groupId>
<artifactId>java-sdk-oauth</artifactId>
<version>${icc.sdk.version}</version>
</dependency>
<!-- ICC基础资源SDK -->
<dependency>
<groupId>com.dahuatech.icc</groupId>
<artifactId>java-sdk-brm</artifactId>
<version>${icc.sdk.version}</version>
</dependency>
<!-- ICC 事件中心sdk -->
<dependency>
<groupId>com.dahuatech.icc</groupId>
<artifactId>java-sdk-event</artifactId>
<version>${icc.sdk.version}</version>
</dependency>
<!-- h8900sdk -->
<dependency>
<groupId>com.dahuatech.icc</groupId>
<artifactId>java-sdk-h8900</artifactId>
<version>${icc.sdk.version}</version>
</dependency>
</dependencies>
<build>

View File

@ -6,6 +6,7 @@ import org.springframework.jms.annotation.EnableJms;
/**
* 启动类
*
* @author XinYi Song
**/
@SpringBootApplication

View File

@ -3,15 +3,11 @@ package com.xkrs.controller;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.EquipmentDao;
import com.xkrs.dao.FireDao;
import com.xkrs.model.entity.Fire;
import com.xkrs.service.FireService;
import com.xkrs.util.Query;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
@ -40,92 +36,100 @@ public class FireController {
/**
* 根据设备编号获取火情信息
*
* @param code
* @return
*/
@GetMapping("/getFireInformation")
public String getFireInformation(@RequestParam("code") String code){
public String getFireInformation(@RequestParam("code") String code) {
return fireService.getFireInformation(code);
}
/**
* 根据设备编码和时间段查询火情信息
*
* @param code
* @param startTime
* @param endTime
* @return
*/
@GetMapping("/selectFireBetweenTime")
public String selectFireBetweenTime(@RequestParam("code") String code, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime){
return fireService.selectFireBetweenTime(code,startTime,endTime);
public String selectFireBetweenTime(@RequestParam("code") String code, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {
return fireService.selectFireBetweenTime(code, startTime, endTime);
}
/**
* 查询最新的300条火情信息
*
* @return
*/
@GetMapping("/findThreeHundredData")
public String findThreeHundredData(){
public String findThreeHundredData() {
return fireService.findThreeHundredData();
}
/**
* 查询一个月中每一天各个街道的火情数量
*
* @param beginTime
* @param endTime
* @return
*/
@GetMapping("/selectEveryDayCount")
public String selectEveryDayCount(@RequestParam("beginTime") String beginTime,@RequestParam("endTime") String endTime){
public String selectEveryDayCount(@RequestParam("beginTime") String beginTime, @RequestParam("endTime") String endTime) {
List<Map<String, Object>> maps = equipmentDao.selectEveryDayCount(beginTime, endTime);
if(maps == null || maps.size() == 0){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"该月暂时没有火情信息!",locale);
if (maps == null || maps.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "该月暂时没有火情信息!", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, maps, locale);
}
/**
* 查询一年中每个月的各个街道的火情数量
*
* @param beginTime
* @param endTime
* @return
*/
@GetMapping("/selectEveryMonthCount")
public String selectEveryMonthCount(@RequestParam("beginTime") String beginTime,@RequestParam("endTime") String endTime){
public String selectEveryMonthCount(@RequestParam("beginTime") String beginTime, @RequestParam("endTime") String endTime) {
List<Map<String, Object>> maps = equipmentDao.selectEveryMonthCount(beginTime, endTime);
if(maps == null || maps.size() == 0){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"该年暂时没有火情信息!",locale);
if (maps == null || maps.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "该年暂时没有火情信息!", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, maps, locale);
}
/**
* 修改火点状态
*
* @param map
* @return
*/
@PostMapping("/updateFireState")
public String updateFireState(@RequestBody Map map){
public String updateFireState(@RequestBody Map map) {
String alarmCode = (String) map.get("alarmCode");
return fireService.updateFireState(alarmCode);
}
/**
* 查询已处理和未处理的火点的数量
*
* @param street
* @param month
* @return
*/
@GetMapping("/selectProcessedNum")
public String selectProcessedNum(@RequestParam("street") String street,@RequestParam("month") String month){
public String selectProcessedNum(@RequestParam("street") String street, @RequestParam("month") String month) {
Map<String, Object> stringObjectMap = fireDao.selectProcessed(street, month);
BigInteger processed = (BigInteger) stringObjectMap.get("processed");
Map<String, Object> stringObjectMap1 = fireDao.selectNotProcessed(street, month);
BigInteger notprocessed = (BigInteger) stringObjectMap1.get("notprocessed");
Map<String,Object> map = new HashMap<>(3);
map.put("processed",processed);
map.put("notProcessed",notprocessed);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,map,locale);
Map<String, Object> map = new HashMap<>(3);
map.put("processed", processed);
map.put("notProcessed", notprocessed);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, map, locale);
}
}

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,71 +34,74 @@ public class FireServerImpl implements FireService {
Locale locale = LocaleContextHolder.getLocale();
/**
* 根据设备编码获取火情的信息
*
* @param code
* @return
*/
@Cacheable(keyGenerator = "keyGenerator",unless="#result == null")
@Cacheable(keyGenerator = "keyGenerator", unless = "#result == null")
@Override
public String getFireInformation(String code) {
List<Fire> byDeviceCode = fireDao.findByDeviceCode(code);
if(byDeviceCode == null || byDeviceCode.size() == 0){
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"暂时没有该设备的火情信息!",locale);
if (byDeviceCode == null || byDeviceCode.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "暂时没有该设备的火情信息!", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,byDeviceCode,locale);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, byDeviceCode, locale);
}
/**
* 根据设备编码和时间段查询火情信息
*
* @param code
* @param startTime
* @param endTime
* @return
*/
@Cacheable(keyGenerator = "keyGenerator",unless="#result == null")
@Cacheable(keyGenerator = "keyGenerator", unless = "#result == null")
@Override
public String selectFireBetweenTime(String code, String startTime, String endTime) {
List<Fire> fires = query.selectFireBetweenTime(code, startTime, endTime);
if(fires == null || fires.size() == 0){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时还没有该设备编号或时间段内的火情!",locale);
if (fires == null || fires.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有该设备编号或时间段内的火情!", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,fires,locale);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, fires, locale);
}
/**
* 查询最新300条火情信息
*
* @return
*/
@Cacheable(keyGenerator = "keyGenerator",unless="#result == null")
@Cacheable(keyGenerator = "keyGenerator", unless = "#result == null")
@Override
public String findThreeHundredData() {
List<Fire> threeHundredData = fireDao.findThreeHundredData();
if(threeHundredData == null || threeHundredData.size() == 0){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有火情信息!",locale);
if (threeHundredData == null || threeHundredData.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有火情信息!", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,threeHundredData,locale);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, threeHundredData, locale);
}
/**
* 修改火点状态
*
* @param alarmCode
* @return
*/
@CacheEvict(value = "FireServiceCache",allEntries = true)
@CacheEvict(value = "FireServiceCache", allEntries = true)
@Transactional(rollbackOn = Exception.class)
@Override
public String updateFireState(String alarmCode) {
Fire byAlarmCode = fireDao.findByAlarmCode(alarmCode);
if(byAlarmCode == null){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"火情编码错误,请检查!",locale);
if (byAlarmCode == null) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "火情编码错误,请检查!", locale);
}
if("1".equals(byAlarmCode.getFireState())){
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"该火情已处理!",locale);
if ("1".equals(byAlarmCode.getFireState())) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "该火情已处理!", locale);
}
fireDao.updateFireState(alarmCode);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"修改成功!",locale);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功!", locale);
}
}