package com.nanometer.smartlab.api.schedule;
|
|
import com.alibaba.fastjson.JSON;
|
import com.nanometer.smartlab.entity.BaseMeta;
|
import com.nanometer.smartlab.service.*;
|
import com.nanometer.smartlab.util.Constants;
|
import org.apache.commons.lang.time.DateFormatUtils;
|
import org.apache.log4j.Logger;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.MediaType;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
import org.springframework.web.client.RestTemplate;
|
|
import javax.annotation.Resource;
|
import java.text.ParseException;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
|
/**
|
* Created by Caspar on 18/4/22.
|
*/
|
@Component
|
//@EnableScheduling
|
public class ReagentSyncSchedule {
|
|
private static Logger logger = Logger.getLogger(ReagentSyncSchedule.class);
|
|
@Value("${reagent.flow.url}")
|
private String reagentFlowUrl;
|
@Value("${reagent.status.url}")
|
private String reagentStatusUrl;
|
@Value("${sensors.url}")
|
private String reagentSensorsUrl;
|
@Lazy
|
@Resource
|
private BaseMetaService baseMetaService;
|
@Lazy
|
@Resource
|
private OpeReagentStatusService reagentStatusService;
|
@Lazy
|
@Resource
|
private OpeUseFlowService opeUseFlowService;
|
@Lazy
|
@Resource
|
private SysContainerSensorsService sysContainerSensorsService;
|
@Lazy
|
@Resource
|
private SysUserService sysUserService;
|
|
private static String reagentStatusLastdate = null;
|
private static String reagentFlowLastdate = null;
|
|
//@Scheduled(fixedDelayString = "${reagent.status.schedule.delay}")
|
// public void syncReagentStatus(){
|
// Date current = new Date();
|
// BaseMeta baseMeta = null;
|
// baseMeta = baseMetaService.getBaseMeta("syncreagentstatuslastdata");
|
// if(reagentStatusLastdate == null) {
|
// reagentStatusLastdate = baseMeta.getMetaValue();
|
// }
|
//
|
// RestTemplate client = new RestTemplate();
|
// HttpHeaders headers = new HttpHeaders();
|
// headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
// MultiValueMap<String, String> varParams= new LinkedMultiValueMap<String, String>();
|
// varParams.add("startTime",reagentStatusLastdate);
|
// String lastDate = DateFormatUtils.format(current, Constants.TIME_PATTERN_YYYY_MM_DD_HH_MM_SS);
|
// varParams.add("endTime",lastDate);
|
//
|
// logger.info("startTime: "+reagentStatusLastdate+"lastDate "+lastDate);
|
//
|
// HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(varParams, headers);
|
// ResponseEntity<LinkedHashMap> response = client.postForEntity(reagentStatusUrl, requestEntity , LinkedHashMap.class );
|
// List<LinkedHashMap> data = (ArrayList)response.getBody().get("data");
|
// if(CollectionUtils.isEmpty(data)==false){
|
// logger.info("result data: "+ JSON.toJSONString(data));
|
// reagentStatusService.syncOpeReagentStatus(data);
|
// }
|
// reagentStatusLastdate = lastDate;
|
// baseMeta.setMetaValue(reagentStatusLastdate);
|
// baseMetaService.updateBaseMeta(baseMeta);
|
// }
|
//
|
// //@Scheduled(fixedDelayString = "${reagent.flow.schedule.delay}")
|
// public void syncReagentFlow() throws ParseException{
|
// Date current = new Date();
|
// BaseMeta baseMeta = null;
|
// baseMeta = baseMetaService.getBaseMeta("syncreagentflowlastdata");
|
// if(reagentFlowLastdate == null) {
|
// reagentFlowLastdate = baseMeta.getMetaValue();
|
// }
|
//
|
// RestTemplate client = new RestTemplate();
|
// HttpHeaders headers = new HttpHeaders();
|
// headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
// MultiValueMap<String, String> varParams= new LinkedMultiValueMap<String, String>();
|
// varParams.add("startTime",reagentFlowLastdate);
|
// String lastDate = DateFormatUtils.format(current, Constants.TIME_PATTERN_YYYY_MM_DD_HH_MM_SS);
|
// varParams.add("endTime",lastDate);
|
//
|
// logger.info("startTime: "+reagentStatusLastdate+"lastDate "+lastDate);
|
//
|
// HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(varParams, headers);
|
// ResponseEntity<LinkedHashMap> response = client.postForEntity(reagentFlowUrl, requestEntity , LinkedHashMap.class );
|
// List<LinkedHashMap> data = (ArrayList)response.getBody().get("data");
|
// if(CollectionUtils.isEmpty(data)==false){
|
// opeUseFlowService.syncReagentFlow(data);
|
// //[{"status":1,"containerCode":"c1000-001","updateTime":"2018-04-15 11:23:49","reagentCode":"r2010-0001","idcard":"u001"}....]
|
// logger.info("result data: "+JSON.toJSONString(data));
|
// }
|
// baseMeta.setMetaValue(lastDate);
|
// reagentFlowLastdate = lastDate;
|
// baseMetaService.updateBaseMeta(baseMeta);
|
// }
|
//
|
// //@Scheduled(fixedDelayString = "${sensors.schedule.delay}")
|
// public void syncSensors() {
|
// Date current = new Date();
|
// BaseMeta baseMeta = baseMetaService.getBaseMeta("syncsensorslastdata");
|
// RestTemplate client = new RestTemplate();
|
// HttpHeaders headers = new HttpHeaders();
|
// headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
// MultiValueMap<String, String> varParams= new LinkedMultiValueMap<String, String>();
|
// varParams.add("startTime",baseMeta.getMetaValue());
|
// varParams.add("endTime",DateFormatUtils.format(current,Constants.TIME_PATTERN_YYYY_MM_DD_HH_MM_SS));
|
// HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(varParams, headers);
|
// ResponseEntity<LinkedHashMap> response = client.postForEntity(reagentSensorsUrl, requestEntity , LinkedHashMap.class );
|
// LinkedHashMap body = response.getBody();
|
// List<LinkedHashMap> data = body == null ? null : (ArrayList) body.get("data");
|
// if(!CollectionUtils.isEmpty(data)){
|
// try {
|
// logger.info("result data: " + JSON.toJSONString(data));
|
// sysContainerSensorsService.syncSysContainerSensors(data);
|
// //{"data": [{"containerCode": "c1000-003", "Temp": 28.0, "Flag": 16, "Humidity": 58, "updateTime": "2018-04-18 13:37:46", "voc1": 20}], "func": "sensors", "method": "POST", "message": "OK", "code": 0}
|
// baseMeta.setMetaValue(DateFormatUtils.format(current, Constants.TIME_PATTERN_YYYY_MM_DD_HH_MM_SS));
|
// baseMetaService.updateBaseMeta(baseMeta);
|
// }catch (Exception e){
|
// logger.error("error occured.", e);
|
// }
|
// }
|
// }
|
//
|
//
|
// @Scheduled(cron = "0 0 2 1 * ?")
|
// public void updateUserPoint() {
|
// logger.debug("updateUserPoint start,and now is "+new Date());
|
// sysUserService.updateUserPointBySelective(20,null);
|
// logger.debug("updateUserPoint end");
|
// }
|
}
|