Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
yangxiujun
/
paidan_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit b6e902ad
authored
Nov 10, 2023
by
chamberone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 添加获取道路距离接口
1 parent
b7a21942
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
114 additions
and
0 deletions
project-dispatch/src/main/java/com/dituhui/pea/dispatch/controller/PathController.java
project-interface/src/main/java/com/dituhui/pea/dispatch/IPath.java
project-interface/src/main/java/com/dituhui/pea/pojo/DistanceDTO.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/controller/PathController.java
0 → 100644
View file @
b6e902a
package
com
.
dituhui
.
pea
.
dispatch
.
controller
;
import
java.util.List
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.alibaba.druid.util.StringUtils
;
import
com.dituhui.pea.common.BusinessException
;
import
com.dituhui.pea.common.Result
;
import
com.dituhui.pea.dispatch.IPath
;
import
com.dituhui.pea.dispatch.dao.OrderInfoRepository
;
import
com.dituhui.pea.dispatch.entity.OrderInfo
;
import
com.dituhui.pea.dispatch.pojo.Location
;
import
com.dituhui.pea.dispatch.utils.RoadDistanceUtils
;
import
com.dituhui.pea.dispatch.utils.RoadDistanceUtils.Distance
;
import
com.dituhui.pea.pojo.DistanceDTO
;
/**
* 道路控制层
*/
@RestController
public
class
PathController
implements
IPath
{
@Autowired
OrderInfoRepository
orderInfoRepository
;
@Override
public
Result
<
DistanceDTO
>
getRoadDistance
(
String
fromOrderId
,
String
toOrderId
,
Integer
vehicleType
)
{
try
{
// 参数检查
if
(
StringUtils
.
isEmpty
(
fromOrderId
)
||
StringUtils
.
isEmpty
(
toOrderId
))
{
return
Result
.
failure
(
"missing fromOrderId or toOrderId"
);
}
if
(
null
==
vehicleType
)
{
vehicleType
=
1
;
}
List
<
OrderInfo
>
fromOrders
=
orderInfoRepository
.
findByOrderId
(
fromOrderId
);
List
<
OrderInfo
>
toOrders
=
orderInfoRepository
.
findByOrderId
(
toOrderId
);
if
(
CollectionUtils
.
isEmpty
(
fromOrders
)
||
CollectionUtils
.
isEmpty
(
toOrders
))
{
return
Result
.
failure
(
"fromOrderId or toOrderId not exists"
);
}
if
(
StringUtils
.
isEmpty
(
fromOrders
.
get
(
0
).
getX
())
||
StringUtils
.
isEmpty
(
fromOrders
.
get
(
0
).
getY
())
||
StringUtils
.
isEmpty
(
toOrders
.
get
(
0
).
getX
())
||
StringUtils
.
isEmpty
(
toOrders
.
get
(
0
).
getY
()))
{
return
Result
.
failure
(
"missing coordinates"
);
}
// 获取距离
Distance
distance
=
RoadDistanceUtils
.
getDistance
(
new
Location
(
0L
,
Float
.
parseFloat
(
fromOrders
.
get
(
0
).
getX
()),
Float
.
parseFloat
(
fromOrders
.
get
(
0
).
getY
())),
new
Location
(
0L
,
Float
.
parseFloat
(
toOrders
.
get
(
0
).
getX
()),
Float
.
parseFloat
(
toOrders
.
get
(
0
).
getY
())),
vehicleType
);
DistanceDTO
dto
=
new
DistanceDTO
();
dto
.
setDis
(
distance
.
getDis
());
dto
.
setTime
(
distance
.
getTime
());
return
Result
.
success
(
dto
);
}
catch
(
BusinessException
e
)
{
return
Result
.
failure
(
e
.
getMessage
());
}
}
}
project-interface/src/main/java/com/dituhui/pea/dispatch/IPath.java
0 → 100644
View file @
b6e902a
package
com
.
dituhui
.
pea
.
dispatch
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
com.dituhui.pea.common.Result
;
import
com.dituhui.pea.pojo.DistanceDTO
;
/**
* 道路相关接口
*
* @author
*/
@FeignClient
(
value
=
"project-dispatch"
,
contextId
=
"dispatch"
)
public
interface
IPath
{
/**
* 获取2个订单之间的道路距离
*
* @param fromOrderId 出发订单id
* @param toOrderId 到达订单id
* @param vehicleType 交通工具:1汽车;2电动车;3自行车;4步行 默认是汽车
* @return
*/
@RequestMapping
(
value
=
"/pea-dispatch/getRoadDistance"
,
method
=
RequestMethod
.
POST
)
public
Result
<
DistanceDTO
>
getRoadDistance
(
@RequestParam
(
"fromOrderId"
)
String
fromOrderId
,
@RequestParam
(
"toOrderId"
)
String
toOrderId
,
@RequestParam
(
name
=
"vehicleType"
,
required
=
false
)
Integer
vehicleType
);
}
project-interface/src/main/java/com/dituhui/pea/pojo/DistanceDTO.java
0 → 100644
View file @
b6e902a
package
com
.
dituhui
.
pea
.
pojo
;
import
lombok.Data
;
@Data
public
class
DistanceDTO
{
/**
* 单位 公里
*/
float
dis
;
/**
* 单位 秒
*/
int
time
;
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment