提交 b08b027d authored 作者: huyufan's avatar huyufan

数据大屏接入Mongo

上级 1c6a4b73
...@@ -233,6 +233,11 @@ ...@@ -233,6 +233,11 @@
<artifactId>log-spring-boot-starter</artifactId> <artifactId>log-spring-boot-starter</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
</dependencies> </dependencies>
......
...@@ -61,4 +61,6 @@ public class RabbitKeyConstants { ...@@ -61,4 +61,6 @@ public class RabbitKeyConstants {
public static final String ORDER_CANCEL_ROUTE_KEY ="clx-order.order.cancel.route.key"; public static final String ORDER_CANCEL_ROUTE_KEY ="clx-order.order.cancel.route.key";
public static final String ORDER_LARGE_SCREEN_QUEUE ="clx-order.order.large.screen.queue";
} }
...@@ -51,4 +51,10 @@ public class LargeScreenController { ...@@ -51,4 +51,10 @@ public class LargeScreenController {
return largeScreenService.sendAddress(addressId); return largeScreenService.sendAddress(addressId);
} }
@ApiOperation(value = "线路", notes = "<br>By:胡宇帆")
@GetMapping("/lineString")
public String lineString(@RequestParam(value = "addressId") Integer addressId) {
return largeScreenService.routeLine(addressId);
}
} }
\ No newline at end of file
package com.clx.performance.dao;
import com.clx.performance.mapper.LargeScreenAddressRouteMapper;
import com.clx.performance.model.LargeScreenAddressRoute;
import com.msl.common.base.Optional;
import com.msl.common.dao.BaseDao;
/**
* @author kavin
* Date 2023-11-22
* Time 10:54
*/
public interface LargeScreenAddressRouteDao extends BaseDao<LargeScreenAddressRouteMapper, LargeScreenAddressRoute, Integer> {
Optional<LargeScreenAddressRoute> getEntityByReceiveAddressIdAndSendAddressId(Integer receiveAddressId, Integer sendAddressId);
}
package com.clx.performance.dao.impl;
import com.clx.performance.dao.LargeScreenAddressRouteDao;
import com.clx.performance.enums.PerformanceResultEnum;
import com.clx.performance.mapper.LargeScreenAddressRouteMapper;
import com.clx.performance.model.LargeScreenAddressRoute;
import com.msl.common.base.Optional;
import com.msl.common.dao.impl.BaseDaoImpl;
import org.springframework.stereotype.Repository;
/**
* @author kavin
* Date 2023-11-22
* Time 10:54
*/
@Repository
public class LargeScreenAddressRouteDaoImpl extends BaseDaoImpl<LargeScreenAddressRouteMapper, LargeScreenAddressRoute, Integer> implements LargeScreenAddressRouteDao {
@Override
public Optional<LargeScreenAddressRoute> getEntityByReceiveAddressIdAndSendAddressId(Integer receiveAddressId, Integer sendAddressId) {
return Optional.ofNullable(baseMapper.selectOne(lQrWrapper().eq(LargeScreenAddressRoute::getReceiveSystemAddressId, receiveAddressId)
.eq(LargeScreenAddressRoute::getSendSystemAddressId, sendAddressId)
));
}
}
package com.clx.performance.listener;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.clx.order.feign.AddressFeign;
import com.clx.order.vo.feign.FeignAddressVO;
import com.clx.order.vo.feign.FeignOrderVO;
import com.clx.order.vo.feign.ReceiveAndSendAddressVO;
import com.clx.performance.constant.RabbitKeyConstants;
import com.clx.performance.dao.LargeScreenAddressRouteDao;
import com.clx.performance.dto.gd.GdPosDTO;
import com.clx.performance.dto.gd.GdRouteDTO;
import com.clx.performance.enums.PerformanceResultEnum;
import com.clx.performance.model.Geometry;
import com.clx.performance.model.LargeScreenAddressRoute;
import com.clx.performance.model.MongoLargeScreenAddressRoute;
import com.clx.performance.utils.gd.GdService;
import com.msl.common.base.Optional;
import com.msl.common.result.Result;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.data.geo.Point;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.geo.GeoJsonLineString;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.LinkedList;
import java.util.List;
@Slf4j
@Component
@AllArgsConstructor
public class LargeScreenListener {
private final LargeScreenAddressRouteDao largeScreenAddressRouteDao;
private final GdService gdService;
private final AddressFeign addressFeign;
private final MongoTemplate mongoTemplate;
@RabbitListener(queues = RabbitKeyConstants.ORDER_LARGE_SCREEN_QUEUE)
public void onMessage(String message) {
try {
log.info("处理数据大屏标准地址路线监听器执行,订单为{}", message);
FeignOrderVO orderVO = JSONUtil.toBean(message, FeignOrderVO.class);
if (ObjectUtil.isNull(orderVO.getSendSystemAddressId()) || ObjectUtil.isNull(orderVO.getReveiveSystemAddressId())) {
return;
}
Integer receiveAddressId = orderVO.getReveiveSystemAddressId();
Integer sendAddressId = orderVO.getSendSystemAddressId();
String receiveName = orderVO.getReveiveAddressShorter();
String sendName = orderVO.getSendAddressShorter();
Optional<LargeScreenAddressRoute> optional = largeScreenAddressRouteDao.getEntityByReceiveAddressIdAndSendAddressId(receiveAddressId, sendAddressId);
if (optional.isPresent()) {
return;
}
ReceiveAndSendAddressVO feignAddressVO = Optional.of(addressFeign.getSendAndReceiveSystemAddress(sendAddressId, receiveAddressId)).filter(Result::succeed)
.map(Result::getData).orElseThrow(PerformanceResultEnum.DATA_NOT_FIND);
BigDecimal sendAddressLatitude = feignAddressVO.getSendAddressVo().getLatitude().setScale(4, RoundingMode.DOWN);
BigDecimal sendAddressLongitude = feignAddressVO.getSendAddressVo().getLongitude().setScale(4, RoundingMode.DOWN);
BigDecimal receiveAddressLatitude = feignAddressVO.getReceiveAddressVo().getLatitude().setScale(4, RoundingMode.DOWN);
BigDecimal receiveAddressLongitude = feignAddressVO.getReceiveAddressVo().getLongitude().setScale(4, RoundingMode.DOWN);
List<GdRouteDTO> route = gdService.getRoute(sendAddressLongitude, sendAddressLatitude, receiveAddressLongitude, receiveAddressLatitude);
MongoLargeScreenAddressRoute mongoEntity = new MongoLargeScreenAddressRoute();
mongoEntity.setName(sendName);
mongoEntity.setReceiveSystemAddressId(receiveAddressId);
mongoEntity.setSendSystemAddressId(sendAddressId);
mongoEntity.setValue(sendName);
mongoEntity.setColorField("3");
mongoEntity.setSizeField("3");
mongoEntity.setInfo(receiveName);
List<Point> points = new LinkedList<>();
List<GdPosDTO> posList = route.get(0).getPosList();
for (GdPosDTO gdPosDTO : posList) {
GeoJsonPoint geoJsonPoint = new GeoJsonPoint(new Point(gdPosDTO.getLongitude().doubleValue(), gdPosDTO.getLatitude().doubleValue()));
points.add(geoJsonPoint);
}
mongoEntity.setGeometry(new GeoJsonLineString(points));
mongoTemplate.insert(mongoEntity);
} catch (Exception e) {
}
// LargeScreenAddressRoute build = LargeScreenAddressRoute.builder().receiveSystemAddressId(receiveAddressId)
// .sendSystemAddressId(receiveAddressId)
// .receiveName(receiveName)
// .sendName(sendName)
// .line("").build();
//
// largeScreenAddressRouteDao.saveEntity(build);
}
}
package com.clx.performance.listener; package com.clx.performance.listener;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.clx.performance.constant.RabbitKeyConstants; import com.clx.performance.constant.RabbitKeyConstants;
import com.clx.performance.enums.RoleEnum;
import com.clx.performance.param.pc.OrderCancelParam; import com.clx.performance.param.pc.OrderCancelParam;
import com.clx.performance.service.OrderCancelService; import com.clx.performance.service.OrderCancelService;
import com.clx.performance.service.breakcontract.BreakContractSettlementOwnerService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Objects;
/** /**
* 处理货单取消吨数回填 * 处理货单取消吨数回填
*/ */
@Slf4j @Slf4j
@Component @Component
@AllArgsConstructor @AllArgsConstructor
public class OrderCancelHandler { public class OrderCancelListener {
private final OrderCancelService orderCancelService; private final OrderCancelService orderCancelService;
......
package com.clx.performance.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.clx.performance.model.LargeScreenAddressRoute;
/**
* @author kavin
* Date 2023-11-22
* Time 10:54
*/
public interface LargeScreenAddressRouteMapper extends BaseMapper<LargeScreenAddressRoute> {
}
package com.clx.performance.model;
import lombok.Data;
import org.springframework.data.mongodb.core.geo.GeoJsonLineString;
import java.util.List;
@Data
public class Geometry {
private String type;
private GeoJsonLineString coordinates;
}
package com.clx.performance.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.msl.common.config.KeyColumn;
import com.msl.common.model.HasKey;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
/**
* @author kavin
* Date 2023-11-22
* Time 10:54
*/
@Getter
@Setter
@Accessors(chain = true)
@TableName("large_screen_address_route")
public class LargeScreenAddressRoute implements HasKey<Integer> {
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@TableField("receive_name")
@ApiModelProperty("收货地址")
private String receiveName;
@TableField("send_name")
@ApiModelProperty("发货地址")
private String sendName;
@TableField("receive_system_address_id")
@ApiModelProperty("收货标准地址id")
private Integer receiveSystemAddressId;
@TableField("send_system_address_id")
@ApiModelProperty("发货标准地址id")
private Integer sendSystemAddressId;
@TableField("value")
@ApiModelProperty("数据大屏展示需要")
private String value;
@TableField("size_field")
@ApiModelProperty("数据大屏展示需要")
private String sizeField;
@TableField("color_field")
@ApiModelProperty("数据大屏展示需要")
private String colorField;
@TableField("info")
@ApiModelProperty("数据大屏展示需要")
private String info;
@TableField("line")
@ApiModelProperty("数据大屏展示需要")
private String line;
@Override
@KeyColumn("id")
public Integer gainKey() {
return this.id;
}
}
package com.clx.performance.model;
import lombok.Data;
import org.springframework.data.mongodb.core.geo.GeoJsonLineString;
import org.springframework.data.mongodb.core.mapping.Document;
@Data
@Document(collection = "demo_entity_collection")
public class MongoLargeScreenAddressRoute {
// private Integer id;
private Integer sendSystemAddressId;
private Integer receiveSystemAddressId;
private String name;
private String value;
private String sizeField;
private String colorField;
private String info;
private GeoJsonLineString geometry;
}
...@@ -14,4 +14,6 @@ public interface LargeScreenService { ...@@ -14,4 +14,6 @@ public interface LargeScreenService {
String sendAddress(Integer addressId); String sendAddress(Integer addressId);
String routeLine(Integer addressId);
} }
...@@ -2,6 +2,7 @@ package com.clx.performance.service.impl; ...@@ -2,6 +2,7 @@ package com.clx.performance.service.impl;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.clx.order.feign.AddressFeign; import com.clx.order.feign.AddressFeign;
import com.clx.order.feign.OrderFeign; import com.clx.order.feign.OrderFeign;
import com.clx.order.vo.feign.FeignAddressVO; import com.clx.order.vo.feign.FeignAddressVO;
...@@ -10,6 +11,7 @@ import com.clx.order.vo.feign.SystemAddressVO; ...@@ -10,6 +11,7 @@ import com.clx.order.vo.feign.SystemAddressVO;
import com.clx.performance.dao.OrderChildDao; import com.clx.performance.dao.OrderChildDao;
import com.clx.performance.dto.zjxl.TruckTraceDTO; import com.clx.performance.dto.zjxl.TruckTraceDTO;
import com.clx.performance.enums.PerformanceResultEnum; import com.clx.performance.enums.PerformanceResultEnum;
import com.clx.performance.model.MongoLargeScreenAddressRoute;
import com.clx.performance.model.OrderChild; import com.clx.performance.model.OrderChild;
import com.clx.performance.service.LargeScreenService; import com.clx.performance.service.LargeScreenService;
import com.clx.performance.utils.zjxl.ZjxlGpsService; import com.clx.performance.utils.zjxl.ZjxlGpsService;
...@@ -22,6 +24,10 @@ import lombok.AllArgsConstructor; ...@@ -22,6 +24,10 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.geo.GeoJsonLineString;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -29,6 +35,7 @@ import java.math.RoundingMode; ...@@ -29,6 +35,7 @@ import java.math.RoundingMode;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Random;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
...@@ -47,6 +54,8 @@ public class LargeScreenServiceImpl implements LargeScreenService { ...@@ -47,6 +54,8 @@ public class LargeScreenServiceImpl implements LargeScreenService {
private final OrderFeign orderFeign; private final OrderFeign orderFeign;
private final MongoTemplate mongoTemplate;
@Override @Override
public List<JSONObject> emptyCarList() { public List<JSONObject> emptyCarList() {
List<String> data = driverFeign.driverTruckList().getData(); List<String> data = driverFeign.driverTruckList().getData();
...@@ -145,7 +154,7 @@ public class LargeScreenServiceImpl implements LargeScreenService { ...@@ -145,7 +154,7 @@ public class LargeScreenServiceImpl implements LargeScreenService {
@Override @Override
public String sendAddress(Integer addressId) { public String sendAddress(Integer addressId) {
List<SystemAddressVO> list = Optional.of(orderFeign.getOrderListByReceiveAddressId(addressId)).filter(Result::succeed) List<SystemAddressVO> list = Optional.of(orderFeign.getOrderListByReceiveAddressId(addressId)).filter(Result::succeed)
.map(Result::getData).orElseThrow(PerformanceResultEnum.HTTP_ERROR); .map(Result::getData).orElseThrow(PerformanceResultEnum.DATA_NOT_FIND);
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();
for (SystemAddressVO vo : list) { for (SystemAddressVO vo : list) {
...@@ -165,5 +174,30 @@ public class LargeScreenServiceImpl implements LargeScreenService { ...@@ -165,5 +174,30 @@ public class LargeScreenServiceImpl implements LargeScreenService {
return jsonArray.toString(); return jsonArray.toString();
} }
@Override
public String routeLine(Integer addressId) {
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
Query query = new Query();
query.addCriteria(Criteria.where("receiveSystemAddressId").is(addressId));
List<MongoLargeScreenAddressRoute> routes = mongoTemplate.find(query, MongoLargeScreenAddressRoute.class);
if (CollectionUtils.isEmpty(routes)) {
return null;
}
int randomNum = (int)(Math.random() * routes.size());
MongoLargeScreenAddressRoute route = routes.get(randomNum);
GeoJsonLineString geometry = route.getGeometry();
jsonObject.set("id", "1");
jsonObject.set("name", route.getName());
jsonObject.set("value", route.getValue());
jsonObject.set("sizeField", "3");
jsonObject.set("sizeField", "3");
jsonObject.set("info", "info");
jsonObject.set("geometry", JSONUtil.parse(geometry.getCoordinates()));
jsonArray.add(jsonObject);
return jsonArray.toString();
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论