You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.4 KiB
93 lines
3.4 KiB
package com.qyft.ms.device.controller;
|
|
|
|
import com.qyft.ms.device.model.bo.DeviceCtrlFuncCMD;
|
|
import com.qyft.ms.device.model.entity.CtrlFunc;
|
|
import com.qyft.ms.device.model.form.CtrlFuncForm;
|
|
import com.qyft.ms.device.model.vo.DeviceCtrlFuncVO;
|
|
import com.qyft.ms.device.service.ICtrlFuncService;
|
|
import com.qyft.ms.system.common.result.Result;
|
|
import com.qyft.ms.system.common.result.ResultCode;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
@Tag(name = "设备控制")
|
|
@RestController
|
|
@RequestMapping("/api/device")
|
|
@RequiredArgsConstructor
|
|
@Slf4j
|
|
public class DeviceCtrlController {
|
|
private final ICtrlFuncService ctrlFuncService;
|
|
|
|
@Operation(summary = "获取所有设备控制方法步骤")
|
|
@GetMapping("/ctrl/step")
|
|
public Result<List<DeviceCtrlFuncCMD>> getAllCtrlFuncStep() {
|
|
List<DeviceCtrlFuncCMD> ctrlFuncList = ctrlFuncService.findAllStepCMD();
|
|
return Result.success(ctrlFuncList);
|
|
}
|
|
|
|
@Operation(summary = "获取所有设备控制方法")
|
|
@GetMapping("/ctrl")
|
|
public Result<List<CtrlFunc>> getAllCtrlFunc() {
|
|
List<CtrlFunc> ctrlFuncList = ctrlFuncService.findAll();
|
|
return Result.success(ctrlFuncList);
|
|
}
|
|
|
|
@Operation(summary = "根据id获取设备控制方法与步骤")
|
|
@GetMapping("/ctrl/{id}")
|
|
public Result<DeviceCtrlFuncVO> getById(@PathVariable Long id) {
|
|
DeviceCtrlFuncVO ctrlFuncVO = ctrlFuncService.findVOById(id);
|
|
return Result.success(ctrlFuncVO);
|
|
}
|
|
|
|
@Operation(summary = "添加设备控制方法与步骤")
|
|
@PostMapping("/ctrl")
|
|
public Result<String> addCtrlFunc(@RequestBody CtrlFuncForm ctrlFuncForm) {
|
|
long count = ctrlFuncService.countFuncCmdByFuncCmd(ctrlFuncForm.getFuncCmd());
|
|
if (count > 0) {
|
|
return Result.failed(ResultCode.DATA_ALREADY_EXISTS);
|
|
|
|
}
|
|
boolean isSuccess = ctrlFuncService.addCtrlFunc(ctrlFuncForm);
|
|
if (isSuccess) {
|
|
return Result.success();
|
|
}
|
|
return Result.failed();
|
|
}
|
|
|
|
@Operation(summary = "更新设备控制方法与步骤")
|
|
@PutMapping("/ctrl/{id}")
|
|
public Result<String> updateCtrlFunc(@PathVariable Long id, @RequestBody CtrlFuncForm ctrlFuncForm) {
|
|
CtrlFunc currentCtrlFunc = ctrlFuncService.getById(id);
|
|
if (currentCtrlFunc != null && !currentCtrlFunc.getFuncCmd().equals(ctrlFuncForm.getFuncCmd())) {
|
|
//改了指令需要判断指令是否重复
|
|
long count = ctrlFuncService.countFuncCmdByFuncCmd(ctrlFuncForm.getFuncCmd());
|
|
if (count > 0) {
|
|
return Result.failed(ResultCode.DATA_ALREADY_EXISTS);
|
|
}
|
|
}
|
|
boolean isSuccess = ctrlFuncService.updateCtrlFunc(id, ctrlFuncForm);
|
|
if (isSuccess) {
|
|
return Result.success();
|
|
}
|
|
|
|
return Result.failed();
|
|
}
|
|
|
|
@Operation(summary = "删除设备控制方法")
|
|
@DeleteMapping("/ctrl/{ids}")
|
|
public Result<String> deleteCtrlFunc(@Parameter(description = "设备控制方法ID,多个以英文逗号(,)分割") @PathVariable String ids) {
|
|
boolean isSuccess = ctrlFuncService.deleteCtrlFunc(ids);
|
|
if (isSuccess) {
|
|
return Result.success();
|
|
}
|
|
return Result.failed();
|
|
}
|
|
|
|
|
|
}
|