邮编查询

pull/2/head
chaiyapeng 2024-08-25 11:10:35 +08:00
parent 2bab7b1fbe
commit 56c5bb26fd
9 changed files with 54 additions and 5 deletions

View File

@ -0,0 +1,22 @@
package com.muyu.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Authorchaiyapeng
* @Packagecom.muyu.domain
* @Projectcloud-mart
* @namePostcode
* @Date2024/8/25 11:04
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Postcode {
private String postcode;
private Integer page;
private Integer pagesize;
private String dtype;
}

View File

@ -9,6 +9,7 @@ import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.domain.Birthday;
import com.muyu.domain.Market;
import com.muyu.domain.Postcode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
@ -80,5 +81,12 @@ public class MarketController extends BaseController {
public Result getBirthday(@RequestBody Birthday birthday){
return marketService.getBirthday(birthday);
}
/**
*
*/
@PostMapping("getPostcode")
public Result getPostcode(@RequestBody Postcode postcode){
return marketService.getPostcode(postcode);
}
}

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.common.core.domain.Result;
import com.muyu.domain.Birthday;
import com.muyu.domain.Market;
import com.muyu.domain.Postcode;
import java.util.List;
@ -26,4 +27,6 @@ public interface MarketService extends IService<Market> {
Result getWeather();
Result getBirthday(Birthday birthday);
Result getPostcode(Postcode postcode);
}

View File

@ -10,6 +10,7 @@ import com.muyu.common.core.domain.Result;
import com.muyu.domain.Birthday;
import com.muyu.domain.Market;
import com.muyu.domain.PhonePlace;
import com.muyu.domain.Postcode;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
@ -106,4 +107,12 @@ public class MarketServiceImpl extends ServiceImpl<MarketMapper, Market> impleme
StringBuffer stringBuffer = BirthdayHelper.queryBirthday(birthday);
return Result.success(stringBuffer);
}
/**
*
*/
@Override
public Result getPostcode(Postcode postcode) {
StringBuffer stringBuffer = PostcodeInquire.queryPostcode(postcode);
return Result.success(stringBuffer);
}
}

View File

@ -17,6 +17,7 @@ import java.util.stream.Collectors;
* @Projectcloud-mart
* @nameBirthdayHelper
* @Date2024/8/24 19:36
*
*/
public class BirthdayHelper {

View File

@ -15,6 +15,7 @@ import static com.muyu.cloud.mart.config.IPLocation.params;
* @Projectcloud-mart
* @nameHeadlines
* @Date2024/8/24 18:39
*
*/
public class Headlines {

View File

@ -15,6 +15,7 @@ import java.util.stream.Collectors;
* @Projectcloud-mart
* @nameIPLocation
* @Date2024/8/23 20:54
* IP
*/
public class IPLocation {
public static StringBuffer queryIPLocation(String ip){

View File

@ -1,5 +1,7 @@
package com.muyu.cloud.mart.utils;
import com.muyu.domain.Postcode;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
@ -18,16 +20,17 @@ import java.util.stream.Collectors;
*/
public class PostcodeInquire {
public static StringBuffer queryPostcode(){
public static StringBuffer queryPostcode(Postcode postcode){
String apiKey = "0cabcd31c150369d8afb2c8b7e41a2c0";
String apiUrl = "http://v.juhe.cn/postcode/query";
HashMap<String, String> map = new HashMap<>();
map.put("key", apiKey);
map.put("postcode", "xxx");
map.put("page", "20");
map.put("pagesize", "");
map.put("dtype", "json");
map.put("postcode", postcode.getPostcode());//邮编215001
postcode.setPostcode(map.put("postcode", postcode.getPostcode()));
map.put("page", String.valueOf(postcode.getPage()));//页数默认1
map.put("pagesize", "");//每页返回,默认:20,最大不超过50
map.put("dtype", "json");//返回数据的格式,xml或json默认json
try {
URL url = new URL(String.format(apiUrl + "?" + params(map)));
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));

View File

@ -16,6 +16,7 @@ import java.util.stream.Collectors;
* @Projectcloud-mart
* @nameWeather
* @Date2024/8/24 18:51
*
*/
public class Weather {
public static StringBuffer queryWeather() {