2024-01-11 15:17:27 +08:00
|
|
|
|
package com.zcloud.util;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.zcloud.entity.PageData;
|
|
|
|
|
import com.zcloud.service.corp.CorpPlsInfoService;
|
|
|
|
|
import com.zcloud.service.system.UsersService;
|
|
|
|
|
import okhttp3.*;
|
2024-01-25 14:20:05 +08:00
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
2024-01-11 15:17:27 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2024-01-25 14:42:22 +08:00
|
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
|
import org.springframework.http.HttpMethod;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
2024-01-25 14:20:05 +08:00
|
|
|
|
import org.springframework.stereotype.Component;
|
2024-01-26 15:54:26 +08:00
|
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
import org.springframework.util.MultiValueMap;
|
2024-01-25 14:42:22 +08:00
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
2024-01-11 15:17:27 +08:00
|
|
|
|
|
2024-01-25 14:20:05 +08:00
|
|
|
|
import javax.annotation.PostConstruct;
|
2024-01-11 15:17:27 +08:00
|
|
|
|
import java.io.IOException;
|
2024-01-25 14:20:05 +08:00
|
|
|
|
import java.util.*;
|
2024-01-11 15:17:27 +08:00
|
|
|
|
|
2024-01-25 14:20:05 +08:00
|
|
|
|
@Component
|
2024-01-11 15:17:27 +08:00
|
|
|
|
public class PLSUtil {
|
2024-01-25 14:20:05 +08:00
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(PLSUtil.class);
|
|
|
|
|
|
|
|
|
|
private static CorpPlsInfoService corpplsinfoService;
|
|
|
|
|
private static UsersService usersService;
|
|
|
|
|
// 后台地址
|
|
|
|
|
public static HashMap<String, String> BAKEADDR = new HashMap<>();
|
2024-01-25 14:42:22 +08:00
|
|
|
|
private static RestTemplate restTemplate;
|
2024-01-25 16:37:20 +08:00
|
|
|
|
|
2024-01-29 10:18:20 +08:00
|
|
|
|
public static JSONObject getPersonnelPositioningCount(String CORPINFO_ID, Integer currentPage, Integer showCount) throws Exception {
|
2024-01-27 11:29:26 +08:00
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
headers.set("Authorization", getToken(CORPINFO_ID));
|
|
|
|
|
HttpEntity<JSONObject> httpEntity = new HttpEntity<>(headers);
|
|
|
|
|
ResponseEntity<JSONObject> exchange = restTemplate.exchange(
|
|
|
|
|
PLSUtil.BAKEADDR.get(CORPINFO_ID) + "/deploy/card/list?sortThePowerLevel=1&pageNum=" +
|
|
|
|
|
currentPage +
|
|
|
|
|
"&pageSize=" + showCount,
|
|
|
|
|
HttpMethod.GET, httpEntity,
|
|
|
|
|
JSONObject.class);
|
|
|
|
|
return exchange.getBody();
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-11 15:17:27 +08:00
|
|
|
|
@Autowired
|
2024-01-25 16:37:20 +08:00
|
|
|
|
public void setCorpplsinfoService(CorpPlsInfoService corpplsinfoServicebean, UsersService usersServicebean, RestTemplate restTemplatebean) {
|
2024-01-25 14:20:05 +08:00
|
|
|
|
corpplsinfoService = corpplsinfoServicebean;
|
|
|
|
|
usersService = usersServicebean;
|
2024-01-25 14:42:22 +08:00
|
|
|
|
restTemplate = restTemplatebean;
|
|
|
|
|
}
|
2024-01-25 16:37:20 +08:00
|
|
|
|
|
2024-01-27 11:29:26 +08:00
|
|
|
|
/**
|
|
|
|
|
* @Description: 告警类型统计
|
|
|
|
|
* @Author: dearLin
|
|
|
|
|
* @Date: 2024/1/25/025 14:37
|
|
|
|
|
* @Param: [java.lang.String, java.lang.Integer, java.lang.Integer] [keywords, currentPage, showCount]
|
|
|
|
|
* @Return: com.alibaba.fastjson.JSONObject
|
|
|
|
|
*/
|
|
|
|
|
public static JSONObject getAlarmTypeCount(String CORPINFO_ID) throws Exception {
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
headers.set("Authorization", getToken(CORPINFO_ID));
|
|
|
|
|
HttpEntity<JSONObject> httpEntity = new HttpEntity<>(headers);
|
|
|
|
|
ResponseEntity<JSONObject> exchange = restTemplate.exchange(
|
|
|
|
|
PLSUtil.BAKEADDR.get(CORPINFO_ID) + "/region/alarm/alarmStatistics?type=day",
|
|
|
|
|
HttpMethod.GET, httpEntity,
|
|
|
|
|
JSONObject.class);
|
|
|
|
|
return exchange.getBody();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-01-26 15:54:26 +08:00
|
|
|
|
/**
|
|
|
|
|
* @Description: 添加摄像头
|
|
|
|
|
* @Author: dearLin
|
|
|
|
|
* @Date: 2024/1/25/025 14:37
|
|
|
|
|
* @Param: [java.lang.String, java.lang.Integer, java.lang.Integer] [keywords, currentPage, showCount]
|
|
|
|
|
* @Return: com.alibaba.fastjson.JSONObject
|
|
|
|
|
*/
|
|
|
|
|
public static JSONObject saveCamera(String CORPINFO_ID, PageData camera) throws Exception {
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
headers.set("Authorization", getToken(CORPINFO_ID));
|
|
|
|
|
headers.setContentType(org.springframework.http.MediaType.valueOf("application/json"));
|
|
|
|
|
JSONObject uriVariables = new JSONObject();
|
2024-01-27 11:29:26 +08:00
|
|
|
|
uriVariables.put("camNo", camera.getString("CODE"));
|
|
|
|
|
uriVariables.put("camName", camera.getString("VIDEONAME"));
|
|
|
|
|
uriVariables.put("camIp", "127.0.0.1");
|
|
|
|
|
uriVariables.put("type", "0");
|
|
|
|
|
uriVariables.put("port", "");
|
|
|
|
|
uriVariables.put("camUserName", "1");
|
|
|
|
|
uriVariables.put("camPassword", "1");
|
|
|
|
|
uriVariables.put("lon", "");
|
|
|
|
|
uriVariables.put("lat", "");
|
|
|
|
|
uriVariables.put("alt", "");
|
|
|
|
|
HttpEntity<JSONObject> httpEntity = new HttpEntity<>(uriVariables, headers);
|
2024-01-26 15:54:26 +08:00
|
|
|
|
// HttpEntity<JSONObject> httpEntity = new HttpEntity<>(uriVariables,headers);
|
|
|
|
|
// ResponseEntity<JSONObject> jsonObjectResponseEntity = restTemplate.postForEntity(PLSUtil.BAKEADDR.get(CORPINFO_ID) + "/device/camera",
|
|
|
|
|
// httpEntity, JSONObject.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ResponseEntity<JSONObject> exchange = restTemplate.exchange(PLSUtil.BAKEADDR.get(CORPINFO_ID) + "/device/camera",
|
|
|
|
|
HttpMethod.POST,
|
|
|
|
|
httpEntity,
|
|
|
|
|
JSONObject.class);
|
|
|
|
|
return exchange.getBody();
|
|
|
|
|
}
|
2024-01-27 11:29:26 +08:00
|
|
|
|
|
2024-01-26 15:54:26 +08:00
|
|
|
|
/**
|
|
|
|
|
* @Description: 修改摄像头
|
|
|
|
|
* @Author: dearLin
|
|
|
|
|
* @Date: 2024/1/25/025 14:37
|
|
|
|
|
* @Param: [java.lang.String, java.lang.Integer, java.lang.Integer] [keywords, currentPage, showCount]
|
|
|
|
|
* @Return: com.alibaba.fastjson.JSONObject
|
|
|
|
|
*/
|
|
|
|
|
public static JSONObject editCamera(String CORPINFO_ID, PageData camera) throws Exception {
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
headers.set("Authorization", getToken(CORPINFO_ID));
|
|
|
|
|
headers.setContentType(org.springframework.http.MediaType.valueOf("application/json"));
|
|
|
|
|
JSONObject uriVariables = new JSONObject();
|
2024-01-27 11:29:26 +08:00
|
|
|
|
uriVariables.put("camNo", camera.getString("CODE"));
|
|
|
|
|
uriVariables.put("camName", camera.getString("VIDEONAME"));
|
|
|
|
|
uriVariables.put("camId", camera.getString("PLS_ID"));
|
|
|
|
|
HttpEntity<JSONObject> httpEntity = new HttpEntity<>(uriVariables, headers);
|
2024-01-26 15:54:26 +08:00
|
|
|
|
ResponseEntity<JSONObject> exchange = restTemplate.exchange(PLSUtil.BAKEADDR.get(CORPINFO_ID) + "/device/camera",
|
|
|
|
|
HttpMethod.PUT, httpEntity,
|
2024-01-27 11:29:26 +08:00
|
|
|
|
JSONObject.class, uriVariables);
|
2024-01-26 15:54:26 +08:00
|
|
|
|
return exchange.getBody();
|
|
|
|
|
}
|
2024-01-27 11:29:26 +08:00
|
|
|
|
|
2024-01-26 15:54:26 +08:00
|
|
|
|
/**
|
|
|
|
|
* @Description: 删除摄像头
|
|
|
|
|
* @Author: dearLin
|
|
|
|
|
* @Date: 2024/1/25/025 14:37
|
|
|
|
|
* @Param: [java.lang.String, java.lang.Integer, java.lang.Integer] [keywords, currentPage, showCount]
|
|
|
|
|
* @Return: com.alibaba.fastjson.JSONObject
|
|
|
|
|
*/
|
|
|
|
|
public static JSONObject removeCamera(String CORPINFO_ID, PageData camera) throws Exception {
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
headers.set("Authorization", getToken(CORPINFO_ID));
|
|
|
|
|
HttpEntity<JSONObject> httpEntity = new HttpEntity<>(headers);
|
2024-01-27 11:29:26 +08:00
|
|
|
|
ResponseEntity<JSONObject> exchange = restTemplate.exchange(PLSUtil.BAKEADDR.get(CORPINFO_ID) + "/device/camera/" + Integer.parseInt(camera.getString("PLS_ID")), HttpMethod.DELETE, httpEntity, JSONObject.class);
|
2024-01-26 15:54:26 +08:00
|
|
|
|
return exchange.getBody();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-01-25 14:42:22 +08:00
|
|
|
|
/**
|
|
|
|
|
* @Description: 电子围栏列表
|
|
|
|
|
* @Author: dearLin
|
|
|
|
|
* @Date: 2024/1/25/025 14:37
|
|
|
|
|
* @Param: [java.lang.String, java.lang.Integer, java.lang.Integer] [keywords, currentPage, showCount]
|
|
|
|
|
* @Return: com.alibaba.fastjson.JSONObject
|
|
|
|
|
*/
|
2024-01-25 16:37:20 +08:00
|
|
|
|
public static JSONObject getRyRegionList(String CORPINFO_ID, String keywords, Integer currentPage, Integer showCount) throws Exception {
|
2024-01-25 14:42:22 +08:00
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
|
2024-01-25 15:57:47 +08:00
|
|
|
|
headers.set("Authorization", getToken(CORPINFO_ID));
|
2024-01-25 14:42:22 +08:00
|
|
|
|
HttpEntity<JSONObject> httpEntity = new HttpEntity<>(headers);
|
2024-01-25 15:57:47 +08:00
|
|
|
|
ResponseEntity<JSONObject> exchange = restTemplate.exchange(PLSUtil.BAKEADDR.get(CORPINFO_ID) + "/region/region/list?pageNum=" +
|
2024-01-25 14:42:22 +08:00
|
|
|
|
currentPage +
|
|
|
|
|
"&pageSize=" + showCount +
|
|
|
|
|
"&str=" + keywords + "&type=0", HttpMethod.GET, httpEntity, JSONObject.class);
|
|
|
|
|
return exchange.getBody();
|
2024-01-25 14:20:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 10:38:22 +08:00
|
|
|
|
/**
|
|
|
|
|
* @Description: 电子围栏详情
|
|
|
|
|
* @Param: [java.lang.String, java.lang.Integer] [CORPINFO_ID, id]
|
|
|
|
|
* @Return: com.alibaba.fastjson.JSONObject
|
|
|
|
|
*/
|
|
|
|
|
public static JSONObject getRyRegionInfo(String CORPINFO_ID, int id) throws Exception {
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
|
|
|
|
|
headers.set("Authorization", getToken(CORPINFO_ID));
|
|
|
|
|
HttpEntity<JSONObject> httpEntity = new HttpEntity<>(headers);
|
|
|
|
|
ResponseEntity<JSONObject> exchange = restTemplate.exchange(PLSUtil.BAKEADDR.get(CORPINFO_ID) + "/region/region/" +
|
|
|
|
|
id, HttpMethod.GET, httpEntity, JSONObject.class);
|
|
|
|
|
return exchange.getBody();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description: 当前在线人员实时位置信息
|
|
|
|
|
* @Date: 2024/1/25/025 14:37
|
|
|
|
|
* @Return: com.alibaba.fastjson.JSONObject
|
|
|
|
|
*/
|
|
|
|
|
public static JSONObject getRealTimeList(String CORPINFO_ID) throws Exception {
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
|
|
|
|
|
headers.set("Authorization", getToken(CORPINFO_ID));
|
|
|
|
|
HttpEntity<JSONObject> httpEntity = new HttpEntity<>(headers);
|
|
|
|
|
ResponseEntity<JSONObject> exchange = restTemplate.exchange(PLSUtil.BAKEADDR.get(CORPINFO_ID) + "/api/prod-api/coordinate/realTime/data", HttpMethod.GET, httpEntity, JSONObject.class);
|
|
|
|
|
return exchange.getBody();
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-25 16:37:20 +08:00
|
|
|
|
/**
|
2024-01-25 17:24:05 +08:00
|
|
|
|
* @Description: 根据定位卡号获取人是否再电子围栏里
|
2024-01-25 16:37:20 +08:00
|
|
|
|
* @Author: dearLin
|
|
|
|
|
* @Date: 2024/1/25/025 14:37
|
|
|
|
|
* @Param: [java.lang.String, java.lang.Integer, java.lang.Integer] [keywords, currentPage, showCount]
|
|
|
|
|
* @Return: com.alibaba.fastjson.JSONObject
|
|
|
|
|
*/
|
2024-01-25 17:24:05 +08:00
|
|
|
|
public static Boolean determineWhetherThePersonIsInTheElectronicFence(String CORPINFO_ID, Integer PLS_ID, String ELECTRONIC_FENCE_ID) throws Exception {
|
2024-01-25 16:37:20 +08:00
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
headers.set("Authorization", getToken(CORPINFO_ID));
|
|
|
|
|
HttpEntity<JSONObject> httpEntity = new HttpEntity<>(headers);
|
2024-01-25 17:24:05 +08:00
|
|
|
|
ResponseEntity<Boolean> exchange = restTemplate.exchange(PLSUtil.BAKEADDR.get(CORPINFO_ID) + "/region/api/electronicFence/determineWhetherThePersonIsInTheElectronicFence2?psn=" +
|
2024-01-25 16:37:20 +08:00
|
|
|
|
PLS_ID +
|
2024-01-30 15:36:15 +08:00
|
|
|
|
"&id=" + ELECTRONIC_FENCE_ID, HttpMethod.GET, httpEntity, Boolean.class);
|
2024-01-25 16:37:20 +08:00
|
|
|
|
return exchange.getBody();
|
|
|
|
|
}
|
2024-01-25 14:42:22 +08:00
|
|
|
|
|
|
|
|
|
|
2024-01-25 14:20:05 +08:00
|
|
|
|
@PostConstruct
|
|
|
|
|
private void initBakeAddr() throws Exception {
|
|
|
|
|
List<PageData> dataList = corpplsinfoService.listAll(new PageData());
|
|
|
|
|
dataList.forEach(item -> {
|
|
|
|
|
BAKEADDR.put(item.getString("CORPINFO_ID"), item.getString("POST_URL"));
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-01-11 15:17:27 +08:00
|
|
|
|
|
2024-01-12 16:40:52 +08:00
|
|
|
|
/**
|
2024-01-25 14:20:05 +08:00
|
|
|
|
* @Description: 获取token
|
|
|
|
|
* @Author: dearLin
|
|
|
|
|
* @Date: 2024/1/24/024 9:59
|
|
|
|
|
* @Param: [] []
|
|
|
|
|
* @Return: java.lang.String
|
2024-01-12 16:40:52 +08:00
|
|
|
|
*/
|
2024-01-25 15:57:47 +08:00
|
|
|
|
public static String getToken(String CORPINFO_ID) throws Exception {
|
2024-01-25 14:20:05 +08:00
|
|
|
|
PageData pd = new PageData();
|
2024-01-25 15:57:47 +08:00
|
|
|
|
pd.put("CORPINFO_ID", CORPINFO_ID);
|
2024-01-11 15:17:27 +08:00
|
|
|
|
pd = corpplsinfoService.findById(pd);
|
|
|
|
|
String token = pd.getString("TOKEN");
|
2024-01-25 14:20:05 +08:00
|
|
|
|
String backAddr = pd.getString("POST_URL");
|
2024-01-11 15:17:27 +08:00
|
|
|
|
String expireTime = pd.getString("EXPIRE_TIME");
|
|
|
|
|
String userName = pd.getString("ACCOUNT");
|
|
|
|
|
String passWord = pd.getString("PASSWORD");
|
|
|
|
|
String loginUrl = pd.getString("POST_URL") + "/auth/login";
|
|
|
|
|
if (token == null || expireTime == null || expireTime.trim().isEmpty() || DateUtil.compareDate(DateUtil.getTime(), expireTime)) {
|
|
|
|
|
JSONObject loginPayload = new JSONObject();
|
|
|
|
|
loginPayload.put("username", userName);
|
|
|
|
|
loginPayload.put("password", passWord);
|
|
|
|
|
loginPayload.put("isPresentationMode", "2");
|
2024-01-25 14:20:05 +08:00
|
|
|
|
PageData response = sendPostHttpRequest(loginUrl, loginPayload.toJSONString(), null);
|
|
|
|
|
if (response != null) {
|
|
|
|
|
PageData valueData = JSONObject.parseObject(response.getString("data"), PageData.class);
|
|
|
|
|
token = valueData.getString("access_token");
|
|
|
|
|
String newExpireTime = DateUtil.getAfterHourDate("12");
|
2024-01-11 15:17:27 +08:00
|
|
|
|
pd.put("TOKEN", token);
|
|
|
|
|
pd.put("EXPIRE_TIME", newExpireTime);
|
|
|
|
|
corpplsinfoService.edit(pd);
|
2024-01-25 14:20:05 +08:00
|
|
|
|
return token;
|
2024-01-11 15:17:27 +08:00
|
|
|
|
} else {
|
2024-01-25 14:20:05 +08:00
|
|
|
|
System.out.println("登录失败");
|
2024-01-11 15:17:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-25 14:20:05 +08:00
|
|
|
|
return token;
|
2024-01-11 15:17:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-11 18:02:48 +08:00
|
|
|
|
|
2024-01-12 16:40:52 +08:00
|
|
|
|
/**
|
2024-01-25 14:20:05 +08:00
|
|
|
|
* @Description: 查询这个人的定位卡号是否存在
|
|
|
|
|
* @Author: dearLin
|
|
|
|
|
* @Date: 2024/1/24/024 10:00
|
|
|
|
|
* @Param: [com.zcloud.entity.PageData] [user]
|
|
|
|
|
* @Return: void
|
2024-01-12 16:40:52 +08:00
|
|
|
|
*/
|
2024-01-25 14:20:05 +08:00
|
|
|
|
public static boolean hasCardNumber(PageData user) throws Exception {
|
|
|
|
|
// 根据 定位卡号获取对应的人
|
|
|
|
|
String url = BAKEADDR.get(Jurisdiction.getCORPINFO_ID()) + "/deploy/card/peopleDisplay/" + user.getString("CARDNO");
|
2024-01-25 15:57:47 +08:00
|
|
|
|
PageData response = sendGetHttpRequest(url, null, getToken(Jurisdiction.getCORPINFO_ID()));
|
2024-01-25 14:20:05 +08:00
|
|
|
|
if (response != null) {
|
|
|
|
|
if (!"200".equals(response.getString("code"))) {
|
|
|
|
|
return false;
|
2024-01-12 16:40:52 +08:00
|
|
|
|
}
|
2024-01-25 14:20:05 +08:00
|
|
|
|
List<PageData> dataList = JSONObject.parseArray(response.getString("data"), PageData.class);
|
|
|
|
|
return dataList.isEmpty();
|
2024-01-12 16:40:52 +08:00
|
|
|
|
}
|
2024-01-25 14:20:05 +08:00
|
|
|
|
return false;
|
2024-01-12 16:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-01-25 14:20:05 +08:00
|
|
|
|
* @Description: 查询这个人的定位卡号是否存在
|
|
|
|
|
* @Author: dearLin
|
|
|
|
|
* @Date: 2024/1/24/024 10:00
|
|
|
|
|
* @Param: [com.zcloud.entity.PageData] [user]
|
|
|
|
|
* @Return: void
|
2024-01-12 16:40:52 +08:00
|
|
|
|
*/
|
2024-01-25 14:20:05 +08:00
|
|
|
|
public static PageData getCardNumberPeople(PageData user) throws Exception {
|
|
|
|
|
// 根据 定位卡号获取对应的人
|
|
|
|
|
String url = BAKEADDR.get(Jurisdiction.getCORPINFO_ID()) + "/deploy/card/peopleDisplay/" + user.getString("CARDNO");
|
2024-01-25 15:57:47 +08:00
|
|
|
|
PageData response = sendGetHttpRequest(url, null, getToken(Jurisdiction.getCORPINFO_ID()));
|
2024-01-25 14:20:05 +08:00
|
|
|
|
if (response != null) {
|
|
|
|
|
if (!"200".equals(response.getString("code"))) {
|
|
|
|
|
return null;
|
2024-01-12 16:40:52 +08:00
|
|
|
|
}
|
2024-01-25 14:20:05 +08:00
|
|
|
|
List<PageData> dataList = JSONObject.parseArray(response.getString("data"), PageData.class);
|
|
|
|
|
return dataList.size() > 0 ? dataList.get(0) : null;
|
2024-01-12 16:40:52 +08:00
|
|
|
|
}
|
2024-01-25 14:20:05 +08:00
|
|
|
|
return null;
|
2024-01-12 16:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-01-25 14:20:05 +08:00
|
|
|
|
* @Description: 把人新增到 人员定位系统
|
|
|
|
|
* @Author: dearLin
|
|
|
|
|
* @Date: 2024/1/24/024 10:00
|
|
|
|
|
* @Param: [com.zcloud.entity.PageData] [user]
|
|
|
|
|
* @Return: void
|
2024-01-12 16:40:52 +08:00
|
|
|
|
*/
|
2024-01-26 15:54:26 +08:00
|
|
|
|
public static PageData saveUser(PageData user) throws Exception {
|
2024-01-25 14:20:05 +08:00
|
|
|
|
String url = BAKEADDR.get(Jurisdiction.getCORPINFO_ID()) + "/deploy/psnmgt/insertPsnIfon";
|
|
|
|
|
JSONObject loginPayload = new JSONObject();
|
|
|
|
|
loginPayload.put("name", user.getString("NAME"));
|
|
|
|
|
loginPayload.put("cardNo", user.getString("CARDNO"));
|
|
|
|
|
loginPayload.put("empNo", "");
|
|
|
|
|
loginPayload.put("sex", "");
|
|
|
|
|
loginPayload.put("certType", "");
|
|
|
|
|
loginPayload.put("certNo", "");
|
|
|
|
|
loginPayload.put("office", "");
|
|
|
|
|
loginPayload.put("staffType", "");
|
|
|
|
|
loginPayload.put("phone", "");
|
|
|
|
|
loginPayload.put("empId", "");
|
|
|
|
|
loginPayload.put("age", "");
|
|
|
|
|
loginPayload.put("addr", "");
|
|
|
|
|
loginPayload.put("remark", "");
|
|
|
|
|
loginPayload.put("enterpriseName", "");
|
|
|
|
|
loginPayload.put("officeName", "");
|
|
|
|
|
loginPayload.put("jobsName", "");
|
|
|
|
|
loginPayload.put("deptName", "");
|
|
|
|
|
loginPayload.put("deptId", "");
|
|
|
|
|
loginPayload.put("avatar", "");
|
2024-01-26 15:54:26 +08:00
|
|
|
|
return sendPostHttpRequest(url, loginPayload.toJSONString(), getToken(Jurisdiction.getCORPINFO_ID()));
|
|
|
|
|
|
2024-01-12 16:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-01-25 14:20:05 +08:00
|
|
|
|
* @Description: 把人新增到 人员定位系统
|
|
|
|
|
* @Author: dearLin
|
|
|
|
|
* @Date: 2024/1/24/024 10:00
|
|
|
|
|
* @Param: [com.zcloud.entity.PageData] [user]
|
|
|
|
|
* @Return: void
|
2024-01-12 16:40:52 +08:00
|
|
|
|
*/
|
2024-01-25 14:20:05 +08:00
|
|
|
|
public static boolean editUser(PageData user) throws Exception {
|
2024-01-26 15:54:26 +08:00
|
|
|
|
// 这个人没有卡号与人id的话
|
|
|
|
|
if (!Tools.notEmpty(user.getString("PLS_ID"))) {
|
|
|
|
|
PageData response = saveUser(user);
|
|
|
|
|
if ("200".equals(response.getString("code"))) {
|
|
|
|
|
user.put("PLS_ID", response.getString("data"));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-01-25 14:20:05 +08:00
|
|
|
|
String url = BAKEADDR.get(Jurisdiction.getCORPINFO_ID()) + "/deploy/psnmgt/updPsnInfoById";
|
|
|
|
|
JSONObject loginPayload = new JSONObject();
|
|
|
|
|
loginPayload.put("name", user.getString("NAME"));
|
|
|
|
|
loginPayload.put("psnId", user.getString("PLS_ID"));
|
|
|
|
|
loginPayload.put("cardNo", user.getString("CARDNO"));
|
|
|
|
|
loginPayload.put("empNo", "");
|
|
|
|
|
loginPayload.put("sex", "");
|
|
|
|
|
loginPayload.put("certType", "");
|
|
|
|
|
loginPayload.put("certNo", "");
|
|
|
|
|
loginPayload.put("office", "");
|
|
|
|
|
loginPayload.put("staffType", "");
|
|
|
|
|
loginPayload.put("phone", "");
|
|
|
|
|
loginPayload.put("empId", "");
|
|
|
|
|
loginPayload.put("age", "");
|
|
|
|
|
loginPayload.put("addr", "");
|
|
|
|
|
loginPayload.put("remark", "");
|
|
|
|
|
loginPayload.put("enterpriseName", "");
|
|
|
|
|
loginPayload.put("officeName", "");
|
|
|
|
|
loginPayload.put("jobsName", "");
|
|
|
|
|
loginPayload.put("deptName", "");
|
|
|
|
|
loginPayload.put("deptId", "");
|
|
|
|
|
loginPayload.put("avatar", "");
|
2024-01-25 15:57:47 +08:00
|
|
|
|
PageData response = sendPostHttpRequest(url, loginPayload.toJSONString(), getToken(Jurisdiction.getCORPINFO_ID()));
|
2024-01-25 14:20:05 +08:00
|
|
|
|
return "200".equals(response.getString("code"));
|
|
|
|
|
}
|
2024-01-25 16:37:20 +08:00
|
|
|
|
|
2024-01-25 14:20:05 +08:00
|
|
|
|
public static boolean removeUser(PageData user) throws Exception {
|
|
|
|
|
String url = BAKEADDR.get(Jurisdiction.getCORPINFO_ID()) + "/deploy/psnmgt";
|
|
|
|
|
PageData removeUser = usersService.findById(user);
|
2024-01-25 15:57:47 +08:00
|
|
|
|
PageData response = sendDeleteHttpRequest(url, Long.parseLong(removeUser.getString("PLS_ID")), getToken(Jurisdiction.getCORPINFO_ID()));
|
2024-01-25 14:20:05 +08:00
|
|
|
|
return "200".equals(response.getString("code"));
|
2024-01-12 16:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-01-25 14:20:05 +08:00
|
|
|
|
* 发送get类型请求
|
|
|
|
|
*
|
|
|
|
|
* @param url
|
|
|
|
|
* @param queryParams
|
|
|
|
|
* @param token
|
|
|
|
|
* @return PageData
|
|
|
|
|
* @throws IOException
|
2024-01-12 16:40:52 +08:00
|
|
|
|
*/
|
|
|
|
|
|
2024-01-25 14:20:05 +08:00
|
|
|
|
private static PageData sendGetHttpRequest(String url, Map<String, String> queryParams, String token) throws IOException {
|
|
|
|
|
OkHttpClient client = new OkHttpClient();
|
|
|
|
|
|
|
|
|
|
HttpUrl.Builder httpBuilder = Objects.requireNonNull(HttpUrl.parse(url)).newBuilder();
|
|
|
|
|
//封装请求参数
|
|
|
|
|
if (queryParams != null) {
|
|
|
|
|
for (Map.Entry<String, String> param : queryParams.entrySet()) {
|
|
|
|
|
httpBuilder.addQueryParameter(param.getKey(), param.getValue());
|
2024-01-15 15:14:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-25 14:20:05 +08:00
|
|
|
|
//设置请求的url
|
|
|
|
|
Request.Builder requestBuilder = new Request.Builder()
|
|
|
|
|
.url(httpBuilder.build());
|
2024-01-15 15:14:16 +08:00
|
|
|
|
|
2024-01-25 14:20:05 +08:00
|
|
|
|
if (token != null && !token.isEmpty()) {
|
|
|
|
|
requestBuilder.addHeader("Authorization", "Bearer " + token);
|
|
|
|
|
}
|
2024-01-15 15:14:16 +08:00
|
|
|
|
|
2024-01-25 14:20:05 +08:00
|
|
|
|
Request request = requestBuilder.build();
|
|
|
|
|
Response execute = client.newCall(request).execute();
|
|
|
|
|
if (execute.code() != 200) {
|
|
|
|
|
logger.error("get请求失败,返回状态码:{},url:{}", execute.code(), url);
|
|
|
|
|
throw new RuntimeException("get请求失败");
|
2024-01-12 16:40:52 +08:00
|
|
|
|
}
|
2024-01-25 14:20:05 +08:00
|
|
|
|
return JSONObject.parseObject(execute.body().string(), PageData.class);
|
|
|
|
|
//发送请求并返回响应数据
|
2024-01-12 16:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-15 15:27:55 +08:00
|
|
|
|
|
2024-01-12 16:40:52 +08:00
|
|
|
|
/**
|
|
|
|
|
* 发送post类型请求
|
2024-01-25 14:20:05 +08:00
|
|
|
|
*
|
2024-01-12 16:40:52 +08:00
|
|
|
|
* @param url
|
|
|
|
|
* @param jsonPayload
|
|
|
|
|
* @param token
|
|
|
|
|
* @return
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
2024-01-25 14:20:05 +08:00
|
|
|
|
private static PageData sendPostHttpRequest(String url, String jsonPayload, String token) throws IOException {
|
2024-01-12 16:40:52 +08:00
|
|
|
|
OkHttpClient client = new OkHttpClient();
|
|
|
|
|
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
|
|
|
|
RequestBody body = RequestBody.create(JSON, jsonPayload);
|
|
|
|
|
Request.Builder builder = new Request.Builder() // 构建一个新的Request对象。
|
|
|
|
|
.url(url)// 设置请求的URL。
|
|
|
|
|
.post(body);// 设置请求的方法为POST,并设置请求体。
|
|
|
|
|
//构建请求头
|
|
|
|
|
if (token != null && !token.isEmpty()) {// 检查token是否存在且不为空。
|
|
|
|
|
builder.addHeader("Authorization", "Bearer " + token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构建请求
|
|
|
|
|
Request request = builder.build();
|
2024-01-25 14:20:05 +08:00
|
|
|
|
Response execute = client.newCall(request).execute();
|
|
|
|
|
if (execute.code() != 200) {
|
|
|
|
|
logger.error("post请求失败,返回状态码:{},url:{}", execute.code(), url);
|
|
|
|
|
throw new RuntimeException("get请求失败");
|
|
|
|
|
}
|
|
|
|
|
PageData pageData = JSONObject.parseObject(execute.body().string(), PageData.class);
|
|
|
|
|
if (!"200".equals(pageData.getString("code"))) {
|
|
|
|
|
logger.error("post请求失败,返回值:{},url:{}", pageData.getString("msg"), url);
|
|
|
|
|
}
|
|
|
|
|
return pageData;
|
2024-01-12 16:40:52 +08:00
|
|
|
|
//发起请求并响应数据
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 发送PUT类型请求
|
2024-01-25 14:20:05 +08:00
|
|
|
|
*
|
2024-01-12 16:40:52 +08:00
|
|
|
|
* @param url
|
|
|
|
|
* @param jsonPayload
|
|
|
|
|
* @param token
|
|
|
|
|
* @return
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
2024-01-25 14:20:05 +08:00
|
|
|
|
private static Response sendPutHttpRequest(String url, String jsonPayload, String token) throws IOException {
|
2024-01-11 18:02:48 +08:00
|
|
|
|
OkHttpClient client = new OkHttpClient();
|
|
|
|
|
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
|
|
|
|
RequestBody body = RequestBody.create(JSON, jsonPayload);
|
|
|
|
|
Request.Builder builder = new Request.Builder()
|
|
|
|
|
.url(url)
|
2024-01-12 16:40:52 +08:00
|
|
|
|
.put(body);
|
2024-01-11 18:02:48 +08:00
|
|
|
|
if (token != null && !token.isEmpty()) {
|
|
|
|
|
builder.addHeader("Authorization", "Bearer " + token);
|
|
|
|
|
}
|
|
|
|
|
Request request = builder.build();
|
2024-01-12 16:40:52 +08:00
|
|
|
|
|
2024-01-11 18:02:48 +08:00
|
|
|
|
return client.newCall(request).execute();
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-12 16:40:52 +08:00
|
|
|
|
/**
|
|
|
|
|
* 发送delete类型请求
|
2024-01-25 14:20:05 +08:00
|
|
|
|
*
|
2024-01-12 16:40:52 +08:00
|
|
|
|
* @param url
|
|
|
|
|
* @param camIds
|
|
|
|
|
* @param token
|
|
|
|
|
* @return
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
2024-01-25 16:37:20 +08:00
|
|
|
|
private static PageData sendDeleteHttpRequest(String url, Long camIds, String token) throws IOException {
|
2024-01-12 16:40:52 +08:00
|
|
|
|
OkHttpClient client = new OkHttpClient();
|
|
|
|
|
//将要删除的Id列表转换为逗号分隔的字符串
|
|
|
|
|
//构建完整的url
|
2024-01-25 14:20:05 +08:00
|
|
|
|
url = url + "/" + camIds;
|
2024-01-12 16:40:52 +08:00
|
|
|
|
|
|
|
|
|
Request.Builder builderBuilder = new Request.Builder()
|
|
|
|
|
.url(url)
|
|
|
|
|
.delete();
|
|
|
|
|
|
|
|
|
|
if (token != null && !token.isEmpty()) {
|
|
|
|
|
builderBuilder.addHeader("Authorization", "Bearer " + token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Request request = builderBuilder.build();
|
2024-01-25 14:20:05 +08:00
|
|
|
|
Response execute = client.newCall(request).execute();
|
|
|
|
|
if (execute.code() != 200) {
|
|
|
|
|
logger.error("post请求失败,返回状态码:{},url:{}", execute.code(), url);
|
|
|
|
|
throw new RuntimeException("get请求失败");
|
|
|
|
|
}
|
|
|
|
|
PageData pageData = JSONObject.parseObject(execute.body().string(), PageData.class);
|
|
|
|
|
if (!"200".equals(pageData.getString("code"))) {
|
|
|
|
|
logger.error("post请求失败,返回值:{},url:{}", pageData.getString("msg"), url);
|
|
|
|
|
}
|
|
|
|
|
return pageData;
|
2024-01-12 16:40:52 +08:00
|
|
|
|
}
|
2024-01-31 10:22:34 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取区域内随机坐标点
|
|
|
|
|
*
|
|
|
|
|
* @param polygon [[lng,lat,alt],[lng,lat,alt],[lng,lat,alt],...]
|
|
|
|
|
* @return [lng,lat,alt]
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
public static List<String> getRandomPointInPolygon(List<List<Double>> polygon) {
|
|
|
|
|
double minX = Double.POSITIVE_INFINITY;
|
|
|
|
|
double minY = Double.POSITIVE_INFINITY;
|
|
|
|
|
double maxX = Double.NEGATIVE_INFINITY;
|
|
|
|
|
double maxY = Double.NEGATIVE_INFINITY;
|
|
|
|
|
|
|
|
|
|
for (List<Double> point : polygon) {
|
|
|
|
|
minX = Math.min(minX, point.get(0));
|
|
|
|
|
minY = Math.min(minY, point.get(1));
|
|
|
|
|
maxX = Math.max(maxX, point.get(0));
|
|
|
|
|
maxY = Math.max(maxY, point.get(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Random rand = new Random();
|
|
|
|
|
while (true) {
|
|
|
|
|
Double x = minX + rand.nextDouble() * (maxX - minX);
|
|
|
|
|
Double y = minY + rand.nextDouble() * (maxY - minY);
|
|
|
|
|
|
|
|
|
|
if (pointInPolygon(polygon, x, y)) {
|
|
|
|
|
List<String> point = Arrays.asList(x.toString(),y.toString(),polygon.get(0).get(2).toString());
|
|
|
|
|
return point;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断点是否在多边形内
|
|
|
|
|
* @param polygon
|
|
|
|
|
* @param lng
|
|
|
|
|
* @param lat
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private static boolean pointInPolygon(List<List<Double>> polygon,double lng, double lat) {
|
|
|
|
|
boolean inside = false;
|
|
|
|
|
int n = polygon.size();
|
|
|
|
|
for (int i = 0, j = n - 1; i < n; j = i++) {
|
|
|
|
|
if (((polygon.get(i).get(1) > lat) != (polygon.get(j).get(1) > lat)) &&
|
|
|
|
|
(lng < (polygon.get(j).get(0) - polygon.get(i).get(0)) * (lat - polygon.get(i).get(1)) / (polygon.get(j).get(1) - polygon.get(i).get(1)) + polygon.get(i).get(0))) {
|
|
|
|
|
inside = !inside;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return inside;
|
|
|
|
|
}
|
2024-01-11 15:17:27 +08:00
|
|
|
|
}
|