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 750a4a41
authored
Jul 24, 2023
by
张晓
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dispatch_order表调整
1 parent
4d9524c5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
56 additions
and
27 deletions
project-dispatch/src/main/java/com/dituhui/pea/dispatch/dao/DispatchOrderRepository.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/dao/OrderInfoRepository.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/entity/DispatchOrder.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/entity/OrderInfo.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/pojo/Customer.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/service/ExtractService.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/SolveServiceImpl.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/utils/DataUtils.java
project-dispatch/src/test/java/com/dituhui/pea/dispatch/SolveServiceTest.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/dao/DispatchOrderRepository.java
View file @
750a4a4
...
@@ -19,5 +19,5 @@ public interface DispatchOrderRepository extends CrudRepository<DispatchOrder, L
...
@@ -19,5 +19,5 @@ public interface DispatchOrderRepository extends CrudRepository<DispatchOrder, L
@Query
(
"from DispatchOrder where groupId=?1 and batchNo=?2 and status !='CONFIRM' and ( engineerCode is not null and engineerCode!='') "
)
@Query
(
"from DispatchOrder where groupId=?1 and batchNo=?2 and status !='CONFIRM' and ( engineerCode is not null and engineerCode!='') "
)
List
<
DispatchOrder
>
findAssigned
(
String
groupId
,
String
batchNo
);
List
<
DispatchOrder
>
findAssigned
(
String
groupId
,
String
batchNo
);
Optional
<
DispatchOrder
>
findByGroupIdAndBatchNoAndOrderId
(
String
groupId
,
String
batchNo
,
String
orderId
);
Optional
<
DispatchOrder
>
findByGroupIdAndBatchNoAndOrderId
AndDt
(
String
groupId
,
String
batchNo
,
String
orderId
,
String
dt
);
}
}
\ No newline at end of file
project-dispatch/src/main/java/com/dituhui/pea/dispatch/dao/OrderInfoRepository.java
View file @
750a4a4
...
@@ -4,6 +4,7 @@ import com.dituhui.pea.dispatch.entity.OrderInfo;
...
@@ -4,6 +4,7 @@ import com.dituhui.pea.dispatch.entity.OrderInfo;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.CrudRepository
;
import
org.springframework.data.repository.CrudRepository
;
import
java.time.LocalDate
;
import
java.util.Optional
;
import
java.util.Optional
;
...
@@ -11,5 +12,6 @@ public interface OrderInfoRepository extends CrudRepository<OrderInfo, Long> {
...
@@ -11,5 +12,6 @@ public interface OrderInfoRepository extends CrudRepository<OrderInfo, Long> {
// @Query(value = "SELECT * FROM order_info WHERE order_id=:orderId ORDER BY dt DESC LIMIT 1",nativeQuery = true)
// @Query(value = "SELECT * FROM order_info WHERE order_id=:orderId ORDER BY dt DESC LIMIT 1",nativeQuery = true)
Optional
<
OrderInfo
>
findOrderInfoByOrderIdOrderByDtDesc
(
String
orderId
);
Optional
<
OrderInfo
>
findOrderInfoByOrderIdAndDt
(
String
orderId
,
LocalDate
dt
);
}
}
project-dispatch/src/main/java/com/dituhui/pea/dispatch/entity/DispatchOrder.java
View file @
750a4a4
...
@@ -36,6 +36,9 @@ public class DispatchOrder implements Serializable {
...
@@ -36,6 +36,9 @@ public class DispatchOrder implements Serializable {
@Column
(
name
=
"order_id"
)
@Column
(
name
=
"order_id"
)
private
String
orderId
;
private
String
orderId
;
@Column
(
name
=
"dt"
)
private
String
dt
;
@Column
(
name
=
"x"
)
@Column
(
name
=
"x"
)
private
String
X
;
private
String
X
;
...
@@ -76,6 +79,14 @@ public class DispatchOrder implements Serializable {
...
@@ -76,6 +79,14 @@ public class DispatchOrder implements Serializable {
@Column
(
name
=
"time_end"
)
@Column
(
name
=
"time_end"
)
private
LocalDateTime
timeEnd
;
private
LocalDateTime
timeEnd
;
//到达耗时(分钟)
@Column
(
name
=
"path_time"
)
private
Integer
pathTime
;
//到达距离(米)
@Column
(
name
=
"path_distance"
)
private
Integer
pathDistance
;
private
String
status
;
private
String
status
;
private
String
ext
;
private
String
ext
;
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/entity/OrderInfo.java
View file @
750a4a4
...
@@ -28,7 +28,10 @@ public class OrderInfo implements Serializable {
...
@@ -28,7 +28,10 @@ public class OrderInfo implements Serializable {
@Column
(
name
=
"order_id"
)
@Column
(
name
=
"order_id"
)
private
String
orderId
;
private
String
orderId
;
private
java
.
sql
.
Date
dt
;
@JsonDeserialize
(
using
=
LocalDateDeserializer
.
class
)
@JsonSerialize
(
using
=
LocalDateSerializer
.
class
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd"
)
private
LocalDate
dt
;
@Column
(
name
=
"sub_id"
)
@Column
(
name
=
"sub_id"
)
private
String
subId
;
private
String
subId
;
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/pojo/Customer.java
View file @
750a4a4
...
@@ -21,6 +21,8 @@ public class Customer {
...
@@ -21,6 +21,8 @@ public class Customer {
private
long
id
;
private
long
id
;
private
String
code
;
private
String
code
;
// orderid(code)+dt 确定唯一一条工单
private
String
dt
;
@JsonIgnore
@JsonIgnore
private
Location
location
;
private
Location
location
;
// 时间窗 分钟
// 时间窗 分钟
...
@@ -45,10 +47,11 @@ public class Customer {
...
@@ -45,10 +47,11 @@ public class Customer {
public
Customer
()
{
public
Customer
()
{
}
}
public
Customer
(
long
id
,
String
code
,
Location
location
,
int
startTime
,
int
endTime
,
String
requiredSkill
,
public
Customer
(
long
id
,
String
code
,
String
dt
,
Location
location
,
int
startTime
,
int
endTime
,
String
requiredSkill
,
int
serviceDuration
)
{
int
serviceDuration
)
{
this
.
id
=
id
;
this
.
id
=
id
;
this
.
code
=
code
;
this
.
code
=
code
;
this
.
dt
=
dt
;
this
.
location
=
location
;
this
.
location
=
location
;
this
.
startTime
=
startTime
;
this
.
startTime
=
startTime
;
this
.
endTime
=
endTime
;
this
.
endTime
=
endTime
;
...
@@ -116,7 +119,7 @@ public class Customer {
...
@@ -116,7 +119,7 @@ public class Customer {
}
}
/**
/**
* 与前一个订单或者出发地depot的距离
* 与前一个订单或者出发地depot的距离
(米)
*
*
* @return
* @return
*/
*/
...
@@ -132,7 +135,7 @@ public class Customer {
...
@@ -132,7 +135,7 @@ public class Customer {
}
}
/**
/**
* 与前一个订单或者出发地depot的路程时间
* 与前一个订单或者出发地depot的路程时间
(分钟)
*
*
* @return
* @return
*/
*/
...
@@ -168,16 +171,17 @@ public class Customer {
...
@@ -168,16 +171,17 @@ public class Customer {
return
"Customer{"
+
return
"Customer{"
+
"id="
+
id
+
"id="
+
id
+
", code='"
+
code
+
'\''
+
", code='"
+
code
+
'\''
+
", dt='"
+
dt
+
'\''
+
", location="
+
location
+
", location="
+
location
+
", startTime="
+
startTime
+
", startTime="
+
startTime
+
", endTime="
+
endTime
+
", endTime="
+
endTime
+
", serviceDuration="
+
serviceDuration
+
", serviceDuration="
+
serviceDuration
+
", requiredSkill='"
+
requiredSkill
+
'\''
+
", requiredSkill='"
+
requiredSkill
+
'\''
+
", technician="
+
((
technician
!=
null
)
?
technician
.
getCode
()
:
"null"
)
+
", technician="
+
((
technician
!=
null
)
?
technician
.
getCode
()
:
"null"
)
+
", previousCustomer="
+
((
previousCustomer
!=
null
)
?
previousCustomer
.
getCode
()
:
"null"
)
+
", previousCustomer="
+
((
previousCustomer
!=
null
)
?
previousCustomer
.
getCode
()
:
"null"
)
+
", nextCustomer="
+
((
nextCustomer
!=
null
)
?
nextCustomer
.
getCode
()
:
"null"
)
+
", nextCustomer="
+
((
nextCustomer
!=
null
)
?
nextCustomer
.
getCode
()
:
"null"
)
+
", arrivalTime="
+
arrivalTime
+
", arrivalTime="
+
arrivalTime
+
", departureTime="
+
((
getDepartureTime
()
!=
null
)
?
getDepartureTime
()
:
0
)
+
", departureTime="
+
((
getDepartureTime
()
!=
null
)
?
getDepartureTime
()
:
0
)
+
'}'
;
'}'
;
}
}
}
}
project-dispatch/src/main/java/com/dituhui/pea/dispatch/service/ExtractService.java
View file @
750a4a4
...
@@ -19,9 +19,7 @@ public interface ExtractService {
...
@@ -19,9 +19,7 @@ public interface ExtractService {
/*
/*
* 将dispath_order 中的计算结果,回写到 order_request, order_appointment
* 将dispath_order 中的计算结果,回写到 order_info
* order_appointment(新增、更新)
* order_request(主要更新状态)
* */
* */
void
extractDispatchToOrder
(
String
groupId
,
String
batchNo
,
boolean
isConfirm
)
;
void
extractDispatchToOrder
(
String
groupId
,
String
batchNo
,
boolean
isConfirm
)
;
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/service/impl/ExtractServiceImpl.java
View file @
750a4a4
...
@@ -16,7 +16,9 @@ import org.springframework.transaction.annotation.Transactional;
...
@@ -16,7 +16,9 @@ import org.springframework.transaction.annotation.Transactional;
import
javax.persistence.EntityManager
;
import
javax.persistence.EntityManager
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.Optional
;
...
@@ -34,7 +36,6 @@ import static org.springframework.transaction.annotation.Isolation.READ_COMMITTE
...
@@ -34,7 +36,6 @@ import static org.springframework.transaction.annotation.Isolation.READ_COMMITTE
@Service
@Service
public
class
ExtractServiceImpl
implements
ExtractService
{
public
class
ExtractServiceImpl
implements
ExtractService
{
@Autowired
@Autowired
EngineerInfoRepository
engineerInfoRepo
;
EngineerInfoRepository
engineerInfoRepo
;
...
@@ -60,9 +61,8 @@ public class ExtractServiceImpl implements ExtractService {
...
@@ -60,9 +61,8 @@ public class ExtractServiceImpl implements ExtractService {
/**
/**
* 将dispath_order 中的计算结果,回写到 order_request, order_appointment
* 将dispath_order 中的计算结果,回写到 order_info
* order_appointment(新增、更新)
* order_info(主要更新状态)
* order_request(主要更新状态)
*/
*/
@Transactional
(
isolation
=
READ_COMMITTED
,
propagation
=
Propagation
.
REQUIRED
)
@Transactional
(
isolation
=
READ_COMMITTED
,
propagation
=
Propagation
.
REQUIRED
)
@Override
@Override
...
@@ -82,11 +82,13 @@ public class ExtractServiceImpl implements ExtractService {
...
@@ -82,11 +82,13 @@ public class ExtractServiceImpl implements ExtractService {
int
idx
=
atomicInteger
.
getAndIncrement
();
int
idx
=
atomicInteger
.
getAndIncrement
();
String
orderId
=
dispatchOrder
.
getOrderId
();
String
orderId
=
dispatchOrder
.
getOrderId
();
String
engCode
=
dispatchOrder
.
getEngineerCode
();
String
engCode
=
dispatchOrder
.
getEngineerCode
();
log
.
info
(
"算法结果更新到工单, step1.1-loop, {}/{}, groupId:{}, batchNo:{}, orderId:{}, engCode:{}"
,
String
dt
=
dispatchOrder
.
getDt
();
idx
,
dispatchOrderList
.
size
(),
groupId
,
batchNo
,
orderId
,
engCode
);
log
.
info
(
"算法结果更新到工单, step1.1-loop, {}/{}, groupId:{}, batchNo:{}, orderId:{}, dt:{}, engCode:{}"
,
idx
,
dispatchOrderList
.
size
(),
groupId
,
batchNo
,
orderId
,
dt
,
engCode
);
Optional
<
OrderInfo
>
orderOpt
=
orderInfoRepo
.
findOrderInfoByOrderIdOrderByDtDesc
(
orderId
);
LocalDate
localDt
=
LocalDate
.
parse
(
dt
,
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
));
if
(!
orderOpt
.
isPresent
())
{
Optional
<
OrderInfo
>
orderOpt
=
orderInfoRepo
.
findOrderInfoByOrderIdAndDt
(
orderId
,
localDt
);
if
(
orderOpt
.
isEmpty
())
{
log
.
warn
(
"算法结果更新到工单, step1.1-loop, 工单不存在, groupId:{}, batchNo:{}, orderId:{}"
,
log
.
warn
(
"算法结果更新到工单, step1.1-loop, 工单不存在, groupId:{}, batchNo:{}, orderId:{}"
,
groupId
,
batchNo
,
orderId
);
groupId
,
batchNo
,
orderId
);
return
;
return
;
...
@@ -121,15 +123,13 @@ public class ExtractServiceImpl implements ExtractService {
...
@@ -121,15 +123,13 @@ public class ExtractServiceImpl implements ExtractService {
age = DateUtil.age(birthDate.toJdkDate(), DateUtil.date());
age = DateUtil.age(birthDate.toJdkDate(), DateUtil.date());
}*/
}*/
if
(
"NOT_ASSIGNED"
.
equals
(
orderInfo
.
getAppointmentStatus
()))
{
jdbcTemplate
.
update
(
"update order_request set appointment_status ='ASSIGNED' where order_id =? and appointment_status='NOT_ASSIGNED'"
,
orderId
);
}
orderInfo
.
setEngineerCode
(
engCode
);
orderInfo
.
setEngineerCode
(
engCode
);
orderInfo
.
setEngineerName
(
engName
);
orderInfo
.
setEngineerName
(
engName
);
orderInfo
.
setEngineerPhone
(
phone
);
orderInfo
.
setEngineerPhone
(
phone
);
orderInfo
.
setPlanStartTime
(
dispatchOrder
.
getTimeBegin
());
orderInfo
.
setPlanStartTime
(
dispatchOrder
.
getTimeBegin
());
orderInfo
.
setPlanEndTime
(
dispatchOrder
.
getTimeEnd
());
orderInfo
.
setPlanEndTime
(
dispatchOrder
.
getTimeEnd
());
orderInfo
.
setArriveElapsed
(
dispatchOrder
.
getPathTime
());
orderInfo
.
setArriveDistance
(
dispatchOrder
.
getPathDistance
());
orderInfo
.
setAppointmentStatus
(
isConfirm
?
"CONFIRM"
:
"PRE"
);
orderInfo
.
setAppointmentStatus
(
isConfirm
?
"CONFIRM"
:
"PRE"
);
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/SolveServiceImpl.java
View file @
750a4a4
This diff is collapsed.
Click to expand it.
project-dispatch/src/main/java/com/dituhui/pea/dispatch/utils/DataUtils.java
View file @
750a4a4
...
@@ -264,7 +264,7 @@ public class DataUtils {
...
@@ -264,7 +264,7 @@ public class DataUtils {
// 初始化订单+技能服务时间
// 初始化订单+技能服务时间
List
<
Customer
>
customerList
=
new
ArrayList
<>();
List
<
Customer
>
customerList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
customerIndexMap
.
keySet
().
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
customerIndexMap
.
keySet
().
size
();
i
++)
{
customerList
.
add
(
new
Customer
(
i
+
1
,
customerIndexMap
.
get
(
i
+
1
),
locationIndex
.
get
(
i
+
2
),
customerList
.
add
(
new
Customer
(
i
+
1
,
customerIndexMap
.
get
(
i
+
1
),
"2000-01-01"
,
locationIndex
.
get
(
i
+
2
),
customerStartMap
.
get
(
i
+
1
),
customerEndMap
.
get
(
i
+
1
),
customerSkillMap
.
get
(
i
+
1
),
customerStartMap
.
get
(
i
+
1
),
customerEndMap
.
get
(
i
+
1
),
customerSkillMap
.
get
(
i
+
1
),
// 初始化技能服务时间
// 初始化技能服务时间
customerCodeServiceTimeMap
.
get
(
customerIndexMap
.
get
(
i
+
1
))));
customerCodeServiceTimeMap
.
get
(
customerIndexMap
.
get
(
i
+
1
))));
...
...
project-dispatch/src/test/java/com/dituhui/pea/dispatch/SolveServiceTest.java
View file @
750a4a4
...
@@ -42,7 +42,7 @@ class SolveServiceTest {
...
@@ -42,7 +42,7 @@ class SolveServiceTest {
ExtractService
extractService
;
ExtractService
extractService
;
String
groupId
=
"gsuzhou"
;
String
groupId
=
"gsuzhou"
;
String
day
=
"2023-0
3-20
"
;
String
day
=
"2023-0
7-23
"
;
private
SolverManager
<
DispatchSolution
,
UUID
>
solverManager
;
private
SolverManager
<
DispatchSolution
,
UUID
>
solverManager
;
private
SolverFactory
<
DispatchSolution
>
solverFactory
;
private
SolverFactory
<
DispatchSolution
>
solverFactory
;
...
@@ -53,7 +53,7 @@ class SolveServiceTest {
...
@@ -53,7 +53,7 @@ class SolveServiceTest {
SolverConfig
solverConfig
=
new
SolverConfig
().
withSolutionClass
(
DispatchSolution
.
class
);
SolverConfig
solverConfig
=
new
SolverConfig
().
withSolutionClass
(
DispatchSolution
.
class
);
solverConfig
.
withEntityClassList
(
Arrays
.
asList
(
Technician
.
class
,
Customer
.
class
));
// 这里不能漏掉,否则约束不生效
solverConfig
.
withEntityClassList
(
Arrays
.
asList
(
Technician
.
class
,
Customer
.
class
));
// 这里不能漏掉,否则约束不生效
solverConfig
.
withConstraintProviderClass
(
DispatchConstraintProvider
.
class
);
solverConfig
.
withConstraintProviderClass
(
DispatchConstraintProvider
.
class
);
solverConfig
.
withTerminationSpentLimit
(
Duration
.
ofSeconds
(
10
));
solverConfig
.
withTerminationSpentLimit
(
Duration
.
ofSeconds
(
5
));
solverFactory
=
SolverFactory
.
create
(
solverConfig
);
solverFactory
=
SolverFactory
.
create
(
solverConfig
);
solver
=
solverFactory
.
buildSolver
();
solver
=
solverFactory
.
buildSolver
();
...
@@ -81,7 +81,17 @@ class SolveServiceTest {
...
@@ -81,7 +81,17 @@ class SolveServiceTest {
solveService
.
saveSolutionWrp
(
solution
);
solveService
.
saveSolutionWrp
(
solution
);
extractService
.
extractDispatchToOrder
(
groupId
,
batchNo
,
false
);
extractService
.
extractDispatchToOrder
(
groupId
,
batchNo
,
false
);
log
.
info
(
"testAsync done"
);
log
.
info
(
"testAsync done"
);
}
}
@Test
public
void
testExtraceToOrder
()
throws
InterruptedException
{
log
.
info
(
"testExtraceToOrder init"
);
String
batchNo
=
"20230723-0810"
;
extractService
.
extractDispatchToOrder
(
groupId
,
batchNo
,
false
);
log
.
info
(
"testExtraceToOrder done"
);
}
}
}
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