| | |
| | | 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; |
| | |
| | | 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 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"); |
| | | } |
| | | // 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"); |
| | | // } |
| | | } |