Bladeren bron

新增报警控制器选择报警主机

jiawuxian 2 jaren geleden
bovenliggende
commit
48b980ba35

+ 9 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/controller/ProtectionController.java

@@ -1,6 +1,8 @@
 package com.xunmei.core.resumption.controller;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.xunmei.common.core.exception.ServiceException;
 import com.xunmei.common.core.vo.IdNameVo;
 import com.xunmei.common.core.web.controller.BaseController;
 import com.xunmei.common.core.web.domain.AjaxResult;
@@ -55,13 +57,20 @@ class ProtectionController extends BaseController {
     @PostMapping("edit")
     @RequiresPermissions(value = {"device:protection:add","device:protection:edit"})
     public AjaxResult edit(@RequestBody ProtectionEditDto editDto) {
+        if(ObjectUtil.isNull(editDto.getAlarmHostId())){
+            throw new ServiceException("请选择报警主机");
+        }
         return success(protectionService.edit(editDto));
     }
     @InnerAuth
     @PostMapping("/addByDevice")
     public AjaxResult addByDevice(@RequestBody ProtectionDTO protectionDTO) {
+        if(ObjectUtil.isNull(protectionDTO.getDeviceId())){
+            throw new ServiceException("设备id不能为空");
+        }
         ProtectionEditDto dto=new ProtectionEditDto();
         BeanUtil.copyProperties(protectionDTO, dto);
+        dto.setAlarmHostId(protectionDTO.getDeviceId());
         return success(protectionService.edit(dto));
     }
     @InnerAuth

+ 1 - 3
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/domain/Protection.java

@@ -24,7 +24,6 @@ public class Protection extends BaseEntity {
      * 编号
      */
     @TableId
-    @JsonSerialize(using = ToStringSerializer.class)
     private Long id;
 
     /**
@@ -38,7 +37,7 @@ public class Protection extends BaseEntity {
     private String code;
 
 
-    private Long alarmHostCode;
+    private Long alarmHostId;
 
     /**
      * 防区的名称
@@ -57,7 +56,6 @@ public class Protection extends BaseEntity {
 
     private Integer allHour;
 
-    @JsonSerialize(using = ToStringSerializer.class)
     private Long orgId;
 
     private String orgPath;

+ 6 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/dto/protection/ProtectionEditDto.java

@@ -2,11 +2,16 @@ package com.xunmei.core.resumption.dto.protection;
 
 import lombok.Data;
 
+import javax.validation.constraints.NotNull;
+
 
 @Data
 public class ProtectionEditDto {
     Long id;
-Long deviceId;
+
+    Long deviceId;
+
+    Long alarmHostId;
     /**
      * 所属机构
      */

+ 0 - 6
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/service/impl/ProtectionServiceImpl.java

@@ -103,16 +103,10 @@ public class ProtectionServiceImpl extends ServiceImpl<ProtectionMapper, Protect
         if (dto.getId() != null) {
             protection = getById(dto.getId());
             BeanUtil.copyProperties(dto, protection);
-            if (null!=dto.getDeviceId()){
-                protection.setAlarmHostCode(dto.getDeviceId());
-            }
             updateById(protection);
         } else {
             BeanUtil.copyProperties(dto, protection);
             protection.setStatus("2");
-            if (null!=dto.getDeviceId()){
-                protection.setAlarmHostCode(dto.getDeviceId());
-            }
             save(protection);
         }
 

+ 16 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysDeviceController.java

@@ -1,7 +1,9 @@
 package com.xunmei.system.controller;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
+import com.xunmei.common.core.vo.IdNameVo;
 import com.xunmei.common.security.annotation.InnerAuth;
 import com.xunmei.system.api.domain.SysDevice;
 import com.xunmei.system.api.domain.SysOrg;
@@ -49,6 +51,19 @@ public class SysDeviceController extends BaseController {
         return sysDeviceService.selectPage(sysDevice);
     }
 
+    @ApiOperation(value = "按条件返回当前机构设备id+name")
+    @GetMapping("/listidname")
+    public AjaxResult listIdName(SysDevice sysDevice) {
+        sysDevice.setPageNum(1L);
+        sysDevice.setPageSize(99999L);
+
+        List<?> table = sysDeviceService.selectPage(sysDevice).getRows();
+        List<IdNameVo> voList = table.stream().map(r -> {
+            return new IdNameVo(((SysDevice) r).getId(), ((SysDevice) r).getDeviceName(), "");
+        }).collect(Collectors.toList());
+
+        return success(voList);
+    }
 
     /**
      * 获取【请填写功能名称】详细信息
@@ -111,6 +126,7 @@ public class SysDeviceController extends BaseController {
     public SysDevice getInfoById(Long id) {
         return sysDeviceService.getById(id);
     }
+
     /**
      * 修改【请填写功能名称】
      */