Commit 0f505160 by huangjinxin

feat:创单及展示添加cutoff逻辑

1 parent 0908004d
......@@ -556,6 +556,22 @@ public class DateUtil {
return false;
}
/***
* @param localDateTime
* @return: boolean
* @Description: 根据LocalDateTime来判断是否是今天
*/
public boolean judgeTimeIsisTomorrow(LocalDateTime localDateTime) {
LocalDateTime startTime = LocalDate.now().plusDays(1).atTime(0, 0, 0);
LocalDateTime endTime = LocalDate.now().plusDays(1).atTime(23, 59, 59);
//如果大于今天的开始日期,小于今天的结束日期
if (localDateTime.isAfter(startTime) && localDateTime.isBefore(endTime)) {
return true;
}
return false;
}
/**
* 根据日期转换到指定时间
* 2023-10-30+2023-10-22 21:21:12 -> 2023-10-30 21:21:12
......
......@@ -86,10 +86,19 @@ public class DispatchOrderListResp {
*/
private String beanPriority;
/**
* 是否是特殊时间段,0否 1是 默认0
*/
private Integer isSpecialTime;
/**
* 是否是cutoff,0否 1是 默认0
*/
private Integer isCutoff;
/**
* bean标签
*/
private String beanTags;
}
}
......@@ -234,4 +234,10 @@ public class OrderInfoEntity {
*/
@Column(name = "reason_for_failure")
private String reasonForFailure;
/**
* 是否是cutoff,0否 1是 默认0
*/
@Column(name = "is_cutoff")
private Integer isCutoff = 0;
}
package com.dituhui.pea.order.enums;
public enum AppointmentMethodEnum {
// 指派方式(MANUAL人工/AUTO_NOW 自动立即/AUTO_BATCH/PROTECTION 自保点)
MANUAL, AUTO_NOW, AUTO_BATCH, PROTECTION
}
package com.dituhui.pea.order.enums;
public enum AppointmentStatus {
// 指派状态: INIT-待指派/PRE-预指派/CONFIRM-确认指派(通知BEAN)
INIT("待指派"),
PRE("预指派"),
CONFIRM("确认指派");
private final String description;
AppointmentStatus(String description){
this.description = description;
}
public String getDescription() {
return description;
}
public static String getEnumName(AppointmentStatus appointmentStatus){
return appointmentStatus.toString();
}
}
......@@ -388,6 +388,8 @@ public class DispatchServiceImpl implements DispatchService {
item.setBeanPriority(o.getBeanPriority());
item.setOrgGroupId(o.getOrgGroupId());
item.setIsSpecialTime(o.getIsSpecialTime());
item.setBeanTags(o.getBeanTags());
item.setIsCutoff(o.getIsCutoff());
item.setOrgGroupName(groupMap.get(o.getOrgGroupId()));
if (isContinue && StringUtils.isNotEmpty(o.getMultipleOrders())) {
List<OrderInfoEntity> byMultipleOrders = orderInfoDao.findByMultipleOrdersAndOrderIdNot(o.getMultipleOrders(), o.getOrderId());
......
......@@ -17,6 +17,7 @@
package com.dituhui.pea.order.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.common.ResultEnum;
import com.dituhui.pea.enums.StatusCodeEnum;
......@@ -27,7 +28,7 @@ import com.dituhui.pea.order.dto.param.Location;
import com.dituhui.pea.order.dto.param.OrderDTO;
import com.dituhui.pea.order.dto.param.OrgTeamInfo;
import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.enums.AppointmentStatus;
import com.dituhui.pea.order.enums.AppointmentMethodEnum;
import com.dituhui.pea.order.enums.OrderFlowEnum;
import com.dituhui.pea.order.enums.OrderStatusEnum;
import com.dituhui.pea.order.service.*;
......@@ -128,7 +129,7 @@ public class OrderCreateServiceImpl implements OrderCreateService {
@Override
@Transactional
public Result<?> createOrder(OrderDTO.OrderCreateRequest req) {
log.info("[createOrder] current XID: {}", RootContext.getXID());
log.info("[createOrder] req: {}", JSONObject.toJSONString(req));
OrderInfoEntity entity = new OrderInfoEntity();
String orderId = req.getOrderId();
if (StringUtils.isEmpty(orderId)) {
......@@ -140,14 +141,13 @@ public class OrderCreateServiceImpl implements OrderCreateService {
return Result.failed(StatusCodeEnum.ORDER_EXISTS);
}
// 分单处理
String peaBrand = fixBrand(req.getBrand());
// location
Location location = req.getLocation();
//先处理时间,后面用
//预处理字段
entity.setExpectTimeBegin(DateUtil.fromDate(req.getExpectBegin()));
entity.setExpectTimeEnd(DateUtil.fromDate(req.getExpectEnd()));
entity.setAppointmentStatus(AppointmentStatus.INIT.getDescription());
entity.setAppointmentStatus(OrderFlowEnum.INIT.name());
entity.setAppointmentMethod(AppointmentMethodEnum.AUTO_NOW.name());
//获取省市区
AdministrativeDistrictReq administrativeDistrictReq = new AdministrativeDistrictReq();
administrativeDistrictReq.setPoints(location.getLongitude() + "," + location.getLatitude());
......@@ -157,21 +157,19 @@ public class OrderCreateServiceImpl implements OrderCreateService {
entity.setCity(adminDistrict.getResult().getSubNames().getCity());
entity.setCounty(adminDistrict.getResult().getSubNames().getCounty());
}
// 分单处理
Result<OrgTeamInfo> fendanResult = fendanService.fendanToGroupCapacity(req, 2, entity.getExpectTimeBegin().toLocalDate(), entity.getExpectTimeBegin().toLocalTime(), entity.getExpectTimeEnd().toLocalTime());
if (!fendanResult.getCode().equals(ResultEnum.SUCCESS.getCode()) || ObjectUtil.isNull(fendanResult.getResult())) {
if (fendanResult.getCode().equals(StatusCodeEnum.FENDAN_IS_TRANSCEND.getCode())) {
// 处理超派
entity.setTranscend(1);
}
OrgBranchEntity branchEntity = orgBranchDao.findByCitycodeListLike("%" + adminDistrict.getResult().getSubNames().getCity() + "%");
entity.setOrgClusterId(branchEntity.getClusterId());
entity.setOrgBranchId(branchEntity.getBranchId());
entity.setAppointmentMethod(AppointmentMethodEnum.MANUAL.name());
//发送通知分部消息
MsgDTO msgDTO = new MsgDTO();
msgDTO.setBranchId(branchEntity.getBranchId());
msgDTO.setType(0);
msgDTO.setOrderIds(orderId);
msgDTO.setContent("有1条预约日期在" + entity.getExpectTimeBegin().toLocalDate() + "的工单需人工外理");
msgService.add(msgDTO);
sendMsg(branchEntity.getBranchId(), orderId, entity.getExpectTimeBegin().toLocalDate());
} else {
// 根据分单工作队,填写clusterId/branchId/groupId/teamId等
OrgTeamInfo teamInfo = fendanResult.getResult();
......@@ -179,11 +177,25 @@ public class OrderCreateServiceImpl implements OrderCreateService {
entity.setOrgBranchId(teamInfo.getBranchId());
entity.setOrgGroupId(teamInfo.getGroupId());
entity.setOrgTeamId(teamInfo.getTeamId());
entity.setAppointmentStatus(AppointmentStatus.PRE.getDescription());
//处理超派,特殊时间段
entity.setIsSpecialTime(CommonUtil.isSpecial(entity.getExpectTimeBegin().toLocalTime(),
entity.getExpectTimeEnd().toLocalTime(), teamInfo.getWorkOn(), teamInfo.getWorkOff()));
entity.setAppointmentStatus(OrderFlowEnum.PRE.name());
//特殊时间段
Integer special = CommonUtil.isSpecial(entity.getExpectTimeBegin().toLocalTime(),
entity.getExpectTimeEnd().toLocalTime(), teamInfo.getWorkOn(), teamInfo.getWorkOff());
Integer cutoff = CommonUtil.isCutoff(entity.getExpectTimeBegin(), teamInfo.getWorkOff());
// 处理cutoff 动态排班结束后创建的当日单和次日单
boolean isToday = DateUtil.judgeTimeIsToday(entity.getExpectTimeBegin());
boolean isTomorrow = DateUtil.judgeTimeIsisTomorrow(entity.getExpectTimeBegin());
// 特殊时间段,当天单,cutoff需要人工处理
if (isToday || (isTomorrow && cutoff == 1) || special == 1) {
//判断是否在今天cutoff之后
entity.setIsCutoff(cutoff);
entity.setIsSpecialTime(special);
entity.setAppointmentMethod(AppointmentMethodEnum.MANUAL.name());
//发送通知分部消息
sendMsg(teamInfo.getBranchId(), orderId, entity.getExpectTimeBegin().toLocalDate());
}
}
// 字段转换
entity.setSource(req.getSource());
entity.setOrderId(orderId);
entity.setName(req.getName());
......@@ -197,7 +209,8 @@ public class OrderCreateServiceImpl implements OrderCreateService {
// 使用期望时间来初始化计划时间,后面在指派环节更新为真正的有效的计划时间
entity.setPlanStartTime(entity.getExpectTimeBegin());
entity.setPlanEndTime(entity.getExpectTimeEnd());
entity.setApplyNote(req.getDescription()); // order_request的description字段,仅仅用于内部备注,不对外
// order_request的description字段,仅仅用于内部备注,不对外
entity.setApplyNote(req.getDescription());
entity.setDt(entity.getExpectTimeBegin().toLocalDate());
entity.setSubId(newSubId(entity.getOrderId(), entity.getDt()));
entity.setX(req.getLocation().getLongitude().toString());
......@@ -205,38 +218,44 @@ public class OrderCreateServiceImpl implements OrderCreateService {
entity.setAddress(location.getAddress());
entity.setAddressId(location.getAddressId());
// 默认值
entity.setAppointmentStatus(OrderFlowEnum.INIT.name());
// entity.setAppointmentStatus(OrderFlowEnum.INIT.name());
entity.setBeanStatus("OPEN");
entity.setBeanSubStatus("");
entity.setAppointmentMethod("AUTO_NOW");
entity.setWorkshop(false);
// 处理工程师
entity.setIsAppointEngineer(req.getIsAppointEngineer());
String appointEngineerCodes = CollectionUtils.isEmpty(req.getAppointEngineerCodes()) ? "" : String.join(",", req.getAppointEngineerCodes());
entity.setAppointEngineerCodes(appointEngineerCodes);
// 处理技能和标签
SkillInfoEntity skillInfoEntity = skillInfoDao.getByBrandAndTypeAndSkill(peaBrand, req.getProductType(), req.getServiceType());
assert skillInfoEntity != null;
entity.setTakeTime(skillInfoEntity.getTakeTime());
// 基础保存
String joinTags = CollectionUtils.isEmpty(req.getOrderTags()) ? "" : String.join(",", req.getOrderTags());
entity.setBeanTags(joinTags);
entity.setBeanPriority(req.getPriority());
entity.setIsMultiple(joinTags.contains("重物搬运") ? 1 : 0);
//一家多单
Result<String> addMultipleOrders = orderInfoService.addMultipleOrders(entity.getDt(), location.getAddressId(), orderId);
entity.setMultipleOrders(addMultipleOrders.getResult());
// todo 服务单状态、预约状态等
// 记录订单和节点
orderInfoDao.save(entity);
// 登记
commonService.addOrderEvent(orderId, "", req.getSource(), "API", OrderStatusEnum.CREATE.getDescription(), OrderStatusEnum.CREATE.getDescription(), "");
// 指派检查,简单处理,遇到第一个可以指派的就停止检查
// tryVirtualAppointment(entity, req.getSource(), teamId);
return Result.success(null);
}
private void sendMsg(String branchId, String orderId, LocalDate toLocalDate) {
MsgDTO msgDTO = new MsgDTO();
msgDTO.setBranchId(branchId);
msgDTO.setType(0);
msgDTO.setOrderIds(orderId);
msgDTO.setContent("有1条预约日期在" + toLocalDate + "的工单需人工外理");
msgService.add(msgDTO);
}
private void tryVirtualAppointment(OrderInfoEntity thisOrderEntity, String source, String teamId) {
try {
List<String> engineerCodes = engineerUtils.getEngineersByLevel("team", teamId).stream()
......
......@@ -4,6 +4,8 @@ import cn.hutool.core.util.StrUtil;
import com.dituhui.pea.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
......@@ -74,7 +76,20 @@ public class CommonUtil {
public static Integer isSpecial(LocalTime expectBegin, LocalTime expectEnd, String strOn, String strOff) {
LocalTime workOn = LocalTime.parse(strOn + ":00", DateUtil.TIME_FORMATTER);
LocalTime workOff = LocalTime.parse(strOff + ":00", DateUtil.TIME_FORMATTER);
if (expectBegin.isBefore(workOn) || expectEnd.isAfter(workOff)) {
if (expectBegin.isBefore(workOn) || expectBegin.isAfter(workOff) || expectEnd.isAfter(workOff) || expectEnd.isBefore(workOn)) {
return 1;
}
return 0;
}
/**
* 判断是否cutoff
*
* @return
*/
public static Integer isCutoff(LocalDateTime localTime, String strOff) {
LocalDateTime workOff = LocalDate.now().atTime(Integer.parseInt(strOff.split(":")[0]), Integer.parseInt(strOff.split(":")[1]), 0);
if (localTime.isAfter(workOff)) {
return 1;
}
return 0;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!