|
|
@ -1,26 +1,34 @@ |
|
|
|
package com.epmet.plugin.power.modules.visit.utils; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.redis.RedisUtils; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.plugin.commons.redis.RedisKeys; |
|
|
|
import com.epmet.plugin.power.config.DhCloudProperties; |
|
|
|
import com.epmet.plugin.power.dto.hik.form.HikAuthorityFormDTO; |
|
|
|
import com.epmet.plugin.power.dto.hik.form.HikPersonFormDTO; |
|
|
|
import com.epmet.plugin.power.dto.visit.form.VisitVisitorFormDTO; |
|
|
|
import com.epmet.plugin.power.dto.visit.DhTokenDTO; |
|
|
|
import com.epmet.plugin.power.dto.visit.form.*; |
|
|
|
import com.epmet.plugin.power.dto.visit.result.DhChannelResultDTO; |
|
|
|
import net.coobird.thumbnailator.Thumbnails; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import javax.imageio.ImageIO; |
|
|
|
import javax.xml.bind.DatatypeConverter; |
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
import java.io.*; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.net.URL; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* 海康设备下放命令 |
|
|
@ -40,8 +48,18 @@ public class DhDeviceUtil { |
|
|
|
|
|
|
|
private final String GET_PUBLIC_KEY = "/WPMS/getPublicKey"; |
|
|
|
private final String GET_LOGIN_PASS = "/WPMS/login"; |
|
|
|
private final String SEND_PERSON = "/api/v1/estate/system/person"; |
|
|
|
private final String ISSUE_AUTHORITY = "/api/v1/estate/entranceGuard/permissions/actions/authorityIssued"; |
|
|
|
private final String GET_DEPARTMENT = "/CardSolution/card/department"; |
|
|
|
private final String GET_PERSON_IDENTITY = "/CardSolution/card/person/personidentity"; |
|
|
|
private final String GET_DOOR_PLAN = "/CardSolution/card/accessControl/timeQuantum/1/page"; |
|
|
|
private final String GET_DOOR_CHANNEL = "/CardSolution/card/accessControl/channel/bycondition/combined"; |
|
|
|
private final String ADD_PERSON = "/CardSolution/card/person"; |
|
|
|
private final String LIST_PERSON = "/CardSolution/card/person/bycondition/combined"; |
|
|
|
private final String DEL_PERSON = "/CardSolution/card/person/delete"; |
|
|
|
private final String ADD_PERSON_IMG = "/CardSolution/common/saveMobileBase64ImageToByte"; |
|
|
|
private final String ADD_AUTH = "/CardSolution/card/accessControl/doorAuthority/update"; |
|
|
|
private final String LIST_CARD = "/CardSolution/card/card/bycondition/combined"; |
|
|
|
private final String DEL_CARD = "/CardSolution/card/card/returnByNumber/"; |
|
|
|
private final String OPEN_CARD = "/CardSolution/card/card/open/batch"; |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取publicKey |
|
|
@ -51,7 +69,7 @@ public class DhDeviceUtil { |
|
|
|
* @author zhy |
|
|
|
* @date 2022/5/20 16:40 |
|
|
|
*/ |
|
|
|
public String getAccessToken() { |
|
|
|
public String getPublicKey() { |
|
|
|
String key = RedisKeys.getDhPublicKey(); |
|
|
|
Object obj = redisUtils.get(key); |
|
|
|
if (null != obj) { |
|
|
@ -59,22 +77,25 @@ public class DhDeviceUtil { |
|
|
|
} |
|
|
|
|
|
|
|
String url = dhCloudProperties.getUrl().concat(GET_PUBLIC_KEY); |
|
|
|
Map<String, Object> paramsMap = new HashMap<>(4); |
|
|
|
paramsMap.put("loginName", dhCloudProperties.getLoginName()); |
|
|
|
Map<String, String> paramsMap = new HashMap<>(4); |
|
|
|
|
|
|
|
DhPublicKeyFormDTO dto = new DhPublicKeyFormDTO(); |
|
|
|
dto.setLoginName(dhCloudProperties.getLoginName()); |
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(dto), paramsMap).getData(); |
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPost(url, paramsMap).getData(); |
|
|
|
if (null == data) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "AccessToken获取失败"); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "publicKey获取失败"); |
|
|
|
} |
|
|
|
|
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
if (!toResult.containsKey("publicKey")) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "AccessToken获取失败"); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "publicKey获取失败"); |
|
|
|
} |
|
|
|
String accessToken = toResult.get("publicKey").toString(); |
|
|
|
String publicKey = toResult.get("publicKey").toString(); |
|
|
|
|
|
|
|
redisUtils.set(key, accessToken, RedisUtils.MINUTE_THIRTY_EXPIRE); |
|
|
|
return accessToken; |
|
|
|
redisUtils.set(key, publicKey, RedisUtils.MINUTE_THIRTY_EXPIRE); |
|
|
|
return publicKey; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -85,28 +106,37 @@ public class DhDeviceUtil { |
|
|
|
* @author zhy |
|
|
|
* @date 2022/5/20 16:40 |
|
|
|
*/ |
|
|
|
public DhToken getLoginPass(String publicKey) { |
|
|
|
public DhTokenDTO getLoginPass(String publicKey) { |
|
|
|
String key = RedisKeys.getDhToken(); |
|
|
|
Object obj = redisUtils.get(key); |
|
|
|
if (null != obj) { |
|
|
|
return (DhToken) obj; |
|
|
|
return (DhTokenDTO) obj; |
|
|
|
} |
|
|
|
|
|
|
|
String url = dhCloudProperties.getUrl().concat(GET_LOGIN_PASS); |
|
|
|
Map<String, Object> paramsMap = new HashMap<>(8); |
|
|
|
paramsMap.put("loginName", dhCloudProperties.getLoginName()); |
|
|
|
paramsMap.put("loginPass", publicKey); |
|
|
|
Map<String, String> paramsMap = new HashMap<>(4); |
|
|
|
|
|
|
|
DhLoginPassFormDTO dto = new DhLoginPassFormDTO(); |
|
|
|
dto.setLoginName(dhCloudProperties.getLoginName()); |
|
|
|
String pwd; |
|
|
|
try { |
|
|
|
pwd = RSAUtils.getPwdByRsa(publicKey, dhCloudProperties.getLoginPass()); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "loginPass加密失败"); |
|
|
|
} |
|
|
|
dto.setLoginPass(pwd); |
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(dto), paramsMap).getData(); |
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPost(url, paramsMap).getData(); |
|
|
|
if (null == data) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "AccessToken获取失败"); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "loginPass获取失败"); |
|
|
|
} |
|
|
|
|
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
if (!toResult.containsKey("token")) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "AccessToken获取失败"); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "loginPass获取失败"); |
|
|
|
} |
|
|
|
DhToken token = new DhToken(); |
|
|
|
DhTokenDTO token = new DhTokenDTO(); |
|
|
|
token.setId(toResult.get("id").toString()); |
|
|
|
token.setLoginName(toResult.get("loginName").toString()); |
|
|
|
token.setPublicKey(toResult.get("publicKey").toString()); |
|
|
@ -116,69 +146,631 @@ public class DhDeviceUtil { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 下发人员 |
|
|
|
* 新增部门 |
|
|
|
* |
|
|
|
* @param dto |
|
|
|
* @return java.lang.String 人员ID |
|
|
|
* @param |
|
|
|
* @return java.lang.String |
|
|
|
* @author zhy |
|
|
|
* @date 2022/5/23 10:08 |
|
|
|
*/ |
|
|
|
public Long getDept() { |
|
|
|
String url = dhCloudProperties.getUrl().concat(GET_DEPARTMENT); |
|
|
|
String urlParam = getDhUrlParams(); |
|
|
|
url = url + urlParam; |
|
|
|
|
|
|
|
Map<String, Object> paramsMap = new HashMap<>(4); |
|
|
|
// DhDeptFormDTO dto = new DhDeptFormDTO();
|
|
|
|
// dto.setName("访客部门");
|
|
|
|
// dto.setParentId(1L);
|
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendGet(url, paramsMap).getData(); |
|
|
|
|
|
|
|
if (null == data) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询部门列表失败"); |
|
|
|
} |
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); |
|
|
|
if (null != toResult.get("success")) { |
|
|
|
result.setCode(200); |
|
|
|
} |
|
|
|
if (!result.getSuccess()) { |
|
|
|
logger.info(result.getErrMsg()); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询部门列表失败!" + result.getErrMsg()); |
|
|
|
} |
|
|
|
Object registerResult = result.getData(); |
|
|
|
|
|
|
|
JSONArray jsonArray = JSON.parseArray(registerResult.toString()); |
|
|
|
for (int i = 0; i < jsonArray.size(); i++) { |
|
|
|
if ("临时人员".equals(jsonArray.getJSONObject(i).get("name").toString())) { |
|
|
|
return Long.parseLong(jsonArray.getJSONObject(i).get("id").toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 人员预处理 |
|
|
|
* |
|
|
|
* @param |
|
|
|
* @return java.lang.String |
|
|
|
* @author zhy |
|
|
|
* @date 2022/5/23 10:08 |
|
|
|
*/ |
|
|
|
public String sendPerson(VisitVisitorFormDTO dto) { |
|
|
|
String url = dhCloudProperties.getUrl().concat(SEND_PERSON); |
|
|
|
public void personHandle(String code) { |
|
|
|
String url = dhCloudProperties.getUrl().concat(LIST_PERSON); |
|
|
|
String urlParam = getDhUrlParams(); |
|
|
|
url = url + urlParam; |
|
|
|
|
|
|
|
Map<String, String> paramsMap = new HashMap<>(4); |
|
|
|
DhToken token = getLoginPass(getAccessToken()); |
|
|
|
String urlParam = "?userId=" + token.getId() + "&username=" + token.getLoginName() + "&token=" + token.getToken(); |
|
|
|
DhPersonPageFormDTO dto = new DhPersonPageFormDTO(); |
|
|
|
dto.setPageNum(1); |
|
|
|
dto.setPageSize(100); |
|
|
|
dto.setCode(code); |
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(dto), paramsMap).getData(); |
|
|
|
|
|
|
|
if (null == data) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询人员列表失败"); |
|
|
|
} |
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); |
|
|
|
if (null != toResult.get("success")) { |
|
|
|
result.setCode(200); |
|
|
|
} |
|
|
|
if (!result.getSuccess()) { |
|
|
|
logger.info(result.getErrMsg()); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询人员列表失败!" + result.getErrMsg()); |
|
|
|
} |
|
|
|
Object registerResult = result.getData(); |
|
|
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(registerResult.toString()); |
|
|
|
|
|
|
|
List<Integer> ids = new ArrayList<>(); |
|
|
|
JSONArray jsonArray = JSON.parseArray(jsonObject.get("pageData").toString()); |
|
|
|
for (int i = 0; i < jsonArray.size(); i++) { |
|
|
|
ids.add(Integer.parseInt(jsonArray.getJSONObject(i).get("id").toString())); |
|
|
|
} |
|
|
|
if (!ids.isEmpty()) { |
|
|
|
DhPersonDelFormDTO del = new DhPersonDelFormDTO(); |
|
|
|
del.setPersonIds(ids); |
|
|
|
delPerson(del); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 卡片预处理 |
|
|
|
* |
|
|
|
* @param |
|
|
|
* @return java.lang.String |
|
|
|
* @author zhy |
|
|
|
* @date 2022/5/23 10:08 |
|
|
|
*/ |
|
|
|
public void cardHandle(String code) { |
|
|
|
String url = dhCloudProperties.getUrl().concat(LIST_CARD); |
|
|
|
String urlParam = getDhUrlParams(); |
|
|
|
url = url + urlParam; |
|
|
|
|
|
|
|
Map<String, String> paramsMap = new HashMap<>(4); |
|
|
|
DhCardPageFormDTO dto = new DhCardPageFormDTO(); |
|
|
|
dto.setPageNum(1); |
|
|
|
dto.setPageSize(100); |
|
|
|
dto.setPersonCode(code); |
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(dto), paramsMap).getData(); |
|
|
|
|
|
|
|
if (null == data) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "人员信息下发失败"); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询卡片列表失败"); |
|
|
|
} |
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
Result result = ConvertUtils.mapToEntity(toResult, Result.class); |
|
|
|
if (null != toResult.get("code")) { |
|
|
|
result.setCode(((Integer) toResult.get("code")).intValue()); |
|
|
|
DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); |
|
|
|
if (null != toResult.get("success")) { |
|
|
|
result.setCode(200); |
|
|
|
} |
|
|
|
if (NumConstant.TWO_HUNDRED != result.getCode()) { |
|
|
|
logger.info(result.getMsg()); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "人员信息下发失败"); |
|
|
|
if (!result.getSuccess()) { |
|
|
|
logger.info(result.getErrMsg()); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询卡片列表失败!" + result.getErrMsg()); |
|
|
|
} |
|
|
|
Object registerResult = result.getData(); |
|
|
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(registerResult.toString()); |
|
|
|
|
|
|
|
JSONArray jsonArray = JSON.parseArray(jsonObject.get("pageData").toString()); |
|
|
|
for (int i = 0; i < jsonArray.size(); i++) { |
|
|
|
delCard(jsonArray.getJSONObject(i).get("cardNumber").toString()); |
|
|
|
} |
|
|
|
Object RegisterResult = result.getData(); |
|
|
|
JSONObject jsonObject = JSON.parseObject(RegisterResult.toString()); |
|
|
|
return jsonObject.getString("personId"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 下发人员权限 |
|
|
|
* 删除人员 |
|
|
|
* |
|
|
|
* @param |
|
|
|
* @return java.lang.String |
|
|
|
* @author zhy |
|
|
|
* @date 2022/5/23 10:08 |
|
|
|
*/ |
|
|
|
public void delPerson(DhPersonDelFormDTO dto) { |
|
|
|
String url = dhCloudProperties.getUrl().concat(DEL_PERSON); |
|
|
|
String urlParam = getDhUrlParams(); |
|
|
|
url = url + urlParam; |
|
|
|
|
|
|
|
Map<String, String> paramsMap = new HashMap<>(4); |
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(dto), paramsMap).getData(); |
|
|
|
if (null == data) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "删除人员失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 退卡 |
|
|
|
* |
|
|
|
* @param |
|
|
|
* @return java.lang.String |
|
|
|
* @author zhy |
|
|
|
* @date 2022/5/23 10:08 |
|
|
|
*/ |
|
|
|
public void delCard(String cardNum) { |
|
|
|
String url = dhCloudProperties.getUrl().concat(DEL_CARD); |
|
|
|
url = url + cardNum; |
|
|
|
String urlParam = getDhUrlParams(); |
|
|
|
url = url + urlParam; |
|
|
|
|
|
|
|
Map<String, String> paramsMap = new HashMap<>(4); |
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, StringUtils.EMPTY, paramsMap).getData(); |
|
|
|
if (null == data) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "删除卡片失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取身份 |
|
|
|
* |
|
|
|
* @param |
|
|
|
* @return java.lang.String |
|
|
|
* @author zhy |
|
|
|
* @date 2022/5/23 11:04 |
|
|
|
*/ |
|
|
|
public String getIdentity() { |
|
|
|
String url = dhCloudProperties.getUrl().concat(GET_PERSON_IDENTITY); |
|
|
|
String urlParam = getDhUrlParams(); |
|
|
|
url = url + urlParam; |
|
|
|
|
|
|
|
Map<String, Object> paramsMap = new HashMap<>(4); |
|
|
|
// DhIdentityFormDTO dto = new DhIdentityFormDTO();
|
|
|
|
// dto.setName("访客");
|
|
|
|
// dto.setSubsidyAmount(0D);
|
|
|
|
// dto.setIsCashRecharge(1);
|
|
|
|
// dto.setIsMachineRecharge(1);
|
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendGet(url, paramsMap).getData(); |
|
|
|
|
|
|
|
if (null == data) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取身份列表失败"); |
|
|
|
} |
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); |
|
|
|
if (null != toResult.get("success")) { |
|
|
|
result.setCode(200); |
|
|
|
} |
|
|
|
if (!result.getSuccess()) { |
|
|
|
logger.info(result.getErrMsg()); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取身份列表失败!" + result.getErrMsg()); |
|
|
|
} |
|
|
|
Object registerResult = result.getData(); |
|
|
|
JSONArray jsonArray = JSON.parseArray(registerResult.toString()); |
|
|
|
for (int i = 0; i < jsonArray.size(); i++) { |
|
|
|
if ("默认身份".equals(jsonArray.getJSONObject(i).get("name").toString())) { |
|
|
|
return jsonArray.getJSONObject(i).get("id").toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return ""; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取开门计划 |
|
|
|
* |
|
|
|
* @param |
|
|
|
* @return java.lang.String |
|
|
|
* @author zhy |
|
|
|
* @date 2022/5/23 11:04 |
|
|
|
*/ |
|
|
|
public Long getPlan() { |
|
|
|
String url = dhCloudProperties.getUrl().concat(GET_DOOR_PLAN); |
|
|
|
String urlParam = getDhUrlParams(); |
|
|
|
url = url + urlParam; |
|
|
|
|
|
|
|
Map<String, String> paramsMap = new HashMap<>(4); |
|
|
|
DhPlanPageFormDTO dto = new DhPlanPageFormDTO(); |
|
|
|
dto.setPageNum(1); |
|
|
|
dto.setPageSize(100); |
|
|
|
dto.setSingleCondition("默认"); |
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(dto), paramsMap).getData(); |
|
|
|
|
|
|
|
if (null == data) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询开门计划失败"); |
|
|
|
} |
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); |
|
|
|
if (null != toResult.get("success")) { |
|
|
|
result.setCode(200); |
|
|
|
} |
|
|
|
if (!result.getSuccess()) { |
|
|
|
logger.info(result.getErrMsg()); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询开门计划失败!" + result.getErrMsg()); |
|
|
|
} |
|
|
|
Object registerResult = result.getData(); |
|
|
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(registerResult.toString()); |
|
|
|
|
|
|
|
JSONArray jsonArray = JSON.parseArray(jsonObject.get("pageData").toString()); |
|
|
|
|
|
|
|
if (jsonArray.size() > 0) { |
|
|
|
return Long.parseLong(jsonArray.getJSONObject(0).get("id").toString()); |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询通道 |
|
|
|
* |
|
|
|
* @param |
|
|
|
* @return java.lang.String |
|
|
|
* @author zhy |
|
|
|
* @date 2022/5/23 11:04 |
|
|
|
*/ |
|
|
|
public List<DhChannelResultDTO> getChannel() { |
|
|
|
String url = dhCloudProperties.getUrl().concat(GET_DOOR_CHANNEL); |
|
|
|
String urlParam = getDhUrlParams(); |
|
|
|
url = url + urlParam; |
|
|
|
|
|
|
|
Map<String, String> paramsMap = new HashMap<>(4); |
|
|
|
DhChannelPageFormDTO dto = new DhChannelPageFormDTO(); |
|
|
|
dto.setPageSize(100); |
|
|
|
dto.setPageSize(1); |
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(dto), paramsMap).getData(); |
|
|
|
|
|
|
|
if (null == data) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询通道列表失败"); |
|
|
|
} |
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); |
|
|
|
if (null != toResult.get("success")) { |
|
|
|
result.setCode(200); |
|
|
|
} |
|
|
|
if (!result.getSuccess()) { |
|
|
|
logger.info(result.getErrMsg()); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询通道列表失败!" + result.getErrMsg()); |
|
|
|
} |
|
|
|
Object registerResult = result.getData(); |
|
|
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(registerResult.toString()); |
|
|
|
|
|
|
|
JSONArray jsonArray = JSON.parseArray(jsonObject.get("pageData").toString()); |
|
|
|
|
|
|
|
List<DhChannelResultDTO> list = new ArrayList<>(); |
|
|
|
for (int i = 0; i < jsonArray.size(); i++) { |
|
|
|
JSONObject jsonItem = jsonArray.getJSONObject(0); |
|
|
|
DhChannelResultDTO channel = new DhChannelResultDTO(); |
|
|
|
channel.setPrivilegeType("1"); |
|
|
|
channel.setResouceCode(jsonItem.get("channelCode").toString()); |
|
|
|
list.add(channel); |
|
|
|
} |
|
|
|
|
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 新增人员 |
|
|
|
* |
|
|
|
* @param dto |
|
|
|
* @return java.lang.String |
|
|
|
* @author zhy |
|
|
|
* @date 2022/5/23 11:04 |
|
|
|
*/ |
|
|
|
public String authorityIssued(HikAuthorityFormDTO dto) { |
|
|
|
String url = dhCloudProperties.getUrl().concat(ISSUE_AUTHORITY); |
|
|
|
public Long addPerson(DhPersonFormDTO dto) { |
|
|
|
// 数据预处理
|
|
|
|
dataHandle(dto.getCode()); |
|
|
|
|
|
|
|
String url = dhCloudProperties.getUrl().concat(ADD_PERSON); |
|
|
|
String urlParam = getDhUrlParams(); |
|
|
|
url = url + urlParam; |
|
|
|
|
|
|
|
Long deptId = getDept(); |
|
|
|
if (null == deptId) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询临时人员部门失败"); |
|
|
|
} |
|
|
|
String identity = getIdentity(); |
|
|
|
if (StringUtils.isBlank(identity)) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取身份失败"); |
|
|
|
} |
|
|
|
dto.setDeptId(deptId); |
|
|
|
dto.setPersonIdentityId(identity); |
|
|
|
|
|
|
|
Map<String, String> paramsMap = new HashMap<>(4); |
|
|
|
paramsMap.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(dto), paramsMap).getData(); |
|
|
|
|
|
|
|
if (null == data) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "人员权限下发失败"); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "新增人员失败"); |
|
|
|
} |
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); |
|
|
|
if (null != toResult.get("success")) { |
|
|
|
result.setCode(200); |
|
|
|
} |
|
|
|
if (!result.getSuccess()) { |
|
|
|
logger.info(result.getErrMsg()); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "新增人员失败!" + result.getErrMsg()); |
|
|
|
} |
|
|
|
Object registerResult = result.getData(); |
|
|
|
if (null != registerResult) { |
|
|
|
return Long.parseLong(registerResult.toString()); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 下发人员头像 |
|
|
|
* |
|
|
|
* @param dto |
|
|
|
* @return java.lang.String |
|
|
|
* @author zhy |
|
|
|
* @date 2022/5/23 11:04 |
|
|
|
*/ |
|
|
|
public String addPersonImg(DhPersonFormDTO dto, String imgUrl) { |
|
|
|
DhPersonImgFormDTO imgFormDTO = new DhPersonImgFormDTO(); |
|
|
|
String url = dhCloudProperties.getUrl().concat(ADD_PERSON_IMG); |
|
|
|
String urlParam = getDhUrlParams(); |
|
|
|
url = url + urlParam; |
|
|
|
|
|
|
|
imgFormDTO.setPersonCode(dto.getCode()); |
|
|
|
imgFormDTO.setBase64file(getBase64ByUrl(imgUrl)); |
|
|
|
|
|
|
|
Map<String, String> paramsMap = new HashMap<>(4); |
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(imgFormDTO), paramsMap).getData(); |
|
|
|
|
|
|
|
if (null == data) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "下发人员头像失败"); |
|
|
|
} |
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
Result result = ConvertUtils.mapToEntity(toResult, Result.class); |
|
|
|
if (null != toResult.get("code")) { |
|
|
|
result.setCode(((Integer) toResult.get("code")).intValue()); |
|
|
|
DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); |
|
|
|
if (null != toResult.get("success")) { |
|
|
|
result.setCode(200); |
|
|
|
} |
|
|
|
if (NumConstant.TWO_HUNDRED != result.getCode()) { |
|
|
|
logger.info(result.getMsg()); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "人员权限下发失败"); |
|
|
|
if (!result.getSuccess()) { |
|
|
|
logger.info(result.getErrMsg()); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "下发人员头像失败!" + result.getErrMsg()); |
|
|
|
} else { |
|
|
|
return "success"; |
|
|
|
} |
|
|
|
return "success"; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 人员开卡 |
|
|
|
* |
|
|
|
* @param dto |
|
|
|
* @return java.lang.String |
|
|
|
* @author zhy |
|
|
|
* @date 2022/5/23 11:04 |
|
|
|
*/ |
|
|
|
public String addPersonCard(DhPersonFormDTO dto) { |
|
|
|
Long personId = addPerson(dto); |
|
|
|
if (personId == null) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "添加人员信息失败"); |
|
|
|
} |
|
|
|
DhPersonCardListFormDTO cardListFormDTO = new DhPersonCardListFormDTO(); |
|
|
|
List<DhPersonCardFormDTO> cardList = new ArrayList<>(); |
|
|
|
DhPersonCardFormDTO cardFormDTO = new DhPersonCardFormDTO(); |
|
|
|
String url = dhCloudProperties.getUrl().concat(OPEN_CARD); |
|
|
|
String urlParam = getDhUrlParams(); |
|
|
|
url = url + urlParam; |
|
|
|
|
|
|
|
cardFormDTO.setPersonId(personId); |
|
|
|
cardFormDTO.setPersonName(dto.getName()); |
|
|
|
cardFormDTO.setCardNumber(generateNiceString(8)); |
|
|
|
cardFormDTO.setCardType("0"); |
|
|
|
cardFormDTO.setCategory("0"); |
|
|
|
cardFormDTO.setCardStatus("ACTIVE"); |
|
|
|
cardFormDTO.setStartDate(LocalDate.now().toString()); |
|
|
|
cardFormDTO.setEndDate(LocalDate.now().plusDays(1L).toString()); |
|
|
|
String pwd; |
|
|
|
try { |
|
|
|
pwd = RSAUtils.getPwdByRsa(getPublicKey(), "123456"); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "密码加密失败"); |
|
|
|
} |
|
|
|
cardFormDTO.setCardPassword(pwd); |
|
|
|
cardFormDTO.setSubSystems("1"); |
|
|
|
cardList.add(cardFormDTO); |
|
|
|
cardListFormDTO.setObjectList(cardList); |
|
|
|
|
|
|
|
Map<String, String> paramsMap = new HashMap<>(4); |
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(cardListFormDTO), paramsMap).getData(); |
|
|
|
|
|
|
|
if (null == data) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "人员开卡失败"); |
|
|
|
} |
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); |
|
|
|
if (null != toResult.get("success")) { |
|
|
|
result.setCode(200); |
|
|
|
} |
|
|
|
if (!result.getSuccess()) { |
|
|
|
logger.info(result.getErrMsg()); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "人员开卡失败!" + result.getErrMsg()); |
|
|
|
} else { |
|
|
|
return cardFormDTO.getCardNumber(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 下发人员权限 |
|
|
|
* |
|
|
|
* @param dto |
|
|
|
* @return java.lang.String |
|
|
|
* @author zhy |
|
|
|
* @date 2022/5/23 11:04 |
|
|
|
*/ |
|
|
|
public String addPersonAuth(DhPersonFormDTO dto, String imgUrl) { |
|
|
|
String personCard = addPersonCard(dto); |
|
|
|
if (StringUtils.isBlank(personCard)) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "开卡失败"); |
|
|
|
} else if (StringUtils.isNotBlank(imgUrl)) { |
|
|
|
addPersonImg(dto, imgUrl); |
|
|
|
} |
|
|
|
|
|
|
|
List<DhChannelResultDTO> channel = getChannel(); |
|
|
|
if (channel.isEmpty()) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取通道失败"); |
|
|
|
} |
|
|
|
|
|
|
|
Long plan = getPlan(); |
|
|
|
if (plan == null) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取开门计划失败"); |
|
|
|
} |
|
|
|
|
|
|
|
DhAuthFormDTO authFormDTO = new DhAuthFormDTO(); |
|
|
|
String url = dhCloudProperties.getUrl().concat(ADD_AUTH); |
|
|
|
String urlParam = getDhUrlParams(); |
|
|
|
url = url + urlParam; |
|
|
|
|
|
|
|
authFormDTO.setCardNumber(personCard); |
|
|
|
authFormDTO.setTimeQuantumId(plan.toString()); |
|
|
|
authFormDTO.setCardPrivilegeDetails(channel); |
|
|
|
|
|
|
|
Map<String, String> paramsMap = new HashMap<>(4); |
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(authFormDTO), paramsMap).getData(); |
|
|
|
|
|
|
|
if (null == data) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "下发人员权限失败"); |
|
|
|
} |
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); |
|
|
|
if (null != toResult.get("success")) { |
|
|
|
result.setCode(200); |
|
|
|
} |
|
|
|
if (!result.getSuccess()) { |
|
|
|
logger.info(result.getErrMsg()); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "下发人员权限失败!" + result.getErrMsg()); |
|
|
|
} else { |
|
|
|
return "success"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 拼接url固定参数 |
|
|
|
* |
|
|
|
* @param |
|
|
|
* @return java.lang.String |
|
|
|
* @author zhy |
|
|
|
* @date 2022/7/28 16:09 |
|
|
|
*/ |
|
|
|
private String getDhUrlParams() { |
|
|
|
DhTokenDTO token = getLoginPass(getPublicKey()); |
|
|
|
return "?userId=" + token.getId() + "&username=" + token.getLoginName() + "&token=" + token.getToken(); |
|
|
|
} |
|
|
|
|
|
|
|
private String getBase64ByUrl(String imgUrl) { |
|
|
|
String ossDomain; |
|
|
|
byte[] fileBytes; |
|
|
|
try { |
|
|
|
URL url = new URL(imgUrl); |
|
|
|
DataInputStream dataInputStream = new DataInputStream(url.openStream()); |
|
|
|
byte[] originBytes = toByteArray(dataInputStream); |
|
|
|
|
|
|
|
fileBytes = compressPicCycle(originBytes, 100L, 0.3); |
|
|
|
} catch (IOException e) { |
|
|
|
logger.error("图片上传异常", e); |
|
|
|
throw new RenException("图片上传异常"); |
|
|
|
} |
|
|
|
return DatatypeConverter.printBase64Binary(fileBytes); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param bytes 原图片字节数组 |
|
|
|
* @param desFileSize 指定图片大小,单位 kb |
|
|
|
* @param accuracy 精度,递归压缩的比率,建议小于0.9 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private byte[] compressPicCycle(byte[] bytes, long desFileSize, double accuracy) throws IOException { |
|
|
|
// 获取目标图片
|
|
|
|
long fileSize = bytes.length; |
|
|
|
System.out.println("=====fileSize======== " + fileSize); |
|
|
|
// 判断图片大小是否小于指定图片大小
|
|
|
|
if (fileSize <= desFileSize * 1024) { |
|
|
|
return bytes; |
|
|
|
} |
|
|
|
//计算宽高
|
|
|
|
BufferedImage bim = ImageIO.read(new ByteArrayInputStream(bytes)); |
|
|
|
int imgWidth = bim.getWidth(); |
|
|
|
System.out.println(imgWidth + "====imgWidth====="); |
|
|
|
int imgHeight = bim.getHeight(); |
|
|
|
int desWidth = new BigDecimal(imgWidth).multiply(new BigDecimal(accuracy)).intValue(); |
|
|
|
System.out.println(desWidth + "====desWidth====="); |
|
|
|
int desHeight = new BigDecimal(imgHeight).multiply(new BigDecimal(accuracy)).intValue(); |
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(); //字节输出流(写入到内存)
|
|
|
|
Thumbnails.of(new ByteArrayInputStream(bytes)).size(desWidth, desHeight).outputQuality(accuracy).toOutputStream(baos); |
|
|
|
//如果不满足要求,递归直至满足要求
|
|
|
|
return compressPicCycle(baos.toByteArray(), desFileSize, accuracy); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* inputstream输入流转换成byte[]字节数组 |
|
|
|
* |
|
|
|
* @param input |
|
|
|
* @return byte[] |
|
|
|
* @author yinzuomei |
|
|
|
* @date 2020/2/27 16:09 |
|
|
|
*/ |
|
|
|
private byte[] toByteArray(InputStream input) throws IOException { |
|
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream(); |
|
|
|
byte[] buffer = new byte[1024 * 4]; |
|
|
|
int n = 0; |
|
|
|
while (-1 != (n = input.read(buffer))) { |
|
|
|
output.write(buffer, 0, n); |
|
|
|
} |
|
|
|
return output.toByteArray(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 随机生成16进制字符串 |
|
|
|
* |
|
|
|
* @param len |
|
|
|
* @return java.lang.String |
|
|
|
* @author zhy |
|
|
|
* @date 2022/7/29 9:47 |
|
|
|
*/ |
|
|
|
private String generateNiceString(int len) { |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
for (int i = 0; i < len; i++) { |
|
|
|
sb.append(Integer.toHexString(new Random().nextInt(16))); |
|
|
|
} |
|
|
|
return sb.toString().toUpperCase(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 退卡,然后删除人员 |
|
|
|
* |
|
|
|
* @param code |
|
|
|
* @return void |
|
|
|
* @author zhy |
|
|
|
* @date 2022/8/3 10:48 |
|
|
|
*/ |
|
|
|
public void dataHandle(String code) { |
|
|
|
// 先退卡
|
|
|
|
cardHandle(code); |
|
|
|
// 再删人员
|
|
|
|
personHandle(code); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|