From d9eb31e884ce41b6869080e9745b57e6058c75f4 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Wed, 25 Nov 2020 11:05:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E6=95=B0=E6=8D=AE=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=8E=86=E5=8F=B2=E7=89=88=E6=9C=AC=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/publish/MapController.java | 10 ++++- .../joylink/rtss/services/IMapService.java | 7 +++- .../rtss/services/IReleaseService.java | 3 +- .../joylink/rtss/services/MapService.java | 17 ++++++-- .../joylink/rtss/services/ReleaseService.java | 42 ++++++++++++------- 5 files changed, 56 insertions(+), 23 deletions(-) diff --git a/src/main/java/club/joylink/rtss/controller/publish/MapController.java b/src/main/java/club/joylink/rtss/controller/publish/MapController.java index 6cc1b7c77..461e42bde 100644 --- a/src/main/java/club/joylink/rtss/controller/publish/MapController.java +++ b/src/main/java/club/joylink/rtss/controller/publish/MapController.java @@ -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 getMapDataVersion(@PathVariable Long id) { + return iMapService.getMapDataVersion(id); + } } diff --git a/src/main/java/club/joylink/rtss/services/IMapService.java b/src/main/java/club/joylink/rtss/services/IMapService.java index efe6ef1ce..3e4ff9bee 100644 --- a/src/main/java/club/joylink/rtss/services/IMapService.java +++ b/src/main/java/club/joylink/rtss/services/IMapService.java @@ -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 queryAllMapName(); void generateMapFunction(Long mapId, UserVO createUser); + + /** + * 获取地图已有的数据版本 + */ + List getMapDataVersion(Long id); } diff --git a/src/main/java/club/joylink/rtss/services/IReleaseService.java b/src/main/java/club/joylink/rtss/services/IReleaseService.java index 30b078d8d..5b3115b44 100644 --- a/src/main/java/club/joylink/rtss/services/IReleaseService.java +++ b/src/main/java/club/joylink/rtss/services/IReleaseService.java @@ -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); } diff --git a/src/main/java/club/joylink/rtss/services/MapService.java b/src/main/java/club/joylink/rtss/services/MapService.java index 8bb006118..732dc89c9 100644 --- a/src/main/java/club/joylink/rtss/services/MapService.java +++ b/src/main/java/club/joylink/rtss/services/MapService.java @@ -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 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 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()); + } + /** * 该版本的地图数据是否存在 */ diff --git a/src/main/java/club/joylink/rtss/services/ReleaseService.java b/src/main/java/club/joylink/rtss/services/ReleaseService.java index 6f48494d1..ba52274ab 100644 --- a/src/main/java/club/joylink/rtss/services/ReleaseService.java +++ b/src/main/java/club/joylink/rtss/services/ReleaseService.java @@ -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 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 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 mapDataWithBLOBsList = mapDataDAO.selectByExampleWithBLOBs(mapDataExample); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(!CollectionUtils.isEmpty(mapDataWithBLOBsList)); + return mapDataWithBLOBsList.get(0); + } + /** * 检查确认该地图的runPlanLoad存在,并且关联的runPlanTemplate也存在; * 检查确认该地图的schedulingPlan数据所关联的runPlanTemplate存在