refactor(sis):

- 第三方数据添加失败通过mq回写信息
refactor(property):
- 仪表sse推送,增加水表消息推送
This commit is contained in:
2025-09-10 20:24:29 +08:00
parent 3317793834
commit a3bd994fa3
26 changed files with 399 additions and 386 deletions

View File

@@ -36,4 +36,6 @@ public class RemoteResidentPersonVo implements Serializable {
private Date authEndDate;
private Integer rosterType;
private String tenantId;
}

View File

@@ -45,4 +45,6 @@ public class RemotePersonAuth implements Serializable {
private Integer rosterType;
private String tenantId;
}

View File

@@ -167,4 +167,6 @@ public class ResidentPersonVo implements Serializable {
private Date updateTime;
private String tenantId;
}

View File

@@ -43,6 +43,7 @@ public class RemoteResidentPersonServiceImpl implements RemoteResidentPersonServ
remoteResidentPersonVo.setAuthGroupId(vo.getAuthGroupId());
remoteResidentPersonVo.setAuthBegDate(vo.getAuthBegDate());
remoteResidentPersonVo.setAuthEndDate(vo.getAuthEndDate());
remoteResidentPersonVo.setTenantId(vo.getTenantId());
return remoteResidentPersonVo;
}).toList();
}
@@ -53,6 +54,7 @@ public class RemoteResidentPersonServiceImpl implements RemoteResidentPersonServ
ResidentPersonBo bo = new ResidentPersonBo();
bo.setId(personId);
bo.setEEightId(e8Id);
bo.setRemark("");
return residentPersonService.updateByBo(bo);
}

View File

@@ -9,10 +9,16 @@ public interface RocketMqConstants {
// mq topic
String TOPIC = "SmartParks";
// mq GROUP
// 仪表消费组
String METER_GROUP = "METER_GROUP";
// 授权记录消费组
String AUTH_GROUP = "AUTH_GROUP";
/*-----------------------------------消息tag------------------------------------*/
// 仪表记录
String METER_RECORD = "METER_RECORD_TAG";
// 授权记录
String AUTH_RECORD = "AUTH_MESSAGE_REPORT";
}

View File

@@ -0,0 +1,9 @@
package org.dromara.property.rocketmq.consumer;
/**
* @author lsm
* @apiNote AuthRecordConsumer
* @since 2025/9/10
*/
public class AuthRecordConsumer {
}

View File

