Browse Source

Merge branch 'feature/visit_zhy' into dev

dev
zhangyuan 3 years ago
parent
commit
54c1e66509
  1. 27
      epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhAuthFormDTO.java
  2. 39
      epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhPersonCardFormDTO.java
  3. 39
      epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhPersonFormDTO.java
  4. 23
      epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhPersonImgFormDTO.java
  5. 23
      epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/result/DhChannelResultDTO.java
  6. 8
      epmet-plugins-module/pli-power-base/pli-power-base-server/pom.xml
  7. 4
      epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/utils/HkDeviceUtil.java
  8. 13
      epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/visit/service/impl/VisitVisitorServiceImpl.java
  9. 483
      epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/visit/utils/DhDeviceUtil.java
  10. 142
      epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/visit/utils/DhResult.java

27
epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhAuthFormDTO.java

@ -0,0 +1,27 @@
package com.epmet.plugin.power.dto.visit.form;
import com.epmet.plugin.power.dto.visit.result.DhChannelResultDTO;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 海康社区人员信息下放
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2022-05-20
*/
@Data
public class DhAuthFormDTO implements Serializable {
private static final long serialVersionUID = 1L;
private String cardNumber;
private String timeQuantumId;
private List<DhChannelResultDTO> cardPrivilegeDetails;
}

39
epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhPersonCardFormDTO.java

@ -0,0 +1,39 @@
package com.epmet.plugin.power.dto.visit.form;
import lombok.Data;
import java.io.Serializable;
/**
* 海康社区人员信息下放
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2022-05-20
*/
@Data
public class DhPersonCardFormDTO implements Serializable {
private static final long serialVersionUID = 1L;
private Long personId;
private String personName;
private String cardNumber;
private String cardType;
private String category;
private String cardStatus;
private String startDate;
private String endDate;
private String cardPassword;
private String subSystems;
}

39
epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhPersonFormDTO.java

@ -0,0 +1,39 @@
package com.epmet.plugin.power.dto.visit.form;
import lombok.Data;
import java.io.Serializable;
/**
* 海康社区人员信息下放
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2022-05-20
*/
@Data
public class DhPersonFormDTO implements Serializable {
private static final long serialVersionUID = 1L;
private String paperType;
private String paperNumber;
private String name;
private String code;
private Long deptId;
private String sex;
private String birthday;
private String phone;
private String status;
private String personIdentityId;
}

23
epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhPersonImgFormDTO.java

@ -0,0 +1,23 @@
package com.epmet.plugin.power.dto.visit.form;
import lombok.Data;
import java.io.Serializable;
/**
* 海康社区人员信息下放
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2022-05-20
*/
@Data
public class DhPersonImgFormDTO implements Serializable {
private static final long serialVersionUID = 1L;
private String personCode;
private String base64file;
}

23
epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/result/DhChannelResultDTO.java

@ -0,0 +1,23 @@
package com.epmet.plugin.power.dto.visit.result;
import lombok.Data;
import java.io.Serializable;
/**
* 海康社区人员信息下放
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2022-05-20
*/
@Data
public class DhChannelResultDTO implements Serializable {
private static final long serialVersionUID = 1L;
private String privilegeType;
private String resouceCode;
}

8
epmet-plugins-module/pli-power-base/pli-power-base-server/pom.xml

@ -83,6 +83,11 @@
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.8</version>
</dependency>
</dependencies>
<build>
@ -346,6 +351,9 @@
<hik.cloud.url>https://api2.hik-cloud.com</hik.cloud.url>
<hik.cloud.client>90688b09bb9d40088f7be404ccb347c7</hik.cloud.client>
<hik.cloud.secret>7b1940707a4240be9c794c5a967a30c9</hik.cloud.secret>
<!--大华-->
<dh.cloud.url>https://api2.hik-cloud.com</dh.cloud.url>
<dh.cloud.loginName>111</dh.cloud.loginName>
</properties>
</profile>
<profile>

4
epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/utils/HkDeviceUtil.java

@ -109,8 +109,8 @@ public class HkDeviceUtil {
logger.info(result.getMsg());
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "人员信息下发失败");
}
Object RegisterResult = result.getData();
JSONObject jsonObject = JSON.parseObject(RegisterResult.toString());
Object registerResult = result.getData();
JSONObject jsonObject = JSON.parseObject(registerResult.toString());
return jsonObject.getString("personId");
}

13
epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/visit/service/impl/VisitVisitorServiceImpl.java

