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 e8cce6d9
authored
Nov 06, 2023
by
Ren Ping
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:自动任务优化
1 parent
9365265a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
29 deletions
project-dispatch/src/main/java/com/dituhui/pea/dispatch/service/impl/BatchServiceImpl.java
project-dispatch/src/main/resources/logback-spring.xml
project-order/src/main/resources/logback-spring.xml
project-dispatch/src/main/java/com/dituhui/pea/dispatch/service/impl/BatchServiceImpl.java
View file @
e8cce6d
...
@@ -11,10 +11,8 @@ import java.util.Optional;
...
@@ -11,10 +11,8 @@ import java.util.Optional;
import
javax.persistence.EntityManager
;
import
javax.persistence.EntityManager
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.dituhui.pea.dispatch.dao.DispatchEngineerRepository
;
import
com.dituhui.pea.dispatch.dao.*
;
import
com.dituhui.pea.dispatch.dao.DispatchOrderRepository
;
import
com.dituhui.pea.dispatch.entity.*
;
import
com.dituhui.pea.dispatch.entity.DispatchEngineer
;
import
com.dituhui.pea.dispatch.entity.DispatchOrder
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -22,10 +20,6 @@ import org.springframework.transaction.annotation.Isolation;
...
@@ -22,10 +20,6 @@ import org.springframework.transaction.annotation.Isolation;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.alibaba.nacos.common.utils.CollectionUtils
;
import
com.alibaba.nacos.common.utils.CollectionUtils
;
import
com.dituhui.pea.dispatch.dao.DispatchBatchRepository
;
import
com.dituhui.pea.dispatch.dao.OrderInfoRepository
;
import
com.dituhui.pea.dispatch.entity.DispatchBatch
;
import
com.dituhui.pea.dispatch.entity.OrderInfo
;
import
com.dituhui.pea.dispatch.service.BatchService
;
import
com.dituhui.pea.dispatch.service.BatchService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -53,6 +47,9 @@ public class BatchServiceImpl implements BatchService {
...
@@ -53,6 +47,9 @@ public class BatchServiceImpl implements BatchService {
OrderInfoRepository
orderInfoRepository
;
OrderInfoRepository
orderInfoRepository
;
@Autowired
@Autowired
OrgTeamDao
orgTeamDao
;
@Autowired
private
EntityManager
entityManager
;
private
EntityManager
entityManager
;
...
@@ -196,25 +193,23 @@ public class BatchServiceImpl implements BatchService {
...
@@ -196,25 +193,23 @@ public class BatchServiceImpl implements BatchService {
@Transactional
(
isolation
=
Isolation
.
READ_COMMITTED
,
rollbackFor
=
Exception
.
class
)
@Transactional
(
isolation
=
Isolation
.
READ_COMMITTED
,
rollbackFor
=
Exception
.
class
)
@Override
@Override
public
String
buildBatchData2
(
String
teamId
,
String
day
)
{
public
String
buildBatchData2
(
String
teamId
,
String
day
)
{
OrgTeamEntity
orgTeamEntity
=
orgTeamDao
.
findByTeamId
(
teamId
);
String
groupId
=
orgTeamEntity
.
getGroupId
();
entityManager
.
clear
();
entityManager
.
clear
();
log
.
info
(
"准备批次数据, teamId:{}, day:{}"
,
teamId
,
day
);
log
.
info
(
"准备批次数据, teamId:{}, day:{}"
,
teamId
,
day
);
String
batchNo
=
""
;
String
batchNo
=
""
;
String
batchDay
=
""
;
String
batchDay
=
""
;
if
(
"team_suzhou_001"
.
equals
(
teamId
)){
System
.
out
.
println
(
teamId
);
}
Optional
<
DispatchBatch
>
optional
=
batchRepository
.
findByTeamIdAndBatchDate
(
teamId
,
day
);
Optional
<
DispatchBatch
>
optional
=
batchRepository
.
findByTeamIdAndBatchDate
(
teamId
,
day
);
if
(!
optional
.
isPresent
())
{
if
(!
optional
.
isPresent
())
{
// 创建batch
// 创建batch
batchNo
=
calcBatchNo
(
day
);
batchNo
=
calcBatchNo
(
day
);
batchDay
=
day
;
batchDay
=
day
;
// 执行数据库操作
// 执行数据库操作
String
sqlInsert
=
"INSERT INTO `dispatch_batch` ( `team_id`, `batch_no`, `batch_date`, `engineer_num`, `order_num`, `start_time`, `end_time`, `status`) "
+
String
sqlInsert
=
"INSERT INTO `dispatch_batch` (
group_id,
`team_id`, `batch_no`, `batch_date`, `engineer_num`, `order_num`, `start_time`, `end_time`, `status`) "
+
" VALUES(?, ?, ?, ?, ?, ?, ?, ?)"
;
" VALUES(?, ?, ?, ?, ?, ?, ?, ?
, ?
)"
;
jdbcTemplate
.
update
(
sqlInsert
,
teamId
,
batchNo
,
batchDay
,
0
,
0
,
LocalDateTime
.
now
(),
null
,
"RUNNING"
);
jdbcTemplate
.
update
(
sqlInsert
,
groupId
,
teamId
,
batchNo
,
batchDay
,
0
,
0
,
LocalDateTime
.
now
(),
null
,
"RUNNING"
);
log
.
info
(
"生成新批次, teamId:{}, day:{}"
,
teamId
,
batchDay
);
log
.
info
(
"生成新批次, teamId:{}, day:{}"
,
teamId
,
batchDay
);
}
else
{
}
else
{
batchNo
=
optional
.
get
().
getBatchNo
();
batchNo
=
optional
.
get
().
getBatchNo
();
...
@@ -230,33 +225,29 @@ public class BatchServiceImpl implements BatchService {
...
@@ -230,33 +225,29 @@ public class BatchServiceImpl implements BatchService {
//dispatchOrderRepository.deleteAllInBatch(dispatchOrderRepository.findByTeamIdAndBatchNo(teamId,batchNo));
//dispatchOrderRepository.deleteAllInBatch(dispatchOrderRepository.findByTeamIdAndBatchNo(teamId,batchNo));
log
.
info
(
"写入新批次技术员、工单数据, teamId:{}, day:{}, batchNo:{}"
,
teamId
,
batchDay
,
batchNo
);
log
.
info
(
"写入新批次技术员、工单数据, teamId:{}, day:{}, batchNo:{}"
,
teamId
,
batchDay
,
batchNo
);
String
sqlEngineer
=
"INSERT INTO dispatch_engineer (team_id, batch_no, engineer_code, engineer_name, x, y, max_num, max_minute, max_distance, vehicle_type)\n"
String
sqlEngineer
=
"INSERT INTO dispatch_engineer (
group_id,
team_id, batch_no, engineer_code, engineer_name, x, y, max_num, max_minute, max_distance, vehicle_type)\n"
+
"SELECT o.team_id,?,o.engineer_code, a.name , b.x, b.y , max_num, max_minute, max_distance, b.vehicle FROM `org_team_engineer` o,engineer_info a,engineer_business b \n"
+
"SELECT
?,
o.team_id,?,o.engineer_code, a.name , b.x, b.y , max_num, max_minute, max_distance, b.vehicle FROM `org_team_engineer` o,engineer_info a,engineer_business b \n"
+
" WHERE o.team_id=? AND o.`status`=1\n"
+
" WHERE o.team_id=? AND o.`status`=1\n"
+
" AND o.engineer_code=a.engineer_code AND a.engineer_code = b.engineer_code \n"
+
" AND o.engineer_code=a.engineer_code AND a.engineer_code = b.engineer_code \n"
+
" AND b.x IS NOT NULL AND b.x !=''"
+
" order by a.engineer_code asc"
;
+
" AND b.x IS NOT NULL AND b.x !=''"
+
" order by a.engineer_code asc"
;
int
engCount
=
jdbcTemplate
.
update
(
sqlEngineer
,
batchNo
,
teamId
);
int
engCount
=
jdbcTemplate
.
update
(
sqlEngineer
,
groupId
,
batchNo
,
teamId
);
if
(
"team_suzhou_001"
.
equals
(
teamId
)){
System
.
out
.
println
(
teamId
);
}
// 未派过的工单(已派过PRE状态还可以再次派)
// 未派过的工单(已派过PRE状态还可以再次派)
String
sqlOrder
=
"INSERT INTO dispatch_order (group_id, batch_no, team_id, order_id , dt, x, y, \n"
String
sqlOrder
=
"INSERT INTO dispatch_order (group_id, batch_no, team_id, order_id , dt, x, y, \n"
+
" expect_time_begin, expect_time_end, tags, priority , skills , take_time, status )\n"
+
" expect_time_begin, expect_time_end, tags, priority , skills , take_time, status )\n"
+
" SELECT
a.org_group_id
, ?, a.org_team_id , a.order_id, ?, a.x, a.y , \n"
+
" SELECT
?
, ?, a.org_team_id , a.order_id, ?, a.x, a.y , \n"
+
" a.expect_time_begin, a.expect_time_end, a.tags, a.priority , \n"
+
" a.expect_time_begin, a.expect_time_end, a.tags, a.priority , \n"
+
" CONCAT(a.brand, '-', a.type, '-', a.skill) skills , a.take_time , a.appointment_status\n"
+
" CONCAT(a.brand, '-', a.type, '-', a.skill) skills , a.take_time , a.appointment_status\n"
+
" FROM order_info a \n"
+
" WHERE a.org_team_id=? AND a.dt = ? AND bean_status='OPEN'\n"
+
" FROM order_info a \n"
+
" WHERE a.org_team_id=? AND a.dt = ? AND bean_status='OPEN'\n"
+
" AND appointment_method LIKE 'AUTO%' AND a.appointment_status IN ('INIT', 'PRE')\n"
+
" AND appointment_method LIKE 'AUTO%' AND a.appointment_status IN ('INIT', 'PRE')\n"
+
" AND order_status ='NORMAL' AND service_status='INIT'\n"
+
" AND order_status ='NORMAL' AND service_status='INIT'\n"
+
" ORDER BY a.expect_time_begin ASC \n"
;
+
" ORDER BY a.expect_time_begin ASC \n"
;
int
orderCount
=
jdbcTemplate
.
update
(
sqlOrder
,
batchNo
,
batchDay
,
teamId
,
batchDay
);
int
orderCount
=
jdbcTemplate
.
update
(
sqlOrder
,
groupId
,
batchNo
,
batchDay
,
teamId
,
batchDay
);
// confirm的要做预占用,所以也加入进来
// confirm的要做预占用,所以也加入进来
String
sqlOrderConfirm
=
"INSERT INTO dispatch_order (group_id, batch_no, team_id, order_id , dt, x, y, \n"
+
String
sqlOrderConfirm
=
"INSERT INTO dispatch_order (group_id, batch_no, team_id, order_id , dt, x, y, \n"
+
" expect_time_begin, expect_time_end, tags, priority , skills , take_time, status, engineer_code, time_begin, time_end )\n"
+
" expect_time_begin, expect_time_end, tags, priority , skills , take_time, status, engineer_code, time_begin, time_end )\n"
+
" select
a.org_group_id
, ?, a.org_team_id , a.order_id, a.dt, a.x, a.y , \n"
+
" select
?
, ?, a.org_team_id , a.order_id, a.dt, a.x, a.y , \n"
+
" a.expect_time_begin, a.expect_time_end, a.tags, a.priority , \n"
+
" a.expect_time_begin, a.expect_time_end, a.tags, a.priority , \n"
+
" concat(a.brand, '-', a.type, '-', a.skill) skills , a.take_time, a.appointment_status, \n"
+
" concat(a.brand, '-', a.type, '-', a.skill) skills , a.take_time, a.appointment_status, \n"
+
" a.engineer_code, a.plan_start_time, a.plan_end_time \n"
+
" a.engineer_code, a.plan_start_time, a.plan_end_time \n"
+
...
@@ -265,7 +256,7 @@ public class BatchServiceImpl implements BatchService {
...
@@ -265,7 +256,7 @@ public class BatchServiceImpl implements BatchService {
" and appointment_method like 'AUTO%' and a.appointment_status in ('CONFIRM')\n"
+
" and appointment_method like 'AUTO%' and a.appointment_status in ('CONFIRM')\n"
+
" and order_status ='NORMAL' and service_status='INIT'\n"
+
" and order_status ='NORMAL' and service_status='INIT'\n"
+
" order by a.expect_time_begin asc "
;
" order by a.expect_time_begin asc "
;
int
orderConfirmCount
=
jdbcTemplate
.
update
(
sqlOrderConfirm
,
batchNo
,
teamId
,
batchDay
);
int
orderConfirmCount
=
jdbcTemplate
.
update
(
sqlOrderConfirm
,
groupId
,
batchNo
,
teamId
,
batchDay
);
log
.
info
(
"准备批次数据 engCount:{}, orderCount:{}, orderConfirmCount:{}"
,
engCount
,
orderCount
,
orderConfirmCount
);
log
.
info
(
"准备批次数据 engCount:{}, orderCount:{}, orderConfirmCount:{}"
,
engCount
,
orderCount
,
orderConfirmCount
);
...
...
project-dispatch/src/main/resources/logback-spring.xml
View file @
e8cce6d
...
@@ -117,7 +117,6 @@
...
@@ -117,7 +117,6 @@
<appender-ref
ref=
"console"
/>
<appender-ref
ref=
"console"
/>
<appender-ref
ref=
"FileAppender"
/>
<appender-ref
ref=
"FileAppender"
/>
<appender-ref
ref=
"FILE_ERROR"
/>
<appender-ref
ref=
"FILE_ERROR"
/>
<appender-ref
ref=
"FILE_DEBUG"
/>
</root>
</root>
</configuration>
</configuration>
\ No newline at end of file
project-order/src/main/resources/logback-spring.xml
View file @
e8cce6d
...
@@ -116,7 +116,7 @@
...
@@ -116,7 +116,7 @@
<appender-ref
ref=
"console"
/>
<appender-ref
ref=
"console"
/>
<appender-ref
ref=
"FileAppender"
/>
<appender-ref
ref=
"FileAppender"
/>
<appender-ref
ref=
"FILE_ERROR"
/>
<appender-ref
ref=
"FILE_ERROR"
/>
<
appender-ref
ref=
"FILE_DEBUG"
/
>
<
!--<appender-ref ref="FILE_DEBUG"/>--
>
</root>
</root>
</configuration>
</configuration>
\ No newline at end of file
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