|
@ -5,20 +5,32 @@ import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
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.redis.RedisUtils; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
import com.epmet.plugin.commons.redis.RedisKeys; |
|
|
import com.epmet.plugin.commons.redis.RedisKeys; |
|
|
import com.epmet.plugin.power.config.DhCloudProperties; |
|
|
import com.epmet.plugin.power.config.DhCloudProperties; |
|
|
|
|
|
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.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.apache.commons.lang3.StringUtils; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
import javax.imageio.ImageIO; |
|
|
import java.util.Map; |
|
|
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.*; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 海康设备下放命令 |
|
|
* 海康设备下放命令 |
|
@ -41,10 +53,11 @@ public class DhDeviceUtil { |
|
|
private final String GET_DEPARTMENT = "/CardSolution/card/department"; |
|
|
private final String GET_DEPARTMENT = "/CardSolution/card/department"; |
|
|
private final String GET_PERSON_IDENTITY = "/CardSolution/card/person/personidentity"; |
|
|
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_PLAN = "/CardSolution/card/accessControl/timeQuantum/1/page"; |
|
|
// private final String GET_DOOR_GROUP = "/api/v1/estate/entranceGuard/permissions/actions/authorityIssued";
|
|
|
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 = " /CardSolution/card/person"; |
|
|
private final String ADD_PERSON_IMG = "/CardSolution/common/saveMobileBase64ImageToByte"; |
|
|
private final String ADD_PERSON_IMG = "/CardSolution/common/saveMobileBase64ImageToByte"; |
|
|
private final String ADD_AUTH = " /CardSolution/card/accessControl/doorAuthority/update"; |
|
|
private final String ADD_AUTH = "/CardSolution/card/accessControl/doorAuthority/update"; |
|
|
|
|
|
private final String OPEN_CARD = "/CardSolution/card/card/open/batch"; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 获取publicKey |
|
|
* 获取publicKey |
|
@ -67,12 +80,12 @@ public class DhDeviceUtil { |
|
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPost(url, paramsMap).getData(); |
|
|
String data = HttpClientManager.getInstance().sendPost(url, paramsMap).getData(); |
|
|
if (null == data) { |
|
|
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); |
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
if (!toResult.containsKey("publicKey")) { |
|
|
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 accessToken = toResult.get("publicKey").toString(); |
|
|
|
|
|
|
|
@ -102,12 +115,12 @@ public class DhDeviceUtil { |
|
|
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPost(url, paramsMap).getData(); |
|
|
String data = HttpClientManager.getInstance().sendPost(url, paramsMap).getData(); |
|
|
if (null == data) { |
|
|
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); |
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
if (!toResult.containsKey("token")) { |
|
|
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(); |
|
|
DhToken token = new DhToken(); |
|
|
token.setId(toResult.get("id").toString()); |
|
|
token.setId(toResult.get("id").toString()); |
|
@ -140,8 +153,8 @@ public class DhDeviceUtil { |
|
|
} |
|
|
} |
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); |
|
|
DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); |
|
|
if (null != toResult.get("code")) { |
|
|
if (null != toResult.get("success")) { |
|
|
result.setCode(((Integer) toResult.get("code")).intValue()); |
|
|
result.setCode(200); |
|
|
} |
|
|
} |
|
|
if (!result.getSuccess()) { |
|
|
if (!result.getSuccess()) { |
|
|
logger.info(result.getErrMsg()); |
|
|
logger.info(result.getErrMsg()); |
|
@ -157,7 +170,7 @@ public class DhDeviceUtil { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 下发人员权限 |
|
|
* 获取身份 |
|
|
* |
|
|
* |
|
|
* @param |
|
|
* @param |
|
|
* @return java.lang.String |
|
|
* @return java.lang.String |
|
@ -174,16 +187,16 @@ public class DhDeviceUtil { |
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, StringUtils.EMPTY, paramsMap).getData(); |
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, StringUtils.EMPTY, paramsMap).getData(); |
|
|
|
|
|
|
|
|
if (null == data) { |
|
|
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); |
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); |
|
|
DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); |
|
|
if (null != toResult.get("code")) { |
|
|
if (null != toResult.get("success")) { |
|
|
result.setCode(((Integer) toResult.get("code")).intValue()); |
|
|
result.setCode(200); |
|
|
} |
|
|
} |
|
|
if (!result.getSuccess()) { |
|
|
if (!result.getSuccess()) { |
|
|
logger.info(result.getErrMsg()); |
|
|
logger.info(result.getErrMsg()); |
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询部门列表失败"); |
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取身份列表失败"); |
|
|
} |
|
|
} |
|
|
Object registerResult = result.getData(); |
|
|
Object registerResult = result.getData(); |
|
|
JSONArray jsonArray = JSON.parseArray(registerResult.toString()); |
|
|
JSONArray jsonArray = JSON.parseArray(registerResult.toString()); |
|
@ -195,25 +208,107 @@ public class DhDeviceUtil { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 下发人员权限 |
|
|
* 查询开门计划 |
|
|
|
|
|
* |
|
|
|
|
|
* @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 |
|
|
* @param dto |
|
|
* @return java.lang.String |
|
|
* @return java.lang.String |
|
|
* @author zhy |
|
|
* @author zhy |
|
|
* @date 2022/5/23 11:04 |
|
|
* @date 2022/5/23 11:04 |
|
|
*/ |
|
|
*/ |
|
|
public String addPerson(DhPersonFormDTO dto) { |
|
|
public Long addPerson(DhPersonFormDTO dto) { |
|
|
String url = dhCloudProperties.getUrl().concat(ADD_PERSON); |
|
|
String url = dhCloudProperties.getUrl().concat(ADD_PERSON); |
|
|
String urlParam = getDhUrlParams(); |
|
|
String urlParam = getDhUrlParams(); |
|
|
url = url + urlParam; |
|
|
url = url + urlParam; |
|
|
|
|
|
|
|
|
Long deptId = getDept(); |
|
|
Long deptId = getDept(); |
|
|
if (0L == deptId) { |
|
|
if (0L == deptId) { |
|
|
return ""; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
String identity = getIdentity(); |
|
|
String identity = getIdentity(); |
|
|
if (StringUtils.isBlank(identity)) { |
|
|
if (StringUtils.isBlank(identity)) { |
|
|
return ""; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
dto.setDeptId(deptId); |
|
|
dto.setDeptId(deptId); |
|
|
dto.setPersonIdentityId(identity); |
|
|
dto.setPersonIdentityId(identity); |
|
@ -223,21 +318,172 @@ public class DhDeviceUtil { |
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(dto), paramsMap).getData(); |
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(dto), paramsMap).getData(); |
|
|
|
|
|
|
|
|
if (null == data) { |
|
|
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); |
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); |
|
|
DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); |
|
|
if (null != toResult.get("code")) { |
|
|
if (null != toResult.get("success")) { |
|
|
result.setCode(((Integer) toResult.get("code")).intValue()); |
|
|
result.setCode(200); |
|
|
} |
|
|
} |
|
|
if (!result.getSuccess()) { |
|
|
if (!result.getSuccess()) { |
|
|
logger.info(result.getErrMsg()); |
|
|
logger.info(result.getErrMsg()); |
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询部门列表失败"); |
|
|
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); |
|
|
|
|
|
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 "success"; |
|
|
|
|
|
} |
|
|
|
|
|
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(); |
|
|
Object registerResult = result.getData(); |
|
|
JSONObject jsonObject = JSON.parseObject(registerResult.toString()); |
|
|
JSONObject jsonObject = JSON.parseObject(registerResult.toString()); |
|
|
if (null != jsonObject) { |
|
|
if (null != jsonObject) { |
|
|
return jsonObject.toString(); |
|
|
return cardFormDTO.getCardNumber(); |
|
|
|
|
|
} |
|
|
|
|
|
return ""; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 下发人员权限 |
|
|
|
|
|
* |
|
|
|
|
|
* @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); |
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
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(), "下发人员权限失败"); |
|
|
|
|
|
} |
|
|
|
|
|
Object registerResult = result.getData(); |
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(registerResult.toString()); |
|
|
|
|
|
if (null != jsonObject) { |
|
|
|
|
|
return "success"; |
|
|
} |
|
|
} |
|
|
return ""; |
|
|
return ""; |
|
|
} |
|
|
} |
|
@ -255,4 +501,83 @@ public class DhDeviceUtil { |
|
|
return "?userId=" + token.getId() + "&username=" + token.getLoginName() + "&token=" + token.getToken(); |
|
|
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(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|