|
|
@@ -7,8 +7,14 @@ import com.usky.common.core.bean.CommonPage;
|
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
import com.usky.sas.domain.SasMapDevice;
|
|
|
import com.usky.sas.domain.SasMaps;
|
|
|
+import com.usky.sas.domain.SasDevice;
|
|
|
+import com.usky.sas.domain.SasPic;
|
|
|
+import com.usky.sas.enums.SystemTypeCodeEnum;
|
|
|
import com.usky.sas.mapper.SasMapDeviceMapper;
|
|
|
import com.usky.sas.mapper.SasMapsMapper;
|
|
|
+import com.usky.sas.mapper.SasPicMapper;
|
|
|
+import com.usky.sas.mapper.SasDeviceMapper;
|
|
|
+import com.usky.sas.common.util.GetIpUtils;
|
|
|
import com.usky.sas.service.SasMapService;
|
|
|
import com.usky.sas.service.vo.MapDeviceBindRequest;
|
|
|
import com.usky.sas.service.vo.MapListItem;
|
|
|
@@ -16,7 +22,10 @@ import com.usky.sas.service.vo.MapPageRequest;
|
|
|
import com.usky.sas.service.vo.MapSaveRequest;
|
|
|
import com.usky.sas.service.vo.MapSaveWithDevicesRequest;
|
|
|
import com.usky.sas.service.vo.MapTreeItem;
|
|
|
+import com.usky.sas.service.vo.MapInfoVo;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
@@ -37,6 +46,18 @@ public class SasMapServiceImpl extends AbstractCrudService<SasMapsMapper, SasMap
|
|
|
@Autowired
|
|
|
private SasMapDeviceMapper mapDeviceMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SasPicMapper sasPicMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SasDeviceMapper sasDeviceMapper;
|
|
|
+
|
|
|
+ @Value("${server.protocol:http}")
|
|
|
+ private String protocol;
|
|
|
+
|
|
|
+ @Value("${server.port:8080}")
|
|
|
+ private String port;
|
|
|
+
|
|
|
@Override
|
|
|
public CommonPage<MapListItem> page(MapPageRequest request) {
|
|
|
IPage<SasMaps> page = new Page<>(request.getCurrent(), request.getSize());
|
|
|
@@ -308,6 +329,112 @@ public class SasMapServiceImpl extends AbstractCrudService<SasMapsMapper, SasMap
|
|
|
return roots;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<MapTreeItem> getMapTreeByType(Integer type) {
|
|
|
+ if (type == null) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<SasMaps> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(SasMaps::getType, type);
|
|
|
+ List<SasMaps> maps = this.list(wrapper);
|
|
|
+ if (maps == null || maps.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ Map<String, MapTreeItem> nodeMap = new HashMap<>();
|
|
|
+ for (SasMaps m : maps) {
|
|
|
+ MapTreeItem node = new MapTreeItem();
|
|
|
+ node.setId(m.getId());
|
|
|
+ node.setName(m.getName());
|
|
|
+ node.setType(m.getType());
|
|
|
+ node.setRemark(m.getRemark());
|
|
|
+ node.setParentId(m.getParentId());
|
|
|
+ node.setWidth(m.getWidth());
|
|
|
+ node.setHeight(m.getHeight());
|
|
|
+ node.setIsMask(m.getIsMask());
|
|
|
+ node.setBackImgId(m.getBackImgId());
|
|
|
+ node.setCreateTime(m.getCreateTime());
|
|
|
+ node.setUpdateTime(m.getUpdateTime());
|
|
|
+ nodeMap.put(m.getId(), node);
|
|
|
+ }
|
|
|
+ List<MapTreeItem> roots = new java.util.ArrayList<>();
|
|
|
+ for (SasMaps m : maps) {
|
|
|
+ MapTreeItem node = nodeMap.get(m.getId());
|
|
|
+ if (m.getParentId() == null || m.getParentId().isEmpty()) {
|
|
|
+ roots.add(node);
|
|
|
+ } else {
|
|
|
+ MapTreeItem parent = nodeMap.get(m.getParentId());
|
|
|
+ if (parent != null) {
|
|
|
+ parent.getChildren().add(node);
|
|
|
+ } else {
|
|
|
+ roots.add(node);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return roots;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MapInfoVo getMapInfo(String mapId) {
|
|
|
+ SasMaps maps = getById(mapId);
|
|
|
+ if (maps == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ MapInfoVo vo = new MapInfoVo();
|
|
|
+ BeanUtils.copyProperties(maps, vo);
|
|
|
+ if (maps.getBackImgId() != null && !maps.getBackImgId().isEmpty()) {
|
|
|
+ SasPic pic = sasPicMapper.selectById(maps.getBackImgId());
|
|
|
+ if (pic != null) {
|
|
|
+ String baseUrl = protocol + "://" + GetIpUtils.getServerIP() + ":" + port;
|
|
|
+ String path = (pic.getUrl() != null ? pic.getUrl() : "") + (pic.getPath() != null ? pic.getPath() : "");
|
|
|
+ vo.setBackImgUrl(baseUrl + path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<SasMapDevice> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(SasMapDevice::getMapId, mapId);
|
|
|
+ List<SasMapDevice> list = mapDeviceMapper.selectList(wrapper);
|
|
|
+ List<MapInfoVo.MapDeviceInfoVo> collect = list.stream().map(mapDevice -> {
|
|
|
+ MapInfoVo.MapDeviceInfoVo dvo = new MapInfoVo.MapDeviceInfoVo();
|
|
|
+ dvo.setId(mapDevice.getId());
|
|
|
+ dvo.setDeviceId(mapDevice.getDeviceId());
|
|
|
+ dvo.setMapId(mapDevice.getMapId());
|
|
|
+ dvo.setImgId(mapDevice.getImgId());
|
|
|
+ dvo.setType(mapDevice.getType());
|
|
|
+ dvo.setX(mapDevice.getX());
|
|
|
+ dvo.setY(mapDevice.getY());
|
|
|
+ dvo.setWidth(mapDevice.getWidth());
|
|
|
+ dvo.setHeight(mapDevice.getHeight());
|
|
|
+ dvo.setAngle(mapDevice.getAngle());
|
|
|
+ dvo.setText(mapDevice.getText());
|
|
|
+ dvo.setCreateTime(mapDevice.getCreateTime());
|
|
|
+ dvo.setUpdateTime(mapDevice.getUpdateTime());
|
|
|
+ SasDevice device = sasDeviceMapper.selectById(mapDevice.getDeviceId());
|
|
|
+ if (device != null) {
|
|
|
+ MapInfoVo.DeviceInfoVo deviceInfo = new MapInfoVo.DeviceInfoVo();
|
|
|
+ deviceInfo.setId(device.getId());
|
|
|
+ deviceInfo.setDeviceId(device.getDeviceId());
|
|
|
+ deviceInfo.setChannel(device.getChannel());
|
|
|
+ deviceInfo.setIpAddr(device.getIpAddr());
|
|
|
+ deviceInfo.setPort(device.getPort());
|
|
|
+ deviceInfo.setAddress(device.getAddress());
|
|
|
+ deviceInfo.setNote(device.getNote());
|
|
|
+ SystemTypeCodeEnum typeEnum = SystemTypeCodeEnum.getByCode(device.getDeviceType());
|
|
|
+ deviceInfo.setDeviceType(typeEnum != null ? typeEnum.getMessage() : null);
|
|
|
+ dvo.setDeviceInfo(deviceInfo);
|
|
|
+ }
|
|
|
+ if (mapDevice.getImgId() != null && !mapDevice.getImgId().isEmpty()) {
|
|
|
+ SasPic imgPic = sasPicMapper.selectById(mapDevice.getImgId());
|
|
|
+ if (imgPic != null) {
|
|
|
+ String baseUrl = protocol + "://" + GetIpUtils.getServerIP() + ":" + port;
|
|
|
+ String path = (imgPic.getUrl() != null ? imgPic.getUrl() : "") + (imgPic.getPath() != null ? imgPic.getPath() : "");
|
|
|
+ dvo.setImgUrl(baseUrl + path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return dvo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ vo.setDeviceList(collect);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 递归删除地图及其子地图,同时删除绑定设备
|
|
|
*/
|