package com.stylefeng.guns.modular.crossCity.server.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.crossCity.dao.DriverSelfTripMapper; import com.stylefeng.guns.modular.crossCity.dao.LineMapper; import com.stylefeng.guns.modular.crossCity.model.DriverSelfTrip; import com.stylefeng.guns.modular.crossCity.model.Line; import com.stylefeng.guns.modular.crossCity.server.ILineService; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class LineServiceImpl extends ServiceImpl implements ILineService { @Resource private LineMapper lineMapper; @Resource private DriverSelfTripMapper driverSelfTripMapper; /** * 根据站点id获取线路 * @param startId * @param endId * @return * @throws Exception */ @Override public List> queryLines(Integer startId, Integer endId, Integer driverId) throws Exception { List> list1 = lineMapper.queryLines(startId, 1); List> list2 = lineMapper.queryLines(endId, 2); List> list = new ArrayList<>(); for(Map map1 : list1){ Integer id1 = Integer.valueOf(map1.get("id").toString()); for(Map map2 : list2){ Integer id2 = Integer.valueOf(map2.get("id").toString()); if(id1 == id2){ map1.put("startAddress", map1.get("siteName")); map1.put("endAddress", map2.get("siteName")); list.add(map1); } } } if(null != driverId){ List> lists = new ArrayList<>(); List> list3 = lineMapper.scanCodeQueryLines(driverId); for(Map map1 : list){ Integer id2 = Integer.valueOf(map1.get("id").toString()); for(Map map : list3){ Integer id1 = Integer.valueOf(map.get("id").toString()); if(id1 == id2){ lists.add(map1); } } } list = lists; } return list; } /** * 扫码获取司机的所有线路 * @param driverId * @return * @throws Exception */ @Override public List> scanCodeQueryLines(Integer driverId) throws Exception { return lineMapper.scanCodeQueryLines(driverId); } /** * 根据司机id查询当前时间之后发车的城际线路 */ @Override public List> queryFutureLinesByDriver(Integer driverId) throws Exception { if (driverId == null) { return new ArrayList<>(); } return lineMapper.queryFutureLinesByDriver(driverId); } /** * 根据起始站点和终点站点查询第一条线路的目的地列表 */ @Override public List> queryFirstLineDestinations(Integer startId, Integer endId) throws Exception { if (startId != null && endId != null && startId < 0 && endId < 0) { Integer startTripId = Math.abs(startId) / 10; Integer startFlag = Math.abs(startId) % 10; Integer endTripId = Math.abs(endId) / 10; Integer endFlag = Math.abs(endId) % 10; if (startTripId > 0 && endTripId > 0 && startTripId.equals(endTripId) && startFlag == 1 && endFlag == 2) { DriverSelfTrip selfTrip = driverSelfTripMapper.selectById(startTripId); if (selfTrip == null || selfTrip.getState() == null || selfTrip.getState() != 1 || ToolUtil.isEmpty(selfTrip.getDestJson())) { return new ArrayList<>(); } JSONArray array = JSON.parseArray(selfTrip.getDestJson()); if (array == null || array.size() == 0) { return new ArrayList<>(); } List> result = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { JSONObject item = array.getJSONObject(i); if (item == null || item.getDouble("endLon") == null || item.getDouble("endLat") == null) { continue; } Map destination = new HashMap<>(); destination.put("id", 0 - (startTripId * 1000 + i + 1)); destination.put("lineId", 0 - startTripId); destination.put("name", item.getString("endAddress")); destination.put("fenceType", 1); destination.put("coordinate", item.getDouble("endLon") + "," + item.getDouble("endLat") + ";3000"); destination.put("defaultPointLon", item.getDouble("endLon")); destination.put("defaultPointLat", item.getDouble("endLat")); destination.put("price5", item.getBigDecimal("price")); destination.put("price7", item.getBigDecimal("price")); destination.put("state", 1); destination.put("isMain", i == 0 ? 1 : 2); Map fenceInfo = new HashMap<>(); fenceInfo.put("fenceType", destination.get("fenceType")); fenceInfo.put("coordinate", destination.get("coordinate")); fenceInfo.put("defaultPointLon", destination.get("defaultPointLon")); fenceInfo.put("defaultPointLat", destination.get("defaultPointLat")); destination.put("fenceInfo", fenceInfo); result.add(destination); } return result; } } List> lines = queryLines(startId, endId, null); if (lines == null || lines.size() <= 0) { return new ArrayList<>(); } Map firstLine = lines.get(0); if (firstLine == null || firstLine.get("id") == null) { return new ArrayList<>(); } Integer lineId = Integer.valueOf(firstLine.get("id").toString()); List> destinations = lineMapper.queryLineDestinations(lineId); if (destinations == null || destinations.size() <= 0) { return new ArrayList<>(); } for (Map destination : destinations) { Map fenceInfo = new HashMap<>(); fenceInfo.put("fenceType", destination.get("fenceType")); fenceInfo.put("coordinate", destination.get("coordinate")); fenceInfo.put("defaultPointLon", destination.get("defaultPointLon")); fenceInfo.put("defaultPointLat", destination.get("defaultPointLat")); destination.put("fenceInfo", fenceInfo); } return destinations; } }