Commit 6ad59d1d by huangjinxin

Merge remote-tracking branch 'origin/develop' into develop

2 parents 30d2eeef 149ddb2d
......@@ -156,7 +156,7 @@ public class Technician {
}
totalDistance += previousLocation.getDistanceTo(this.getVehicleType(), depot.getLocation());
return totalDistance * 1000;
return totalDistance;
}
/**
......
......@@ -3,7 +3,7 @@ server:
dispatch:
cron:
expr: 0 35 8-23 * * ?
expr: 0 20 8-23 * * ?
next-day-limit: 2
scheduler:
......
package com.dituhui.pea.order.dto;
import com.dituhui.pea.order.dto.param.TLocation;
import com.dituhui.pea.order.enums.TestimonialsEngineerTag;
import lombok.Data;
......@@ -19,6 +20,10 @@ public class OrderAssignRecommendResp {
* 工程师标签
*/
private TestimonialsEngineerTag distanceDesc;
/**
* 不同类型的坐标点
*/
private List<TLocation> locations;
private String timeDesc;
private String desc;
private String startTime;
......
......@@ -12,11 +12,11 @@ public class BaseLocation {
* 地址纬度
*/
@NotNull(message = "地址纬度必填")
private Double latitude;
protected Double latitude;
/**
* 地址经度
*/
@NotNull(message = "地址经度必填")
private Double longitude;
protected Double longitude;
}
package com.dituhui.pea.order.dto.param;
import com.dituhui.pea.order.enums.LocationType;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
/**
* 带类型的坐标
*/
@Setter
@Getter
@EqualsAndHashCode(callSuper = false)
public class TLocation extends BaseLocation {
/**
* 坐标类型--绑定工程师使用
*/
protected LocationType locationType;
/**
* 详细地址, xx路xx号等信息
*/
protected String address;
}
package com.dituhui.pea.order.enums;
/**
* 工程师坐标类型
*/
public enum LocationType {
/**
* 准实时
*/
QUASI_REALTIME,
/**
* 常规
*/
GENERAL,
/**
* 上一单
*/
PREVIOUS_ORDER,
/**
* 下一单
*/
NEXT_ORDER;
}
package com.dituhui.pea.order.service;
import com.dituhui.pea.order.dto.EngineerBusinessDTO;
import com.dituhui.pea.order.dto.param.TLocation;
import java.util.List;
......@@ -14,4 +15,11 @@ public interface EngineerBusinessService {
void updateEngineerCenter(EngineerBusinessDTO.EngineerCenterUpdateReqDTO centerReq );
List<EngineerBusinessDTO.Blocks> getBlocks(EngineerBusinessDTO.Request engineerReq);
/**
* 获取工程师出发位置
* @param engineerCode 工程师编号
* @return 工程师出发位置
*/
TLocation engineerDepartLocation(String engineerCode);
}
......@@ -2,7 +2,9 @@ package com.dituhui.pea.order.service.impl;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.EngineerBusinessDTO;
import com.dituhui.pea.order.dto.param.TLocation;
import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.enums.LocationType;
import com.dituhui.pea.order.service.EngineerBusinessService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -128,4 +130,15 @@ public class EngineerBusinessServiceImpl implements EngineerBusinessService {
return block;
}).collect(Collectors.toList());
}
@Override
public TLocation engineerDepartLocation(String engineerCode) {
EngineerBusinessEntity byEngineerCode = engineerBusinessDao.getByEngineerCode(engineerCode);
TLocation location = new TLocation();
location.setAddress(byEngineerCode.getAddress());
location.setLongitude(StringUtils.isNotBlank(byEngineerCode.getX()) ? Double.parseDouble(byEngineerCode.getX()) : 0.0);
location.setLatitude(StringUtils.isNotBlank(byEngineerCode.getY()) ? Double.parseDouble(byEngineerCode.getY()) : 0.0);
location.setLocationType(LocationType.GENERAL);
return location;
}
}
......@@ -10,7 +10,6 @@ import com.dituhui.pea.order.common.OrderAssignCheck;
import com.dituhui.pea.order.common.Stapial4jUtil;
import com.dituhui.pea.order.common.TimeUtils;
import com.dituhui.pea.order.common.jackson.DateUtil;
import com.dituhui.pea.order.dao.EngineerBusinessDao;
import com.dituhui.pea.order.dao.EngineerInfoDao;
import com.dituhui.pea.order.dao.EngineerSkillGroupDao;
import com.dituhui.pea.order.dao.OrderInfoDao;
......@@ -23,9 +22,8 @@ import com.dituhui.pea.order.dto.OrderAssignRecommendResp;
import com.dituhui.pea.order.dto.OrderAssignReq;
import com.dituhui.pea.order.dto.OrderReschedule;
import com.dituhui.pea.order.dto.TimeLineDTO;
import com.dituhui.pea.order.dto.param.Location;
import com.dituhui.pea.order.dto.param.RecommendEngineersReq;
import com.dituhui.pea.order.entity.EngineerBusinessEntity;
import com.dituhui.pea.order.dto.param.TLocation;
import com.dituhui.pea.order.entity.EngineerInfoEntity;
import com.dituhui.pea.order.entity.EngineerSkillGroupEntity;
import com.dituhui.pea.order.entity.OrderInfoEntity;
......@@ -33,12 +31,14 @@ import com.dituhui.pea.order.entity.OrgTeamEngineerEntity;
import com.dituhui.pea.order.entity.OrgTeamEntity;
import com.dituhui.pea.order.entity.SkillInfoEntity;
import com.dituhui.pea.order.enums.AppointmentMethodEnum;
import com.dituhui.pea.order.enums.LocationType;
import com.dituhui.pea.order.enums.OrderEventEnum;
import com.dituhui.pea.order.enums.OrderFlowEnum;
import com.dituhui.pea.order.enums.OrderStatusEnum;
import com.dituhui.pea.order.enums.ServiceStatusEnum;
import com.dituhui.pea.order.enums.TestimonialsEngineerTag;
import com.dituhui.pea.order.service.CommonService;
import com.dituhui.pea.order.service.EngineerBusinessService;
import com.dituhui.pea.order.service.EngineerCalendarService;
import com.dituhui.pea.order.service.MsgService;
import com.dituhui.pea.order.service.OrderAssign;
......@@ -117,9 +117,8 @@ public class OrderAssignImpl implements OrderAssign {
@Autowired
private IUser userService;
@Autowired
private EngineerBusinessDao engineerBusinessDao;
private EngineerBusinessService engineerBusinessService;
@Autowired
private EngineerCalendarService engineerCalendarService;
......@@ -179,6 +178,7 @@ public class OrderAssignImpl implements OrderAssign {
//标签判定
//判定当前工程师是否在队内, 否则判定是否在10KM内, 否则
TempEngineer tempEngineer = engineerDistanceMap.get(engineerCode);
item.setLocations(tempEngineer.getLocations());
if (Objects.nonNull(orgTeamEngineerDao.findByTeamIdAndEngineerCode(orgTeamId, engineerCode))) {
engineerTag = TestimonialsEngineerTag.TEAM;
} else if (tempEngineer.getDistance().compareTo(judgeDistance) <= 0) {
......@@ -198,8 +198,6 @@ public class OrderAssignImpl implements OrderAssign {
int index = result.getIndex() + 1;
item.setDesc(String.format("将被插入在第%d单,受此影响原第%d单变化第%d单,第%d单将增加%d公里路程,比预计晚到%d分钟,建议调整;", index, index, index + 1, index + 1, result.getAdditionDistance() / 1000, result.getAdditionElapsed()));
item.setStartTime(String.format("%s 08:00:00", date));
item.setEndTime(String.format("%s 18:00:00", date));
item.setOrders(this.packTimelines(orderAppointments, orderTips));
items.add(item);
......@@ -372,11 +370,13 @@ public class OrderAssignImpl implements OrderAssign {
//均计算距离
List<TempEngineer> result = engineerCodes1.stream()
.map(engineerCode -> {
Location location = engineerDateLocation(engineerCode);
List<TLocation> tLocations = engineerDateLocation(engineerCode);
TLocation location = tLocations.stream().filter(t -> Objects.equals(t.getLocationType(), LocationType.QUASI_REALTIME))
.findFirst().get();
BigDecimal orderAndEngineerDistance = BigDecimal.valueOf(Stapial4jUtil.getDistance(location.getLongitude(), location.getLatitude(),
orderLongitude, orderLatitude));
return new TempEngineer(engineerCode, orderAndEngineerDistance);
return new TempEngineer(engineerCode, orderAndEngineerDistance, tLocations);
}).collect(Collectors.toList());
// 距离过滤
if (Objects.nonNull(distance)) {
......@@ -399,28 +399,36 @@ public class OrderAssignImpl implements OrderAssign {
* 距离 (KM)
*/
private BigDecimal distance;
/**
* 不同类型坐标
*/
private List<TLocation> locations;
}
private Location engineerDateLocation(String engineerCode) {
private List<TLocation> engineerDateLocation(String engineerCode) {
final LocalDate currentDate = LocalDate.now();
List<OrderInfoEntity> engineerDateOrderList = orderInfoDao.getEngineerDateOrder(engineerCode, DateUtils.formatDate(currentDate));
Set<String> ss = Set.of("CANCELED", "RESCHEDULED");
engineerDateOrderList = engineerDateOrderList.stream()
.filter(e -> !ss.contains(e.getOrderStatus()))
.sorted(Comparator.comparing(OrderInfoEntity::getPlanStartTime))
.collect(Collectors.toList());
Location location = new Location();
TLocation quasiRealTimeLocation = new TLocation();
quasiRealTimeLocation.setLocationType(LocationType.QUASI_REALTIME);
//查询工程师已开始的工单
Optional<OrderInfoEntity> startedOrder = engineerDateOrderList.stream()
.filter(e -> Objects.equals("STARTED", e.getServiceStatus()))
.max(Comparator.comparing(OrderInfoEntity::getPlanStartTime));
OrderInfoEntity currentOrder = null;
if (startedOrder.isPresent()) {
OrderInfoEntity startedOrderInfo = startedOrder.get();
location.setAddress(startedOrderInfo.getAddress());
location.setLongitude(Double.parseDouble(startedOrderInfo.getX()));
location.setLatitude(Double.parseDouble(startedOrderInfo.getY()));
return location;
quasiRealTimeLocation.setAddress(startedOrderInfo.getAddress());
quasiRealTimeLocation.setLongitude(Double.parseDouble(startedOrderInfo.getX()));
quasiRealTimeLocation.setLatitude(Double.parseDouble(startedOrderInfo.getY()));
currentOrder = startedOrderInfo;
}
//如果没有已开始的工单 查询 最后一个已完成工单
......@@ -428,20 +436,50 @@ public class OrderAssignImpl implements OrderAssign {
.filter(e -> Objects.equals("FINISHED", e.getServiceStatus()))
.max(Comparator.comparing(OrderInfoEntity::getActualEndTime));
ArrayList<TLocation> resultLocationList = new ArrayList<>();
TLocation generalLocation = engineerBusinessService.engineerDepartLocation(engineerCode);
//常规位置, 出发地
resultLocationList.add(generalLocation);
if (finishedOrder.isPresent()) {
OrderInfoEntity finishedOrderInfo = finishedOrder.get();
location.setAddress(finishedOrderInfo.getAddress());
location.setLongitude(Double.parseDouble(finishedOrderInfo.getX()));
location.setLatitude(Double.parseDouble(finishedOrderInfo.getY()));
quasiRealTimeLocation.setAddress(finishedOrderInfo.getAddress());
quasiRealTimeLocation.setLongitude(Double.parseDouble(finishedOrderInfo.getX()));
quasiRealTimeLocation.setLatitude(Double.parseDouble(finishedOrderInfo.getY()));
currentOrder = finishedOrderInfo;
} else {
// 如果都没有, 则获取工程师出发地址
EngineerBusinessEntity byEngineerCode = engineerBusinessDao.getByEngineerCode(engineerCode);
location.setAddress(byEngineerCode.getAddress());
location.setLongitude(StringUtils.isNotBlank(byEngineerCode.getX()) ? Double.parseDouble(byEngineerCode.getX()) : 0.0);
location.setLatitude(StringUtils.isNotBlank(byEngineerCode.getY()) ? Double.parseDouble(byEngineerCode.getY()) : 0.0);
quasiRealTimeLocation.setAddress(generalLocation.getAddress());
quasiRealTimeLocation.setLongitude(generalLocation.getLongitude());
quasiRealTimeLocation.setLatitude(generalLocation.getLatitude());
}
//准实时位置
resultLocationList.add(quasiRealTimeLocation);
//
if (Objects.nonNull(currentOrder)) {
int i = engineerDateOrderList.indexOf(currentOrder);
//上一单
if (i > 0) {
OrderInfoEntity order = engineerDateOrderList.get(i - 1);
TLocation pre = new TLocation();
pre.setLocationType(LocationType.PREVIOUS_ORDER);
pre.setAddress(order.getAddress());
pre.setLongitude(Double.parseDouble(order.getX()));
pre.setLatitude(Double.parseDouble(order.getY()));
resultLocationList.add(pre);
}
//下一单
if (i < engineerDateOrderList.size() - 1) {
OrderInfoEntity order = engineerDateOrderList.get(i + 1);
TLocation next = new TLocation();
next.setLocationType(LocationType.NEXT_ORDER);
next.setAddress(order.getAddress());
next.setLongitude(Double.parseDouble(order.getX()));
next.setLatitude(Double.parseDouble(order.getY()));
resultLocationList.add(next);
}
}
return location;
return resultLocationList;
}
......
......@@ -16,6 +16,7 @@ import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.enums.OrderFlowEnum;
import com.dituhui.pea.order.enums.VehicleEnum;
import com.dituhui.pea.order.service.ScheduleService;
import com.dituhui.pea.order.utils.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
......@@ -149,7 +150,7 @@ public class ScheduleServiceImpl implements ScheduleService {
child.setOrderDesc(Integer.toString(orders2.size()));
Integer distanceSum = orders2.stream().map(order -> Objects.nonNull(order.getArriveDistance()) ? order.getArriveDistance() : 0).reduce(Integer::sum).orElse(0);
teamDistance += distanceSum;
child.setDistanceDesc(distanceSum/1000.0 + "");
child.setDistanceDesc(CommonUtil.converMToKm(distanceSum));
children.add(child);
......@@ -189,8 +190,8 @@ public class ScheduleServiceImpl implements ScheduleService {
teamEngineers.size() > 0 ? new BigDecimal(teamDistance)
.divide(new BigDecimal(teamEngineers.size()), 2, RoundingMode.HALF_UP)
.stripTrailingZeros() : 0,
minDistance/1000.0,
maxDistance/1000.0));
CommonUtil.converMToKm(minDistance),
CommonUtil.converMToKm(maxDistance)));
teams.add(team);
}
......@@ -267,7 +268,7 @@ public class ScheduleServiceImpl implements ScheduleService {
.divide(new BigDecimal(60), 2, RoundingMode.HALF_UP)
.stripTrailingZeros()
+ "时");
dynamics.setRoadTotalDistance(sumDistance / 1000.0 + "公里");
dynamics.setRoadTotalDistance(CommonUtil.converMToKm(sumDistance) + "公里");
if (Objects.nonNull(engineerBusinessEntity)) {
dynamics.setWorkTime(engineerBusinessEntity.getWorkOn() + "-" + engineerBusinessEntity.getWorkOff());
} else {
......@@ -289,7 +290,7 @@ public class ScheduleServiceImpl implements ScheduleService {
item.setSkill(o.getSkill());
item.setOrderStatus(o.getAppointmentStatus());
item.setOrderStatusName("");
item.setDistance(Objects.nonNull(o.getArriveDistance()) ? o.getArriveDistance() / 1000.0 + "" : null);
item.setDistance(CommonUtil.converMToKm(o.getArriveDistance()));
item.setTimeType("auto");
if (Objects.nonNull(o.getArriveElapsed())) {
......
......@@ -5,6 +5,7 @@ import com.dituhui.pea.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
......@@ -112,6 +113,13 @@ public class CommonUtil {
}
}
public static String converMToKm(Integer m) {
if (Objects.isNull(m)) {
return null;
}
return BigDecimal.valueOf(m / 1000.0).stripTrailingZeros().toString();
}
public static void main(String[] args) {
isCutoff(LocalDateTime.now(), "18:00");
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!