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 a540e135
authored
Jun 30, 2023
by
张晓
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口逻辑增加
1 parent
ede28e8b
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
162 additions
and
10 deletions
pom.xml
project-pre-dispatch/pom.xml
project-pre-dispatch/src/main/java/com/dituhui/pea/pre/controller/BatchController.java
project-pre-dispatch/src/main/java/com/dituhui/pea/pre/controller/PrepareController.java
project-pre-dispatch/src/main/java/com/dituhui/pea/pre/scheduler/Scheduler.java
project-pre-dispatch/src/main/java/com/dituhui/pea/pre/service/BatchService.java
project-pre-dispatch/src/main/java/com/dituhui/pea/pre/service/impl/BatchServiceImpl.java
project-pre-dispatch/src/main/resources/application.yaml
pom.xml
View file @
a540e13
...
...
@@ -100,7 +100,7 @@
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<optional>
true
</optional>
<version>
1.18.
16
</version>
<version>
1.18.
24
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
...
...
project-pre-dispatch/pom.xml
View file @
a540e13
...
...
@@ -125,6 +125,14 @@
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-devtools
</artifactId>
<!-- <scope>runtime</scope>-->
<!-- <optional>true</optional>-->
</dependency>
</dependencies>
<build>
<plugins>
...
...
project-pre-dispatch/src/main/java/com/dituhui/pea/pre/controller/BatchController.java
0 → 100644
View file @
a540e13
package
com
.
dituhui
.
pea
.
pre
.
controller
;
import
com.dituhui.pea.common.Result
;
import
com.dituhui.pea.pre.entity.DispatchBatch
;
import
com.dituhui.pea.pre.service.BatchService
;
import
lombok.Data
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.sql.SQLException
;
import
java.time.LocalDateTime
;
/**
* @author zhangx
*/
@Slf4j
@RequestMapping
(
"/pea-pre"
)
@RestController
public
class
BatchController
{
@Autowired
BatchService
batchService
;
/*
* 检查指定日期的小组是否有在运行的批次任务,有则返回,没有则创建后返回批次码
*/
@GetMapping
(
"/batch/build/{groupId}/{day}"
)
public
Result
<?>
buildBatch
(
@PathVariable
String
groupId
,
@PathVariable
String
day
)
{
log
.
info
(
"buildBatch, groupId:{}, day:{}"
,
groupId
,
day
);
try
{
String
batchNo
=
batchService
.
buildBatchNo
(
groupId
,
day
);
DispatchBatch
batch
=
batchService
.
queryBatch
(
groupId
,
batchNo
);
DispatchBatchDTO
batchDTO
=
new
DispatchBatchDTO
();
BeanUtils
.
copyProperties
(
batch
,
batchDTO
);
return
Result
.
success
(
batchDTO
);
}
catch
(
SQLException
e
)
{
log
.
error
(
"buildBatch error"
,
e
);
return
Result
.
failed
(
e
.
getMessage
());
}
}
@GetMapping
(
"/batch/query/{groupId}/{batchNo}"
)
public
Result
<?>
queryBatch
(
@PathVariable
String
groupId
,
@PathVariable
String
batchNo
)
{
log
.
info
(
"buildBatch, groupId:{}, batchNo:{}"
,
groupId
,
batchNo
);
DispatchBatch
batch
=
batchService
.
queryBatch
(
groupId
,
batchNo
);
DispatchBatchDTO
batchDTO
=
new
DispatchBatchDTO
();
BeanUtils
.
copyProperties
(
batch
,
batchDTO
);
return
Result
.
success
(
batch
);
}
@Data
class
DispatchBatchDTO
{
String
groupId
;
String
batchNo
;
int
engineerNum
;
int
orderNum
;
LocalDateTime
startTime
;
LocalDateTime
endTime
;
String
status
;
}
}
project-pre-dispatch/src/main/java/com/dituhui/pea/pre/controller/PrepareController.java
0 → 100644
View file @
a540e13
package
com
.
dituhui
.
pea
.
pre
.
controller
;
import
cn.hutool.core.map.MapUtil
;
import
com.dituhui.pea.common.Result
;
import
com.dituhui.pea.pre.opta.domain.Vehicle
;
import
com.dituhui.pea.pre.opta.domain.VehicleRoutingSolution
;
import
com.dituhui.pea.pre.service.BatchService
;
import
com.dituhui.pea.pre.service.PrepareService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.optaplanner.core.api.score.buildin.hardsoftlong.HardSoftLongScore
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.sql.SQLException
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author zhangx
*/
@Slf4j
@RequestMapping
(
"/pea-pre"
)
@RestController
public
class
PrepareController
{
@Autowired
PrepareService
prepareService
;
/*
* 检查指定日期的小组是否有在运行的批次任务,有则返回,没有则创建后返回批次码
*/
@GetMapping
(
"/prepare/solve/{groupId}/{batchNo}"
)
public
Result
<?>
prepareAndSolve
(
@PathVariable
String
groupId
,
@PathVariable
String
batchNo
)
{
log
.
info
(
"prepareSolve, groupId:{}, day:{}"
,
groupId
,
batchNo
);
VehicleRoutingSolution
solution
=
prepareService
.
prepareAndSolveSolution
(
groupId
,
batchNo
);
List
<
Vehicle
>
engineerList
=
solution
.
getVehicleList
();
HardSoftLongScore
score
=
solution
.
getScore
();
log
.
info
(
"prepareSolve done, groupId:{}, day:{}, score:{}"
,
groupId
,
batchNo
,
score
.
toString
());
Map
<
String
,
Object
>
resultMap
=
MapUtil
.
builder
(
new
HashMap
<
String
,
Object
>()).
put
(
"score"
,
score
).
put
(
"engineers"
,
engineerList
).
build
();
return
Result
.
success
(
resultMap
);
}
}
project-pre-dispatch/src/main/java/com/dituhui/pea/pre/scheduler/Scheduler.java
View file @
a540e13
...
...
@@ -5,17 +5,21 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
/**
* @author zhangx
*/
@Slf4j
@Component
public
class
Scheduler
{
@Scheduled
(
fixedRate
=
1000
*
10
)
//
@Scheduled(fixedRate = 1000*10)
public
void
RunLog
(){
log
.
info
(
"RunLog"
);
}
@Scheduled
(
cron
=
"${pre-dispatch.cron.expr}"
)
//
@Scheduled(cron = "${pre-dispatch.cron.expr}")
public
void
dispatchRun
(){
log
.
info
(
"dispatchRun"
);
}
...
...
project-pre-dispatch/src/main/java/com/dituhui/pea/pre/service/BatchService.java
View file @
a540e13
package
com
.
dituhui
.
pea
.
pre
.
service
;
import
com.dituhui.pea.pre.entity.DispatchBatch
;
import
java.sql.SQLException
;
/**
* @author zhangx
*
* 批次排班数据准备
*
* <p>
* 批次排班数据准备
*/
public
interface
BatchService
{
// 检查指定日期的小组是否有在运行的批次任务,有则返回,没有则创建后返回批次码
String
buildBatchNo
(
String
groupId
,
String
day
)
throws
SQLException
;
DispatchBatch
queryBatch
(
String
groupId
,
String
day
);
}
project-pre-dispatch/src/main/java/com/dituhui/pea/pre/service/impl/BatchServiceImpl.java
View file @
a540e13
...
...
@@ -16,6 +16,7 @@ import java.sql.SQLException;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.List
;
import
java.util.Optional
;
...
...
@@ -144,4 +145,15 @@ public class BatchServiceImpl implements BatchService {
return
batchNo
;
}
public
DispatchBatch
queryBatch
(
String
groupId
,
String
batchNo
)
{
List
<
DispatchBatch
>
batchList
=
batchRepository
.
findLatestGroup
(
groupId
,
batchNo
);
if
(
batchList
.
size
()
>
0
)
{
return
batchList
.
get
(
0
);
}
else
{
return
new
DispatchBatch
();
}
}
}
project-pre-dispatch/src/main/resources/application.yaml
View file @
a540e13
server
:
port
:
8012
pre-dispatch
:
cron
:
expr
:
0 */5 8-18 * * ?
...
...
@@ -13,7 +10,7 @@ spring:
name
:
project-pre-dispatch
jackson
:
default-property-inclusion
:
NON_NULL
#
time-zone: GMT+8
time-zone
:
GMT+8
date-format
:
yyyy-MM-dd HH:mm:ss
cloud
:
...
...
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