@ -4,12 +4,14 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.IcNeighborHoodDTO;
import com.epmet.feign.GovOrgOpenFeignClient;
import com.epmet.plugin.power.dto.visit.VisitVisitorDTO;
import com.epmet.plugin.power.dto.visit.form.DhPersonFormDTO;
import com.epmet.plugin.power.dto.visit.form.VisitVisitorChartFormDTO;
import com.epmet.plugin.power.dto.visit.form.VisitVisitorFormDTO;
import com.epmet.plugin.power.dto.visit.result.VisitVisitorChartResultDTO;
@ -149,7 +151,16 @@ public class VisitVisitorServiceImpl extends BaseServiceImpl<VisitVisitorDao, Vi
* @date 2022/7/28 9:13
*/
private void send(VisitVisitorFormDTO dto) {
dhDeviceUtil.sendPerson(dto);
DhPersonFormDTO formDTO = new DhPersonFormDTO();
formDTO.setPaperType("身份证");
formDTO.setPaperNumber(dto.getIdCard());
formDTO.setName(dto.getName());
formDTO.setCode(dto.getIdCard().substring(dto.getIdCard().length() - 10));
formDTO.setSex(NumConstant.ZERO_STR.equals(dto.getGender()) ? "女" : "男");
formDTO.setBirthday(dto.getIdCard().substring(6, 10) + "-" + dto.getIdCard().substring(10, 12) + "-" + dto.getIdCard().substring(12, 14));
formDTO.setPhone(dto.getMobile());
formDTO.setStatus("在职");
dhDeviceUtil.addPersonAuth(formDTO, dto.getFaceImg());
}
}

483
epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/visit/utils/DhDeviceUtil.java

@ -1,26 +1,36 @@
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.form.DhAuthFormDTO;
import com.epmet.plugin.power.dto.visit.form.DhPersonCardFormDTO;
import com.epmet.plugin.power.dto.visit.form.DhPersonFormDTO;
import com.epmet.plugin.power.dto.visit.form.DhPersonImgFormDTO;
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 +50,14 @@ 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 ADD_PERSON_IMG = "/CardSolution/common/saveMobileBase64ImageToByte";
private final String ADD_AUTH = "/CardSolution/card/accessControl/doorAuthority/update";
private final String OPEN_CARD = "/CardSolution/card/card/open/batch";
/**
* 获取publicKey
@ -64,12 +80,12 @@ public class DhDeviceUtil {
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();
@ -99,12 +115,12 @@ public class DhDeviceUtil {
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();
token.setId(toResult.get("id").toString());
@ -116,38 +132,303 @@ public class DhDeviceUtil {
}
/**
* 下发人员
* 查询部门列表
*
* @param dto
* @return java.lang.String 人员ID
* @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 Long getDept() {
String url = dhCloudProperties.getUrl().concat(GET_DEPARTMENT);
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();
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, StringUtils.EMPTY, 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(), "查询部门列表失败");
}
Object registerResult = result.getData();
JSONArray jsonArray = JSON.parseArray(registerResult.toString());
JSONObject jsonObject = jsonArray.getJSONObject(0);
if (null != jsonObject) {
return Long.parseLong(jsonObject.get("deptId").toString());
}
return 0L;
}
/**
* 获取身份
*
* @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, 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(), "获取身份列表失败");
}
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(), "获取身份列表失败");
}
Object registerResult = result.getData();
JSONArray jsonArray = JSON.parseArray(registerResult.toString());
JSONObject jsonObject = jsonArray.getJSONObject(0);
if (null != jsonObject) {
return jsonObject.get("id").toString();
}
return "";
}
/**
* 查询开门计划
*
* @param
* @return java.lang.String
* @author zhy
* @date 2022/5/23 11:04
*/
public String getPlan() {
String url = dhCloudProperties.getUrl().concat(GET_DOOR_PLAN);
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(), "查询开门计划失败");
}
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(), "查询开门计划失败");
}
Object registerResult = result.getData();
JSONArray jsonArray = JSON.parseArray(registerResult.toString());
JSONObject jsonObject = jsonArray.getJSONObject(0);
if (null != jsonObject) {
return jsonObject.get("id").toString();
}
return "";
}
/**
* 查询通道
*
* @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);
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, StringUtils.EMPTY, 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(), "查询通道列表失败");
}
Object registerResult = result.getData();
JSONArray jsonArray = JSON.parseArray(registerResult.toString());
List<DhChannelResultDTO> list = new ArrayList<>();
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(0);
DhChannelResultDTO channel = new DhChannelResultDTO();
channel.setPrivilegeType("1");
channel.setResouceCode(jsonObject.get("channelCode").toString());
list.add(channel);
}
return list;
}
/**
* 新增人员
*
* @param dto
* @return java.lang.String
* @author zhy
* @date 2022/5/23 11:04
*/
public Long addPerson(DhPersonFormDTO dto) {
String url = dhCloudProperties.getUrl().concat(ADD_PERSON);
String urlParam = getDhUrlParams();
url = url + urlParam;
Long deptId = getDept();
if (0L == deptId) {
return null;
}
String identity = getIdentity();
if (StringUtils.isBlank(identity)) {
return null;
}
dto.setDeptId(deptId);
dto.setPersonIdentityId(identity);
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(), "人员信息下发失败");
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(), "新增人员失败");
}
Object registerResult = result.getData();
JSONObject jsonObject = JSON.parseObject(registerResult.toString());
if (null != jsonObject) {
return Long.parseLong(jsonObject.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 (!result.getSuccess()) {
logger.info(result.getErrMsg());
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "下发人员头像失败");
}
if (NumConstant.TWO_HUNDRED != result.getCode()) {
logger.info(result.getMsg());
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "人员信息下发失败");
Object registerResult = result.getData();
JSONObject jsonObject = JSON.parseObject(registerResult.toString());
if (null != jsonObject) {
return "success";
}
Object RegisterResult = result.getData();
JSONObject jsonObject = JSON.parseObject(RegisterResult.toString());
return jsonObject.getString("personId");
return "";
}
/**
* 人员开卡
*
* @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) {
return "添加人员信息失败";
}
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());
cardFormDTO.setCardPassword("0");
cardFormDTO.setSubSystems("1");
Map<String, String> paramsMap = new HashMap<>(4);
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(cardFormDTO), 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(), "人员开卡失败");
}
Object registerResult = result.getData();
JSONObject jsonObject = JSON.parseObject(registerResult.toString());
if (null != jsonObject) {
return cardFormDTO.getCardNumber();
}
return "";
}
/**
@ -158,27 +439,145 @@ public class DhDeviceUtil {
* @author zhy
* @date 2022/5/23 11:04
*/
public String authorityIssued(HikAuthorityFormDTO dto) {
String url = dhCloudProperties.getUrl().concat(ISSUE_AUTHORITY);
public String addPersonAuth(DhPersonFormDTO dto, String imgUrl) {
String personCard = addPersonCard(dto);
List<DhChannelResultDTO> channel = getChannel();
String plan = getPlan();
if (StringUtils.isBlank(personCard)) {
return "开卡失败";
} else if (StringUtils.isNotBlank(imgUrl)) {
addPersonImg(dto, imgUrl);
}
if (channel.isEmpty()) {
return "获取通道失败";
}
if (StringUtils.isBlank(plan)) {
return "获取开门计划失败";
}
DhAuthFormDTO authFormDTO = new DhAuthFormDTO();
String url = dhCloudProperties.getUrl().concat(ADD_AUTH);
String urlParam = getDhUrlParams();
url = url + urlParam;
authFormDTO.setCardNumber(personCard);
authFormDTO.setTimeQuantumId(plan);
authFormDTO.setCardPrivilegeDetails(channel);
Map<String, String> paramsMap = new HashMap<>(4);
paramsMap.put("Authorization", getAccessToken());
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(dto), paramsMap).getData();
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(authFormDTO), 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(), "下发人员权限失败");
}
return "success";
Object registerResult = result.getData();
JSONObject jsonObject = JSON.parseObject(registerResult.toString());
if (null != jsonObject) {
return "success";
}
return "";
}
/**
* 拼接url固定参数
*
* @param
* @return java.lang.String
* @author zhy
* @date 2022/7/28 16:09
*/
private String getDhUrlParams() {
DhToken token = getLoginPass(getAccessToken());
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
*/
public static 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
*/
public static 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();
}
}

