Parcourir la source

nfc 音量设置api,spi

tanbin il y a 9 mois
Parent
commit
beb3706984

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

@@ -500,4 +500,24 @@ public class MercMiniDeviceController {
         return R.ok(deviceBluetoothAuthService.saveOrUpdate(deviceBluetoothAuth));
     }
 
+
+    @ApiOperation("支付宝Npad音量设置")
+    @PostMapping("setAliNpadVol")
+    public R<Boolean> setAliNpadVol(@RequestBody @Validated DeviceInfoDto.NfcVol nfcVol) {
+        String deviceId = nfcVol.getDeviceId();
+        DeviceSetAttr dto = new DeviceSetAttr();
+        dto.setType("VOL").setTerminalId(deviceId).setValue(nfcVol.getValue());
+        return R.ok(R.feignCheckData(alipayDeviceService.setAttributes(dto)));
+    }
+
+
+    @ApiOperation("音量、温度查询")
+    @PostMapping("queryAliNpadVol")
+    public R<Boolean> queryAliNpadVol(@RequestBody DeviceInfoDto.NfcVolQuery dto) {
+        DeviceQueryAttr deviceQueryAttr = new DeviceQueryAttr();
+        deviceQueryAttr.setTerminalId(dto.getDeviceId());
+        deviceQueryAttr.setType("VOL");
+        return R.ok(R.feignCheckData(alipayDeviceService.queryAttributes(deviceQueryAttr)));
+    }
+
 }

+ 18 - 14
device-api-service/src/main/java/com/xy/service/factory/device/impl/alipay/AliPayOpenDeviceFatoryImpl.java

@@ -340,18 +340,18 @@ public class AliPayOpenDeviceFatoryImpl implements DeviceFactory, SpiDeviceServi
         String value = dto.getValue();
 
         //查询设备信息
-        DeviceInfo deviceInfo = deviceInfoService.getById(Long.valueOf(terminalId));
+        DeviceInfoDto.Vo deviceInfo = R.feignCheckData(deviceInfoService.obj(new DeviceInfoDto.Obj().setIsSysinfo(true).setDeviceId(Long.valueOf(terminalId))));
         if (deviceInfo == null) {
             log.warn("温度、音量查询SPI通知,无设备信息");
             return SpiResponseConst.SUCCESS;
         }
+        DeviceSysinfoDto.Vo deviceSysinfo = deviceInfo.getDeviceSysinfo();
+        boolean isHaveNfc = false;
+        if (deviceSysinfo != null && StrUtil.isNotEmpty(deviceSysinfo.getNfcSn())) {
+            isHaveNfc = true;
+        }
         //温度更新
         FunctionUtils.NoParamsNoResult updateTmp = () -> {
-//            deviceStatus.setTempValue(Integer.valueOf(value));
-//            deviceStatusService.updateById(deviceStatus);
-//            DeviceSysinfoDto.Up sysUp = new DeviceSysinfoDto.Up();
-//            sysUp.setDeviceId(deviceInfo.getDeviceId()).setIsHaveTemp(true);
-//            deviceSysinfoService.up(sysUp);
             DeviceStatusDto.Up up = new DeviceStatusDto.Up();
             up.setDeviceId(deviceInfo.getDeviceId())
                     .setTempState(0)
@@ -360,21 +360,19 @@ public class AliPayOpenDeviceFatoryImpl implements DeviceFactory, SpiDeviceServi
         };
 
         DeviceStatus deviceStatus = deviceStatusService.getById(deviceInfo.getDeviceId());
