feat: 新增订单任务飞行,删除订单飞行任务接口;
This commit is contained in:
parent
b27dd589e1
commit
80c6699006
@ -270,6 +270,12 @@ public class OrderBiz {
|
|||||||
if (!orderMain.getMainOrderStatus().equals(MainOrderStatusEnum.NOT_STARTED.getCode())) {
|
if (!orderMain.getMainOrderStatus().equals(MainOrderStatusEnum.NOT_STARTED.getCode())) {
|
||||||
throw new BadRequestException("当前订单状态不是处于未进行中,不允许删除");
|
throw new BadRequestException("当前订单状态不是处于未进行中,不允许删除");
|
||||||
}
|
}
|
||||||
|
// 判断当前登录人、是否为订单发起人,不是则不允许修改
|
||||||
|
EmEmployees employees = JSON.parseObject(SecurityUtils.getCurrentEmployee(), EmEmployees.class);
|
||||||
|
Long currentId = employees.getId();
|
||||||
|
if (!currentId.equals(orderMain.getOrderInitiatorId())) {
|
||||||
|
throw new BadRequestException("当前登录用户不是订单发起人,不允许删除订单");
|
||||||
|
}
|
||||||
// 检查是否存在订单任务
|
// 检查是否存在订单任务
|
||||||
List<OrderDetail> orderDetailList = orderDetailService.queryOrderDetailByOrderId(orderId);
|
List<OrderDetail> orderDetailList = orderDetailService.queryOrderDetailByOrderId(orderId);
|
||||||
if (CollectionUtil.isNotEmpty(orderDetailList)) {
|
if (CollectionUtil.isNotEmpty(orderDetailList)) {
|
||||||
@ -299,4 +305,70 @@ public class OrderBiz {
|
|||||||
}
|
}
|
||||||
return orderOperatorList;
|
return orderOperatorList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改订单任务状态
|
||||||
|
*
|
||||||
|
* @param orderTaskId 订单任务ID
|
||||||
|
* @param taskStatus 飞行状态
|
||||||
|
*/
|
||||||
|
public void editOrderTaskStatus(Long orderTaskId, Integer taskStatus) {
|
||||||
|
// 获取订单详情
|
||||||
|
OrderDetail orderDetail = orderDetailService.obtainOrderDetailById(orderTaskId);
|
||||||
|
if (ObjectUtil.isNull(orderDetail)) {
|
||||||
|
throw new BadRequestException("订单任务不存在");
|
||||||
|
}
|
||||||
|
// 判断当前用户是否是订单发起者
|
||||||
|
EmEmployees employees = JSON.parseObject(SecurityUtils.getCurrentEmployee(), EmEmployees.class);
|
||||||
|
Long currentOperatorId = employees.getId();
|
||||||
|
if (!currentOperatorId.equals(orderDetail.getOperatorId())) {
|
||||||
|
throw new BadRequestException("您没有权限更改此飞行任务状态");
|
||||||
|
}
|
||||||
|
// 获取当前订单状态的枚举值
|
||||||
|
OrderTaskStatusEnum orderTaskStatusEnum = OrderTaskStatusEnum.getInstance(orderDetail.getOrderItemStatus());
|
||||||
|
if (ObjectUtil.isNull(orderTaskStatusEnum)) {
|
||||||
|
throw new BadRequestException("订单任务状态错误");
|
||||||
|
}
|
||||||
|
boolean checkStatusTransitionValid = OrderTaskStatusEnum.checkStatusTransitionValid(orderTaskStatusEnum.getCode(), taskStatus);
|
||||||
|
if (!checkStatusTransitionValid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 进行订单状态变更,飞行任务变更
|
||||||
|
Long orderId = orderDetail.getOrderId();
|
||||||
|
OrderMain orderMain = orderMainService.obtainOrderMainById(orderId);
|
||||||
|
if (ObjectUtil.isNull(orderMain)) {
|
||||||
|
throw new BadRequestException("订单不存在,无法更新订单飞行任务状态");
|
||||||
|
}
|
||||||
|
orderDetailService.updateOrderTaskStatus(orderTaskId, taskStatus);
|
||||||
|
if (MainOrderStatusEnum.PROCESSING.getCode().equals(orderMain.getMainOrderStatus())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 更新主单状态
|
||||||
|
orderMainService.updateOrderStatus(orderId, MainOrderStatusEnum.PROCESSING.getCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除飞行任务
|
||||||
|
*
|
||||||
|
* @param orderTaskId 订单任务ID
|
||||||
|
*/
|
||||||
|
public void deleteOrderTask(Long orderTaskId) {
|
||||||
|
OrderDetail orderDetail = orderDetailService.obtainOrderDetailById(orderTaskId);
|
||||||
|
if (ObjectUtil.isNull(orderDetail)) {
|
||||||
|
throw new BadRequestException("订单飞行任务不存在");
|
||||||
|
}
|
||||||
|
EmEmployees employees = JSON.parseObject(SecurityUtils.getCurrentEmployee(), EmEmployees.class);
|
||||||
|
Long orderInitiatorId = employees.getId();
|
||||||
|
// 判断当前用户是否是订单发起者
|
||||||
|
if (!orderInitiatorId.equals(orderDetail.getOperatorId())) {
|
||||||
|
throw new BadRequestException("您没有权限删除此订单任务");
|
||||||
|
}
|
||||||
|
// 判断订单任务是否处于未开始
|
||||||
|
if (!OrderTaskStatusEnum.NOT_STARTED.getCode().equals(orderDetail.getOrderItemStatus())) {
|
||||||
|
String description = OrderTaskStatusEnum.getInstance(orderDetail.getOrderItemStatus()).getDescription();
|
||||||
|
String msg = String.format("订单飞行任务处于[%s]状态,不能进行删除", description);
|
||||||
|
throw new BadRequestException(msg);
|
||||||
|
}
|
||||||
|
orderDetailService.deleteOrderDetailByOrderId(orderTaskId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,13 +67,33 @@ public class OrderMainController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation("新增订单任务")
|
@ApiOperation("新增订单飞行任务")
|
||||||
@PostMapping("/addOrderTask")
|
@PostMapping("/addOrderTask")
|
||||||
public ResponseEntity<Object> addOrderTask(@RequestBody @Validated AddOrderTaskDTO orderTaskDTO) {
|
public ResponseEntity<Object> addOrderTask(@RequestBody @Validated AddOrderTaskDTO orderTaskDTO) {
|
||||||
orderBiz.addOrderTask(orderTaskDTO);
|
orderBiz.addOrderTask(orderTaskDTO);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("编辑订单飞行任务状态")
|
||||||
|
@PutMapping("/editOrderStatus/{orderTaskId}/{taskStatus}")
|
||||||
|
public ResponseEntity<Object> editOrderTaskStatus(
|
||||||
|
@ApiParam(value = "订单任务ID", required = true, example = "1946509536383438850")
|
||||||
|
@PathVariable("orderTaskId") Long orderTaskId,
|
||||||
|
@ApiParam(value = "飞行任务变更状态: 0=未进行中, 1=进行中, 2=已完成, 3=任务失败", required = true, example = "0")
|
||||||
|
@PathVariable("taskStatus") Integer taskStatus) {
|
||||||
|
orderBiz.editOrderTaskStatus(orderTaskId, taskStatus);
|
||||||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("删除订单飞行任务")
|
||||||
|
@DeleteMapping("/deleteOrderTask/{orderTaskId}")
|
||||||
|
public ResponseEntity<Object> deleteOrderTask(
|
||||||
|
@ApiParam(value = "订单任务ID", required = true, example = "1946509536383438850")
|
||||||
|
@PathVariable("orderTaskId") Long orderTaskId) {
|
||||||
|
orderBiz.deleteOrderTask(orderTaskId);
|
||||||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据订单ID查询详情
|
* 根据订单ID查询详情
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.aircraft.modules.order.domain.enums;
|
package com.aircraft.modules.order.domain.enums;
|
||||||
|
|
||||||
|
import com.aircraft.exception.BadRequestException;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@ -57,4 +58,34 @@ public enum OrderTaskStatusEnum {
|
|||||||
return Arrays.stream(OrderTaskStatusEnum.values())
|
return Arrays.stream(OrderTaskStatusEnum.values())
|
||||||
.filter(o -> o.getCode().equals(code)).findFirst().orElse(null);
|
.filter(o -> o.getCode().equals(code)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测状态转换是否有效
|
||||||
|
*
|
||||||
|
* @param oldStatusCode 旧状态
|
||||||
|
* @param changeStatusCode 将要改变的状态值
|
||||||
|
* @return boolean 返回异常信息 变更合法返回true,false 则无需处理状态变更
|
||||||
|
*/
|
||||||
|
public static boolean checkStatusTransitionValid(Integer oldStatusCode, Integer changeStatusCode) {
|
||||||
|
// 未发生变化直接返回
|
||||||
|
if (oldStatusCode.equals(changeStatusCode)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (COMPLETED.code.equals(oldStatusCode) || FAILED.code.equals(oldStatusCode)) {
|
||||||
|
// 获取对应的值返回错误信息
|
||||||
|
OrderTaskStatusEnum oldStatus = OrderTaskStatusEnum.getInstance(oldStatusCode);
|
||||||
|
String msg = String.format("订单任务状态不能进行状态变更,当前状态为:%s", oldStatus.getDescription());
|
||||||
|
throw new BadRequestException(msg);
|
||||||
|
}
|
||||||
|
// 订单状态变更要大于本身的值,否则不允许修改,提示相关错误信息
|
||||||
|
if (changeStatusCode < oldStatusCode) {
|
||||||
|
// 当前状态是什么,不允许变更为什么
|
||||||
|
OrderTaskStatusEnum changeStatus = OrderTaskStatusEnum.getInstance(changeStatusCode);
|
||||||
|
OrderTaskStatusEnum oldStatus = OrderTaskStatusEnum.getInstance(oldStatusCode);
|
||||||
|
String msg = String.format("订单任务状态不能进行状态变更,当前状态为:%s,不允许修改为:%s", oldStatus.getDescription(), changeStatus.getDescription());
|
||||||
|
throw new BadRequestException(msg);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,4 +44,20 @@ public interface IOrderDetailService extends IService<OrderDetail> {
|
|||||||
* @param orderInitiatorId 飞行员ID
|
* @param orderInitiatorId 飞行员ID
|
||||||
*/
|
*/
|
||||||
void checkOrderDetail(Long orderId, Long orderInitiatorId);
|
void checkOrderDetail(Long orderId, Long orderInitiatorId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取订单任务详情
|
||||||
|
*
|
||||||
|
* @param orderTaskId 订单任务ID
|
||||||
|
* @return {@link OrderDetail}
|
||||||
|
*/
|
||||||
|
OrderDetail obtainOrderDetailById(Long orderTaskId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改订单任务状态
|
||||||
|
*
|
||||||
|
* @param orderTaskId 订单任务ID
|
||||||
|
* @param taskStatus 订单任务状态
|
||||||
|
*/
|
||||||
|
void updateOrderTaskStatus(Long orderTaskId, Integer taskStatus);
|
||||||
}
|
}
|
||||||
|
@ -56,4 +56,12 @@ public interface IOrderMainService extends IService<OrderMain> {
|
|||||||
* @param orderId 订单ID
|
* @param orderId 订单ID
|
||||||
*/
|
*/
|
||||||
void deleteOrderMainById(Long orderId);
|
void deleteOrderMainById(Long orderId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改订单状态
|
||||||
|
*
|
||||||
|
* @param orderId 订单ID
|
||||||
|
* @param orderStatus 订单状态
|
||||||
|
*/
|
||||||
|
void updateOrderStatus(Long orderId, Integer orderStatus);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import com.aircraft.modules.order.domain.OrderDetail;
|
|||||||
import com.aircraft.modules.order.domain.enums.OrderTaskStatusEnum;
|
import com.aircraft.modules.order.domain.enums.OrderTaskStatusEnum;
|
||||||
import com.aircraft.modules.order.mapper.OrderDetailMapper;
|
import com.aircraft.modules.order.mapper.OrderDetailMapper;
|
||||||
import com.aircraft.modules.order.service.IOrderDetailService;
|
import com.aircraft.modules.order.service.IOrderDetailService;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -54,4 +55,16 @@ public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, Order
|
|||||||
}
|
}
|
||||||
throw new BadRequestException("新增订单飞行任务: 同一个订单同一个飞行员下,只能存在一个任务状态处于[未进行或进行中]");
|
throw new BadRequestException("新增订单飞行任务: 同一个订单同一个飞行员下,只能存在一个任务状态处于[未进行或进行中]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OrderDetail obtainOrderDetailById(Long orderTaskId) {
|
||||||
|
return getById(orderTaskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateOrderTaskStatus(Long orderTaskId, Integer taskStatus) {
|
||||||
|
LambdaUpdateWrapper<OrderDetail> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.eq(OrderDetail::getId, orderTaskId)
|
||||||
|
.set(OrderDetail::getOrderItemStatus, taskStatus);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,4 +77,11 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
|
|||||||
public void deleteOrderMainById(Long orderId) {
|
public void deleteOrderMainById(Long orderId) {
|
||||||
this.removeById(orderId);
|
this.removeById(orderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateOrderStatus(Long orderId, Integer orderStatus) {
|
||||||
|
this.update(Wrappers.<OrderMain>lambdaUpdate()
|
||||||
|
.eq(OrderMain::getId, orderId)
|
||||||
|
.set(OrderMain::getMainOrderStatus, orderStatus));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user