|
@@ -0,0 +1,327 @@
|
|
|
+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 org.springframework.core.ParameterizedTypeReference;
|
|
|
+import org.springframework.http.*;
|
|
|
+import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@EnableScheduling
|
|
|
+@Component
|
|
|
+public class DataCollectTask {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserFvTimeMapper userFvTimeMapper;
|
|
|
+ @Resource
|
|
|
+ private BusinessTripMapper businessTripMapper;
|
|
|
+ @Resource
|
|
|
+ private LeaveSheetMapper leaveSheetMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ErpOrderInfoMapper erpOrderInfoMapper;
|
|
|
+
|
|
|
+ private static final String PREFIX_URL = "http://58.210.104.138:10020";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 0 1 * * ?")
|
|
|
+ public void sqlServerTask() {
|
|
|
+ System.out.println("开始测试任务定时=======================");
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ String sumUrl = PREFIX_URL+"/dataCollect/getSqlServerDataSum";
|
|
|
+ String listUrl = PREFIX_URL+"/dataCollect/getSqlServerDataList";
|
|
|
+
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ System.out.println("总数量为==== "+totalNum);
|
|
|
+ if(totalNum > 0){
|
|
|
+ int pageSize = 1000;
|
|
|
+ int offset = 0;
|
|
|
+ List<ErpOrderInfo> toAddList = new ArrayList<>();
|
|
|
+ List<ErpOrderInfo> 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<ErpOrderInfo>> listResponse = restTemplate.exchange(
|
|
|
+ listUrl,
|
|
|
+ HttpMethod.POST,
|
|
|
+ requestEntity,
|
|
|
+ new ParameterizedTypeReference<List<ErpOrderInfo>>(){}
|
|
|
+ );
|
|
|
+ if (listResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
+ List<ErpOrderInfo> dataList = listResponse.getBody();
|
|
|
+ if(org.apache.commons.collections.CollectionUtils.isNotEmpty(dataList)){
|
|
|
+ List<String> collect = dataList.stream().map(ErpOrderInfo::getMoDId).distinct().collect(Collectors.toList());
|
|
|
+ List<String> existIds = erpOrderInfoMapper.getExistIds(collect);
|
|
|
+ if(!CollectionUtils.isEmpty(existIds)){
|
|
|
+ toUpdateList.addAll(dataList.stream().filter(t -> existIds.contains(t.getMoDId())).collect(Collectors.toList()));
|
|
|
+ toAddList.addAll(dataList.stream().filter(t -> !existIds.contains(t.getMoDId())).collect(Collectors.toList()));
|
|
|
+ }else{
|
|
|
+ toAddList.addAll(dataList);
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(toAddList)){
|
|
|
+ erpOrderInfoMapper.batchInsert(toAddList);
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
+ for (ErpOrderInfo orderInfo : toUpdateList) {
|
|
|
+ erpOrderInfoMapper.updateById(orderInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ toUpdateList.clear();
|
|
|
+ toAddList.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ offset += pageSize;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("请求发生异常: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 21 11 * * ?")
|
|
|
+ public void workDayTask(){
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ String sumUrl = PREFIX_URL+"/dataCollect/getWorkDayDataSum";
|
|
|
+ String listUrl = PREFIX_URL+"/dataCollect/getWorkDayDataList";
|
|
|
+
|
|
|
+ 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<UserFvTime> toAddList = new ArrayList<>();
|
|
|
+ List<UserFvTime> 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<UserFvTime>> listResponse = restTemplate.exchange(
|
|
|
+ listUrl,
|
|
|
+ HttpMethod.POST,
|
|
|
+ requestEntity,
|
|
|
+ new ParameterizedTypeReference<List<UserFvTime>>(){}
|
|
|
+ );
|
|
|
+ if (listResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
+ List<UserFvTime> dataList = listResponse.getBody();
|
|
|
+ if(org.apache.commons.collections.CollectionUtils.isNotEmpty(dataList)){
|
|
|
+ List<String> collect = dataList.stream().map(UserFvTime::getProcinstId).distinct().collect(Collectors.toList());
|
|
|
+ List<String> existIds = userFvTimeMapper.getExistIds(collect);
|
|
|
+ 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()));
|
|
|
+ }else{
|
|
|
+ toAddList.addAll(dataList);
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(toAddList)){
|
|
|
+ userFvTimeMapper.batchInsertCollect(toAddList);
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
+ for (UserFvTime tmp : toUpdateList) {
|
|
|
+ userFvTimeMapper.updateById(tmp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ toUpdateList.clear();
|
|
|
+ toAddList.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ offset += pageSize;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("请求发生异常: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 0 2 * * ?")
|
|
|
+ public void leaveSheetTask(){
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ String sumUrl = PREFIX_URL + "/dataCollect/getLeaveSheetDataSum";
|
|
|
+ String listUrl = PREFIX_URL + "/dataCollect/getLeaveSheetDataList";
|
|
|
+
|
|
|
+ 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<LeaveSheet> toAddList = new ArrayList<>();
|
|
|
+ List<LeaveSheet> 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<LeaveSheet>> listResponse = restTemplate.exchange(
|
|
|
+ listUrl,
|
|
|
+ HttpMethod.POST,
|
|
|
+ requestEntity,
|
|
|
+ new ParameterizedTypeReference<List<LeaveSheet>>(){}
|
|
|
+ );
|
|
|
+ if (listResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
+ List<LeaveSheet> dataList = listResponse.getBody();
|
|
|
+ if(org.apache.commons.collections.CollectionUtils.isNotEmpty(dataList)){
|
|
|
+ List<String> collect = dataList.stream().map(LeaveSheet::getProcinstId).distinct().collect(Collectors.toList());
|
|
|
+ List<String> existIds = leaveSheetMapper.getExistIds(collect);
|
|
|
+ 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()));
|
|
|
+ }else{
|
|
|
+ toAddList.addAll(dataList);
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(toAddList)){
|
|
|
+ leaveSheetMapper.batchInsert(toAddList);
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
+ for (LeaveSheet tmp : toUpdateList) {
|
|
|
+ leaveSheetMapper.updateById(tmp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ toUpdateList.clear();
|
|
|
+ toAddList.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ offset += pageSize;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("请求发生异常: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 30 2 * * ?")
|
|
|
+ public void businessTripTask(){
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ String sumUrl = PREFIX_URL+"/dataCollect/getBusinessTripDataSum";
|
|
|
+ String listUrl = PREFIX_URL+"/dataCollect/getBusinessTripDataList";
|
|
|
+
|
|
|
+ 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<BusinessTrip> toAddList = new ArrayList<>();
|
|
|
+ List<BusinessTrip> 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<BusinessTrip>> listResponse = restTemplate.exchange(
|
|
|
+ listUrl,
|
|
|
+ HttpMethod.POST,
|
|
|
+ requestEntity,
|
|
|
+ new ParameterizedTypeReference<List<BusinessTrip>>(){}
|
|
|
+ );
|
|
|
+ if (listResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
+ List<BusinessTrip> dataList = listResponse.getBody();
|
|
|
+ if(org.apache.commons.collections.CollectionUtils.isNotEmpty(dataList)){
|
|
|
+ List<String> collect = dataList.stream().map(BusinessTrip::getProcinstId).distinct().collect(Collectors.toList());
|
|
|
+ List<String> existIds = businessTripMapper.getExistIds(collect);
|
|
|
+ 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()));
|
|
|
+ }else{
|
|
|
+ toAddList.addAll(dataList);
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(toAddList)){
|
|
|
+ businessTripMapper.batchInsert(toAddList);
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
+ for (BusinessTrip tmp : toUpdateList) {
|
|
|
+ businessTripMapper.updateById(tmp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ toUpdateList.clear();
|
|
|
+ toAddList.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ offset += pageSize;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("请求发生异常: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|