-        if (deviceStatus == null) {
+        if (deviceStatus == null && !isHaveNfc) {
             log.warn("温度、音量查询SPI通知,无设备状态记录");
             return SpiResponseConst.SUCCESS;
         }
         //音量更新
         FunctionUtils.NoParamsNoResult updateVoice = () -> {
-//            deviceStatus.setVoiceVolume(Integer.valueOf(value));
-//            deviceStatusService.updateById(deviceStatus);
             DeviceStatusDto.Up up = new DeviceStatusDto.Up();
             up.setDeviceId(deviceInfo.getDeviceId())
                     .setVoiceVolume(Integer.valueOf(value));
             deviceStatusService.up(up);
         };
 
-        if (BooleanUtil.isTrue(success)) {
+        if (BooleanUtil.isTrue(success) && !isHaveNfc) {
             //温度:TEMP 音量:VOL
             if ("VOL".equals(type)) {
                 updateVoice.run();
@@ -394,13 +392,19 @@ public class AliPayOpenDeviceFatoryImpl implements DeviceFactory, SpiDeviceServi
         String value = dto.getValue();
 
         //查询设备信息
-        DeviceInfo deviceInfo = deviceInfoService.getById(Long.valueOf(terminalId));
+        DeviceInfoDto.Vo deviceInfo = R.feignCheckData(deviceInfoService.obj(new DeviceInfoDto.Obj().setIsSysinfo(true).setDeviceId(Long.valueOf(terminalId))));
         if (deviceInfo == null) {
-            log.warn("温度、音量设置SPI通知,无设备信息");
+            log.warn("温度、音量查询SPI通知,无设备信息");
             return SpiResponseConst.SUCCESS;
         }
+        DeviceSysinfoDto.Vo deviceSysinfo = deviceInfo.getDeviceSysinfo();
+        boolean isHaveNfc = false;
+        if (deviceSysinfo != null && StrUtil.isNotEmpty(deviceSysinfo.getNfcSn())) {
+            isHaveNfc = true;
+        }
+
         DeviceStatus deviceStatus = deviceStatusService.getById(deviceInfo.getDeviceId());
-        if (deviceStatus == null) {
+        if (deviceStatus == null && !isHaveNfc) {
             log.warn("温度、音量设置SPI通知,无设备状态记录");
             return SpiResponseConst.SUCCESS;
         }
@@ -415,7 +419,7 @@ public class AliPayOpenDeviceFatoryImpl implements DeviceFactory, SpiDeviceServi
             deviceStatusService.updateById(deviceStatus);
         };
 
-        if (BooleanUtil.isTrue(success)) {
+        if (BooleanUtil.isTrue(success) && !isHaveNfc) {
             //温度:TEMP 音量:VOL
             if ("VOL".equals(type)) {
                 updateVoice.run();

+ 23 - 1
device-api/src/main/java/com/xy/dto/DeviceInfoDto.java

@@ -26,6 +26,7 @@ import java.util.List;
 @Data
 @Accessors(chain = true)
 public class DeviceInfoDto {
+
     /**
      * 删除线路\点位时时指定 传入 wherePlaceLineId\wherePlaceId
      */
@@ -39,6 +40,27 @@ public class DeviceInfoDto {
      */
     public final static String CLEAR = "clear";
 
+    @Data
+    @Accessors(chain = true)
+    public static class NfcVol {
+        @NotBlank(message = "设备编号不可为空")
+        @ApiModelProperty(value = "设备编号", required = true)
+        private String deviceId;
+
+        @NotBlank(message = "值不可为空")
+        @ApiModelProperty(value = " 音量:0~15 (最小颗粒为1)", required = true)
+        private String value;
+    }
+
+    @Data
+    @Accessors(chain = true)
+    public static class NfcVolQuery {
+        @NotBlank(message = "设备编号不可为空")
+        @ApiModelProperty(value = "设备编号", required = true)
+        private String deviceId;
+ 
+    }
+
 
     @Data
     @Accessors(chain = true)
@@ -218,7 +240,7 @@ public class DeviceInfoDto {
 
         @ApiModelProperty("算法ID")
         private Long algorithmId;
-        
+
         @ApiModelProperty("货道数量")
         private Integer aisleNum;