Merge remote-tracking branch 'origin/feature-BOX一期' into feature-BOX一期

This commit is contained in:
weiyachao 2023-09-18 18:57:26 +08:00
commit d3b914f259
4 changed files with 4024 additions and 51 deletions

View File

@ -38,55 +38,56 @@ public class DeviceController {
private static Long timeOut = 120000l;//2分钟
// @GetMapping("/init")
// public Mono<DeviceInitResp> deviceInit(@RequestParam String wifiMac, @RequestParam String btMac,
// @RequestParam Integer type, @RequestParam Long time,
// @RequestParam String signature){
// Long now = System.currentTimeMillis();
// if(checkTimeout && now - time > timeOut){
// //超时
// BusinessException ex = new BusinessException("请求已失效");
// return Mono.error(ex);
// }
// //设备类型是否匹配暂时不做限制
// //验签
// String wifiMd5 = MD5.create().digestHex(wifiMac).toLowerCase();
// String btMd5 = MD5.create().digestHex(btMac).toLowerCase();
// String md5 = MD5.create().digestHex(wifiMd5 + btMd5 + type + time + key).toLowerCase();
// if (md5.equals(signature)) {
// //
// DeviceInfoRequest request = new DeviceInfoRequest();
// request.setWifiMac(wifiMac);
// request.setBtMac(btMac);
// Mono<DeviceInfoEntity> mono = deviceInfoService.selectDeviceInfoByRequest(request);
// return mono.flatMap(d -> {
// Mono o = null;
// if(d == null){
// DeviceTypeEnum entryTypeEnum = DeviceTypeEnum.getEnumWithCode(type);
// d = new DeviceInfoEntity();
// d.setWifiMac(wifiMac);
// d.setBtMac(btMac);
// d.setDeviceType(type);
// d.setKey( com.qiuguo.iot.base.utils.StringUtils.getRandomStr(10));//生成key
// DateTimeFormatter df = DateTimeFormatter.ofPattern("yyMMddHHmmss");
// d.setSn("QG" + entryTypeEnum.getSn() +df.format(LocalDateTime.now()) + StringUtils.getRandomStr(3));
// o = deviceInfoService.insertDeviceInfo(d);
// }else{
// d.setKey( com.qiuguo.iot.base.utils.StringUtils.getRandomStr(10));//重新生成Key
// o = deviceInfoService.updateDeviceInfoById(d);
// }
// final DeviceInfoEntity entity = d;
// DeviceInitResp resp = new DeviceInitResp();
// resp.setSn(entity.getSn());
// resp.setKey(entity.getKey());
// return resp;
//
//
// });
// }
// //验签失败
// BusinessException ex = new BusinessException("验签失败");
// return Mono.error(ex);
//
// }
@GetMapping("/init")
public Mono<DeviceInitResp> deviceInit(@RequestParam String wifiMac, @RequestParam String btMac,
@RequestParam Integer type, @RequestParam Long time,
@RequestParam String signature){
Long now = System.currentTimeMillis();
if(checkTimeout && now - time > timeOut){
//超时
BusinessException ex = new BusinessException("请求已失效");
return Mono.error(ex);
}
//设备类型是否匹配暂时不做限制
//验签
String wifiMd5 = MD5.create().digestHex(wifiMac).toLowerCase();
String btMd5 = MD5.create().digestHex(btMac).toLowerCase();
String md5 = MD5.create().digestHex(wifiMd5 + btMd5 + type + time + key).toLowerCase();
if (md5.equals(signature)) {
//
DeviceInfoRequest request = new DeviceInfoRequest();
request.setWifiMac(wifiMac);
request.setBtMac(btMac);
Mono<DeviceInfoEntity> mono = deviceInfoService.selectDeviceInfoByRequest(request);
return mono.defaultIfEmpty(new DeviceInfoEntity()).flatMap(entity -> {
if(entity.getId() == null){
DeviceTypeEnum entryTypeEnum = DeviceTypeEnum.getEnumWithCode(type);
entity = new DeviceInfoEntity();
entity.setWifiMac(wifiMac);
entity.setBtMac(btMac);
entity.setBatchId(1l);
entity.setName(entryTypeEnum.getName());
entity.setDeviceType(type);
entity.setKey( com.qiuguo.iot.base.utils.StringUtils.getRandomStr(10));//生成key
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyMMddHHmmss");
entity.setSn("QG" + entryTypeEnum.getSn() +df.format(LocalDateTime.now()) + StringUtils.getRandomStr(3));
deviceInfoService.insertDeviceInfo(entity);
}else{
entity.setKey( com.qiuguo.iot.base.utils.StringUtils.getRandomStr(10));//重新生成Key
deviceInfoService.updateDeviceInfoById(entity);
}
return Mono.just(entity);
}).map(o -> {
DeviceInitResp resp = new DeviceInitResp();
resp.setKey(o.getKey());
resp.setSn(o.getSn());
return resp;
});
}
//验签失败
BusinessException ex = new BusinessException("验签失败");
return Mono.error(ex);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff