|
@@ -1,9 +1,18 @@
|
|
|
package com.huaxu.controller;
|
|
|
|
|
|
|
|
|
+import com.huaxu.dto.DeviceTypeDto;
|
|
|
import com.huaxu.dto.TreeDataDto;
|
|
|
+import com.huaxu.entity.DeviceAttributeEntity;
|
|
|
+import com.huaxu.entity.DeviceAttributeSpecsEntity;
|
|
|
+import com.huaxu.entity.DeviceParmEntity;
|
|
|
+import com.huaxu.model.AjaxMessage;
|
|
|
+import com.huaxu.model.ResultStatus;
|
|
|
+import com.huaxu.service.DeviceAttributeService;
|
|
|
+import com.huaxu.service.DeviceAttributeSpecsService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.ApiParam;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -15,6 +24,8 @@ import java.util.Date;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import com.huaxu.entity.DeviceTypeEntity;
|
|
|
import com.huaxu.service.DeviceTypeService;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
|
/**
|
|
|
* 设备型号页面控制器
|
|
@@ -28,6 +39,14 @@ public class DeviceTypeController {
|
|
|
|
|
|
@Autowired
|
|
|
private DeviceTypeService deviceTypeService;
|
|
|
+ @Autowired
|
|
|
+ private DeviceAttributeService deviceAttributeService;
|
|
|
+ @Autowired
|
|
|
+ private DeviceAttributeSpecsService deviceAttributeSpecsService;
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+ @Value("${http_pool.requesturl}")
|
|
|
+ private String requestUrl;
|
|
|
|
|
|
@ApiOperation(value = "查询设备类型")
|
|
|
@RequestMapping(value = "/selectList", method = RequestMethod.POST)
|
|
@@ -37,4 +56,42 @@ public class DeviceTypeController {
|
|
|
return treeDataDtos;
|
|
|
}
|
|
|
|
|
|
+ @RequestMapping(value = "batchAdd", method = RequestMethod.POST)
|
|
|
+ @ApiOperation(value = "批量同步设备类型")
|
|
|
+ public AjaxMessage<Integer> batchAdd() {
|
|
|
+ int result = 0;
|
|
|
+ DeviceTypeDto deviceTypeDto = restTemplate.getForObject("http://114.135.61.188:48322/unit/profiles/list", DeviceTypeDto.class);
|
|
|
+ //判断是否存在,不存在则进行添加
|
|
|
+ for (DeviceTypeEntity item : deviceTypeDto.getData()) {
|
|
|
+ if (deviceTypeService.findListByName(item).size() == 0) {
|
|
|
+ item.setCreateBy("admin");
|
|
|
+ item.setDateCreate(new Date());
|
|
|
+ item.setStatus(1);
|
|
|
+ item.setUpdateBy("admin");
|
|
|
+ item.setDateUpdate(new Date());
|
|
|
+ deviceTypeService.save(item);
|
|
|
+ for (DeviceAttributeEntity item2 : item.getProperties()) {
|
|
|
+ item2.setDeviceTypeId(item.getId());
|
|
|
+ item2.setCreateBy("admin");
|
|
|
+ item2.setDateCreate(new Date());
|
|
|
+ item2.setStatus(1);
|
|
|
+ item2.setUpdateBy("admin");
|
|
|
+ item2.setDateUpdate(new Date());
|
|
|
+ deviceAttributeService.save(item2);
|
|
|
+ for (DeviceAttributeSpecsEntity item3 : item2.getSpecs()) {
|
|
|
+ item3.setAttributeId(item2.getId());
|
|
|
+ item3.setCreateBy("admin");
|
|
|
+ item3.setDateCreate(new Date());
|
|
|
+ item3.setStatus(1);
|
|
|
+ item3.setUpdateBy("admin");
|
|
|
+ item3.setDateUpdate(new Date());
|
|
|
+ deviceAttributeSpecsService.save(item3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return new AjaxMessage<>(ResultStatus.OK, result);
|
|
|
+ }
|
|
|
+
|
|
|
}
|