diff --git a/src/main/java/club/joylink/rtss/configuration/WebConfig.java b/src/main/java/club/joylink/rtss/configuration/WebConfig.java index de7bd05c4..49dbb7d9b 100644 --- a/src/main/java/club/joylink/rtss/configuration/WebConfig.java +++ b/src/main/java/club/joylink/rtss/configuration/WebConfig.java @@ -67,6 +67,7 @@ public class WebConfig implements WebMvcConfigurer { whiteList.add("/api/mapFunction/oldDataHandle"); whiteList.add("/api/v2/paper/composition/oldData/handle"); whiteList.add("/api/user/sync"); + whiteList.add("/dataHandle"); registry.addInterceptor(authenticateInterceptor).excludePathPatterns(whiteList); } diff --git a/src/main/java/club/joylink/rtss/controller/DataHandleController.java b/src/main/java/club/joylink/rtss/controller/DataHandleController.java new file mode 100644 index 000000000..555eb704f --- /dev/null +++ b/src/main/java/club/joylink/rtss/controller/DataHandleController.java @@ -0,0 +1,83 @@ +package club.joylink.rtss.controller; + +import club.joylink.rtss.controller.org.OrgProjectController; +import club.joylink.rtss.controller.paper.PaperCompositionController; +import club.joylink.rtss.controller.publish.MapFunctionController; +import club.joylink.rtss.controller.user.UserController; +import club.joylink.rtss.dao.MapDataDAO; +import club.joylink.rtss.dao.MapInfoDAO; +import club.joylink.rtss.entity.MapData; +import club.joylink.rtss.entity.MapDataExample; +import club.joylink.rtss.entity.MapInfo; +import club.joylink.rtss.entity.MapInfoExample; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * 2023.01.10版本处理接口数据 + */ +@RestController +@RequestMapping("/dataHandle") +public class DataHandleController { + @Autowired + private MapInfoDAO mapInfoDAO; + @Autowired + private MapDataDAO mapDataDAO; + @Autowired + private OrgProjectController orgProjectController; + @Autowired + private MapFunctionController mapFunctionController; + @Autowired + private PaperCompositionController paperCompositionController; + @Autowired + private UserController userController; + + @Transactional(rollbackFor = Exception.class) + @PostMapping + public List handle(HttpServletResponse response) { + correctMapVersion(); + + orgProjectController.oldDataHandle(); + + List msgList = new ArrayList<>(mapFunctionController.oldDataHandle()); + + msgList.addAll(paperCompositionController.oldDataHandle()); + + userController.sync(response); + return msgList; + } + + /** + * 纠正地图信息表的版本字段,使用地图数据的最后一个版本 + */ + private void correctMapVersion() { + MapInfoExample mapInfoExample = new MapInfoExample(); + mapInfoExample.createCriteria().andStatusEqualTo("1"); + List onlineMaps = mapInfoDAO.selectByExample(mapInfoExample); + Map onlineMapMap = onlineMaps.stream().collect(Collectors.toMap(MapInfo::getId, Function.identity())); + MapDataExample mapDataExample = new MapDataExample(); + mapDataExample.createCriteria().andMapIdIn(new ArrayList<>(onlineMapMap.keySet())); + + List onlineMapDataList = mapDataDAO.selectByExample(mapDataExample); + onlineMapDataList.stream() + .collect(Collectors.toMap(MapData::getMapId, MapData::getVersion, (d1, d2) -> { + float v1 = Float.parseFloat(d1); + float v2 = Float.parseFloat(d2); + return v1 > v2 ? d1 : d2; + })).forEach((mapId, version) -> { + MapInfo mapInfo = onlineMapMap.get(mapId); + mapInfo.setVersion(version); + mapInfoDAO.updateByPrimaryKey(mapInfo); + }); + } +} diff --git a/src/main/java/club/joylink/rtss/controller/paper/PaperCompositionController.java b/src/main/java/club/joylink/rtss/controller/paper/PaperCompositionController.java index 0e8365d4e..9b8ee61dc 100644 --- a/src/main/java/club/joylink/rtss/controller/paper/PaperCompositionController.java +++ b/src/main/java/club/joylink/rtss/controller/paper/PaperCompositionController.java @@ -181,8 +181,9 @@ public class PaperCompositionController { lsLessonExample.createCriteria().andMapIdIn(new ArrayList<>(onlineMaps.keySet())).andStatusEqualTo("1"); List validLessonIds = lsLessonDAO.selectByExample(lsLessonExample) .stream().map(LsLesson::getId).collect(Collectors.toList()); - //所有项目-组织对应关系 - Map projectCode_orgId_map = orgProjectDAO.selectByExample(null).stream().collect(Collectors.toMap(OrgProject::getProjectCode, OrgProject::getOrgId)); + //所有项目-组织对应关系(目前仅教学通用项目 + Map projectCode_orgId_map = orgProjectDAO.selectByExample(null).stream() + .collect(Collectors.toMap(OrgProject::getProjectCode, OrgProject::getOrgId, (oId1, oId2) -> oId1)); //转化试卷并记录试卷id变化 ExamDefinitionExample examDefinitionExample = new ExamDefinitionExample(); examDefinitionExample.createCriteria().andStatusEqualTo("1").andLessonIdIn(validLessonIds); diff --git a/src/main/java/club/joylink/rtss/controller/publish/MapFunctionController.java b/src/main/java/club/joylink/rtss/controller/publish/MapFunctionController.java index 6a3c25241..6bfae8172 100644 --- a/src/main/java/club/joylink/rtss/controller/publish/MapFunctionController.java +++ b/src/main/java/club/joylink/rtss/controller/publish/MapFunctionController.java @@ -47,7 +47,7 @@ public class MapFunctionController { } /** - * 列表查询地图系统(新) + * 列表查询地图功能(新) */ @GetMapping("/list") public List listQuery(RtsMapFunctionQueryVO queryVO) { @@ -55,7 +55,7 @@ public class MapFunctionController { } /** - * 分页查询地图系统(新) + * 分页查询地图功能(新) */ @GetMapping("/paged") public PageVO pagedQuery(RtsMapFunctionQueryVO queryVO) { @@ -63,7 +63,7 @@ public class MapFunctionController { } /** - * 删除地图系统(新) + * 删除地图功能(新) */ @Role(RoleEnum.Admin) @DeleteMapping("/{id}") @@ -81,7 +81,7 @@ public class MapFunctionController { } /** - * 更新地图系统(新) + * 更新地图功能(新) */ @Role(RoleEnum.Admin) @PutMapping("/{id}") @@ -90,7 +90,7 @@ public class MapFunctionController { } /** - * 根据ID获取地图系统信息 + * 根据ID获取地图功能信息 */ @GetMapping("/{id}") public RtsMapFunctionVO queryOne(@PathVariable Long id) {