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 89e71502
authored
Jun 13, 2023
by
丁伟峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
单条容量查询
1 parent
0451c17d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
14 deletions
project-order/src/main/java/com/alibaba/cloud/integration/order/controller/OrderCreateController.java
project-order/src/main/java/com/alibaba/cloud/integration/order/dao/CapacityTeamStatDao.java
project-order/src/main/java/com/alibaba/cloud/integration/order/dao/MapBlockInfoDao.java
project-order/src/main/java/com/alibaba/cloud/integration/order/service/impl/CapacityQueryServiceImpl.java
project-order/src/main/java/com/alibaba/cloud/integration/order/controller/OrderCreateController.java
View file @
89e7150
...
@@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.*;
...
@@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.*;
public
class
OrderCreateController
{
public
class
OrderCreateController
{
@Autowired
@Autowired
private
OrderCreateService
orderService
;
private
OrderCreateService
order
Create
Service
;
@Autowired
@Autowired
private
CapacityQueryService
capacityQueryService
;
private
CapacityQueryService
capacityQueryService
;
...
@@ -41,7 +41,7 @@ public class OrderCreateController {
...
@@ -41,7 +41,7 @@ public class OrderCreateController {
public
Result
<?>
createOrder
(
@Validated
@RequestBody
OrderCreateReqDTO
orderCreateReqDTO
)
{
public
Result
<?>
createOrder
(
@Validated
@RequestBody
OrderCreateReqDTO
orderCreateReqDTO
)
{
Result
<?>
res
=
null
;
Result
<?>
res
=
null
;
try
{
try
{
res
=
orderService
.
createOrder
(
orderCreateReqDTO
);
res
=
order
Create
Service
.
createOrder
(
orderCreateReqDTO
);
}
catch
(
BusinessException
e
)
{
}
catch
(
BusinessException
e
)
{
return
Result
.
failed
(
e
.
getMessage
());
return
Result
.
failed
(
e
.
getMessage
());
}
}
...
@@ -52,7 +52,7 @@ public class OrderCreateController {
...
@@ -52,7 +52,7 @@ public class OrderCreateController {
public
Result
<?>
getParameter
()
{
public
Result
<?>
getParameter
()
{
Result
<?>
res
=
null
;
Result
<?>
res
=
null
;
try
{
try
{
res
=
orderService
.
initParameter
();
res
=
order
Create
Service
.
initParameter
();
}
catch
(
BusinessException
e
)
{
}
catch
(
BusinessException
e
)
{
return
Result
.
failed
(
e
.
getMessage
());
return
Result
.
failed
(
e
.
getMessage
());
}
}
...
...
project-order/src/main/java/com/alibaba/cloud/integration/order/dao/CapacityTeamStatDao.java
View file @
89e7150
package
com
.
alibaba
.
cloud
.
integration
.
order
.
dao
;
package
com
.
alibaba
.
cloud
.
integration
.
order
.
dao
;
import
com.alibaba.cloud.integration.order.entity.CapacityTeamStatEntity
;
import
com.alibaba.cloud.integration.order.entity.CapacityTeamStatEntity
;
import
org.hibernate.annotations.Where
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
...
@@ -17,4 +16,10 @@ public interface CapacityTeamStatDao extends JpaRepository<CapacityTeamStatEntit
...
@@ -17,4 +16,10 @@ public interface CapacityTeamStatDao extends JpaRepository<CapacityTeamStatEntit
@Query
(
"select c from CapacityTeamStatEntity c where c.teamId = :teamId and c.workday between :beginDate and :endDate"
)
@Query
(
"select c from CapacityTeamStatEntity c where c.teamId = :teamId and c.workday between :beginDate and :endDate"
)
Page
<?>
findByTeamIdAndWorkdayBetween
(
String
teamId
,
String
beginDate
,
String
endDate
,
Pageable
pageable
);
Page
<?>
findByTeamIdAndWorkdayBetween
(
String
teamId
,
String
beginDate
,
String
endDate
,
Pageable
pageable
);
@Query
(
value
=
"SELECT team_id FROM capacity_team_stat where layer = :layer ORDER BY RAND() LIMIT 1"
,
nativeQuery
=
true
)
String
getRandomTeamIdByLayer
(
String
layer
);
@Query
(
value
=
"SELECT team_id FROM capacity_team_stat ORDER BY RAND() LIMIT 1"
,
nativeQuery
=
true
)
String
getRandomTeamId
();
}
}
project-order/src/main/java/com/alibaba/cloud/integration/order/dao/MapBlockInfoDao.java
View file @
89e7150
...
@@ -11,5 +11,5 @@ import org.springframework.stereotype.Repository;
...
@@ -11,5 +11,5 @@ import org.springframework.stereotype.Repository;
public
interface
MapBlockInfoDao
extends
JpaRepository
<
MapBlockInfoEntity
,
Integer
>
{
public
interface
MapBlockInfoDao
extends
JpaRepository
<
MapBlockInfoEntity
,
Integer
>
{
@Query
(
"select s.teamId from MapBlockInfoEntity s where s.blockId = :blockId and s.layer = :layer"
)
@Query
(
"select s.teamId from MapBlockInfoEntity s where s.blockId = :blockId and s.layer = :layer"
)
String
getTeam
idByBlocki
dAndLayer
(
String
blockId
,
String
layer
);
String
getTeam
IdByBlockI
dAndLayer
(
String
blockId
,
String
layer
);
}
}
project-order/src/main/java/com/alibaba/cloud/integration/order/service/impl/CapacityQueryServiceImpl.java
View file @
89e7150
...
@@ -12,6 +12,7 @@ import com.alibaba.cloud.integration.order.entity.OrgGroupEntity;
...
@@ -12,6 +12,7 @@ import com.alibaba.cloud.integration.order.entity.OrgGroupEntity;
import
com.alibaba.cloud.integration.order.service.CapacityQueryService
;
import
com.alibaba.cloud.integration.order.service.CapacityQueryService
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.experimental.Accessors
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
...
@@ -57,10 +58,26 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
...
@@ -57,10 +58,26 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
/*
/*
location ==> [layer_info] ==> team ==> (+skill) ==> [capacity_team_stat]
location ==> [layer_info] ==> team ==> (+skill) ==> [capacity_team_stat]
*/
*/
String
teamId
;
String
layer
=
productCategoryDao
.
getLayerByBrandAndTypeAndSkill
(
reqDTO
.
getBrand
(),
reqDTO
.
getType
(),
reqDTO
.
getSkill
());
String
layer
=
productCategoryDao
.
getLayerByBrandAndTypeAndSkill
(
reqDTO
.
getBrand
(),
reqDTO
.
getType
(),
reqDTO
.
getSkill
());
String
teamId
=
getTeamByLayer
(
reqDTO
.
getLocation
(),
reqDTO
.
getAddress
(),
layer
);
List
<
LayerAndArea
>
layerAndAreas
=
getLayerAndAreas
(
reqDTO
.
getLocation
(),
reqDTO
.
getAddress
());
if
(
layerAndAreas
==
null
||
layerAndAreas
.
size
()
==
0
)
{
// 分单接口没有查到,本地随机处理一下
teamId
=
capacityTeamStatDao
.
getRandomTeamIdByLayer
(
layer
);
}
else
{
// 生成随机索引
int
randomIndex
=
new
Random
().
nextInt
(
layerAndAreas
.
size
());
// 获取随机元素
LayerAndArea
layerAndArea
=
layerAndAreas
.
get
(
randomIndex
);
teamId
=
mapBlockInfoDao
.
getTeamIdByBlockIdAndLayer
(
layerAndArea
.
areaId
,
layer
);
}
if
(
teamId
==
null
||
teamId
.
isBlank
())
{
teamId
=
capacityTeamStatDao
.
getRandomTeamId
();
}
assert
(
teamId
!=
null
&&
!
teamId
.
isBlank
());
CapacityQueryOrderRespDTO
capacityQueryRespDTO
=
new
CapacityQueryOrderRespDTO
();
CapacityQueryOrderRespDTO
capacityQueryRespDTO
=
new
CapacityQueryOrderRespDTO
();
capacityQueryRespDTO
.
setBeginDate
(
capacityQueryResp
DTO
.
getBeginDate
()).
setEndDate
(
reqDTO
.
getEndDate
());
capacityQueryRespDTO
.
setBeginDate
(
req
DTO
.
getBeginDate
()).
setEndDate
(
reqDTO
.
getEndDate
());
capacityQueryRespDTO
.
setCalendar
(
getTimeRangeByTeamSkill
(
teamId
,
reqDTO
.
getSkill
(),
reqDTO
.
getBeginDate
(),
reqDTO
.
getEndDate
()));
capacityQueryRespDTO
.
setCalendar
(
getTimeRangeByTeamSkill
(
teamId
,
reqDTO
.
getSkill
(),
reqDTO
.
getBeginDate
(),
reqDTO
.
getEndDate
()));
capacityQueryRespDTO
.
setRemark
(
String
.
format
(
"%s-%s"
,
teamId
,
layer
));
capacityQueryRespDTO
.
setRemark
(
String
.
format
(
"%s-%s"
,
teamId
,
layer
));
return
Result
.
success
(
capacityQueryRespDTO
);
return
Result
.
success
(
capacityQueryRespDTO
);
...
@@ -107,8 +124,10 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
...
@@ -107,8 +124,10 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
* @param location
* @param location
* @return
* @return
*/
*/
private
String
getTeamByLayer
(
String
location
,
String
address
,
String
layer
)
{
private
List
<
LayerAndArea
>
getLayerAndAreas
(
String
location
,
String
address
)
{
// todo 由于saas的分单接口尚未完成,目前仅仅是调用分单获取
// 根据坐标 查询分单接口,获得区块、图层列表 ===> 查询map_block_info表,根据优先级,确定 工作队;
// 根据工作队+图层,查询 capacity_team_stat,返回
// todo 由于saas的分单接口尚未完成,目前仅仅是调用分单获取图层、区块名称,对于我们的容量查询没有真正使用,目前采用随机返回方式
// 创建RestTemplate实例
// 创建RestTemplate实例
RestTemplate
restTemplate
=
new
RestTemplate
();
RestTemplate
restTemplate
=
new
RestTemplate
();
...
@@ -144,13 +163,14 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
...
@@ -144,13 +163,14 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
// 使用Jackson库解析JSON数据
// 使用Jackson库解析JSON数据
ObjectMapper
objectMapper
=
new
ObjectMapper
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
try
{
try
{
List
<
LayerAndArea
>
results
=
new
ArrayList
<>();
JsonNode
responseJson
=
objectMapper
.
readTree
(
responseBody
);
JsonNode
responseJson
=
objectMapper
.
readTree
(
responseBody
);
// 获取areaResults[0]的值
// 获取areaResults[0]的值
JsonNode
areaResult
=
responseJson
.
get
(
"result"
).
get
(
0
).
get
(
"areaResults"
).
get
(
0
);
for
(
JsonNode
r
:
responseJson
.
get
(
"result"
).
get
(
0
).
get
(
"areaResults"
))
{
// 分单接口暂时无图层返回
// 将areaResult转换为JSON字符串
results
.
add
(
new
LayerAndArea
().
setAreaId
(
r
.
get
(
"field2"
).
asText
()).
setAreaName
(
r
.
get
(
"field1"
).
asText
()));
// todo 分单接口其实也应该直接返回 图层
}
return
mapBlockInfoDao
.
getTeamidByBlockidAndLayer
(
areaResult
.
get
(
"field2"
).
toString
(),
layer
)
;
return
results
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
return
null
;
return
null
;
}
}
...
@@ -221,4 +241,11 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
...
@@ -221,4 +241,11 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
return
String
.
format
(
"周%s"
,
weekday
.
getDisplayName
(
TextStyle
.
SHORT
,
Locale
.
CHINA
));
return
String
.
format
(
"周%s"
,
weekday
.
getDisplayName
(
TextStyle
.
SHORT
,
Locale
.
CHINA
));
}
}
@lombok
.
Data
@Accessors
(
chain
=
true
)
private
static
class
LayerAndArea
{
private
String
layer
;
private
String
areaId
;
private
String
areaName
;
}
}
}
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