Kaynağa Gözat

增加设备激活前检测接口

hechunping 2 yıl önce
ebeveyn
işleme
49c493a66e

+ 31 - 16
device-api-service-merc-mini/src/main/java/com/xy/controller/MercMiniDeviceController.java

@@ -116,20 +116,20 @@ public class MercMiniDeviceController {
         dto.setMercId(MercAuthUtils.getMercId());
         return deviceInfoService.dataCount(dto);
     }
-
-    @PostMapping("active")
-    @ApiOperation("激活设备")
-    public R active(@RequestBody MercMiniDeviceDto.Active active) {
-        DeviceInfo deviceInfo = deviceInfoService.getById(active.getDeviceId());
-        if (deviceInfo.getActiveState().equals(Integer.valueOf(DictSonEnum.DEVICE_ACTIVE_STATUS_1.getKey()))) {
-            return R.fail("机器已激活");
-        }
+    @PostMapping("getActiveInfo")
+    @ApiOperation("激活设备前判断")
+    public R getActiveInfo(@RequestBody MercMiniDeviceDto.Active active){
         Long mercId = MercAuthUtils.getMercId();
         //商户是否已通过审核
         MercDto.Vo mercInfo = mercFeignService.obj(new MercDto.ListDTO().setId(mercId)).getData();
         if (!mercInfo.getStatus().equals(String.valueOf(MercStatus.APPROVED.getCode()))) {
             return R.fail("商户未通过审核");
         }
+        DeviceInfo deviceInfo = deviceInfoService.getById(active.getDeviceId());
+        //设备是否存在
+        if(!Emptys.check(deviceInfo)){
+            return R.fail("机器不存在");
+        }
         //机器是否已授权给该商户
         if (!deviceInfo.getMercId().equals(mercId)) {
             return R.fail("机器未授权给商户");
@@ -138,17 +138,32 @@ public class MercMiniDeviceController {
         if (deviceInfo.getFreezeStatus().equals(Integer.valueOf(DictSonEnum.DEVICE_FREEZE_STATUS_2.getKey()))) {
             return R.fail("机器已冻结");
         }
-        //激活设备
-        DeviceInfo updateDeviceInfo = new DeviceInfo()
-                .setDeviceId(active.getDeviceId())
-                .setActiveState(Integer.valueOf(DictSonEnum.DEVICE_ACTIVE_STATUS_1.getKey()))
-                .setBusyState(Integer.valueOf(DictSonEnum.DEVICE_BUSY_STATUS_1.getKey()))
-                .setActiveTime(LocalDateTime.now())
-                .setShowStatus(true);
-        deviceInfoService.updateById(updateDeviceInfo);
+        if (deviceInfo.getActiveState().equals(Integer.valueOf(DictSonEnum.DEVICE_ACTIVE_STATUS_1.getKey()))) {
+            return R.fail("机器已激活");
+        }
         return R.ok();
     }
 
+    @PostMapping("active")
+    @ApiOperation("激活设备")
+    public R active(@RequestBody MercMiniDeviceDto.Active active) {
+        R activeInfo = this.getActiveInfo(active);
+        if(activeInfo.getCode() == R.Enum.SUCCESS.getCode()){
+            //激活设备
+            DeviceInfo updateDeviceInfo = new DeviceInfo()
+                    .setDeviceId(active.getDeviceId())
+                    .setActiveState(Integer.valueOf(DictSonEnum.DEVICE_ACTIVE_STATUS_1.getKey()))
+                    .setBusyState(Integer.valueOf(DictSonEnum.DEVICE_BUSY_STATUS_1.getKey()))
+                    .setActiveTime(LocalDateTime.now())
+                    .setShowStatus(true);
+            deviceInfoService.updateById(updateDeviceInfo);
+            return R.ok();
+        }else{
+            return activeInfo;
+        }
+
+    }
+
     @PostMapping("modifyBusyStage")
     @ApiOperation("运营状态修改")
     public R modifyBusyStage(@RequestBody @Validated MercMiniDeviceDto.BusySate busySate) {