|
@@ -1,141 +0,0 @@
|
|
|
-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.DeviceChangeStatusDTO;
|
|
|
-import com.xy.dto.MercMiniDeviceDto;
|
|
|
-import com.xy.entity.DeviceInfo;
|
|
|
-import com.xy.service.AlipayDeviceService;
|
|
|
-import com.xy.service.DeviceInfoServiceImpl;
|
|
|
-import com.xy.utils.AuthorizeUtils;
|
|
|
-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;
|
|
|
-
|
|
|
- private AlipayDeviceService alipayDeviceService;
|
|
|
-
|
|
|
- /**
|
|
|
- * 支付宝设备
|
|
|
- *
|
|
|
- * @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;
|
|
|
- }
|
|
|
- //发送支付宝设备重启请求
|
|
|
- if (data.getStr("type").equals("app") && data.getStr("task").equals("restart")) {
|
|
|
- alipayDeviceService.deviceReboot(deviceInfo.getDistrictId().toString());
|
|
|
- }
|
|
|
- });
|
|
|
- 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);
|
|
|
- //发送支付宝设备修改运营状态请求
|
|
|
- DeviceChangeStatusDTO deviceChangeStatusDTO = new DeviceChangeStatusDTO()
|
|
|
- .setTerminalId(String.valueOf(deviceId))
|
|
|
- .setOperatorId(AuthorizeUtils.getLoginId(String.class))
|
|
|
- .setStatus(busySate.getBusyState());
|
|
|
- alipayDeviceService.changeStatus(deviceChangeStatusDTO);
|
|
|
- return false;
|
|
|
- }
|
|
|
-}
|