From 1790e32ecf2148d459fb26c1239fe5871386e276 Mon Sep 17 00:00:00 2001 From: XinYi Song <2037158277@qq.com> Date: Fri, 18 Feb 2022 14:19:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E6=8A=A5=E8=AD=A6=E7=BC=96=E7=A0=81=E6=9F=A5=E8=AF=A2=E6=8A=A5?= =?UTF-8?q?=E8=AD=A6=E7=B1=BB=E5=9E=8B=E7=9A=84=E5=8A=9F=E8=83=BD=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/controller/EquipmentController.java | 18 +++++ src/main/java/com/xkrs/dao/AlarmDao.java | 22 ++++++ .../java/com/xkrs/model/entity/Alarm.java | 73 +++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 src/main/java/com/xkrs/dao/AlarmDao.java create mode 100644 src/main/java/com/xkrs/model/entity/Alarm.java diff --git a/src/main/java/com/xkrs/controller/EquipmentController.java b/src/main/java/com/xkrs/controller/EquipmentController.java index ab556e0..8a87800 100644 --- a/src/main/java/com/xkrs/controller/EquipmentController.java +++ b/src/main/java/com/xkrs/controller/EquipmentController.java @@ -9,6 +9,7 @@ import com.xkrs.common.encapsulation.PromptMessageEnum; import com.xkrs.common.tools.GetTokenTool; import com.xkrs.common.tools.GetVideoTool; import com.xkrs.common.tools.JackSonTool; +import com.xkrs.dao.AlarmDao; import com.xkrs.dao.EquipmentDao; import com.xkrs.model.entity.Equipment; import com.xkrs.util.DateTimeUtil; @@ -28,6 +29,9 @@ public class EquipmentController { @Resource private EquipmentDao equipmentDao; + @Resource + private AlarmDao alarmDao; + Locale locale = LocaleContextHolder.getLocale(); /*@GetMapping("/getEquipment") @@ -192,4 +196,18 @@ public class EquipmentController { } return outputEncapsulationObject(PromptMessageEnum.SUCCESS, maps, locale); } + + /** + * 根据报警编码查询报警类型 + * @param alarmCode + * @return + */ + @GetMapping("/findAlarmTypeByCode") + public String findAlarmTypeByCode(@RequestParam("alarmCode") String alarmCode){ + String alarmTypeByCode = alarmDao.findAlarmTypeByCode(alarmCode); + if(alarmTypeByCode == null || "".equals(alarmTypeByCode)){ + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该编号的报警类型!", locale); + } + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, alarmTypeByCode, locale); + } } diff --git a/src/main/java/com/xkrs/dao/AlarmDao.java b/src/main/java/com/xkrs/dao/AlarmDao.java new file mode 100644 index 0000000..b7e54a5 --- /dev/null +++ b/src/main/java/com/xkrs/dao/AlarmDao.java @@ -0,0 +1,22 @@ +package com.xkrs.dao; + +import com.xkrs.model.entity.Alarm; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Component; + +/** + * @Author: XinYi Song + * @Date: 2022/2/18 11:58 + */ +@Component +public interface AlarmDao extends JpaRepository { + + /** + * 根据报警编号查询报警类型 + * @param code + * @return + */ + @Query(value = "select alarm_type from alarm where alarm_code = ?",nativeQuery = true) + String findAlarmTypeByCode(String code); +} diff --git a/src/main/java/com/xkrs/model/entity/Alarm.java b/src/main/java/com/xkrs/model/entity/Alarm.java new file mode 100644 index 0000000..f72a39a --- /dev/null +++ b/src/main/java/com/xkrs/model/entity/Alarm.java @@ -0,0 +1,73 @@ +package com.xkrs.model.entity; + +import javax.persistence.*; + +/** + * @Author: XinYi Song + * @Date: 2022/2/18 11:37 + */ +@Entity +@Table(name = "alarm") +public class Alarm { + /** + * 主键id + */ + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "alarm_seq_gen") + @SequenceGenerator(name = "alarm_seq_gen", sequenceName = "alarm_id_seq",allocationSize = 1) + private Integer id; + + /** + * 报警类型 + */ + @Column(length = 32, columnDefinition = "varchar(32)") + private String alarmType; + + /** + * 报警编码 + */ + @Column(length = 32, columnDefinition = "varchar(32)") + private String alarmCode; + + public Alarm() { + } + + public Alarm(Integer id, String alarmType, String alarmCode) { + this.id = id; + this.alarmType = alarmType; + this.alarmCode = alarmCode; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getAlarmType() { + return alarmType; + } + + public void setAlarmType(String alarmType) { + this.alarmType = alarmType; + } + + public String getAlarmCode() { + return alarmCode; + } + + public void setAlarmCode(String alarmCode) { + this.alarmCode = alarmCode; + } + + @Override + public String toString() { + return "Alarm{" + + "id=" + id + + ", alarmType='" + alarmType + '\'' + + ", alarmCode='" + alarmCode + '\'' + + '}'; + } +}