diff --git a/src/main/java/club/joylink/rtss/controller/DataHandleController.java b/src/main/java/club/joylink/rtss/controller/DataHandleController.java index 555eb704f..79057fe13 100644 --- a/src/main/java/club/joylink/rtss/controller/DataHandleController.java +++ b/src/main/java/club/joylink/rtss/controller/DataHandleController.java @@ -1,15 +1,14 @@ package club.joylink.rtss.controller; +import club.joylink.rtss.constants.Project; 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 club.joylink.rtss.dao.OrgDAO; +import club.joylink.rtss.entity.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PostMapping; @@ -17,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletResponse; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -41,12 +41,16 @@ public class DataHandleController { private PaperCompositionController paperCompositionController; @Autowired private UserController userController; + @Autowired + private OrgDAO orgDAO; @Transactional(rollbackFor = Exception.class) @PostMapping public List handle(HttpServletResponse response) { correctMapVersion(); + confirmDefaultOrgExist(); + orgProjectController.oldDataHandle(); List msgList = new ArrayList<>(mapFunctionController.oldDataHandle()); @@ -80,4 +84,16 @@ public class DataHandleController { mapInfoDAO.updateByPrimaryKey(mapInfo); }); } + + private void confirmDefaultOrgExist() { + Org org = new Org(); + org.setName("默认组织"); + org.setProjectCode(Project.DEFAULT.name()); + org.setStatus("1"); + org.setCreateTime(LocalDateTime.now()); + org.setCreatorId(1L); + orgDAO.insert(org); + org.setRootId(org.getId()); + orgDAO.updateByPrimaryKey(org); + } } diff --git a/src/main/java/club/joylink/rtss/controller/org/OrgProjectController.java b/src/main/java/club/joylink/rtss/controller/org/OrgProjectController.java index 652f3a889..2ce8ec697 100644 --- a/src/main/java/club/joylink/rtss/controller/org/OrgProjectController.java +++ b/src/main/java/club/joylink/rtss/controller/org/OrgProjectController.java @@ -1,24 +1,30 @@ package club.joylink.rtss.controller.org; +import club.joylink.rtss.constants.Project; import club.joylink.rtss.dao.OrgDAO; import club.joylink.rtss.dao.OrgProjectDAO; +import club.joylink.rtss.dao.project.ProjectDAO; import club.joylink.rtss.entity.Org; import club.joylink.rtss.entity.OrgExample; import club.joylink.rtss.entity.OrgProject; import club.joylink.rtss.services.org.IOrgProjectService; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.client.org.OrgProjectVO; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import java.time.LocalDateTime; import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; /** * 组织-项目关系管理接口 */ +@Slf4j @RestController @RequestMapping("/api/orgProject") public class OrgProjectController { @@ -46,6 +52,8 @@ public class OrgProjectController { private OrgProjectDAO orgProjectDAO; @Autowired private OrgDAO orgDAO; + @Autowired + ProjectDAO projectDAO; /** * 旧数据处理(用完删除) @@ -55,22 +63,34 @@ public class OrgProjectController { public void oldDataHandle() { orgProjectDAO.deleteByExample(null); + //查询项目和组织数据 + Map projectMap = projectDAO.selectByExample(null).stream() + .collect(Collectors.toMap(club.joylink.rtss.entity.project.Project::getCode, Function.identity())); + OrgExample orgExample = new OrgExample(); + orgExample.clear(); + orgExample.createCriteria().andStatusEqualTo("1").andParentIdIsNull(); + Map orgMap = orgDAO.selectByExample(orgExample).stream() + .collect(Collectors.toMap(Org::getProjectCode, Function.identity())); + OrgProject orgProject = new OrgProject(); orgProject.setCreateTime(LocalDateTime.now()); orgProject.setCreatorId(1L); - OrgExample orgExample = new OrgExample(); - orgExample.createCriteria().andStatusEqualTo("1").andParentIdIsNull(); - List orgs = orgDAO.selectByExample(orgExample); - for (Org org : orgs) { - String projectCodeStr = org.getProjectCode(); - if (StringUtils.hasText(projectCodeStr)) { - for (String projectCode : projectCodeStr.split(",")) { - orgProject.setId(null); - orgProject.setOrgId(org.getId()); - orgProject.setProjectCode(projectCode); - orgProjectDAO.insert(orgProject); - } + for (Map.Entry entry : projectMap.entrySet()) { + String projectCode = entry.getKey(); + club.joylink.rtss.entity.project.Project project = entry.getValue(); + //建立项目-组织关系 + Org org = orgMap.get(projectCode); + if (org == null) { + org = orgMap.get(Project.DEFAULT.name()); } + orgProject.setId(null); + orgProject.setProjectCode(projectCode); + orgProject.setOrgId(org.getId()); + log.info(orgProject.getOrgId() + "-" + orgProject.getProjectCode()); + orgProjectDAO.insert(orgProject); + //修改项目默认组织 + project.setDefaultOrg(org.getId()); + projectDAO.updateByPrimaryKey(project); } } }