feat:开门、关门判断

This commit is contained in:
dzc committed 2025-04-14 20:59:20 +08:00
1 parent c73dd6a583
commit 5a2e90f67c
7 files changed
+144 -22

No files matched your search

@@ -6,7 +6,8 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@Getter
public enum MerchantTypeEnum {
CANTEEN("1", "食堂"),
OTHER_CANTEEN("0", "其他食堂"),
CANTEEN("1", "自营食堂"),
SUPERMARKET("2", "合作商家"),
SELF_SUPERMARKET("3", "自营商家"),
;
@@ -18,8 +18,8 @@ public class HardDoorFlowOpenDto {
/**
* 智能柜编号
*/
@NotEmpty(message = "货柜编号不能为空")
private String cabinetNo;
@NotNull(message = "货柜编号不能为空")
private Integer cabinetNo;
/**
* 流程类型
@@ -40,6 +40,11 @@ public class HardDoorFlowController {
private final HardDoorFlowService hardDoorFlowService;
/* ************************************* start 远程调用 start ************************************* */
/* ************************************* end 远程调用 end ************************************* */
/* ************************************* start app start ************************************* */
@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.bsd.pjcloud.hard.api.dto.HardDoorFlowOpenDto;
import com.bsd.pjcloud.hard.api.entity.HardDoorFlowEntity;
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorManagerVo;
import com.bsd.pjcloud.thirdparty.dto.door.DoorOpenCallbackDto;
import com.bsd.pjcloud.thirdparty.dto.door.DoorVideoCallbackDto;
public interface HardDoorFlowService extends IService<HardDoorFlowEntity> {
@@ -27,4 +29,14 @@ public interface HardDoorFlowService extends IService<HardDoorFlowEntity> {
* 上架开门
*/
void openDoorRepertory(HardDoorFlowOpenDto dto);
/**
* 处理开门回调
*/
void disposeLocakCallback(DoorOpenCallbackDto dto);
/**
* 处理视频回调
*/
void disposeVideoCallback(DoorVideoCallbackDto dto);
}
@@ -22,6 +22,11 @@ public interface HardDoorManagerService extends IService<HardDoorManagerEntity>
*/
void bind(HardDoorManagerEntity dto);
/**
* 刷新设备信息
*/
HardDoorManagerEntity refresh(String deviceCode);
/**
* 音量修改
*/
@@ -9,12 +9,15 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
import com.bsd.pjcloud.hard.api.dto.HardDoorFlowOpenDto;
import com.bsd.pjcloud.hard.api.entity.HardDoorFlowEntity;
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorManagerEntity;
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorManagerVo;
import com.bsd.pjcloud.hard.mapper.HardDoorFlowMapper;
import com.bsd.pjcloud.hard.service.HardDoorFlowService;
import com.bsd.pjcloud.hard.service.HardDoorManagerService;
import com.bsd.pjcloud.thirdparty.api.feign.RemoterThirdDoorApiService;
import com.bsd.pjcloud.thirdparty.dto.door.DoorOpenCallbackDto;
import com.bsd.pjcloud.thirdparty.dto.door.DoorOpenDto;
import com.bsd.pjcloud.thirdparty.dto.door.DoorVideoCallbackDto;
import com.bsd.pjcloud.thirdparty.vo.door.DoorOpenVo;
import com.bsd.pjcloud.thirdparty.vo.door.DoorStatusVo;
import lombok.RequiredArgsConstructor;
@@ -35,6 +38,8 @@ import java.util.List;
@Service
public class HardDoorFlowServiceImpl extends ServiceImpl<HardDoorFlowMapper, HardDoorFlowEntity> implements HardDoorFlowService {
private static final String TAG = "智能柜流程";
private final HardDoorManagerService hardDoorManagerService;
private final RemoterThirdDoorApiService thirdDoorApiService;
@@ -46,18 +51,26 @@ public class HardDoorFlowServiceImpl extends ServiceImpl<HardDoorFlowMapper, Har
public void openDoor(HardDoorFlowOpenDto dto, HardDoorManagerVo hardDoorVo) {
HardDoorFlowEntity saveObj = HardDoorFlowEntity.builder().userId(dto.getUserId()).bizType(dto.getFlowType().getType()).isOpen(YesNoEnum.NO.getCode()).build();
baseMapper.insert(saveObj);
HardDoorManagerEntity hardDoorStatus = hardDoorManagerService.refresh(hardDoorVo.getDeviceCode());
if (ObjectUtil.isEmpty(hardDoorStatus) || ObjectUtil.isEmpty(hardDoorStatus.getCabinetList())) {
throw new RuntimeException("设备离线");
}
List<DoorStatusVo.Cabinet> list = JSONUtil.toList(hardDoorStatus.getCabinetList(), DoorStatusVo.Cabinet.class);
validateCabinetStatus(list, dto.getCabinetNo());
// 请求开门
DoorOpenDto openDto = BeanUtil.toBean(dto, DoorOpenDto.class);
openDto.setOutOpenNo(hardDoorVo.getDeviceCode());
openDto.setOutOpenNo(dto.getCabinetNo());
openDto.setDeviceCode(String.valueOf(saveObj.getId()));
openDto.setDeviceCode(hardDoorVo.getDeviceCode());
openDto.setCabinetNo(dto.getCabinetNo());
openDto.setOutOpenNo(String.valueOf(saveObj.getId()));
openDto.setEventType(Integer.valueOf(dto.getOpenType().getType()));
DoorOpenVo openVo = thirdDoorApiService.open(openDto).getData();
if (ObjectUtil.isEmpty(openVo) || !openVo.isSuccess()) throw new RuntimeException("开门失败");
if (ObjectUtil.isEmpty(openVo) || !openVo.isSuccess()) throw new RuntimeException(openVo.getMessage());
HardDoorFlowEntity updateObj = HardDoorFlowEntity.builder().id(saveObj.getId()).requestOpenDto(JSONUtil.toJsonStr(openDto)).requestOpenVo(JSONUtil.toJsonStr(openVo)).requestOpenTime(LocalDateTime.now()).build();
// 是否开门成功
updateObj.setIsOpen(YesNoEnum.YES.getCode());
baseMapper.updateById(updateObj);
// 刷新状态
hardDoorManagerService.refresh(hardDoorVo.getDeviceCode());
}
@@ -81,9 +94,9 @@ public class HardDoorFlowServiceImpl extends ServiceImpl<HardDoorFlowMapper, Har
HardDoorManagerVo doorDetail = checkDeviceAndCabinet(dto.getHardDoorId(), dto.getCabinetNo());
// 请求关门
DoorOpenDto openDto = BeanUtil.toBean(dto, DoorOpenDto.class);
openDto.setOutOpenNo(doorDetail.getDeviceCode());
openDto.setOutOpenNo(dto.getCabinetNo());
openDto.setDeviceCode(RandomUtil.randomString(32));
openDto.setDeviceCode(doorDetail.getDeviceCode());
openDto.setCabinetNo(dto.getCabinetNo());
openDto.setOutOpenNo(RandomUtil.randomString(32));
openDto.setEventType(Integer.valueOf(dto.getOpenType().getType()));
DoorOpenVo openVo = thirdDoorApiService.open(openDto).getData();
if (ObjectUtil.isEmpty(openVo) || !openVo.isSuccess()) {
@@ -107,10 +120,62 @@ public class HardDoorFlowServiceImpl extends ServiceImpl<HardDoorFlowMapper, Har
}
/**
* 处理开门回调
*/
@Override
public void disposeLocakCallback(DoorOpenCallbackDto dto) {
if (ObjectUtil.isEmpty(dto) || ObjectUtil.isEmpty(dto.getType())) {
log.info("|{}|disposeLocakCallback 参数错误dto|{}|", TAG, JSONUtil.toJsonStr(dto));
return;
}
// 查询流程
HardDoorFlowEntity flowDetail = baseMapper.selectById(dto.getOutOpenNo());
if (ObjectUtil.isEmpty(flowDetail)) {
log.info("|{}|disposeLocakCallback 流程不存在dto|{}|", TAG, JSONUtil.toJsonStr(dto));
return;
}
// 更新流程
boolean isOpenDoor = ObjectUtil.equals(dto.getType(), "OPEN");
HardDoorFlowEntity updateObj = HardDoorFlowEntity.builder()
.id(flowDetail.getId())
.isOpen(isOpenDoor ? YesNoEnum.YES.getCode() : YesNoEnum.NO.getCode())
.openCallbackTime(LocalDateTime.now())
.openCallbackVo(JSONUtil.toJsonStr(dto))
.build();
baseMapper.updateById(updateObj);
}
/**
* 处理视频回调
*/
@Override
public void disposeVideoCallback(DoorVideoCallbackDto dto) {
if (ObjectUtil.isEmpty(dto) || ObjectUtil.isEmpty(dto.getVideoList())) {
log.info("|{}|disposeVideoCallback 参数错误dto|{}|", TAG, JSONUtil.toJsonStr(dto));
return;
}
// 查询流程
HardDoorFlowEntity flowDetail = baseMapper.selectById(dto.getOutOpenNo());
if (ObjectUtil.isEmpty(flowDetail)) {
log.info("|{}|disposeVideoCallback 流程不存在dto|{}|", TAG, JSONUtil.toJsonStr(dto));
return;
}
// 更新流程
HardDoorFlowEntity updateObj = HardDoorFlowEntity.builder()
.id(flowDetail.getId())
.videoCallbackVo(JSONUtil.toJsonStr(dto))
.videoCallbackTime(LocalDateTime.now())
.build();
baseMapper.updateById(updateObj);
// 提交识别
}
/**
* 校验设备和货柜编号
*/
private HardDoorManagerVo checkDeviceAndCabinet(Long hardDoorId, String cabinetNo) {
private HardDoorManagerVo checkDeviceAndCabinet(Long hardDoorId, Integer cabinetNo) {
// 查询智能柜
HardDoorManagerVo doorDetail = hardDoorManagerService.getByHardId(hardDoorId);
if (ObjectUtil.isEmpty(doorDetail)) throw new RuntimeException("智能柜不存在");
@@ -122,6 +187,22 @@ public class HardDoorFlowServiceImpl extends ServiceImpl<HardDoorFlowMapper, Har
return doorDetail;
}
/**
* 判断货柜状态
*/
private void validateCabinetStatus(List<DoorStatusVo.Cabinet> list, Integer cabinetNo) {
list.stream().filter(v -> ObjectUtil.equals(v.getCabinetNo(), cabinetNo)).findFirst().ifPresentOrElse(
status -> {
if (ObjectUtil.equals(status.getSaleStatus(), 1)) {
// throw new RuntimeException("该货柜为在售,不能开门");
}
},
() -> {
throw new RuntimeException("货柜不存在");
}
);
}
private HardDoorFlowServiceImpl getSelf() {
return SpringUtil.getBean(getClass());
}
@@ -2,6 +2,7 @@ package com.bsd.pjcloud.hard.service.impl.manager;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.common.data.datascope.DataScope;
@@ -20,6 +21,7 @@ import com.bsd.pjcloud.thirdparty.vo.door.DoorVolumeVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
/**
@@ -50,6 +52,7 @@ public class HardDoorManagerServiceImpl extends ServiceImpl<HardDoorManagerMappe
* 绑定设备
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void bind(HardDoorManagerEntity dto) {
// 查询设备
HardDoorManagerVo hardDoorDetail = getByHardId(dto.getHardId());
@@ -87,19 +90,37 @@ public class HardDoorManagerServiceImpl extends ServiceImpl<HardDoorManagerMappe
if (!bindVo.isSuccess()) {
throw new RuntimeException(bindVo.getMessage());
}
// 查询设备状态
// 查询设备详情
HardDoorManagerEntity hardDoorManagerDetail = baseMapper.selectById(dto.getId());
// 注册的设备信息
HardDoorManagerEntity updateObj = new HardDoorManagerEntity();
updateObj.setId(hardDoorManagerDetail.getId());
updateObj.setDeviceCode(registerVo.getDeviceCode());
updateObj.setCabinetNum(registerVo.getCabinetNum());
updateObj.setCabinetCameraNum(registerVo.getCabinetCameraNum());
updateObj.setCabinetWeightUnitNum(registerVo.getCabinetWeightUnitNum());
baseMapper.updateById(updateObj);
refresh(updateObj.getDeviceCode());
}
@Override
@Transactional(rollbackFor = Exception.class)
public HardDoorManagerEntity refresh(String deviceCode) {
// 查询设备
HardDoorManagerEntity hardDoorDetail = baseMapper.selectOne(new LambdaQueryWrapper<HardDoorManagerEntity>()
.eq(HardDoorManagerEntity::getDeviceCode, deviceCode)
.orderByDesc(HardDoorManagerEntity::getCreateTime)
.last("limit 1")
);
if (ObjectUtil.isEmpty(hardDoorDetail)) throw new RuntimeException("刷新失败,设备不存在");
DoorStatusDto statusDto = new DoorStatusDto();
statusDto.setDeviceCode(bindVo.getDeviceCode());
statusDto.setDeviceCode(deviceCode);
DoorStatusVo statusVo = thirdDoorApiService.status(statusDto).getData();
if (!statusVo.isSuccess()) {
throw new RuntimeException(statusVo.getMessage());
}
// 查询设备详情
HardDoorManagerEntity hardDoorManagerDetail = baseMapper.selectById(dto.getId());
// 更新设备信息
HardDoorManagerEntity updateObj = new HardDoorManagerEntity();
updateObj.setDeviceCode(bindVo.getDeviceCode());
updateObj.setId(hardDoorManagerDetail.getId());
updateObj.setId(hardDoorDetail.getId());
updateObj.setPowerStatus(statusVo.getPowerStatus());
updateObj.setNetStatus(statusVo.getNetStatus());
updateObj.setNetStatus(statusVo.getSaleStatus());
@@ -108,16 +129,13 @@ public class HardDoorManagerServiceImpl extends ServiceImpl<HardDoorManagerMappe
updateObj.setSignalIntensity(statusVo.getSignalIntensity());
updateObj.setSignalRatio(statusVo.getSignalRatio());
updateObj.setSignalTime(statusVo.getSignalTime());
// 注册的设备信息
updateObj.setCabinetNum(registerVo.getCabinetNum());
updateObj.setCabinetCameraNum(registerVo.getCabinetCameraNum());
updateObj.setCabinetWeightUnitNum(registerVo.getCabinetWeightUnitNum());
if (ObjectUtil.isEmpty(statusVo.getCabinetStatusList())) {
updateObj.setCabinetList("");
} else {
updateObj.setCabinetList(JSONUtil.toJsonStr(statusVo.getCabinetStatusList()));
}
baseMapper.updateById(updateObj);
return updateObj;
}
/**