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
102 lines
3.6 KiB
package com.iflytop.gd.app.service;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.iflytop.gd.app.mapper.DeviceParamConfigMapper;
|
|
import com.iflytop.gd.app.model.entity.DeviceParamConfig;
|
|
import com.iflytop.gd.app.model.vo.DeviceParamGroupVO;
|
|
import com.iflytop.gd.app.model.vo.ModuleIdVO;
|
|
import com.iflytop.gd.app.model.vo.RegIndexVO;
|
|
import com.iflytop.gd.infrastructure.drivers.ModuleId;
|
|
import com.iflytop.gd.infrastructure.drivers.RegIndex;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* 设备参数配置服务
|
|
*/
|
|
@Service
|
|
@RequiredArgsConstructor
|
|
public class DeviceParamConfigService extends ServiceImpl<DeviceParamConfigMapper, DeviceParamConfig> {
|
|
private final DeviceParamConfigMapper deviceParamConfigMapper;
|
|
|
|
/**
|
|
* 按 ModuleId 分组,列出每个模块下的 regIndex + regVal
|
|
*/
|
|
public List<DeviceParamGroupVO> listGroupedByModule() {
|
|
// 拉取所有配置记录
|
|
List<DeviceParamConfig> all = this.list();
|
|
|
|
// 按 mid 分组
|
|
Map<String, List<DeviceParamConfig>> grouped = all.stream()
|
|
.collect(Collectors.groupingBy(DeviceParamConfig::getMid));
|
|
|
|
// 构造 VO 列表
|
|
return grouped.entrySet().stream()
|
|
.map(entry -> {
|
|
String moduleId = entry.getKey();
|
|
List<DeviceParamGroupVO.ParamItem> items = entry.getValue().stream()
|
|
.map(cfg -> new DeviceParamGroupVO.ParamItem(
|
|
cfg.getRegIndex(),
|
|
cfg.getRegVal()
|
|
))
|
|
.collect(Collectors.toList());
|
|
return new DeviceParamGroupVO(moduleId, items);
|
|
})
|
|
.collect(Collectors.toList());
|
|
}
|
|
|
|
/**
|
|
* 根据模块标识和寄存器索引查询设备参数配置
|
|
*
|
|
* @param moduleId 模块枚举
|
|
* @param regIndex 寄存器索引
|
|
* @return 唯一匹配的 DeviceParamConfig,找不到返回 null
|
|
*/
|
|
public DeviceParamConfig getByModuleAndReg(ModuleId moduleId, RegIndex regIndex) {
|
|
return deviceParamConfigMapper.selectOne(
|
|
new LambdaQueryWrapper<DeviceParamConfig>()
|
|
.eq(DeviceParamConfig::getMid, moduleId.name())
|
|
.eq(DeviceParamConfig::getRegIndex, regIndex.name())
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 列出所有 ModuleId,返回 VO 列表
|
|
*
|
|
* @return List<ModuleIdVO>
|
|
*/
|
|
public List<ModuleIdVO> listAllModuleIds() {
|
|
return Arrays.stream(ModuleId.values())
|
|
.map(e -> new ModuleIdVO(
|
|
e.name(), // 枚举常量名
|
|
e.name // 描述字段
|
|
))
|
|
.collect(Collectors.toList());
|
|
}
|
|
|
|
/**
|
|
* 列出所有寄存器索引枚举,返回 VO 列表
|
|
*
|
|
* @return List<RegIndexVO>
|
|
*/
|
|
public List<RegIndexVO> listAllRegIndices() {
|
|
return Arrays.stream(RegIndex.values())
|
|
.map(e -> new RegIndexVO(
|
|
e.name() // 枚举常量名
|
|
))
|
|
.collect(Collectors.toList());
|
|
}
|
|
|
|
public boolean deleteDeviceParam(String idsStr) {
|
|
List<Long> ids = Arrays.stream(idsStr.split(","))
|
|
.map(Long::parseLong)
|
|
.collect(Collectors.toList());
|
|
return this.removeByIds(ids);
|
|
}
|
|
}
|