石墨消解仪后端服务
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.

102 lines
3.6 KiB

  1. package com.iflytop.gd.app.service;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4. import com.iflytop.gd.app.mapper.DeviceParamConfigMapper;
  5. import com.iflytop.gd.app.model.entity.DeviceParamConfig;
  6. import com.iflytop.gd.app.model.vo.DeviceParamGroupVO;
  7. import com.iflytop.gd.app.model.vo.ModuleIdVO;
  8. import com.iflytop.gd.app.model.vo.RegIndexVO;
  9. import com.iflytop.gd.infrastructure.drivers.ModuleId;
  10. import com.iflytop.gd.infrastructure.drivers.RegIndex;
  11. import lombok.RequiredArgsConstructor;
  12. import org.springframework.stereotype.Service;
  13. import java.util.Arrays;
  14. import java.util.List;
  15. import java.util.Map;
  16. import java.util.stream.Collectors;
  17. /**
  18. * 设备参数配置服务
  19. */
  20. @Service
  21. @RequiredArgsConstructor
  22. public class DeviceParamConfigService extends ServiceImpl<DeviceParamConfigMapper, DeviceParamConfig> {
  23. private final DeviceParamConfigMapper deviceParamConfigMapper;
  24. /**
  25. * ModuleId 分组列出每个模块下的 regIndex + regVal
  26. */
  27. public List<DeviceParamGroupVO> listGroupedByModule() {
  28. // 拉取所有配置记录
  29. List<DeviceParamConfig> all = this.list();
  30. // 按 mid 分组
  31. Map<String, List<DeviceParamConfig>> grouped = all.stream()
  32. .collect(Collectors.groupingBy(DeviceParamConfig::getMid));
  33. // 构造 VO 列表
  34. return grouped.entrySet().stream()
  35. .map(entry -> {
  36. String moduleId = entry.getKey();
  37. List<DeviceParamGroupVO.ParamItem> items = entry.getValue().stream()
  38. .map(cfg -> new DeviceParamGroupVO.ParamItem(
  39. cfg.getRegIndex(),
  40. cfg.getRegVal()
  41. ))
  42. .collect(Collectors.toList());
  43. return new DeviceParamGroupVO(moduleId, items);
  44. })
  45. .collect(Collectors.toList());
  46. }
  47. /**
  48. * 根据模块标识和寄存器索引查询设备参数配置
  49. *
  50. * @param moduleId 模块枚举
  51. * @param regIndex 寄存器索引
  52. * @return 唯一匹配的 DeviceParamConfig找不到返回 null
  53. */
  54. public DeviceParamConfig getByModuleAndReg(ModuleId moduleId, RegIndex regIndex) {
  55. return deviceParamConfigMapper.selectOne(
  56. new LambdaQueryWrapper<DeviceParamConfig>()
  57. .eq(DeviceParamConfig::getMid, moduleId.name())
  58. .eq(DeviceParamConfig::getRegIndex, regIndex.name())
  59. );
  60. }
  61. /**
  62. * 列出所有 ModuleId返回 VO 列表
  63. *
  64. * @return List<ModuleIdVO>
  65. */
  66. public List<ModuleIdVO> listAllModuleIds() {
  67. return Arrays.stream(ModuleId.values())
  68. .map(e -> new ModuleIdVO(
  69. e.name(), // 枚举常量名
  70. e.name // 描述字段
  71. ))
  72. .collect(Collectors.toList());
  73. }
  74. /**
  75. * 列出所有寄存器索引枚举返回 VO 列表
  76. *
  77. * @return List<RegIndexVO>
  78. */
  79. public List<RegIndexVO> listAllRegIndices() {
  80. return Arrays.stream(RegIndex.values())
  81. .map(e -> new RegIndexVO(
  82. e.name() // 枚举常量名
  83. ))
  84. .collect(Collectors.toList());
  85. }
  86. public boolean deleteDeviceParam(String idsStr) {
  87. List<Long> ids = Arrays.stream(idsStr.split(","))
  88. .map(Long::parseLong)
  89. .collect(Collectors.toList());
  90. return this.removeByIds(ids);
  91. }
  92. }