修改一键数据处理接口

This commit is contained in:
joylink_zhangsai 2023-01-09 15:03:39 +08:00
parent bb4abc24e1
commit 70a95f0813
2 changed files with 53 additions and 17 deletions

View File

@ -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<String> handle(HttpServletResponse response) {
correctMapVersion();
confirmDefaultOrgExist();
orgProjectController.oldDataHandle();
List<String> 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);
}
}

View File

@ -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<String, club.joylink.rtss.entity.project.Project> 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<String, Org> 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<Org> 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<String, club.joylink.rtss.entity.project.Project> 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);
}
}
}