refactor 接口参数
parent
8e7c103494
commit
62fe672ec2
|
@ -133,15 +133,14 @@ public class DeviceController {
|
|||
|
||||
@ApiOperation("获取设备详情")
|
||||
@PostMapping(Constants.API_DEVICE.DETAIL)
|
||||
public DeviceInfo getDetail(@PathVariable("deviceId") String deviceId) {
|
||||
return deviceServiceImpl.getDetail(deviceId);
|
||||
public DeviceInfo getDetail(@PathVariable("deviceId") Request<String> deviceId) {
|
||||
return deviceServiceImpl.getDetail(deviceId.getData());
|
||||
}
|
||||
|
||||
@ApiOperation("获取设备详情")
|
||||
@PostMapping("/{pk}/{dn}")
|
||||
public DeviceInfo getByPkDn(@PathVariable("pk") String pk,
|
||||
@PathVariable("dn") String dn) {
|
||||
return deviceServiceImpl.getByPkDn(pk, dn);
|
||||
@PostMapping("/getByPkDn")
|
||||
public DeviceInfo getByPkDn(@Validated @RequestBody Request<DeviceQueryByPkDnBo> query) {
|
||||
return deviceServiceImpl.getByPkDn(query.getData().getPk(), query.getData().getDn());
|
||||
}
|
||||
|
||||
@ApiOperation("删除设备")
|
||||
|
@ -178,7 +177,7 @@ public class DeviceController {
|
|||
@PostMapping("/getThingModel")
|
||||
public ThingModelVo getThingModel(@Validated @RequestBody Request<String> request) {
|
||||
String deviceId = request.getData();
|
||||
DeviceInfo deviceInfo = getDetail(deviceId);
|
||||
DeviceInfo deviceInfo = deviceServiceImpl.getDetail(deviceId);
|
||||
return productService.getThingModelByProductKey(deviceInfo.getProductKey());
|
||||
}
|
||||
|
||||
|
@ -198,14 +197,12 @@ public class DeviceController {
|
|||
/**
|
||||
* 消费设备信息消息(实时推送设备信息)
|
||||
*/
|
||||
@PostMapping("/{deviceId}/consumer/{clientId}")
|
||||
@PostMapping("/consumer")
|
||||
public DeferredResult<ThingModelMessage> consumerDeviceInfo(
|
||||
@PathVariable("deviceId") String deviceId,
|
||||
@PathVariable("clientId") String clientId
|
||||
@Validated @RequestBody Request<DeviceConsumerBo> bo
|
||||
) {
|
||||
|
||||
return deviceServiceImpl.addConsumer(deviceId, clientId);
|
||||
|
||||
DeviceConsumerBo data = bo.getData();
|
||||
return deviceServiceImpl.addConsumer(data.getDeviceId(), data.getClientId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -298,8 +295,10 @@ public class DeviceController {
|
|||
/**
|
||||
* 设备配置下发
|
||||
*/
|
||||
@PostMapping("/config/{deviceId}/send")
|
||||
public InvokeResult sendConfig(@PathVariable("deviceId") String deviceId) {
|
||||
@ApiOperation(value = "设备配置下发")
|
||||
@PostMapping("/config/send")
|
||||
public InvokeResult sendConfig(@Validated @RequestBody Request<String> bo) {
|
||||
String deviceId = bo.getData();
|
||||
return new InvokeResult(deviceService.sendConfig(deviceId));
|
||||
}
|
||||
|
||||
|
|
|
@ -110,9 +110,9 @@ public class ProductController {
|
|||
@SaCheckRole("iot_admin")
|
||||
@ApiOperation("品类编辑")
|
||||
@PostMapping("/category/edit")
|
||||
public boolean saveCategory(@Validated @RequestBody CategoryBo req) {
|
||||
public boolean saveCategory(@Validated @RequestBody Request<CategoryBo> req) {
|
||||
|
||||
return productService.editCategory(req);
|
||||
return productService.editCategory(req.getData());
|
||||
}
|
||||
|
||||
@SaCheckRole("iot_admin")
|
||||
|
@ -131,13 +131,13 @@ public class ProductController {
|
|||
|
||||
@PostMapping("/getModelsByProductKey")
|
||||
@ApiModelProperty("获取产品型号")
|
||||
public List<ProductModelVo> getModels(String productKey) {
|
||||
return productService.getModels(productKey);
|
||||
public List<ProductModelVo> getModels(@Validated @RequestBody Request<String> bo) {
|
||||
return productService.getModels(bo.getData());
|
||||
}
|
||||
|
||||
@PostMapping("/productModel/edit")
|
||||
@ApiOperation("编辑产品型号")
|
||||
public boolean saveProductModel(ProductModelBo productModel) {
|
||||
return productService.editProductModel(productModel);
|
||||
public boolean saveProductModel(@Validated @RequestBody Request<ProductModelBo> bo) {
|
||||
return productService.editProductModel(bo.getData());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,14 +66,14 @@ public class ProtocolController {
|
|||
|
||||
@ApiOperation("添加组件")
|
||||
@PostMapping("/addComponent")
|
||||
public boolean addComponent(@RequestBody @Validated ProtocolComponentBo component) {
|
||||
return protocolService.addComponent(component);
|
||||
public boolean addComponent(@RequestBody @Validated Request<ProtocolComponentBo> bo) {
|
||||
return protocolService.addComponent(bo.getData());
|
||||
}
|
||||
|
||||
@ApiOperation("修改组件")
|
||||
@PostMapping("/editComponent")
|
||||
public String saveComponent(@RequestBody @Validated ProtocolComponentBo component) {
|
||||
return protocolService.saveComponent(component);
|
||||
public String saveComponent(@RequestBody @Validated Request<ProtocolComponentBo> bo) {
|
||||
return protocolService.saveComponent(bo.getData());
|
||||
}
|
||||
|
||||
@ApiOperation("获取组件详情")
|
||||
|
@ -87,8 +87,8 @@ public class ProtocolController {
|
|||
@ApiOperation("保存组件脚本")
|
||||
@PostMapping("/saveComponentScript")
|
||||
public boolean saveComponentScript(@Validated
|
||||
@RequestBody ProtocolComponentBo upReq) {
|
||||
return protocolService.saveComponentScript(upReq);
|
||||
@RequestBody Request<ProtocolComponentBo> upReq) {
|
||||
return protocolService.saveComponentScript(upReq.getData());
|
||||
}
|
||||
|
||||
|
||||
|
@ -113,15 +113,14 @@ public class ProtocolController {
|
|||
|
||||
@ApiOperation("新增转换脚本")
|
||||
@PostMapping("/converter/add")
|
||||
public boolean addConverter(@Validated @RequestBody ProtocolConverterBo converter) {
|
||||
return protocolService.addConverter(converter);
|
||||
|
||||
public boolean addConverter(@Validated @RequestBody Request<ProtocolConverterBo> converter) {
|
||||
return protocolService.addConverter(converter.getData());
|
||||
}
|
||||
|
||||
@ApiOperation("修改转换脚本")
|
||||
@PostMapping("/converter/edit")
|
||||
public boolean editConverter(ProtocolConverterBo req) {
|
||||
return protocolService.editConverter(req);
|
||||
public boolean editConverter(Request<ProtocolConverterBo> req) {
|
||||
return protocolService.editConverter(req.getData());
|
||||
}
|
||||
|
||||
|
||||
|
@ -138,9 +137,9 @@ public class ProtocolController {
|
|||
@PostMapping("/converterScript/edit")
|
||||
@ApiOperation("保存转换脚本")
|
||||
public boolean saveConverterScript(
|
||||
@Validated @RequestBody ProtocolConverterBo req) {
|
||||
@Validated @RequestBody Request<ProtocolConverterBo> req) {
|
||||
|
||||
return protocolService.saveConverterScript(req);
|
||||
return protocolService.saveConverterScript(req.getData());
|
||||
}
|
||||
|
||||
@PostMapping("/converter/delete")
|
||||
|
@ -152,8 +151,8 @@ public class ProtocolController {
|
|||
|
||||
@PostMapping("/component/changeState}")
|
||||
@ApiOperation("组件启用/禁用")
|
||||
public boolean changeComponentState(@RequestBody @Validated ChangeStateBo req) {
|
||||
return protocolService.changeComponentState(req);
|
||||
public boolean changeComponentState(@RequestBody @Validated Request<ChangeStateBo> req) {
|
||||
return protocolService.changeComponentState(req.getData());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,8 +69,8 @@ public class RuleEngineController {
|
|||
|
||||
@ApiOperation("规则编辑")
|
||||
@PostMapping("/edit")
|
||||
public boolean saveRule(@RequestBody @Validated RuleInfoBo ruleInfoBo) {
|
||||
return ruleEngineService.saveRule(ruleInfoBo);
|
||||
public boolean saveRule(@RequestBody @Validated Request<RuleInfoBo> ruleInfoBo) {
|
||||
return ruleEngineService.saveRule(ruleInfoBo.getData());
|
||||
|
||||
}
|
||||
|
||||
|
@ -120,8 +120,8 @@ public class RuleEngineController {
|
|||
|
||||
@ApiOperation("定时任务编辑")
|
||||
@PostMapping("/task/save")
|
||||
public boolean saveTask(@Validated @RequestBody TaskInfoBo taskInfo) {
|
||||
return ruleEngineService.saveTask(taskInfo);
|
||||
public boolean saveTask(@Validated @RequestBody Request<TaskInfoBo> taskInfo) {
|
||||
return ruleEngineService.saveTask(taskInfo.getData());
|
||||
}
|
||||
|
||||
@ApiOperation("停止定时任务")
|
||||
|
|
|
@ -10,11 +10,16 @@
|
|||
package cc.iotkit.manager.controller;
|
||||
|
||||
import cc.iotkit.common.api.PageRequest;
|
||||
import cc.iotkit.common.api.Request;
|
||||
import cc.iotkit.common.enums.ErrCode;
|
||||
import cc.iotkit.common.exception.BizException;
|
||||
import cc.iotkit.common.satoken.utils.AuthUtil;
|
||||
import cc.iotkit.common.utils.ReflectUtil;
|
||||
import cc.iotkit.data.manager.IVirtualDeviceData;
|
||||
import cc.iotkit.manager.dto.bo.ChangeStateBo;
|
||||
import cc.iotkit.manager.dto.bo.device.DeviceLogQueryBo;
|
||||
import cc.iotkit.manager.dto.bo.device.DeviceSaveScriptBo;
|
||||
import cc.iotkit.manager.dto.bo.virtualdevice.VirtualSaveDevicesBo;
|
||||
import cc.iotkit.manager.service.DataOwnerService;
|
||||
import cc.iotkit.common.api.Paging;
|
||||
import cc.iotkit.model.device.VirtualDevice;
|
||||
|
@ -23,8 +28,10 @@ import cc.iotkit.model.product.Product;
|
|||
import cc.iotkit.temporal.IVirtualDeviceLogData;
|
||||
import cc.iotkit.virtualdevice.VirtualManager;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -44,7 +51,9 @@ public class VirtualDeviceController {
|
|||
@Autowired
|
||||
private IVirtualDeviceLogData virtualDeviceLogData;
|
||||
|
||||
@PostMapping("/list/{size}/{page}")
|
||||
|
||||
@ApiOperation("获取虚拟设备列表")
|
||||
@PostMapping("/list")
|
||||
public Paging<VirtualDevice> getDevices(
|
||||
PageRequest<VirtualDevice> pageRequest) {
|
||||
String uid = AuthUtil.getUserId();
|
||||
|
@ -58,6 +67,7 @@ public class VirtualDeviceController {
|
|||
/**
|
||||
* 添加虚拟设备
|
||||
*/
|
||||
@ApiOperation("添加虚拟设备")
|
||||
@PostMapping("/add")
|
||||
public void add(VirtualDevice virtualDevice) {
|
||||
virtualDevice.setId(null);
|
||||
|
@ -70,8 +80,10 @@ public class VirtualDeviceController {
|
|||
/**
|
||||
* 修改虚拟设备
|
||||
*/
|
||||
@ApiOperation("修改虚拟设备")
|
||||
@PostMapping("/modify")
|
||||
public void modify(VirtualDevice virtualDevice) {
|
||||
public void modify(Request<VirtualDevice> bo) {
|
||||
VirtualDevice virtualDevice = bo.getData();
|
||||
VirtualDevice oldData = checkOwner(virtualDevice.getId());
|
||||
ReflectUtil.copyNoNulls(virtualDevice, oldData,
|
||||
"name", "productKey", "type", "trigger", "triggerExpression");
|
||||
|
@ -82,16 +94,21 @@ public class VirtualDeviceController {
|
|||
/**
|
||||
* 获取虚拟设备详情
|
||||
*/
|
||||
@GetMapping("/{id}/detail")
|
||||
public VirtualDevice detail(@PathVariable("id") String id) {
|
||||
return checkOwner(id);
|
||||
@ApiOperation("获取虚拟设备详情")
|
||||
@GetMapping("/getDetail")
|
||||
public VirtualDevice detail(@Validated @RequestBody Request<String> bo) {
|
||||
return checkOwner(bo.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置虚拟设备状态
|
||||
*/
|
||||
@PostMapping("/{id}/setState")
|
||||
public void setState(@PathVariable("id") String id, String state) {
|
||||
@ApiOperation("设置虚拟设备状态")
|
||||
@PostMapping("/setState")
|
||||
public void setState(@Validated @RequestBody Request<ChangeStateBo> bo) {
|
||||
ChangeStateBo data = bo.getData();
|
||||
String id = data.getId();
|
||||
String state = data.getState();
|
||||
VirtualDevice oldData = checkOwner(id);
|
||||
if (!VirtualDevice.STATE_RUNNING.equals(state)
|
||||
&& !VirtualDevice.STATE_STOPPED.equals(state)) {
|
||||
|
@ -109,8 +126,10 @@ public class VirtualDeviceController {
|
|||
/**
|
||||
* 删除
|
||||
*/
|
||||
@DeleteMapping("/{id}/delete")
|
||||
public void delete(@PathVariable("id") String id) {
|
||||
@ApiOperation("删除虚拟设备")
|
||||
@DeleteMapping("/delete")
|
||||
public void delete(@Validated @RequestBody Request<String> bo) {
|
||||
String id = bo.getData();
|
||||
checkOwner(id);
|
||||
virtualDeviceData.deleteById(id);
|
||||
}
|
||||
|
@ -118,8 +137,12 @@ public class VirtualDeviceController {
|
|||
/**
|
||||
* 保存脚本
|
||||
*/
|
||||
@PostMapping("/{id}/saveScript")
|
||||
public void saveScript(@PathVariable("id") String id, String script) {
|
||||
@ApiOperation("保存脚本")
|
||||
@PostMapping("/saveScript")
|
||||
public void saveScript(@Validated @RequestBody Request<DeviceSaveScriptBo> bo) {
|
||||
DeviceSaveScriptBo data = bo.getData();
|
||||
String id = data.getId();
|
||||
String script = data.getScript();
|
||||
VirtualDevice old = checkOwner(id);
|
||||
old.setScript(script);
|
||||
virtualDeviceData.save(old);
|
||||
|
@ -128,8 +151,12 @@ public class VirtualDeviceController {
|
|||
/**
|
||||
* 保存关联设备
|
||||
*/
|
||||
@PostMapping("/{id}/saveDevices")
|
||||
public void saveDevices(@PathVariable("id") String id, @RequestBody List<String> devices) {
|
||||
@ApiOperation("保存关联设备")
|
||||
@PostMapping("/saveDevices")
|
||||
public void saveDevices(@Validated @RequestBody Request<VirtualSaveDevicesBo> bo) {
|
||||
VirtualSaveDevicesBo data = bo.getData();
|
||||
List<String> devices = data.getDevices();
|
||||
String id = data.getId();
|
||||
VirtualDevice old = checkOwner(id);
|
||||
old.setDevices(devices);
|
||||
virtualDeviceData.save(old);
|
||||
|
@ -138,8 +165,10 @@ public class VirtualDeviceController {
|
|||
/**
|
||||
* 手动执行虚拟设备
|
||||
*/
|
||||
@PostMapping("/{id}/run")
|
||||
public void run(@PathVariable("id") String id) {
|
||||
@ApiOperation("手动执行虚拟设备")
|
||||
@PostMapping("/run")
|
||||
public void run(@Validated @RequestBody Request<String> bo) {
|
||||
String id = bo.getData();
|
||||
VirtualDevice virtualDevice = checkOwner(id);
|
||||
virtualManager.run(virtualDevice);
|
||||
}
|
||||
|
@ -147,15 +176,16 @@ public class VirtualDeviceController {
|
|||
/**
|
||||
* 取虚拟设备执行日志
|
||||
*/
|
||||
@PostMapping("/{id}/logs/{size}/{page}")
|
||||
@ApiOperation("取虚拟设备执行日志")
|
||||
@PostMapping("/logs/list")
|
||||
public Paging<VirtualDeviceLog> getLogs(
|
||||
@PathVariable("id") String id,
|
||||
@PathVariable("size") int size,
|
||||
@PathVariable("page") int page
|
||||
) {
|
||||
return virtualDeviceLogData.findByVirtualDeviceId(id, page, size);
|
||||
@Validated @RequestBody PageRequest<DeviceLogQueryBo> bo) {
|
||||
DeviceLogQueryBo data = bo.getData();
|
||||
|
||||
return virtualDeviceLogData.findByVirtualDeviceId(data.getDeviceId(), bo.getPageNum(), bo.getPageSize());
|
||||
}
|
||||
|
||||
|
||||
private VirtualDevice checkOwner(String id) {
|
||||
VirtualDevice oldData = virtualDeviceData.findById(id);
|
||||
if (oldData == null) {
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package cc.iotkit.manager.dto.bo.device;
|
||||
|
||||
import cc.iotkit.common.api.BaseDto;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
|
||||
@ApiModel(value = "DeviceConsumerBo")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class DeviceConsumerBo extends BaseDto {
|
||||
|
||||
private static final long serialVersionUID = -1L;
|
||||
|
||||
@NotBlank(message = "deviceId不能为空")
|
||||
@ApiModelProperty(value = "设备id")
|
||||
private String deviceId;
|
||||
|
||||
@NotBlank(message = "clientId不能为空")
|
||||
@ApiModelProperty(value = "clientId")
|
||||
private String clientId;
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package cc.iotkit.manager.dto.bo.device;
|
||||
|
||||
import cc.iotkit.common.api.BaseDto;
|
||||
import io.github.linpeilie.annotations.AutoMapping;
|
||||
import io.github.linpeilie.annotations.ReverseAutoMapping;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
|
||||
@ApiModel(value = "DeviceQueryByPkDnBo")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class DeviceQueryByPkDnBo extends BaseDto {
|
||||
|
||||
private static final long serialVersionUID = -1L;
|
||||
|
||||
@NotBlank(message = "产品key不能为空")
|
||||
@ApiModelProperty(value = "产品key")
|
||||
private String pk;
|
||||
|
||||
@NotBlank(message = "设备不能为空")
|
||||
@ApiModelProperty(value = "设备")
|
||||
private String dn;
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package cc.iotkit.manager.dto.bo.device;
|
||||
|
||||
import cc.iotkit.common.api.BaseDto;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
|
||||
@ApiModel(value = "DeviceSaveScriptBo")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class DeviceSaveScriptBo extends BaseDto {
|
||||
|
||||
private static final long serialVersionUID = -1L;
|
||||
|
||||
@NotBlank(message = "id不能为空")
|
||||
@ApiModelProperty(value = "id")
|
||||
private String id;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "脚本")
|
||||
private String script;
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package cc.iotkit.manager.dto.bo.virtualdevice;
|
||||
|
||||
import cc.iotkit.common.api.BaseDto;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@ApiModel(value = "VirtualSaveDevicesBo")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class VirtualSaveDevicesBo extends BaseDto {
|
||||
|
||||
private static final long serialVersionUID = -1L;
|
||||
|
||||
@NotBlank(message = "id不能为空")
|
||||
@ApiModelProperty(value = "id")
|
||||
private String id;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "设备id列表")
|
||||
private List<String> devices;
|
||||
|
||||
}
|
Loading…
Reference in New Issue