Bläddra i källkod

支付宝设备重启、运营状态修改

李进 1 år sedan
förälder
incheckning
beceb95d36

+ 0 - 14
device-api-service-alipay/pom.xml

@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <parent>
-        <artifactId>xy-device</artifactId>
-        <groupId>com.xy</groupId>
-        <version>1.0</version>
-    </parent>
-    <modelVersion>4.0.0</modelVersion>
-
-    <artifactId>device-api-service-alipay</artifactId>
-
-</project>

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

@@ -3,6 +3,7 @@ package com.xy.controller;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.xy.alipay.AliPay;
 import com.xy.annotate.RestMappingController;
 import com.xy.annotate.RestMappingController;
 import com.xy.dto.DeviceBluetoothAuthDto;
 import com.xy.dto.DeviceBluetoothAuthDto;
 import com.xy.dto.DeviceInfoDto;
 import com.xy.dto.DeviceInfoDto;
@@ -217,8 +218,9 @@ public class MercMiniDeviceController {
         }
         }
     }
     }
 
 
-    @PostMapping("modifyBusyStage")
     @ApiOperation("运营状态修改")
     @ApiOperation("运营状态修改")
+    @PostMapping("modifyBusyStage")
+    @AliPay(AliPay.Type.BUSY_STATE)
     public R modifyBusyStage(@RequestBody @Validated MercMiniDeviceDto.BusySate busySate) {
     public R modifyBusyStage(@RequestBody @Validated MercMiniDeviceDto.BusySate busySate) {
         Long mercId = MercAuthUtils.getMercId();
         Long mercId = MercAuthUtils.getMercId();
         Long deviceId = busySate.getDeviceId();
         Long deviceId = busySate.getDeviceId();

+ 0 - 5
device-api-service/pom.xml

@@ -49,11 +49,6 @@
             <artifactId>merc-api</artifactId>
             <artifactId>merc-api</artifactId>
             <version>1.0</version>
             <version>1.0</version>
         </dependency>
         </dependency>
-        <dependency>
-            <groupId>com.xy</groupId>
-            <artifactId>device-api-service-alipay</artifactId>
-            <version>1.0</version>
-        </dependency>
 
 
         <dependency>
         <dependency>
             <groupId>com.xy</groupId>
             <groupId>com.xy</groupId>

+ 39 - 0
device-api-service/src/main/java/com/xy/alipay/AliPay.java

@@ -0,0 +1,39 @@
+package com.xy.alipay;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.lang.annotation.*;
+
+/**
+ * 支付宝注解
+ *
+ * @author lijin
+ */
+@Target({ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface AliPay {
+
+    /**
+     * 类型
+     *
+     * @return
+     */
+    Type value();
+
+
+    @Getter
+    @AllArgsConstructor
+    enum Type {
+
+        RESTART("重启设备"),
+
+        BUSY_STATE("修改运营状态")
+
+        ;
+
+        private String type;
+    }
+
+}

+ 133 - 0
device-api-service/src/main/java/com/xy/alipay/AliPayAspet.java

@@ -0,0 +1,133 @@
+package com.xy.alipay;
+
+import cn.hutool.json.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.xy.collections.list.JArrayList;
+import com.xy.collections.map.JMap;
+import com.xy.dto.CommandMqtt;
+import com.xy.dto.MercMiniDeviceDto;
+import com.xy.entity.DeviceInfo;
+import com.xy.service.DeviceInfoServiceImpl;
+import com.xy.utils.FunctionUtils;
+import com.xy.utils.R;
+import com.xy.utils.enums.DictSonEnum;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Slf4j
+@Aspect
+@Component
+@AllArgsConstructor
+public class AliPayAspet {
+
+    private DeviceInfoServiceImpl deviceInfoService;
+
+    /**
+     * 支付宝设备
+     *
+     * @param joinPoint
+     * @param aliPay
+     * @return
+     * @throws Throwable
+     */
+    @Around("@annotation(aliPay)")
+    public Object timer(ProceedingJoinPoint joinPoint, AliPay aliPay) throws Throwable {
+        String type = aliPay.value().getType();
+        Object[] args = joinPoint.getArgs();
+        Object result = R.ok();
+        try {
+            boolean fal = before(type, args);
+            if (fal) {
+                result = joinPoint.proceed(args);
+            }
+        } catch (Exception e) {
+            throw e;
+        }
+        return result;
+    }
+
+    public boolean before(String type, Object[] args) {
+        boolean fal = true;
+        //重启设备
+        if (type.equals(AliPay.Type.RESTART.getType())) {
+            List<CommandMqtt> restart = restart(args);
+            if (restart.size() > 0) {
+                args[0] = restart;
+            } else {
+                fal = false;
+            }
+        }
+        //修改运营状态
+        if (type.equals(AliPay.Type.BUSY_STATE.getType())) {
+            fal = busyState(args);
+        }
+        return fal;
+    }
+
+    /**
+     * 重启设备
+     *
+     * @param args
+     */
+    private List<CommandMqtt> restart(Object[] args) {
+        List<CommandMqtt> result = new ArrayList<>();
+        List<CommandMqtt> commandMqtts = (List<CommandMqtt>) args[0];
+        //查询支付宝设备信息
+        List<DeviceInfo> deviceInfos = deviceInfoService.list(new LambdaQueryWrapper<DeviceInfo>()
+                .in(DeviceInfo::getDeviceId, new JArrayList<>(commandMqtts).comparing(CommandMqtt::getDeviceId).getProperty(CommandMqtt::getDeviceId))
+                .eq(DeviceInfo::getDeviceType, DictSonEnum.DEVICE_TYPE_5.getKey())
+        );
+        if (deviceInfos.size() == 0) {
+            return commandMqtts;
+        }
+        JMap<Long, DeviceInfo> deviceInfosJMaps = new JArrayList<>(deviceInfos).toMap(DeviceInfo::getDeviceId).cover();
+        commandMqtts.forEach(commandMqtt -> {
+            JSONObject templet = commandMqtt.getTemplet();
+            JSONObject data = templet.getJSONObject("data");
+            DeviceInfo deviceInfo = deviceInfosJMaps.get(commandMqtt.getDeviceId());
+            if (deviceInfo == null) {
+                result.add(commandMqtt);
+                return;
+            }
+            //todo 发送支付宝设备重启请求
+            if (data.getStr("type").equals("app") && data.getStr("task").equals("restart")) {
+                log.info("支付宝设备重启:{}", deviceInfo.getDeviceId());
+            }
+        });
+        return result;
+    }
+
+    /**
+     * 修改运营状态
+     *
+     * @param args
+     * @return
+     */
+    private boolean busyState(Object[] args) {
+        MercMiniDeviceDto.BusySate busySate = (MercMiniDeviceDto.BusySate) args[0];
+        //查询支付宝设备信息
+        DeviceInfo deviceInfo = deviceInfoService.getOne(new LambdaQueryWrapper<DeviceInfo>()
+                .eq(DeviceInfo::getDeviceId, busySate.getDeviceId())
+                .eq(DeviceInfo::getDeviceType, DictSonEnum.DEVICE_TYPE_5.getKey())
+        );
+        if (deviceInfo == null) {
+            return true;
+        }
+        Long deviceId = busySate.getDeviceId();
+        DeviceInfo updateDeviceInfo = new DeviceInfo()
+                .setDeviceId(deviceId)
+                .setBusyState(busySate.getBusyState())
+                .setFreezeStatus(busySate.getBusyState());
+        deviceInfoService.updateById(updateDeviceInfo);
+        //todo 发送支付宝设备修改运营状态请求
+
+        return false;
+    }
+}

+ 2 - 1
device-api-service/src/main/java/com/xy/service/MqttServiceImpl.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xy.alipay.AliPay;
 import com.xy.annotate.Runners;
 import com.xy.annotate.Runners;
 import com.xy.annotate.Timer;
 import com.xy.annotate.Timer;
 import com.xy.collections.map.JHashMap;
 import com.xy.collections.map.JHashMap;
@@ -123,9 +124,9 @@ public class MqttServiceImpl extends ServiceImpl<MqttCommandMapper, MqttCommand>
         snInit = true;
         snInit = true;
     }
     }
 
 
-    @Timer
     @Override
     @Override
     @ApiOperation("指令发送")
     @ApiOperation("指令发送")
+    @AliPay(AliPay.Type.RESTART)
     public R<List<Tuple.Tuple3<Long, Long, Boolean>>> senCommand(List<CommandMqtt> commandMqtts) {
     public R<List<Tuple.Tuple3<Long, Long, Boolean>>> senCommand(List<CommandMqtt> commandMqtts) {
         //发送指令
         //发送指令
         List<MqttDto> mqttDtos = new ArrayList<>();
         List<MqttDto> mqttDtos = new ArrayList<>();

+ 0 - 1
pom.xml

@@ -14,7 +14,6 @@
         <module>device-start</module>
         <module>device-start</module>
         <module>device-api-service-merc-mini</module>
         <module>device-api-service-merc-mini</module>
         <module>device-api-service-member</module>
         <module>device-api-service-member</module>
-        <module>device-api-service-alipay</module>
     </modules>
     </modules>
     <packaging>pom</packaging>
     <packaging>pom</packaging>