diff --git a/src/main/java/com/xkrs/controller/FireController.java b/src/main/java/com/xkrs/controller/FireController.java index 9559f50..cf52959 100644 --- a/src/main/java/com/xkrs/controller/FireController.java +++ b/src/main/java/com/xkrs/controller/FireController.java @@ -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(); - } - } } diff --git a/src/main/java/com/xkrs/controller/FireEventController.java b/src/main/java/com/xkrs/controller/FireEventController.java new file mode 100644 index 0000000..853819f --- /dev/null +++ b/src/main/java/com/xkrs/controller/FireEventController.java @@ -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(); + } + +} diff --git a/src/main/java/com/xkrs/dao/FireEventDao.java b/src/main/java/com/xkrs/dao/FireEventDao.java new file mode 100644 index 0000000..ae9d293 --- /dev/null +++ b/src/main/java/com/xkrs/dao/FireEventDao.java @@ -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, JpaSpecificationExecutor { + +} diff --git a/src/main/java/com/xkrs/model/entity/FireEvent.java b/src/main/java/com/xkrs/model/entity/FireEvent.java new file mode 100644 index 0000000..86ac0af --- /dev/null +++ b/src/main/java/com/xkrs/model/entity/FireEvent.java @@ -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; + +} diff --git a/src/main/java/com/xkrs/service/FireEventService.java b/src/main/java/com/xkrs/service/FireEventService.java new file mode 100644 index 0000000..47717fc --- /dev/null +++ b/src/main/java/com/xkrs/service/FireEventService.java @@ -0,0 +1,11 @@ +package com.xkrs.service; + +/** + * @Author: XinYi Song + * @Date: 2022/2/11 8:51 + */ +public interface FireEventService { + + String selectFireEventList(); + +} diff --git a/src/main/java/com/xkrs/service/FireService.java b/src/main/java/com/xkrs/service/FireService.java index b40b49f..26d5af5 100644 --- a/src/main/java/com/xkrs/service/FireService.java +++ b/src/main/java/com/xkrs/service/FireService.java @@ -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 */ diff --git a/src/main/java/com/xkrs/service/impl/FireEventServiceImpl.java b/src/main/java/com/xkrs/service/impl/FireEventServiceImpl.java new file mode 100644 index 0000000..6ed2f24 --- /dev/null +++ b/src/main/java/com/xkrs/service/impl/FireEventServiceImpl.java @@ -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 fireEventList = fireEventDao.findAll(); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, fireEventList, locale); + } + +} diff --git a/src/main/java/com/xkrs/service/impl/FireServerImpl.java b/src/main/java/com/xkrs/service/impl/FireServerImpl.java index beaef54..bebdb7c 100644 --- a/src/main/java/com/xkrs/service/impl/FireServerImpl.java +++ b/src/main/java/com/xkrs/service/impl/FireServerImpl.java @@ -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 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 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 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); } }