diff --git a/pom.xml b/pom.xml index 720421d..272133e 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,20 @@ + + + org.gavaghan + geodesy + 1.1.3 + + + + jakarta.validation + jakarta.validation-api + 3.1.1 + + + org.springframework.boot diff --git a/src/main/java/com/ykMap/base/config/MyBatisPlusConfig.java b/src/main/java/com/ykMap/base/config/MyBatisPlusConfig.java new file mode 100644 index 0000000..dc42731 --- /dev/null +++ b/src/main/java/com/ykMap/base/config/MyBatisPlusConfig.java @@ -0,0 +1,24 @@ +package com.ykMap.base.config; + +/** + * mybatis-plus分页查询 + * + * @author wu + * @since 2025/3/19 16:55 + */ + +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class MyBatisPlusConfig { + + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); + return interceptor; + } +} \ No newline at end of file diff --git a/src/main/java/com/ykMap/controller/CarController.java b/src/main/java/com/ykMap/controller/CarController.java new file mode 100644 index 0000000..be96885 --- /dev/null +++ b/src/main/java/com/ykMap/controller/CarController.java @@ -0,0 +1,42 @@ +package com.ykMap.controller; + +import com.ykMap.base.controller.BaseController; +import com.ykMap.base.domain.AjaxResult; +import com.ykMap.entity.request.CarPageRequest; +import com.ykMap.entity.response.CarPageResponse; +import com.ykMap.service.CarService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 车辆实时定位 + * + * @author wu + * @since 2025/3/12 10:22 + */ +@RestController +@RequestMapping("/ykmap/car") +@Api(tags = "车辆实时定位接口") +public class CarController extends BaseController { + + @Resource + private CarService carService; + + /** + * 分页查询单位内外的车辆任务 + * + * @param req 请求类 + * @return 响应类 + */ + @GetMapping("page") + @ApiOperation(value = "分页查询单位内外的车辆任务", response = CarPageResponse.class) + public AjaxResult page( @Valid CarPageRequest req) { + return success(carService.page(req)); + } +} diff --git a/src/main/java/com/ykMap/entity/ColDTO.java b/src/main/java/com/ykMap/entity/ColDTO.java new file mode 100644 index 0000000..a233711 --- /dev/null +++ b/src/main/java/com/ykMap/entity/ColDTO.java @@ -0,0 +1,19 @@ +package com.ykMap.entity; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author wu + * @since 2025/3/19 17:04 + */ +@Data +public class ColDTO implements Serializable { + private static final long serialVersionUID = -8045055883099483791L; + + private String value; + + private String label; + +} diff --git a/src/main/java/com/ykMap/entity/request/CarPageRequest.java b/src/main/java/com/ykMap/entity/request/CarPageRequest.java new file mode 100644 index 0000000..bcb9d4f --- /dev/null +++ b/src/main/java/com/ykMap/entity/request/CarPageRequest.java @@ -0,0 +1,44 @@ +package com.ykMap.entity.request; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.io.Serializable; + +/** + * 分页查询单位内外的车辆任务请求类 + * + * @author wu + * @since 2025/3/14 14:22 + */ +@Data +@ApiModel("分页查询单位内外的车辆任务请求类") +public class CarPageRequest implements Serializable { + private static final long serialVersionUID = 1031466955513130671L; + /** + * 当前页 + */ + @ApiModelProperty(value = "当前页 默认1") + public Integer pageNo = 1; + + /** + * 每页显示条数 + */ + @ApiModelProperty(value = "每页显示条数 默认10") + public Integer pageSize = 10; + + /** + * 距离单位距离 + */ + @ApiModelProperty(value = "距离单位距离(米) 默认200米") + public double distance = 200; + + /** + * 单位内外 1单位外 2单位内 + */ + @ApiModelProperty(value = "单位内外 1单位外 2单位内", required = true) + @NotNull(message = "单位内外不能为空") + private Integer type; +} diff --git a/src/main/java/com/ykMap/entity/response/CarGPSResponse.java b/src/main/java/com/ykMap/entity/response/CarGPSResponse.java new file mode 100644 index 0000000..2327706 --- /dev/null +++ b/src/main/java/com/ykMap/entity/response/CarGPSResponse.java @@ -0,0 +1,31 @@ +package com.ykMap.entity.response; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 车辆实时数据 + * + * @author wu + * @since 2025/3/14 15:02 + */ +@Data +public class CarGPSResponse implements Serializable { + private static final long serialVersionUID = 6524106295010311569L; + + /** + * 车牌号 + */ + public String carPlate; + + /** + * 84坐标系经度 + */ + public String lat; + + /** + * 84坐标系纬度 + */ + public String lng; +} diff --git a/src/main/java/com/ykMap/entity/response/CarPageResponse.java b/src/main/java/com/ykMap/entity/response/CarPageResponse.java new file mode 100644 index 0000000..748cd0d --- /dev/null +++ b/src/main/java/com/ykMap/entity/response/CarPageResponse.java @@ -0,0 +1,30 @@ +package com.ykMap.entity.response; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * 分页查询单位内外的车辆任务响应类 + * + * @author wu + * @since 2025/3/14 14:32 + */ +@Data +@ApiModel("分页查询单位内外的车辆任务响应类") +public class CarPageResponse implements Serializable { + + /** + * 车牌号 + */ + @ApiModelProperty(value = "车牌号") + public String carNumber; + + /** + * 车辆关联任务 + */ + @ApiModelProperty(value = "车辆关联任务") + public String taskTitle; +} diff --git a/src/main/java/com/ykMap/entity/response/CarResponse.java b/src/main/java/com/ykMap/entity/response/CarResponse.java new file mode 100644 index 0000000..adbcfec --- /dev/null +++ b/src/main/java/com/ykMap/entity/response/CarResponse.java @@ -0,0 +1,30 @@ +package com.ykMap.entity.response; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * 分页查询单位内外的车辆任务响应类 + * + * @author wu + * @since 2025/3/14 14:32 + */ +@Data +@ApiModel("分页查询单位内外的车辆任务响应类") +public class CarResponse implements Serializable { + + /** + * 车牌号 + */ + @ApiModelProperty(value = "车牌号") + public String carNumber; + + /** + * 车辆关联任务 + */ + @ApiModelProperty(value = "车辆关联任务") + public String taskTitle; +} diff --git a/src/main/java/com/ykMap/entity/response/ContentResponse.java b/src/main/java/com/ykMap/entity/response/ContentResponse.java new file mode 100644 index 0000000..d050992 --- /dev/null +++ b/src/main/java/com/ykMap/entity/response/ContentResponse.java @@ -0,0 +1,24 @@ +package com.ykMap.entity.response; + +import com.ykMap.entity.ColDTO; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * @author wu + * @since 2025/3/19 17:02 + */ +@Data +public class ContentResponse implements Serializable { + private static final long serialVersionUID = -8078281805074879229L; + + private List col; + + private List data; + + private Long totalCount = 0L; + private Long pageNum = 1L; + private Long pageSize = 10L; +} diff --git a/src/main/java/com/ykMap/exception/GlobalExceptionHandler.java b/src/main/java/com/ykMap/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000..46f31c6 --- /dev/null +++ b/src/main/java/com/ykMap/exception/GlobalExceptionHandler.java @@ -0,0 +1,110 @@ +package com.ykMap.exception; + +import com.ykMap.base.domain.AjaxResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.validation.BindException; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.MissingPathVariableException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; + +import javax.servlet.http.HttpServletRequest; +import java.util.Objects; + +/** + * 全局异常处理器 + * + * @author wu + * @since 2025/3/13 17:28 + */ +@RestControllerAdvice +public class GlobalExceptionHandler { + private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class); + + + /** + * 请求方式不支持 + */ + @ExceptionHandler(HttpRequestMethodNotSupportedException.class) + public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, + HttpServletRequest request) { + String requestURI = request.getRequestURI(); + log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod()); + return AjaxResult.error(e.getMessage()); + } + + /** + * 业务异常 + */ + @ExceptionHandler(ServiceException.class) + public AjaxResult handleServiceException(ServiceException e) { + log.error(e.getMessage(), e); + Integer code = e.getCode(); + return code != null ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage()); + } + + /** + * 请求路径中缺少必需的路径变量 + */ + @ExceptionHandler(MissingPathVariableException.class) + public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request) { + String requestURI = request.getRequestURI(); + log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e); + return AjaxResult.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName())); + } + + /** + * 请求参数类型不匹配 + */ + @ExceptionHandler(MethodArgumentTypeMismatchException.class) + public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request) { + String requestURI = request.getRequestURI(); + log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e); + return AjaxResult.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", + e.getName(), Objects.requireNonNull(e.getRequiredType()).getName(), e.getValue())); + } + + /** + * 拦截未知的运行时异常 + */ + @ExceptionHandler(RuntimeException.class) + public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request) { + String requestURI = request.getRequestURI(); + log.error("请求地址'{}',发生未知异常.", requestURI, e); + return AjaxResult.error(e.getMessage()); + } + + /** + * 系统异常 + */ + @ExceptionHandler(Exception.class) + public AjaxResult handleException(Exception e, HttpServletRequest request) { + String requestURI = request.getRequestURI(); + log.error("请求地址'{}',发生系统异常.", requestURI, e); + return AjaxResult.error(e.getMessage()); + } + + /** + * 自定义验证异常 + */ + @ExceptionHandler(BindException.class) + public AjaxResult handleBindException(BindException e) { + log.error(e.getMessage(), e); + String message = e.getAllErrors().get(0).getDefaultMessage(); + return AjaxResult.error(message); + } + + /** + * 自定义验证异常 + */ + @ExceptionHandler(MethodArgumentNotValidException.class) + public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { + log.error(e.getMessage(), e); + String message = Objects.requireNonNull(e.getBindingResult().getFieldError()).getDefaultMessage(); + return AjaxResult.error(message); + } + +} diff --git a/src/main/java/com/ykMap/exception/ServiceException.java b/src/main/java/com/ykMap/exception/ServiceException.java new file mode 100644 index 0000000..792df5e --- /dev/null +++ b/src/main/java/com/ykMap/exception/ServiceException.java @@ -0,0 +1,64 @@ +package com.ykMap.exception; + +/** + * 业务异常 + * + * @author wu + * @since 2025/3/13 17:28 + */ +public final class ServiceException extends RuntimeException { + private static final long serialVersionUID = 1L; + + /** + * 错误码 + */ + private Integer code; + + /** + * 错误提示 + */ + private String message; + + /** + * 错误明细,内部调试错误 + */ + private String detailMessage; + + /** + * 空构造方法,避免反序列化问题 + */ + public ServiceException() { + } + + public ServiceException(String message) { + this.message = message; + } + + public ServiceException(String message, Integer code) { + this.message = message; + this.code = code; + } + + public String getDetailMessage() { + return detailMessage; + } + + public ServiceException setDetailMessage(String detailMessage) { + this.detailMessage = detailMessage; + return this; + } + + @Override + public String getMessage() { + return message; + } + + public ServiceException setMessage(String message) { + this.message = message; + return this; + } + + public Integer getCode() { + return code; + } +} \ No newline at end of file diff --git a/src/main/java/com/ykMap/mapper/LineMapper.java b/src/main/java/com/ykMap/mapper/LineMapper.java index c5730f9..464d53f 100644 --- a/src/main/java/com/ykMap/mapper/LineMapper.java +++ b/src/main/java/com/ykMap/mapper/LineMapper.java @@ -65,4 +65,10 @@ public interface LineMapper{ * @return 创建时间 */ LocalDateTime findLineTemplateTime(); + + /** + * 获取最新数据的创建时间 + * @return 创建时间 + */ + LocalDateTime findCityTime(); } diff --git a/src/main/java/com/ykMap/mapper/TaskMissionMapper.java b/src/main/java/com/ykMap/mapper/TaskMissionMapper.java index 69515a7..52bf802 100644 --- a/src/main/java/com/ykMap/mapper/TaskMissionMapper.java +++ b/src/main/java/com/ykMap/mapper/TaskMissionMapper.java @@ -1,7 +1,9 @@ package com.ykMap.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ykMap.entity.TaskMission; +import com.ykMap.entity.response.CarPageResponse; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -29,5 +31,14 @@ public interface TaskMissionMapper extends BaseMapper { * @return 响应类 */ List findByPlateNums(@Param("array") String[] arr); + + /** + * 根据车牌号分页查询车辆任务 + * + * @param page 分页条件 + * @param list 车牌号集合 + * @return 响应类 + */ + Page pageByPlateNums(Page page, @Param("list") List list); } diff --git a/src/main/java/com/ykMap/service/CarService.java b/src/main/java/com/ykMap/service/CarService.java new file mode 100644 index 0000000..a5c0ebe --- /dev/null +++ b/src/main/java/com/ykMap/service/CarService.java @@ -0,0 +1,21 @@ +package com.ykMap.service; + +import com.ykMap.entity.request.CarPageRequest; +import com.ykMap.entity.response.ContentResponse; + +/** + * 车辆实时定位业务层 + * + * @author wu + * @since 2025/3/13 17:28 + */ +public interface CarService { + + /** + * 分页查询单位内外的车辆任务 + * + * @param req 请求类 + * @return 响应类 + */ + ContentResponse page(CarPageRequest req); +} diff --git a/src/main/java/com/ykMap/service/TaskMissionService.java b/src/main/java/com/ykMap/service/TaskMissionService.java index 3b34bb5..42984ea 100644 --- a/src/main/java/com/ykMap/service/TaskMissionService.java +++ b/src/main/java/com/ykMap/service/TaskMissionService.java @@ -1,7 +1,9 @@ package com.ykMap.service; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.ykMap.entity.TaskMission; +import com.ykMap.entity.response.CarPageResponse; import java.util.List; @@ -29,5 +31,14 @@ public interface TaskMissionService extends IService { * @return 响应类 */ List findByPlateNums(String plateNum); + + /** + * 根据车牌号分页查询车辆任务 + * + * @param page 分页条件 + * @param plateNums 车牌号集合 + * @return 响应类 + */ + Page pageByPlateNums(Page page, List plateNums); } diff --git a/src/main/java/com/ykMap/service/impl/CarServiceImpl.java b/src/main/java/com/ykMap/service/impl/CarServiceImpl.java new file mode 100644 index 0000000..e4c55b0 --- /dev/null +++ b/src/main/java/com/ykMap/service/impl/CarServiceImpl.java @@ -0,0 +1,155 @@ +package com.ykMap.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.json.JSONUtil; +import com.alibaba.fastjson2.JSONObject; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ykMap.entity.ColDTO; +import com.ykMap.entity.request.CarPageRequest; +import com.ykMap.entity.response.CarGPSResponse; +import com.ykMap.entity.response.CarPageResponse; +import com.ykMap.entity.response.ContentResponse; +import com.ykMap.exception.ServiceException; +import com.ykMap.service.CarService; +import com.ykMap.service.TaskMissionService; +import com.ykMap.utils.SpaceUtils; +import lombok.extern.slf4j.Slf4j; +import org.gavaghan.geodesy.GlobalCoordinates; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 车辆实时定位实现层 + * + * @author wu + * @since 2025/3/13 17:28 + */ +@Service("CarService") +@Slf4j +public class CarServiceImpl implements CarService { + + @Resource + private TaskMissionService taskMissionService; + + + /** + * 分页查询单位内外的车辆任务 + * + * @param req 请求类 + * @return 响应类 + */ + @Override + public ContentResponse page(CarPageRequest req) { + // 查询sessionId + String sessionId = findSessionId(); + // 获取车辆实时定位 + List carGPSList = findCarGPS(sessionId); + GlobalCoordinates companyLocation = new GlobalCoordinates(31.226963,120.634355); + // 过滤后的车辆 + List list = new ArrayList<>(); + if (CollectionUtil.isEmpty(carGPSList)) { + return null; + } + for (CarGPSResponse res : carGPSList) { + GlobalCoordinates carLocation = new GlobalCoordinates(Double.parseDouble(res.getLat()), Double.parseDouble(res.getLng())); + double distanceMeter = SpaceUtils.getDistanceMeter(companyLocation, carLocation); + if (req.getType() == 1) { + if (NumberUtil.compare(req.getDistance(), distanceMeter) != 1) { + // 单位外 + list.add(res); + } + } else { + if (NumberUtil.compare(req.getDistance(), distanceMeter) == 1) { + // 单位内 + list.add(res); + } + } + } + if (CollectionUtil.isEmpty(list)) { + return null; + } + List plateNums = list.stream().map(CarGPSResponse::getCarPlate).collect(Collectors.toList()); + Page page = new Page<>(); + page.setCurrent(req.getPageNo()); + page.setSize(req.getPageSize()); + Page carPageResponsePage = taskMissionService.pageByPlateNums(page, plateNums); + ContentResponse contentResponse = new ContentResponse(); + contentResponse.setTotalCount(carPageResponsePage.getTotal()); + contentResponse.setPageNum(carPageResponsePage.getCurrent()); + contentResponse.setPageSize(carPageResponsePage.getSize()); + ArrayList colDTOS = new ArrayList<>(); + ColDTO colDTO = new ColDTO(); + colDTO.setValue("carNumber"); + colDTO.setLabel("车辆号码"); + ColDTO colDTO2 = new ColDTO(); + colDTO2.setValue("Title"); + colDTO2.setLabel("任务名称"); + colDTOS.add(colDTO); + colDTOS.add(colDTO2); + contentResponse.setCol(colDTOS); + contentResponse.setData(carPageResponsePage.getRecords()); + return contentResponse; + } + + /** + * 获取sessionId + * + * @return sessionId + */ + private String findSessionId() { + String body = HttpRequest.get("http://192.168.0.91/gps-web/api/login.jsp") + .form("userId", 99999) + .form("password", "6d0fd76ab81325588d8065ec1036fdd3") + .form("loginType", "user") + .execute().body(); + JSONObject json; + log.info("================获取sessionId数据================="); + log.info(body); + try { + json = JSONObject.parse(body); + } catch (Exception e) { + log.error(e.getMessage()); + throw new ServiceException("未获取到sessionId"); + } + return json.get("sessionId").toString(); + } + + /** + * 获取车辆实时定位 + * + * @return 车辆实时数据 + */ + private List findCarGPS(String sessionId) { + String body = HttpRequest.get("http://192.168.0.91/gps-web/api/get_gps_r.jsp") + .form("teamId", 2) + .form("sessionId", sessionId) + .execute().body(); + JSONObject json; + log.info("================获取车辆实时定位数据================="); + log.info(body); + try { + json = JSONObject.parse(body); + } catch (Exception e) { + log.error(e.getMessage()); + throw new ServiceException("获取车辆实时定位失败"); + } + List list = Collections.emptyList(); + Object listStr = json.get("list"); + String recordsStr = JSONUtil.toJsonStr(listStr); + if (StrUtil.isNotEmpty(recordsStr)) { + // 获取所有车辆经纬度 + list = JSONUtil.toList(recordsStr, CarGPSResponse.class); + + } + return list; + } + +} diff --git a/src/main/java/com/ykMap/service/impl/LineServiceImpl.java b/src/main/java/com/ykMap/service/impl/LineServiceImpl.java index 9d64cfb..2b82277 100644 --- a/src/main/java/com/ykMap/service/impl/LineServiceImpl.java +++ b/src/main/java/com/ykMap/service/impl/LineServiceImpl.java @@ -99,16 +99,26 @@ public class LineServiceImpl implements LineService { */ @Override public List searchCity() { - LocalDate now = LocalDate.now(); - if (now.getDayOfMonth() < 26) { - LocalDate a1 = now.minusMonths(2).withDayOfMonth(26); - LocalDate a2 = now.minusMonths(1).withDayOfMonth(25); - return lineMapper.searchCity(a1, a2); - } else { - LocalDate a1 = now.minusMonths(1).withDayOfMonth(26); - LocalDate a2 = now.withDayOfMonth(25); - return lineMapper.searchCity(a1, a2); +// LocalDate now = LocalDate.now(); +// if (now.getDayOfMonth() < 26) { +// LocalDate a1 = now.minusMonths(2).withDayOfMonth(26); +// LocalDate a2 = now.minusMonths(1).withDayOfMonth(25); +// return lineMapper.searchCity(a1, a2); +// } else { +// LocalDate a1 = now.minusMonths(1).withDayOfMonth(26); +// LocalDate a2 = now.withDayOfMonth(25); +// return lineMapper.searchCity(a1, a2); +// } + // 查询数据库最新时间 + LocalDateTime dataTime = lineMapper.findCityTime(); + if (dataTime == null) { + return null; } + // 获取数据库最新时间月份的第一天 + LocalDate firstDayOfMonth = dataTime.with(TemporalAdjusters.firstDayOfMonth()).toLocalDate(); + // 获取数据库最新时间月份的最后一天 + LocalDate lastDayOfMonth = dataTime.with(TemporalAdjusters.lastDayOfMonth()).toLocalDate(); + return lineMapper.searchCity(firstDayOfMonth, lastDayOfMonth); } /** @@ -116,16 +126,26 @@ public class LineServiceImpl implements LineService { */ @Override public SearchCityCountResponse searchCityCount() { - LocalDate now = LocalDate.now(); - if (now.getDayOfMonth() < 26) { - LocalDate a1 = now.minusMonths(2).withDayOfMonth(26); - LocalDate a2 = now.minusMonths(1).withDayOfMonth(25); - return lineMapper.searchCityCount(a1, a2); - } else { - LocalDate a1 = now.minusMonths(1).withDayOfMonth(26); - LocalDate a2 = now.withDayOfMonth(25); - return lineMapper.searchCityCount(a1, a2); +// LocalDate now = LocalDate.now(); +// if (now.getDayOfMonth() < 26) { +// LocalDate a1 = now.minusMonths(2).withDayOfMonth(26); +// LocalDate a2 = now.minusMonths(1).withDayOfMonth(25); +// return lineMapper.searchCityCount(a1, a2); +// } else { +// LocalDate a1 = now.minusMonths(1).withDayOfMonth(26); +// LocalDate a2 = now.withDayOfMonth(25); +// return lineMapper.searchCityCount(a1, a2); +// } + // 查询数据库最新时间 + LocalDateTime dataTime = lineMapper.findCityTime(); + if (dataTime == null) { + return null; } + // 获取数据库最新时间月份的第一天 + LocalDate firstDayOfMonth = dataTime.with(TemporalAdjusters.firstDayOfMonth()).toLocalDate(); + // 获取数据库最新时间月份的最后一天 + LocalDate lastDayOfMonth = dataTime.with(TemporalAdjusters.lastDayOfMonth()).toLocalDate(); + return lineMapper.searchCityCount(firstDayOfMonth, lastDayOfMonth); } /** diff --git a/src/main/java/com/ykMap/service/impl/TaskMissionServiceImpl.java b/src/main/java/com/ykMap/service/impl/TaskMissionServiceImpl.java index dde31d7..825de1a 100644 --- a/src/main/java/com/ykMap/service/impl/TaskMissionServiceImpl.java +++ b/src/main/java/com/ykMap/service/impl/TaskMissionServiceImpl.java @@ -1,7 +1,9 @@ package com.ykMap.service.impl; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ykMap.entity.TaskMission; +import com.ykMap.entity.response.CarPageResponse; import com.ykMap.mapper.TaskMissionMapper; import com.ykMap.service.TaskMissionService; import org.springframework.stereotype.Service; @@ -44,5 +46,17 @@ public class TaskMissionServiceImpl extends ServiceImpl pageByPlateNums(Page page, List plateNums) { + return baseMapper.pageByPlateNums(page,plateNums); + } } diff --git a/src/main/java/com/ykMap/utils/SpaceUtils.java b/src/main/java/com/ykMap/utils/SpaceUtils.java new file mode 100644 index 0000000..10e0df2 --- /dev/null +++ b/src/main/java/com/ykMap/utils/SpaceUtils.java @@ -0,0 +1,30 @@ +package com.ykMap.utils; + +import org.gavaghan.geodesy.Ellipsoid; +import org.gavaghan.geodesy.GeodeticCalculator; +import org.gavaghan.geodesy.GeodeticCurve; +import org.gavaghan.geodesy.GlobalCoordinates; + +/** + * 空间坐标计算工具类 + * + * @author wu + * @since 2025/3/14 15:12 + */ +public class SpaceUtils { + + /** + * 根据两个经纬度计算距离(米) + * + * @param point1 经纬度1 + * @param point2 经纬度2 + * @return 距离(米) + */ + public static double getDistanceMeter(GlobalCoordinates point1, GlobalCoordinates point2) { + GeodeticCalculator calc = new GeodeticCalculator(); + Ellipsoid ellipsoid = Ellipsoid.WGS84; // 使用 WGS84 椭球模型 + GeodeticCurve geoCurve = calc.calculateGeodeticCurve(ellipsoid, point1, point2); + return geoCurve.getEllipsoidalDistance(); + } + +} diff --git a/src/main/resources/com/ykMap/mapper/LineMapper.xml b/src/main/resources/com/ykMap/mapper/LineMapper.xml index e0354fa..bd7c063 100644 --- a/src/main/resources/com/ykMap/mapper/LineMapper.xml +++ b/src/main/resources/com/ykMap/mapper/LineMapper.xml @@ -75,4 +75,13 @@ limit 1 + + diff --git a/src/main/resources/com/ykMap/mapper/TaskMissionMapper.xml b/src/main/resources/com/ykMap/mapper/TaskMissionMapper.xml index 7346379..036e4bc 100644 --- a/src/main/resources/com/ykMap/mapper/TaskMissionMapper.xml +++ b/src/main/resources/com/ykMap/mapper/TaskMissionMapper.xml @@ -32,4 +32,24 @@ ORDER BY tm.update_time DESC; + + + +