Commit 99e21ea6 by huangjinxin

fix:指派插单公里换成米,订单筛选添加延误,超时

1 parent e89c42fb
......@@ -6,7 +6,7 @@ import lombok.Data;
public class DistanceDTO {
/**
* 单位 公里
* 单位 米
*/
float dis;
/**
......
......@@ -82,27 +82,27 @@ public interface OrderInfoDao extends JpaRepository<OrderInfoEntity, Long>, JpaS
@Query(value = "SELECT count(*) from order_info WHERE dt =:dt and (service_status ='INIT' or service_status ='CONTACTED') " +
"and DATE_ADD(NOW(), INTERVAL 10 MINUTE) > expect_time_begin and org_cluster_id = :orgCusterId", nativeQuery = true)
"and DATE_SUB(NOW(), INTERVAL 10 MINUTE) > plan_start_time and org_cluster_id = :orgCusterId", nativeQuery = true)
long countDelayByDtAndOrgClusterId(LocalDate dt, String orgCusterId);
@Query(value = "SELECT count(*) from order_info WHERE dt =:dt and (service_status ='INIT' or service_status ='CONTACTED') " +
"and DATE_ADD(NOW(), INTERVAL 10 MINUTE) > expect_time_begin and org_group_id = :orgGroupId", nativeQuery = true)
"and DATE_SUB(NOW(), INTERVAL 10 MINUTE) > plan_start_time and org_group_id = :orgGroupId", nativeQuery = true)
long countDelayByDtAndOrgGroupId(LocalDate dt, String orgGroupId);
@Query(value = "SELECT count(*) from order_info WHERE dt =:dt and (service_status ='INIT' or service_status ='CONTACTED') " +
"and DATE_ADD(NOW(), INTERVAL 10 MINUTE) > expect_time_begin and org_branch_id = :orgBranchId", nativeQuery = true)
"and DATE_SUB(NOW(), INTERVAL 10 MINUTE) > plan_start_time and org_branch_id = :orgBranchId", nativeQuery = true)
long countDelayByDtAndOrgBranchId(LocalDate dt, String orgBranchId);
@Query(value = "SELECT count(*) from order_info WHERE dt =:dt and service_status ='STARTED' and actual_end_time is null " +
"and DATE_ADD(NOW(), INTERVAL 10 MINUTE) > plan_end_time and org_cluster_id = :orgCusterId", nativeQuery = true)
"and DATE_SUB(NOW(), INTERVAL 10 MINUTE) > plan_end_time and org_cluster_id = :orgCusterId", nativeQuery = true)
long countOvertimeByDtAndOrgClusterId(LocalDate dt, String orgCusterId);
@Query(value = "SELECT count(*) from order_info WHERE dt =:dt and service_status ='STARTED' and actual_end_time is null " +
"and DATE_ADD(NOW(), INTERVAL 10 MINUTE) > plan_end_time and org_group_id = :orgGroupId", nativeQuery = true)
"and DATE_SUB(NOW(), INTERVAL 10 MINUTE) > plan_end_time and org_group_id = :orgGroupId", nativeQuery = true)
long countOvertimeByDtAndOrgGroupId(LocalDate dt, String orgGroupId);
@Query(value = "SELECT count(*) from order_info WHERE dt =:dt and service_status ='STARTED' and actual_end_time is null " +
"and DATE_ADD(NOW(), INTERVAL 10 MINUTE) > plan_end_time and org_branch_id = :orgBranchId", nativeQuery = true)
"and DATE_SUB(NOW(), INTERVAL 10 MINUTE) > plan_end_time and org_branch_id = :orgBranchId", nativeQuery = true)
long countOvertimeByDtAndOrgBranchId(LocalDate dt, String orgBranchId);
@Query(value = "from OrderInfoEntity where orderStatus <> 'CANCELED'"
......
......@@ -43,4 +43,14 @@ public class OrderServiceListReq {
* 服务状态
*/
private List<String> serviceStatus;
/**
* 1所需工时、2创建时间、3预约单状态、4指派状态、5指派策略、6服务状态 默认2创建时间
*/
private Integer orderByField = 2;
/**
* 1正序、2倒序 默认2倒序
*/
private Integer orderBy = 2;
}
\ No newline at end of file
......@@ -566,7 +566,7 @@ public class OrderInfoServiceImpl implements OrderInfoService {
OrderInfoEntity nestOrder = orderInfoDao.getByOrderId(nestOrderSegment.getOrderId());
nestOrder.setArriveElapsed(roadTime);
nestOrder.setArriveDistance(BigDecimal.valueOf(distanceDTO.getDis() * 1000).intValue());
nestOrder.setArriveDistance(BigDecimal.valueOf(distanceDTO.getDis()).intValue());
if (orderSegment.getStart().plusMinutes(takeTime + roadTime).compareTo(nestOrder.getPlanStartTime()) > 0) {
long minutes = Duration.between(nestOrder.getPlanStartTime(), planStartTime.plusMinutes(skillInfo.getTakeTime() + roadTime)).toMinutes();
nestOrder.setPlanStartTime(nestOrder.getPlanStartTime().plusMinutes(minutes));
......@@ -592,12 +592,12 @@ public class OrderInfoServiceImpl implements OrderInfoService {
insertOrder.setPlanStartTime(planStartTime);
insertOrder.setPlanEndTime(planStartTime.plusMinutes(skillInfo.getTakeTime()));
insertOrder.setArriveElapsed(roadTime);
insertOrder.setArriveDistance(BigDecimal.valueOf(distanceDTO.getDis() * 1000).intValue());
insertOrder.setArriveDistance(BigDecimal.valueOf(distanceDTO.getDis()).intValue());
return Result.success(insertOrder);
}
OrderInfoEntity nestOrder = orderInfoDao.getByOrderId(nestOrderSegment.getOrderId());
nestOrder.setArriveElapsed(roadTime);
nestOrder.setArriveDistance(BigDecimal.valueOf(distanceDTO.getDis() * 1000).intValue());
nestOrder.setArriveDistance(BigDecimal.valueOf(distanceDTO.getDis()).intValue());
orderInfoDao.save(nestOrder);
continue;
}
......@@ -611,12 +611,12 @@ public class OrderInfoServiceImpl implements OrderInfoService {
log.info("【getRoadDistancePrev】结果------------->{}", JsonUtil.toJson(roadResultPrev));
int roadTimePrev = BigDecimal.valueOf(roadResultPrev.getResult().getTime()).divide(BigDecimal.valueOf(60), 0, RoundingMode.HALF_UP).intValue();
insertOrder.setArriveElapsed(roadTimePrev);
insertOrder.setArriveDistance(BigDecimal.valueOf(roadResultPrev.getResult().getDis() * 1000).intValue());
insertOrder.setArriveDistance(BigDecimal.valueOf(roadResultPrev.getResult().getDis()).intValue());
}
OrderInfoEntity nestOrder = orderInfoDao.getByOrderId(orderSegment.getOrderId());
nestOrder.setArriveElapsed(roadTime);
nestOrder.setArriveDistance(BigDecimal.valueOf(distanceDTO.getDis() * 1000).intValue());
nestOrder.setArriveDistance(BigDecimal.valueOf(distanceDTO.getDis()).intValue());
long minutes = Duration.between(nestOrder.getPlanStartTime(), planStartTime.plusMinutes(skillInfo.getTakeTime() + roadTime)).toMinutes();
nestOrder.setPlanStartTime(nestOrder.getPlanStartTime().plusMinutes(minutes));
nestOrder.setPlanEndTime(nestOrder.getPlanEndTime().plusMinutes(minutes));
......
......@@ -21,6 +21,7 @@ import com.dituhui.pea.order.entity.OrderInfoEntity;
import com.dituhui.pea.order.entity.OrgGroupEntity;
import com.dituhui.pea.order.entity.SkillInfoEntity;
import com.dituhui.pea.order.service.OrderServiceDetail;
import com.dituhui.pea.order.utils.OrderUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -82,7 +83,7 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
res.setStatus(order.getOrderStatus());
res.setAppointmentStatus(order.getAppointmentStatus());
res.setOrderStatus(order.getOrderStatus());
res.setServiceStatus(order.getServiceStatus());
res.setServiceStatus(OrderUtil.handleServiceStatus(order));
res.setLocation(String.format("%s,%s", order.getX(), order.getY()));
res.setItems(items);
......
......@@ -13,13 +13,16 @@ import com.dituhui.pea.order.dto.OrderServiceList;
import com.dituhui.pea.order.dto.OrderServiceListReq;
import com.dituhui.pea.order.dto.OrderServiceListResp;
import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.enums.ServiceStatusEnum;
import com.dituhui.pea.order.service.OrderServiceListService;
import com.dituhui.pea.order.utils.OrderUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
......@@ -61,7 +64,21 @@ public class OrderServiceListServiceImpl implements OrderServiceListService {
lqw.in(StringUtils.isNotEmpty(reqDTO.getOrderId()), OrderInfo::getOrderId, reqDTO.getOrderId().split(","));
}
lqw.eq(StringUtils.isNotEmpty(reqDTO.getPhone()), OrderInfo::getPhone, reqDTO.getPhone());
lqw.in(ListUtils.isNotEmpty(reqDTO.getServiceStatus()), OrderInfo::getServiceStatus, reqDTO.getServiceStatus());
if (ListUtils.isNotEmpty(reqDTO.getServiceStatus())) {
List<String> serviceStatus = reqDTO.getServiceStatus();
if (serviceStatus.contains(ServiceStatusEnum.DELAY.getCode())) {
serviceStatus.add(ServiceStatusEnum.INIT.getCode());
serviceStatus.add(ServiceStatusEnum.CONTACTED.getCode());
lqw.le(OrderInfo::getPlanStartTime, LocalDateTime.now().minusMinutes(10));
}
if (serviceStatus.contains(ServiceStatusEnum.UNFINISHED.getCode())) {
serviceStatus.add(ServiceStatusEnum.STARTED.getCode());
lqw.isNotNull(OrderInfo::getActualEndTime);
lqw.le(OrderInfo::getPlanEndTime, LocalDateTime.now().minusMinutes(10));
}
serviceStatus = serviceStatus.stream().distinct().collect(Collectors.toList());
lqw.in(OrderInfo::getServiceStatus, serviceStatus);
}
lqw.in(ListUtils.isNotEmpty(reqDTO.getOrderStatus()), OrderInfo::getOrderStatus, reqDTO.getOrderStatus());
lqw.in(ListUtils.isNotEmpty(reqDTO.getBranchIds()), OrderInfo::getOrgBranchId, reqDTO.getBranchIds());
lqw.in(ListUtils.isNotEmpty(reqDTO.getGroupIds()), OrderInfo::getOrgGroupId, reqDTO.getGroupIds());
......@@ -69,8 +86,7 @@ public class OrderServiceListServiceImpl implements OrderServiceListService {
lqw.in(ListUtils.isNotEmpty(reqDTO.getAppointmentType()), OrderInfo::getAppointmentMethod, reqDTO.getAppointmentType());
lqw.in(ListUtils.isNotEmpty(reqDTO.getAppointmentStatus()), OrderInfo::getAppointmentStatus, reqDTO.getAppointmentStatus());
lqw.in(ListUtils.isNotEmpty(reqDTO.getPriorities()), OrderInfo::getBeanPriority, reqDTO.getPriorities());
lqw.orderByDesc(OrderInfo::getCreateTime);
lqw = handleOrderBy(lqw, reqDTO);
if (ListUtils.isNotEmpty(reqDTO.getEngineerCodes())) {
lqw.and(w ->
w.in(OrderInfo::getEngineerCode, reqDTO.getEngineerCodes())
......@@ -149,7 +165,7 @@ public class OrderServiceListServiceImpl implements OrderServiceListService {
record.setAppointmentType(o.getAppointmentMethod());
record.setAppointmentStatus(o.getAppointmentStatus());
record.setOrderStatus(o.getOrderStatus());
record.setServiceStatus(o.getServiceStatus());
record.setServiceStatus(OrderUtil.handleServiceStatus(o));
record.setDispatcher(o.getDispatcher());
record.setCreateTime(TimeUtils.IsoTimestamp2DateTime(o.getCreateTime()));
......@@ -195,6 +211,35 @@ public class OrderServiceListServiceImpl implements OrderServiceListService {
}
/**
* 处理订单排序
*
* @param lqw
* @param reqDTO
* @return
*/
private LambdaQueryWrapper<OrderInfo> handleOrderBy(LambdaQueryWrapper<OrderInfo> lqw, OrderServiceListReq reqDTO) {
if (reqDTO.getOrderByField() == 1) {
lqw.orderBy(true, reqDTO.getOrderBy() == 1, OrderInfo::getTakeTime);
}
if (reqDTO.getOrderByField() == 2) {
lqw.orderBy(true, reqDTO.getOrderBy() == 1, OrderInfo::getCreateTime);
}
if (reqDTO.getOrderByField() == 3) {
lqw.orderBy(true, reqDTO.getOrderBy() == 1, OrderInfo::getOrderStatus);
}
if (reqDTO.getOrderByField() == 4) {
lqw.orderBy(true, reqDTO.getOrderBy() == 1, OrderInfo::getAppointmentStatus);
}
if (reqDTO.getOrderByField() == 5) {
lqw.orderBy(true, reqDTO.getOrderBy() == 1, OrderInfo::getAppointmentMethod);
}
if (reqDTO.getOrderByField() == 6) {
lqw.orderBy(true, reqDTO.getOrderBy() == 1, OrderInfo::getServiceStatus);
}
return lqw;
}
/**
* 获取团队配件仓地址
*
* @param orders
......@@ -271,7 +316,7 @@ public class OrderServiceListServiceImpl implements OrderServiceListService {
record.setAppointmentType(o.getAppointmentMethod());
record.setAppointmentStatus(o.getAppointmentStatus());
record.setOrderStatus(o.getOrderStatus());
record.setServiceStatus(o.getServiceStatus());
record.setServiceStatus(OrderUtil.handleServiceStatus(o));
record.setDispatcher(o.getDispatcher());
record.setCreateTime(TimeUtils.IsoLocalDateTime2String(o.getCreateTime()));
......
package com.dituhui.pea.order.utils;
import cn.hutool.core.util.ObjectUtil;
import com.dituhui.pea.order.entity.OrderInfo;
import com.dituhui.pea.order.entity.OrderInfoEntity;
import com.dituhui.pea.order.enums.OrderPeaTagsEnum;
import com.dituhui.pea.order.enums.ServiceStatusEnum;
......@@ -60,6 +61,57 @@ public class OrderUtil {
/**
* 处理工单状态,主要处理以延迟和已超时
*
* @param order
* @return
*/
public static String handleServiceStatus(OrderInfo order) {
if (isDelay(order)) {
return ServiceStatusEnum.DELAY.getCode();
}
if (isOvertime(order)) {
return ServiceStatusEnum.UNFINISHED.getCode();
}
return order.getServiceStatus();
}
/**
* 判断订单是否是延迟订单
*
* @param order
* @return
*/
public static Boolean isDelay(OrderInfo order) {
if (!order.getServiceStatus().equals(ServiceStatusEnum.INIT.getCode()) && !order.getServiceStatus().equals(ServiceStatusEnum.CONTACTED.getCode())) {
return false;
}
if (order.getPlanStartTime().getTime() + 10 * 60 * 1000 < System.currentTimeMillis()) {
return true;
}
return false;
}
/**
* 判断订单是否是延迟订单
*
* @param order
* @return
*/
public static Boolean isOvertime(OrderInfo order) {
if (!order.getServiceStatus().equals(ServiceStatusEnum.STARTED.getCode()) || ObjectUtil.isNotNull(order.getActualEndTime())) {
return false;
}
if (order.getPlanEndTime().getTime() + 10 * 60 * 1000 < System.currentTimeMillis()) {
return true;
}
return false;
}
/**
* 判断订单是否是延迟订单
*
* @param order
......@@ -69,7 +121,7 @@ public class OrderUtil {
if (!order.getServiceStatus().equals(ServiceStatusEnum.INIT.getCode()) && !order.getServiceStatus().equals(ServiceStatusEnum.CONTACTED.getCode())) {
return false;
}
if (order.getExpectTimeBegin().plusMinutes(10).isBefore(LocalDateTime.now())) {
if (order.getPlanStartTime().plusMinutes(10).isBefore(LocalDateTime.now())) {
return true;
}
return false;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!