diff --git a/gather-app/src/main/java/com/ruoyi/database/controller/BaseCustomerInfoController.java b/gather-app/src/main/java/com/ruoyi/database/controller/BaseCustomerInfoController.java index 1530e81..c5b49b8 100644 --- a/gather-app/src/main/java/com/ruoyi/database/controller/BaseCustomerInfoController.java +++ b/gather-app/src/main/java/com/ruoyi/database/controller/BaseCustomerInfoController.java @@ -24,7 +24,7 @@ public class BaseCustomerInfoController extends BaseController { private final BaseCustomerInfoService baseCustomerInfoService; @GetMapping - @ApiOperation("查询客户管理表") + @ApiOperation("查询客户管理") public TableDataInfo list(BaseCustomerInfo baseCustomerInfo) { startPage(); QueryWrapper queryWrapper = new QueryWrapper<>(baseCustomerInfo); @@ -34,21 +34,21 @@ public class BaseCustomerInfoController extends BaseController { } @PostMapping - @ApiOperation("新增客户管理表") + @ApiOperation("新增客户管理") @Log(title = "客户管理表", businessType = BusinessType.INSERT) public AjaxResult insert(@RequestBody BaseCustomerInfo baseCustomerInfo) { return toAjax(baseCustomerInfoService.save(baseCustomerInfo)); } @PutMapping - @ApiOperation("修改客户管理表") + @ApiOperation("修改客户管理") @Log(title = "客户管理表", businessType = BusinessType.UPDATE) public AjaxResult update(@RequestBody BaseCustomerInfo baseCustomerInfo) { return toAjax(baseCustomerInfoService.updateById(baseCustomerInfo)); } @DeleteMapping - @ApiOperation("删除客户管理表") + @ApiOperation("删除客户管理") @Log(title = "客户管理表", businessType = BusinessType.DELETE) public AjaxResult delete(@RequestParam("idList") List idList) { return toAjax(baseCustomerInfoService.removeByIds(idList)); diff --git a/gather-app/src/main/java/com/ruoyi/database/controller/BaseParkingLotInfoController.java b/gather-app/src/main/java/com/ruoyi/database/controller/BaseParkingLotInfoController.java index e0f679d..5f62776 100644 --- a/gather-app/src/main/java/com/ruoyi/database/controller/BaseParkingLotInfoController.java +++ b/gather-app/src/main/java/com/ruoyi/database/controller/BaseParkingLotInfoController.java @@ -24,7 +24,7 @@ public class BaseParkingLotInfoController extends BaseController { private final BaseParkingLotInfoService baseParkingLotInfoService; @GetMapping - @ApiOperation("查询停车场管理表") + @ApiOperation("查询停车场管理") public TableDataInfo list(BaseParkingLotInfo baseParkingLotInfo) { startPage(); QueryWrapper queryWrapper = new QueryWrapper<>(baseParkingLotInfo); @@ -34,21 +34,21 @@ public class BaseParkingLotInfoController extends BaseController { } @PostMapping - @ApiOperation("新增停车场管理表") + @ApiOperation("新增停车场管理") @Log(title = "停车场管理表", businessType = BusinessType.INSERT) public AjaxResult insert(@RequestBody BaseParkingLotInfo baseParkingLotInfo) { return toAjax(baseParkingLotInfoService.save(baseParkingLotInfo)); } @PutMapping - @ApiOperation("修改停车场管理表") + @ApiOperation("修改停车场管理") @Log(title = "停车场管理表", businessType = BusinessType.UPDATE) public AjaxResult update(@RequestBody BaseParkingLotInfo baseParkingLotInfo) { return toAjax(baseParkingLotInfoService.updateById(baseParkingLotInfo)); } @DeleteMapping - @ApiOperation("删除停车场管理表") + @ApiOperation("删除停车场管理") @Log(title = "停车场管理表", businessType = BusinessType.DELETE) public AjaxResult delete(@RequestParam("idList") List idList) { return toAjax(baseParkingLotInfoService.removeByIds(idList)); diff --git a/gather-app/src/main/java/com/ruoyi/database/util/AmapGeocoding.java b/gather-app/src/main/java/com/ruoyi/database/util/AmapGeocoding.java new file mode 100644 index 0000000..d3d6e32 --- /dev/null +++ b/gather-app/src/main/java/com/ruoyi/database/util/AmapGeocoding.java @@ -0,0 +1,77 @@ +package com.ruoyi.database.util; + +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +public class AmapGeocoding { + + + public static String apiKey = "4cc27f0dbf3ebb77a3cf219866b405ad"; + + + public static String getLocation(String address){ + // 对地址进行URL编码,处理特殊字符 + String encodedAddress = java.net.URLEncoder.encode(address); + // 构建请求URL + String urlStr = "https://restapi.amap.com/v3/geocode/geo?key=" + apiKey + + "&address=" + encodedAddress + "&output=json"; + try { + // 创建URL对象并建立连接 + URL url = new URL(urlStr); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + + // 读取API返回的响应 + BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String inputLine; + StringBuffer response = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + + // 将响应转换为JSON对象便于解析 + JSONObject jsonResponse = new JSONObject(response.toString()); + + // 检查API请求状态 + if ("1".equals(jsonResponse.getStr("status"))) { + // 获取地理编码数组 + JSONArray geocodes = jsonResponse.getJSONArray("geocodes"); + if (geocodes.size() > 0) { + // 从第一个结果中获取经纬度 + String location = geocodes.getJSONObject(0).getStr("location"); + System.out.println("该地址的经纬度为: " + location); // 输出示例: "116.480881,39.989410" + // 如果需要单独使用经度和纬度 + String[] lngLat = location.split(","); + String longitude = lngLat[0]; // 经度 + String latitude = lngLat[1]; // 纬度 + System.out.println("经度: " + longitude + ", 纬度: " + latitude); + + return location; + } else { + System.out.println("未找到该地址对应的经纬度。"); + } + } else { + // 处理请求失败的情况 + String errorInfo = jsonResponse.getStr("info"); + System.err.println("地理编码请求失败: " + errorInfo); + } + + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + + public static void main(String[] args) { + String location = getLocation("常熟市海虞北路27号"); + System.out.println(location); + //120.754471,31.666573 + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java index 0d3f806..4efa5a7 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java @@ -7,6 +7,7 @@ import com.ruoyi.common.core.domain.entity.SysMenu; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginBody; import com.ruoyi.common.core.domain.model.LoginBodyByPhone; +import com.ruoyi.common.core.domain.model.LoginUserByPhone; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.database.domain.BaseCustomerInfo; import com.ruoyi.database.service.BaseCustomerInfoService; @@ -21,6 +22,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import java.util.List; import java.util.Set; @@ -100,6 +102,7 @@ public class SysLoginController { * * @return 用户信息 */ + @ApiOperation("获取管理员信息") @GetMapping("getInfo") public AjaxResult getInfo() { SysUser user = SecurityUtils.getLoginUser().getUser(); @@ -122,6 +125,23 @@ public class SysLoginController { return ajax; } + + @ApiOperation("获取客户信息") + @GetMapping("getCustomerInfo") + public AjaxResult getCustomerInfo(HttpServletRequest request) { + LoginUserByPhone loginUser = loginService.getLoginUserByPhone(request); + if (loginUser != null) { + BaseCustomerInfo one = baseCustomerInfoService.lambdaQuery() + .eq(BaseCustomerInfo::getPhone, loginUser.getPhone()) + .last("limit 1") + .one(); + return AjaxResult.success(one); + } + return AjaxResult.success(loginUser); + } + + + public static String truncateAndPad(String str) { if ("0".equals(StringKit.toString(str))) { return str; diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index f8f14a5..d8ea881 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -5,6 +5,7 @@ import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; +import com.ruoyi.common.core.domain.model.LoginUserByPhone; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.exception.user.*; @@ -27,6 +28,7 @@ import org.springframework.security.core.Authentication; import org.springframework.stereotype.Component; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; /** * 登录校验方法 @@ -148,6 +150,10 @@ public class SysLoginService { return tokenService.createTokenByPhone(phone); } + public LoginUserByPhone getLoginUserByPhone(HttpServletRequest request) { + return tokenService.getLoginUserByPhone(request); + } + /** * 校验验证码