| | |
| | | package com.xiaopeng.order.controller; |
| | | |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.xiaopeng.api.dto.automaticPilot.PushOrderDto; |
| | | import com.xiaopeng.api.dto.map.OrderRouteAndFareDto; |
| | | import com.xiaopeng.api.dto.operation.LonLatDto; |
| | | import com.xiaopeng.api.dto.order.AddCruiseMissionDto; |
| | | import com.xiaopeng.api.feignClient.automaticPilot.OrderMissionClient; |
| | | import com.xiaopeng.api.feignClient.map.XpMapClient; |
| | | import com.xiaopeng.api.model.order.XpCruiseOrder; |
| | | import com.xiaopeng.api.vo.OrderType; |
| | | import com.xiaopeng.api.vo.operation.RouteVo; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.utils.WebUtils; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.common.redis.service.RedisService; |
| | | import com.xiaopeng.order.model.exportExcel.XpCruiseOrderExportExcel; |
| | | import com.xiaopeng.order.model.exportExcel.XpOrderExportExcel; |
| | | import com.xiaopeng.order.model.query.XpCruiseOrderExcelQuery; |
| | | import com.xiaopeng.order.model.vo.XpOrderPageVO; |
| | | import com.xiaopeng.order.service.IXpCruiseOrderService; |
| | | import com.xiaopeng.order.model.query.XpCruiseOrderPageQuery; |
| | | import com.xiaopeng.order.model.vo.XpCruiseOrderPageVO; |
| | | import com.xiaopeng.order.service.IXpOrderService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private final OrderMissionClient orderMissionClient; |
| | | private final IXpOrderService xpOrderService; |
| | | |
| | | @Resource |
| | | private XpMapClient xpMapClient; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 查询并终止订单信息 返回id信息 |
| | | * 根据车辆VIN码取消订单 |
| | | * 发送取消订单XPU报文 |
| | | * |
| | | * @param |
| | | */ |
| | | @PostMapping("/inner/cruiseOrder/updateCruiseOrder") |
| | | public R<Long> updateCruiseOrder(@RequestParam String vin) { |
| | | Long id = xpCruiseOrderService.updateCruiseOrder(vin); |
| | | return R.ok(id); |
| | | @PostMapping("/logan/inner/cruiseOrder/cancelCruiseOrderByVin") |
| | | public R<XpCruiseOrder> cancelCruiseOrderByVin(@RequestParam String vin) { |
| | | XpCruiseOrder cruiseOrder = xpCruiseOrderService.cancelCruiseOrderByVin(vin); |
| | | return R.ok(cruiseOrder); |
| | | } |
| | | |
| | | /** |
| | | * 查询并完成订单信息 返回id信息 |
| | | * 完成订单 |
| | | * |
| | | * @param |
| | | */ |
| | | @PostMapping("/inner/cruiseOrder/closeCruiseOrder") |
| | | public R<Long> closeCruiseOrder(@RequestParam String vin) { |
| | | Long id = xpCruiseOrderService.closeCruiseOrder(vin); |
| | | return R.ok(id); |
| | | @PostMapping("/logan/inner/cruiseOrder/completeCruiseOrder") |
| | | public R<?> completeCruiseOrder(@RequestParam Long orderId) { |
| | | xpCruiseOrderService.completeCruiseOrder(orderId); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据订单ID查询取消订单 |
| | | * |
| | | * @param orderId |
| | | * @return |
| | | */ |
| | | @PostMapping("/inner/cruiseOrder/updateCruiseOrderId") |
| | | public R<Long> updateCruiseOrderId(@RequestParam Long orderId){ |
| | | return xpCruiseOrderService.updateCruiseOrderId(orderId); |
| | | @PostMapping("/logan/inner/cruiseOrder/cancelCruiseOrderById") |
| | | public R<XpCruiseOrder> cancelCruiseOrderById(@RequestParam Long orderId) { |
| | | return xpCruiseOrderService.cancelCruiseOrderById(orderId); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询订单信息 |
| | | * |
| | | * @param orderId |
| | | * @return |
| | | */ |
| | | @PostMapping("/inner/cruiseOrder/getCruiseOrder") |
| | | public R<XpCruiseOrder> getCruiseOrder(@RequestParam Long orderId){ |
| | | @PostMapping("/logan/inner/cruiseOrder/getCruiseOrder") |
| | | public R<XpCruiseOrder> getCruiseOrder(@RequestParam Long orderId) { |
| | | return R.ok(xpCruiseOrderService.getById(orderId)); |
| | | } |
| | | |
| | |
| | | * @param |
| | | * @return 订单ID |
| | | */ |
| | | @PostMapping("/inner/cruiseOrder/addCruiseOrder") |
| | | @PostMapping("/logan/inner/cruiseOrder/addCruiseOrder") |
| | | public R<Long> addCruiseOrder(@RequestBody XpCruiseOrder order) { |
| | | boolean save = xpCruiseOrderService.save(order); |
| | | if (!save) { |
| | |
| | | |
| | | // 下发命令 |
| | | PushOrderDto pushOrderDto = new PushOrderDto(); |
| | | pushOrderDto.setEndTaskId(order.getXpuTaskId()); |
| | | pushOrderDto.setVin(order.getVehicleVin()); |
| | | pushOrderDto.setOrderId("XU" + order.getId()); |
| | | pushOrderDto.setStartWaypointId(order.getStartPointId()); |
| | | pushOrderDto.setEndWaypointId(order.getEndPointId()); |
| | | pushOrderDto.setStartLatitude(order.getStartLat()); |
| | | pushOrderDto.setStartLongitude(order.getStartLon()); |
| | | pushOrderDto.setEndLatitude(order.getEndLat()); |
| | | pushOrderDto.setEndLongitude(order.getEndLon()); |
| | | pushOrderDto.setOrderType(OrderType.CRUISE_ORDER); |
| | | pushOrderDto.setStage(2); |
| | | if(null != order){ |
| | | pushOrderDto.setLastOrderId(order.getLastOrderId1()); |
| | | pushOrderDto.setLastXpuTaskId(order.getLastXpuTaskId()); |
| | | } |
| | | pushOrderDto.setTaskActionType(order.getTaskActionType()); |
| | | // 调用推送服务 orderId + carVin |
| | | orderMissionClient.pushOrder(pushOrderDto); |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 添加巡游任务 下发命令 |
| | | * @param |
| | | * @param |
| | | * 终止所有没结束或者终止的订单 |
| | | * |
| | | * @param vin |
| | | * @return |
| | | */ |
| | | @PostMapping("/inner/cruiseOrder/addCruiseMission") |
| | | public R<?> addCruiseMission(@RequestBody AddCruiseMissionDto dto){ |
| | | xpOrderService.addCruiseMission(dto.getVehicle(),dto.getOrder()); |
| | | @PostMapping("/logan/inner/cruiseOrder/stopAllCruiseOrder") |
| | | public R<?> stopAllCruiseOrder(@RequestParam String vin) { |
| | | xpCruiseOrderService.update(new UpdateWrapper<XpCruiseOrder>().eq("vehicleVin", vin) |
| | | .in("status", Arrays.asList(0, 1)).set("status", 2)); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 巡游订单导出 |
| | | * |
| | | * @param query 查询参数 |
| | | */ |
| | | @ApiOperation(value = "巡游订单导出", tags = {"管理后台-巡游订单"}) |
| | | @PostMapping("/api/v1/cruiseOrder/exportExcel") |
| | | public void exportExcel(@RequestBody XpCruiseOrderExcelQuery query) { |
| | | // 1. 查询导出数据 |
| | | List<XpCruiseOrderPageVO> dataList = xpCruiseOrderService.getExportList(query); |
| | | |
| | | // 2. 转换为导出对象 |
| | | List<XpCruiseOrderExportExcel> exportList = BeanUtil.copyToList(dataList, XpCruiseOrderExportExcel.class); |
| | | exportList.forEach(item -> item.setOrderSource("系统自动创建")); |
| | | |
| | | // 3. 生成 Excel |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), XpCruiseOrderExportExcel.class, exportList); |
| | | |
| | | // 4. 输出到响应流 |
| | | HttpServletResponse response = WebUtils.response(); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | String fileName = URLEncoder.encode("巡游订单订单列表.xls", "utf-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | if (outputStream != null) { |
| | | outputStream.close(); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除巡游订单 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "删除巡游订单", tags = {"管理后台-巡游订单"}) |
| | | @DeleteMapping(value = "/api/v1/cruise-order/deleteById/{id}") |
| | | public R<?> deleteById(@PathVariable Long id){ |
| | | xpCruiseOrderService.removeById(id); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "巡游订单详情", tags = {"管理后台-巡游订单"}) |
| | | @GetMapping(value = "/api/v1/cruise-order/getDetailById/{id}") |
| | | public R<XpCruiseOrderPageVO> getDetailById(@PathVariable Long id){ |
| | | XpCruiseOrderPageVO xpCruiseOrder = xpCruiseOrderService.getDetailById(id); |
| | | return R.ok(xpCruiseOrder); |
| | | } |
| | | } |