123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- 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.DictsSonEnum;
- 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, DictsSonEnum.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.getDeviceId().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, DictsSonEnum.DEVICE_TYPE_5.getKey())
- );
- if (deviceInfo == null) {
- return true;
- }
- //发送支付宝设备修改运营状态请求
- DeviceChangeStatusDTO deviceChangeStatusDTO = new DeviceChangeStatusDTO()
- .setTerminalId(String.valueOf(busySate.getDeviceId()))
- .setOperatorId(AuthorizeUtils.getLoginId(String.class))
- .setStatus(busySate.getBusyState());
- alipayDeviceService.changeStatus(deviceChangeStatusDTO);
- return false;
- }
- }
|