| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | |
| | | |
| | | @Resource |
| | | private LineShiftMapper lineShiftMapper; |
| | | |
| | | @Resource |
| | | private LinePriceMapper linePriceMapper; |
| | | |
| | | @Resource |
| | | private CarServiceMapper carServiceMapper; |
| | |
| | | return ResultUtil.error("您还没预约呢"); |
| | | } |
| | | if(type == 1){//预约操作 |
| | | int completedCount = lineShiftDriverMapper.countCompletedShiftOrders(driverId, lineShiftId, date.get("startTime")); |
| | | if (completedCount > 0) { |
| | | return ResultUtil.error("该班次已完成,不能重复领取"); |
| | | } |
| | | boolean b = this.judgeTime(driverId, lineShiftId, date.get("startTime")); |
| | | if(b){ |
| | | return ResultUtil.error("预约间隔超出给定可预约范围"); |
| | |
| | | if(null == query){ |
| | | return ResultUtil.error("车辆未开通该服务"); |
| | | } |
| | | Map<String, Object> query1 = linePriceMapper.query(lineShift.getLineId(), query.getServerCarModelId()); |
| | | if(null == query1){ |
| | | return ResultUtil.error("该线路还未设置服务车型相关数据,请联系管理员!"); |
| | | List<Map<String, Object>> destinations = lineMapper.queryLineDestinations(lineShift.getLineId()); |
| | | if(destinations == null || destinations.size() == 0){ |
| | | return ResultUtil.error("该线路还未设置目的地价格,请联系管理员!"); |
| | | } |
| | | CarModel carModel = carModelMapper.selectById(carService.selectById(driverService.selectById(driverId).getCarId()).getCarModelId()); |
| | | LineShiftDriver lineShiftDriver = new LineShiftDriver(); |
| | |
| | | lineItem.setLineId(entry.getKey()); |
| | | lineItem.setLineName(lineNameMap.get(entry.getKey())); |
| | | |
| | | // 查询线路单价 |
| | | Double unitPrice = 0.0D; |
| | | if (carModel != null){ |
| | | List<Map<String, Object>> maps = lineMapper.queryLineDestinations(entry.getKey()); |
| | | if (!maps.isEmpty()){ |
| | | Object o = maps.get(0).get("price" + (carModel.getSeat() + 1)); |
| | | if (o != null){ |
| | | unitPrice = Double.valueOf(o.toString()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // if (serverCarModelId != null) { |
| | | // Map<String, Object> priceInfo = linePriceMapper.query(entry.getKey(), serverCarModelId); |
| | | // if (priceInfo != null && priceInfo.get("content") != null) { |
| | | // // 解析 content JSON,获取 num1(单人价格) |
| | | // String content = priceInfo.get("content").toString(); |
| | | // JSONObject jsonObject = JSON.parseObject(content); |
| | | // String num1 = jsonObject.getString("num1"); |
| | | // if (num1 != null && !num1.isEmpty()) { |
| | | // unitPrice = Double.parseDouble(num1); |
| | | // } |
| | | // } |
| | | // } |
| | | lineItem.setUnitPrice(unitPrice); |
| | | lineItem.setUnitPrice(queryDefaultDestinationPrice(entry.getKey(), carModel == null ? null : carModel.getSeat())); |
| | | |
| | | List<LineShiftItemWarpper> shifts = new ArrayList<>(); |
| | | for (Map<String, Object> shiftMap : entry.getValue()) { |
| | |
| | | result.setStartTime(data.get("startTime") != null ? data.get("startTime").toString() : null); |
| | | result.setEndTime(data.get("endTime") != null ? data.get("endTime").toString() : null); |
| | | result.setTotalSeat(data.get("totalSeat") != null ? Integer.parseInt(data.get("totalSeat").toString()) : null); |
| | | result.setTotalSeatImage(getTotalSeatImage(result.getTotalSeat())); |
| | | result.setLaveSeat(data.get("laveSeat") != null ? Integer.parseInt(data.get("laveSeat").toString()) : null); |
| | | result.setLaveSeatNumber(data.get("laveSeatNumber") != null ? data.get("laveSeatNumber").toString() : null); |
| | | |
| | | // 3. 解析价格JSON获取单人价格 |
| | | String priceContent = data.get("priceContent") != null ? data.get("priceContent").toString() : null; |
| | | if (priceContent != null && !priceContent.isEmpty()) { |
| | | JSONObject json = JSON.parseObject(priceContent); |
| | | String num1 = json.getString("num1"); |
| | | if (num1 != null && !num1.isEmpty()) { |
| | | result.setUnitPrice(Double.parseDouble(num1)); |
| | | } |
| | | }else { |
| | | result.setUnitPrice(0.0); |
| | | } |
| | | result.setUnitPrice(queryDefaultDestinationPrice(result.getLineId(), result.getTotalSeat())); |
| | | |
| | | // 站点信息 |
| | | result.setStartSiteId(data.get("startSiteId") != null ? Integer.parseInt(data.get("startSiteId").toString()) : null); |
| | |
| | | result.setStartTime(trip.getStartTime()); |
| | | result.setEndTime(trip.getStartTime()); |
| | | result.setTotalSeat(lineShiftDriver.getTotalSeat()); |
| | | result.setTotalSeatImage(getTotalSeatImage(result.getTotalSeat())); |
| | | result.setLaveSeat(lineShiftDriver.getLaveSeat()); |
| | | result.setLaveSeatNumber(lineShiftDriver.getLaveSeatNumber()); |
| | | |
| | |
| | | System.out.println("自动清除无效车程数量 " + cancelCount); |
| | | return cancelCount; |
| | | } |
| | | |
| | | private Double queryDefaultDestinationPrice(Integer lineId, Integer totalSeat) { |
| | | List<Map<String, Object>> destinations = lineMapper.queryLineDestinations(lineId); |
| | | if (destinations == null || destinations.size() == 0) { |
| | | return 0.0D; |
| | | } |
| | | Map<String, Object> destination = destinations.get(0); |
| | | BigDecimal price = totalSeat != null && totalSeat == 6 |
| | | ? getBigDecimal(destination.get("price7")) |
| | | : getBigDecimal(destination.get("price5")); |
| | | if (price == null) { |
| | | price = getBigDecimal(destination.get("price5")); |
| | | } |
| | | return price == null ? 0.0D : price.doubleValue(); |
| | | } |
| | | |
| | | private BigDecimal getBigDecimal(Object value) { |
| | | if (value == null || ToolUtil.isEmpty(String.valueOf(value))) { |
| | | return null; |
| | | } |
| | | try { |
| | | return new BigDecimal(String.valueOf(value)); |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | private String getTotalSeatImage(Integer totalSeat) { |
| | | if (totalSeat == null) { |
| | | return null; |
| | | } |
| | | String fileName; |
| | | if (totalSeat == 4) { |
| | | fileName = "seat/seat_five.png"; |
| | | } else if (totalSeat == 5) { |
| | | fileName = "seat/seat_six.png"; |
| | | } else if (totalSeat == 6) { |
| | | fileName = "seat/seat_seven.png"; |
| | | } else { |
| | | return null; |
| | | } |
| | | try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(fileName)) { |
| | | if (inputStream == null) { |
| | | return null; |
| | | } |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | byte[] buffer = new byte[4096]; |
| | | int length; |
| | | while ((length = inputStream.read(buffer)) != -1) { |
| | | outputStream.write(buffer, 0, length); |
| | | } |
| | | return "data:image/png;base64," + Base64.getEncoder().encodeToString(outputStream.toByteArray()); |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | } |
| | | } |