diff --git a/epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhAuthFormDTO.java b/epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhAuthFormDTO.java new file mode 100644 index 0000000..0f5062e --- /dev/null +++ b/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 cardPrivilegeDetails; + +} \ No newline at end of file diff --git a/epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhPersonCardFormDTO.java b/epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhPersonCardFormDTO.java new file mode 100644 index 0000000..0c53aa0 --- /dev/null +++ b/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; + +} \ No newline at end of file diff --git a/epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhPersonFormDTO.java b/epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhPersonFormDTO.java new file mode 100644 index 0000000..3cfcc53 --- /dev/null +++ b/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; + +} \ No newline at end of file diff --git a/epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhPersonImgFormDTO.java b/epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhPersonImgFormDTO.java new file mode 100644 index 0000000..62c0e89 --- /dev/null +++ b/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; + +} \ No newline at end of file diff --git a/epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/result/DhChannelResultDTO.java b/epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/result/DhChannelResultDTO.java new file mode 100644 index 0000000..737b3e8 --- /dev/null +++ b/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; + +} \ No newline at end of file diff --git a/epmet-plugins-module/pli-power-base/pli-power-base-server/pom.xml b/epmet-plugins-module/pli-power-base/pli-power-base-server/pom.xml index d674639..0b22591 100644 --- a/epmet-plugins-module/pli-power-base/pli-power-base-server/pom.xml +++ b/epmet-plugins-module/pli-power-base/pli-power-base-server/pom.xml @@ -83,6 +83,11 @@ RELEASE compile + + net.coobird + thumbnailator + 0.4.8 + @@ -346,6 +351,9 @@ https://api2.hik-cloud.com 90688b09bb9d40088f7be404ccb347c7 7b1940707a4240be9c794c5a967a30c9 + + https://api2.hik-cloud.com + 111 diff --git a/epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/utils/HkDeviceUtil.java b/epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/utils/HkDeviceUtil.java index f52f535..fd9689b 100644 --- a/epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/utils/HkDeviceUtil.java +++ b/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"); } diff --git a/epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/visit/service/impl/VisitVisitorServiceImpl.java b/epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/visit/service/impl/VisitVisitorServiceImpl.java index b4b1a57..a923a45 100644 --- a/epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/visit/service/impl/VisitVisitorServiceImpl.java +++ b/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 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 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 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 getChannel() { + String url = dhCloudProperties.getUrl().concat(GET_DOOR_CHANNEL); + String urlParam = getDhUrlParams(); + url = url + urlParam; + + Map 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 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 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 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 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 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 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(); + } + + } diff --git a/epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/visit/utils/DhResult.java b/epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/visit/utils/DhResult.java new file mode 100644 index 0000000..86a8748 --- /dev/null +++ b/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 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 ok(T data) { + this.setData(data); + return this; + } + + public boolean success(){ + return code == 0; + } + + /** + * 返回 + * "code": 8000, + * "msg": "服务器开小差了...", + */ + public DhResult 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 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 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 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); + } +}