init
This commit is contained in:
3
sl-express-ms-transport-service/.gitignore
vendored
Normal file
3
sl-express-ms-transport-service/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.idea
|
||||
target/
|
||||
*.iml
|
13
sl-express-ms-transport-service/Dockerfile
Normal file
13
sl-express-ms-transport-service/Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
||||
FROM openjdk:11-jdk
|
||||
LABEL maintainer="研究院研发组 <research@itcast.cn>"
|
||||
|
||||
# 时区修改为东八区
|
||||
ENV TZ=Asia/Shanghai
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
WORKDIR /app
|
||||
ARG JAR_FILE=target/*.jar
|
||||
ADD ${JAR_FILE} app.jar
|
||||
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["sh","-c","java -Djava.security.egd=file:/dev/./urandom -jar $JAVA_OPTS app.jar"]
|
102
sl-express-ms-transport-service/pom.xml
Normal file
102
sl-express-ms-transport-service/pom.xml
Normal file
@@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.sl-express</groupId>
|
||||
<artifactId>sl-express-parent</artifactId>
|
||||
<version>1.4</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.sl-express.ms.transport</groupId>
|
||||
<artifactId>sl-express-ms-transport-service</artifactId>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
<description>线路规划微服务</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<sl-express-common.version>1.2-SNAPSHOT</sl-express-common.version>
|
||||
<sl-express-ms-transport-domain.version>1.1-SNAPSHOT</sl-express-ms-transport-domain.version>
|
||||
<sl-express-ms-mq.version>1.1-SNAPSHOT</sl-express-ms-mq.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.sl-express.common</groupId>
|
||||
<artifactId>sl-express-common</artifactId>
|
||||
<version>${sl-express-common.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sl-express.ms.transport</groupId>
|
||||
<artifactId>sl-express-ms-transport-domain</artifactId>
|
||||
<version>${sl-express-ms-transport-domain.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sl-express.mq</groupId>
|
||||
<artifactId>sl-express-mq</artifactId>
|
||||
<version>${sl-express-ms-mq.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-neo4j</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itheima.em</groupId>
|
||||
<artifactId>eaglemap-spring-boot-starter</artifactId>
|
||||
<version>${eaglemap.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
<goal>build-info</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<!--指定主类-->
|
||||
<mainClass>com.sl.TransportApplication</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@@ -0,0 +1,18 @@
|
||||
package com.sl;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class TransportApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TransportApplication.class, args);
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package com.sl.transport.controller;
|
||||
|
||||
import com.sl.transport.domain.CostConfigurationDTO;
|
||||
import com.sl.transport.service.CostConfigurationService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 成本配置相关业务对外提供接口服务
|
||||
*
|
||||
* @author wxb
|
||||
* @version 1.0
|
||||
*/
|
||||
@Api(tags = "成本配置")
|
||||
@RequestMapping("cost-configuration")
|
||||
@Validated
|
||||
@RestController
|
||||
public class CostConfigurationController {
|
||||
@Resource
|
||||
private CostConfigurationService costConfigurationService;
|
||||
|
||||
@ApiOperation(value = "查询成本配置")
|
||||
@GetMapping
|
||||
public List<CostConfigurationDTO> findConfiguration() {
|
||||
return costConfigurationService.findConfiguration();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "保存成本配置")
|
||||
@PostMapping
|
||||
public void saveConfiguration(@RequestBody List<CostConfigurationDTO> dto) {
|
||||
costConfigurationService.saveConfiguration(dto);
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package com.sl.transport.controller;
|
||||
|
||||
import com.sl.transport.domain.DispatchConfigurationDTO;
|
||||
import com.sl.transport.service.DispatchConfigurationService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 调度配置相关业务对外提供接口服务
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
@Api(tags = "调度配置")
|
||||
@RequestMapping("dispatch-configuration")
|
||||
@Validated
|
||||
@RestController
|
||||
public class DispatchConfigurationController {
|
||||
@Resource
|
||||
private DispatchConfigurationService dispatchConfigurationService;
|
||||
|
||||
@ApiOperation(value = "查询调度配置")
|
||||
@GetMapping
|
||||
public DispatchConfigurationDTO findConfiguration() {
|
||||
return dispatchConfigurationService.findConfiguration();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "保存调度配置")
|
||||
@PostMapping
|
||||
public void saveConfiguration(@RequestBody DispatchConfigurationDTO dto) {
|
||||
dispatchConfigurationService.saveConfiguration(dto);
|
||||
}
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
package com.sl.transport.controller;
|
||||
|
||||
import com.sl.transport.common.exception.SLException;
|
||||
import com.sl.transport.domain.OrganDTO;
|
||||
import com.sl.transport.entity.node.BaseEntity;
|
||||
import com.sl.transport.service.OrganService;
|
||||
import com.sl.transport.utils.OrganServiceFactory;
|
||||
import com.sl.transport.utils.OrganUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 对外提供机构服务,机构、一级转运中心、二级转运中心统称为机构
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
@Api(tags = "机构服务")
|
||||
@RequestMapping("organs")
|
||||
@Validated
|
||||
@RestController
|
||||
public class OrganController {
|
||||
|
||||
@Resource
|
||||
private OrganService organService;
|
||||
|
||||
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "机构id", dataTypeClass = String.class)
|
||||
})
|
||||
@ApiOperation(value = "查询", notes = "根据业务id查询机构数据")
|
||||
@GetMapping("{id}")
|
||||
public OrganDTO queryById(@NotNull(message = "id不能为空") @PathVariable("id") Long id) {
|
||||
return this.organService.findByBid(id);
|
||||
}
|
||||
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "ids", value = "机构ids", dataTypeClass = String.class)
|
||||
})
|
||||
@ApiOperation(value = "批量查询", notes = "根据业务ids查询机构数据")
|
||||
@GetMapping("/ids")
|
||||
public List<OrganDTO> queryByIds(@NotNull(message = "ids不能为空") @RequestParam("ids") List<Long> ids) {
|
||||
return this.organService.findByBids(ids);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "更新", notes = "更新机构")
|
||||
@PutMapping
|
||||
public void update(@RequestBody OrganDTO organDTO) {
|
||||
BaseEntity entity = OrganUtils.toEntity(organDTO);
|
||||
BaseEntity entityData = OrganServiceFactory.getBean(organDTO.getType()).update(entity);
|
||||
if (null == entityData) {
|
||||
throw new SLException("更新机构失败!", HttpStatus.INTERNAL_SERVER_ERROR.value());
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询所有的机构", notes = "查询所有的机构,如果name不为空的按照name模糊查询")
|
||||
@GetMapping("all")
|
||||
public List<OrganDTO> findAll(@RequestParam(value = "name", required = false) String name) {
|
||||
return this.organService.findAll(name);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询机构树", notes = "查询机构树")
|
||||
@GetMapping("tree")
|
||||
public String findAllTree() {
|
||||
return this.organService.findAllTree();
|
||||
}
|
||||
}
|
@@ -0,0 +1,136 @@
|
||||
package com.sl.transport.controller;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.sl.transport.common.exception.SLException;
|
||||
import com.sl.transport.common.util.PageResponse;
|
||||
import com.sl.transport.domain.TransportLineDTO;
|
||||
import com.sl.transport.domain.TransportLineNodeDTO;
|
||||
import com.sl.transport.domain.TransportLineSearchDTO;
|
||||
import com.sl.transport.entity.line.TransportLine;
|
||||
import com.sl.transport.service.TransportLineService;
|
||||
import com.sl.transport.utils.TransportLineUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 物流路线相关业务对外提供接口服务
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
@Api(tags = "物流路线")
|
||||
@RequestMapping("transports")
|
||||
@Validated
|
||||
@RestController
|
||||
public class TransportLineController {
|
||||
|
||||
@Resource
|
||||
private TransportLineService transportLineService;
|
||||
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "startId", value = "开始网点业务id", required = true),
|
||||
@ApiImplicitParam(name = "endId", value = "结束网点业务id", required = true)
|
||||
})
|
||||
@ApiOperation(value = "最短的路线", notes = "查询两个网点之间最短的路线,最大查询深度为:10")
|
||||
@GetMapping("{startId}/{endId}")
|
||||
public TransportLineNodeDTO queryShortestPath(@NotNull(message = "startId不能为空") @PathVariable("startId") Long startId,
|
||||
@NotNull(message = "endId不能为空") @PathVariable("endId") Long endId) {
|
||||
return this.transportLineService.queryShortestPath(startId, endId);
|
||||
}
|
||||
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "startId", value = "开始网点业务id", required = true),
|
||||
@ApiImplicitParam(name = "endId", value = "结束网点业务id", required = true)
|
||||
})
|
||||
@ApiOperation(value = "成本最低的路线", notes = "查询两个网点之间成本最低的路线,最大查询深度为:10")
|
||||
@GetMapping("lowest/{startId}/{endId}")
|
||||
public TransportLineNodeDTO findLowestPath(@NotNull(message = "startId不能为空") @PathVariable("startId") Long startId,
|
||||
@NotNull(message = "endId不能为空") @PathVariable("endId") Long endId) {
|
||||
return this.transportLineService.findLowestPath(startId, endId);
|
||||
}
|
||||
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "startId", value = "开始网点业务id", required = true),
|
||||
@ApiImplicitParam(name = "endId", value = "结束网点业务id", required = true)
|
||||
})
|
||||
@ApiOperation(value = "根据调度策略查询路线", notes = "根据调度策略选择最短路线或者成本最低路线")
|
||||
@GetMapping("/dispatchMethod/{startId}/{endId}")
|
||||
public TransportLineNodeDTO queryPathByDispatchMethod(@NotNull(message = "startId不能为空") @PathVariable("startId") Long startId,
|
||||
@NotNull(message = "endId不能为空") @PathVariable("endId") Long endId) {
|
||||
return this.transportLineService.queryPathByDispatchMethod(startId, endId);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增路线", notes = "新增路线,干线:起点终点无顺序,支线:起点必须是二级转运中心,接驳路线:起点必须是网点")
|
||||
@PostMapping
|
||||
public void createLine(@RequestBody TransportLineDTO transportLineDTO) {
|
||||
TransportLine transportLine = TransportLineUtils.toEntity(transportLineDTO);
|
||||
Boolean result = this.transportLineService.createLine(transportLine);
|
||||
if (!result) {
|
||||
throw new SLException("新增路线失败!", HttpStatus.INTERNAL_SERVER_ERROR.value());
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "更新路线", notes = "更新路线,可更新字段:cost、name、distance、time、extra,更新数据时id不能为空")
|
||||
@PutMapping
|
||||
public void updateLine(@RequestBody TransportLineDTO transportLineDTO) {
|
||||
TransportLine transportLine = TransportLineUtils.toEntity(transportLineDTO);
|
||||
Boolean result = this.transportLineService.updateLine(transportLine);
|
||||
if (!result) {
|
||||
throw new SLException("更新路线失败!", HttpStatus.INTERNAL_SERVER_ERROR.value());
|
||||
}
|
||||
}
|
||||
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "路线id", required = true)
|
||||
})
|
||||
@ApiOperation(value = "删除路线", notes = "删除路线,单向删除")
|
||||
@DeleteMapping("{id}")
|
||||
public void deleteLine(@PathVariable("id") Long id) {
|
||||
Boolean result = this.transportLineService.deleteLine(id);
|
||||
if (!result) {
|
||||
throw new SLException("更新路线失败!", HttpStatus.INTERNAL_SERVER_ERROR.value());
|
||||
}
|
||||
}
|
||||
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "路线id", required = true)
|
||||
})
|
||||
@ApiOperation(value = "根据id查询路线", notes = "根据id查询路线")
|
||||
@GetMapping("{id}")
|
||||
public TransportLineDTO queryById(@PathVariable("id") Long id) {
|
||||
TransportLine transportLine = this.transportLineService.queryById(id);
|
||||
return TransportLineUtils.toDTO(transportLine);
|
||||
}
|
||||
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "ids", value = "路线id列表", required = true)
|
||||
})
|
||||
@ApiOperation(value = "根据ids批量查询路线", notes = "根据ids批量查询路线")
|
||||
@GetMapping("list")
|
||||
public List<TransportLineDTO> queryByIds(@Size(min = 1, message = "至少要传入1个id") @RequestParam("ids") Long[] ids) {
|
||||
List<TransportLine> list = this.transportLineService.queryByIds(ids);
|
||||
return TransportLineUtils.toDTOList(list);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "分页查询路线", notes = "分页查询路线,如果有条件就进行筛选查询")
|
||||
@PostMapping("page")
|
||||
public PageResponse<TransportLineDTO> queryPageList(@RequestBody TransportLineSearchDTO transportLineSearchDTO) {
|
||||
PageResponse<TransportLine> pageResponse = this.transportLineService.queryPageList(transportLineSearchDTO);
|
||||
|
||||
PageResponse<TransportLineDTO> result = new PageResponse<>();
|
||||
BeanUtil.copyProperties(pageResponse, result, "items");
|
||||
result.setItems(TransportLineUtils.toDTOList(pageResponse.getItems()));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package com.sl.transport.entity.line;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 运输路线实体
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TransportLine {
|
||||
|
||||
private Long id;
|
||||
private String number; // 编号
|
||||
private Double cost; //成本
|
||||
private Integer type; //类型
|
||||
private String name; //路线名称
|
||||
private Double distance; //距离,单位:米
|
||||
private Long time; //时间,单位:秒
|
||||
private Long created; //创建时间
|
||||
private Long updated; //修改时间
|
||||
private String extra; //扩展字段,以json格式存储
|
||||
private Long startOrganId; //起点机构id
|
||||
private String startOrganName; //起点机构名称,只有在查询时返回
|
||||
private Long endOrganId; //终点机构id
|
||||
private String endOrganName; //终点机构名称,只有在查询时返回
|
||||
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package com.sl.transport.entity.node;
|
||||
|
||||
import com.sl.transport.enums.OrganTypeEnum;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.springframework.data.neo4j.core.schema.Node;
|
||||
|
||||
/**
|
||||
* 网点实体
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
@Node("AGENCY")
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@SuperBuilder(toBuilder = true)
|
||||
@NoArgsConstructor
|
||||
public class AgencyEntity extends BaseEntity {
|
||||
|
||||
@Override
|
||||
public OrganTypeEnum getAgencyType() {
|
||||
return OrganTypeEnum.AGENCY;
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
package com.sl.transport.entity.node;
|
||||
|
||||
import com.sl.transport.enums.OrganTypeEnum;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.springframework.data.geo.Point;
|
||||
import org.springframework.data.neo4j.core.schema.GeneratedValue;
|
||||
import org.springframework.data.neo4j.core.schema.Id;
|
||||
|
||||
/**
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder(toBuilder = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public abstract class BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@ApiModelProperty(value = "Neo4j ID", hidden = true)
|
||||
private Long id;
|
||||
@ApiModelProperty(value = "父节点id", required = true)
|
||||
private Long parentId;
|
||||
@ApiModelProperty(value = "业务id", required = true)
|
||||
private Long bid;
|
||||
@ApiModelProperty(value = "名称", required = true)
|
||||
private String name;
|
||||
@ApiModelProperty(value = "负责人", required = true)
|
||||
private String managerName;
|
||||
@ApiModelProperty(value = "电话", required = true)
|
||||
private String phone;
|
||||
@ApiModelProperty(value = "地址", required = true)
|
||||
private String address;
|
||||
@ApiModelProperty(value = "位置坐标, x: 纬度,y: 经度", required = true)
|
||||
private Point location;
|
||||
@ApiModelProperty(value = "是否可用", required = true)
|
||||
private Boolean status;
|
||||
@ApiModelProperty(value = "扩展字段,以json格式存储")
|
||||
private String extra;
|
||||
|
||||
//机构类型
|
||||
public abstract OrganTypeEnum getAgencyType();
|
||||
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package com.sl.transport.entity.node;
|
||||
|
||||
import com.sl.transport.enums.OrganTypeEnum;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.springframework.data.neo4j.core.schema.Node;
|
||||
|
||||
/**
|
||||
* 一级转运中心实体 (OneLevelTransportEntity)
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
@Node("OLT")
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@SuperBuilder(toBuilder = true)
|
||||
@NoArgsConstructor
|
||||
public class OLTEntity extends BaseEntity {
|
||||
|
||||
@Override
|
||||
public OrganTypeEnum getAgencyType() {
|
||||
return OrganTypeEnum.OLT;
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package com.sl.transport.entity.node;
|
||||
|
||||
import com.sl.transport.enums.OrganTypeEnum;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.springframework.data.neo4j.core.schema.Node;
|
||||
|
||||
/**
|
||||
* 二级转运中心实体(TwoLevelTransportEntity)
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
@Node("TLT")
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@SuperBuilder(toBuilder = true)
|
||||
@NoArgsConstructor
|
||||
public class TLTEntity extends BaseEntity {
|
||||
|
||||
@Override
|
||||
public OrganTypeEnum getAgencyType() {
|
||||
return OrganTypeEnum.TLT;
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
package com.sl.transport.enums;
|
||||
|
||||
import cn.hutool.core.util.EnumUtil;
|
||||
import com.sl.transport.common.enums.BaseExceptionEnum;
|
||||
|
||||
/**
|
||||
* 异常枚举
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public enum ExceptionEnum implements BaseExceptionEnum {
|
||||
|
||||
ORGAN_NOT_FOUND(1001, "机构不存在"),
|
||||
START_END_ORGAN_NOT_FOUND(1002, "起点、终点机构不能为空"),
|
||||
TRANSPORT_LINE_ALREADY_EXISTS(1003, "路线已经存在"),
|
||||
TRANSPORT_LINE_NOT_FOUND(1004, "路线不存在"),
|
||||
TRANSPORT_LINE_TYPE_ERROR(1005, "路线类型错误"),
|
||||
ORGAN_TYPE_ERROR(1006, "机构类型错误");
|
||||
|
||||
private Integer code;
|
||||
private Integer status;
|
||||
private String value;
|
||||
|
||||
ExceptionEnum(Integer code, String value) {
|
||||
this.code = code;
|
||||
this.value = value;
|
||||
this.status = 500;
|
||||
}
|
||||
|
||||
ExceptionEnum(Integer code, Integer status, String value) {
|
||||
this.code = code;
|
||||
this.value = value;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public static ExceptionEnum codeOf(Integer code) {
|
||||
return EnumUtil.getBy(ExceptionEnum::getCode, code);
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
package com.sl.transport.enums;
|
||||
|
||||
import cn.hutool.core.util.EnumUtil;
|
||||
import com.sl.transport.common.enums.BaseEnum;
|
||||
|
||||
/**
|
||||
* 机构类型枚举
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public enum OrganTypeEnum implements BaseEnum {
|
||||
|
||||
OLT(1, "一级转运中心"),
|
||||
TLT(2, "二级转运中心"),
|
||||
AGENCY(3, "网点");
|
||||
|
||||
/**
|
||||
* 类型编码
|
||||
*/
|
||||
private final Integer code;
|
||||
|
||||
/**
|
||||
* 类型值
|
||||
*/
|
||||
private final String value;
|
||||
|
||||
OrganTypeEnum(Integer code, String value) {
|
||||
this.code = code;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static OrganTypeEnum codeOf(Integer code) {
|
||||
return EnumUtil.getBy(OrganTypeEnum::getCode, code);
|
||||
}
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
package com.sl.transport.enums;
|
||||
|
||||
import cn.hutool.core.util.EnumUtil;
|
||||
import com.sl.transport.common.enums.BaseEnum;
|
||||
|
||||
/**
|
||||
* 路线类型枚举
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public enum TransportLineEnum implements BaseEnum {
|
||||
|
||||
TRUNK_LINE(1, "干线", "一级转运中心到一级转运中心"),
|
||||
BRANCH_LINE(2, "支线", "一级转运中心与二级转运中心之间线路"),
|
||||
CONNECT_LINE(3, "接驳路线", "二级转运中心到网点"),
|
||||
SPECIAL_LINE(4, "专线", "任务城市到任意城市"),
|
||||
TEMP_LINE(5, "临时线路", "任意转运中心到任意转运中心");
|
||||
|
||||
/**
|
||||
* 类型编码
|
||||
*/
|
||||
private final Integer code;
|
||||
|
||||
/**
|
||||
* 类型值
|
||||
*/
|
||||
private final String value;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private final String desc;
|
||||
|
||||
TransportLineEnum(Integer code, String value, String desc) {
|
||||
this.code = code;
|
||||
this.value = value;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public static TransportLineEnum codeOf(Integer code) {
|
||||
return EnumUtil.getBy(TransportLineEnum::getCode, code);
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package com.sl.transport.repository;
|
||||
|
||||
import com.sl.transport.entity.node.AgencyEntity;
|
||||
|
||||
/**
|
||||
* 网点数据操作
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface AgencyRepository extends BaseRepository<AgencyEntity, Long> {
|
||||
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package com.sl.transport.repository;
|
||||
|
||||
import com.sl.transport.entity.node.BaseEntity;
|
||||
import org.springframework.data.neo4j.repository.Neo4jRepository;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Repository基本方法的实现
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
@NoRepositoryBean
|
||||
public interface BaseRepository<T extends BaseEntity, ID> extends Neo4jRepository<T, ID> {
|
||||
|
||||
/**
|
||||
* 根据业务id查询节点数据
|
||||
*
|
||||
* @param bid 业务id
|
||||
* @return 节点数据
|
||||
*/
|
||||
Optional<T> findByBid(Long bid);
|
||||
|
||||
/**
|
||||
* 根据业务id删除节点数据
|
||||
*
|
||||
* @param bid 业务id
|
||||
* @return 删除的数据数量
|
||||
*/
|
||||
Long deleteByBid(Long bid);
|
||||
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package com.sl.transport.repository;
|
||||
|
||||
import com.sl.transport.entity.node.OLTEntity;
|
||||
|
||||
/**
|
||||
* 一级转运中心数据操作
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface OLTRepository extends BaseRepository<OLTEntity, Long> {
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package com.sl.transport.repository;
|
||||
|
||||
import com.sl.transport.domain.OrganDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 通用机构查询
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface OrganRepository {
|
||||
|
||||
/**
|
||||
* 无需指定type,根据id查询
|
||||
*
|
||||
* @param bid 业务id
|
||||
* @return 机构数据
|
||||
*/
|
||||
OrganDTO findByBid(Long bid);
|
||||
|
||||
/**
|
||||
* 无需指定type,根据ids查询
|
||||
*
|
||||
* @param bids 业务id
|
||||
* @return 机构数据
|
||||
*/
|
||||
List<OrganDTO> findByBids(List<Long> bids);
|
||||
|
||||
/**
|
||||
* 查询所有的机构,如果name不为空的按照name模糊查询
|
||||
*
|
||||
* @param name 机构名称
|
||||
* @return 机构列表
|
||||
*/
|
||||
List<OrganDTO> findAll(String name);
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package com.sl.transport.repository;
|
||||
|
||||
import com.sl.transport.entity.node.TLTEntity;
|
||||
|
||||
/**
|
||||
* 二级转运中心数据操作
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface TLTRepository extends BaseRepository<TLTEntity, Long> {
|
||||
|
||||
}
|
@@ -0,0 +1,109 @@
|
||||
package com.sl.transport.repository;
|
||||
|
||||
import com.sl.transport.common.util.PageResponse;
|
||||
import com.sl.transport.domain.TransportLineNodeDTO;
|
||||
import com.sl.transport.domain.TransportLineSearchDTO;
|
||||
import com.sl.transport.entity.line.TransportLine;
|
||||
import com.sl.transport.entity.node.AgencyEntity;
|
||||
import com.sl.transport.entity.node.BaseEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 运输路线查询
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface TransportLineRepository {
|
||||
|
||||
/**
|
||||
* 查询两个网点之间最短的路线,查询深度为:10
|
||||
*
|
||||
* @param start 开始网点
|
||||
* @param end 结束网点
|
||||
* @return 路线
|
||||
*/
|
||||
TransportLineNodeDTO findShortestPath(AgencyEntity start, AgencyEntity end);
|
||||
|
||||
/**
|
||||
* 查询两个网点之间最短的路线,最大查询深度为:10
|
||||
*
|
||||
* @param start 开始网点
|
||||
* @param end 结束网点
|
||||
* @param depth 查询深度,最大为:10
|
||||
* @return 路线
|
||||
*/
|
||||
TransportLineNodeDTO findShortestPath(AgencyEntity start, AgencyEntity end, int depth);
|
||||
|
||||
/**
|
||||
* 查询两个网点之间的路线列表,成本优先 > 转运节点优先
|
||||
*
|
||||
* @param start 开始网点
|
||||
* @param end 结束网点
|
||||
* @param depth 查询深度
|
||||
* @param limit 返回路线的数量
|
||||
* @return 路线
|
||||
*/
|
||||
List<TransportLineNodeDTO> findPathList(AgencyEntity start, AgencyEntity end, int depth, int limit);
|
||||
|
||||
/**
|
||||
* 查询数据节点之间的关系数量
|
||||
*
|
||||
* @param firstNode 第一个节点
|
||||
* @param secondNode 第二个节点
|
||||
* @return 数量
|
||||
*/
|
||||
Long queryCount(BaseEntity firstNode, BaseEntity secondNode);
|
||||
|
||||
/**
|
||||
* 新增路线
|
||||
*
|
||||
* @param firstNode 第一个节点
|
||||
* @param secondNode 第二个节点
|
||||
* @param transportLine 路线数据
|
||||
* @return 新增关系的数量
|
||||
*/
|
||||
Long create(BaseEntity firstNode, BaseEntity secondNode, TransportLine transportLine);
|
||||
|
||||
/**
|
||||
* 更新路线
|
||||
*
|
||||
* @param transportLine 路线数据
|
||||
* @return 更新的数量
|
||||
*/
|
||||
Long update(TransportLine transportLine);
|
||||
|
||||
/**
|
||||
* 删除路线
|
||||
*
|
||||
* @param lineId 关系id
|
||||
* @return 删除关系的数量
|
||||
*/
|
||||
Long remove(Long lineId);
|
||||
|
||||
/**
|
||||
* 分页查询路线
|
||||
*
|
||||
* @param transportLineSearchDTO 搜索参数
|
||||
* @return 路线列表
|
||||
*/
|
||||
PageResponse<TransportLine> queryPageList(TransportLineSearchDTO transportLineSearchDTO);
|
||||
|
||||
|
||||
/**
|
||||
* 根据ids批量查询路线
|
||||
*
|
||||
* @param ids id列表
|
||||
* @return 路线列表
|
||||
*/
|
||||
List<TransportLine> queryByIds(Long... ids);
|
||||
|
||||
/**
|
||||
* 根据id查询路线
|
||||
*
|
||||
* @param id 路线id
|
||||
* @return 路线数据
|
||||
*/
|
||||
TransportLine queryById(Long id);
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package com.sl.transport.service;
|
||||
|
||||
import com.sl.transport.entity.node.AgencyEntity;
|
||||
|
||||
/**
|
||||
* 网点数据服务
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface AgencyService extends IService<AgencyEntity> {
|
||||
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package com.sl.transport.service;
|
||||
|
||||
import com.sl.transport.domain.CostConfigurationDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 成本配置相关业务
|
||||
*
|
||||
* @author wxb
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface CostConfigurationService {
|
||||
/**
|
||||
* 查询成本配置
|
||||
*
|
||||
* @return 成本配置
|
||||
*/
|
||||
List<CostConfigurationDTO> findConfiguration();
|
||||
|
||||
/**
|
||||
* 保存成本配置
|
||||
* @param dto 成本配置
|
||||
*/
|
||||
void saveConfiguration(List<CostConfigurationDTO> dto);
|
||||
|
||||
/**
|
||||
* 查询成本根据类型
|
||||
* @param type 类型
|
||||
* @return 成本
|
||||
*/
|
||||
Double findCostByType(Integer type);
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package com.sl.transport.service;
|
||||
|
||||
import com.sl.transport.domain.DispatchConfigurationDTO;
|
||||
|
||||
/**
|
||||
* 调度配置相关业务
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface DispatchConfigurationService {
|
||||
/**
|
||||
* 查询调度配置
|
||||
*
|
||||
* @return 调度配置
|
||||
*/
|
||||
DispatchConfigurationDTO findConfiguration();
|
||||
|
||||
/**
|
||||
* 保存调度配置
|
||||
* @param dto 调度配置
|
||||
*/
|
||||
void saveConfiguration(DispatchConfigurationDTO dto);
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
package com.sl.transport.service;
|
||||
|
||||
import com.sl.transport.entity.node.BaseEntity;
|
||||
|
||||
/**
|
||||
* 基础服务实现
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface IService<T extends BaseEntity> {
|
||||
|
||||
/**
|
||||
* 根据业务id查询数据
|
||||
*
|
||||
* @param bid 业务id
|
||||
* @return 节点数据
|
||||
*/
|
||||
T queryByBid(Long bid);
|
||||
|
||||
/**
|
||||
* 新增节点
|
||||
*
|
||||
* @param t 节点数据
|
||||
* @return 新增的节点数据
|
||||
*/
|
||||
T create(T t);
|
||||
|
||||
/**
|
||||
* 更新节点
|
||||
*
|
||||
* @param t 节点数据
|
||||
* @return 更新的节点数据
|
||||
*/
|
||||
T update(T t);
|
||||
|
||||
/**
|
||||
* 根据业务id删除数据
|
||||
*
|
||||
* @param bid 业务id
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
Boolean deleteByBid(Long bid);
|
||||
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package com.sl.transport.service;
|
||||
|
||||
import com.sl.transport.entity.node.OLTEntity;
|
||||
|
||||
/**
|
||||
* 一级转运中心数据服务
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface OLTService extends IService<OLTEntity> {
|
||||
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
package com.sl.transport.service;
|
||||
|
||||
import com.sl.transport.domain.OrganDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface OrganService {
|
||||
|
||||
/**
|
||||
* 无需指定type,根据id查询
|
||||
*
|
||||
* @param bid 机构id
|
||||
* @return 机构信息
|
||||
*/
|
||||
OrganDTO findByBid(Long bid);
|
||||
|
||||
/**
|
||||
* 无需指定type,根据ids查询
|
||||
*
|
||||
* @param bids 机构ids
|
||||
* @return 机构信息
|
||||
*/
|
||||
List<OrganDTO> findByBids(List<Long> bids);
|
||||
|
||||
/**
|
||||
* 查询所有的机构,如果name不为空的按照name模糊查询
|
||||
*
|
||||
* @param name 机构名称
|
||||
* @return 机构列表
|
||||
*/
|
||||
List<OrganDTO> findAll(String name);
|
||||
|
||||
/**
|
||||
* 查询机构树
|
||||
* @return 机构树
|
||||
*/
|
||||
String findAllTree();
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package com.sl.transport.service;
|
||||
|
||||
import com.sl.transport.entity.node.TLTEntity;
|
||||
|
||||
/**
|
||||
* 二级转运中心数据服务
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface TLTService extends IService<TLTEntity> {
|
||||
|
||||
}
|
@@ -0,0 +1,92 @@
|
||||
package com.sl.transport.service;
|
||||
|
||||
import com.sl.transport.common.util.PageResponse;
|
||||
import com.sl.transport.domain.TransportLineNodeDTO;
|
||||
import com.sl.transport.domain.TransportLineSearchDTO;
|
||||
import com.sl.transport.entity.line.TransportLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 计算路线相关业务
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface TransportLineService {
|
||||
|
||||
/**
|
||||
* 新增路线
|
||||
*
|
||||
* @param transportLine 路线数据
|
||||
* @return 是否成功
|
||||
*/
|
||||
Boolean createLine(TransportLine transportLine);
|
||||
|
||||
/**
|
||||
* 更新路线
|
||||
*
|
||||
* @param transportLine 路线数据
|
||||
* @return 是否成功
|
||||
*/
|
||||
Boolean updateLine(TransportLine transportLine);
|
||||
|
||||
/**
|
||||
* 删除路线
|
||||
*
|
||||
* @param id 路线id
|
||||
* @return 是否成功
|
||||
*/
|
||||
Boolean deleteLine(Long id);
|
||||
|
||||
/**
|
||||
* 分页查询路线
|
||||
*
|
||||
* @param transportLineSearchDTO 搜索参数
|
||||
* @return 路线列表
|
||||
*/
|
||||
PageResponse<TransportLine> queryPageList(TransportLineSearchDTO transportLineSearchDTO);
|
||||
|
||||
/**
|
||||
* 查询两个网点之间最短的路线,最大查询深度为:10
|
||||
*
|
||||
* @param startId 开始网点id
|
||||
* @param endId 结束网点id
|
||||
* @return 路线
|
||||
*/
|
||||
TransportLineNodeDTO queryShortestPath(Long startId, Long endId);
|
||||
|
||||
/**
|
||||
* 查询两个网点之间成本最低的路线,最大查询深度为:10
|
||||
*
|
||||
* @param startId 开始网点id
|
||||
* @param endId 结束网点id
|
||||
* @return 路线集合
|
||||
*/
|
||||
TransportLineNodeDTO findLowestPath(Long startId, Long endId);
|
||||
|
||||
/**
|
||||
* 根据调度策略查询路线
|
||||
*
|
||||
* @param startId 开始网点id
|
||||
* @param endId 结束网点id
|
||||
* @return 路线
|
||||
*/
|
||||
TransportLineNodeDTO queryPathByDispatchMethod(Long startId, Long endId);
|
||||
|
||||
/**
|
||||
* 根据ids批量查询路线
|
||||
*
|
||||
* @param ids id列表
|
||||
* @return 路线列表
|
||||
*/
|
||||
List<TransportLine> queryByIds(Long... ids);
|
||||
|
||||
/**
|
||||
* 根据id查询路线
|
||||
*
|
||||
* @param id 路线id
|
||||
* @return 路线数据
|
||||
*/
|
||||
TransportLine queryById(Long id);
|
||||
}
|
@@ -0,0 +1,91 @@
|
||||
package com.sl.transport.service.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.sl.transport.common.exception.SLException;
|
||||
import com.sl.transport.domain.CostConfigurationDTO;
|
||||
import com.sl.transport.enums.ExceptionEnum;
|
||||
import com.sl.transport.enums.TransportLineEnum;
|
||||
import com.sl.transport.service.CostConfigurationService;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 成本配置相关业务
|
||||
*
|
||||
* @author wxb
|
||||
* @version 1.0
|
||||
*/
|
||||
@Service
|
||||
public class CostConfigurationServiceImpl implements CostConfigurationService {
|
||||
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
/**
|
||||
* 成本配置 redis key
|
||||
*/
|
||||
static final String SL_TRANSPORT_COST_REDIS_KEY = "SL_TRANSPORT_COST_CONFIGURATION";
|
||||
|
||||
/**
|
||||
* 默认成本配置
|
||||
*/
|
||||
static final Map<Object, Object> DEFAULT_COST = Map.of(
|
||||
TransportLineEnum.TRUNK_LINE.getCode(), 0.8,
|
||||
TransportLineEnum.BRANCH_LINE.getCode(), 1.2,
|
||||
TransportLineEnum.CONNECT_LINE.getCode(), 1.5);
|
||||
|
||||
/**
|
||||
* 查询成本配置
|
||||
*
|
||||
* @return 成本配置
|
||||
*/
|
||||
@Override
|
||||
public List<CostConfigurationDTO> findConfiguration() {
|
||||
Map<Object, Object> entries = stringRedisTemplate.opsForHash().entries(SL_TRANSPORT_COST_REDIS_KEY);
|
||||
if (ObjectUtil.isEmpty(entries)) {
|
||||
// 使用默认值
|
||||
entries = DEFAULT_COST;
|
||||
}
|
||||
// 返回
|
||||
return entries.entrySet().stream()
|
||||
.map(v -> new CostConfigurationDTO(Convert.toInt(v.getKey()), Convert.toDouble(v.getValue())))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存成本配置
|
||||
*
|
||||
* @param dto 成本配置
|
||||
*/
|
||||
@Override
|
||||
public void saveConfiguration(List<CostConfigurationDTO> dto) {
|
||||
Map<Object, Object> map = dto.stream().collect(Collectors.toMap(v -> v.getTransportLineType().toString(), v -> v.getCost().toString()));
|
||||
stringRedisTemplate.opsForHash().putAll(SL_TRANSPORT_COST_REDIS_KEY, map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询成本根据类型
|
||||
*
|
||||
* @param type 类型
|
||||
* @return 成本
|
||||
*/
|
||||
@Override
|
||||
public Double findCostByType(Integer type) {
|
||||
if (ObjectUtil.isEmpty(type)) {
|
||||
throw new SLException(ExceptionEnum.TRANSPORT_LINE_TYPE_ERROR);
|
||||
}
|
||||
// 查询redis
|
||||
Object o = stringRedisTemplate.opsForHash().get(SL_TRANSPORT_COST_REDIS_KEY, type.toString());
|
||||
if (ObjectUtil.isNotEmpty(o)) {
|
||||
return Convert.toDouble(o);
|
||||
}
|
||||
// 返回默认值
|
||||
return Convert.toDouble(DEFAULT_COST.get(type));
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
package com.sl.transport.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.sl.transport.domain.DispatchConfigurationDTO;
|
||||
import com.sl.transport.service.DispatchConfigurationService;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 调度服务相关业务
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
@Service
|
||||
public class DispatchConfigurationServiceImpl implements DispatchConfigurationService {
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
/**
|
||||
* 调度时间配置
|
||||
*/
|
||||
static final String DISPATCH_TIME_REDIS_KEY = "DISPATCH_CONFIGURATION:TIME";
|
||||
|
||||
/**
|
||||
* 调度方式配置
|
||||
*/
|
||||
static final String DISPATCH_METHOD_REDIS_KEY = "DISPATCH_CONFIGURATION:METHOD";
|
||||
|
||||
@Override
|
||||
public DispatchConfigurationDTO findConfiguration() {
|
||||
//调度时间配置
|
||||
String dispatchTime = stringRedisTemplate.opsForValue().get(DISPATCH_TIME_REDIS_KEY);
|
||||
|
||||
//调度方式配置
|
||||
String dispatchMethod = stringRedisTemplate.opsForValue().get(DISPATCH_METHOD_REDIS_KEY);
|
||||
|
||||
//组装响应结果
|
||||
return DispatchConfigurationDTO.builder()
|
||||
//如果查不到调度时间,默认值为2小时
|
||||
.dispatchTime(Integer.parseInt(ObjectUtil.defaultIfBlank(dispatchTime, "2")))
|
||||
//如果查不到调度方式,默认值为2成本最低
|
||||
.dispatchMethod(Integer.parseInt(ObjectUtil.defaultIfBlank(dispatchMethod, "2")))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveConfiguration(DispatchConfigurationDTO dto) {
|
||||
//调度时间配置
|
||||
stringRedisTemplate.opsForValue().set(DISPATCH_TIME_REDIS_KEY, String.valueOf(dto.getDispatchTime()));
|
||||
|
||||
//调度方式配置
|
||||
stringRedisTemplate.opsForValue().set(DISPATCH_METHOD_REDIS_KEY, String.valueOf(dto.getDispatchMethod()));
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
package com.sl.transport.utils;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.sl.transport.common.exception.SLException;
|
||||
import com.sl.transport.enums.ExceptionEnum;
|
||||
import com.sl.transport.enums.OrganTypeEnum;
|
||||
import com.sl.transport.service.AgencyService;
|
||||
import com.sl.transport.service.IService;
|
||||
import com.sl.transport.service.OLTService;
|
||||
import com.sl.transport.service.TLTService;
|
||||
|
||||
/**
|
||||
* 根据type选择对应的service返回
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public class OrganServiceFactory {
|
||||
|
||||
public static IService getBean(Integer type) {
|
||||
OrganTypeEnum organTypeEnum = OrganTypeEnum.codeOf(type);
|
||||
if (null == organTypeEnum) {
|
||||
throw new SLException(ExceptionEnum.ORGAN_TYPE_ERROR);
|
||||
}
|
||||
|
||||
switch (organTypeEnum) {
|
||||
case AGENCY: {
|
||||
return SpringUtil.getBean(AgencyService.class);
|
||||
}
|
||||
case OLT: {
|
||||
return SpringUtil.getBean(OLTService.class);
|
||||
}
|
||||
case TLT: {
|
||||
return SpringUtil.getBean(TLTService.class);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
package com.sl.transport.utils;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.sl.transport.common.exception.SLException;
|
||||
import com.sl.transport.domain.OrganDTO;
|
||||
import com.sl.transport.entity.node.AgencyEntity;
|
||||
import com.sl.transport.entity.node.BaseEntity;
|
||||
import com.sl.transport.entity.node.OLTEntity;
|
||||
import com.sl.transport.entity.node.TLTEntity;
|
||||
import com.sl.transport.enums.ExceptionEnum;
|
||||
import com.sl.transport.enums.OrganTypeEnum;
|
||||
import org.springframework.data.geo.Point;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 机构工具类
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public class OrganUtils {
|
||||
|
||||
public static OrganDTO toAgencyDTO(BaseEntity baseEntity) {
|
||||
OrganDTO organDTO = BeanUtil.toBean(baseEntity, OrganDTO.class, CopyOptions.create().setIgnoreProperties("id", "location"));
|
||||
//数据库中的bid是对外的id
|
||||
organDTO.setId(baseEntity.getBid());
|
||||
organDTO.setLatitude(BeanUtil.getProperty(baseEntity.getLocation(), "x"));
|
||||
organDTO.setLongitude(BeanUtil.getProperty(baseEntity.getLocation(), "y"));
|
||||
organDTO.setType(baseEntity.getAgencyType().getCode());
|
||||
return organDTO;
|
||||
}
|
||||
|
||||
public static BaseEntity toEntity(OrganDTO organDTO) {
|
||||
BaseEntity baseEntity;
|
||||
OrganTypeEnum organType = OrganTypeEnum.codeOf(organDTO.getType());
|
||||
switch (organType) {
|
||||
case OLT: {
|
||||
baseEntity = BeanUtil.toBean(organDTO, OLTEntity.class, CopyOptions.create().ignoreNullValue());
|
||||
break;
|
||||
}
|
||||
case TLT: {
|
||||
baseEntity = BeanUtil.toBean(organDTO, TLTEntity.class, CopyOptions.create().ignoreNullValue());
|
||||
break;
|
||||
}
|
||||
case AGENCY: {
|
||||
baseEntity = BeanUtil.toBean(organDTO, AgencyEntity.class, CopyOptions.create().ignoreNullValue());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new SLException(ExceptionEnum.ORGAN_TYPE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
baseEntity.setId(null);
|
||||
baseEntity.setBid(organDTO.getId());
|
||||
if (ObjectUtil.isAllNotEmpty(organDTO.getLatitude(), organDTO.getLongitude())) {
|
||||
baseEntity.setLocation(new Point(organDTO.getLatitude(), organDTO.getLongitude()));
|
||||
}
|
||||
return baseEntity;
|
||||
}
|
||||
|
||||
public static List<OrganDTO> toAgencyDTOList(List<? extends BaseEntity> list) {
|
||||
return list.stream()
|
||||
.map(OrganUtils::toAgencyDTO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
package com.sl.transport.utils;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.sl.transport.domain.OrganDTO;
|
||||
import com.sl.transport.domain.TransportLineDTO;
|
||||
import com.sl.transport.domain.TransportLineNodeDTO;
|
||||
import com.sl.transport.entity.line.TransportLine;
|
||||
import com.sl.transport.enums.OrganTypeEnum;
|
||||
import org.neo4j.driver.internal.value.PathValue;
|
||||
import org.neo4j.driver.types.Path;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 对象转化工具类
|
||||
*
|
||||
* @author zzj
|
||||
* @version 1.0
|
||||
*/
|
||||
public class TransportLineUtils {
|
||||
|
||||
public static TransportLine toEntity(TransportLineDTO transportLineDTO) {
|
||||
return BeanUtil.toBeanIgnoreError(transportLineDTO, TransportLine.class);
|
||||
}
|
||||
|
||||
public static TransportLineDTO toDTO(TransportLine transportLine) {
|
||||
return BeanUtil.toBeanIgnoreError(transportLine, TransportLineDTO.class);
|
||||
}
|
||||
|
||||
public static List<TransportLineDTO> toDTOList(List<TransportLine> transportLine) {
|
||||
return transportLine.stream()
|
||||
.map(TransportLineUtils::toDTO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* PathValue对象转化成TransferLineDTO对象
|
||||
*
|
||||
* @param pathValue Neo4j对象
|
||||
* @return TransferLineDTO对象
|
||||
*/
|
||||
public static TransportLineNodeDTO convert(PathValue pathValue) {
|
||||
TransportLineNodeDTO transportLineNodeDTO = new TransportLineNodeDTO();
|
||||
Path path = pathValue.asPath();
|
||||
|
||||
//提取node中的数据,封装成 NodeDTO 对象
|
||||
path.nodes().forEach(node -> {
|
||||
Map<String, Object> map = node.asMap();
|
||||
OrganDTO organDTO = BeanUtil.toBeanIgnoreError(map, OrganDTO.class);
|
||||
//取第一个标签作为类型
|
||||
organDTO.setType(OrganTypeEnum.valueOf(CollUtil.getFirst(node.labels())).getCode());
|
||||
//查询出来的数据,x:经度,y:纬度
|
||||
organDTO.setLatitude(BeanUtil.getProperty(map.get("location"), "y"));
|
||||
organDTO.setLongitude(BeanUtil.getProperty(map.get("location"), "x"));
|
||||
transportLineNodeDTO.getNodeList().add(organDTO);
|
||||
});
|
||||
|
||||
//提取关系中的 cost 数据,进行求和计算,算出该路线的总成本
|
||||
path.relationships().forEach(relationship -> {
|
||||
Map<String, Object> objectMap = relationship.asMap();
|
||||
double cost = Convert.toDouble(objectMap.get("cost"), 0d);
|
||||
transportLineNodeDTO.setCost(NumberUtil.add(cost, transportLineNodeDTO.getCost().doubleValue()));
|
||||
});
|
||||
|
||||
//取2位小数
|
||||
transportLineNodeDTO.setCost(NumberUtil.round(transportLineNodeDTO.getCost(), 2).doubleValue());
|
||||
return transportLineNodeDTO;
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
|
||||
_ ${spring.application.name} ${application.version}
|
||||
___ | | ___ __ __ _ __ _ __ ___ ___ ___ Port: ${server.port}
|
||||
/ __|| | _____ / _ \\ \/ /| '_ \ | '__|/ _ \/ __|/ __| Pid: ${pid} Profile(s): ${AnsiColor.GREEN}${spring.profiles.active}${AnsiColor.DEFAULT}
|
||||
\__ \| ||_____|| __/ > < | |_) || | | __/\__ \\__ \
|
||||
|___/|_| \___|/_/\_\| .__/ |_| \___||___/|___/ https://sl-express.itheima.net/
|
||||
|_|
|
@@ -0,0 +1,30 @@
|
||||
server:
|
||||
port: 18083
|
||||
tomcat:
|
||||
uri-encoding: UTF-8
|
||||
threads:
|
||||
max: 1000
|
||||
min-spare: 30
|
||||
spring:
|
||||
cloud:
|
||||
nacos:
|
||||
username: nacos
|
||||
password: nacos
|
||||
server-addr: 192.168.150.101:8848
|
||||
discovery:
|
||||
namespace: ecae68ba-7b43-4473-a980-4ddeb6157bdc
|
||||
config:
|
||||
namespace: ecae68ba-7b43-4473-a980-4ddeb6157bdc
|
||||
shared-configs: #共享配置
|
||||
- data-id: shared-spring-rabbitmq.yml
|
||||
group: SHARED_GROUP
|
||||
refresh: false
|
||||
- data-id: shared-spring-eaglemap.yml
|
||||
group: SHARED_GROUP
|
||||
refresh: false
|
||||
- data-id: shared-spring-neo4j.yml
|
||||
group: SHARED_GROUP
|
||||
refresh: false
|
||||
- data-id: shared-spring-redis.yml
|
||||
group: SHARED_GROUP
|
||||
refresh: false
|
@@ -0,0 +1,30 @@
|
||||
server:
|
||||
port: 18083
|
||||
tomcat:
|
||||
uri-encoding: UTF-8
|
||||
threads:
|
||||
max: 1000
|
||||
min-spare: 30
|
||||
spring:
|
||||
cloud:
|
||||
nacos:
|
||||
username: nacos
|
||||
password: nacos
|
||||
server-addr: 192.168.150.101:8848
|
||||
discovery:
|
||||
namespace: ecae68ba-7b43-4473-a980-4ddeb6157bdc
|
||||
config:
|
||||
namespace: ecae68ba-7b43-4473-a980-4ddeb6157bdc
|
||||
shared-configs: #共享配置
|
||||
- data-id: shared-spring-rabbitmq.yml
|
||||
group: SHARED_GROUP
|
||||
refresh: false
|
||||
- data-id: shared-spring-eaglemap.yml
|
||||
group: SHARED_GROUP
|
||||
refresh: false
|
||||
- data-id: shared-spring-neo4j.yml
|
||||
group: SHARED_GROUP
|
||||
refresh: false
|
||||
- data-id: shared-spring-redis.yml
|
||||
group: SHARED_GROUP
|
||||
refresh: false
|
@@ -0,0 +1,30 @@
|
||||
server:
|
||||
port: 18083
|
||||
tomcat:
|
||||
uri-encoding: UTF-8
|
||||
threads:
|
||||
max: 1000
|
||||
min-spare: 30
|
||||
spring:
|
||||
cloud:
|
||||
nacos:
|
||||
username: nacos
|
||||
password: nacos
|
||||
server-addr: nacos-service.yjy-public-slwl-java.svc.cluster.local:8848
|
||||
discovery:
|
||||
namespace: 92312ba8-1119-440f-81af-c29618df303b
|
||||
config:
|
||||
namespace: 92312ba8-1119-440f-81af-c29618df303b
|
||||
shared-configs: #共享配置
|
||||
- data-id: shared-spring-rabbitmq.yml
|
||||
group: SHARED_GROUP
|
||||
refresh: false
|
||||
- data-id: shared-spring-eaglemap.yml
|
||||
group: SHARED_GROUP
|
||||
refresh: false
|
||||
- data-id: shared-spring-neo4j.yml
|
||||
group: SHARED_GROUP
|
||||
refresh: false
|
||||
- data-id: shared-spring-redis.yml
|
||||
group: SHARED_GROUP
|
||||
refresh: false
|
@@ -0,0 +1,25 @@
|
||||
application:
|
||||
version: v1.0
|
||||
logging:
|
||||
config: classpath:logback-spring.xml
|
||||
# level:
|
||||
# org.springframework.data.neo4j: debug
|
||||
spring:
|
||||
application:
|
||||
name: sl-express-transport
|
||||
profiles:
|
||||
active: local
|
||||
mvc:
|
||||
pathmatch:
|
||||
#解决异常:swagger Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
|
||||
#因为Springfox使用的路径匹配是基于AntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher
|
||||
matching-strategy: ant_path_matcher
|
||||
sl:
|
||||
swagger:
|
||||
package-path: com.sl.transport.controller
|
||||
title: 神领物流 - 运输路线微服务接口文档
|
||||
description: 该微服务完成网点、二级转运中心、一级转运中心的路线计算服务。
|
||||
contact-name: 传智教育·研究院
|
||||
contact-url: http://www.itcast.cn/
|
||||
contact-email: yjy@itcast.cn
|
||||
version: ${application.version}
|
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--scan: 当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true。-->
|
||||
<!--scanPeriod: 设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。-->
|
||||
<!--debug: 当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。-->
|
||||
<configuration debug="false" scan="false" scanPeriod="60 seconds">
|
||||
<springProperty scope="context" name="appName" source="spring.application.name"/>
|
||||
<!--文件名-->
|
||||
<property name="logback.appname" value="${appName}"/>
|
||||
<!--文件位置-->
|
||||
<property name="logback.logdir" value="/data/logs"/>
|
||||
|
||||
<!-- 定义控制台输出 -->
|
||||
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} - [%thread] - %-5level - %logger{50} - %msg%n</pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>DEBUG</level>
|
||||
</filter>
|
||||
<File>${logback.logdir}/${logback.appname}/${logback.appname}.log</File>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<FileNamePattern>${logback.logdir}/${logback.appname}/${logback.appname}.%d{yyyy-MM-dd}.log.zip</FileNamePattern>
|
||||
<maxHistory>90</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<charset>UTF-8</charset>
|
||||
<pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
<!--evel:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,-->
|
||||
<!--不能设置为INHERITED或者同义词NULL。默认是DEBUG。-->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="stdout"/>
|
||||
</root>
|
||||
</configuration>
|
Reference in New Issue
Block a user