package com.cdzy.operations.controller; import cn.dev33.satoken.stp.StpUtil; import com.cdzy.common.enums.Message; import com.cdzy.common.model.request.PageParam; import com.cdzy.common.model.response.JsonResult; import com.cdzy.operations.enums.OrderHandleState; import com.cdzy.operations.model.dto.*; import com.cdzy.operations.model.entity.EbikeRegion; import com.cdzy.operations.model.vo.*; import com.cdzy.operations.service.EbikeBikeOrderService; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.util.StringUtil; import jakarta.annotation.Resource; import jakarta.validation.constraints.NotNull; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.util.List; import java.util.Objects; import static com.cdzy.operations.model.entity.table.EbikeBikeInfoTableDef.EBIKE_BIKE_INFO; import static com.cdzy.operations.model.entity.table.EbikeBikeOrderTableDef.EBIKE_BIKE_ORDER; /** * 工单信息 控制层。 * * @author attiya * @since 2025-11-24 */ @RestController @RequestMapping("/ebikeBikeOrder") @Validated public class EbikeBikeOrderController { @Resource private EbikeBikeOrderService ebikeBikeOrderService; /** * 分页查询工单信息。 * * @param page 分页对象 * @return 分页对象 */ @GetMapping("page") public JsonResult page(PageParam page, Integer orderType, String bikeCode) { QueryWrapper queryWrapper = QueryWrapper.create() .select(EBIKE_BIKE_INFO.LOCATION, EBIKE_BIKE_ORDER.ALL_COLUMNS) .where(EBIKE_BIKE_ORDER.HANDLE_STATE.eq(OrderHandleState.UNPROCESSED)) .where(EBIKE_BIKE_ORDER.ORDER_TYPE.eq(orderType, Objects.nonNull(orderType))) .where(EBIKE_BIKE_ORDER.BIKE_CODE.like(bikeCode, StringUtil.hasText(bikeCode))) .leftJoin(EBIKE_BIKE_INFO).on(EBIKE_BIKE_INFO.BIKE_CODE.eq(EBIKE_BIKE_ORDER.BIKE_CODE)); Page orderPage = ebikeBikeOrderService.pageAs(page.getPage(), queryWrapper, EbikeBikeOrderPageDto.class); return JsonResult.success(orderPage); } /** * 分页查询当前员工接取的工单信息。 * * @param page 分页对象 * @return 分页对象 */ @GetMapping("pageByStaff") public JsonResult pageByStaff(PageParam page, Integer orderType, String bikeCode) { QueryWrapper queryWrapper = QueryWrapper.create() .select(EBIKE_BIKE_INFO.LOCATION, EBIKE_BIKE_ORDER.ALL_COLUMNS) .where(EBIKE_BIKE_ORDER.HANDLE_STATE.eq(OrderHandleState.ACCEPTED)) .or(EBIKE_BIKE_ORDER.HANDLE_STATE.eq(OrderHandleState.ACCEPTED)) .where(EBIKE_BIKE_ORDER.ORDER_TYPE.eq(orderType, Objects.nonNull(orderType))) .where(EBIKE_BIKE_ORDER.BIKE_CODE.like(bikeCode, StringUtil.hasText(bikeCode))) .where(EBIKE_BIKE_ORDER.RECEIVER_ID.eq(StpUtil.getLoginIdAsLong())) .leftJoin(EBIKE_BIKE_INFO).on(EBIKE_BIKE_INFO.BIKE_CODE.eq(EBIKE_BIKE_ORDER.BIKE_CODE)) .orderBy(EBIKE_BIKE_ORDER.CREATED_AT.desc()); Page orderPage = ebikeBikeOrderService.pageAs(page.getPage(), queryWrapper, EbikeBikeOrderPageDto.class); return JsonResult.success(orderPage); } /** * 工单详情。 * * @param orderId 工单ID * @return 分页对象 */ @GetMapping("getInfo") public JsonResult getInfo(@NotNull(message = "工单ID不能为空") Long orderId) { EbikeBikeOrderInfoDto infoDto = ebikeBikeOrderService.getInfo(orderId); return JsonResult.success(infoDto); } /** * 生成换电工单。 * * @param ecuSn 中控编码 * @return 结果 */ @GetMapping("batterySwapOrder") public JsonResult batterySwapOrder(@NotNull(message = "中控编号不能为空") String ecuSn) { ebikeBikeOrderService.createBatterySwapOrder(ecuSn); return JsonResult.success(); } /** * 生成巡检工单。 * * @param inspectionSwapOrderVo 巡检信息 * @return 结果 */ @PostMapping("inspectionSwapOrder") public JsonResult inspectionSwapOrder(@Validated @RequestBody InspectionSwapOrderVo inspectionSwapOrderVo) { ebikeBikeOrderService.createInspectionSwapOrder(inspectionSwapOrderVo); return JsonResult.success(); } /** * 完成巡检工单。 * * @return 结果 */ @PostMapping("doInspection") public JsonResult doInspection(@RequestBody @Validated DoneInspectionVo inspectionVo) { ebikeBikeOrderService.doInspection(inspectionVo); return JsonResult.success(); } /** * 生成调度工单。 * * @param bikeCode 车辆编号 * @return 结果 */ @GetMapping("dispatchSwapOrder") public JsonResult dispatchSwapOrder(@NotNull(message = "车辆编号不能为空") String bikeCode) { ebikeBikeOrderService.createDispatchSwapOrder(bikeCode); return JsonResult.success(); } /** * 校验车辆是否可以生成调度工单。 * * @param bikeCode 车辆编号 * @return 结果 */ @GetMapping("checkDispatchSwapOrder") public JsonResult checkDispatchSwapOrder(@NotNull(message = "车辆编号不能为空") String bikeCode) { Boolean checked = ebikeBikeOrderService.checkDispatchSwapOrder(bikeCode); return JsonResult.success(checked); } /** * 批量生成调度工单。 * * @param dispatchSwapVo 信息 * @return 结果 */ @PostMapping("dispatchSwapOrders") public JsonResult dispatchSwapOrders(@RequestBody @Validated DispatchSwapVo dispatchSwapVo) { ebikeBikeOrderService.createDispatchSwapOrders(dispatchSwapVo); return JsonResult.success(); } /** * 生成维修工单。 * * @param faultOrderVo 故障信息 * @return 结果 */ @PostMapping("faultOrder") public JsonResult faultOrder(@Validated @RequestBody FaultOrderVo faultOrderVo) { Long orderId = ebikeBikeOrderService.faultOrder(faultOrderVo); return JsonResult.success(orderId); } /** * 完成维修工单。 * * @param faultOrderVo 故障信息 * @return 结果 */ @PostMapping("doFault") public JsonResult doFault(@Validated @RequestBody DoneFaultOrderVo faultOrderVo) { ebikeBikeOrderService.doFault(faultOrderVo); return JsonResult.success(); } /** * 接取工单。 * * @param orderId 工单ID * @return 分页对象 */ @GetMapping("acceptOrder") public JsonResult acceptOrder(@NotNull(message = "工单ID不能为空") Long orderId) { ebikeBikeOrderService.acceptOrder(orderId); return JsonResult.success(); } /** * 上传远程故障图片 * * @param file 文件 * @return 操作结果 */ @PostMapping("upload") public JsonResult upload(@RequestParam("file") MultipartFile file) throws Exception { String result = ebikeBikeOrderService.upload(file); return JsonResult.success(Message.SUCCESS, result); } /** * 电池二维码检查(换电工单用,包含带电池中控二维码) * @param code 电池二维码 * * @return 操作结果 */ @GetMapping("checkCode") public JsonResult checkCode(@NotNull(message = "二维码不能为空")String code) { ebikeBikeOrderService.checkCode(code); return JsonResult.success(Message.SUCCESS); } /** * 领取电池(换电工单用) * * @return 操作结果 */ @PostMapping("batteryClaim") public JsonResult batteryClaim(@Validated @RequestBody EbikeBatteryClaimReturnVo batteryClaimVo) { ebikeBikeOrderService.batteryClaim(batteryClaimVo); return JsonResult.success(Message.SUCCESS); } /** * 归还电池(换电工单用) * * @return 操作结果 */ @PostMapping("batteryReturn") public JsonResult batteryReturn(@Validated @RequestBody EbikeBatteryClaimReturnVo batteryClaimVo) { ebikeBikeOrderService.batteryReturn(batteryClaimVo); return JsonResult.success(Message.SUCCESS); } /** * 更换电池(换电工单用,完成换电工单) * * @return 操作结果 */ @PostMapping("batteryChange") public JsonResult batteryChange(@Validated @RequestBody EbikeBatteryChangeVo changeVo) { ebikeBikeOrderService.batteryChange(changeVo); return JsonResult.success(); } /** * 完成调度工单。 * * @param doneDispatchOrderVo 调度信息 * @return 结果 */ @PostMapping("bikeDispatch") public JsonResult bikeDispatch(@RequestBody @Validated DoneDispatchOrderVo doneDispatchOrderVo) { ebikeBikeOrderService.bikeDispatch(doneDispatchOrderVo); return JsonResult.success(); } /** * 运营区列表(工单用) * * @return 操作结果 */ @PostMapping("regionList") public JsonResult> regionList(@RequestBody OrderRegionVo orderRegionVo){ List list = ebikeBikeOrderService.regionList(orderRegionVo); return JsonResult.success(list); } /** * 车辆列表(工单用) * * @return 操作结果 */ @GetMapping("bikeList") public JsonResult> bikeList(@RequestParam("regionId") Long regionId) throws IOException { List list = ebikeBikeOrderService.bikeList(regionId); return JsonResult.success(list); } /** * 车辆详情(工单用) * * @return 操作结果 */ @GetMapping("bikeInfo") public JsonResult bikeInfo(@RequestParam("bikeCode") String bikeCode,Integer orderType) throws IOException { EbikeOrderBikeInfoDto info = ebikeBikeOrderService.bikeInfo(bikeCode,orderType); return JsonResult.success(info); } /** * 有效调度工单统计 * * @return 操作结果 */ @GetMapping("effectiveDispatchOrder") public JsonResult> effectiveDispatchOrder(@RequestBody EffectiveDispatchOrderVo effectiveDispatchOrderVo) { List list = ebikeBikeOrderService.effectiveDispatchOrder(effectiveDispatchOrderVo); return JsonResult.success(list); } /** * 工单看板 * * @return 操作结果 */ @GetMapping("bulletinBoard") public JsonResult bulletinBoard() { EbikeOrderBulletinBoardInfo info = ebikeBikeOrderService.bulletinBoard(); return JsonResult.success(info); } /** * 个人未完成工单统计 * * @return 操作结果 */ @GetMapping("unfinishedOrders") public JsonResult unfinishedOrders() { EbikeOrderUnfinishedInfo info = ebikeBikeOrderService.unfinishedOrders(); return JsonResult.success(info); } /** * 查看未完成调度工单的车辆编号列表 * * @return 操作结果 */ @GetMapping("unfinishedDispatchBikeCodes") public JsonResult> unfinishedDispatchBikeCodes() { List list = ebikeBikeOrderService.unfinishedDispatchBikeCodes(); return JsonResult.success(list); } /** * 批量完成调度工单 * * @return 操作结果 */ @GetMapping("batchFinishDispatch") public JsonResult batchFinishDispatch(@RequestBody @Validated EbikeBatchDispatchVo dispatchVo) { ebikeBikeOrderService.batchFinishDispatch(dispatchVo); return JsonResult.success(); } }