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<LineMapper, Line> implements ILineService {
|
|
@Resource
|
private LineMapper lineMapper;
|
|
@Resource
|
private DriverSelfTripMapper driverSelfTripMapper;
|
|
|
/**
|
* 根据站点id获取线路
|
* @param startId
|
* @param endId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryLines(Integer startId, Integer endId, Integer driverId) throws Exception {
|
List<Map<String, Object>> list1 = lineMapper.queryLines(startId, 1);
|
List<Map<String, Object>> list2 = lineMapper.queryLines(endId, 2);
|
List<Map<String, Object>> list = new ArrayList<>();
|
for(Map<String, Object> map1 : list1){
|
Integer id1 = Integer.valueOf(map1.get("id").toString());
|
for(Map<String, Object> 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<Map<String, Object>> lists = new ArrayList<>();
|
List<Map<String, Object>> list3 = lineMapper.scanCodeQueryLines(driverId);
|
for(Map<String, Object> map1 : list){
|
Integer id2 = Integer.valueOf(map1.get("id").toString());
|
for(Map<String, Object> 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<Map<String, Object>> scanCodeQueryLines(Integer driverId) throws Exception {
|
return lineMapper.scanCodeQueryLines(driverId);
|
}
|
|
/**
|
* 根据司机id查询当前时间之后发车的城际线路
|
*/
|
@Override
|
public List<Map<String, Object>> queryFutureLinesByDriver(Integer driverId) throws Exception {
|
if (driverId == null) {
|
return new ArrayList<>();
|
}
|
return lineMapper.queryFutureLinesByDriver(driverId);
|
}
|
|
/**
|
* 根据起始站点和终点站点查询第一条线路的目的地列表
|
*/
|
@Override
|
public List<Map<String, Object>> 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<Map<String, Object>> 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<String, Object> 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<String, Object> 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<Map<String, Object>> lines = queryLines(startId, endId, null);
|
if (lines == null || lines.size() <= 0) {
|
return new ArrayList<>();
|
}
|
Map<String, Object> firstLine = lines.get(0);
|
if (firstLine == null || firstLine.get("id") == null) {
|
return new ArrayList<>();
|
}
|
Integer lineId = Integer.valueOf(firstLine.get("id").toString());
|
List<Map<String, Object>> destinations = lineMapper.queryLineDestinations(lineId);
|
if (destinations == null || destinations.size() <= 0) {
|
return new ArrayList<>();
|
}
|
for (Map<String, Object> destination : destinations) {
|
Map<String, Object> 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;
|
}
|
}
|