Commit cad67587 by chamberone

fix: 添加数据复制逻辑

1 parent 44bd4786
package com.dituhui.pea.dispatch.service.impl;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;
import javax.persistence.EntityManager;
......@@ -13,8 +15,11 @@ import org.springframework.stereotype.Service;
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;
......@@ -33,6 +38,9 @@ public class BatchServiceImpl implements BatchService {
DispatchBatchRepository batchRepository;
@Autowired
OrderInfoRepository orderInfoRepository;
@Autowired
private EntityManager entityManager;
......@@ -76,9 +84,45 @@ public class BatchServiceImpl implements BatchService {
batchDay = optional.get().getBatchDate();
}
// int engCount = queryEnginerCount(groupId);
// int orderCount = queryOrderCount(groupId, batchDay);
// FIXME 因为系统暂时没有订单,每次固定拉取2023-08-13号订单数据生成新订单
LocalDate localDt = LocalDate.parse(batchDay, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
List<OrderInfo> orders = orderInfoRepository.findByOrgTeamIdAndDt(groupId, localDt);
if (CollectionUtils.isEmpty(orders)) {
String tempDay = "2023-08-13";
String createOrder = "INSERT INTO order_info (\r\n" + " order_id,\r\n" + " dt,\r\n" + " sub_id,\r\n"
+ " NAME,\r\n" + " phone,\r\n" + " province,\r\n" + " city,\r\n" + " county,\r\n"
+ " address,\r\n" + " X,\r\n" + " Y,\r\n" + " bean_brand,\r\n" + " brand,\r\n" + " TYPE,\r\n"
+ " skill,\r\n" + " take_time,\r\n" + " is_workshop,\r\n" + " fault_describe,\r\n"
+ " apply_note,\r\n" + " expect_time_begin,\r\n" + " expect_time_end,\r\n"
+ " expect_time_desc,\r\n" + " source,\r\n" + " bean_priority,\r\n" + " bean_tags,\r\n"
+ " bean_status,\r\n" + " bean_sub_status,\r\n" + " area_id,\r\n" + " org_cluster_id,\r\n"
+ " org_branch_id,\r\n" + " org_group_id,\r\n" + " org_team_id,\r\n" + " priority,\r\n"
+ " tags,\r\n" + " appointment_method,\r\n" + " appointment_status,\r\n" + " dispatcher,\r\n"
+ " order_status,\r\n" + " service_status,\r\n" + " engineer_code,\r\n" + " engineer_name,\r\n"
+ " engineer_phone,\r\n" + " engineer_code_sub,\r\n" + " plan_start_time,\r\n"
+ " plan_end_time,\r\n" + " arrive_elapsed,\r\n" + " arrive_distance,\r\n"
+ " actual_start_time,\r\n" + " actual_end_time,\r\n" + " description,\r\n" + " extra_info,\r\n"
+ " create_time,\r\n" + " update_time\r\n" + ") \r\n" + "SELECT \r\n" + " order_id,\r\n" + " '"
+ batchDay + "',\r\n" + " sub_id,\r\n" + " NAME,\r\n" + " phone,\r\n" + " province,\r\n"
+ " city,\r\n" + " county,\r\n" + " address,\r\n" + " X,\r\n" + " Y,\r\n" + " bean_brand,\r\n"
+ " brand,\r\n" + " TYPE,\r\n" + " skill,\r\n" + " take_time,\r\n" + " is_workshop,\r\n"
+ " fault_describe,\r\n" + " apply_note,\r\n" + " expect_time_begin,\r\n"
+ " expect_time_end,\r\n" + " expect_time_desc,\r\n" + " source,\r\n" + " bean_priority,\r\n"
+ " bean_tags,\r\n" + " bean_status,\r\n" + " bean_sub_status,\r\n" + " area_id,\r\n"
+ " org_cluster_id,\r\n" + " org_branch_id,\r\n" + " org_group_id,\r\n" + " org_team_id,\r\n"
+ " priority,\r\n" + " tags,\r\n" + " appointment_method,\r\n" + " appointment_status,\r\n"
+ " dispatcher,\r\n" + " order_status,\r\n" + " service_status,\r\n" + " engineer_code,\r\n"
+ " engineer_name,\r\n" + " engineer_phone,\r\n" + " engineer_code_sub,\r\n"
+ " plan_start_time,\r\n" + " plan_end_time,\r\n" + " arrive_elapsed,\r\n"
+ " arrive_distance,\r\n" + " actual_start_time,\r\n" + " actual_end_time,\r\n"
+ " description,\r\n" + " extra_info,\r\n" + " create_time,\r\n" + " update_time \r\n"
+ "FROM\r\n" + " order_info a \r\n" + "WHERE a.org_group_id = 'gsuzhou' \r\n" + " AND a.dt = '"
+ tempDay + "' \r\n" + " AND bean_status = 'OPEN' \r\n"
+ " AND appointment_method LIKE 'AUTO%' \r\n"
+ " AND a.appointment_status IN ('INIT', 'PRE') \r\n" + " AND order_status = 'NORMAL' \r\n"
+ " AND service_status = 'INIT' \r\n" + "";
int createCount = jdbcTemplate.update(createOrder, batchNo, batchDay, groupId, tempDay);
}
log.info("清理原批次数据, groupId:{}, day:{}, batchNo:{}", groupId, batchDay, batchNo);
jdbcTemplate.update("delete from dispatch_engineer where group_id=? and batch_no=?", groupId, batchNo);
......@@ -105,12 +149,7 @@ public class BatchServiceImpl implements BatchService {
" 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 ";
String tempDay = "2023-08-13";
int orderCount = jdbcTemplate.update(sqlOrder, batchNo, batchDay, groupId,
/**
* FIXME 因为系统暂时没有订单,每次固定拉取2023-08-13号数据tempDay,上线后改成batchDay
*/
tempDay);
int orderCount = jdbcTemplate.update(sqlOrder, batchNo, batchDay, groupId, batchDay);
// confirm的要做预占用,所以也加入进来
String sqlOrderConfirm = "INSERT INTO dispatch_order (group_id, batch_no, team_id, order_id , dt, x, y, \n" +
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!