package com.moral.controller;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
import javax.annotation.Resource;
|
|
import com.moral.common.bean.ResultBean;
|
import com.moral.entity.DeviceVersion;
|
import com.moral.entity.layout.RealTimeDeviceLayout;
|
import com.moral.entity.layout.RtdLayoutUpload;
|
import com.moral.entity.layout.SensorComb;
|
import com.moral.service.DeviceVersionService;
|
import com.moral.service.OrganizationLayoutService;
|
import com.moral.service.SensorService;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
@RestController
|
@RequestMapping("org-layout")
|
public class OrganizationLayoutController {
|
@Resource
|
private OrganizationLayoutService organizationLayoutService;
|
@Resource
|
private SensorService sensorService;
|
@Resource
|
private DeviceVersionService deviceVersionService;
|
@GetMapping("rtd-config")
|
public ResultBean<Map<String,Object>> getRealTimeDevicetConfig(Integer orgId){
|
Map<String,Object> resultMap = new HashMap();
|
resultMap.put("deviceVersions",new ArrayList<>());
|
resultMap.put("sensorCombs", new ArrayList<>());
|
resultMap.put("sensors", new ArrayList<>());
|
resultMap.put("rtdLayout", new HashMap<>());
|
// 获取当前组织所含设备版本数组
|
List<DeviceVersion> deviceVersionList = deviceVersionService.queryByOrgId(orgId);
|
// 获取第一个version 下所有传感器
|
if (deviceVersionList!=null && deviceVersionList.size()>0) {
|
Integer versionId = deviceVersionList.get(0).getId();
|
Integer versionNum = deviceVersionList.get(0).getVersion();
|
// 转为 SensorComb 保持对象一致
|
List<String> fixedItemKeys = organizationLayoutService.getFixedItemKeys();
|
List<SensorComb> optionalFixedItems = new ArrayList<>();
|
List<SensorComb> sensorCombList = sensorService.queryListByVersionId(versionId)
|
.stream()
|
.filter(item -> {
|
for (String key: fixedItemKeys) {
|
if( key.equals(item.getSensorKey()) ) {
|
SensorComb sensorComb = new SensorComb();
|
sensorComb.setName(item.getDescription());
|
sensorComb.setSensorKey(item.getSensorKey());
|
optionalFixedItems.add(sensorComb);
|
return false;
|
}
|
}
|
return true;
|
})
|
.map(item -> {
|
SensorComb sensorComb = new SensorComb();
|
sensorComb.setName(item.getDescription());
|
sensorComb.setSensorKey(item.getSensorKey());
|
return sensorComb;
|
}).collect(Collectors.toList());
|
RealTimeDeviceLayout realTimeDeviceLayout = organizationLayoutService.queryRealTimeDeviceLayout(orgId,versionNum);
|
resultMap.put("deviceVersions",deviceVersionList);
|
resultMap.put("sensorCombs",sensorCombList);
|
resultMap.put("rtdLayout",realTimeDeviceLayout);
|
resultMap.put("optionalFixedItems",optionalFixedItems);
|
}
|
return new ResultBean<>(resultMap);
|
}
|
@GetMapping("rtd-act-config")
|
public ResultBean<Map<String,Object>> getRealTimeDeviceConfigWithVer(Integer orgId,Integer versionNo){
|
Map<String,Object> resultMap = new HashMap();
|
resultMap.put("sensors","");
|
resultMap.put("rtdLayout","");
|
// 转为 SensorComb 保持对象一致
|
List<String> fixedItemKeys = organizationLayoutService.getFixedItemKeys();
|
List<SensorComb> optionalFixedItems = new ArrayList<>();
|
List<SensorComb> sensorCombList = sensorService.queryListByVersionNo(versionNo)
|
.stream()
|
.filter(item -> {
|
for (String key: fixedItemKeys) {
|
if( key.equals(item.getSensorKey()) ) {
|
SensorComb sensorComb = new SensorComb();
|
sensorComb.setName(item.getDescription());
|
sensorComb.setSensorKey(item.getSensorKey());
|
optionalFixedItems.add(sensorComb);
|
return false;
|
}
|
}
|
return true;
|
})
|
.map(item -> {
|
SensorComb sensorComb = new SensorComb();
|
sensorComb.setName(item.getDescription());
|
sensorComb.setSensorKey(item.getSensorKey());
|
return sensorComb;
|
}).collect(Collectors.toList());
|
RealTimeDeviceLayout realTimeDeviceLayout = organizationLayoutService.queryRealTimeDeviceLayout(orgId,versionNo);
|
resultMap.put("sensorCombs",sensorCombList);
|
resultMap.put("rtdLayout",realTimeDeviceLayout);
|
resultMap.put("optionalFixedItems",optionalFixedItems); // 可显示固定项
|
return new ResultBean<>(resultMap);
|
}
|
@PostMapping("rtd-save")
|
public ResultBean RealTimeDeviceSave(@RequestBody RtdLayoutUpload rtdLayoutUpload) {
|
organizationLayoutService.saveRtdLayout(rtdLayoutUpload);
|
return ResultBean.success();
|
}
|
@GetMapping("rtd-remove")
|
public ResultBean RealTimeDeviceRemove(Integer orgId,Integer version) {
|
organizationLayoutService.deleteRtdLayout(orgId,version);
|
return ResultBean.success();
|
}
|
}
|