perf: 优化订单飞行任务;完善订单详情列表;修复获取当前用户的空指针异常
This commit is contained in:
parent
88305f65a7
commit
285b351e2e
@ -40,6 +40,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -212,9 +213,7 @@ public class OrderBiz {
|
||||
public void addOrder(AddOrderDTO addOrderDTO) {
|
||||
|
||||
// 获取当前登录用户(飞行端用户)
|
||||
EmEmployees employees = JSON.parseObject(SecurityUtils.getCurrentEmployee(), EmEmployees.class);
|
||||
// 发起人ID
|
||||
Long orderInitiatorId = employees.getId();
|
||||
Long orderInitiatorId = SecurityUtils.getCurrentUserId();
|
||||
// 新增订单
|
||||
OrderMain orderMain = orderMainService.addOrder(buildOrderParam(addOrderDTO, orderInitiatorId));
|
||||
// 构建保存操作人信息
|
||||
@ -268,8 +267,7 @@ public class OrderBiz {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addOrderTask(AddOrderTaskDTO orderTaskDTO) {
|
||||
// 获取当前登录用户
|
||||
EmEmployees employees = JSON.parseObject(SecurityUtils.getCurrentEmployee(), EmEmployees.class);
|
||||
Long orderInitiatorId = employees.getId();
|
||||
Long orderInitiatorId = SecurityUtils.getCurrentUserId();
|
||||
|
||||
// 新建订单飞行任务限制(当前飞行员不能存在任务处于未进行,进行中)
|
||||
Long orderId = orderTaskDTO.getOrderId();
|
||||
@ -277,15 +275,15 @@ public class OrderBiz {
|
||||
|
||||
// 构建任务参数
|
||||
OrderDetail orderTask = buildOrderTaskParam(orderTaskDTO, orderInitiatorId);
|
||||
// 批量新增
|
||||
orderDetailService.addOrderDetail(orderTask);
|
||||
// 新增订单飞行任务
|
||||
OrderDetail orderDetail = orderDetailService.addOrderDetail(orderTask);
|
||||
|
||||
// 判断是否存在材料
|
||||
if (CollectionUtil.isEmpty(orderTaskDTO.getAttachmentMaterialList())) {
|
||||
return;
|
||||
}
|
||||
// 保存材料
|
||||
List<AttachmentMaterial> attachmentMaterialList = buildAttachmentMaterialParam(orderTaskDTO);
|
||||
List<AttachmentMaterial> attachmentMaterialList = buildAttachmentMaterialParam(orderTaskDTO, orderDetail.getId());
|
||||
attachmentMaterialService.batchAddAttachmentMaterial(attachmentMaterialList);
|
||||
}
|
||||
|
||||
@ -311,13 +309,14 @@ public class OrderBiz {
|
||||
* 构建保存材料参数
|
||||
*
|
||||
* @param orderTaskDTO {@link AddOrderTaskDTO}
|
||||
* @param orderDetailId 订单详情ID
|
||||
* @return {@link AttachmentMaterial}
|
||||
*/
|
||||
private List<AttachmentMaterial> buildAttachmentMaterialParam(AddOrderTaskDTO orderTaskDTO) {
|
||||
private List<AttachmentMaterial> buildAttachmentMaterialParam(AddOrderTaskDTO orderTaskDTO, Long orderDetailId) {
|
||||
List<AttachmentMaterial> materialList = new ArrayList<>();
|
||||
for (LocalAttachmentMaterialDTO materialDTO : orderTaskDTO.getAttachmentMaterialList()) {
|
||||
AttachmentMaterial attachmentMaterial = new AttachmentMaterial();
|
||||
attachmentMaterial.setBusinessId(orderTaskDTO.getOrderId());
|
||||
attachmentMaterial.setBusinessId(orderDetailId);
|
||||
attachmentMaterial.setBusinessType(AttachmentMaterialBusinessTypeEnum.ORDER_TASK_MATERIAL.getCode());
|
||||
attachmentMaterial.setFileType(materialDTO.getFileType());
|
||||
attachmentMaterial.setSourceFileName(materialDTO.getSourceFileName());
|
||||
@ -335,6 +334,7 @@ public class OrderBiz {
|
||||
public OrderAllDetailVO queryOrderDetail(Long id) {
|
||||
// 获取订单详情
|
||||
OrderMain orderMain = orderMainService.obtainOrderMainById(id);
|
||||
|
||||
Long orderInitiatorId = orderMain.getOrderInitiatorId();
|
||||
List<EmEmployees> emEmployeesList = emEmployeesService.list();
|
||||
Map<Long, EmEmployees> emEmployeesMap = emEmployeesList.stream().collect( Collectors.toMap(EmEmployees::getId, v -> v));
|
||||
@ -343,29 +343,20 @@ public class OrderBiz {
|
||||
|
||||
// 构建订单回显
|
||||
OrderAllDetailVO orderAllDetailVO = new OrderAllDetailVO();
|
||||
orderAllDetailVO.setId(orderMain.getId());
|
||||
orderAllDetailVO.setOrderNo(orderMain.getOrderNo());
|
||||
orderAllDetailVO.setOrderType(OrderTypeEnum.getInstance(orderMain.getOrderType()).getDescription());
|
||||
orderAllDetailVO.setOrderInitiator(emEmployees.getName());
|
||||
orderAllDetailVO.setInitiatorPhone(emEmployees.getPhone());
|
||||
orderAllDetailVO.setCustomerName(customerName);
|
||||
orderAllDetailVO.setPhone(orderMain.getPhone());
|
||||
orderAllDetailVO.setCargoWeight(orderMain.getCargoWeight());
|
||||
orderAllDetailVO.setSurchargeAmount(orderMain.getSurchargeAmount());
|
||||
orderAllDetailVO.setAmount(orderMain.getAmount());
|
||||
orderAllDetailVO.setScenicName(emScenicService.obtainScenicById(orderMain.getAttractionId()).getName());
|
||||
|
||||
// 获取路线
|
||||
String routeIds = orderMain.getRouteIds();
|
||||
List<CpRoute> cpRoutes = cpRouteService.obtainAllRoutes();
|
||||
Map<Long, CpRoute> routeMap = cpRoutes.stream().collect(Collectors.toMap(CpRoute::getId, route -> route));
|
||||
String[] routeIdArray = routeIds.split(StrUtil.COMMA);
|
||||
StringBuilder routeNameBuilder = new StringBuilder();
|
||||
for (String routeIdStr : routeIdArray) {
|
||||
CpRoute cpRoute = routeMap.get(Long.valueOf(routeIdStr));
|
||||
String name = cpRoute.getName();
|
||||
routeNameBuilder.append(name).append(StrUtil.COMMA);
|
||||
}
|
||||
// 去掉最后一个逗号
|
||||
String routeName = routeNameBuilder.substring(0, routeNameBuilder.length() - 1);
|
||||
String routeName = obtainRouteName(orderMain);
|
||||
orderAllDetailVO.setRouteName(routeName);
|
||||
|
||||
// 获取该订单下的操作人
|
||||
List<OrderOperator> orderOperatorList = orderOperatorService.queryAllByOrderIds(List.of(id));
|
||||
// 转成map
|
||||
@ -433,6 +424,27 @@ public class OrderBiz {
|
||||
return orderAllDetailVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取路线名称
|
||||
*
|
||||
* @param orderMain {@link OrderMain}
|
||||
* @return 拼接的路线名称
|
||||
*/
|
||||
private String obtainRouteName(OrderMain orderMain) {
|
||||
String routeIds = orderMain.getRouteIds();
|
||||
List<CpRoute> cpRoutes = cpRouteService.obtainAllRoutes();
|
||||
Map<Long, CpRoute> routeMap = cpRoutes.stream().collect(Collectors.toMap(CpRoute::getId, route -> route));
|
||||
String[] routeIdArray = routeIds.split(StrUtil.COMMA);
|
||||
StringBuilder routeNameBuilder = new StringBuilder();
|
||||
for (String routeIdStr : routeIdArray) {
|
||||
CpRoute cpRoute = routeMap.get(Long.valueOf(routeIdStr));
|
||||
String name = cpRoute.getName();
|
||||
routeNameBuilder.append(name).append(StrUtil.COMMA);
|
||||
}
|
||||
// 去掉最后一个逗号
|
||||
return routeNameBuilder.substring(0, routeNameBuilder.length() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改订单
|
||||
*/
|
||||
@ -449,8 +461,7 @@ public class OrderBiz {
|
||||
throw new BadRequestException("当前订单状态不是未进行中,不允许修改");
|
||||
}
|
||||
// 判断当前登录人、是否为订单发起人,不是则不允许修改
|
||||
EmEmployees employees = JSON.parseObject(SecurityUtils.getCurrentEmployee(), EmEmployees.class);
|
||||
Long currentId = employees.getId();
|
||||
Long currentId = SecurityUtils.getCurrentUserId();
|
||||
if (!currentId.equals(orderMain.getOrderInitiatorId())) {
|
||||
throw new BadRequestException("当前登录用户不是订单发起人,不允许修改");
|
||||
}
|
||||
@ -484,8 +495,7 @@ public class OrderBiz {
|
||||
throw new BadRequestException("当前订单状态不是处于未进行中,不允许删除");
|
||||
}
|
||||
// 判断当前登录人、是否为订单发起人,不是则不允许修改
|
||||
EmEmployees employees = JSON.parseObject(SecurityUtils.getCurrentEmployee(), EmEmployees.class);
|
||||
Long currentId = employees.getId();
|
||||
Long currentId = SecurityUtils.getCurrentUserId();
|
||||
if (!currentId.equals(orderMain.getOrderInitiatorId())) {
|
||||
throw new BadRequestException("当前登录用户不是订单发起人,不允许删除订单");
|
||||
}
|
||||
@ -532,8 +542,7 @@ public class OrderBiz {
|
||||
throw new BadRequestException("订单任务不存在");
|
||||
}
|
||||
// 判断当前用户是否是订单发起者
|
||||
EmEmployees employees = JSON.parseObject(SecurityUtils.getCurrentEmployee(), EmEmployees.class);
|
||||
Long currentOperatorId = employees.getId();
|
||||
Long currentOperatorId = SecurityUtils.getCurrentUserId();
|
||||
if (!currentOperatorId.equals(orderDetail.getOperatorId())) {
|
||||
throw new BadRequestException("您没有权限更改此飞行任务状态");
|
||||
}
|
||||
@ -570,8 +579,7 @@ public class OrderBiz {
|
||||
if (ObjectUtil.isNull(orderDetail)) {
|
||||
throw new BadRequestException("订单飞行任务不存在");
|
||||
}
|
||||
EmEmployees employees = JSON.parseObject(SecurityUtils.getCurrentEmployee(), EmEmployees.class);
|
||||
Long orderInitiatorId = employees.getId();
|
||||
Long orderInitiatorId = SecurityUtils.getCurrentUserId();
|
||||
// 判断当前用户是否是订单发起者
|
||||
if (!orderInitiatorId.equals(orderDetail.getOperatorId())) {
|
||||
throw new BadRequestException("您没有权限删除此订单任务");
|
||||
|
@ -82,7 +82,13 @@ public class OrderAllDetailVO {
|
||||
* 附加费
|
||||
*/
|
||||
@ApiModelProperty(value = "附加费")
|
||||
private BigDecimal additionalFee;
|
||||
private BigDecimal surchargeAmount;
|
||||
|
||||
/**
|
||||
* 订单金额
|
||||
*/
|
||||
@ApiModelProperty(value = "订单金额")
|
||||
private BigDecimal amount;
|
||||
|
||||
/**
|
||||
* 操作员,多个逗号拼接返回
|
||||
|
@ -95,6 +95,11 @@ public class OrderMainPageQueryVO {
|
||||
@ApiModelProperty(value = "结算状态: 0=未结算, 1=已结算")
|
||||
private Integer settlementStatus;
|
||||
|
||||
/**
|
||||
* 附加费surcharge_amount
|
||||
*/
|
||||
@ApiModelProperty(value = "附加费")
|
||||
private BigDecimal surchargeAmount;
|
||||
/**
|
||||
* 订单金额
|
||||
*/
|
||||
|
@ -20,7 +20,7 @@ public interface IOrderDetailService extends IService<OrderDetail> {
|
||||
*
|
||||
* @param orderTask {@link OrderDetail}订单任务
|
||||
*/
|
||||
void addOrderDetail(OrderDetail orderTask);
|
||||
OrderDetail addOrderDetail(OrderDetail orderTask);
|
||||
|
||||
/**
|
||||
* 获取订单详情
|
||||
|
@ -25,8 +25,9 @@ import java.util.List;
|
||||
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements IOrderDetailService {
|
||||
|
||||
@Override
|
||||
public void addOrderDetail(OrderDetail orderTask) {
|
||||
this.save(orderTask);
|
||||
public OrderDetail addOrderDetail(OrderDetail orderTask) {
|
||||
this.save(orderTask);
|
||||
return orderTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user