feat:刷新智能柜货柜二维码

This commit is contained in:
dzc committed 2025-04-15 19:04:28 +08:00
1 parent b2d7db1f52
commit a1d3dbc7f2
10 files changed
+157 -38

No files matched your search

-1
View File
@@ -56,7 +56,6 @@ CREATE TABLE hard_door_manager
signal_intensity int DEFAULT NULL COMMENT 'sim 信号强度。大于-95 表示信号强度好;-95 到-105 表示信号强度中等;小于-105 表示信号差;', signal_intensity int DEFAULT NULL COMMENT 'sim 信号强度。大于-95 表示信号强度好;-95 到-105 表示信号强度中等;小于-105 表示信号差;',
signal_ratio int DEFAULT NULL COMMENT '信噪比,体现信道传输质量的参数。大于 15 表示质量好;15 到 0 表示质量中等;小于等于 0 表示质量差;', signal_ratio int DEFAULT NULL COMMENT '信噪比,体现信道传输质量的参数。大于 15 表示质量好;15 到 0 表示质量中等;小于等于 0 表示质量差;',
signal_time datetime DEFAULT NULL COMMENT 'sim 信号值更新时间。yyyy-MM-dd HH:mm:ss', signal_time datetime DEFAULT NULL COMMENT 'sim 信号值更新时间。yyyy-MM-dd HH:mm:ss',
cabinet_list text DEFAULT NULL COMMENT '货柜列表JSON',
restart_time datetime DEFAULT NULL COMMENT '上次重启时间', restart_time datetime DEFAULT NULL COMMENT '上次重启时间',
system_volume int DEFAULT 0 COMMENT '系统音量', system_volume int DEFAULT 0 COMMENT '系统音量',
media_volume int DEFAULT 0 COMMENT '媒体音量', media_volume int DEFAULT 0 COMMENT '媒体音量',
@@ -114,12 +114,6 @@ public class HardDoorManagerEntity extends Model<HardDoorManagerEntity> {
@Schema(description = "sim 信号值更新时间。yyyy-MM-dd HH:mm:ss") @Schema(description = "sim 信号值更新时间。yyyy-MM-dd HH:mm:ss")
private LocalDateTime signalTime; private LocalDateTime signalTime;
/**
* 货柜列表JSON
*/
@Schema(description = "货柜列表JSON")
private String cabinetList;
/** /**
* 上次重启时间 * 上次重启时间
*/ */
@@ -0,0 +1,18 @@
package com.bsd.pjcloud.hard.api.vo.manager;
import lombok.Data;
@Data
public class HardDoorCabinetCodeVo {
/**
* 智能柜id
*/
private String hardDoorId;
/**
* 货柜编号
*/
private String cabinetNo;
}
@@ -1,8 +1,11 @@
package com.bsd.pjcloud.hard.api.vo.manager; package com.bsd.pjcloud.hard.api.vo.manager;
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorCabinetEntity;
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorManagerEntity; import com.bsd.pjcloud.hard.api.entity.manager.HardDoorManagerEntity;
import lombok.Data; import lombok.Data;
import java.util.List;
@Data @Data
public class HardDoorManagerVo extends HardDoorManagerEntity { public class HardDoorManagerVo extends HardDoorManagerEntity {
/** /**
@@ -12,4 +15,6 @@ public class HardDoorManagerVo extends HardDoorManagerEntity {
private String hardType; private String hardType;
private List<HardDoorCabinetEntity> cabinetList;
} }
@@ -13,8 +13,8 @@ import com.bsd.pjcloud.hard.api.dto.manager.HardDoorManagerDto;
import com.bsd.pjcloud.hard.api.dto.spu.HardChangeVolume; import com.bsd.pjcloud.hard.api.dto.spu.HardChangeVolume;
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorManagerEntity; import com.bsd.pjcloud.hard.api.entity.manager.HardDoorManagerEntity;
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorManagerVo; import com.bsd.pjcloud.hard.api.vo.manager.HardDoorManagerVo;
import com.bsd.pjcloud.hard.service.HardDoorCabinetService;
import com.bsd.pjcloud.hard.service.HardDoorManagerService; import com.bsd.pjcloud.hard.service.HardDoorManagerService;
import com.bsd.pjcloud.thirdparty.dto.door.DoorVolumeDto;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel; import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@@ -39,6 +39,7 @@ import java.util.List;
public class HardDoorManagerController { public class HardDoorManagerController {
private final HardDoorManagerService hardDoorManagerService; private final HardDoorManagerService hardDoorManagerService;
private final HardDoorCabinetService hardDoorCabinetService;
@Operation(summary = "绑定设备", description = "绑定设备") @Operation(summary = "绑定设备", description = "绑定设备")
@PostMapping("/bind") @PostMapping("/bind")
@@ -48,6 +49,12 @@ public class HardDoorManagerController {
return R.ok(); return R.ok();
} }
@Operation(summary = "刷新智能柜货柜二维码", description = "刷新智能柜货柜二维码")
@GetMapping("/refresh-qr-code")
public R refreshQrCode(@RequestParam Long hardDoorId, @RequestParam Integer cabinetNo) {
return R.ok(hardDoorCabinetService.refreshQrCode(hardDoorId, cabinetNo));
}
@Operation(summary = "音量修改", description = "音量修改") @Operation(summary = "音量修改", description = "音量修改")
@PostMapping("/change-volume") @PostMapping("/change-volume")
public R changeVolume(@Validated @RequestBody HardChangeVolume dto) { public R changeVolume(@Validated @RequestBody HardChangeVolume dto) {
@@ -2,7 +2,18 @@ package com.bsd.pjcloud.hard.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorCabinetEntity; import com.bsd.pjcloud.hard.api.entity.manager.HardDoorCabinetEntity;
import com.bsd.pjcloud.thirdparty.vo.door.DoorStatusVo;
import java.util.List;
public interface HardDoorCabinetService extends IService<HardDoorCabinetEntity> { public interface HardDoorCabinetService extends IService<HardDoorCabinetEntity> {
void saveOrUpdate(Long hardDoorId, List<DoorStatusVo.Cabinet> list);
List<HardDoorCabinetEntity> getListByHardDoorId(Long hardDoorId);
/**
* 刷新智能柜货柜二维码
*/
String refreshQrCode(Long hardDoorId, Integer cabinetNo);
} }
@@ -50,11 +50,8 @@ public class HardDoorFlowServiceImpl extends ServiceImpl<HardDoorFlowMapper, Har
HardDoorFlowEntity saveObj = HardDoorFlowEntity.builder().userId(dto.getUserId()).bizType(dto.getFlowType().getType()).isOpen(YesNoEnum.NO.getCode()).build(); HardDoorFlowEntity saveObj = HardDoorFlowEntity.builder().userId(dto.getUserId()).bizType(dto.getFlowType().getType()).isOpen(YesNoEnum.NO.getCode()).build();
baseMapper.insert(saveObj); baseMapper.insert(saveObj);
HardDoorManagerEntity hardDoorStatus = hardDoorManagerService.refresh(hardDoorVo.getDeviceCode()); HardDoorManagerEntity hardDoorStatus = hardDoorManagerService.refresh(hardDoorVo.getDeviceCode());
if (ObjectUtil.isEmpty(hardDoorStatus) || ObjectUtil.isEmpty(hardDoorStatus.getCabinetList())) { // 校验设备和货柜编号
throw new RuntimeException("设备离线"); hardDoorStatus = hardDoorManagerService.checkDeviceAndCabinet(dto.getHardDoorId(), dto.getCabinetNo());
}
List<DoorStatusVo.Cabinet> list = JSONUtil.toList(hardDoorStatus.getCabinetList(), DoorStatusVo.Cabinet.class);
validateCabinetStatus(list, dto.getCabinetNo());
// 请求开门 // 请求开门
DoorOpenDto openDto = BeanUtil.toBean(dto, DoorOpenDto.class); DoorOpenDto openDto = BeanUtil.toBean(dto, DoorOpenDto.class);
openDto.setDeviceCode(hardDoorVo.getDeviceCode()); openDto.setDeviceCode(hardDoorVo.getDeviceCode());
@@ -181,22 +178,6 @@ public class HardDoorFlowServiceImpl extends ServiceImpl<HardDoorFlowMapper, Har
} }
/**
* 判断货柜状态
*/
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() { private HardDoorFlowServiceImpl getSelf() {
return SpringUtil.getBean(getClass()); return SpringUtil.getBean(getClass());
} }
@@ -1,14 +1,112 @@
package com.bsd.pjcloud.hard.service.impl.manager; package com.bsd.pjcloud.hard.service.impl.manager;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.admin.api.feign.RemoteFileService;
import com.bsd.pjcloud.common.core.util.QRCodeImageGenerator;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorCabinetEntity; import com.bsd.pjcloud.hard.api.entity.manager.HardDoorCabinetEntity;
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorCabinetCodeVo;
import com.bsd.pjcloud.hard.mapper.manager.HardDoorCabinetMapper; import com.bsd.pjcloud.hard.mapper.manager.HardDoorCabinetMapper;
import com.bsd.pjcloud.hard.service.HardDoorCabinetService; import com.bsd.pjcloud.hard.service.HardDoorCabinetService;
import com.bsd.pjcloud.thirdparty.vo.door.DoorStatusVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/** /**
* 智能柜货柜 * 智能柜货柜
*/ */
@Validated
@Slf4j
@RequiredArgsConstructor
@Service @Service
public class HardDoorCabinetServiceImpl extends ServiceImpl<HardDoorCabinetMapper, HardDoorCabinetEntity> implements HardDoorCabinetService { public class HardDoorCabinetServiceImpl extends ServiceImpl<HardDoorCabinetMapper, HardDoorCabinetEntity> implements HardDoorCabinetService {
private final RemoteFileService remoteFileService;
@Override
public void saveOrUpdate(Long hardDoorId, List<DoorStatusVo.Cabinet> list) {
List<HardDoorCabinetEntity> cabinetList = baseMapper.selectList(new LambdaQueryWrapper<HardDoorCabinetEntity>()
.eq(HardDoorCabinetEntity::getHardDoorId, hardDoorId)
);
if (ObjectUtil.isEmpty(cabinetList)) {
List<HardDoorCabinetEntity> addList = new ArrayList<>();
for (DoorStatusVo.Cabinet cabinet : list) {
HardDoorCabinetEntity entity = new HardDoorCabinetEntity();
entity.setHardDoorId(hardDoorId);
entity.setCabinetNo(cabinet.getCabinetNo());
entity.setIsLockOnline(cabinet.getIsLockOnline());
entity.setLockStatus(cabinet.getLockStatus());
entity.setDoorStatus(cabinet.getDoorStatus());
entity.setSaleStatus(cabinet.getSaleStatus());
addList.add(entity);
}
baseMapper.insert(addList);
return;
}
for (DoorStatusVo.Cabinet cabinet : list) {
cabinetList.stream().filter(i -> ObjectUtil.equals(i.getCabinetNo(), cabinet.getCabinetNo()))
.findFirst()
.ifPresent(i -> {
i.setIsLockOnline(cabinet.getIsLockOnline());
i.setLockStatus(cabinet.getLockStatus());
i.setDoorStatus(cabinet.getDoorStatus());
i.setSaleStatus(cabinet.getSaleStatus());
baseMapper.updateById(i);
});
}
}
@Override
public List<HardDoorCabinetEntity> getListByHardDoorId(Long hardDoorId) {
return baseMapper.selectList(new LambdaQueryWrapper<HardDoorCabinetEntity>()
.eq(HardDoorCabinetEntity::getHardDoorId, hardDoorId)
);
}
/**
* 刷新智能柜货柜二维码
*/
@Override
public String refreshQrCode(Long hardDoorId, Integer cabinetNo) {
// 查找货柜
HardDoorCabinetEntity cabinetDetail = baseMapper.selectOne(new LambdaQueryWrapper<HardDoorCabinetEntity>()
.eq(HardDoorCabinetEntity::getHardDoorId, hardDoorId)
.eq(HardDoorCabinetEntity::getCabinetNo, cabinetNo)
);
if (ObjectUtil.isEmpty(cabinetDetail)) throw new RuntimeException("货柜不存在");
HardDoorCabinetCodeVo cabinetCodeVo = new HardDoorCabinetCodeVo();
cabinetCodeVo.setHardDoorId(String.valueOf(hardDoorId));
cabinetCodeVo.setCabinetNo(String.valueOf(cabinetNo));
// 生成二维码
String coeContent = Base64.encode(JSONUtil.toJsonStr(cabinetCodeVo));
try {
byte[] bytes = QRCodeImageGenerator.generateQrCodeImage(coeContent, 300);
MultipartFile multipartFile = new MockMultipartFile("file", hardDoorId + "-" + System.currentTimeMillis() + ".png", "image/png", new ByteArrayInputStream(bytes));
R upload = remoteFileService.innerUpload(multipartFile, null, null, null);
Map data = (Map) upload.getData();
String url = (String) data.get("url");
// 更新
HardDoorCabinetEntity updateObj = new HardDoorCabinetEntity();
updateObj.setId(cabinetDetail.getId());
updateObj.setQrCode(url);
baseMapper.updateById(updateObj);
return url;
} catch (Exception e) {
log.error("refreshQrCode刷新智能柜货柜二维码,hardDoorId:{},cabinetNo:{}", hardDoorId, cabinetNo, e);
throw new RuntimeException("刷新二维码失败");
}
}
} }
@@ -1,16 +1,17 @@
package com.bsd.pjcloud.hard.service.impl.manager; package com.bsd.pjcloud.hard.service.impl.manager;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.common.data.datascope.DataScope; import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.hard.api.dto.manager.HardDoorManagerDto; import com.bsd.pjcloud.hard.api.dto.manager.HardDoorManagerDto;
import com.bsd.pjcloud.hard.api.dto.spu.HardChangeVolume; import com.bsd.pjcloud.hard.api.dto.spu.HardChangeVolume;
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorCabinetEntity;
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorManagerEntity; import com.bsd.pjcloud.hard.api.entity.manager.HardDoorManagerEntity;
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorManagerVo; import com.bsd.pjcloud.hard.api.vo.manager.HardDoorManagerVo;
import com.bsd.pjcloud.hard.mapper.manager.HardDoorManagerMapper; import com.bsd.pjcloud.hard.mapper.manager.HardDoorManagerMapper;
import com.bsd.pjcloud.hard.service.HardDoorCabinetService;
import com.bsd.pjcloud.hard.service.HardDoorManagerService; import com.bsd.pjcloud.hard.service.HardDoorManagerService;
import com.bsd.pjcloud.thirdparty.api.feign.RemoterThirdDoorApiService; import com.bsd.pjcloud.thirdparty.api.feign.RemoterThirdDoorApiService;
import com.bsd.pjcloud.thirdparty.dto.door.*; import com.bsd.pjcloud.thirdparty.dto.door.*;
@@ -35,6 +36,8 @@ import java.util.List;
@Service @Service
public class HardDoorManagerServiceImpl extends ServiceImpl<HardDoorManagerMapper, HardDoorManagerEntity> implements HardDoorManagerService { public class HardDoorManagerServiceImpl extends ServiceImpl<HardDoorManagerMapper, HardDoorManagerEntity> implements HardDoorManagerService {
private final HardDoorCabinetService hardDoorCabinetService;
private final RemoterThirdDoorApiService thirdDoorApiService; private final RemoterThirdDoorApiService thirdDoorApiService;
@Override @Override
@@ -47,7 +50,14 @@ public class HardDoorManagerServiceImpl extends ServiceImpl<HardDoorManagerMappe
*/ */
@Override @Override
public HardDoorManagerVo getByHardId(Long hardId) { public HardDoorManagerVo getByHardId(Long hardId) {
return baseMapper.pageJoin(hardId); HardDoorManagerVo hardDoor = baseMapper.pageJoin(hardId);
if (ObjectUtil.isNotEmpty(hardDoor)) {
List<HardDoorCabinetEntity> cabinetList = hardDoorCabinetService.getListByHardDoorId(hardDoor.getId());
if (ObjectUtil.isNotEmpty(cabinetList)) {
hardDoor.setCabinetList(cabinetList);
}
}
return hardDoor;
} }
/** /**
@@ -131,10 +141,8 @@ public class HardDoorManagerServiceImpl extends ServiceImpl<HardDoorManagerMappe
updateObj.setSignalIntensity(statusVo.getSignalIntensity()); updateObj.setSignalIntensity(statusVo.getSignalIntensity());
updateObj.setSignalRatio(statusVo.getSignalRatio()); updateObj.setSignalRatio(statusVo.getSignalRatio());
updateObj.setSignalTime(statusVo.getSignalTime()); updateObj.setSignalTime(statusVo.getSignalTime());
if (ObjectUtil.isEmpty(statusVo.getCabinetStatusList())) { if (ObjectUtil.isNotEmpty(statusVo.getCabinetStatusList())) {
updateObj.setCabinetList(""); hardDoorCabinetService.saveOrUpdate(hardDoorDetail.getId(), statusVo.getCabinetStatusList());
} else {
updateObj.setCabinetList(JSONUtil.toJsonStr(statusVo.getCabinetStatusList()));
} }
baseMapper.updateById(updateObj); baseMapper.updateById(updateObj);
return updateObj; return updateObj;
@@ -173,7 +181,7 @@ public class HardDoorManagerServiceImpl extends ServiceImpl<HardDoorManagerMappe
// 查询智能柜 // 查询智能柜
HardDoorManagerVo doorDetail = getByHardId(hardDoorId); HardDoorManagerVo doorDetail = getByHardId(hardDoorId);
if (ObjectUtil.isEmpty(doorDetail)) throw new RuntimeException("智能柜不存在"); if (ObjectUtil.isEmpty(doorDetail)) throw new RuntimeException("智能柜不存在");
List<DoorStatusVo.Cabinet> cabinetList = JSONUtil.toList(doorDetail.getCabinetList(), DoorStatusVo.Cabinet.class); List<HardDoorCabinetEntity> cabinetList = hardDoorCabinetService.getListByHardDoorId(hardDoorId);
if (ObjectUtil.isEmpty(cabinetList)) throw new RuntimeException("货柜不存在"); if (ObjectUtil.isEmpty(cabinetList)) throw new RuntimeException("货柜不存在");
if (ObjectUtil.isEmpty(cabinetList.stream().filter(i -> ObjectUtil.equals(i.getCabinetNo(), cabinetNo)).findFirst().orElse(null))) { if (ObjectUtil.isEmpty(cabinetList.stream().filter(i -> ObjectUtil.equals(i.getCabinetNo(), cabinetNo)).findFirst().orElse(null))) {
throw new RuntimeException("货柜不存在"); throw new RuntimeException("货柜不存在");
@@ -18,7 +18,6 @@
<result property="signalIntensity" column="signal_intensity"/> <result property="signalIntensity" column="signal_intensity"/>
<result property="signalRatio" column="signal_ratio"/> <result property="signalRatio" column="signal_ratio"/>
<result property="signalTime" column="signal_time"/> <result property="signalTime" column="signal_time"/>
<result property="cabinetList" column="cabinet_list"/>
<result property="restartTime" column="restart_time"/> <result property="restartTime" column="restart_time"/>
<result property="systemVolume" column="system_volume"/> <result property="systemVolume" column="system_volume"/>
<result property="mediaVolume" column="media_volume"/> <result property="mediaVolume" column="media_volume"/>
@@ -46,7 +45,6 @@
a.signal_intensity, a.signal_intensity,
a.signal_ratio, a.signal_ratio,
a.signal_time, a.signal_time,
a.cabinet_list,
a.restart_time, a.restart_time,
a.system_volume, a.system_volume,
a.media_volume, a.media_volume,