|
@@ -0,0 +1,91 @@
|
|
|
+package com.sky.ioc.service.security.impl;
|
|
|
+
|
|
|
+import com.sky.ioc.entity.domain.security.SecurityDevice;
|
|
|
+import com.sky.ioc.mapper.job.TokenMapper;
|
|
|
+import com.sky.ioc.mapper.security.SecurityDeviceMapper;
|
|
|
+import com.sky.ioc.service.security.SecurityDeviceService;
|
|
|
+import com.sky.ioc.tool.ReturnMsg;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.HttpMethod;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class SecurityDeviceServiceImpl implements SecurityDeviceService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TokenMapper tokenMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SecurityDeviceMapper securityDeviceMapper;
|
|
|
+
|
|
|
+ final static String SECURITY_CAMERA_URL = "http://192.168.1.45:9001/api/safety/Hikvision/camera/list";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReturnMsg syncAllCameras() {
|
|
|
+ Map<String,String> tokenMap = tokenMapper.getNewToken();
|
|
|
+ String token ="Bearer eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6IjUwZTU1NTRkLWJjYzYtNGRhMS1iZDUxLWFhNTc3YzU4YTFiNCIsInVzZXJuYW1lIjoiYWRtaW4ifQ.X10VPYJfeeRTka7OtqNPOGMpL4QkW3fR_TfCKXCmO-yXbIIrr_40fcwiVnpXfYVENo_BvXWEACRd-Y6nXsbkog";
|
|
|
+ if(tokenMap!=null){
|
|
|
+ token = "Bearer "+tokenMap.get("token");
|
|
|
+ }
|
|
|
+ // 创建一个请求头对象
|
|
|
+ HttpHeaders httpHeaders = new HttpHeaders();
|
|
|
+ // 设置参数
|
|
|
+ httpHeaders.set("authorization", token);
|
|
|
+ // 创建一个响应体对象
|
|
|
+ HttpEntity<String> httpEntity = new HttpEntity(httpHeaders);
|
|
|
+ // 3.创建RestTemplate
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ // 发送GET请求
|
|
|
+ ResponseEntity<Map> responseEntity = restTemplate.exchange(SECURITY_CAMERA_URL, HttpMethod.GET, httpEntity, Map.class);
|
|
|
+ // 获取响应对象里的 body 对象
|
|
|
+ Map<String, Object> body = responseEntity.getBody();
|
|
|
+ // 获取状态码
|
|
|
+ Integer code = (Integer)body.get("code");
|
|
|
+ // 获取响应信息
|
|
|
+ String message = (String)body.get("msg");
|
|
|
+ if(code==200){
|
|
|
+ ArrayList list = (ArrayList) body.get("rows");
|
|
|
+ if(list!=null&&list.size()>0){
|
|
|
+ securityDeviceMapper.delete(null);
|
|
|
+ for (int i=0;i<list.size();i++){
|
|
|
+ LinkedHashMap json = (LinkedHashMap) list.get(i);
|
|
|
+ SecurityDevice device = new SecurityDevice();
|
|
|
+
|
|
|
+ device.setThirdId(json.get("id").toString());
|
|
|
+ device.setDeviceName((String) json.get("cameraName"));
|
|
|
+ device.setDeviceId((String) json.get("cameraIndexCode"));
|
|
|
+ device.setDeviceType(1);
|
|
|
+ device.setDeviceLocation((String) json.get("cameraName"));
|
|
|
+ device.setDeviceAge(0);
|
|
|
+ device.setCompanyId("0");
|
|
|
+ device.setUserId("");
|
|
|
+ device.setDeviceGroup("");
|
|
|
+ device.setStatus(1);
|
|
|
+ securityDeviceMapper.insert(device);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ReturnMsg.ok();
|
|
|
+ }else{
|
|
|
+ log.info("获取摄像头列表数据:"+message);
|
|
|
+ return ReturnMsg.fail(message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReturnMsg getAllCameras() {
|
|
|
+ List<SecurityDevice> securityDevices = securityDeviceMapper.selectList(null);
|
|
|
+ return ReturnMsg.ok(securityDevices);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|