|
@@ -1,15 +1,12 @@
|
|
|
package com.management.platform.task;
|
|
|
|
|
|
-import com.management.platform.entity.BusinessTrip;
|
|
|
-import com.management.platform.entity.ErpOrderInfo;
|
|
|
-import com.management.platform.entity.LeaveSheet;
|
|
|
-import com.management.platform.entity.UserFvTime;
|
|
|
-import com.management.platform.mapper.BusinessTripMapper;
|
|
|
-import com.management.platform.mapper.ErpOrderInfoMapper;
|
|
|
-import com.management.platform.mapper.LeaveSheetMapper;
|
|
|
-import com.management.platform.mapper.UserFvTimeMapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.management.platform.entity.*;
|
|
|
+import com.management.platform.mapper.*;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.core.ParameterizedTypeReference;
|
|
|
import org.springframework.http.*;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
@@ -37,13 +34,25 @@ public class DataCollectTask {
|
|
|
@Resource
|
|
|
private ErpOrderInfoMapper erpOrderInfoMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ProjectMapper projectMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ProjectCategoryMapper projectCategoryMapper;
|
|
|
+
|
|
|
private static final String PREFIX_URL = "http://58.210.104.138:10020";
|
|
|
|
|
|
+ private static final int specialCompanyId = 7536;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+ @Resource
|
|
|
+ private BustripProjectMapper bustripProjectMapper;
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "0 0 1 * * ?")
|
|
|
+ @Async
|
|
|
public void sqlServerTask() {
|
|
|
- System.out.println("开始测试任务定时=======================");
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
String sumUrl = PREFIX_URL+"/dataCollect/getSqlServerDataSum";
|
|
|
String listUrl = PREFIX_URL+"/dataCollect/getSqlServerDataList";
|
|
@@ -137,6 +146,9 @@ public class DataCollectTask {
|
|
|
int offset = 0;
|
|
|
List<UserFvTime> toAddList = new ArrayList<>();
|
|
|
List<UserFvTime> toUpdateList = new ArrayList<>();
|
|
|
+ List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId, specialCompanyId));
|
|
|
+ Map<String, User> userMap = users.stream().filter(t -> StringUtils.isNotBlank(t.getJobNumber()))
|
|
|
+ .collect(Collectors.toMap(User::getJobNumber, t -> t));
|
|
|
while (offset < totalNum) {
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
@@ -153,8 +165,12 @@ public class DataCollectTask {
|
|
|
if (listResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
List<UserFvTime> dataList = listResponse.getBody();
|
|
|
if(org.apache.commons.collections.CollectionUtils.isNotEmpty(dataList)){
|
|
|
+ for (UserFvTime userFvTime : dataList) {
|
|
|
+ User tmp = userMap.get(userFvTime.getUserId());
|
|
|
+ userFvTime.setUserId(null==tmp?null:tmp.getId());
|
|
|
+ }
|
|
|
List<String> collect = dataList.stream().map(UserFvTime::getProcinstId).distinct().collect(Collectors.toList());
|
|
|
- List<String> existIds = userFvTimeMapper.getExistIds(collect);
|
|
|
+ List<String> existIds = userFvTimeMapper.getExistIds(collect,specialCompanyId);
|
|
|
if(!CollectionUtils.isEmpty(existIds)){
|
|
|
toUpdateList.addAll(dataList.stream().filter(t -> existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
|
toAddList.addAll(dataList.stream().filter(t -> !existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
@@ -185,6 +201,7 @@ public class DataCollectTask {
|
|
|
}
|
|
|
|
|
|
@Scheduled(cron = "0 0 2 * * ?")
|
|
|
+ @Async
|
|
|
public void leaveSheetTask(){
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
String sumUrl = PREFIX_URL + "/dataCollect/getLeaveSheetDataSum";
|
|
@@ -208,6 +225,9 @@ public class DataCollectTask {
|
|
|
int offset = 0;
|
|
|
List<LeaveSheet> toAddList = new ArrayList<>();
|
|
|
List<LeaveSheet> toUpdateList = new ArrayList<>();
|
|
|
+ List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId, specialCompanyId));
|
|
|
+ Map<String, User> userMap = users.stream().filter(t -> StringUtils.isNotBlank(t.getJobNumber()))
|
|
|
+ .collect(Collectors.toMap(User::getJobNumber, t -> t));
|
|
|
while (offset < totalNum) {
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
@@ -224,8 +244,14 @@ public class DataCollectTask {
|
|
|
if (listResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
List<LeaveSheet> dataList = listResponse.getBody();
|
|
|
if(org.apache.commons.collections.CollectionUtils.isNotEmpty(dataList)){
|
|
|
+ for (LeaveSheet leaveSheet : dataList) {
|
|
|
+ User ownerTmp = userMap.get(leaveSheet.getOwnerId());
|
|
|
+ User opTmp = userMap.get(leaveSheet.getOperatorId());
|
|
|
+ leaveSheet.setOwnerId(null==ownerTmp?null:ownerTmp.getId());
|
|
|
+ leaveSheet.setOperatorId(null==opTmp?null:opTmp.getId());
|
|
|
+ }
|
|
|
List<String> collect = dataList.stream().map(LeaveSheet::getProcinstId).distinct().collect(Collectors.toList());
|
|
|
- List<String> existIds = leaveSheetMapper.getExistIds(collect);
|
|
|
+ List<String> existIds = leaveSheetMapper.getExistIds(collect,specialCompanyId);
|
|
|
if(!CollectionUtils.isEmpty(existIds)){
|
|
|
toUpdateList.addAll(dataList.stream().filter(t -> existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
|
toAddList.addAll(dataList.stream().filter(t -> !existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
@@ -255,6 +281,161 @@ public class DataCollectTask {
|
|
|
}
|
|
|
|
|
|
@Scheduled(cron = "0 30 2 * * ?")
|
|
|
+ @Async
|
|
|
+ public void sqlServerProjectTypeTask() {
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ String sumUrl = PREFIX_URL+"/dataCollect/getSqlServerProjectTypeDataSum";
|
|
|
+ String listUrl = PREFIX_URL+"/dataCollect/getSqlServerProjectTypeDataList";
|
|
|
+
|
|
|
+ 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<ProjectCategory> toAddList = new ArrayList<>();
|
|
|
+ List<ProjectCategory> 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<String>> listResponse = restTemplate.exchange(
|
|
|
+ listUrl,
|
|
|
+ HttpMethod.POST,
|
|
|
+ requestEntity,
|
|
|
+ new ParameterizedTypeReference<List<String>>(){}
|
|
|
+ );
|
|
|
+ if (listResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
+ List<String> dataList = listResponse.getBody();
|
|
|
+ List<ProjectCategory> tmpList = new ArrayList<>();
|
|
|
+ if(org.apache.commons.collections.CollectionUtils.isNotEmpty(dataList)){
|
|
|
+ List<String> existIds = projectCategoryMapper.getExistIds(dataList,specialCompanyId);
|
|
|
+ if(!CollectionUtils.isEmpty(existIds)){
|
|
|
+ for (String name : dataList) {
|
|
|
+ ProjectCategory tmp = new ProjectCategory();
|
|
|
+ tmp.setName(name);
|
|
|
+ tmp.setCompanyId(specialCompanyId);
|
|
|
+ tmpList.add(tmp);
|
|
|
+ }
|
|
|
+ toUpdateList.addAll(tmpList.stream().filter(t -> existIds.contains(t.getName())).collect(Collectors.toList()));
|
|
|
+ toAddList.addAll(tmpList.stream().filter(t -> !existIds.contains(t.getName())).collect(Collectors.toList()));
|
|
|
+ }else{
|
|
|
+ for (String name : dataList) {
|
|
|
+ ProjectCategory tmp = new ProjectCategory();
|
|
|
+ tmp.setName(name);
|
|
|
+ tmp.setCompanyId(specialCompanyId);
|
|
|
+ tmpList.add(tmp);
|
|
|
+ }
|
|
|
+ toAddList.addAll(tmpList);
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(toAddList)){
|
|
|
+ projectCategoryMapper.batchInsert(toAddList);
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
+ for (ProjectCategory projectCategory : toUpdateList) {
|
|
|
+ projectCategoryMapper.updateById(projectCategory);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ toUpdateList.clear();
|
|
|
+ toAddList.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ offset += pageSize;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("请求发生异常: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 0 3 * * ?")
|
|
|
+ @Async
|
|
|
+ public void sqlServerProjectTask() {
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ String sumUrl = PREFIX_URL+"/dataCollect/getSqlServerProjectDataSum";
|
|
|
+ String listUrl = PREFIX_URL+"/dataCollect/getSqlServerProjectDataList";
|
|
|
+
|
|
|
+ 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,specialCompanyId);
|
|
|
+ if(!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(!CollectionUtils.isEmpty(toAddList)){
|
|
|
+ projectMapper.batchInsert(toAddList);
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
+ for (Project orderInfo : toUpdateList) {
|
|
|
+ projectMapper.updateById(orderInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ toUpdateList.clear();
|
|
|
+ toAddList.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ offset += pageSize;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("请求发生异常: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 30 3 * * ?")
|
|
|
+ @Async
|
|
|
public void businessTripTask(){
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
String sumUrl = PREFIX_URL+"/dataCollect/getBusinessTripDataSum";
|
|
@@ -278,6 +459,11 @@ public class DataCollectTask {
|
|
|
int offset = 0;
|
|
|
List<BusinessTrip> toAddList = new ArrayList<>();
|
|
|
List<BusinessTrip> toUpdateList = new ArrayList<>();
|
|
|
+ List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId, specialCompanyId));
|
|
|
+ Map<String, User> userMap = users.stream().filter(t -> StringUtils.isNotBlank(t.getJobNumber()))
|
|
|
+ .collect(Collectors.toMap(User::getJobNumber, t -> t));
|
|
|
+ List<Project> projects = projectMapper.selectList(new LambdaQueryWrapper<Project>().eq(Project::getCompanyId, specialCompanyId));
|
|
|
+ Map<String, Project> projectCodeMap = projects.stream().collect(Collectors.toMap(Project::getProjectCode, t -> t));
|
|
|
while (offset < totalNum) {
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
@@ -294,8 +480,12 @@ public class DataCollectTask {
|
|
|
if (listResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
List<BusinessTrip> dataList = listResponse.getBody();
|
|
|
if(org.apache.commons.collections.CollectionUtils.isNotEmpty(dataList)){
|
|
|
+ for (BusinessTrip businessTrip : dataList) {
|
|
|
+ User ownerTmp = userMap.get(businessTrip.getOwnerId());
|
|
|
+ businessTrip.setOwnerId(null==ownerTmp?null:ownerTmp.getId());
|
|
|
+ }
|
|
|
List<String> collect = dataList.stream().map(BusinessTrip::getProcinstId).distinct().collect(Collectors.toList());
|
|
|
- List<String> existIds = businessTripMapper.getExistIds(collect);
|
|
|
+ List<String> existIds = businessTripMapper.getExistIds(collect,specialCompanyId);
|
|
|
if(!CollectionUtils.isEmpty(existIds)){
|
|
|
toUpdateList.addAll(dataList.stream().filter(t -> existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
|
toAddList.addAll(dataList.stream().filter(t -> !existIds.contains(t.getProcinstId())).collect(Collectors.toList()));
|
|
@@ -303,7 +493,17 @@ public class DataCollectTask {
|
|
|
toAddList.addAll(dataList);
|
|
|
}
|
|
|
if(!CollectionUtils.isEmpty(toAddList)){
|
|
|
- businessTripMapper.batchInsert(toAddList);
|
|
|
+// businessTripMapper.batchInsert(toAddList);
|
|
|
+ for (BusinessTrip businessTrip : toAddList) {
|
|
|
+ businessTripMapper.insert(businessTrip);
|
|
|
+ BustripProject bustripProject = new BustripProject();
|
|
|
+ bustripProject.setBustripId(businessTrip.getId());
|
|
|
+ Project project = projectCodeMap.get(businessTrip.getCCcxmNo());
|
|
|
+ bustripProject.setProjectId(null == project?null:project.getId());
|
|
|
+ bustripProject.setStartDate(businessTrip.getStartDate());
|
|
|
+ bustripProject.setEndDate(businessTrip.getEndDate());
|
|
|
+ bustripProjectMapper.insert(bustripProject);
|
|
|
+ }
|
|
|
}
|
|
|
if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
for (BusinessTrip tmp : toUpdateList) {
|