longz
2026-06-04 da780b14b8db78043d2c0f27d3bfd73111e6d550
UserYKDTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/crossCity/server/impl/LineSiteServiceImpl.java
@@ -1,7 +1,6 @@
package com.stylefeng.guns.modular.crossCity.server.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.util.ToolUtil;
@@ -24,6 +23,7 @@
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -80,6 +80,7 @@
        if (lineId != null && lineId < 0) {
            List<Map<String, Object>> result = lineSiteMapper.queryDriverBySelfTripId(Math.abs(lineId), sdf.parse(day), driverId);
            filterAllOrdersFinishedShift(result);
            for (Map<String, Object> map : result) {
                map.put("chooseSeat", chooseSeat);
            }
@@ -131,14 +132,17 @@
                if(driverId1.size() > 0){
                    continue;
                }
                if(Integer.valueOf(map.get("laveSeat").toString()) <= 0){
                    continue;
                }
                if(lineShift.getId().intValue() == Integer.valueOf(map.get("id").toString()).intValue()){
                    if (isAllOrdersFinishedShift(map.get("lineShiftDriverId"))) {
                        b = false;
                        continue;
                    }
                    if(Integer.valueOf(map.get("laveSeat").toString()) <= 0){
                        continue;
                    }
                    b = false;
                    String content = map.get("content").toString();
                    JSONObject jsonObject = JSON.parseObject(content);
                    map.put("price", jsonObject.getString("num1"));
                    BigDecimal price = getDefaultDestinationPrice(map);
                    map.put("price", price == null ? "0" : price.toPlainString());
                    if (chooseSeat){
                        map.put("chooseSeat", chooseSeat);
                    }else if (driverId == null){
@@ -159,6 +163,56 @@
        return list;
    }
    private BigDecimal getDefaultDestinationPrice(Map<String, Object> map) {
        if (map == null) {
            return null;
        }
        Integer totalSeat = map.get("totalSeat") == null ? null : Integer.valueOf(map.get("totalSeat").toString());
        BigDecimal price = totalSeat != null && totalSeat == 6 ? getBigDecimal(map.get("defaultPrice7")) : getBigDecimal(map.get("defaultPrice5"));
        return price == null ? getBigDecimal(map.get("defaultPrice5")) : price;
    }
    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 void filterAllOrdersFinishedShift(List<Map<String, Object>> result) {
        if (result == null || result.size() == 0) {
            return;
        }
        Iterator<Map<String, Object>> iterator = result.iterator();
        while (iterator.hasNext()) {
            Map<String, Object> map = iterator.next();
            if (isAllOrdersFinishedShift(map.get("lineShiftDriverId"))) {
                iterator.remove();
            }
        }
    }
    private boolean isAllOrdersFinishedShift(Object lineShiftDriverId) {
        if (lineShiftDriverId == null) {
            return false;
        }
        int orderCount = orderCrossCityService.selectCount(new EntityWrapper<OrderCrossCity>()
                .eq("lineShiftDriverId", lineShiftDriverId)
                .eq("isDelete", 1)
                .ne("state", 10));
        if (orderCount <= 0) {
            return false;
        }
        int finishCount = orderCrossCityService.selectCount(new EntityWrapper<OrderCrossCity>()
                .eq("lineShiftDriverId", lineShiftDriverId)
                .eq("isDelete", 1)
                .in("state", Arrays.asList(6, 8, 9)));
        return orderCount == finishCount;
    }
    /**
     * 根据司机排班数据id获取数据(剩余座位号和总座位数)