#init
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package com.fastbee.controller;
|
||||
|
||||
import com.fastbee.common.CommandConstant;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.domain.model.LoginUser;
|
||||
import com.fastbee.common.utils.SecurityUtils;
|
||||
import com.fastbee.common.utils.json.JsonUtils;
|
||||
import com.fastbee.dto.DeviceTaskQueryDTO;
|
||||
import com.fastbee.dto.NettyDevice;
|
||||
import com.fastbee.dto.ObstacleData;
|
||||
import com.fastbee.iot.domain.DevicePlan;
|
||||
import com.fastbee.manager.DeviceSessionManager;
|
||||
import com.fastbee.service.DeviceTaskService;
|
||||
import com.fastbee.utils.CommandUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.java_websocket.WebSocket;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/iot/api")
|
||||
public class DeviceExternalApiController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private DeviceSessionManager deviceSessionManager;
|
||||
|
||||
@PostMapping("/obstacleData")
|
||||
public AjaxResult obstacleData(@RequestBody ObstacleData obstacleData) {
|
||||
Map<String, Object> data = obstacleData.getData();
|
||||
String deviceId = (String) data.get("deviceId");
|
||||
if (StringUtils.isEmpty(deviceId)) {
|
||||
return AjaxResult.error("deviceId为空!");
|
||||
}
|
||||
// Map<String, Object> obstacle = (Map<String, Object>) data.get("obstacle");
|
||||
// Boolean isSecure = (Boolean) data.get("isSecure");
|
||||
|
||||
List<NettyDevice> devices = deviceSessionManager.getSlaveControl(deviceId);
|
||||
if (!CollectionUtils.isEmpty(devices)) {
|
||||
devices.forEach(x -> {
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
CommandUtils.buildCommand(buf, obstacleData, CommandConstant.interaction);
|
||||
String content = buf.toString(CharsetUtil.UTF_8);
|
||||
logger.info("推送设备:{}障碍物消息:{}到:{}", deviceId, content, x.getConnectorId());
|
||||
if (x.getChannel() != null && x.getChannel().isActive()) {
|
||||
x.getChannel().writeAndFlush(buf);
|
||||
}
|
||||
});
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.fastbee.controller;
|
||||
|
||||
import com.fastbee.manager.DeviceSessionManager;
|
||||
import com.fastbee.memory.GlobalMemory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/memory/device")
|
||||
public class DeviceMemoryController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private DeviceSessionManager deviceSessionManager;
|
||||
|
||||
@Autowired
|
||||
private GlobalMemory globalMemory;
|
||||
|
||||
@GetMapping("getDeviceMemory")
|
||||
public Map<String, Object> getDeviceMemory() {
|
||||
Map<String, Object> res = new HashMap<>();
|
||||
res.put("deviceMap", deviceSessionManager.getDeviceMap());
|
||||
res.put("channelToDeviceIdMap", deviceSessionManager.getChannelToDeviceIdMap());
|
||||
res.put("channelMap", deviceSessionManager.getChannelMap());
|
||||
return res;
|
||||
}
|
||||
//
|
||||
// @GetMapping("getGlobalMemory")
|
||||
// public Map<String, Object> getGlobalMemory() {
|
||||
// Map<String, Object> res = new HashMap<>();
|
||||
// res.put("sysLoginMap", globalMemory.getSysLoginMap());
|
||||
// res.put("sysLoginDataMap", globalMemory.getSysLoginDataMap());
|
||||
// return res;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.fastbee.controller;
|
||||
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.domain.model.LoginUser;
|
||||
import com.fastbee.common.utils.SecurityUtils;
|
||||
import com.fastbee.dto.DeviceTaskQueryDTO;
|
||||
import com.fastbee.iot.domain.DevicePlan;
|
||||
import com.fastbee.service.DeviceTaskService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/iot/deviceTask")
|
||||
public class DeviceTaskController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private DeviceTaskService deviceTaskService;
|
||||
|
||||
@PostMapping("/save")
|
||||
public AjaxResult insertOrUpdate(@RequestBody DevicePlan devicePlan) {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
return AjaxResult.success(deviceTaskService.insertOrUpdate(devicePlan, loginUser));
|
||||
}
|
||||
|
||||
@GetMapping("/getAllDeviceTaskByUser")
|
||||
public AjaxResult getAllDeviceTaskByUser(@RequestParam Long userId) {
|
||||
return AjaxResult.success(deviceTaskService.getDeviceTaskByUser(userId));
|
||||
}
|
||||
|
||||
@PostMapping("/getDevicePlan")
|
||||
public AjaxResult getDevicePlan(@RequestBody DeviceTaskQueryDTO dto) {
|
||||
return AjaxResult.success(deviceTaskService.getDeviceTask(dto));
|
||||
}
|
||||
|
||||
@GetMapping("/delete")
|
||||
public AjaxResult delete(@RequestParam Long id) {
|
||||
return AjaxResult.success(deviceTaskService.delete(id));
|
||||
}
|
||||
|
||||
@GetMapping("/start")
|
||||
public AjaxResult start(@RequestParam Long id) {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
deviceTaskService.start(id, loginUser);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@GetMapping("/devicePlanStatistics")
|
||||
public AjaxResult devicePlanStatistics(@RequestParam Long userId) {
|
||||
return AjaxResult.success(deviceTaskService.getDevicePlanStatistics(userId));
|
||||
}
|
||||
|
||||
@GetMapping("/devicePlanTaskStatistics")
|
||||
public AjaxResult devicePlanTaskStatistics(@RequestParam Long userId) {
|
||||
|
||||
return AjaxResult.success(deviceTaskService.getDevicePlanTaskStatistics(userId));
|
||||
}
|
||||
|
||||
@GetMapping("/concurrentDeviceRoute")
|
||||
public AjaxResult concurrentDeviceRoute(@RequestParam String deviceId) {
|
||||
return AjaxResult.success(deviceTaskService.concurrentDevicePlanTask(deviceId));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/workStatistics")
|
||||
public AjaxResult workStatistics(@RequestParam Long userId) {
|
||||
return AjaxResult.success(deviceTaskService.workStatistics(userId));
|
||||
}
|
||||
|
||||
@PostMapping("/deviceTaskPool")
|
||||
public AjaxResult deviceTaskPool(@RequestBody DeviceTaskQueryDTO dto) {
|
||||
return AjaxResult.success(deviceTaskService.deviceTaskPool(dto));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.fastbee.controller;
|
||||
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.iot.domain.DeviceRunningStatusHistory;
|
||||
import com.fastbee.entity.ErrorIdentificationStandard;
|
||||
import com.fastbee.service.NettyDeviceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/netty/device")
|
||||
public class NettyDeviceController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private NettyDeviceService nettyDeviceService;
|
||||
|
||||
@GetMapping("/statusHistory")
|
||||
public TableDataInfo statusHistory(DeviceRunningStatusHistory history)
|
||||
{
|
||||
startPage();
|
||||
List<DeviceRunningStatusHistory> list = nettyDeviceService.statusHistory(history);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@GetMapping("/getErrorIdentification")
|
||||
public TableDataInfo getErrorIdentification()
|
||||
{
|
||||
startPage();
|
||||
List<ErrorIdentificationStandard> list = nettyDeviceService.allErrorIdentificationStandard();
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@PostMapping("/updateErrorIdentification")
|
||||
public AjaxResult updateErrorIdentification(@RequestBody ErrorIdentificationStandard standard)
|
||||
{
|
||||
int i = nettyDeviceService.updateErrorIdentification(standard);
|
||||
return AjaxResult.success(i);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.fastbee.controller;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.domain.model.LoginUser;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.dto.DeviceBindDTO;
|
||||
import com.fastbee.service.TransferDeviceService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/forward/device")
|
||||
public class TransferDeviceController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private TransferDeviceService transferDeviceService;
|
||||
|
||||
@PostMapping("bind")
|
||||
@ApiOperation("绑定设备")
|
||||
@Log(title = "绑定设备", businessType = BusinessType.OTHER)
|
||||
public AjaxResult bind(@RequestBody DeviceBindDTO bindDTO) {
|
||||
|
||||
if (StringUtils.isEmpty(bindDTO.getDeviceId())) {
|
||||
return AjaxResult.error("deviceId为空!");
|
||||
}
|
||||
LoginUser user = getLoginUser();
|
||||
return transferDeviceService.bind(bindDTO, user);
|
||||
}
|
||||
|
||||
@PostMapping("unbind")
|
||||
@ApiOperation("解绑设备")
|
||||
@Log(title = "解绑设备", businessType = BusinessType.OTHER)
|
||||
public AjaxResult unbind(@RequestBody DeviceBindDTO bindDTO) {
|
||||
if (StringUtils.isEmpty(bindDTO.getDeviceId())) {
|
||||
return AjaxResult.error("deviceId为空!");
|
||||
}
|
||||
LoginUser user = getLoginUser();
|
||||
return transferDeviceService.unbind(bindDTO, user);
|
||||
}
|
||||
|
||||
@PostMapping("updateDeviceAlias")
|
||||
@ApiOperation("更新设备别名")
|
||||
@Log(title = "更新设备别名", businessType = BusinessType.OTHER)
|
||||
public AjaxResult updateDeviceAlias(@RequestBody DeviceBindDTO bindDTO) {
|
||||
if (StringUtils.isEmpty(bindDTO.getDeviceId())) {
|
||||
return AjaxResult.error("deviceId为空!");
|
||||
}
|
||||
if (StringUtils.isEmpty(bindDTO.getDeviceAlias())) {
|
||||
return AjaxResult.error("设备别名为空!");
|
||||
}
|
||||
LoginUser user = getLoginUser();
|
||||
return transferDeviceService.updateDeviceAlias(bindDTO, user);
|
||||
}
|
||||
|
||||
@PostMapping("switchDevice")
|
||||
@ApiOperation("切换设备")
|
||||
@Log(title = "切换设备", businessType = BusinessType.OTHER)
|
||||
public AjaxResult switchDevice(@RequestBody DeviceBindDTO bindDTO) {
|
||||
if (StringUtils.isEmpty(bindDTO.getDeviceId())) {
|
||||
return AjaxResult.error("deviceId为空!");
|
||||
}
|
||||
if (StringUtils.isEmpty(bindDTO.getPlatform())) {
|
||||
return AjaxResult.error("平台为空!");
|
||||
}
|
||||
LoginUser user = getLoginUser();
|
||||
if (user == null) {
|
||||
return AjaxResult.error("当前token用户不存在!");
|
||||
}
|
||||
return AjaxResult.success(transferDeviceService.switchDevice(bindDTO, user));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前的控制权在哪 能否控制
|
||||
*/
|
||||
@PostMapping("remoteControl")
|
||||
@ApiOperation("获取当前设备控制权")
|
||||
@Log(title = "获取当前设备控制权", businessType = BusinessType.OTHER)
|
||||
public AjaxResult remoteControl(@RequestBody DeviceBindDTO bindDTO) {
|
||||
try {
|
||||
if (StringUtils.isEmpty(bindDTO.getDeviceId())) {
|
||||
return AjaxResult.error("deviceId为空!");
|
||||
}
|
||||
if (StringUtils.isEmpty(bindDTO.getPlatform())) {
|
||||
return AjaxResult.error("平台为空!");
|
||||
}
|
||||
LoginUser user = getLoginUser();
|
||||
return AjaxResult.success(transferDeviceService.remoteControl(bindDTO, user));
|
||||
} catch (Exception e) {
|
||||
logger.error("获取设备控制权出错", e);
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换控制请求
|
||||
*/
|
||||
@PostMapping("switchControl")
|
||||
@ApiOperation("切换控制请求")
|
||||
@Log(title = "切换控制请求", businessType = BusinessType.OTHER)
|
||||
public AjaxResult switchControl(@RequestBody DeviceBindDTO bindDTO) {
|
||||
if (StringUtils.isEmpty(bindDTO.getDeviceId())) {
|
||||
return AjaxResult.error("deviceId为空!");
|
||||
}
|
||||
if (StringUtils.isEmpty(bindDTO.getPlatform())) {
|
||||
return AjaxResult.error("平台为空!");
|
||||
}
|
||||
LoginUser user = getLoginUser();
|
||||
return AjaxResult.success(transferDeviceService.switchControl(bindDTO, user));
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放控制权
|
||||
*/
|
||||
@PostMapping("releaseControl")
|
||||
@ApiOperation("释放控制权")
|
||||
@Log(title = "释放控制权", businessType = BusinessType.OTHER)
|
||||
public AjaxResult releaseControl(@RequestBody DeviceBindDTO bindDTO) {
|
||||
if (StringUtils.isEmpty(bindDTO.getPlatform())) {
|
||||
return AjaxResult.error("平台为空!");
|
||||
}
|
||||
LoginUser user = getLoginUser();
|
||||
transferDeviceService.releaseControl(bindDTO, user);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user