|
@@ -19,9 +19,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.LinkedList;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class ConfigService {
|
|
@@ -36,14 +35,25 @@ public class ConfigService {
|
|
|
pageParam.setCreateUserId(null);
|
|
|
}
|
|
|
List<ConfigVO> list = configMapper.getConfigPageList(pageParam);
|
|
|
+ //传感器数量
|
|
|
+ list.forEach(configVO -> {
|
|
|
+ List<ConfigSensorVO> sensorList = configMapper.getConfigSensors(configVO);
|
|
|
+ Map<String, List<ConfigSensorVO>> configSensors = sensorList.stream().collect(Collectors.groupingBy(ConfigSensorVO::getSensorType));
|
|
|
+ Map<String,String> sensorCount = new HashMap<>();
|
|
|
+ configSensors.forEach((sensorType,configSensorVOs)->{
|
|
|
+ sensorCount.put(sensorType,String.valueOf(configSensorVOs.size()));
|
|
|
+ });
|
|
|
+ configVO.setSensorCount(sensorCount);
|
|
|
+ });
|
|
|
return new PageInfo<>(list);
|
|
|
}
|
|
|
|
|
|
- public ConfigVO getConfigInfo(ConfigPageParam pageParam) {
|
|
|
- ConfigVO ConfigvehicleVO = configMapper.getConfigInfo(pageParam);
|
|
|
- List<ConfigSensorVO> configSensors = configMapper.getConfigSensors(pageParam);
|
|
|
- ConfigvehicleVO.setConfigSensors(configSensors);
|
|
|
- return ConfigvehicleVO;
|
|
|
+ public ConfigVO getConfigInfo(ConfigVO configVO) {
|
|
|
+ configVO = configMapper.getConfigInfo(configVO);
|
|
|
+ List<ConfigSensorVO> sensorList = configMapper.getConfigSensors(configVO);
|
|
|
+ Map<String, List<ConfigSensorVO>> configSensors = sensorList.stream().collect(Collectors.groupingBy(ConfigSensorVO::getSensorType));
|
|
|
+ configVO.setConfigSensors(configSensors);
|
|
|
+ return configVO;
|
|
|
}
|
|
|
|
|
|
public ConfigPO saveConfig(ConfigVO configVO) {
|
|
@@ -57,6 +67,7 @@ public class ConfigService {
|
|
|
configPO.setModifyUserId(currentUserId);
|
|
|
configPO.setModifyTime(currentTime);
|
|
|
configPO.setIsDeleted(DictConstants.NO);
|
|
|
+ configPO.setShare(DictConstants.NO);//私有
|
|
|
//单独处理配置描述
|
|
|
configPO.setDescription(configVO.getConfigDescription());
|
|
|
//名称校验
|
|
@@ -71,7 +82,6 @@ public class ConfigService {
|
|
|
configId = StringUtil.getRandomUUID();
|
|
|
configPO.setId(configId);
|
|
|
configPO.setConfigCode(StringUtil.getRandomCode());
|
|
|
- configPO.setShare(DictConstants.NO);//私有
|
|
|
configMapper.insertConfig(configPO);
|
|
|
}else{//修改
|
|
|
configMapper.updateConfig(configPO);
|
|
@@ -79,21 +89,26 @@ public class ConfigService {
|
|
|
//删除子表旧数据
|
|
|
configMapper.delConfigSensors(configPO);
|
|
|
//构建字表新数据
|
|
|
- List<ConfigSensorVO> configSensorVOs = configVO.getConfigSensors();
|
|
|
+ //List<ConfigSensorVO> configSensorVOs = configVO.getConfigSensors();
|
|
|
+ Map<String, List<ConfigSensorVO>> configSensors = configVO.getConfigSensors();
|
|
|
List<ConfigSensorPO> configSensorPOs = new ArrayList<>();
|
|
|
- if(ObjectUtil.isNotNull(configSensorVOs)){
|
|
|
- configSensorVOs.forEach(vo -> {
|
|
|
- ConfigSensorPO po = new ConfigSensorPO();
|
|
|
- ObjectUtil.voToPo(vo,po);
|
|
|
- po.setId(StringUtil.getRandomUUID());
|
|
|
- //子表外键
|
|
|
- po.setConfigId(configPO.getId());
|
|
|
- po.setCreateUserId(currentUserId);
|
|
|
- po.setCreateTime(currentTime);
|
|
|
- po.setModifyUserId(currentUserId);
|
|
|
- po.setModifyTime(currentTime);
|
|
|
- po.setIsDeleted(DictConstants.NO);
|
|
|
- configSensorPOs.add(po);
|
|
|
+ if(ObjectUtil.isNotNull(configSensors)){
|
|
|
+ configSensors.forEach((sensorType,configSensorVOs)->{
|
|
|
+ if(ObjectUtil.isNotNull(configSensorVOs)){
|
|
|
+ configSensorVOs.forEach(vo -> {
|
|
|
+ ConfigSensorPO po = new ConfigSensorPO();
|
|
|
+ ObjectUtil.voToPo(vo,po);
|
|
|
+ po.setId(StringUtil.getRandomUUID());
|
|
|
+ //子表外键
|
|
|
+ po.setConfigId(configPO.getId());
|
|
|
+ po.setCreateUserId(currentUserId);
|
|
|
+ po.setCreateTime(currentTime);
|
|
|
+ po.setModifyUserId(currentUserId);
|
|
|
+ po.setModifyTime(currentTime);
|
|
|
+ po.setIsDeleted(DictConstants.NO);
|
|
|
+ configSensorPOs.add(po);
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
if(ObjectUtil.isNotNull(configSensorPOs)){
|
|
@@ -111,4 +126,66 @@ public class ConfigService {
|
|
|
int i = configMapper.delConfigById(po);
|
|
|
return i;
|
|
|
}
|
|
|
+
|
|
|
+ public ConfigPO shareConfigByInfo(ConfigVO configVO) {
|
|
|
+ //构建主表对象
|
|
|
+ ConfigPO configPO = new ConfigPO();
|
|
|
+ ObjectUtil.voToPo(configVO,configPO);
|
|
|
+ configPO.setShare(DictConstants.YES);//转公有
|
|
|
+ configPO.setCreateUserId(null);
|
|
|
+ //名称校验
|
|
|
+ List<ConfigVO> list = configMapper.checkConfigName(configPO);
|
|
|
+ if(ObjectUtil.isNotNull(list)){
|
|
|
+ configPO.setId(null);
|
|
|
+ return configPO;
|
|
|
+ }
|
|
|
+ String currentUserId = AuthUtil.getCurrentUserId();
|
|
|
+ Timestamp currentTime = TimeUtil.getNowForMysql();
|
|
|
+ configPO.setCreateUserId(currentUserId);
|
|
|
+ configPO.setCreateTime(currentTime);
|
|
|
+ configPO.setModifyUserId(currentUserId);
|
|
|
+ configPO.setModifyTime(currentTime);
|
|
|
+ configPO.setIsDeleted(DictConstants.NO);
|
|
|
+ //单独处理配置描述
|
|
|
+ configPO.setDescription(configVO.getConfigDescription());
|
|
|
+ //主表主键
|
|
|
+ String configId = StringUtil.getRandomUUID();
|
|
|
+ configPO.setId(configId);
|
|
|
+ configPO.setConfigCode(StringUtil.getRandomCode());
|
|
|
+ configMapper.insertConfig(configPO);
|
|
|
+ //删除子表旧数据
|
|
|
+ configMapper.delConfigSensors(configPO);
|
|
|
+ //构建字表新数据
|
|
|
+ Map<String, List<ConfigSensorVO>> configSensors = configVO.getConfigSensors();
|
|
|
+ List<ConfigSensorPO> configSensorPOs = new ArrayList<>();
|
|
|
+ if(ObjectUtil.isNotNull(configSensors)){
|
|
|
+ configSensors.forEach((sensorType,configSensorVOs)->{
|
|
|
+ if(ObjectUtil.isNotNull(configSensorVOs)){
|
|
|
+ configSensorVOs.forEach(vo -> {
|
|
|
+ ConfigSensorPO po = new ConfigSensorPO();
|
|
|
+ ObjectUtil.voToPo(vo,po);
|
|
|
+ po.setId(StringUtil.getRandomUUID());
|
|
|
+ //子表外键
|
|
|
+ po.setConfigId(configPO.getId());
|
|
|
+ po.setCreateUserId(currentUserId);
|
|
|
+ po.setCreateTime(currentTime);
|
|
|
+ po.setModifyUserId(currentUserId);
|
|
|
+ po.setModifyTime(currentTime);
|
|
|
+ po.setIsDeleted(DictConstants.NO);
|
|
|
+ configSensorPOs.add(po);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNotNull(configSensorPOs)){
|
|
|
+ configMapper.insertConfigSensors(configSensorPOs);
|
|
|
+ }
|
|
|
+ return configPO;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ConfigPO shareConfigById(ConfigVO configVO) {
|
|
|
+ configVO = getConfigInfo(configVO);
|
|
|
+ ConfigPO configPO = shareConfigByInfo(configVO);
|
|
|
+ return configPO;
|
|
|
+ }
|
|
|
}
|