From f31c1d3d45a61e7e8b3abab8fffe093a35526c2f Mon Sep 17 00:00:00 2001 From: zhangyuan Date: Thu, 28 Jul 2022 16:21:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=86=E5=A4=87=E4=B8=8B=E5=8F=91=E8=AE=BE?= =?UTF-8?q?=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../power/dto/visit/form/DhPersonFormDTO.java | 39 +++++ .../power/modules/utils/HkDeviceUtil.java | 4 +- .../service/impl/VisitVisitorServiceImpl.java | 13 +- .../modules/visit/utils/DhDeviceUtil.java | 138 +++++++++++++---- .../power/modules/visit/utils/DhResult.java | 142 ++++++++++++++++++ 5 files changed, 301 insertions(+), 35 deletions(-) create mode 100644 epmet-plugins-module/pli-power-base/pli-power-base-client/src/main/java/com/epmet/plugin/power/dto/visit/form/DhPersonFormDTO.java create mode 100644 epmet-plugins-module/pli-power-base/pli-power-base-server/src/main/java/com/epmet/plugin/power/modules/visit/utils/DhResult.java 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-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..61e7787 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("code")) { + result.setCode(((Integer) toResult.get("code")).intValue()); + } + 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; - String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url, JSON.toJSONString(dto), paramsMap).getData(); + 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(), "人员信息下发失败"); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询部门列表失败"); } JSONObject toResult = JSON.parseObject(data); - Result result = ConvertUtils.mapToEntity(toResult, Result.class); + DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); if (null != toResult.get("code")) { result.setCode(((Integer) toResult.get("code")).intValue()); } - 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(), "查询部门列表失败"); } - Object RegisterResult = result.getData(); - JSONObject jsonObject = JSON.parseObject(RegisterResult.toString()); - return jsonObject.getString("personId"); + Object registerResult = result.getData(); + JSONArray jsonArray = JSON.parseArray(registerResult.toString()); + JSONObject jsonObject = jsonArray.getJSONObject(0); + if (null != jsonObject) { + return jsonObject.get("id").toString(); + } + return ""; } /** @@ -158,27 +202,57 @@ 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 addPerson(DhPersonFormDTO dto) { + String url = dhCloudProperties.getUrl().concat(ADD_PERSON); + String urlParam = getDhUrlParams(); + url = url + urlParam; + + Long deptId = getDept(); + if (0L == deptId) { + return ""; + } + String identity = getIdentity(); + if (StringUtils.isBlank(identity)) { + return ""; + } + dto.setDeptId(deptId); + dto.setPersonIdentityId(identity); Map 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); - Result result = ConvertUtils.mapToEntity(toResult, Result.class); + DhResult result = ConvertUtils.mapToEntity(toResult, DhResult.class); if (null != toResult.get("code")) { result.setCode(((Integer) toResult.get("code")).intValue()); } - 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 jsonObject.toString(); + } + 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(); } } 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); + } +}