Commit e8cce6d9 by Ren Ping

fix:自动任务优化

1 parent 9365265a
......@@ -11,10 +11,8 @@ import java.util.Optional;
import javax.persistence.EntityManager;
import com.alibaba.fastjson.JSONObject;
import com.dituhui.pea.dispatch.dao.DispatchEngineerRepository;
import com.dituhui.pea.dispatch.dao.DispatchOrderRepository;
import com.dituhui.pea.dispatch.entity.DispatchEngineer;
import com.dituhui.pea.dispatch.entity.DispatchOrder;
import com.dituhui.pea.dispatch.dao.*;
import com.dituhui.pea.dispatch.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
......@@ -22,10 +20,6 @@ import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
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 lombok.extern.slf4j.Slf4j;
......@@ -53,6 +47,9 @@ public class BatchServiceImpl implements BatchService {
OrderInfoRepository orderInfoRepository;
@Autowired
OrgTeamDao orgTeamDao;
@Autowired
private EntityManager entityManager;
......@@ -196,25 +193,23 @@ public class BatchServiceImpl implements BatchService {
@Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
@Override
public String buildBatchData2(String teamId, String day) {
OrgTeamEntity orgTeamEntity = orgTeamDao.findByTeamId(teamId);
String groupId = orgTeamEntity.getGroupId();
entityManager.clear();
log.info("准备批次数据, teamId:{}, day:{}", teamId, day);
String batchNo = "";
String batchDay = "";
if("team_suzhou_001".equals(teamId)){
System.out.println(teamId);
}
Optional<DispatchBatch> optional = batchRepository.findByTeamIdAndBatchDate(teamId, day);
if (!optional.isPresent()) {
// 创建batch
batchNo = calcBatchNo(day);
batchDay = day;
// 执行数据库操作
String sqlInsert = "INSERT INTO `dispatch_batch` ( `team_id`, `batch_no`, `batch_date`, `engineer_num`, `order_num`, `start_time`, `end_time`, `status`) " +
" VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
String sqlInsert = "INSERT INTO `dispatch_batch` (group_id, `team_id`, `batch_no`, `batch_date`, `engineer_num`, `order_num`, `start_time`, `end_time`, `status`) " +
" 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);
} else {
batchNo = optional.get().getBatchNo();
......@@ -230,33 +225,29 @@ public class BatchServiceImpl implements BatchService {
//dispatchOrderRepository.deleteAllInBatch(dispatchOrderRepository.findByTeamIdAndBatchNo(teamId,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"
+ "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"
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"
+ " 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 b.x IS NOT NULL AND b.x !=''" + " order by a.engineer_code asc";
int engCount = jdbcTemplate.update(sqlEngineer, batchNo, teamId);
if("team_suzhou_001".equals(teamId)){
System.out.println(teamId);
}
int engCount = jdbcTemplate.update(sqlEngineer, groupId, batchNo, teamId);
// 未派过的工单(已派过PRE状态还可以再次派)
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"
+ " 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"
+ " 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"
+ " AND appointment_method LIKE 'AUTO%' AND a.appointment_status IN ('INIT', 'PRE')\n"
+ " AND order_status ='NORMAL' AND service_status='INIT'\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的要做预占用,所以也加入进来
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" +
" 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" +
" 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" +
......@@ -265,7 +256,7 @@ public class BatchServiceImpl implements BatchService {
" and appointment_method like 'AUTO%' and a.appointment_status in ('CONFIRM')\n" +
" and order_status ='NORMAL' and service_status='INIT'\n" +
" 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);
......
......@@ -117,7 +117,6 @@
<appender-ref ref="console"/>
<appender-ref ref="FileAppender"/>
<appender-ref ref="FILE_ERROR"/>
<appender-ref ref="FILE_DEBUG"/>
</root>
</configuration>
\ No newline at end of file
......@@ -116,7 +116,7 @@
<appender-ref ref="console"/>
<appender-ref ref="FileAppender"/>
<appender-ref ref="FILE_ERROR"/>
<appender-ref ref="FILE_DEBUG"/>
<!--<appender-ref ref="FILE_DEBUG"/>-->
</root>
</configuration>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!