142
epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/visit/utils/DhResult.java

@ -0,0 +1,142 @@
/**
* Copyright (c) 2018 人人开源 All rights reserved.
*
* https://www.renren.io
*
* 版权所有侵权必究
*/
package com.epmet.plugin.power.modules.visit.utils;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.ErrorCode;
import com.epmet.commons.tools.utils.MessageUtils;
import com.epmet.commons.tools.utils.Result;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
/**
* 响应数据
*
* @author Mark sunlightcs@gmail.com
* @since 1.0.0
*/
public class DhResult<T> implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 编码0表示成功其他值表示失败
*/
private Integer code = 0;
/**
* 消息内容
*/
private String errMsg = "success";
/**
* 内部信息
*/
private Boolean success = true;
/**
* 响应数据
*/
private T data;
public DhResult<T> ok(T data) {
this.setData(data);
return this;
}
public boolean success(){
return code == 0;
}
/**
* 返回
* "code": 8000,
* "msg": "服务器开小差了...",
*/
public DhResult<T> error() {
this.code = EpmetErrorCode.SERVER_ERROR.getCode();
this.errMsg = EpmetErrorCode.getMsg(code);
if (StringUtils.isBlank(this.errMsg)) {
this.errMsg = MessageUtils.getMessage(this.code);
}
return this;
}
/**
* 根据错误编码查询msg返回
*/
public DhResult<T> error(int code) {
this.code = code;
this.errMsg = EpmetErrorCode.getMsg(code);
if (StringUtils.isBlank(this.errMsg)) {
this.errMsg = MessageUtils.getMessage(this.code);
}
return this;
}
/**
* 传入错误编码+msg返回
*/
public DhResult<T> error(int code, String msg) {
this.code = code;
this.errMsg = msg;
return this;
}
/**
*
* @param msg
* @return 此方法废弃统一使用
* logger.error(XXXX);
* throw new RenException(XXXX);
* XXXX定义常量里
*/
@Deprecated
public DhResult<T> error(String msg) {
this.code = ErrorCode.INTERNAL_SERVER_ERROR;
this.errMsg = msg;
return this;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getErrMsg() {
return errMsg;
}
public void setErrMsg(String errMsg) {
this.errMsg = errMsg;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
@Override
public String toString() {
return JSON.toJSONString(this);
}
}
Loading…
Cancel
Save