|
|
@@ -14348,90 +14348,85 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
String sumUrl = DataCollectTask.PREFIX_URL+"/dataCollect/getSqlServerProjectDataSum";
|
|
|
String listUrl = DataCollectTask.PREFIX_URL+"/dataCollect/getSqlServerProjectDataList";
|
|
|
Company company = companyMapper.selectById(honghuCompId);
|
|
|
- try {
|
|
|
- ResponseEntity<String> sumResponse = restTemplate.exchange(
|
|
|
- sumUrl,
|
|
|
- HttpMethod.GET,
|
|
|
- null,
|
|
|
- String.class
|
|
|
- );
|
|
|
- Integer totalNum = 0;
|
|
|
- if (sumResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
- totalNum = Integer.parseInt(sumResponse.getBody());
|
|
|
- } else {
|
|
|
- System.out.println("请求失败,状态码: " + sumResponse.getStatusCode());
|
|
|
- }
|
|
|
- if(totalNum > 0){
|
|
|
- int pageSize = 1000;
|
|
|
- int offset = 0;
|
|
|
- List<Project> toAddList = new ArrayList<>();
|
|
|
- List<Project> toUpdateList = new ArrayList<>();
|
|
|
- while (offset < totalNum) {
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
- Map<String, Object> requestBody = new HashMap<>();
|
|
|
- requestBody.put("pageNo", offset);
|
|
|
- requestBody.put("pageSize", pageSize);
|
|
|
- HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers);
|
|
|
- ResponseEntity<List<Project>> listResponse = restTemplate.exchange(
|
|
|
- listUrl,
|
|
|
- HttpMethod.POST,
|
|
|
- requestEntity,
|
|
|
- new ParameterizedTypeReference<List<Project>>(){}
|
|
|
- );
|
|
|
- if (listResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
- List<Project> dataList = listResponse.getBody();
|
|
|
- if(org.apache.commons.collections.CollectionUtils.isNotEmpty(dataList)){
|
|
|
- List<String> collect = dataList.stream().map(Project::getProjectCode).distinct().collect(Collectors.toList());
|
|
|
- List<String> existIds = projectMapper.getExistIds(collect, honghuCompId);
|
|
|
- if(!org.springframework.util.CollectionUtils.isEmpty(existIds)){
|
|
|
- toUpdateList.addAll(dataList.stream().filter(t -> existIds.contains(t.getProjectCode())).collect(Collectors.toList()));
|
|
|
- toAddList.addAll(dataList.stream().filter(t -> !existIds.contains(t.getProjectCode())).collect(Collectors.toList()));
|
|
|
- }else{
|
|
|
- toAddList.addAll(dataList);
|
|
|
- }
|
|
|
- if(!org.springframework.util.CollectionUtils.isEmpty(toAddList)){
|
|
|
- for (Project project : toAddList) {
|
|
|
- //以项目编码前五为作为分类名称
|
|
|
- String categoryName = project.getProjectCode().substring(0,5);
|
|
|
- project.setCategoryName(categoryName);
|
|
|
- ProjectCategory category = projectCategoryMapper.selectOne(new LambdaQueryWrapper<ProjectCategory>()
|
|
|
- .eq(ProjectCategory::getCompanyId, honghuCompId)
|
|
|
- .eq(ProjectCategory::getName, project.getCategoryName())
|
|
|
- .last(" limit 1 ")
|
|
|
- );
|
|
|
- int categoryId;
|
|
|
- if(null != category){
|
|
|
- categoryId = category.getId();
|
|
|
- }else{
|
|
|
- ProjectCategory tmp = new ProjectCategory();
|
|
|
- tmp.setName(project.getCategoryName());
|
|
|
- tmp.setCompanyId(honghuCompId);
|
|
|
- projectCategoryMapper.insert(tmp);
|
|
|
- categoryId = tmp.getId();
|
|
|
- }
|
|
|
- if(0!= categoryId){
|
|
|
- project.setCategory(categoryId);
|
|
|
- projectMapper.insert(project);
|
|
|
- if (company.getPackageProject() == 1) {
|
|
|
- initGroup(honghuCompId,project.getId());
|
|
|
- }
|
|
|
+ ResponseEntity<String> sumResponse = restTemplate.exchange(
|
|
|
+ sumUrl,
|
|
|
+ HttpMethod.GET,
|
|
|
+ null,
|
|
|
+ String.class
|
|
|
+ );
|
|
|
+ Integer totalNum = 0;
|
|
|
+ if (sumResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
+ totalNum = Integer.parseInt(sumResponse.getBody());
|
|
|
+ } else {
|
|
|
+ System.out.println("请求失败,状态码: " + sumResponse.getStatusCode());
|
|
|
+ }
|
|
|
+ if(totalNum > 0){
|
|
|
+ int pageSize = 1000;
|
|
|
+ int offset = 0;
|
|
|
+ List<Project> toAddList = new ArrayList<>();
|
|
|
+ List<Project> toUpdateList = new ArrayList<>();
|
|
|
+ while (offset < totalNum) {
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ Map<String, Object> requestBody = new HashMap<>();
|
|
|
+ requestBody.put("pageNo", offset);
|
|
|
+ requestBody.put("pageSize", pageSize);
|
|
|
+ HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers);
|
|
|
+ ResponseEntity<List<Project>> listResponse = restTemplate.exchange(
|
|
|
+ listUrl,
|
|
|
+ HttpMethod.POST,
|
|
|
+ requestEntity,
|
|
|
+ new ParameterizedTypeReference<List<Project>>(){}
|
|
|
+ );
|
|
|
+ if (listResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
+ List<Project> dataList = listResponse.getBody();
|
|
|
+ if(org.apache.commons.collections.CollectionUtils.isNotEmpty(dataList)){
|
|
|
+ List<String> collect = dataList.stream().map(Project::getProjectCode).distinct().collect(Collectors.toList());
|
|
|
+ List<String> existIds = projectMapper.getExistIds(collect, honghuCompId);
|
|
|
+ if(!org.springframework.util.CollectionUtils.isEmpty(existIds)){
|
|
|
+ toUpdateList.addAll(dataList.stream().filter(t -> existIds.contains(t.getProjectCode())).collect(Collectors.toList()));
|
|
|
+ toAddList.addAll(dataList.stream().filter(t -> !existIds.contains(t.getProjectCode())).collect(Collectors.toList()));
|
|
|
+ }else{
|
|
|
+ toAddList.addAll(dataList);
|
|
|
+ }
|
|
|
+ if(!org.springframework.util.CollectionUtils.isEmpty(toAddList)){
|
|
|
+ for (Project project : toAddList) {
|
|
|
+ //以项目编码前五为作为分类名称
|
|
|
+ String categoryName = project.getProjectCode().substring(0,5);
|
|
|
+ project.setCategoryName(categoryName);
|
|
|
+ ProjectCategory category = projectCategoryMapper.selectOne(new LambdaQueryWrapper<ProjectCategory>()
|
|
|
+ .eq(ProjectCategory::getCompanyId, honghuCompId)
|
|
|
+ .eq(ProjectCategory::getName, project.getCategoryName())
|
|
|
+ .last(" limit 1 ")
|
|
|
+ );
|
|
|
+ int categoryId;
|
|
|
+ if(null != category){
|
|
|
+ categoryId = category.getId();
|
|
|
+ }else{
|
|
|
+ ProjectCategory tmp = new ProjectCategory();
|
|
|
+ tmp.setName(project.getCategoryName());
|
|
|
+ tmp.setCompanyId(honghuCompId);
|
|
|
+ projectCategoryMapper.insert(tmp);
|
|
|
+ categoryId = tmp.getId();
|
|
|
+ }
|
|
|
+ if(0!= categoryId){
|
|
|
+ project.setCategory(categoryId);
|
|
|
+ projectMapper.insert(project);
|
|
|
+ if (company.getPackageProject() == 1) {
|
|
|
+ initGroup(honghuCompId,project.getId());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if(!org.springframework.util.CollectionUtils.isEmpty(toUpdateList)){
|
|
|
- updateBatchById(toUpdateList);
|
|
|
- }
|
|
|
- toUpdateList.clear();
|
|
|
- toAddList.clear();
|
|
|
}
|
|
|
+ if(!org.springframework.util.CollectionUtils.isEmpty(toUpdateList)){
|
|
|
+ updateBatchById(toUpdateList);
|
|
|
+ }
|
|
|
+ toUpdateList.clear();
|
|
|
+ toAddList.clear();
|
|
|
}
|
|
|
- offset += pageSize;
|
|
|
}
|
|
|
+ offset += pageSize;
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("请求发生异常: " + e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|