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 45ffe9bd
authored
Jul 05, 2023
by
丁伟峰
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature-dingwf-0715' into develop
2 parents
687772a1
f71aa2b6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
144 additions
and
135 deletions
project-order/src/main/java/com/dituhui/pea/order/controller/EngineerController.java
project-order/src/main/java/com/dituhui/pea/order/service/CommonService.java
project-order/src/main/java/com/dituhui/pea/order/service/impl/CommonServiceImpl.java
project-order/src/main/java/com/dituhui/pea/order/controller/EngineerController.java
View file @
45ffe9b
...
...
@@ -118,7 +118,6 @@ public class EngineerController {
@PostMapping
(
value
=
"/engineer/schedule/gantt"
)
public
Result
<?>
getEngineersGanttList
(
@Validated
@RequestBody
EngineersGanttReqDTO
reqDTO
)
{
// todo 待移到 controller的engineer中
log
.
info
(
"getEngineersGanttList: {}"
,
reqDTO
);
Result
<?>
res
=
null
;
try
{
...
...
project-order/src/main/java/com/dituhui/pea/order/service/CommonService.java
View file @
45ffe9b
package
com
.
dituhui
.
pea
.
order
.
service
;
import
com.dituhui.pea.order.dao.CapacityTeamStatDao
;
import
com.dituhui.pea.order.dao.MapBlockInfoDao
;
import
com.dituhui.pea.order.dao.OrderChangeDao
;
import
com.dituhui.pea.order.entity.OrderChangeEntity
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.experimental.Accessors
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.*
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestTemplate
;
public
interface
CommonService
{
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Random
;
@Service
@Slf4j
public
class
CommonService
{
String
getTeamIdByInput
(
String
location
,
String
address
,
String
layer
);
@Autowired
private
MapBlockInfoDao
mapBlockInfoDao
;
void
addOrderChange
(
String
orderId
,
String
subOrderId
,
String
source
,
String
operator
,
String
content
,
String
memo
);
@Autowired
private
CapacityTeamStatDao
capacityTeamStatDao
;
@Autowired
private
OrderChangeDao
orderChangeDao
;
public
String
getTeamIdByInput
(
String
location
,
String
address
,
String
layer
)
{
// todo 目前会随机兜底,后面将合理化
log
.
info
(
"====== getTeamIdByInput ==="
);
String
teamId
=
null
;
List
<
LayerAndArea
>
layerAndAreas
=
getLayerAndAreas
(
location
,
address
);
if
(
layerAndAreas
==
null
||
layerAndAreas
.
size
()
==
0
)
{
// 分单接口没有查到,本地随机处理一下
teamId
=
capacityTeamStatDao
.
getRandomTeamIdByLayer
(
layer
);
log
.
info
(
"分单接口没有查到,本地随机处理一下 ==> {}"
,
teamId
);
}
else
{
// 分单接口查到了areaId(blockId),查询map_block_info,从而限定groupId,然后再随机teamId,这样就相对真实一点
// 生成随机索引
int
randomIndex
=
new
Random
().
nextInt
(
layerAndAreas
.
size
());
// 获取随机元素
LayerAndArea
layerAndArea
=
layerAndAreas
.
get
(
randomIndex
);
teamId
=
mapBlockInfoDao
.
getTeamIdByBlockIdAndLayer
(
layerAndArea
.
areaId
,
layer
);
log
.
info
(
"分单接口查询返回区块,layerAndArea=={}, teamId=={}"
,
layerAndArea
,
teamId
);
}
if
(
StringUtils
.
isEmpty
(
teamId
))
{
teamId
=
capacityTeamStatDao
.
getRandomTeamId
();
log
.
info
(
"查询没有teamId,需要随机生成teamId=={}"
,
teamId
);
}
log
.
info
(
"teamId ==> {}"
,
teamId
);
assert
(
StringUtils
.
isNotEmpty
(
teamId
));
return
teamId
;
}
/**
* 根据提供的地址信息,获取对应的片区图层定义的工作队;如果没有找到,返回为空
* 目前layer_info表中,area_data是保存位置围栏的json数据,后面可能会是对于其他图层的引用;
*
* @param location
* @return
*/
private
List
<
LayerAndArea
>
getLayerAndAreas
(
String
location
,
String
address
)
{
// 根据坐标 查询分单接口,获得区块、图层列表 ===> 查询map_block_info表,根据优先级,确定 工作队;
// 根据工作队+图层,查询 capacity_team_stat,返回
// todo 由于saas的分单接口尚未完成,目前仅仅是调用分单获取图层、区块名称,对于我们的容量查询没有真正使用,目前采用随机返回方式
// 创建RestTemplate实例
log
.
info
(
"===> getLayerAndAreas({}, {})"
,
location
,
address
);
RestTemplate
restTemplate
=
new
RestTemplate
();
// 设置请求头
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
);
// 构建请求参数
String
url
;
MultiValueMap
<
String
,
Object
>
params
=
new
LinkedMultiValueMap
<>();
params
.
add
(
"ak"
,
"284c57cbabad4755a9c657885a8df3e2"
);
if
(
StringUtils
.
isNotEmpty
(
location
))
{
url
=
"https://pea-test.bshg.com.cn/v1/xyfendan"
;
String
[]
coordinates
=
location
.
split
(
","
);
params
.
add
(
"coordinate"
,
String
.
format
(
"{\"x\":%s, \"y\":%s}"
,
coordinates
[
0
],
coordinates
[
1
]));
}
else
{
url
=
"https://pea-test.bshg.com.cn/v2/fendan"
;
params
.
add
(
"addresses"
,
String
.
format
(
"[{\"address\":\"%s\"}]"
,
address
));
}
params
.
add
(
"need_district"
,
"false"
);
params
.
add
(
"need_layer"
,
"true"
);
// params.add("related_point_fields", "");
params
.
add
(
"area_fields"
,
"名称,唯一编号,区块"
);
log
.
info
(
"request params ==> {}"
,
params
);
// 构建请求实体
HttpEntity
<
MultiValueMap
<
String
,
Object
>>
requestEntity
=
new
HttpEntity
<>(
params
,
headers
);
// 发送POST请求
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
requestEntity
,
String
.
class
);
// 获取响应结果
String
responseBody
=
responseEntity
.
getBody
();
log
.
info
(
"after call saas ==> {}"
,
responseEntity
.
getBody
());
// 使用Jackson库解析JSON数据
ObjectMapper
objectMapper
=
new
ObjectMapper
();
try
{
List
<
LayerAndArea
>
results
=
new
ArrayList
<>();
JsonNode
responseJson
=
objectMapper
.
readTree
(
responseBody
);
// 获取areaResults[0]的值
for
(
JsonNode
r
:
responseJson
.
get
(
"result"
).
get
(
0
).
get
(
"areaResults"
))
{
// 分单接口暂时无图层返回
results
.
add
(
new
LayerAndArea
().
setAreaId
(
r
.
get
(
"field3"
).
asText
()).
setAreaName
(
r
.
get
(
"field1"
).
asText
()));
}
return
results
;
}
catch
(
Exception
e
)
{
return
null
;
}
}
@lombok
.
Data
@Accessors
(
chain
=
true
)
private
static
class
LayerAndArea
{
private
String
layer
;
private
String
areaId
;
private
String
areaName
;
}
public
void
addOrderChange
(
String
orderId
,
String
subOrderId
,
String
source
,
String
operator
,
String
content
,
String
memo
)
{
OrderChangeEntity
entity
=
new
OrderChangeEntity
();
entity
.
setOrderId
(
orderId
).
setSuborderId
(
subOrderId
).
setSource
(
source
).
setOperator
(
operator
).
setContent
(
content
).
setMemo
(
memo
);
entity
.
setCreateTime
(
LocalDateTime
.
now
()).
setUpdateTime
(
LocalDateTime
.
now
());
orderChangeDao
.
save
(
entity
);
}
}
project-order/src/main/java/com/dituhui/pea/order/service/impl/CommonServiceImpl.java
0 → 100644
View file @
45ffe9b
package
com
.
dituhui
.
pea
.
order
.
service
.
impl
;
import
com.dituhui.pea.order.dao.CapacityTeamStatDao
;
import
com.dituhui.pea.order.dao.MapBlockInfoDao
;
import
com.dituhui.pea.order.dao.OrderChangeDao
;
import
com.dituhui.pea.order.entity.OrderChangeEntity
;
import
com.dituhui.pea.order.service.CommonService
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.experimental.Accessors
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.*
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestTemplate
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Random
;
@Service
@Slf4j
public
class
CommonServiceImpl
implements
CommonService
{
@Autowired
private
MapBlockInfoDao
mapBlockInfoDao
;
@Autowired
private
CapacityTeamStatDao
capacityTeamStatDao
;
@Autowired
private
OrderChangeDao
orderChangeDao
;
public
String
getTeamIdByInput
(
String
location
,
String
address
,
String
layer
)
{
// todo 目前会随机兜底,后面将合理化
log
.
info
(
"====== getTeamIdByInput ==="
);
String
teamId
=
null
;
List
<
LayerAndArea
>
layerAndAreas
=
getLayerAndAreas
(
location
,
address
);
if
(
layerAndAreas
==
null
||
layerAndAreas
.
size
()
==
0
)
{
// 分单接口没有查到,本地随机处理一下
teamId
=
capacityTeamStatDao
.
getRandomTeamIdByLayer
(
layer
);
log
.
info
(
"分单接口没有查到,本地随机处理一下 ==> {}"
,
teamId
);
}
else
{
// 分单接口查到了areaId(blockId),查询map_block_info,从而限定groupId,然后再随机teamId,这样就相对真实一点
// 生成随机索引
int
randomIndex
=
new
Random
().
nextInt
(
layerAndAreas
.
size
());
// 获取随机元素
LayerAndArea
layerAndArea
=
layerAndAreas
.
get
(
randomIndex
);
teamId
=
mapBlockInfoDao
.
getTeamIdByBlockIdAndLayer
(
layerAndArea
.
areaId
,
layer
);
log
.
info
(
"分单接口查询返回区块,layerAndArea=={}, teamId=={}"
,
layerAndArea
,
teamId
);
}
if
(
StringUtils
.
isEmpty
(
teamId
))
{
teamId
=
capacityTeamStatDao
.
getRandomTeamId
();
log
.
info
(
"查询没有teamId,需要随机生成teamId=={}"
,
teamId
);
}
log
.
info
(
"teamId ==> {}"
,
teamId
);
assert
(
StringUtils
.
isNotEmpty
(
teamId
));
return
teamId
;
}
/**
* 根据提供的地址信息,获取对应的片区图层定义的工作队;如果没有找到,返回为空
* 目前layer_info表中,area_data是保存位置围栏的json数据,后面可能会是对于其他图层的引用;
*
* @param location
* @return
*/
private
List
<
LayerAndArea
>
getLayerAndAreas
(
String
location
,
String
address
)
{
// 根据坐标 查询分单接口,获得区块、图层列表 ===> 查询map_block_info表,根据优先级,确定 工作队;
// 根据工作队+图层,查询 capacity_team_stat,返回
// todo 由于saas的分单接口尚未完成,目前仅仅是调用分单获取图层、区块名称,对于我们的容量查询没有真正使用,目前采用随机返回方式
// 创建RestTemplate实例
log
.
info
(
"===> getLayerAndAreas({}, {})"
,
location
,
address
);
RestTemplate
restTemplate
=
new
RestTemplate
();
// 设置请求头
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
);
// 构建请求参数
String
url
;
MultiValueMap
<
String
,
Object
>
params
=
new
LinkedMultiValueMap
<>();
params
.
add
(
"ak"
,
"284c57cbabad4755a9c657885a8df3e2"
);
if
(
StringUtils
.
isNotEmpty
(
location
))
{
url
=
"https://pea-test.bshg.com.cn/v1/xyfendan"
;
String
[]
coordinates
=
location
.
split
(
","
);
params
.
add
(
"coordinate"
,
String
.
format
(
"{\"x\":%s, \"y\":%s}"
,
coordinates
[
0
],
coordinates
[
1
]));
}
else
{
url
=
"https://pea-test.bshg.com.cn/v2/fendan"
;
params
.
add
(
"addresses"
,
String
.
format
(
"[{\"address\":\"%s\"}]"
,
address
));
}
params
.
add
(
"need_district"
,
"false"
);
params
.
add
(
"need_layer"
,
"true"
);
// params.add("related_point_fields", "");
params
.
add
(
"area_fields"
,
"名称,唯一编号,区块"
);
log
.
info
(
"request params ==> {}"
,
params
);
// 构建请求实体
HttpEntity
<
MultiValueMap
<
String
,
Object
>>
requestEntity
=
new
HttpEntity
<>(
params
,
headers
);
// 发送POST请求
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
requestEntity
,
String
.
class
);
// 获取响应结果
String
responseBody
=
responseEntity
.
getBody
();
log
.
info
(
"after call saas ==> {}"
,
responseEntity
.
getBody
());
// 使用Jackson库解析JSON数据
ObjectMapper
objectMapper
=
new
ObjectMapper
();
try
{
List
<
LayerAndArea
>
results
=
new
ArrayList
<>();
JsonNode
responseJson
=
objectMapper
.
readTree
(
responseBody
);
// 获取areaResults[0]的值
for
(
JsonNode
r
:
responseJson
.
get
(
"result"
).
get
(
0
).
get
(
"areaResults"
))
{
// 分单接口暂时无图层返回
results
.
add
(
new
LayerAndArea
().
setAreaId
(
r
.
get
(
"field3"
).
asText
()).
setAreaName
(
r
.
get
(
"field1"
).
asText
()));
}
return
results
;
}
catch
(
Exception
e
)
{
return
null
;
}
}
@lombok
.
Data
@Accessors
(
chain
=
true
)
private
static
class
LayerAndArea
{
private
String
layer
;
private
String
areaId
;
private
String
areaName
;
}
public
void
addOrderChange
(
String
orderId
,
String
subOrderId
,
String
source
,
String
operator
,
String
content
,
String
memo
)
{
OrderChangeEntity
entity
=
new
OrderChangeEntity
();
entity
.
setOrderId
(
orderId
).
setSuborderId
(
subOrderId
).
setSource
(
source
).
setOperator
(
operator
).
setContent
(
content
).
setMemo
(
memo
);
entity
.
setCreateTime
(
LocalDateTime
.
now
()).
setUpdateTime
(
LocalDateTime
.
now
());
orderChangeDao
.
save
(
entity
);
}
}
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