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 d772bb98
authored
Nov 20, 2023
by
Ren Ping
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:路网更新为redis缓存
1 parent
810f3686
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
74 additions
and
36 deletions
project-dispatch/src/main/java/com/dituhui/pea/dispatch/DispatchServiceApplication.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/common/RedisConfig.java → project-dispatch/src/main/java/com/dituhui/pea/dispatch/common/redis/RedisConfig.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/common/redis/RedisUtil.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/common/RedissonConfig.java → project-dispatch/src/main/java/com/dituhui/pea/dispatch/common/redis/RedissonConfig.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/common/RedissonUtil.java → project-dispatch/src/main/java/com/dituhui/pea/dispatch/common/redis/RedissonUtil.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/constraint/RedisKeyConstant.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/quartz/dispatch/AutoDispatchJob.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/scheduler/BatchScheduler.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/service/impl/ExtractServiceImpl.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/service/impl/SchedulerServiceImpl.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/utils/RoadDistanceUtils.java
project-dispatch/src/main/resources/application-dev.yaml
project-dispatch/src/main/java/com/dituhui/pea/dispatch/DispatchServiceApplication.java
View file @
d772bb9
...
@@ -19,6 +19,7 @@ package com.dituhui.pea.dispatch;
...
@@ -19,6 +19,7 @@ package com.dituhui.pea.dispatch;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
/**
/**
...
@@ -27,6 +28,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
...
@@ -27,6 +28,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@SpringBootApplication
@EnableScheduling
@EnableScheduling
@EnableFeignClients
(
basePackages
=
{
"com.dituhui.pea.user"
})
@EnableFeignClients
(
basePackages
=
{
"com.dituhui.pea.user"
})
@Import
(
cn
.
hutool
.
extra
.
spring
.
SpringUtil
.
class
)
public
class
DispatchServiceApplication
{
public
class
DispatchServiceApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/common/RedisConfig.java
→
project-dispatch/src/main/java/com/dituhui/pea/dispatch/common/
redis/
RedisConfig.java
View file @
d772bb9
package
com
.
dituhui
.
pea
.
dispatch
.
common
;
package
com
.
dituhui
.
pea
.
dispatch
.
common
.
redis
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
@Configuration
@Configuration
...
@@ -16,10 +21,27 @@ public class RedisConfig {
...
@@ -16,10 +21,27 @@ public class RedisConfig {
// objectMapper.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(),
// objectMapper.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(),
// ObjectMapper.DefaultTyping.EVERYTHING, JsonTypeInfo.As.PROPERTY);
// ObjectMapper.DefaultTyping.EVERYTHING, JsonTypeInfo.As.PROPERTY);
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
Jackson2JsonRedisSerializer
jacksonSerial
=
new
Jackson2JsonRedisSerializer
(
Object
.
class
);
ObjectMapper
objectMapper
=
new
ObjectMapper
();
// 指定要序列化的域,field, get和set,以及修饰符范围,ANY是都有包括private和public
objectMapper
.
setVisibility
(
PropertyAccessor
.
ALL
,
JsonAutoDetect
.
Visibility
.
ANY
);
// 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会抛出异常
objectMapper
.
activateDefaultTyping
(
objectMapper
.
getPolymorphicTypeValidator
(),
ObjectMapper
.
DefaultTyping
.
NON_FINAL
);
// jsonToBean时,json中有的字段,bean中没有 无法匹配时,忽略此字段,不抛出异常(默认是抛出异常的)
objectMapper
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
jacksonSerial
.
setObjectMapper
(
objectMapper
);
RedisTemplate
<
String
,
String
>
redisTemplate
=
new
RedisTemplate
<>();
RedisTemplate
<
String
,
String
>
redisTemplate
=
new
RedisTemplate
<>();
redisTemplate
.
setConnectionFactory
(
connectionFactory
);
redisTemplate
.
setConnectionFactory
(
connectionFactory
);
redisTemplate
.
setKeySerializer
(
new
StringRedisSerializer
());
redisTemplate
.
setKeySerializer
(
new
StringRedisSerializer
());
redisTemplate
.
setValueSerializer
(
new
StringRedisSerializer
());
redisTemplate
.
setValueSerializer
(
jacksonSerial
);
// 设置hash key 和 value 序列化模式
redisTemplate
.
setHashKeySerializer
(
new
StringRedisSerializer
());
redisTemplate
.
setHashValueSerializer
(
jacksonSerial
);
return
redisTemplate
;
return
redisTemplate
;
}
}
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/common/redis/RedisUtil.java
0 → 100644
View file @
d772bb9
This diff is collapsed.
Click to expand it.
project-dispatch/src/main/java/com/dituhui/pea/dispatch/common/RedissonConfig.java
→
project-dispatch/src/main/java/com/dituhui/pea/dispatch/common/
redis/
RedissonConfig.java
View file @
d772bb9
package
com
.
dituhui
.
pea
.
dispatch
.
common
;
package
com
.
dituhui
.
pea
.
dispatch
.
common
.
redis
;
import
org.redisson.Redisson
;
import
org.redisson.Redisson
;
import
org.redisson.api.RedissonClient
;
import
org.redisson.api.RedissonClient
;
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/common/RedissonUtil.java
→
project-dispatch/src/main/java/com/dituhui/pea/dispatch/common/
redis/
RedissonUtil.java
View file @
d772bb9
package
com
.
dituhui
.
pea
.
dispatch
.
common
;
package
com
.
dituhui
.
pea
.
dispatch
.
common
.
redis
;
import
cn.hutool.extra.spring.SpringUtil
;
import
cn.hutool.extra.spring.SpringUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/constraint/RedisKeyConstant.java
0 → 100644
View file @
d772bb9
package
com
.
dituhui
.
pea
.
dispatch
.
constraint
;
public
class
RedisKeyConstant
{
public
static
final
String
LOCATION_DISTANCE_KEY
=
"location:%s:distance:%s"
;
public
static
final
String
LOCATION_DISTANCE_TIME_KEY
=
"location:%s:distanceTime:%s"
;
}
project-dispatch/src/main/java/com/dituhui/pea/dispatch/quartz/dispatch/AutoDispatchJob.java
View file @
d772bb9
package
com
.
dituhui
.
pea
.
dispatch
.
quartz
.
dispatch
;
package
com
.
dituhui
.
pea
.
dispatch
.
quartz
.
dispatch
;
import
com.dituhui.pea.dispatch.common.RedissonUtil
;
import
com.dituhui.pea.dispatch.service.SchedulerService
;
import
com.dituhui.pea.dispatch.service.SchedulerService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.quartz.DisallowConcurrentExecution
;
import
org.quartz.DisallowConcurrentExecution
;
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/scheduler/BatchScheduler.java
View file @
d772bb9
...
@@ -40,9 +40,9 @@ public class BatchScheduler {
...
@@ -40,9 +40,9 @@ public class BatchScheduler {
@Autowired
@Autowired
ExtractService
extractService
;
ExtractService
extractService
;
@Autowired
@Autowired
OrgTeamDao
orgTeamDao
;
OrgTeamDao
orgTeamDao
;
private
DefaultSolverFactory
<
DispatchSolution
>
solverFactory
;
private
DefaultSolverFactory
<
DispatchSolution
>
solverFactory
;
private
Solver
<
DispatchSolution
>
solver
;
private
Solver
<
DispatchSolution
>
solver
;
...
@@ -52,22 +52,22 @@ public class BatchScheduler {
...
@@ -52,22 +52,22 @@ public class BatchScheduler {
solver
=
solverFactory
.
buildSolver
();
solver
=
solverFactory
.
buildSolver
();
}
}
/*
/*
* 异步执行任务开始
* 异步执行任务开始
*/
*/
//@Scheduled(cron = "${dispatch.cron.expr}")
//@Scheduled(cron = "${dispatch.cron.expr}")
public
void
dispatchRun2
()
{
public
void
dispatchRun2
()
{
String
groupId
=
"gsuzhou"
;
String
groupId
=
"gsuzhou"
;
log
.
info
(
"dispatchRun group:{}"
,
groupId
);
log
.
info
(
"dispatchRun group:{}"
,
groupId
);
// TODO 分布式任务,循环大区/分部/分站/小队
// TODO 分布式任务,循环大区/分部/分站/小队
// 循环分站/网点下面的小队
// 循环分站/网点下面的小队
List
<
OrgTeamEntity
>
teams
=
orgTeamDao
.
findByGroupId
(
groupId
);
List
<
OrgTeamEntity
>
teams
=
orgTeamDao
.
findByGroupId
(
groupId
);
for
(
OrgTeamEntity
team
:
teams
)
{
for
(
OrgTeamEntity
team
:
teams
)
{
String
teamId
=
team
.
getTeamId
();
String
teamId
=
team
.
getTeamId
();
for
(
int
i
=
1
;
i
<=
nextDaysLimit
;
i
++)
{
for
(
int
i
=
1
;
i
<=
nextDaysLimit
;
i
++)
{
String
currDay
=
LocalDate
.
now
().
plusDays
(
i
).
format
(
DateTimeFormatter
.
ISO_LOCAL_DATE
);
String
currDay
=
LocalDate
.
now
().
plusDays
(
i
).
format
(
DateTimeFormatter
.
ISO_LOCAL_DATE
);
log
.
info
(
"dispatchRun begin----- teamId:{}, day:{}"
,
teamId
,
currDay
);
log
.
info
(
"dispatchRun begin----- teamId:{}, day:{}"
,
teamId
,
currDay
);
String
batchNo
=
batchService
.
buildBatchData2
(
teamId
,
currDay
,
false
);
String
batchNo
=
batchService
.
buildBatchData2
(
teamId
,
currDay
,
false
);
UUID
problemId
=
solveService
.
generateProblemId
(
teamId
,
batchNo
);
UUID
problemId
=
solveService
.
generateProblemId
(
teamId
,
batchNo
);
...
@@ -88,19 +88,19 @@ public class BatchScheduler {
...
@@ -88,19 +88,19 @@ public class BatchScheduler {
log
.
info
(
"dispatchRun done ------ teamId:{}, day:{}"
,
teamId
,
currDay
);
log
.
info
(
"dispatchRun done ------ teamId:{}, day:{}"
,
teamId
,
currDay
);
JacksonSolutionFileIO
<
DispatchSolution
>
exporter
=
new
JacksonSolutionFileIO
<
DispatchSolution
>(
DispatchSolution
.
class
);
JacksonSolutionFileIO
<
DispatchSolution
>
exporter
=
new
JacksonSolutionFileIO
<
DispatchSolution
>(
DispatchSolution
.
class
);
exporter
.
write
(
solution
,
new
File
(
String
.
format
(
"dispatchSolution_%s_%s.json"
,
teamId
,
currDay
)));
exporter
.
write
(
solution
,
new
File
(
String
.
format
(
"dispatchSolution_%s_%s.json"
,
teamId
,
currDay
)));
}
}
}
}
log
.
info
(
"dispatchRun group:{} done"
,
groupId
);
}
log
.
info
(
"dispatchRun group:{} done"
,
groupId
);
}
/*
/*
* 异步执行任务开始
* 异步执行任务开始
* */
* */
//@Scheduled(cron = "${dispatch.cron.expr}")
//@Scheduled(cron = "${dispatch.cron.expr}")
public
void
dispatchRun
()
{
public
void
dispatchRun
()
{
String
groupId
=
"gsuzhou"
;
String
groupId
=
"gsuzhou"
;
log
.
info
(
"dispatchRun group:{}"
,
groupId
);
log
.
info
(
"dispatchRun group:{}"
,
groupId
);
try
{
try
{
for
(
int
i
=
0
;
i
<=
nextDaysLimit
;
i
++)
{
for
(
int
i
=
0
;
i
<=
nextDaysLimit
;
i
++)
{
...
@@ -155,7 +155,7 @@ public class BatchScheduler {
...
@@ -155,7 +155,7 @@ public class BatchScheduler {
// Set the output file.
// Set the output file.
exporter
.
write
(
solution
,
new
File
(
String
.
format
(
"dispatchSolution_%s_%s.json"
,
groupId
,
currDay
)));
exporter
.
write
(
solution
,
new
File
(
String
.
format
(
"dispatchSolution_%s_%s.json"
,
groupId
,
currDay
)));
Thread
.
sleep
(
1000
*
5
);
Thread
.
sleep
(
1000
*
5
);
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/service/impl/ExtractServiceImpl.java
View file @
d772bb9
...
@@ -3,9 +3,12 @@ package com.dituhui.pea.dispatch.service.impl;
...
@@ -3,9 +3,12 @@ package com.dituhui.pea.dispatch.service.impl;
import
cn.hutool.core.date.DateTime
;
import
cn.hutool.core.date.DateTime
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.alibaba.nacos.common.utils.CollectionUtils
;
import
com.alibaba.nacos.common.utils.CollectionUtils
;
import
com.dituhui.pea.dispatch.dao.*
;
import
com.dituhui.pea.dispatch.dao.*
;
import
com.dituhui.pea.dispatch.entity.*
;
import
com.dituhui.pea.dispatch.entity.*
;
import
com.dituhui.pea.dispatch.pojo.Customer
;
import
com.dituhui.pea.dispatch.pojo.DispatchSolution
;
import
com.dituhui.pea.dispatch.service.ExtractService
;
import
com.dituhui.pea.dispatch.service.ExtractService
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Maps
;
...
@@ -295,7 +298,13 @@ public class ExtractServiceImpl implements ExtractService {
...
@@ -295,7 +298,13 @@ public class ExtractServiceImpl implements ExtractService {
orderInfo
.
setArriveElapsed
(
0
);
orderInfo
.
setArriveElapsed
(
0
);
orderInfo
.
setArriveDistance
(
0
);
orderInfo
.
setArriveDistance
(
0
);
orderInfo
.
setAppointmentStatus
(
"INIT"
);
orderInfo
.
setAppointmentStatus
(
"INIT"
);
orderInfo
.
setDispatcher
(
"AUTO_BATCH"
);
if
(
cutOff
)
{
orderInfo
.
setAppointmentMethod
(
"MANUAL"
);
orderInfo
.
setDispatcher
(
"MANUAL"
);
log
.
info
(
"算法结果更新到工单为人工, teamId:{}, batchNo:{}, orderId:{}"
,
teamId
,
batchNo
,
orderId
);
}
else
{
orderInfo
.
setDispatcher
(
"AUTO_BATCH"
);
}
orderInfo
.
setUpdateTime
(
LocalDateTime
.
now
());
orderInfo
.
setUpdateTime
(
LocalDateTime
.
now
());
orderInfoRepo
.
save
(
orderInfo
);
orderInfoRepo
.
save
(
orderInfo
);
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/service/impl/SchedulerServiceImpl.java
View file @
d772bb9
...
@@ -3,7 +3,6 @@ package com.dituhui.pea.dispatch.service.impl;
...
@@ -3,7 +3,6 @@ package com.dituhui.pea.dispatch.service.impl;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.dituhui.pea.dispatch.common.RedissonUtil
;
import
com.dituhui.pea.dispatch.dao.DispatchBatchRepository
;
import
com.dituhui.pea.dispatch.dao.DispatchBatchRepository
;
import
com.dituhui.pea.dispatch.dao.OrgGroupRepository
;
import
com.dituhui.pea.dispatch.dao.OrgGroupRepository
;
import
com.dituhui.pea.dispatch.dao.OrgTeamDao
;
import
com.dituhui.pea.dispatch.dao.OrgTeamDao
;
...
@@ -11,7 +10,6 @@ import com.dituhui.pea.dispatch.entity.DispatchBatch;
...
@@ -11,7 +10,6 @@ import com.dituhui.pea.dispatch.entity.DispatchBatch;
import
com.dituhui.pea.dispatch.entity.OrgGroup
;
import
com.dituhui.pea.dispatch.entity.OrgGroup
;
import
com.dituhui.pea.dispatch.entity.OrgTeamEntity
;
import
com.dituhui.pea.dispatch.entity.OrgTeamEntity
;
import
com.dituhui.pea.dispatch.pojo.DispatchSolution
;
import
com.dituhui.pea.dispatch.pojo.DispatchSolution
;
import
com.dituhui.pea.dispatch.quartz.dispatch.AutoDispatchJob
;
import
com.dituhui.pea.dispatch.service.BatchService
;
import
com.dituhui.pea.dispatch.service.BatchService
;
import
com.dituhui.pea.dispatch.service.ExtractService
;
import
com.dituhui.pea.dispatch.service.ExtractService
;
import
com.dituhui.pea.dispatch.service.SchedulerService
;
import
com.dituhui.pea.dispatch.service.SchedulerService
;
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/utils/RoadDistanceUtils.java
View file @
d772bb9
This diff is collapsed.
Click to expand it.
project-dispatch/src/main/resources/application-dev.yaml
View file @
d772bb9
...
@@ -3,7 +3,7 @@ server:
...
@@ -3,7 +3,7 @@ server:
dispatch
:
dispatch
:
cron
:
cron
:
expr
:
0
9
8-23 * * ?
expr
:
0
37
8-23 * * ?
next-day-limit
:
2
next-day-limit
:
2
scheduler
:
scheduler
:
...
...
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