@@ -726,6 +726,7 @@ public class ServiceWorkOrdersServiceImpl implements IServiceWorkOrdersService {
assert add != null;
add.setOrderName("工单名称");
add.setProcessingWeight(typeVo.getProcessingWeight());
add.setOrderNo("GD" + IdUtil.getSnowflakeNextIdStr());
add.setStatus(WorkOrderStatusEnum.CREATE_ORDER.getValue());
add.setReportingType(OrderReportingTypeEnum.PHONE_REPORT.getValue());

View File

@@ -246,7 +246,8 @@ public class TbMeterInfoServiceImpl implements ITbMeterInfoService {
List<TbMeterInfoVo> meterInfoVos = this.queryList(bo);
if (isMeter) {
if (meterInfoVos != null && !meterInfoVos.isEmpty()) {
List<TreeNode<Long>> l4 = meterInfoVos.stream().map(item -> {
List<TbMeterInfoVo> sortList = meterSort(meterInfoVos);
List<TreeNode<Long>> l4 = sortList.stream().map(item -> {
TreeNode<Long> node = new TreeNode<>();
node.setLevel(4);
node.setCode(item.getId());
@@ -278,20 +279,22 @@ public class TbMeterInfoServiceImpl implements ITbMeterInfoService {
// 获取当前登录用户
LoginUser user = LoginHelper.getLoginUser();
String tokenValue = StpUtil.getTokenValue();
String meter = meterType == 1L ? "power" : meterType == 2L ? "water" : meterType == 3L ? "gas" : "";
if (user == null) {
heartbeatTasks.stopTask(tokenValue);
heartbeatTasks.stopTask(tokenValue + meter);
return;
}
// 参数校验
if (meterType == 0L || floorId == 0L) {
heartbeatTasks.stopTask(tokenValue);
heartbeatTasks.stopTask(tokenValue + meter);
return;
}
// 初始化WebSocket消息
JSONObject jsonObject = new JSONObject();
jsonObject.put("type", "meter");
jsonObject.put("meterType", meterType);
// 查询仪表信息
TbMeterInfoBo meterInfoBo = new TbMeterInfoBo();
@@ -301,7 +304,7 @@ public class TbMeterInfoServiceImpl implements ITbMeterInfoService {
// 如果没有仪表信息,直接返回
if (meterInfoVoList.isEmpty()) {
heartbeatTasks.stopTask(tokenValue);
heartbeatTasks.stopTask(tokenValue + meter);
jsonObject.put("readingTime", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
jsonObject.put("data", new ArrayList<>());
remoteMessageService.sendMessage(user.getUserId(), tokenValue, jsonObject.toString());
@@ -320,7 +323,7 @@ public class TbMeterInfoServiceImpl implements ITbMeterInfoService {
}
// 启动定时任务
heartbeatTasks.startHeartbeatTask(tokenValue, () -> {
heartbeatTasks.startHeartbeatTask(tokenValue + meter, () -> {
jsonObject.put("readingTime", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
List<MeterResult> meterResults;
@@ -349,8 +352,8 @@ public class TbMeterInfoServiceImpl implements ITbMeterInfoService {
// 创建比较器
Comparator<TbMeterInfoVo> comparator = (m1, m2) -> {
// 提取楼层和编号数值
int[] parts1 = extractNumbers(m1.getMeterName());
int[] parts2 = extractNumbers(m2.getMeterName());
int[] parts1 = extractNumbers(m1.getMeterName(), m1.getMeterType());
int[] parts2 = extractNumbers(m2.getMeterName(), m2.getMeterType());
// 先比较楼层
if (parts1[0] != parts2[0]) {
@@ -366,11 +369,13 @@ public class TbMeterInfoServiceImpl implements ITbMeterInfoService {
/**
* 从字符串提取数字(返回[楼层, 编号]
*
* @param name 仪表名称
* @param name 仪表名称
* @param meterType 水电气类型
* @return int[]
*/
private int[] extractNumbers(String name) {
Pattern pattern = Pattern.compile("(\\d+)楼电表(\\d+)号");
private int[] extractNumbers(String name, Long meterType) {
String meter = meterType == 1L ? "" : meterType == 2L ? "" : "";
Pattern pattern = Pattern.compile("(\\d+)楼" + meter + "表(\\d+)号");
Matcher matcher = pattern.matcher(name);
if (matcher.find()) {
return new int[]{Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))};

View File

@@ -7,6 +7,7 @@ import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.sis.sdk.e8.E8PlatformApi;
import org.dromara.sis.sdk.e8.domain.ApiResp;
import org.dromara.sis.sdk.e8.domain.QueryDto;
import org.dromara.sis.sdk.e8.domain.accessControl.req.AccessRecordFindReq;
import org.dromara.sis.sdk.e8.domain.accessControl.res.AccessRecordFindRes;
@@ -72,7 +73,7 @@ public class E8Controller {
dto.setQueryDto(req);
dto.setPageIndex(pageNum);
dto.setMaxResultCount(pageSize);
return e8PlatformApi.getPageAccessRecordList(dto);
return e8PlatformApi.getPageAccessRecordList(dto).getResult();
}
/**
@@ -82,7 +83,7 @@ public class E8Controller {
*/
@GetMapping("/door/online")
public R<Map<String, Long>> doorOnline() {
List<AuthDoorDeviceFindRes> list = e8PlatformApi.getPageAuthDoorDeviceList();
List<AuthDoorDeviceFindRes> list = e8PlatformApi.getPageAuthDoorDeviceList().getResult();
Map<String, Long> map = new HashMap<>();
map.put("on", list.stream().filter(o -> o.getOnlineStatus() == 1).count());
map.put("off", list.stream().filter(o -> o.getOnlineStatus() == 0).count());

View File

@@ -88,4 +88,9 @@ public class SisPersonLibImgBo extends BaseEntity {
* 图片MD5
*/
private String imgMd5Value;
/**
* 租户id
*/
private String tenantId;
}

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
@@ -14,12 +15,18 @@ import org.dromara.sis.domain.vo.SisAccessControlVo;
import org.dromara.sis.domain.vo.SisAuthGroupRefVo;
import org.dromara.sis.domain.vo.SisAuthRecordVo;
import org.dromara.sis.domain.vo.SisPersonLibImgVo;
import org.dromara.sis.rocketmq.RocketMqConstants;
import org.dromara.sis.rocketmq.producer.ProducerService;
import org.dromara.sis.sdk.e8.E8PlatformApi;
import org.dromara.sis.sdk.e8.domain.ApiResp;
import org.dromara.sis.sdk.e8.domain.accessControl.req.CustomerAuthAddReq;
import org.dromara.sis.sdk.e8.domain.custom.req.CustomAddReq;
import org.dromara.sis.sdk.e8.domain.custom.res.CustomAddRes;
import org.dromara.sis.sdk.e8.domain.voucher.req.IssueVoucherReq;
import org.dromara.sis.sdk.e8.domain.voucher.res.IssueVoucherRes;
import org.dromara.sis.sdk.huawei.HuaWeiBoxApi;
import org.dromara.sis.sdk.huawei.domain.AddHWPersonReq;
import org.dromara.sis.sdk.huawei.domain.HWResult;
import org.dromara.sis.service.ISisAccessControlService;
import org.dromara.sis.service.ISisAuthGroupRefService;
import org.dromara.sis.service.ISisAuthRecordService;
@@ -47,6 +54,8 @@ public class RemoteSisAuthServiceImpl implements RemoteSisAuthService {
private final ISisAuthGroupRefService sisAuthGroupRefService;
private final ISisAccessControlService sisAccessControlService;
private final ProducerService producerService;
/**
* 人员授权
*
@@ -55,7 +64,14 @@ public class RemoteSisAuthServiceImpl implements RemoteSisAuthService {
*/
@Override
public Boolean personAuth(RemotePersonAuth personAuth) {
return sisAuthRecordService.insertByPerson(personAuth);
Boolean flag = sisAuthRecordService.insertByPerson(personAuth);
if (!flag) {
JSONObject jsonObject = new JSONObject();
jsonObject.putOnce("personId", personAuth.getId());
jsonObject.putOnce("message", "写入授权记录失败!");
producerService.send(RocketMqConstants.TOPIC, RocketMqConstants.AUTH_MESSAGE, jsonObject.toString());
}
return flag;
}
/**
@@ -113,24 +129,41 @@ public class RemoteSisAuthServiceImpl implements RemoteSisAuthService {
}
AddHWPersonReq req = new AddHWPersonReq();
req.setIndex(CodePrefixConstants.PERSON_LIB_IMAGE_CODE_PREFIX + IdUtil.getSnowflakeNextIdStr());
req.setName(person.getName());
req.setCredentialType("5");
req.setCredentialNumber(vo.getId().toString());
req.setGender(person.getSex() == 1 ? "0" : person.getSex() == 2 ? "1" : "-1");
ArrayList<String> pictures = new ArrayList<>();
pictures.add(Base64.getEncoder().encodeToString(imgByte));
req.setPictures(pictures);
pId = huaWeiBoxApi.addPerson(List.of(req));
req.setName(person.getName());
pId = addHuaWeiBox(req, person.getId().toString(), imgByte);
} catch (Exception e) {
log.info("同步华为盒子失败:{}----{}", person.getName(), person.getId());
JSONObject jsonObject = new JSONObject();
jsonObject.putOnce("message", e.getMessage());
jsonObject.putOnce("personId", person.getId());
producerService.send(RocketMqConstants.TOPIC, RocketMqConstants.AUTH_MESSAGE, jsonObject.toString());
log.info("{}{}----{}", e.getMessage(), person.getName(), person.getId());
return null;
}
return pId;
}
public Long addHuaWeiBox(AddHWPersonReq req, String id, byte[] imgByte) {
req.setCredentialNumber(id);
req.setIndex(CodePrefixConstants.PERSON_LIB_IMAGE_CODE_PREFIX + IdUtil.getSnowflakeNextIdStr());
ArrayList<String> pictures = new ArrayList<>();
pictures.add(Base64.getEncoder().encodeToString(imgByte));
req.setPictures(pictures);
HWResult<Long> result = huaWeiBoxApi.addPerson(List.of(req));
Assert.notNull(result, "调用华为盒子新增图片出错");
if (result.getCode() != 200) {
JSONObject jsonObject = new JSONObject();
jsonObject.putOnce("personId", id);
jsonObject.putOnce("message", result.getMessage());
producerService.send(RocketMqConstants.TOPIC, RocketMqConstants.AUTH_MESSAGE, jsonObject.toString());
return null;
} else {
return result.getData();
}
}
/**
* 更新人像信息
*
@@ -159,18 +192,20 @@ public class RemoteSisAuthServiceImpl implements RemoteSisAuthService {
try {
log.info("e8平台上传照片");
String e8ImgUrl = e8PlatformApi.uploadFace(imgByte);
Assert.notNull(e8ImgUrl, "图片上传E8平台失败" + person.getName() + "----" + person.getId());
ApiResp<String> imgResult = e8PlatformApi.uploadFace(imgByte);
Assert.isTrue(imgResult.getSuccess(), "图片上传E8平台失败" + imgResult.getMessage() + "--" + person.getName() + "----" + person.getId());
log.info("e8平台上传照片完成");
String e8ImgUrl = imgResult.getResult();
count++; // 图片上传完成步进器+1
log.info("e8同步新建人员");
CustomAddReq req = new CustomAddReq();
req.setName(person.getName());
req.setGender(person.getSex() != 1 ? 0 : 1);
e8Id = e8PlatformApi.addCustomer(req).getId();
Assert.notNull(e8Id, "e8同步新建人员失败" + person.getName() + "----" + person.getId());
ApiResp<CustomAddRes> cusResult = e8PlatformApi.addCustomer(req);
Assert.isTrue(cusResult.getSuccess(), "e8同步新建人员失败" + cusResult.getMessage() + "--" + person.getName() + "----" + person.getId());
log.info("e8同步新建人员完成");
e8Id = cusResult.getResult().getId();
count++; // 新增人员完成步进器+1
log.info("e8平台开始发行凭证");
@@ -179,8 +214,8 @@ public class RemoteSisAuthServiceImpl implements RemoteSisAuthService {
voucherReq.setPersonID(e8Id);
voucherReq.setTxtData(e8ImgUrl);
voucherReq.setCardType(34);
Long voucherId = e8PlatformApi.issueVoucher(voucherReq);
Assert.notNull(voucherId, "e8平台发行凭证失败" + person.getName() + "----" + person.getId());
ApiResp<IssueVoucherRes> voucherResult = e8PlatformApi.issueVoucher(voucherReq);
Assert.isTrue(voucherResult.getSuccess(), "e8平台发行凭证失败" + voucherResult.getMessage() + "--" + person.getName() + "----" + person.getId());
log.info("e8平台发行凭证成功");
count++; // 发行凭证完成步进器+1
@@ -206,13 +241,17 @@ public class RemoteSisAuthServiceImpl implements RemoteSisAuthService {
authReq.setAuthData(list);
log.info("e8平台开始授权");
Boolean flag = e8PlatformApi.addCustomerAuth(authReq);
Assert.isTrue(flag, "E8平台授权失败" + person.getName() + "----" + person.getId());
ApiResp<Void> flag = e8PlatformApi.addCustomerAuth(authReq);
Assert.isTrue(flag.getSuccess(), "E8平台授权失败" + flag.getMessage() + "--" + person.getName() + "----" + person.getId());
log.info("E8平台授权完成!");
count++; // 授权完成步进器+1
}
} catch (Exception e) {
log.info(e.getMessage());
JSONObject jsonObject = new JSONObject();
jsonObject.putOnce("personId", person.getId());
jsonObject.putOnce("message", e.getMessage());
producerService.send(RocketMqConstants.TOPIC, RocketMqConstants.AUTH_MESSAGE, jsonObject.toString());
return null;
}

View File

@@ -51,7 +51,7 @@ public class RemoteVisitorServiceImpl implements RemoteVisitorService {
byte[] zipByte = imageUtil.compressImageToRequirements(imgByte);
imgUrl = e8PlatformApi.uploadFace(zipByte);
imgUrl = e8PlatformApi.uploadFace(zipByte).getResult();
Assert.notNull(imgUrl, "e8平台上传访客照片失败");
}
VisitorAddReq req = new VisitorAddReq();

View File

@@ -29,4 +29,6 @@ public interface RocketMqConstants {
String HIGH_DENSITY = "HIGH_DENSITY_REPORT";
// 停车上报
String PARKING_ALARM = "PARKING_ALARM_REPORT";
// 授权消息上报
String AUTH_MESSAGE = "AUTH_MESSAGE_REPORT";
}

View File

@@ -0,0 +1,37 @@
package org.dromara.sis.rocketmq.producer;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.stereotype.Component;
/**
* @author lsm
* @apiNote ProducerService
* @since 2025/9/9
*/
@Slf4j
@Component
public class ProducerService {
@Resource
private RocketMQTemplate rocketMqTemplate;
/**
* 向mq写入消息
*
* @param topic 消息topic
* @param tag 消息tag
* @param msg 消息
*/
public void send(String topic, String tag, String msg) {
Message message = new Message(topic, tag, msg.getBytes());
try {
rocketMqTemplate.getProducer().send(message);
log.info("发送RocketMQ消息成功");
} catch (Exception e) {
log.error("发送RocketMQ消息失败", e);
}
}
}

View File

@@ -21,9 +21,11 @@ import org.dromara.sis.sdk.e8.domain.lift.req.LiftAddReq;
import org.dromara.sis.sdk.e8.domain.lift.req.LiftUpdateReq;
import org.dromara.sis.sdk.e8.domain.lift.res.LiftFindRes;
import org.dromara.sis.sdk.e8.domain.visitors.req.VisitorAddReq;
import org.dromara.sis.sdk.e8.domain.visitors.res.VisitorAddRes;
import org.dromara.sis.sdk.e8.domain.voucher.req.ChangeCardReq;
import org.dromara.sis.sdk.e8.domain.voucher.req.IssueVoucherReq;
import org.dromara.sis.sdk.e8.domain.voucher.req.OperateVoucherReq;
import org.dromara.sis.sdk.e8.domain.voucher.res.IssueVoucherRes;
import java.util.List;
@@ -42,7 +44,7 @@ public interface E8PlatformApi {
* @param findReq 传参
* @return CustomFindRes
*/
CustomFindRes findCustomer(CustomFindReq findReq);
ApiResp<CustomFindRes> findCustomer(CustomFindReq findReq);
/**
* 人员信息分页查询
@@ -50,31 +52,31 @@ public interface E8PlatformApi {
* @param dto 传参
* @return TableDataInfo<CustomFindRes>
*/
TableDataInfo<CustomFindRes> findCustomerList(QueryDto dto);
ApiResp<TableDataInfo<CustomFindRes>> findCustomerList(QueryDto dto);
/**
* 新增人员信息
*
* @param addReq 传参
* @return CustomAddRes
* @return ApiResp<CustomAddRes>
*/
CustomAddRes addCustomer(CustomAddReq addReq);
ApiResp<CustomAddRes> addCustomer(CustomAddReq addReq);
/**
* 人员信息修改
*
* @param updateReq 传参
* @return Boolean
* @return ApiResp<Void>
*/
Boolean updateCustomer(CustomUpdateReq updateReq);
ApiResp<Void> updateCustomer(CustomUpdateReq updateReq);
/**
* 删除人员信息
*
* @param id 传参
* @return Boolean
* @return ApiResp<Void>
*/
Boolean deleteCustomer(Long id);
ApiResp<Void> deleteCustomer(Long id);
//***************************************门禁信息接口*******************************************
@@ -84,7 +86,7 @@ public interface E8PlatformApi {
* @param id 入参
* @return DoorDeviceFindRes
*/
DoorDeviceFindRes findDoorDevice(Long id);
ApiResp<DoorDeviceFindRes> findDoorDevice(Long id);
/**
* 门禁信息分页查询
@@ -92,7 +94,7 @@ public interface E8PlatformApi {
* @param dto 入参
* @return IPage<DoorDeviceFindRes>
*/
TableDataInfo<DoorDeviceFindRes> findDoorDeviceList(QueryDto dto);
ApiResp<TableDataInfo<DoorDeviceFindRes>> findDoorDeviceList(QueryDto dto);
/**
* 新增门禁信息
@@ -100,7 +102,7 @@ public interface E8PlatformApi {
* @param addReq 入参
* @return DoorDeviceAddRes
*/
DoorDeviceAddRes addDoorDevice(DoorDeviceAddReq addReq);
ApiResp<DoorDeviceAddRes> addDoorDevice(DoorDeviceAddReq addReq);
/**
* 门禁信息修改
@@ -108,7 +110,7 @@ public interface E8PlatformApi {
* @param updateReq 入参
* @return DoorDeviceUpdateRes
*/
Boolean updateDoorDevice(DoorDeviceUpdateReq updateReq);
ApiResp<Void> updateDoorDevice(DoorDeviceUpdateReq updateReq);
/**
* 删除门禁信息
@@ -116,14 +118,14 @@ public interface E8PlatformApi {
* @param id 入参
* @return Boolean
*/
Boolean deleteDoorDevice(Long id);
ApiResp<Void> deleteDoorDevice(Long id);
/**
* 分页获取授权门信息
*
* @return TableDataInfo<AuthDoorDeviceFindRes>
* @return List<AuthDoorDeviceFindRes>
*/
List<AuthDoorDeviceFindRes> getPageAuthDoorDeviceList();
ApiResp<List<AuthDoorDeviceFindRes>> getPageAuthDoorDeviceList();
/**
* 远程开门
@@ -131,7 +133,7 @@ public interface E8PlatformApi {
* @param req 传参
* @return Boolean
*/
Boolean remoteOpenDoor(RemoteOpenDoorReq req);
ApiResp<Void> remoteOpenDoor(RemoteOpenDoorReq req);
/**
@@ -140,7 +142,7 @@ public interface E8PlatformApi {
* @param dto 传参
* @return IPage<AccessRecordFindRes>
*/
TableDataInfo<AccessRecordFindRes> getPageAccessRecordList(QueryDto dto);
ApiResp<TableDataInfo<AccessRecordFindRes>> getPageAccessRecordList(QueryDto dto);
/**
* 人员授权
@@ -148,7 +150,7 @@ public interface E8PlatformApi {
* @param req 传参
* @return Boolean
*/
Boolean addCustomerAuth(CustomerAuthAddReq req);
ApiResp<Void> addCustomerAuth(CustomerAuthAddReq req);
/**
* 获取人员权限分页列表
@@ -156,7 +158,7 @@ public interface E8PlatformApi {
* @param dto 传参
* @return TableDataInfo<CustomerAuthFindRes>
*/
TableDataInfo<CustomerAuthFindRes> getPageCustomerAuth(QueryDto dto);
ApiResp<TableDataInfo<CustomerAuthFindRes>> getPageCustomerAuth(QueryDto dto);
//***************************************电梯信息接口*******************************************
@@ -166,7 +168,7 @@ public interface E8PlatformApi {
* @param dto 传参
* @return TableDataInfo<LiftFindRes>
*/
TableDataInfo<LiftFindRes> getPageList(QueryDto dto);
ApiResp<TableDataInfo<LiftFindRes>> getPageList(QueryDto dto);
/**
* 查询电梯楼层
@@ -174,7 +176,7 @@ public interface E8PlatformApi {
* @param id 传参
* @return LiftFindRes
*/
LiftFindRes getLiftFloor(Long id);
ApiResp<LiftFindRes> getLiftFloor(Long id);
/**
* 添加电梯
@@ -182,7 +184,7 @@ public interface E8PlatformApi {
* @param addReq 传参
* @return Boolean
*/
Boolean addLift(LiftAddReq addReq);
ApiResp<Void> addLift(LiftAddReq addReq);
/**
* 修改电梯信息
@@ -190,7 +192,7 @@ public interface E8PlatformApi {
* @param updateReq 传参
* @return Boolean
*/
Boolean updateLift(LiftUpdateReq updateReq);
ApiResp<Void> updateLift(LiftUpdateReq updateReq);
/**
* 删除电梯信息
@@ -198,7 +200,7 @@ public interface E8PlatformApi {
* @param id 传参
* @return Boolean
*/
Boolean deleteLift(Integer id);
ApiResp<Void> deleteLift(Integer id);
//***************************************凭证信息接口*******************************************
@@ -208,7 +210,7 @@ public interface E8PlatformApi {
* @param req 凭证数据
* @return Boolean
*/
Long issueVoucher(IssueVoucherReq req);
ApiResp<IssueVoucherRes> issueVoucher(IssueVoucherReq req);
/**
* 操作凭证
@@ -216,7 +218,7 @@ public interface E8PlatformApi {
* @param req 入参
* @return Boolean
*/
Boolean operateVoucher(OperateVoucherReq req);
ApiResp<Void> operateVoucher(OperateVoucherReq req);
/**
* 换卡补卡
@@ -224,7 +226,7 @@ public interface E8PlatformApi {
* @param req 入参
* @return Boolean
*/
Boolean changeCard(ChangeCardReq req);
ApiResp<Void> changeCard(ChangeCardReq req);
/**
* 上传人脸
@@ -232,7 +234,7 @@ public interface E8PlatformApi {
* @param imageByte 入参
* @return imageUrl 人脸图片地址
*/
String uploadFace(byte[] imageByte);
ApiResp<String> uploadFace(byte[] imageByte);
//***************************************访客信息接口*******************************************
@@ -242,7 +244,7 @@ public interface E8PlatformApi {
* @param req 入参
* @return ApiResp
*/
ApiResp addVisitor(VisitorAddReq req);
ApiResp<VisitorAddRes> addVisitor(VisitorAddReq req);
/**
* 获取访客二维码
@@ -250,5 +252,5 @@ public interface E8PlatformApi {
* @param ids 访客ids
* @return ApiResp
*/
ApiResp getVisitorQrCode(List<Long> ids);
ApiResp<VisitorAddRes> getVisitorQrCode(List<Long> ids);
}

View File

@@ -10,7 +10,7 @@ import lombok.Data;
*/
@Data
@AllArgsConstructor
public class ApiResp {
public class ApiResp<T> {
/**
* success为false时返回错误信息
*/
@@ -24,7 +24,7 @@ public class ApiResp {
/**
* 返回处理结果(数据由具体接口决定)
*/
private Object result;
private T result;
/**
* true表示成功false表示失败

View File

@@ -2,6 +2,7 @@ package org.dromara.sis.sdk.e8.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -31,6 +32,7 @@ import org.dromara.sis.sdk.e8.domain.lift.req.LiftFindReq;
import org.dromara.sis.sdk.e8.domain.lift.req.LiftUpdateReq;
import org.dromara.sis.sdk.e8.domain.lift.res.LiftFindRes;
import org.dromara.sis.sdk.e8.domain.visitors.req.VisitorAddReq;
import org.dromara.sis.sdk.e8.domain.visitors.res.VisitorAddRes;
import org.dromara.sis.sdk.e8.domain.voucher.req.ChangeCardReq;
import org.dromara.sis.sdk.e8.domain.voucher.req.IssueVoucherReq;
import org.dromara.sis.sdk.e8.domain.voucher.req.OperateVoucherReq;
@@ -58,7 +60,68 @@ public class E8PlatformApiService implements E8PlatformApi {
@Value("${E8Plat.imgUrl}")
private String imgUrl;
private final static String URL = "http://192.168.24.8:50030";
private final static String E8_BASE_URL = "http://192.168.24.8:50030";
/**
* 统一处理API响应
*
* @param result JSON字符串响应
* @param clazz 目标类型
* @param <T> 泛型类型
* @return ApiResp<T>
*/
private <T> ApiResp<T> handleApiResponse(String result, Class<T> clazz) {
if (result == null) {
return new ApiResp<>("E8服务器内部错误", null, null, false, 500);
}
JSONObject apiResp = JSONUtil.parseObj(result);
T data = null;
if (apiResp.containsKey("result") && clazz != Void.class) {
data = JSONUtil.toBean(apiResp.getStr("result"), clazz);
}
return new ApiResp<>(
apiResp.getStr("message"),
apiResp.getLong("sessionId"),
data,
apiResp.getBool("success"),
apiResp.getInt("code")
);
}
/**
* 统一处理分页API响应
*
* @param result JSON字符串响应
* @param clazz 列表元素类型
* @param <T> 泛型类型
* @return ApiResp<TableDataInfo < T>>
*/
private <T> ApiResp<TableDataInfo<T>> handlePagedApiResponse(String result, Class<T> clazz) {
if (result == null) {
return new ApiResp<>("E8服务器内部错误", null, null, false, 500);
}
JSONObject apiResp = JSONUtil.parseObj(result);
Map<String, Object> resultMap = JSONUtil.toBean(apiResp.getStr("result"), new TypeReference<Map<String, Object>>() {
}, false);
TableDataInfo<T> tableDataInfo = new TableDataInfo<>();
tableDataInfo.setTotal(Long.parseLong(resultMap.get("total").toString()));
tableDataInfo.setRows(JSONUtil.toList(JSONUtil.toJsonStr(resultMap.get("item")), clazz));
tableDataInfo.setCode(200);
tableDataInfo.setMsg("查询成功");
return new ApiResp<>(
apiResp.getStr("message"),
apiResp.getLong("sessionId"),
tableDataInfo,
apiResp.getBool("success"),
apiResp.getInt("code")
);
}
//***************************************客户信息接口*******************************************
private final static String CUSTOMER_GET_PAGE_LIST = "/api/E8/customer/get-page-list";
@@ -74,22 +137,12 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return CustomerInfo
*/
@Override
public CustomFindRes findCustomer(CustomFindReq findReq) {
public ApiResp<CustomFindRes> findCustomer(CustomFindReq findReq) {
// 将查询请求对象转换为参数映射
Map<String, Object> params = BeanUtil.beanToMap(findReq);
// 调用API接口获取客户信息
ApiResp apiResp = e8ApiUtil.doPost(params, CUSTOMER_GET_FIRST_OR_DEFAULT);
// 检查API调用是否成功
if (!apiResp.getSuccess()) {
log.error("E8查询人员信息失败 errorMsg:{}", apiResp);
// 如果API调用失败返回null
return null;
}
// 将API响应结果转换为CustomFindRes对象并返回
return JSONUtil.toBean(JSONUtil.toJsonStr(apiResp.getResult()), CustomFindRes.class);
String result = e8ApiUtil.doPost(params, CUSTOMER_GET_FIRST_OR_DEFAULT);
return handleApiResponse(result, CustomFindRes.class);
}
/**
@@ -99,7 +152,7 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return IPage<CustomerInfo>
*/
@Override
public TableDataInfo<CustomFindRes> findCustomerList(QueryDto dto) {
public ApiResp<TableDataInfo<CustomFindRes>> findCustomerList(QueryDto dto) {
// 创建参数映射用于存储HTTP请求的参数
Map<String, Object> params = new HashMap<>();
// 添加分页参数:当前页码和最大结果数量
@@ -108,53 +161,25 @@ public class E8PlatformApiService implements E8PlatformApi {
// 将查询条件对象转换为JSON字符串并再次转换为Map对象然后添加到参数映射中
params.put("queryDto", JSONUtil.toBean(JSONUtil.toJsonStr(dto.getQueryDto()), CustomFindReq.class));
// 调用API工具类的POST方法发送请求到第三方API并获取响应结果
ApiResp apiResp = e8ApiUtil.doPost(params, CUSTOMER_GET_PAGE_LIST);
if (!apiResp.getSuccess()) {
log.error("E8人员信息分页查询 errorMsg:{}", apiResp);
// 如果API响应不成功返回null
return null;
}
// 将API响应结果转换为Map对象以便于后续处理
Map<String, Object> result = JSONUtil.toBean(JSONUtil.toJsonStr(apiResp.getResult()), new TypeReference<>() {
}, false);
// 创建一个分页对象,用于存储客户信息列表和分页数据
TableDataInfo<CustomFindRes> tableDataInfo = new TableDataInfo<>();
// 设置总记录数
tableDataInfo.setTotal(Long.parseLong(result.get("total").toString()));
// 将API响应结果中的客户信息列表转换为CustomFindRes对象列表并设置到分页对象中
tableDataInfo.setRows(JSONUtil.toList(JSONUtil.toJsonStr(result.get("item")), CustomFindRes.class));
// 返回分页对象
return tableDataInfo;
// 调用API接口获取人员分页信息
String result = e8ApiUtil.doPost(params, CUSTOMER_GET_PAGE_LIST);
return handlePagedApiResponse(result, CustomFindRes.class);
}
/**
* 新增人员信息
*
* @param addReq 传参
* @return Boolean
* @return ApiResp<CustomAddRes>
*/
@Override
public CustomAddRes addCustomer(CustomAddReq addReq) {
public ApiResp<CustomAddRes> addCustomer(CustomAddReq addReq) {
// 将添加请求对象转换为Map对象以便后续API调用
Map<String, Object> params = BeanUtil.beanToMap(addReq);
// 执行客户创建API调用并获取API响应对象
ApiResp apiResp = e8ApiUtil.doPost(params, CUSTOMER_CREATE);
// 检查API调用是否成功
if (!apiResp.getSuccess()) {
log.error("E8新增人员信息失败 errorMsg:{}", apiResp);
// 如果API调用失败返回null
return null;
}
// 返回API调用是否成功的标志
return JSONUtil.toBean(JSONUtil.toJsonStr(apiResp.getResult()), CustomAddRes.class);
String result = e8ApiUtil.doPost(params, CUSTOMER_CREATE);
return handleApiResponse(result, CustomAddRes.class);
}
/**
@@ -164,7 +189,7 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return Boolean
*/
@Override
public Boolean updateCustomer(CustomUpdateReq updateReq) {
public ApiResp<Void> updateCustomer(CustomUpdateReq updateReq) {
// 根据更新请求构建API URL
String api = CUSTOMER_UPDATE.replace("{id}", updateReq.getId().toString());
@@ -172,32 +197,24 @@ public class E8PlatformApiService implements E8PlatformApi {
Map<String, Object> params = BeanUtil.beanToMap(updateReq);
// 调用API工具类发送POST请求并获取API响应对象
ApiResp apiResp = e8ApiUtil.doPost(params, api);
if (!apiResp.getSuccess()) log.error("E8人员信息修改失败 errorMsg:{}", apiResp);
// 返回API调用是否成功的标志
return apiResp.getSuccess();
String result = e8ApiUtil.doPost(params, api);
return handleApiResponse(result, Void.class);
}
/**
* 删除人员信息
*
* @param id 传参
* @return Boolean
* @return ApiResp<Void>
*/
@Override
public Boolean deleteCustomer(Long id) {
public ApiResp<Void> deleteCustomer(Long id) {
// 构造删除客户的API请求URL
String api = CUSTOMER_DELETE.replace("{id}", id.toString());
// 调用API工具类的 doGetOrDel 方法发送GET或DELETE请求并获取响应结果
ApiResp apiResp = e8ApiUtil.doGetOrDel(api, null, true);
if (!apiResp.getSuccess()) log.error("E8删除人员信息失败 errorMsg:{}", apiResp);
// 返回API请求是否成功的标志
return apiResp.getSuccess();
String result = e8ApiUtil.doGetOrDel(api, null, true);
return handleApiResponse(result, Void.class);
}
//***************************************门禁信息接口*******************************************
@@ -220,23 +237,13 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return DoorDeviceFindRes
*/
@Override
public DoorDeviceFindRes findDoorDevice(Long id) {
public ApiResp<DoorDeviceFindRes> findDoorDevice(Long id) {
// 使用给定的ID替换API模板中的{id}占位符
String api = DOOR_DEVICE_GET_FIRST_OR_DEFAULT.replace("{id}", id.toString());
// 调用E8 API工具类的doGetOrDel方法发送GET请求并获取响应结果
ApiResp apiResp = e8ApiUtil.doGetOrDel(api, null, false);
// 检查API响应是否成功
if (!apiResp.getSuccess()) {
log.error("查询E8门禁信息失败 errorMsg:{}", apiResp);
// 如果响应不成功则返回null
return null;
}
// 将API响应结果转换为指定的Java对象并返回该对象
return JSONUtil.toBean(JSONUtil.toJsonStr(apiResp.getResult()), DoorDeviceFindRes.class);
String result = e8ApiUtil.doGetOrDel(api, null, false);
return handleApiResponse(result, DoorDeviceFindRes.class);
}
/**
@@ -246,7 +253,7 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return IPage<DoorDeviceFindRes>
*/
@Override
public TableDataInfo<DoorDeviceFindRes> findDoorDeviceList(QueryDto dto) {
public ApiResp<TableDataInfo<DoorDeviceFindRes>> findDoorDeviceList(QueryDto dto) {
// 创建一个参数映射用于存储API请求所需的参数
Map<String, Object> params = new HashMap<>();
// 将分页索引和最大结果数放入参数映射中
@@ -256,48 +263,24 @@ public class E8PlatformApiService implements E8PlatformApi {
params.put("QueryDto", JSONUtil.toBean(JSONUtil.toJsonStr(dto.getQueryDto()), DoorDeviceFindReq.class));
// 调用第三方API获取门禁设备分页列表
ApiResp apiResp = e8ApiUtil.doPost(params, DOOR_DEVICE_GET_PAGE_LIST);
// 如果API调用不成功则返回null
if (!apiResp.getSuccess()) {
log.error("分页查询E8门禁信息失败 errorMsg:{}", apiResp);
// 如果响应不成功则返回null
return null;
}
// 将API响应结果转换为Map对象以便后续处理
Map<String, Object> result = JSONUtil.toBean(JSONUtil.toJsonStr(apiResp.getResult()), new TypeReference<>() {
}, false);
// 创建一个分页对象,用于存储处理后的门禁设备信息
TableDataInfo<DoorDeviceFindRes> tableDataInfo = new TableDataInfo<>();
// 设置分页对象的总记录数
tableDataInfo.setTotal(Long.parseLong(result.get("total").toString()));
// 将API响应结果中的门禁设备信息列表转换为DoorDeviceFindRes对象列表并设置到分页对象中
tableDataInfo.setRows(JSONUtil.toList(JSONUtil.toJsonStr(result.get("item")), DoorDeviceFindRes.class));
// 返回处理后的分页对象
return tableDataInfo;
String result = e8ApiUtil.doPost(params, DOOR_DEVICE_GET_PAGE_LIST);
return handlePagedApiResponse(result, DoorDeviceFindRes.class);
}
/**
* 新增门禁信息
*
* @param addReq 传参
* @return Boolean
* @return DoorDeviceAddRes
*/
@Override
public DoorDeviceAddRes addDoorDevice(DoorDeviceAddReq addReq) {
public ApiResp<DoorDeviceAddRes> addDoorDevice(DoorDeviceAddReq addReq) {
// 将DoorDeviceAddReq转为Map对象以便作为API请求的参数
Map<String, Object> params = BeanUtil.beanToMap(addReq);
// 调用第三方API进行门禁设备创建并传入转换后的参数
ApiResp apiResp = e8ApiUtil.doPost(params, DOOR_DEVICE_CREATE);
if (!apiResp.getSuccess()) {
log.error("新增E8门禁信息errorMsg:{}", apiResp);
// 如果响应不成功则返回null
return null;
}
return JSONUtil.toBean(JSONUtil.toJsonStr(apiResp.getResult()), DoorDeviceAddRes.class);
String result = e8ApiUtil.doPost(params, DOOR_DEVICE_CREATE);
return handleApiResponse(result, DoorDeviceAddRes.class);
}
/**
@@ -307,8 +290,7 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return DoorDeviceUpdateRes
*/
@Override
public Boolean updateDoorDevice(DoorDeviceUpdateReq updateReq) {
public ApiResp<Void> updateDoorDevice(DoorDeviceUpdateReq updateReq) {
// 构造门设备更新API的URL
String api = DOOR_DEVICE_UPDATE.replace("{id}", updateReq.getId().toString());
@@ -316,11 +298,8 @@ public class E8PlatformApiService implements E8PlatformApi {
Map<String, Object> params = BeanUtil.beanToMap(updateReq);
// 调用API进行门设备信息更新
ApiResp apiResp = e8ApiUtil.doPost(params, api);
if (!apiResp.getSuccess()) log.error("修改E8门禁信息errorMsg:{}", apiResp);
return apiResp.getSuccess();
String result = e8ApiUtil.doPost(params, api);
return handleApiResponse(result, Void.class);
}
/**
@@ -330,18 +309,13 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return Boolean
*/
@Override
public Boolean deleteDoorDevice(Long id) {
public ApiResp<Void> deleteDoorDevice(Long id) {
// 构造删除门设备的API路径使用设备ID替换占位符
String api = DOOR_DEVICE_DELETE.replace("{id}", id.toString());
// 调用E8 API工具类进行HTTP DELETE请求参数为构造的API路径和null因为DELETE请求通常不需要请求体
ApiResp apiResp = e8ApiUtil.doGetOrDel(api, null, true);
if (!apiResp.getSuccess()) log.error("删除E8门禁信息errorMsg:{}", apiResp);
// 返回API响应的成功标志
return apiResp.getSuccess();
String result = e8ApiUtil.doGetOrDel(api, null, true);
return handleApiResponse(result, Void.class);
}
/**
@@ -349,7 +323,7 @@ public class E8PlatformApiService implements E8PlatformApi {
*
* @return List<AuthDoorDeviceFindRes>
*/
public List<AuthDoorDeviceFindRes> getPageAuthDoorDeviceList() {
public ApiResp<List<AuthDoorDeviceFindRes>> getPageAuthDoorDeviceList() {
Map<String, Object> queryDto = new HashMap<>();
queryDto.put("type", -1);
queryDto.put("matchString", "");
@@ -360,19 +334,9 @@ public class E8PlatformApiService implements E8PlatformApi {
params.put("MaxResultCount", 100000);
params.put("QueryDto", queryDto);
ApiResp apiResp = e8ApiUtil.doPost(params, AUTH_DOOR_DEVICE_GET_LIST);
// 如果API调用不成功则返回null
if (!apiResp.getSuccess()) {
log.error("分页获取授权门信息失败 errorMsg:{}", apiResp);
// 如果响应不成功则返回null
return null;
}
// 将API响应结果转换为Map对象以便后续处理
Map<String, Object> result = JSONUtil.toBean(JSONUtil.toJsonStr(apiResp.getResult()), new TypeReference<>() {
}, false);
// 返回list
return JSONUtil.toList(JSONUtil.toJsonStr(result.get("item")), AuthDoorDeviceFindRes.class);
String result = e8ApiUtil.doPost(params, AUTH_DOOR_DEVICE_GET_LIST);
ApiResp<TableDataInfo<AuthDoorDeviceFindRes>> resp = handlePagedApiResponse(result, AuthDoorDeviceFindRes.class);
return new ApiResp<>(resp.getMessage(), resp.getSessionId(), resp.getResult().getRows(), resp.getSuccess(), resp.getCode());
}
/**
@@ -382,17 +346,13 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return Boolean
*/
@Override
public Boolean remoteOpenDoor(RemoteOpenDoorReq req) {
public ApiResp<Void> remoteOpenDoor(RemoteOpenDoorReq req) {
// 将RemoteOpenDoorReq转为Map对象以便作为API请求的参数
Map<String, Object> params = BeanUtil.beanToMap(req);
// 调用第三方API进行开门操作传入处理后的参数和指定的API端点
ApiResp apiResp = e8ApiUtil.doPost(params, REMOTE_OPEN_DOOR);
if (!apiResp.getSuccess()) log.error("调用E8远程开门失败errorMsg:{}", apiResp);
// 返回API调用是否成功的结果
return apiResp.getSuccess();
String result = e8ApiUtil.doPost(params, REMOTE_OPEN_DOOR);
return handleApiResponse(result, Void.class);
}
/**
@@ -402,7 +362,7 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return IPage<AccessRecordFindRes>
*/
@Override
public TableDataInfo<AccessRecordFindRes> getPageAccessRecordList(QueryDto dto) {
public ApiResp<TableDataInfo<AccessRecordFindRes>> getPageAccessRecordList(QueryDto dto) {
// 创建一个参数映射用于存储API请求的参数
Map<String, Object> params = new HashMap<>();
// 将分页索引和最大结果数放入参数映射中
@@ -412,35 +372,36 @@ public class E8PlatformApiService implements E8PlatformApi {
params.put("queryDto", JSONUtil.toBean(JSONUtil.toJsonStr(dto.getQueryDto()), AccessRecordFindReq.class));
// 调用API工具类的POST方法传入参数和API路径获取API响应对象
ApiResp apiResp = e8ApiUtil.doPost(params, GET_PAGE_ACCESS_RECORD_PAGE_LIST);
String result = e8ApiUtil.doPost(params, GET_PAGE_ACCESS_RECORD_PAGE_LIST);
// 如果API响应不成功则返回null
if (!apiResp.getSuccess()) {
log.error("调用E8获取通行记录分页列表失败errorMsg:{}", apiResp);
return null;
if (result == null) {
return new ApiResp<>("e8服务器内部错误", null, null, false, 500);
}
JSONObject apiResp = JSONUtil.parseObj(result);
// 将API响应的结果转换为JSON字符串再转换为Map对象
Map<String, Object> result = JSONUtil.toBean(JSONUtil.toJsonStr(apiResp.getResult()), new TypeReference<>() {
Map<String, Object> resultMap = JSONUtil.toBean(apiResp.getStr("result"), new TypeReference<>() {
}, false);
// 创建一个分页对象,传入分页索引和最大结果数
TableDataInfo<AccessRecordFindRes> tableData = new TableDataInfo<>();
// 从结果映射中获取总记录数,转换为长整型后设置到分页对象中
tableData.setTotal(Long.parseLong(result.get("total").toString()));
tableData.setTotal(Long.parseLong(resultMap.get("total").toString()));
// 从结果映射中获取项目列表,转换为访问记录信息列表后设置到分页对象中
tableData.setRows(JSONUtil.toList(JSONUtil.toJsonStr(result.get("item")), AccessRecordFindRes.class));
tableData.setRows(JSONUtil.toList(JSONUtil.toJsonStr(resultMap.get("item")), AccessRecordFindRes.class));
for (AccessRecordFindRes res : tableData.getRows()){
for (AccessRecordFindRes res : tableData.getRows()) {
if (res.getVoucherUrl() != null && !res.getVoucherUrl().isEmpty()) {
res.setVoucherUrl(res.getVoucherUrl().replace(URL, imgUrl));
res.setVoucherUrl(res.getVoucherUrl().replace(E8_BASE_URL, imgUrl));
}
if (res.getPictureUrl() != null && !res.getPictureUrl().isEmpty()) {
res.setPictureUrl(res.getPictureUrl().replace(URL, imgUrl));
res.setPictureUrl(res.getPictureUrl().replace(E8_BASE_URL, imgUrl));
}
}
tableData.setCode(200);
tableData.setMsg("查询成功");
// 返回填充了数据的分页对象
return tableData;
return new ApiResp<>(apiResp.getStr("message"), apiResp.getLong("sessionId"), tableData, apiResp.getBool("success"), apiResp.getInt("code"));
}
/**
@@ -450,17 +411,13 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return Boolean
*/
@Override
public Boolean addCustomerAuth(CustomerAuthAddReq req) {
public ApiResp<Void> addCustomerAuth(CustomerAuthAddReq req) {
// 创建一个参数映射用于存储API请求的参数
Map<String, Object> params = BeanUtil.beanToMap(req);
// 调用API工具类的POST方法传入参数和API路径获取API响应对象
ApiResp apiResp = e8ApiUtil.doPost(params, PERSON_AUTHORIZATION);
if (!apiResp.getSuccess()) log.error("调用E8人员授权失败errorMsg:{}", apiResp);
// 返回API调用是否成功
return apiResp.getSuccess();
String result = e8ApiUtil.doPost(params, PERSON_AUTHORIZATION);
return handleApiResponse(result, Void.class);
}
/**
@@ -470,7 +427,7 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return TableDataInfo<CustomerAuthFindRes>
*/
@Override
public TableDataInfo<CustomerAuthFindRes> getPageCustomerAuth(QueryDto dto) {
public ApiResp<TableDataInfo<CustomerAuthFindRes>> getPageCustomerAuth(QueryDto dto) {
// 创建一个参数映射用于存储API请求的参数
Map<String, Object> params = new HashMap<>();
// 将分页索引和最大结果数放入参数映射中
@@ -480,24 +437,8 @@ public class E8PlatformApiService implements E8PlatformApi {
params.put("queryDto", JSONUtil.toBean(JSONUtil.toJsonStr(dto.getQueryDto()), CustomerAuthFindReq.class));
// 调用API工具类的POST方法传入参数和API路径获取API响应对象
ApiResp apiResp = e8ApiUtil.doPost(params, GET_PAGE_PERSON_AUTHORIZATION_PAGE_LIST);
// 如果API响应不成功则返回null
if (!apiResp.getSuccess()) {
log.error("调用E8获取人员权限分页列表失败errorMsg:{}", apiResp);
return null;
}
// 将API响应的结果转换为JSON字符串再转换为Map对象
Map<String, Object> result = JSONUtil.toBean(JSONUtil.toJsonStr(apiResp.getResult()), new TypeReference<>() {
}, false);
// 创建一个分页对象,传入分页索引和最大结果数
TableDataInfo<CustomerAuthFindRes> tableData = new TableDataInfo<>();
// 从结果映射中获取总记录数,转换为长整型后设置到分页对象中
tableData.setTotal(Long.parseLong(result.get("total").toString()));
// 从结果映射中获取项目列表,转换为访问记录信息列表后设置到分页对象中
tableData.setRows(JSONUtil.toList(JSONUtil.toJsonStr(result.get("item")), CustomerAuthFindRes.class));
// 返回填充了数据的分页对象
return tableData;
String result = e8ApiUtil.doPost(params, GET_PAGE_PERSON_AUTHORIZATION_PAGE_LIST);
return handlePagedApiResponse(result, CustomerAuthFindRes.class);
}
//***************************************电梯信息接口*******************************************
@@ -514,7 +455,7 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return TableDataInfo<LiftFindRes>
*/
@Override
public TableDataInfo<LiftFindRes> getPageList(QueryDto dto) {
public ApiResp<TableDataInfo<LiftFindRes>> getPageList(QueryDto dto) {
// 创建一个参数映射用于存储API请求所需的参数
Map<String, Object> params = new HashMap<>();
// 将分页索引和最大结果数放入参数映射中
@@ -524,24 +465,8 @@ public class E8PlatformApiService implements E8PlatformApi {
params.put("queryDto", JSONUtil.toBean(JSONUtil.toJsonStr(dto.getQueryDto()), LiftFindReq.class));
// 调用E8 API工具类的POST方法传入参数和API路径获取API响应
ApiResp apiResp = e8ApiUtil.doPost(params, GET_PAGE_LIST);
// 如果API响应不成功则返回null
if (!apiResp.getSuccess()) {
return null;
}
// 将API响应的结果转换为一个Map对象
Map<String, Object> result = JSONUtil.toBean(JSONUtil.toJsonStr(apiResp.getResult()), new TypeReference<>() {
}, false);
// 创建一个分页对象,传入分页索引和最大结果数
TableDataInfo<LiftFindRes> tableDataInfo = new TableDataInfo<>();
// 设置分页对象的总记录数
tableDataInfo.setTotal(Long.parseLong(result.get("total").toString()));
// 将结果中的项转换为LiftFindRes列表并设置为分页对象的记录
tableDataInfo.setRows(JSONUtil.toList(JSONUtil.toJsonStr(result.get("item")), LiftFindRes.class));
// 返回填充了数据的分页对象
return tableDataInfo;
String result = e8ApiUtil.doPost(params, GET_PAGE_LIST);
return handlePagedApiResponse(result, LiftFindRes.class);
}
/**
@@ -551,20 +476,14 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return LiftFindRes
*/
@Override
public LiftFindRes getLiftFloor(Long id) {
public ApiResp<LiftFindRes> getLiftFloor(Long id) {
// 构造请求URL其中{id}将被liftInfo的ID替换
String url = GET_LIFT_FLOOR.replace("{id}", id.toString());
// 调用API接口获取电梯信息
ApiResp apiResp = e8ApiUtil.doPost(new HashMap<>(), url);
// 如果API调用不成功则返回null
if (!apiResp.getSuccess()) {
return null;
}
// 将API响应结果转换为LiftFindRes对象并返回
return JSONUtil.toBean(JSONUtil.toJsonStr(apiResp.getResult()), LiftFindRes.class);
String result = e8ApiUtil.doPost(new HashMap<>(), url);
return handleApiResponse(result, LiftFindRes.class);
}
/**
@@ -574,15 +493,13 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return Boolean
*/
@Override
public Boolean addLift(LiftAddReq addReq) {
public ApiResp<Void> addLift(LiftAddReq addReq) {
// 将添加请求对象转换为Map对象便于后续操作
Map<String, Object> params = BeanUtil.beanToMap(addReq);
// 调用第三方API进行电梯添加操作并获取API响应结果
ApiResp apiResp = e8ApiUtil.doPost(params, LIFT_ADD);
// 返回API操作是否成功的标志
return apiResp.getSuccess();
String result = e8ApiUtil.doPost(params, LIFT_ADD);
return handleApiResponse(result, Void.class);
}
/**
@@ -592,19 +509,16 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return Boolean
*/
@Override
public Boolean updateLift(LiftUpdateReq updateReq) {
public ApiResp<Void> updateLift(LiftUpdateReq updateReq) {
// 根据LiftUpdateReq对象中的ID生成请求URL
String url = LIFT_UPDATE.replace("{id}", updateReq.getId().toString());
// 将LiftUpdateReq对象转换为Map类型以便于API请求参数的处理
Map<String, Object> params = BeanUtil.beanToMap(updateReq);
// 调用E8 API进行POST请求并返回API响应对象
ApiResp apiResp = e8ApiUtil.doPost(params, url);
// 返回API调用是否成功的标志
return apiResp.getSuccess();
String result = e8ApiUtil.doPost(params, url);
return handleApiResponse(result, Void.class);
}
/**
@@ -614,16 +528,14 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return Boolean
*/
@Override
public Boolean deleteLift(Integer id) {
public ApiResp<Void> deleteLift(Integer id) {
// 构造删除电梯的API请求URL使用id替换模板中的{id}占位符
String url = LIFT_DELETE.replace("{id}", id.toString());
// 调用e8ApiUtils工具类执行DELETE请求并获取API响应结果
ApiResp apiResp = e8ApiUtil.doGetOrDel(url, null, true);
// 返回API响应中的成功标志表示删除操作是否成功
return apiResp.getSuccess();
String result = e8ApiUtil.doGetOrDel(url, null, true);
return handleApiResponse(result, Void.class);
}
//***************************************凭证信息接口*******************************************
@@ -638,21 +550,13 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return 是否成功
*/
@Override
public Long issueVoucher(IssueVoucherReq req) {
public ApiResp<IssueVoucherRes> issueVoucher(IssueVoucherReq req) {
// 封装入参
Map<String, Object> params = BeanUtil.beanToMap(req);
// 调用API
ApiResp apiResp = e8ApiUtil.doPost(params, ISSUANCE_VOUCHER);
if (!apiResp.getSuccess()) {
log.error("E8发行凭证失败errorMsg{}", apiResp);
return null;
}
IssueVoucherRes res = JSONUtil.toBean(JSONUtil.toJsonStr(apiResp.getResult()), IssueVoucherRes.class);
return res.getId();
String result = e8ApiUtil.doPost(params, ISSUANCE_VOUCHER);
return handleApiResponse(result, IssueVoucherRes.class);
}
/**
@@ -662,16 +566,13 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return Boolean
*/
@Override
public Boolean operateVoucher(OperateVoucherReq req) {
public ApiResp<Void> operateVoucher(OperateVoucherReq req) {
// 封装入参
Map<String, Object> params = BeanUtil.beanToMap(req);
// 调用API
ApiResp apiResp = e8ApiUtil.doPost(params, OPERATE_VOUCHER);
if (!apiResp.getSuccess()) log.error("E8操作凭证失败errorMsg{}", apiResp);
return apiResp.getSuccess();
String result = e8ApiUtil.doPost(params, OPERATE_VOUCHER);
return handleApiResponse(result, Void.class);
}
/**
@@ -681,16 +582,13 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return Boolean
*/
@Override
public Boolean changeCard(ChangeCardReq req) {
public ApiResp<Void> changeCard(ChangeCardReq req) {
// 封装入参
Map<String, Object> params = BeanUtil.beanToMap(req);
// 调用API
ApiResp apiResp = e8ApiUtil.doPost(params, CHANGE_CARD);
if (!apiResp.getSuccess()) log.error("E8换卡补卡失败errorMsg{}", apiResp);
return apiResp.getSuccess();
String result = e8ApiUtil.doPost(params, CHANGE_CARD);
return handleApiResponse(result, Void.class);
}
/**
@@ -700,16 +598,9 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return imageUrl 人脸图片地址
*/
@Override
public String uploadFace(byte[] imageByte) {
ApiResp apiResp = e8ApiUtil.doFaceImgUpload(imageByte);
if (!apiResp.getSuccess()) {
log.error("上传人脸图片失败errorMsg{}", apiResp);
return null;
}
return apiResp.getMessage();
public ApiResp<String> uploadFace(byte[] imageByte) {
String result = e8ApiUtil.doFaceImgUpload(imageByte);
return handleApiResponse(result, String.class);
}
//***************************************电梯信息接口*******************************************
@@ -723,22 +614,13 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return VisitorAddRes
*/
@Override
public ApiResp addVisitor(VisitorAddReq req) {
public ApiResp<VisitorAddRes> addVisitor(VisitorAddReq req) {
// 将添加请求对象转换为Map对象以便后续API调用
Map<String, Object> params = BeanUtil.beanToMap(req);
// 执行客户创建API调用并获取API响应对象
ApiResp apiResp = e8ApiUtil.doPost(params, VISITOR_CREATE);
// 检查API调用是否成功
if (!apiResp.getSuccess()) {
log.error("E8新增访客信息失败 errorMsg:{}", apiResp);
// 如果API调用失败返回null
return apiResp;
}
// 返回API调用是否成功的标志
return apiResp;
String result = e8ApiUtil.doPost(params, VISITOR_CREATE);
return handleApiResponse(result, VisitorAddRes.class);
}
/**
@@ -748,22 +630,12 @@ public class E8PlatformApiService implements E8PlatformApi {
* @return String
*/
@Override
public ApiResp getVisitorQrCode(List<Long> ids) {
public ApiResp<VisitorAddRes> getVisitorQrCode(List<Long> ids) {
Map<String, Object> params = new HashMap<>();
params.put("ids", ids);
// 执行客户创建API调用并获取API响应对象
ApiResp apiResp = e8ApiUtil.doPost(params, VISITOR_QRCODE);
// 检查API调用是否成功
if (!apiResp.getSuccess()) {
log.error("E8获取访客二维码失败 errorMsg:{}", apiResp);
// 如果API调用失败返回null
return apiResp;
}
// 返回API调用是否成功的标志
// return JSONUtil.toList(JSONUtil.toJsonStr(apiResp.getResult()), VisitorAddRes.class).get(0);
return apiResp;
String result = e8ApiUtil.doPost(params, VISITOR_QRCODE);
return handleApiResponse(result, VisitorAddRes.class);
}
}

View File

@@ -6,7 +6,6 @@ import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sis.sdk.e8.domain.ApiResp;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
@@ -41,7 +40,7 @@ public class E8ApiUtil {
* @param api 请求接口
* @return 请求结果
*/
public ApiResp doPost(Map<String, Object> params, String api) {
public String doPost(Map<String, Object> params, String api) {
// 时间戳
String timestamp = Long.toString(System.currentTimeMillis());
@@ -75,7 +74,12 @@ public class E8ApiUtil {
.header("sign", sign)
.body(base64Body)
.execute()) {
return JSONUtil.toBean(response.body(), ApiResp.class);
if (response.getStatus() == 200) {
return response.body();
} else {
log.error("e8POST请求失败{}", response.body());
return null;
}
}
}
@@ -86,7 +90,7 @@ public class E8ApiUtil {
* @param paramStr 请求入参
* @return 请求结果
*/
public ApiResp doGetOrDel(String api, String paramStr, Boolean isDelete) {
public String doGetOrDel(String api, String paramStr, Boolean isDelete) {
// 时间戳
String timestamp = Long.toString(System.currentTimeMillis());
// sign签名
@@ -103,7 +107,12 @@ public class E8ApiUtil {
.header("sign", sign)
.header("timestamp", timestamp)
.header("paramstr", paramStr == null ? "50014" : paramStr).execute()) {
return JSONUtil.toBean(response.body(), ApiResp.class);
if (response.getStatus() == 200) {
return response.body();
} else {
log.error("e8DEL请求失败{}", response.body());
return null;
}
}
} else {
// 发送请求获取响应
@@ -113,7 +122,12 @@ public class E8ApiUtil {
.header("sign", sign)
.header("timestamp", timestamp)
.header("paramstr", paramStr == null ? "50014" : paramStr).execute()) {
return JSONUtil.toBean(response.body(), ApiResp.class);
if (response.getStatus() == 200) {
return response.body();
} else {
log.error("e8GET请求失败{}", response.body());
return null;
}
}
}
}
@@ -124,7 +138,7 @@ public class E8ApiUtil {
* @param imageByte 请求入参
* @return 请求结果
*/
public ApiResp doFaceImgUpload(byte[] imageByte) {
public String doFaceImgUpload(byte[] imageByte) {
// 请求地址
String api = "/api/E8/voucher/upload-images";
// 时间戳
@@ -143,8 +157,12 @@ public class E8ApiUtil {
.header("timestamp", timestamp)
.form("file", imageByte, "image.jpg")
.execute()) {
return JSONUtil.toBean(response.body(), ApiResp.class);
if (response.getStatus() == 200) {
return response.body();
} else {
log.error("e8人脸图片上传请求失败{}", response.body());
return null;
}
}
}
@@ -161,9 +179,9 @@ public class E8ApiUtil {
// one&two
String paramsUrl;
if (StrUtil.equals(url, buildUrlWithParams(url, params))){
if (StrUtil.equals(url, buildUrlWithParams(url, params))) {
paramsUrl = url + "timestamp=" + timestamp;
}else {
} else {
paramsUrl = buildUrlWithParams(url, params) + "&timestamp=" + timestamp;
}
// three

View File

@@ -18,9 +18,9 @@ public interface HuaWeiBoxApi {
* 新增图片
*
* @param req 入参
* @return Long
* @return HWResult<Long>
*/
Long addPerson(List<AddHWPersonReq> req);
HWResult<Long> addPerson(List<AddHWPersonReq> req);
/**
* 删除图片
@@ -34,7 +34,7 @@ public interface HuaWeiBoxApi {
* 根据抓拍图片比对返回人员ID
*
* @param base64Img 入参
* @return Map<String, Object>
* @return HWResult<Long>
*/
HWResult<Long> findPerson(String base64Img);
}

View File

@@ -32,10 +32,10 @@ public class HuaWeiBoxApiService implements HuaWeiBoxApi {
* 新增图片
*
* @param req 入参
* @return Long
* @return HWResult<Long>
*/
@Override
public Long addPerson(List<AddHWPersonReq> req) {
public HWResult<Long> addPerson(List<AddHWPersonReq> req) {
String url = "/sdk_service/rest/facerepositories/201/peoples";
JSONObject json = new JSONObject();
@@ -47,12 +47,12 @@ public class HuaWeiBoxApiService implements HuaWeiBoxApi {
if (jsonRes.getInt("resultCode") != 0) {
log.error("华为盒子新增图片失败msg{}", jsonRes.getStr("resultMsg"));
return null;
return new HWResult<>(jsonRes.getInt("resultCode"), jsonRes.getStr("resultMsg"), 0L);
}
JSONArray jsonArr = jsonRes.getJSONArray("ids");
JSONObject obj = jsonArr.getJSONObject(0);
return Long.parseLong(obj.getStr("peopleId"));
return new HWResult<>(200, "ok", obj.getLong("peopleId"));
}
/**
@@ -84,7 +84,7 @@ public class HuaWeiBoxApiService implements HuaWeiBoxApi {
* 根据抓拍图片比对返回人员ID
*
* @param base64Img 入参
* @return Long
* @return HWResult<Long>
*/
@Override
public HWResult<Long> findPerson(String base64Img) {

View File

@@ -214,7 +214,7 @@ public class EventAlarmReportServiceImpl implements IEventAlarmReportService {
data.setDeviceId(Long.parseLong(ac.getOutCode()));
data.setDoorId(Long.parseLong(ac.getOutCode()));
req.setControlList(List.of(data));
Boolean flag = e8PlatformApi.remoteOpenDoor(req);
Boolean flag = e8PlatformApi.remoteOpenDoor(req).getSuccess();
log.info("远程开门结果,result={}", flag);
}
}

View File

@@ -260,7 +260,7 @@ public class SisAccessControlServiceImpl implements ISisAccessControlService {
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean syncE8() {
List<AuthDoorDeviceFindRes> authDoorDeviceFindRes = e8PlatformApi.getPageAuthDoorDeviceList();
List<AuthDoorDeviceFindRes> authDoorDeviceFindRes = e8PlatformApi.getPageAuthDoorDeviceList().getResult();
if (CollUtil.isEmpty(authDoorDeviceFindRes)) {
return false;
}

View File

@@ -124,7 +124,7 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
add.setGroupId(bo.getAuthGroupId());
add.setBegDate(bo.getAuthBegDate());
add.setEndDate(bo.getAuthEndDate());
add.setTenantId("000000");
add.setTenantId(bo.getTenantId());
boolean flag = baseMapper.insert(add) > 0;
Assert.isTrue(flag, "新增授权记录失败");
}
@@ -155,6 +155,7 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
personLibImg.setResidentPersonId(bo.getId());
personLibImg.setImgMd5Value(md5);
personLibImg.setRosterType(bo.getRosterType());
personLibImg.setTenantId(bo.getTenantId());
Boolean flag = sisPersonLibImgService.insertByBo(personLibImg);
if (flag) log.info("写入安防人像信息完成");
return flag;
@@ -213,7 +214,7 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
}
// 删除e8人员
flag = e8PlatformApi.deleteCustomer(bo.getE8Id());
flag = e8PlatformApi.deleteCustomer(bo.getE8Id()).getSuccess();
Assert.isTrue(flag, "删除e8人员失败");
return flag;

View File

@@ -17,9 +17,11 @@ import org.dromara.resource.api.RemoteFileService;
import org.dromara.sis.domain.SisPersonLibImg;
import org.dromara.sis.domain.bo.SisPersonLibImgBo;
import org.dromara.sis.domain.vo.*;
import org.dromara.sis.dubbo.RemoteSisAuthServiceImpl;
import org.dromara.sis.mapper.SisPersonLibImgMapper;
import org.dromara.sis.sdk.huawei.HuaWeiBoxApi;
import org.dromara.sis.sdk.huawei.domain.AddHWPersonReq;
import org.dromara.sis.sdk.huawei.domain.HWResult;
import org.dromara.sis.service.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -109,12 +111,11 @@ public class SisPersonLibImgServiceImpl implements ISisPersonLibImgService {
public Boolean insertByBo(SisPersonLibImgBo bo) {
SisPersonLibImg add = MapstructUtils.convert(bo, SisPersonLibImg.class);
assert add != null;
add.setTenantId("000000");
Assert.notNull(add, "数据处理失败");
boolean flag = baseMapper.insert(add) > 0;
Assert.isTrue(flag, "新增数据失败");
if (bo.getResidentPersonId() == null){
if (bo.getResidentPersonId() == null) {
try {
bo.setId(add.getId());
// 记录图片md5值
@@ -132,16 +133,17 @@ public class SisPersonLibImgServiceImpl implements ISisPersonLibImgService {
ArrayList<String> pictures = new ArrayList<>();
pictures.add(Base64.getEncoder().encodeToString(imgByte));
req.setPictures(pictures);
Long pId = huaWeiBoxApi.addPerson(List.of(req));
Assert.notNull(pId, "调用华为盒子新增图片失败");
bo.setRemoteHwId(pId);
this.updateByBo(bo);
HWResult<Long> result = huaWeiBoxApi.addPerson(List.of(req));
Assert.notNull(result, "调用华为盒子新增图片失败");
if (result.getCode() == 200) {
bo.setRemoteHwId(result.getData());
this.updateByBo(bo);
} else {
Assert.notNull(null, result.getMessage());
}
} catch (Exception e) {
log.info(e.getMessage());
}
}
return flag;

View File

@@ -55,7 +55,7 @@ public class SyncLiftAuthTask {
// 9号电梯
lift.setDeviceId(550757939925061L);
dto.setQueryDto(lift);
TableDataInfo<AccessRecordFindRes> nineLiftList = apiService.getPageAccessRecordList(dto);
TableDataInfo<AccessRecordFindRes> nineLiftList = apiService.getPageAccessRecordList(dto).getResult();
if (nineLiftList.getTotal() != 0) {
liftAuth(nineLiftList.getRows(), "nineLift", "192.168.24.188");
}
@@ -63,7 +63,7 @@ public class SyncLiftAuthTask {
// 15号电梯
lift.setDeviceId(545024837750853L);
dto.setQueryDto(lift);
TableDataInfo<AccessRecordFindRes> fifteenLiftList = apiService.getPageAccessRecordList(dto);
TableDataInfo<AccessRecordFindRes> fifteenLiftList = apiService.getPageAccessRecordList(dto).getResult();
if (fifteenLiftList.getTotal() != 0) {
liftAuth(fifteenLiftList.getRows(), "fifteenLift", "192.168.24.188");
}

View File

@@ -132,7 +132,11 @@ public class SyncGrantAuthTask {
continue;
}
// 更新入驻员工E8平台id
remoteResidentPersonService.updateE8Id(person.getId(), e8Id);
Boolean updateE8Id = remoteResidentPersonService.updateE8Id(person.getId(), e8Id);
if (!updateE8Id) {
log.info("更新入驻员工E8平台id失败{}-----{}", person.getName(), person.getId());
remoteSisAuthService.deletePersonAuth(List.of(person.getId()), new ArrayList<>());
}
}
} else {
// 存在授权记录,为了避免重复授权,删除授权记录,等待下次定时任务
@@ -188,6 +192,7 @@ public class SyncGrantAuthTask {
personAuth.setAuthBegDate(person.getAuthBegDate());
personAuth.setAuthEndDate(person.getAuthEndDate());
personAuth.setRosterType(person.getRosterType());
personAuth.setTenantId(person.getTenantId());
return personAuth;
}