Timing remote data acquisition tasks

package com.sf.XWFS.task;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sf.XWFS.domain.OrderDO;
import com.sf.XWFS.domain.YHOrderDO;
import com.sf.XWFS.mapper.YHOrderMapper;
import com.sf.XWFS.service.OrderService;
import com.sf.XWFS.service.YHOrderService;
import io.jsonwebtoken.lang.Collections;
import io.swagger.annotations.Api;
import org.apache.commons.collections.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.config.ScheduledTask;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util. *;

/ **
* Order the Scheduled timer task request voyage
* @author puxiaozhe
* @date 2019-05-07
* /

@Component
public class SchedulerTask {

private Logger logger = LoggerFactory.getLogger(SchedulerTask.class);

private OrderService orderService;

private YHOrderService yhOrderService;

/ *
* Get data from a database voyage
*
* /
@Scheduled (fixedRate = 60000)
public void refreshOrder () {

logger.info ( "start -----> Refresh beginning to obtain orders from the voyage data");

orderService = (OrderService)ApplicationContextUtil.getBean("orderServiceImpl");
yhOrderService = (YHOrderService)ApplicationContextUtil.getBean("YHOrderServiceImpl");

// start time of the recording system
Long Start = System.currentTimeMillis ();
// Number of Article
int the pageSize = 50;
// Offset
int PageStart = 0;
// most queries
int maxTimes = 50;
// initial query time
int = 0 queryTimes;
Boolean = ISSTOP to false;

HashMap<String,Object> param = new HashMap<String,Object>();

{the try
// query 50 times, a total of 2500
param.put ( "pageSize", pageSize);
// Sort
param.put ( "orderBy", "id asc");

while( queryTimes ++ <= maxTimes){
param.put("pageStart", pageStart);
try{
List<Map<String,Object>> List = new ArrayList<Map<String,Object>>();
Map<String ,Object> map = new HashedMap();
List.add(map);
List<Map<String, Object>> YHOrderList =yhOrderService.queryYHOrder(List,param);

IF (Collections.isEmpty (YHOrderList)) {
logger.info ( "first" + queryTimes + "empty queries to data");
BREAK;
}
logger.info ( "first" + queryTimes + "to record queries:" + YHOrderList .size ());
IF (YHOrderList.size () <50) {
ISSTOP = to true;
}
// save data to a local line voyage
save (YHOrderList);
} the catch (Exception EX) {
ISSTOP = to true;
logger.error ( "", EX);
}
// have no need to update the order data
IF (ISSTOP) {
BREAK;
}
// flip
PageStart + = the pageSize;
}
} the catch (Exception EX) {
logger.error ( "Get Order from voyage data anomalies ", EX);
} {the finally
logger.info (" end -----> order data acquired from voyage end, Processed: "+ (System.currentTimeMillis() - start) + "ms");

}
}

/ **
* Fi authentication timeout
* /
// @Scheduled (fixedRate = 60000)
// public void NetworkConnection () {
//
// logger.info ( "Start -----> Server starts to detect connection status" );
//
// orderService = (OrderService) ApplicationContextUtil.getBean ( "the OrderServiceImpl");
// yhOrderService = (YHOrderService) ApplicationContextUtil.getBean ( "YHOrderServiceImpl");
//
// // start time of the recording system
// long start System.currentTimeMillis = ();
// // record the execution time sql
// Long executeTimes = 0;
// // interrupt flag
// = ISSTOP to false Boolean;
// the try {
// the while (executeTimes ++ <= 60000 ) {
// the try {
// List <the Map <String, Object List >> new new = the ArrayList <the Map <String, Object >> ();
The Map // <String, Object> = new new HashedMap the Map ();
// List.add (the Map);
// List <the Map <String, Object >> YHOrderList = yhOrderService.queryYHOrder (List, param);
// IF ( Collections.isEmpty (YHOrderList)) {
//// logger.info ( "first" + queryTimes + "empty queries to data");
// BREAK;
//}
//// logger.info ( "first" + queryTimes + "to record queries:" + YHOrderList.size ());
// IF (YHOrderList.size () <50) {
// = ISSTOP to true;
//}
//} the catch (Exception EX) {
// ISSTOP to true =;
// logger.error ( "", EX);
//}
// // network interruption ?????
// IF (ISSTOP) {
// bREAK;
//}
//}
//} the catch (Exception EX) {
// logger.error ( "exception the network connection", ex);
// } finally {
// logger.info ( "end -----> Processed Total detecting network connection:" + (System.currentTimeMillis () - Start) + "MS");
//}
//}


/**
* 更新到本地数据库
* @param YHOrderList
*/
// private void updateToDateBase(List<Map<String, Object>> YHOrderList){
//
// try{
// if(YHOrderList == null ||YHOrderList.size()==0){
// return;
// }
// Map<String, List<OrderDO>> map = new HashMap<String, List<OrderDO>>() ;
// List<OrderDO> list = new ArrayList<OrderDO>();
//
// YHOrderList.forEach(jsonObj ->{
// JSONObject json = (JSONObject)jsonObj;
// if(json.get("error") != null){
// return;
// }
//
// String id = json.getString("id");
// String khxm= json.getString("khxm");
// String dh = json.getString("dh");
String = json.getString shdz // ( "shdz");
//
// OrderDO new new OrderDO the Order = ();
// order.setOrderid (the above mentioned id);
// order.setdContact (khxm);
// order.setdTel ( DH);
// order.setdAddress (shdz);
// List.add (Order);
//});
// map.put ( "List", List);
// // saved locally
// Integer rest yhOrderService.saveYHOrder = (List);
// logger.info ( "successfully saved voyage order data into the database:" REST +);
//} the catch (exception EX) {
// logger.error ( "save voyage data line abnormality" , EX);
//}
//}

 

/ **
* Save to local database
* @param OrderList
* /
public void the Save (List <the Map <String, Object >> OrderList) {

// save the bulk of orders voyage data
yhOrderService.batchSaveYHOrder (orderList);

}

}

Guess you like

Origin www.cnblogs.com/pxzbky/p/10995003.html