9 changed files with 375 additions and 146 deletions
-
122src/main/java/com/iflytop/handacid/app/controller/DeviceParamController.java
-
27src/main/java/com/iflytop/handacid/app/core/command/DeviceCommandGenerator.java
-
62src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java
-
11src/main/java/com/iflytop/handacid/common/model/bo/DeviceInitializationData.java
-
2src/main/java/com/iflytop/handacid/common/service/DeviceParamConfigService.java
-
43src/main/java/com/iflytop/handacid/hardware/controller/StepMotorController.java
-
2src/main/resources/application-dev.yml
-
14src/main/resources/sql/init.sql
@ -0,0 +1,122 @@ |
|||||
|
package com.iflytop.handacid.app.controller; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
|
import com.iflytop.handacid.common.model.entity.DeviceParamConfig; |
||||
|
import com.iflytop.handacid.common.model.vo.DeviceParamGroupVO; |
||||
|
import com.iflytop.handacid.common.model.vo.ModuleIdVO; |
||||
|
import com.iflytop.handacid.common.model.vo.RegIndexVO; |
||||
|
import com.iflytop.handacid.common.result.Result; |
||||
|
import com.iflytop.handacid.common.service.DeviceParamConfigService; |
||||
|
import io.swagger.v3.oas.annotations.Operation; |
||||
|
import io.swagger.v3.oas.annotations.Parameter; |
||||
|
import io.swagger.v3.oas.annotations.tags.Tag; |
||||
|
import jakarta.validation.Valid; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.http.MediaType; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
import org.springframework.web.multipart.MultipartFile; |
||||
|
|
||||
|
import java.io.BufferedReader; |
||||
|
import java.io.IOException; |
||||
|
import java.io.InputStreamReader; |
||||
|
import java.nio.charset.StandardCharsets; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 设备参数配置 |
||||
|
*/ |
||||
|
@Tag(name = "设备参数配置") |
||||
|
@RestController |
||||
|
@RequestMapping("/api/device-param") |
||||
|
@RequiredArgsConstructor |
||||
|
@Slf4j |
||||
|
public class DeviceParamController { |
||||
|
|
||||
|
private final DeviceParamConfigService deviceParamConfigService; |
||||
|
|
||||
|
@Operation(summary = "获取所有设备配置") |
||||
|
@GetMapping("/list") |
||||
|
public Result<List<DeviceParamGroupVO>> getList() { |
||||
|
List<DeviceParamGroupVO> vos = deviceParamConfigService.listGroupedByModule(); |
||||
|
return Result.success(vos); |
||||
|
} |
||||
|
|
||||
|
@Operation(summary = "获取所有设备模块") |
||||
|
@GetMapping("/modules") |
||||
|
public Result<List<ModuleIdVO>> listAllModules() { |
||||
|
List<ModuleIdVO> vos = deviceParamConfigService.listAllModuleIds(); |
||||
|
return Result.success(vos); |
||||
|
} |
||||
|
|
||||
|
@Operation(summary = "获取所有设备模块配置项") |
||||
|
@GetMapping("/reg-indices") |
||||
|
public Result<List<RegIndexVO>> listAllRegIndices() { |
||||
|
List<RegIndexVO> vos = deviceParamConfigService.listAllRegIndices(); |
||||
|
return Result.success(vos); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@Operation(summary = "添加新配置") |
||||
|
@PostMapping("") |
||||
|
public Result<String> add(@Valid @RequestBody DeviceParamConfig deviceParamConfig) { |
||||
|
deviceParamConfigService.save(deviceParamConfig); |
||||
|
return Result.success(); |
||||
|
} |
||||
|
|
||||
|
@Operation(summary = "修改配置") |
||||
|
@PutMapping("") |
||||
|
public Result<String> update(@Valid @RequestBody DeviceParamConfig deviceParamConfig) { |
||||
|
deviceParamConfigService.updateById(deviceParamConfig); |
||||
|
return Result.success(); |
||||
|
} |
||||
|
|
||||
|
@Operation(summary = "删除配置") |
||||
|
@DeleteMapping("/{ids}") |
||||
|
public Result<String> delete(@Parameter(description = "矿石ID,多个以英文逗号(,)分割") @PathVariable String ids) { |
||||
|
boolean isSuccess = deviceParamConfigService.deleteDeviceParam(ids); |
||||
|
if (isSuccess) { |
||||
|
return Result.success(); |
||||
|
} |
||||
|
return Result.failed(); |
||||
|
} |
||||
|
|
||||
|
@Operation(summary = "上传csv文件覆盖数据库配置") |
||||
|
@PostMapping(value = "/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
||||
|
public Result<String> uploadFile(@RequestPart("file") MultipartFile file) { |
||||
|
//文件后缀检查 |
||||
|
if (!file.getOriginalFilename().endsWith(".csv")) { |
||||
|
return Result.failed("<UNK>.csv<UNK>"); |
||||
|
} |
||||
|
try (BufferedReader reader = new BufferedReader( |
||||
|
new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) { |
||||
|
String line; |
||||
|
deviceParamConfigService.remove(new QueryWrapper<>());//删除所有配置 |
||||
|
//是否含有表头 |
||||
|
boolean isHeader = true; |
||||
|
List<DeviceParamConfig> deviceParamConfigList = new ArrayList<>(); |
||||
|
while ((line = reader.readLine()) != null) { |
||||
|
if (isHeader) { |
||||
|
isHeader = false; |
||||
|
continue; // 跳过CSV文件的标题行 |
||||
|
} |
||||
|
String[] data = line.split(","); |
||||
|
if (data.length >= 4) { // 假设CSV文件至少包含4列 |
||||
|
DeviceParamConfig deviceParamConfig = new DeviceParamConfig(); |
||||
|
deviceParamConfig.setId(Long.valueOf(data[0])); |
||||
|
deviceParamConfig.setMid(String.valueOf(data[1])); |
||||
|
deviceParamConfig.setRegIndex(String.valueOf(data[2])); |
||||
|
deviceParamConfig.setRegVal(Integer.valueOf(data[3])); |
||||
|
deviceParamConfigList.add(deviceParamConfig); |
||||
|
deviceParamConfigService.save(deviceParamConfig); |
||||
|
} |
||||
|
} |
||||
|
} catch (IOException e) { |
||||
|
log.error("csv文件导入数据库失败:{}", e.getMessage()); |
||||
|
throw new RuntimeException(e); |
||||
|
} |
||||
|
return Result.success(); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
package com.iflytop.handacid.common.model.bo; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Data |
||||
|
public class DeviceInitializationData { |
||||
|
private int id; |
||||
|
private String mid; |
||||
|
private String regIndex; |
||||
|
private int regInitVal; |
||||
|
} |
@ -1,4 +1,4 @@ |
|||||
package com.iflytop.handacid.app.service; |
|
||||
|
package com.iflytop.handacid.common.service; |
||||
|
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue