| | |
| | | package com.ycl.task; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.mongodb.client.result.DeleteResult; |
| | | import com.ycl.feign.PythonClient; |
| | | import com.ycl.feign.UYClient; |
| | | import com.ycl.platform.domain.param.UY.*; |
| | | import com.ycl.platform.domain.result.UY.*; |
| | | import com.ycl.platform.service.ITMonitorService; |
| | | import com.ycl.platform.service.IYwThresholdService; |
| | | import com.ycl.platform.service.UYErrorTypeCheckService; |
| | | import com.ycl.utils.DateUtils; |
| | | import constant.ApiConstants; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * python对接任务 |
| | | * 拿去osd标注、标注时间数据 |
| | | */ |
| | | @Slf4j |
| | | @Component("pythonTask") |
| | | public class PythonTask { |
| | | @Autowired |
| | | private MongoTemplate mongoTemplate; |
| | | @Autowired |
| | | private PythonClient pythonClient; |
| | | @Autowired |
| | | private UYErrorTypeCheckService uyErrorTypeCheckService; |
| | | |
| | | public void pythonOsdTask(){ |
| | | log.info("开始执行pythonOsd数据同步"); |
| | | PyOsdParam pyOsdParam = new PyOsdParam(); |
| | | pyOsdParam.setDate(DateUtils.getDate()); |
| | | Query query = new Query(Criteria.where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | List<MonitorQualifyResult> oneMachineFileResults = mongoTemplate.find(query, MonitorQualifyResult.class); |
| | | if(!CollectionUtils.isEmpty(oneMachineFileResults)) { |
| | | List<String> deviceIdList = oneMachineFileResults.stream().map(result -> result.getSerialNumber().getValue()).collect(Collectors.toList()); |
| | | pyOsdParam.setDeviceNoList(deviceIdList); |
| | | //查询osd标注和时间信息 |
| | | JSONObject jsonObject = pythonClient.pythonOsd(pyOsdParam); |
| | | if (jsonObject != null) { |
| | | if (ApiConstants.UYSuccessCode.equals(jsonObject.getInteger("code"))) { |
| | | List<PyOsdResult> records = jsonObject.getList("data", PyOsdResult.class); |
| | | if (!CollectionUtils.isEmpty(records)) { |
| | | //如果今天存在之前的数据先删除 |
| | | Query pyQuery = new Query(Criteria |
| | | .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | DeleteResult result = mongoTemplate.remove(pyQuery, PyOsdResult.class); |
| | | //存放在mongo中 |
| | | mongoTemplate.insertAll(records); |
| | | // 工单生成 |
| | | uyErrorTypeCheckService.osdCheck(records); |
| | | } |
| | | } else { |
| | | log.error("pythonOsd数据为空{}", jsonObject); |
| | | } |
| | | } |
| | | log.info("结束执行pythonOsd数据同步"); |
| | | } |
| | | } |
| | | } |
| | | //package com.ycl.task; |
| | | // |
| | | //import com.alibaba.fastjson2.JSONObject; |
| | | //import com.mongodb.client.result.DeleteResult; |
| | | //import com.ycl.platform.domain.param.UY.*; |
| | | //import com.ycl.platform.domain.result.UY.*; |
| | | //import com.ycl.platform.service.UYErrorTypeCheckService; |
| | | //import com.ycl.utils.DateUtils; |
| | | //import constant.ApiConstants; |
| | | //import lombok.extern.slf4j.Slf4j; |
| | | //import org.springframework.beans.factory.annotation.Autowired; |
| | | //import org.springframework.data.mongodb.core.MongoTemplate; |
| | | //import org.springframework.data.mongodb.core.query.Criteria; |
| | | //import org.springframework.data.mongodb.core.query.Query; |
| | | //import org.springframework.stereotype.Component; |
| | | //import org.springframework.util.CollectionUtils; |
| | | // |
| | | //import java.util.Date; |
| | | //import java.util.List; |
| | | //import java.util.stream.Collectors; |
| | | // |
| | | ///** |
| | | // * python对接任务 |
| | | // * 拿去osd标注、标注时间数据 |
| | | // */ |
| | | //@Slf4j |
| | | //@Component("pythonTask") |
| | | //public class PythonTask { |
| | | // @Autowired |
| | | // private MongoTemplate mongoTemplate; |
| | | // @Autowired |
| | | // private PythonClient pythonClient; |
| | | // @Autowired |
| | | // private UYErrorTypeCheckService uyErrorTypeCheckService; |
| | | // |
| | | // public void pythonOsdTask(){ |
| | | // log.info("开始执行pythonOsd数据同步"); |
| | | // PyOsdParam pyOsdParam = new PyOsdParam(); |
| | | // pyOsdParam.setDate(DateUtils.getDate()); |
| | | // Query query = new Query(Criteria.where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | // List<MonitorQualifyResult> oneMachineFileResults = mongoTemplate.find(query, MonitorQualifyResult.class); |
| | | // if(!CollectionUtils.isEmpty(oneMachineFileResults)) { |
| | | // List<String> deviceIdList = oneMachineFileResults.stream().map(result -> result.getSerialNumber().getValue()).collect(Collectors.toList()); |
| | | // pyOsdParam.setDeviceNoList(deviceIdList); |
| | | // //查询osd标注和时间信息 |
| | | // JSONObject jsonObject = pythonClient.pythonOsd(pyOsdParam); |
| | | // if (jsonObject != null) { |
| | | // if (ApiConstants.UYSuccessCode.equals(jsonObject.getInteger("code"))) { |
| | | // List<PyOsdResult> records = jsonObject.getList("data", PyOsdResult.class); |
| | | // if (!CollectionUtils.isEmpty(records)) { |
| | | // //如果今天存在之前的数据先删除 |
| | | // Query pyQuery = new Query(Criteria |
| | | // .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); |
| | | // DeleteResult result = mongoTemplate.remove(pyQuery, PyOsdResult.class); |
| | | // //存放在mongo中 |
| | | // mongoTemplate.insertAll(records); |
| | | // // 工单生成 |
| | | // uyErrorTypeCheckService.osdCheck(records); |
| | | // } |
| | | // } else { |
| | | // log.error("pythonOsd数据为空{}", jsonObject); |
| | | // } |
| | | // } |
| | | // log.info("结束执行pythonOsd数据同步"); |
| | | // } |
| | | // } |
| | | //} |