|
|
@@ -1,143 +1,143 @@
|
|
|
-package com.aoyang.tms.job;
|
|
|
-
|
|
|
-import com.aoyang.tms.entity.*;
|
|
|
-import com.aoyang.tms.feign.result.TmsMongoDoc;
|
|
|
-import com.aoyang.tms.service.*;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import com.xxl.job.core.biz.model.ReturnT;
|
|
|
-import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
-import com.xxl.job.core.log.XxlJobLogger;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.data.domain.Sort;
|
|
|
-import org.springframework.data.geo.*;
|
|
|
-import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
-import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
-import org.springframework.data.mongodb.core.query.NearQuery;
|
|
|
-import org.springframework.data.mongodb.core.query.Query;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-/**
|
|
|
- * @Description: 围栏位置自动检查定时任务
|
|
|
- * @version: v1.0.0
|
|
|
- * @date: 2021-06-10 13:35:44
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-@Component
|
|
|
-public class SpotCheckJob {
|
|
|
-
|
|
|
- @Resource
|
|
|
- private WorkCycleService workCycleService;
|
|
|
- @Resource
|
|
|
- private WorkOrderService workOrderService;
|
|
|
- @Resource
|
|
|
- private TruckService truckService;
|
|
|
- @Resource
|
|
|
- private WorkSpotService workSpotService;
|
|
|
- @Resource
|
|
|
- private TruckSimCardService truckSimCardService;
|
|
|
- @Resource
|
|
|
- private MongoTemplate mongoTemplate;
|
|
|
- @Resource
|
|
|
- private CommonService commonService;
|
|
|
-
|
|
|
- /**
|
|
|
- * 围栏位置自动检查定时任务
|
|
|
- */
|
|
|
- @XxlJob("spotCheckHandler")
|
|
|
- public ReturnT<String> SpotCheckHandler(String param) throws Exception {
|
|
|
- log.info("围栏位置信息检查 SpotCheckJob. {}", param);
|
|
|
- // TODO 物流客户
|
|
|
- Long orgId = null;
|
|
|
- long startTime = System.currentTimeMillis();
|
|
|
- XxlJobLogger.log("spotCheckHandler is start ");
|
|
|
- List<Truck> truckList = truckService.list(new QueryWrapper<Truck>().eq("org_id", orgId).eq("status", 0));
|
|
|
- for (Truck truck : truckList) {
|
|
|
- try {
|
|
|
- Long truckId = truck.getTruckId();
|
|
|
- TruckSimCard truckSimCard = truckSimCardService.getOne(new QueryWrapper<TruckSimCard>().eq("truck_id", truckId));
|
|
|
- if (truckSimCard == null) {
|
|
|
- log.info("车辆{} 不存在simcard信息.", truck.getCarNumber());
|
|
|
- continue;
|
|
|
- }
|
|
|
- QueryWrapper<WorkCycle> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("truck_id", truckId);
|
|
|
- queryWrapper.eq("status", 1);
|
|
|
- WorkCycle workCycle = workCycleService.getOne(queryWrapper);
|
|
|
- if (workCycle == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- List<WorkOrder> workOrders = workOrderService.list(new QueryWrapper<WorkOrder>().eq("cycle_id", workCycle.getId()));
|
|
|
- for (WorkOrder workOrder : workOrders) {
|
|
|
- if (workOrder.getLeaveTime() != null) {
|
|
|
- // 已离开围栏
|
|
|
- continue;
|
|
|
- }
|
|
|
- LocalDateTime workStartTime = workOrder.getWorkStartTime();
|
|
|
- WorkSpot spot = workSpotService.getById(workOrder.getSpotId());
|
|
|
- String latitude = spot.getLatitude();
|
|
|
- String longitude = spot.getLongitude();
|
|
|
- Point point = new Point(Double.valueOf(longitude), Double.valueOf(latitude));
|
|
|
- if (workOrder.getEnterTime() == null) {
|
|
|
- // 未进入围栏
|
|
|
- Criteria criteria = Criteria.where("clientId").is(truckSimCard.getClientId());
|
|
|
- criteria.andOperator(Criteria.where("createTime").gt(workStartTime));
|
|
|
- Query query = new Query(criteria);
|
|
|
- query.with(new Sort(Sort.Direction.ASC, "dateTime"));
|
|
|
- NearQuery nearQuery = NearQuery.near(point).query(query)
|
|
|
- .maxDistance(new Distance(spot.getValidDistance(), Metrics.KILOMETERS))
|
|
|
- .num(1);
|
|
|
- GeoResults<TmsMongoDoc> geoResults = mongoTemplate.geoNear(nearQuery, TmsMongoDoc.class);
|
|
|
- if (geoResults == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- List<GeoResult<TmsMongoDoc>> content = geoResults.getContent();
|
|
|
- if (content == null || content.size() == 0) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- TmsMongoDoc loc = content.get(0).getContent();
|
|
|
- // 设置WorkOrder出入围栏标识
|
|
|
- workOrder.setEnterTime(loc.getCreateTime());
|
|
|
- workOrderService.updateById(workOrder);
|
|
|
- // TODO 记录行车日志
|
|
|
-
|
|
|
- } else if (workOrder.getLeaveTime() == null) {
|
|
|
- // 已进入围栏 无进入围栏标识,则无需判断离开围栏
|
|
|
- Query query = new Query(Criteria.where("clientId").is(truckSimCard.getClientId()));
|
|
|
- query.with(new Sort(Sort.Direction.DESC, "dateTime"));
|
|
|
- query.limit(10);
|
|
|
- NearQuery nearQuery = NearQuery.near(point).query(query).num(1)
|
|
|
- .maxDistance(new Distance(spot.getValidDistance(), Metrics.KILOMETERS));
|
|
|
- GeoResults<TmsMongoDoc> geoResults = mongoTemplate.geoNear(nearQuery, TmsMongoDoc.class);
|
|
|
- if (geoResults == null || geoResults.getContent() == null || geoResults.getContent().size() == 0) {
|
|
|
- // 设置WorkOrder出入围栏标识
|
|
|
- workOrder.setEnterTime(LocalDateTime.now());
|
|
|
- workOrderService.updateById(workOrder);
|
|
|
- // TODO 记录行车日志
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("围栏位置自动检查定时任务异常 truck:{} msg:{}", truck.getCarNumber(), e);
|
|
|
- throw e;
|
|
|
- }
|
|
|
- }
|
|
|
- workCycleService.list();
|
|
|
- long endTime = System.currentTimeMillis();
|
|
|
- XxlJobLogger.log("spotCheckHandler finish. cost:{} sec", (endTime - startTime)/1000);
|
|
|
- log.info("围栏位置信息检查 SpotCheckJob completed. cost:{} sec", (endTime - startTime)/1000);
|
|
|
- return ReturnT.SUCCESS;
|
|
|
- }
|
|
|
-
|
|
|
- private TmsMongoDoc getGeoNear() {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+//package com.aoyang.tms.job;
|
|
|
+//
|
|
|
+//import com.aoyang.tms.entity.*;
|
|
|
+//import com.aoyang.tms.feign.result.TmsMongoDoc;
|
|
|
+//import com.aoyang.tms.service.*;
|
|
|
+//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+//import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+//import com.xxl.job.core.biz.model.ReturnT;
|
|
|
+//import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
+//import com.xxl.job.core.log.XxlJobLogger;
|
|
|
+//import lombok.extern.slf4j.Slf4j;
|
|
|
+//import org.springframework.data.domain.Sort;
|
|
|
+//import org.springframework.data.geo.*;
|
|
|
+//import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
+//import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
+//import org.springframework.data.mongodb.core.query.NearQuery;
|
|
|
+//import org.springframework.data.mongodb.core.query.Query;
|
|
|
+//import org.springframework.stereotype.Component;
|
|
|
+//
|
|
|
+//import javax.annotation.Resource;
|
|
|
+//import java.time.LocalDateTime;
|
|
|
+//import java.util.List;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * @Description: 围栏位置自动检查定时任务
|
|
|
+// * @version: v1.0.0
|
|
|
+// * @date: 2021-06-10 13:35:44
|
|
|
+// */
|
|
|
+//@Slf4j
|
|
|
+//@Component
|
|
|
+//public class SpotCheckJob {
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// private WorkCycleService workCycleService;
|
|
|
+// @Resource
|
|
|
+// private WorkOrderService workOrderService;
|
|
|
+// @Resource
|
|
|
+// private TruckService truckService;
|
|
|
+// @Resource
|
|
|
+// private WorkSpotService workSpotService;
|
|
|
+// @Resource
|
|
|
+// private TruckSimCardService truckSimCardService;
|
|
|
+// @Resource
|
|
|
+// private MongoTemplate mongoTemplate;
|
|
|
+// @Resource
|
|
|
+// private CommonService commonService;
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 围栏位置自动检查定时任务
|
|
|
+// */
|
|
|
+// @XxlJob("spotCheckHandler")
|
|
|
+// public ReturnT<String> SpotCheckHandler(String param) throws Exception {
|
|
|
+// log.info("围栏位置信息检查 SpotCheckJob. {}", param);
|
|
|
+// // TODO 物流客户
|
|
|
+// Long orgId = null;
|
|
|
+// long startTime = System.currentTimeMillis();
|
|
|
+// XxlJobLogger.log("spotCheckHandler is start ");
|
|
|
+// List<Truck> truckList = truckService.list(new QueryWrapper<Truck>().eq("org_id", orgId).eq("status", 0));
|
|
|
+// for (Truck truck : truckList) {
|
|
|
+// try {
|
|
|
+// Long truckId = truck.getTruckId();
|
|
|
+// TruckSimCard truckSimCard = truckSimCardService.getOne(new QueryWrapper<TruckSimCard>().eq("truck_id", truckId));
|
|
|
+// if (truckSimCard == null) {
|
|
|
+// log.info("车辆{} 不存在simcard信息.", truck.getCarNumber());
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// QueryWrapper<WorkCycle> queryWrapper = new QueryWrapper<>();
|
|
|
+// queryWrapper.eq("truck_id", truckId);
|
|
|
+// queryWrapper.eq("status", 1);
|
|
|
+// WorkCycle workCycle = workCycleService.getOne(queryWrapper);
|
|
|
+// if (workCycle == null) {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// List<WorkOrder> workOrders = workOrderService.list(new QueryWrapper<WorkOrder>().eq("cycle_id", workCycle.getId()));
|
|
|
+// for (WorkOrder workOrder : workOrders) {
|
|
|
+// if (workOrder.getLeaveTime() != null) {
|
|
|
+// // 已离开围栏
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// LocalDateTime workStartTime = workOrder.getWorkStartTime();
|
|
|
+// WorkSpot spot = workSpotService.getById(workOrder.getSpotId());
|
|
|
+// String latitude = spot.getLatitude();
|
|
|
+// String longitude = spot.getLongitude();
|
|
|
+// Point point = new Point(Double.valueOf(longitude), Double.valueOf(latitude));
|
|
|
+// if (workOrder.getEnterTime() == null) {
|
|
|
+// // 未进入围栏
|
|
|
+// Criteria criteria = Criteria.where("clientId").is(truckSimCard.getClientId());
|
|
|
+// criteria.andOperator(Criteria.where("createTime").gt(workStartTime));
|
|
|
+// Query query = new Query(criteria);
|
|
|
+// query.with(new Sort(Sort.Direction.ASC, "dateTime"));
|
|
|
+// NearQuery nearQuery = NearQuery.near(point).query(query)
|
|
|
+// .maxDistance(new Distance(spot.getValidDistance(), Metrics.KILOMETERS))
|
|
|
+// .num(1);
|
|
|
+// GeoResults<TmsMongoDoc> geoResults = mongoTemplate.geoNear(nearQuery, TmsMongoDoc.class);
|
|
|
+// if (geoResults == null) {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// List<GeoResult<TmsMongoDoc>> content = geoResults.getContent();
|
|
|
+// if (content == null || content.size() == 0) {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// TmsMongoDoc loc = content.get(0).getContent();
|
|
|
+// // 设置WorkOrder出入围栏标识
|
|
|
+// workOrder.setEnterTime(loc.getCreateTime());
|
|
|
+// workOrderService.updateById(workOrder);
|
|
|
+// // TODO 记录行车日志
|
|
|
+//
|
|
|
+// } else if (workOrder.getLeaveTime() == null) {
|
|
|
+// // 已进入围栏 无进入围栏标识,则无需判断离开围栏
|
|
|
+// Query query = new Query(Criteria.where("clientId").is(truckSimCard.getClientId()));
|
|
|
+// query.with(new Sort(Sort.Direction.DESC, "dateTime"));
|
|
|
+// query.limit(10);
|
|
|
+// NearQuery nearQuery = NearQuery.near(point).query(query).num(1)
|
|
|
+// .maxDistance(new Distance(spot.getValidDistance(), Metrics.KILOMETERS));
|
|
|
+// GeoResults<TmsMongoDoc> geoResults = mongoTemplate.geoNear(nearQuery, TmsMongoDoc.class);
|
|
|
+// if (geoResults == null || geoResults.getContent() == null || geoResults.getContent().size() == 0) {
|
|
|
+// // 设置WorkOrder出入围栏标识
|
|
|
+// workOrder.setEnterTime(LocalDateTime.now());
|
|
|
+// workOrderService.updateById(workOrder);
|
|
|
+// // TODO 记录行车日志
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("围栏位置自动检查定时任务异常 truck:{} msg:{}", truck.getCarNumber(), e);
|
|
|
+// throw e;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// workCycleService.list();
|
|
|
+// long endTime = System.currentTimeMillis();
|
|
|
+// XxlJobLogger.log("spotCheckHandler finish. cost:{} sec", (endTime - startTime)/1000);
|
|
|
+// log.info("围栏位置信息检查 SpotCheckJob completed. cost:{} sec", (endTime - startTime)/1000);
|
|
|
+// return ReturnT.SUCCESS;
|
|
|
+// }
|
|
|
+//
|
|
|
+// private TmsMongoDoc getGeoNear() {
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+//
|
|
|
+//}
|