|
@@ -1,5 +1,7 @@
|
|
|
package com.xy.open;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
@@ -7,12 +9,14 @@ import com.xy.annotate.RestMappingController;
|
|
|
import com.xy.annotation.Open;
|
|
|
import com.xy.bean.OpenContext;
|
|
|
import com.xy.bean.ServiceContext;
|
|
|
+import com.xy.dto.CommandMqtt;
|
|
|
import com.xy.dto.OpenPlatformConfigDto;
|
|
|
import com.xy.entity.DeviceInfo;
|
|
|
import com.xy.exception.ServiceException;
|
|
|
import com.xy.open.dto.DeviceOpenApiDTO;
|
|
|
import com.xy.open.vo.DeviceOpenApiVO;
|
|
|
import com.xy.service.DeviceInfoServiceImpl;
|
|
|
+import com.xy.service.MqttService;
|
|
|
import com.xy.service.OpenPlatformConfigService;
|
|
|
import com.xy.utils.PageBean;
|
|
|
import com.xy.utils.R;
|
|
@@ -25,6 +29,8 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
import static com.xy.utils.PlusBeans.toIPage;
|
|
|
import static com.xy.utils.PlusBeans.toPageBean;
|
|
@@ -42,6 +48,8 @@ public class DeviceOpenApiService {
|
|
|
|
|
|
private final DeviceInfoServiceImpl deviceInfoService;
|
|
|
private final OpenPlatformConfigService openPlatformConfigService;
|
|
|
+ private final MqttService mqttService;
|
|
|
+
|
|
|
|
|
|
@ApiOperation(value = "获取商户设备列表", notes = "获取商户设备列表")
|
|
|
@Open(value = "device.page.get", version = "1.0", permission = true)
|
|
@@ -61,4 +69,46 @@ public class DeviceOpenApiService {
|
|
|
return toPageBean(DeviceOpenApiVO.DeviceList.class, iPage);
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation(value = "设备操作", notes = "设备操作(开打印机门锁:openPrinterLock)")
|
|
|
+ @Open(value = "device.operate", version = "1.0", permission = true)
|
|
|
+ @PostMapping("/device/operate")
|
|
|
+ public DeviceOpenApiDTO.DeviceOperateResult deviceOperate(@RequestBody @Valid DeviceOpenApiDTO.DeviceOperate dto) {
|
|
|
+ DeviceOpenApiDTO.DeviceOperateResult result = new DeviceOpenApiDTO.DeviceOperateResult();
|
|
|
+ OpenContext oct = ServiceContext.getCurrentContext().getOpenContext();
|
|
|
+ String appId = oct.getAppId();
|
|
|
+ List<Long> mercIds = R.feignCheckData(openPlatformConfigService.getMercIdsByAppId(new OpenPlatformConfigDto.QueryByApp().setAppId(appId)));
|
|
|
+ if (CollUtil.isEmpty(mercIds)) {
|
|
|
+ throw new ServiceException("尚未分配商户,请联系平台客服!");
|
|
|
+ }
|
|
|
+ Long deviceId = dto.getDeviceId();
|
|
|
+ DeviceInfo deviceInfo = deviceInfoService.getById(deviceId);
|
|
|
+ if (deviceInfo == null) {
|
|
|
+ throw new ServiceException("设备不存在!");
|
|
|
+ }
|
|
|
+ if (!CollUtil.contains(mercIds, deviceInfo.getMercId())) {
|
|
|
+ throw new ServiceException("您没有权限操作该设备!");
|
|
|
+ }
|
|
|
+ String action = dto.getAction();
|
|
|
+ if ("openPrinterLock".equals(action)) {
|
|
|
+ action = "locker";
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("未知或不支持的操作类型!");
|
|
|
+ }
|
|
|
+ List<CommandMqtt> commandMqtts = new ArrayList<>();
|
|
|
+ JSONObject templet = new JSONObject();
|
|
|
+ templet.putOnce("wkSn", "$wkSn$");
|
|
|
+ templet.putOnce("cmdType", "task");
|
|
|
+ templet.putOnce("actionType", "issue");
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.putOnce("type", action);
|
|
|
+ data.putOnce("id", "0");
|
|
|
+ data.putOnce("jgh", "1");
|
|
|
+ data.putOnce("task", "open");
|
|
|
+ templet.putOnce("data", data);
|
|
|
+ commandMqtts.add(new CommandMqtt().setDeviceId(deviceId).setTemplet(templet));
|
|
|
+ mqttService.senCommand(commandMqtts);
|
|
|
+ result.setResult(true);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|