手机号查询归属地
parent
1a778306d8
commit
3feffee3e8
|
@ -23,6 +23,19 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MybatisPlus代码自动生成器 -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>3.5.7</version>
|
||||
</dependency>
|
||||
<!-- 默认模板引擎 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<version>2.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ public class Market {
|
|||
private String name;
|
||||
private String cardno;
|
||||
private String descriot;
|
||||
private String ctfTp;
|
||||
private String ctfId;
|
||||
private String ctftp;
|
||||
private String ctfid;
|
||||
private String gender;
|
||||
private String birthday;
|
||||
private String address;
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.muyu.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @Author:chaiyapeng
|
||||
* @Package:com.muyu.domain
|
||||
* @Project:cloud-mart
|
||||
* @name:User
|
||||
* @Date:2024/8/22 15:26
|
||||
*/
|
||||
@Data
|
||||
public class User {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Integer userId;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String userName;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String userPwd;
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String userPhone;
|
||||
/**
|
||||
* 身份证
|
||||
*/
|
||||
private String userIdentityCard;
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String userMailbox;
|
||||
/**
|
||||
* 余额
|
||||
*/
|
||||
private BigDecimal userBalance;
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.muyu.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @Author:chaiyapeng
|
||||
* @Package:com.muyu.domain
|
||||
* @Project:cloud-mart
|
||||
* @name:UserSearch
|
||||
* @Date:2024/8/22 16:55
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UserSearch {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Integer userId;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String userName;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String userPwd;
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String userPhone;
|
||||
/**
|
||||
* 身份证
|
||||
*/
|
||||
private String userIdentityCard;
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String userMailbox;
|
||||
/**
|
||||
* 余额
|
||||
*/
|
||||
private BigDecimal userBalance;
|
||||
/**
|
||||
* 用户名查询
|
||||
*/
|
||||
private String blur;
|
||||
/**
|
||||
* 当前页
|
||||
*/
|
||||
private Integer pageSum;
|
||||
/**
|
||||
*每页显示的条数
|
||||
*/
|
||||
private Integer pageSize;
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.muyu.utli;
|
||||
|
||||
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.config.OutputFile;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
|
||||
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.Types;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @Author:chaiyapeng
|
||||
* @Package:com.muyu.utli
|
||||
* @Project:cloud-mart
|
||||
* @name:CodeGenerator
|
||||
* @Date:2024/8/22 14:39
|
||||
*/
|
||||
public class CodeGenerator {
|
||||
public static void main(String[] args) {
|
||||
FastAutoGenerator.create("jdbc:mysql://172.13.1.1:3306/datamart",
|
||||
"root", "root")
|
||||
.globalConfig(builder -> {
|
||||
builder.author("cyp") // 设置作者
|
||||
.enableSwagger() // 开启 swagger 模式
|
||||
.outputDir(System.getProperty("cloud-mart-server")+"/src/main/java"); // 指定输出目录
|
||||
})
|
||||
.dataSourceConfig(builder ->
|
||||
builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
|
||||
int typeCode = metaInfo.getJdbcType().TYPE_CODE;
|
||||
if (typeCode == Types.SMALLINT) {
|
||||
// 自定义类型转换
|
||||
return DbColumnType.INTEGER;
|
||||
}
|
||||
return typeRegistry.getColumnType(metaInfo);
|
||||
})
|
||||
)
|
||||
.packageConfig(builder ->
|
||||
builder.parent("com.muyu.cloud") // 设置父包名
|
||||
.moduleName("mart") // 设置父包模块名
|
||||
.serviceImpl("MarketServiceImpl")
|
||||
.pathInfo(Collections.singletonMap(OutputFile.xml, "D://")) // 设置mapperXml生成路径
|
||||
)
|
||||
.strategyConfig(builder ->
|
||||
builder.addInclude("market") // 设置需要生成的表名
|
||||
.addTablePrefix("t_", "c_") // 设置过滤表前缀
|
||||
)
|
||||
.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
|
||||
.execute();
|
||||
}
|
||||
}
|
|
@ -90,6 +90,30 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-mart-common</artifactId>
|
||||
</dependency>
|
||||
<!-- 手机号归属地-->
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>1.9.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sf.json-lib</groupId>
|
||||
<artifactId>json-lib</artifactId>
|
||||
<version>2.4</version>
|
||||
<classifier>jdk13</classifier>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.muyu</groupId>-->
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
package com.muyu.cloud.mart.config;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.muyu.domain.Market;
|
||||
import net.sf.json.JSONObject;
|
||||
/**
|
||||
* @Author:chaiyapeng
|
||||
* @Package:com.muyu.cloud.mart.config
|
||||
* @Project:cloud-mart
|
||||
* @name:JuheDemo
|
||||
* @Date:2024/8/22 22:03
|
||||
*/
|
||||
public class JuheDemo {
|
||||
public static final String DEF_CHATSET = "UTF-8";
|
||||
public static final int DEF_CONN_TIMEOUT = 30000;
|
||||
public static final int DEF_READ_TIMEOUT = 30000;
|
||||
public static String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";
|
||||
|
||||
public static void mobileQuery(Market market){
|
||||
String result =null;
|
||||
String url ="http://apis.juhe.cn/mobile/get";//请求接口地址
|
||||
Map params = new HashMap();//请求参数
|
||||
params.put("phone",market.getTel());//需要查询的手机号码
|
||||
params.put("key","8e5493da8edee8e42831574b9a2c3492");//应用APPKEY(应用详细页查询)
|
||||
try {
|
||||
result = net(url, params, "GET");
|
||||
JSONObject object = JSONObject.fromObject(result);
|
||||
if(object.getInt("error_code")==0){
|
||||
System.out.println(object.get("result"));
|
||||
}else{
|
||||
System.out.println(object.get("error_code")+":"+object.get("reason"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param strUrl 请求地址
|
||||
* @param params 请求参数
|
||||
* @param method 请求方法
|
||||
* @return 网络请求字符串
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String net(String strUrl, Map params,String method) throws Exception {
|
||||
HttpURLConnection conn = null;
|
||||
BufferedReader reader = null;
|
||||
String rs = null;
|
||||
try {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if(method==null || method.equals("GET")){
|
||||
strUrl = strUrl+"?"+urlencode(params);
|
||||
}
|
||||
URL url = new URL(strUrl);
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
if(method==null || method.equals("GET")){
|
||||
conn.setRequestMethod("GET");
|
||||
}else{
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setDoOutput(true);
|
||||
}
|
||||
conn.setRequestProperty("User-agent", userAgent);
|
||||
conn.setUseCaches(false);
|
||||
conn.setConnectTimeout(DEF_CONN_TIMEOUT);
|
||||
conn.setReadTimeout(DEF_READ_TIMEOUT);
|
||||
conn.setInstanceFollowRedirects(false);
|
||||
conn.connect();
|
||||
if (params!= null && method.equals("POST")) {
|
||||
try {
|
||||
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
|
||||
out.writeBytes(urlencode(params));
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
InputStream is = conn.getInputStream();
|
||||
reader = new BufferedReader(new InputStreamReader(is, DEF_CHATSET));
|
||||
String strRead = null;
|
||||
while ((strRead = reader.readLine()) != null) {
|
||||
sb.append(strRead);
|
||||
}
|
||||
rs = sb.toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
if (conn != null) {
|
||||
conn.disconnect();
|
||||
}
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
//将map型转为请求参数型
|
||||
public static String urlencode(Map<String,String> data) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Map.Entry i : data.entrySet()) {
|
||||
try {
|
||||
sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue()+"","UTF-8")).append("&");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,146 @@
|
|||
package com.muyu.cloud.mart.config;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MobileLocation {
|
||||
// 手机归属地查询接口地址
|
||||
// http://apis.juhe.cn/mobile/get http://127.0.0.1:8369/query?mobile
|
||||
public static String API_URL = "http://apis.juhe.cn/mobile/get";
|
||||
// 接口请求Key
|
||||
public static String API_KEY = "8e5493da8edee8e42831574b9a2c3492";
|
||||
|
||||
public static void main(String[] args) {
|
||||
String mobile = "15332689388";
|
||||
queryMobileLocation(mobile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据手机号码/手机号码前7位查询号码归属地
|
||||
* @param mobile
|
||||
*/
|
||||
public static void queryMobileLocation(String mobile)
|
||||
{
|
||||
Map<String, Object> params = new HashMap<>();//组合参数
|
||||
params.put("phone", mobile);
|
||||
params.put("key", API_KEY);
|
||||
String queryParams = urlencode(params);
|
||||
|
||||
String response = doGet(API_URL, queryParams);
|
||||
try {
|
||||
JSONObject jsonObject = JSONObject.fromObject(response);
|
||||
int error_code = jsonObject.getInt("error_code");
|
||||
if (error_code == 0) {
|
||||
System.out.println("调用接口成功");
|
||||
|
||||
JSONObject result = jsonObject.getJSONObject("result");
|
||||
|
||||
System.out.printf("省份:%s%n", result.getString("province"));
|
||||
System.out.printf("城市:%s%n", result.getString("city"));
|
||||
System.out.printf("区号:%s%n", result.getString("areacode"));
|
||||
System.out.printf("邮编:%s%n", result.getString("zip"));
|
||||
System.out.printf("运营商:%s%n", result.getString("company"));
|
||||
|
||||
} else {
|
||||
System.out.println("调用接口失败:" + jsonObject.getString("reason"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get方式的http请求
|
||||
*
|
||||
* @param httpUrl 请求地址
|
||||
* @return 返回结果
|
||||
*/
|
||||
public static String doGet(String httpUrl, String queryParams) {
|
||||
HttpURLConnection connection = null;
|
||||
InputStream inputStream = null;
|
||||
BufferedReader bufferedReader = null;
|
||||
String result = null;// 返回结果字符串
|
||||
try {
|
||||
// 创建远程url连接对象
|
||||
URL url = new URL(new StringBuffer(httpUrl).append("?").append(queryParams).toString());
|
||||
// 通过远程url连接对象打开一个连接,强转成httpURLConnection类
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
// 设置连接方式:get
|
||||
connection.setRequestMethod("GET");
|
||||
// 设置连接主机服务器的超时时间:15000毫秒
|
||||
connection.setConnectTimeout(5000);
|
||||
// 设置读取远程返回的数据时间:60000毫秒
|
||||
connection.setReadTimeout(6000);
|
||||
// 发送请求
|
||||
connection.connect();
|
||||
// 通过connection连接,获取输入流
|
||||
if (connection.getResponseCode() == 200) {
|
||||
inputStream = connection.getInputStream();
|
||||
// 封装输入流,并指定字符集
|
||||
bufferedReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
||||
// 存放数据
|
||||
StringBuilder sbf = new StringBuilder();
|
||||
String temp;
|
||||
while ((temp = bufferedReader.readLine()) != null) {
|
||||
sbf.append(temp);
|
||||
sbf.append(System.getProperty("line.separator"));
|
||||
}
|
||||
result = sbf.toString();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 关闭资源
|
||||
if (null != bufferedReader) {
|
||||
try {
|
||||
bufferedReader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (null != inputStream) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (connection != null) {
|
||||
connection.disconnect();// 关闭远程连接
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将map型转为请求参数型
|
||||
*
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public static String urlencode(Map<String, ?> data) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Map.Entry<String, ?> i : data.entrySet()) {
|
||||
try {
|
||||
sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue() + "", "UTF-8")).append("&");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
String result = sb.toString();
|
||||
result = result.substring(0, result.lastIndexOf("&"));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
//package com.muyu.cloud.mart.config;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.annotation.DbType;
|
||||
//import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
//import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
//import org.mybatis.spring.annotation.MapperScan;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//
|
||||
///**
|
||||
// * @Author:chaiyapeng
|
||||
// * @Package:com.muyu.cloud.mart.config
|
||||
// * @Project:cloud-mart
|
||||
// * @name:MybatisPlusConfig
|
||||
// * @Date:2024/8/22 16:59
|
||||
// */
|
||||
//@Configuration
|
||||
//@MapperScan("com.muyu.cloud.mart.mapper")
|
||||
//public class MybatisPlusConfig {
|
||||
// @Bean
|
||||
// public MybatisPlusInterceptor mybatisPlusInterceptor(){
|
||||
// MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
// interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
// return interceptor;
|
||||
// }
|
||||
//}
|
|
@ -1,6 +1,8 @@
|
|||
package com.muyu.cloud.mart.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.dtflys.forest.annotation.Post;
|
||||
|
||||
import com.muyu.cloud.mart.service.MarketService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
|
@ -9,10 +11,7 @@ import com.muyu.common.security.annotation.RequiresPermissions;
|
|||
import com.muyu.domain.Market;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
@ -37,8 +36,13 @@ public class MarketController extends BaseController {
|
|||
private RedisTemplate<String,String>redisTemplate;
|
||||
|
||||
// @RequiresPermissions("mart:info:list")
|
||||
|
||||
/**
|
||||
* 两千万条数据查询
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("findMarketList")
|
||||
public Result<TableDataInfo<Market>> findMarketList(Market market){
|
||||
public Result<TableDataInfo<Market>> findMarketList(){
|
||||
if (redisTemplate.hasKey("list")){
|
||||
List<String> list = redisTemplate.opsForList().range("list", 0, -1);
|
||||
ArrayList<Market> markets = new ArrayList<>();
|
||||
|
@ -50,53 +54,19 @@ public class MarketController extends BaseController {
|
|||
}
|
||||
|
||||
startPage();
|
||||
List<Market> list = marketService.findMarketList(market);
|
||||
List<Market> list = marketService.findMarketList();
|
||||
for (Market market1 : list) {
|
||||
redisTemplate.opsForList().rightPush("list", JSON.toJSONString(market1));
|
||||
}
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@GetMapping("selectMobileAddress")
|
||||
//查询手机号码所属地区
|
||||
public static String getMobileAddress(String mobile) throws Exception
|
||||
{
|
||||
String address = "";
|
||||
try
|
||||
{
|
||||
mobile = mobile.trim();
|
||||
if (mobile.matches("^(13|15|18)\\d{9}$") || mobile.matches("^(013|015|018)\\d{9}$")) //以13,15,18开头,后面九位全为数字
|
||||
{
|
||||
String url = "http://172.13.1.1:8080/datamart?action=mobile&mobile=" + mobile;
|
||||
URLConnection connection = (URLConnection) new URL(url).openConnection();
|
||||
connection.setDoOutput(true);
|
||||
InputStream os = connection.getInputStream();
|
||||
Thread.sleep(100);
|
||||
int length = os.available();
|
||||
byte[] buff = new byte[length];
|
||||
os.read(buff);
|
||||
String s = new String(buff, "gbk");
|
||||
int len = s.indexOf("卡号归属地");
|
||||
s = s.substring(len, len+100);
|
||||
len = s.lastIndexOf("</TD>");
|
||||
address = s.substring(0, len);
|
||||
len = address.lastIndexOf(">");
|
||||
address = address.substring(len+1, address.length());
|
||||
address = address.replace(" ", ",");
|
||||
address = address.replace("d> -->", "");
|
||||
address = address.replace(" -->", "");
|
||||
address = address.replace("-->", "");
|
||||
s = null;
|
||||
buff = null;
|
||||
os.close();
|
||||
connection = null;
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
address = "未知";
|
||||
System.out.println("手机所属地查询失败====================");
|
||||
}
|
||||
return address;
|
||||
/**
|
||||
* 手机号查询归属地
|
||||
*/
|
||||
|
||||
@PostMapping("getPhonePlace")
|
||||
public Result getPhonePlace(@RequestBody String tel){
|
||||
return marketService.getPhonePlace(tel);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package com.muyu.cloud.mart.controller;
|
||||
|
||||
import com.dtflys.forest.annotation.Post;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.muyu.cloud.mart.mapper.UserMapper;
|
||||
import com.muyu.cloud.mart.service.UserService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
import com.muyu.domain.User;
|
||||
import com.muyu.domain.UserSearch;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:chaiyapeng
|
||||
* @Package:com.muyu.cloud.mart.controller
|
||||
* @Project:cloud-mart
|
||||
* @name:UserController
|
||||
* @Date:2024/8/22 15:28
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("user")
|
||||
public class UserController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
/**
|
||||
* 查询所以用户信息
|
||||
*/
|
||||
@GetMapping("getAllUsers")
|
||||
public Result getAllUsers(){
|
||||
List<User> list = userService.getAllUsers();
|
||||
return Result.success(list);
|
||||
}
|
||||
/**
|
||||
* 添加新用户
|
||||
*/
|
||||
@PostMapping("/addUser")
|
||||
public Result addUser(@RequestBody User user){
|
||||
return userService.addUser(user);
|
||||
}
|
||||
/**
|
||||
* 更新用户
|
||||
*/
|
||||
@PostMapping("/updateUser")
|
||||
public Result updateUser(@RequestBody User user){
|
||||
return userService.updateUser(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*/
|
||||
@PostMapping("deleteUser")
|
||||
public Result deleteUser(@RequestBody User user){
|
||||
return userService.deleteUser(user);
|
||||
}
|
||||
/**
|
||||
* 多条件分页查询
|
||||
*/
|
||||
@PostMapping("getAllUserByCon")
|
||||
public Result getAllUserByCon(@RequestBody UserSearch userSearch){
|
||||
startPage();
|
||||
return userService.getAllUserByCon(userSearch);
|
||||
}
|
||||
}
|
|
@ -15,5 +15,5 @@ import java.util.List;
|
|||
*/
|
||||
@Mapper
|
||||
public interface MarketMapper extends BaseMapper<Market> {
|
||||
List<Market> mybatisplus(Market market);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.cloud.mart.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.domain.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Author:chaiyapeng
|
||||
* @Package:com.muyu.cloud.mart.mapper
|
||||
* @Project:cloud-mart
|
||||
* @name:UserMapper
|
||||
* @Date:2024/8/22 15:28
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.muyu.cloud.mart.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.domain.Market;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -13,5 +14,7 @@ import java.util.List;
|
|||
* @Date:2024/8/21 21:54
|
||||
*/
|
||||
public interface MarketService extends IService<Market> {
|
||||
List<Market> findMarketList(Market market);
|
||||
List<Market> findMarketList();
|
||||
|
||||
Result getPhonePlace(String tel);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.muyu.cloud.mart.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.domain.User;
|
||||
import com.muyu.domain.UserSearch;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:chaiyapeng
|
||||
* @Package:com.muyu.cloud.mart.service
|
||||
* @Project:cloud-mart
|
||||
* @name:UserService
|
||||
* @Date:2024/8/22 15:28
|
||||
*/
|
||||
public interface UserService extends IService<User> {
|
||||
List<User> getAllUsers();
|
||||
|
||||
Result addUser(User user);
|
||||
|
||||
Result updateUser(User user);
|
||||
|
||||
Result deleteUser(User user);
|
||||
|
||||
Result getAllUserByCon(UserSearch userSearch);
|
||||
}
|
|
@ -1,13 +1,21 @@
|
|||
package com.muyu.cloud.mart.service.impl;
|
||||
|
||||
import cn.hutool.log.Log;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import com.muyu.cloud.mart.config.JuheDemo;
|
||||
import com.muyu.cloud.mart.config.MobileLocation;
|
||||
import com.muyu.cloud.mart.mapper.MarketMapper;
|
||||
import com.muyu.cloud.mart.service.MarketService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.domain.Market;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @Author:chaiyapeng
|
||||
|
@ -17,13 +25,23 @@ import java.util.List;
|
|||
* @Date:2024/8/21 21:54
|
||||
*/
|
||||
@Service
|
||||
@Log4j2
|
||||
public class MarketServiceImpl extends ServiceImpl<MarketMapper, Market> implements MarketService {
|
||||
|
||||
@Autowired
|
||||
private MarketMapper marketMapper;
|
||||
|
||||
@Override
|
||||
public List<Market> findMarketList(Market market) {
|
||||
return marketMapper.mybatisplus(market);
|
||||
public List<Market> findMarketList() {
|
||||
List<Market> list = marketMapper.selectList(null);
|
||||
return list;
|
||||
}
|
||||
// public static final PhoneNumberOfflineGeocoder GEOCODER = PhoneNumberOfflineGeocoder.getInstance();
|
||||
|
||||
public static final int COUNTRY_CODE = 86;
|
||||
@Override
|
||||
public Result getPhonePlace(String tel) {
|
||||
MobileLocation.queryMobileLocation(tel);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
package com.muyu.cloud.mart.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.muyu.cloud.mart.mapper.UserMapper;
|
||||
import com.muyu.cloud.mart.service.UserService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.domain.User;
|
||||
import com.muyu.domain.UserSearch;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:chaiyapeng
|
||||
* @Package:com.muyu.cloud.mart.service.impl
|
||||
* @Project:cloud-mart
|
||||
* @name:UserServiceImpl
|
||||
* @Date:2024/8/22 15:29
|
||||
*/
|
||||
@Service
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public List<User> getAllUsers() {
|
||||
List<User> list = userMapper.selectList(null);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result addUser(User user) {
|
||||
Integer i = userMapper.insert(user);
|
||||
if (i>0){
|
||||
return Result.success(i,"添加成功");
|
||||
}else {
|
||||
return Result.error("添加失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result updateUser(User user) {
|
||||
Integer i = userMapper.updateById(user);
|
||||
if (i>0){
|
||||
return Result.success(i,"更新成功");
|
||||
}else{
|
||||
return Result.error("更新失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result deleteUser(User user) {
|
||||
Integer i = userMapper.deleteById(user);
|
||||
if (i>0){
|
||||
return Result.success(i,"删除成功");
|
||||
}else {
|
||||
return Result.error("删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getAllUserByCon(UserSearch userSearch) {
|
||||
QueryWrapper<User> wrapper = new QueryWrapper<>();
|
||||
if (userSearch.getBlur()!=null && !userSearch.getBlur().equals("")){
|
||||
wrapper.like("user_name",userSearch.getBlur());
|
||||
}
|
||||
List<User> list = userMapper.selectList(wrapper);
|
||||
return Result.success(list);
|
||||
}
|
||||
}
|
|
@ -5,7 +5,5 @@
|
|||
<mapper namespace="com.muyu.cloud.mart.mapper.MarketMapper">
|
||||
|
||||
|
||||
<select id="mybatisplus" resultType="com.muyu.domain.Market">
|
||||
select name,ctfId,birthday,address from market
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue