地图数据保存历史版本相关功能修正

This commit is contained in:
joylink_zhangsai 2020-11-25 11:05:39 +08:00
parent fbaadf8ae8
commit d9eb31e884
5 changed files with 56 additions and 23 deletions

View File

@ -262,8 +262,8 @@ public class MapController {
@ApiOperation("导入地图相关数据")
@PutMapping("/{id}/import/new")
public void importFromJson(@PathVariable Long id, @RequestBody ReleaseVO json) {
iReleaseService.importFromJson(id, json);
public void importFromJson(@PathVariable Long id, @RequestBody ReleaseVO json, @RequestAttribute UserVO user) {
iReleaseService.importFromJson(id, json, user);
}
@ApiOperation("一键生成发布地图相关功能:目前生成权限及子系统")
@ -271,4 +271,10 @@ public class MapController {
public void generate(@PathVariable Long id, @ApiIgnore @RequestAttribute UserVO user) {
this.iMapService.generateMapFunction(id, user);
}
@ApiOperation("查询地图数据现有版本")
@GetMapping("/{id}/dataVersions")
public List<String> getMapDataVersion(@PathVariable Long id) {
return iMapService.getMapDataVersion(id);
}
}

View File

@ -193,7 +193,7 @@ public interface IMapService {
*/
Map3dDataVO findMap3dDataByMapId(Long mapId);
MapDataVO getMapDataByMapId(Long mapId, Boolean drayWay);
MapDataVO getMapData(Long mapId, Boolean drayWay, String version);
/**
* 根据选项拷贝发布地图数据
@ -273,4 +273,9 @@ public interface IMapService {
List<MapVO> queryAllMapName();
void generateMapFunction(Long mapId, UserVO createUser);
/**
* 获取地图已有的数据版本
*/
List<String> getMapDataVersion(Long id);
}

View File

@ -1,5 +1,6 @@
package club.joylink.rtss.services;
import club.joylink.rtss.vo.UserVO;
import club.joylink.rtss.vo.client.ReleaseConfigVO;
import club.joylink.rtss.vo.client.ReleaseVO;
@ -12,5 +13,5 @@ public interface IReleaseService {
/**
* 从json导入
*/
void importFromJson(Long id, ReleaseVO releaseVO);
void importFromJson(Long id, ReleaseVO releaseVO, UserVO user);
}

View File

@ -230,7 +230,7 @@ public class MapService implements IMapService {
// // 查询map版本
// String version = this.findMapVersion(mapVO.getId());
// mapVO.setVersion(version);
MapDataVO mapDataVO = this.getMapDataByMapId(mapVO.getId(), mapVO.isDrawWay());
MapDataVO mapDataVO = this.getMapData(mapVO.getId(), mapVO.isDrawWay(), mapVO.getVersion());
mapVO.setMapData(mapDataVO);
// mapVO.setMap3dData(this.findMap3dDataByMapId(mapVO.getId()));
// todo 后面可以设置为永不过期缓存
@ -248,13 +248,13 @@ public class MapService implements IMapService {
}
@Override
public MapDataVO getMapDataByMapId(Long mapId, Boolean drayWay) {
public MapDataVO getMapData(Long mapId, Boolean drayWay, String version) {
Objects.requireNonNull(mapId, "mapId不能为空");
MapDataExample example = new MapDataExample();
example.createCriteria().andMapIdEqualTo(mapId);
example.createCriteria().andMapIdEqualTo(mapId).andVersionEqualTo(version);
List<MapDataWithBLOBs> mapDataList = this.mapDataDAO.selectByExampleWithBLOBs(example);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(!CollectionUtils.isEmpty(mapDataList),
String.format("地图id[%s]的地图数据不存在", mapId));
String.format("地图id[%s]版本号[%s]的地图数据不存在", mapId, version));
return new MapDataVO(mapDataList.get(0), drayWay);
}
@ -353,6 +353,7 @@ public class MapService implements IMapService {
map.setStatus(MapStatus.Online.getCode());
map.setProject(false);
map.setDrawWay(mapVO.isDrawWay());
map.setVersion("0.1");
mapInfoDAO.insert(map);
} else {
map = mapInfoList.get(0);
@ -835,6 +836,14 @@ public class MapService implements IMapService {
}
}
@Override
public List<String> getMapDataVersion(Long id) {
MapDataExample example = new MapDataExample();
example.setOrderByClause("time desc");
example.createCriteria().andMapIdEqualTo(id);
return mapDataDAO.selectByExample(example).stream().map(MapData::getVersion).collect(Collectors.toList());
}
/**
* 该版本的地图数据是否存在
*/

View File

@ -5,14 +5,18 @@ import club.joylink.rtss.controller.cache.CacheController;
import club.joylink.rtss.dao.*;
import club.joylink.rtss.entity.*;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.util.VersionUtil;
import club.joylink.rtss.vo.UserVO;
import club.joylink.rtss.vo.client.ReleaseConfigVO;
import club.joylink.rtss.vo.client.ReleaseVO;
import club.joylink.rtss.vo.client.map.MapInfoUpdateVO;
import club.joylink.rtss.vo.client.map.MapVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@ -63,10 +67,10 @@ public class ReleaseService implements IReleaseService {
@Override
public ReleaseVO exportAsJson(Long mapId, ReleaseConfigVO config) {
ReleaseVO releaseVO = new ReleaseVO();
//地图数据强制选择
releaseVO.setMapData(getMapDataWithBLOBs(mapId));
//线路配置强制选择
MapVO mapInfo = iMapService.getMapInfoById(mapId);
//地图数据强制选择
releaseVO.setMapData(getMapDataWithBLOBs(mapId, mapInfo.getVersion()));
//线路配置强制选择
RealLineExample realLineExample = new RealLineExample();
realLineExample.createCriteria().andCodeEqualTo(mapInfo.getLineCode());
List<RealLine> realLines = realLineDAO.selectByExampleWithBLOBs(realLineExample);
@ -148,17 +152,9 @@ public class ReleaseService implements IReleaseService {
return releaseVO;
}
private MapDataWithBLOBs getMapDataWithBLOBs(Long mapId) {
MapDataExample mapDataExample = new MapDataExample();
mapDataExample.createCriteria().andMapIdEqualTo(mapId);
List<MapDataWithBLOBs> mapDataWithBLOBsList = mapDataDAO.selectByExampleWithBLOBs(mapDataExample);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(!CollectionUtils.isEmpty(mapDataWithBLOBsList));
return mapDataWithBLOBsList.get(0);
}
@Transactional
@Override
public void importFromJson(Long mapId, ReleaseVO releaseVO) {
public void importFromJson(Long mapId, ReleaseVO releaseVO, UserVO user) {
BusinessExceptionAssertEnum.INVALID_OPERATION.assertNotNull(releaseVO.getMapData());
BusinessExceptionAssertEnum.INVALID_OPERATION.assertNotNull(releaseVO.getRealLineConfig());
@ -169,9 +165,17 @@ public class ReleaseService implements IReleaseService {
MapDataWithBLOBs mapDataWithBLOBs = releaseVO.getMapData();
mapDataWithBLOBs.setId(null);
mapDataWithBLOBs.setMapId(mapId);
MapDataExample mapDataExample = new MapDataExample();
mapDataExample.createCriteria().andMapIdEqualTo(mapId);
mapDataDAO.updateByExampleSelective(mapDataWithBLOBs, mapDataExample);
mapDataWithBLOBs.setVersion(VersionUtil.generateNext(iMapService.findMapVersion(mapId)));
mapDataWithBLOBs.setTime(LocalDateTime.now());
mapDataWithBLOBs.setUserId(user.getId());
mapDataDAO.insert(mapDataWithBLOBs);
//更新mapInfo的地图数据版本
MapInfoUpdateVO mapInfoUpdateVO = new MapInfoUpdateVO();
mapInfoUpdateVO.setName(selectedMapInfo.getName());
mapInfoUpdateVO.setLineCode(selectedMapInfo.getLineCode());
mapInfoUpdateVO.setCityCode(selectedMapInfo.getCityCode());
mapInfoUpdateVO.setVersion(mapDataWithBLOBs.getVersion());
iMapService.updateBasicInfo(mapId, mapInfoUpdateVO, user);
//清除地图数据缓存
cacheController.remove(BusinessConsts.CachePrefix.Map + mapId);
@ -321,6 +325,14 @@ public class ReleaseService implements IReleaseService {
}
}
private MapDataWithBLOBs getMapDataWithBLOBs(Long mapId, String version) {
MapDataExample mapDataExample = new MapDataExample();
mapDataExample.createCriteria().andMapIdEqualTo(mapId).andVersionEqualTo(version);
List<MapDataWithBLOBs> mapDataWithBLOBsList = mapDataDAO.selectByExampleWithBLOBs(mapDataExample);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(!CollectionUtils.isEmpty(mapDataWithBLOBsList));
return mapDataWithBLOBsList.get(0);
}
/**
* 检查确认该地图的runPlanLoad存在并且关联的runPlanTemplate也存在;
* 检查确认该地图的schedulingPlan数据所关联的runPlanTemplate存在