|
@@ -7,6 +7,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.github.yitter.idgen.YitIdHelper;
|
|
|
import com.xy.annotate.RestMappingController;
|
|
|
import com.xy.annotation.LogOperate;
|
|
|
import com.xy.collections.list.JArrayList;
|
|
@@ -469,6 +470,50 @@ public class MercMiniDeviceController {
|
|
|
return R.ok(deviceBluetoothAuthService.save(saveInfo));
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("genCodeByAdmin")
|
|
|
+ @ApiOperation("蓝牙开门-平台管理员生成授权码(通用码)")
|
|
|
+ public R<Long> genCodeByAdmin(@RequestBody @Validated DeviceBluetoothAuthDto.GenCodeByAdmin dto) {
|
|
|
+
|
|
|
+ long deviceId = YitIdHelper.nextId();
|
|
|
+
|
|
|
+ // 缓存
|
|
|
+ setCacheAuthCode(deviceId, String.valueOf(deviceId));
|
|
|
+ DeviceBluetoothAuth saveInfo = new DeviceBluetoothAuth()
|
|
|
+ .setDeviceId(deviceId)
|
|
|
+ .setMercId(0L)
|
|
|
+ .setDeviceId(deviceId).setAuthCode(String.valueOf(deviceId));
|
|
|
+ deviceBluetoothAuthService.save(saveInfo);
|
|
|
+ return R.ok(deviceId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("verificationBlueCode")
|
|
|
+ @ApiOperation("蓝牙开门-校验并使用授权码(平台管理员生成)")
|
|
|
+ public R<Boolean> verificationBlueCode(@RequestBody @Validated DeviceBluetoothAuthDto.VerificationCodeByAdmin dto) {
|
|
|
+ String authCode = dto.getAuthCode();
|
|
|
+ String cacheAuthCode = getCacheAuthCode(Long.valueOf(authCode));
|
|
|
+ if (!authCode.equals(cacheAuthCode)) {
|
|
|
+ return R.fail("您输入的授权码有误或者无效!");
|
|
|
+ }
|
|
|
+ // 验证通过,缓存去掉授权码,并更新状态
|
|
|
+// Long mercId = MercAuthUtils.getMercId();
|
|
|
+ DeviceBluetoothAuth deviceBluetoothAuth = deviceBluetoothAuthService.getOne(Wrappers.<DeviceBluetoothAuth>lambdaQuery()
|
|
|
+ .eq(DeviceBluetoothAuth::getDeviceId, Long.valueOf(authCode))
|
|
|
+ .eq(DeviceBluetoothAuth::getAuthCode, authCode)
|
|
|
+ .eq(DeviceBluetoothAuth::getUseStatus, DeviceAuthCodeUseStatus.UN_USED.getCode())
|
|
|
+ );
|
|
|
+ if (deviceBluetoothAuth == null) {
|
|
|
+ return R.fail("您输入的授权码无效!");
|
|
|
+ }
|
|
|
+ // 缓存去掉授权码
|
|
|
+ delCacheAuthCode(Long.valueOf(authCode));
|
|
|
+ deviceBluetoothAuth.setUseStatus(DeviceAuthCodeUseStatus.USED.getCode());
|
|
|
+ deviceBluetoothAuth.setUseUser(AuthorizeUtils.getLoginId(Long.class));
|
|
|
+ deviceBluetoothAuth.setUseTime(LocalDateTime.now());
|
|
|
+ return R.ok(deviceBluetoothAuthService.saveOrUpdate(deviceBluetoothAuth));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@PostMapping("verificationCode")
|
|
|
@ApiOperation("蓝牙开门-校验并使用授权码")
|
|
|
public R<Boolean> verificationCode(@RequestBody @Validated DeviceBluetoothAuthDto.VerificationCode dto) {
|