代码修改

master
wuyifan 1 year ago
parent 8b7bee7c1d
commit 8299139603

@ -1,30 +1,25 @@
package com.softegg.freetogo.Api.authencation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
/**
* @description:
* @author: zhanglinhao
* @date: 2024/5/23 15:47
*/
@RestController
@RequestMapping("/api")
public class authenticationController {
@Autowired
com.softegg.freetogo.Api.authencation.authenticationService authenticationService;
/**
* @description:
* @author: zhanglinhao
* @date: 2024/5/29 14:54
*/
@GetMapping("authenticate")
public boolean authenticate(String idc, String phone, String name) throws IOException {
return authenticationService.authenticate(idc, phone, name);
}
}
//package com.softegg.freetogo.Api.authencation;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.io.IOException;
//
///**
// * @description:
// * @author: zhanglinhao
// * @date: 2024/5/23 15:47
// */
//@RestController
//@RequestMapping("/api")
//public class authenticationController {
// @Autowired
// com.softegg.freetogo.Api.authencation.authenticationService authenticationService;
//
// @GetMapping("authenticate")
// public void authenticate(String idc, String phone, String name) throws IOException {
// authenticationService.authenticate(idc, phone, name);
// }
//}

@ -1,58 +1,56 @@
package com.softegg.freetogo.Api.authencation;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* @description: api
* @author: zhanglinhao
* @date: 2024/5/23 15:12
*/
@Service
public class authenticationService {
public Boolean authenticate(String idc, String phone, String name) throws IOException {
String url = "https://mobile3elements.shumaidata.com/mobile/verify_real_name";
String appCode = "15704c321ae8459bb36fcadd888d67c4";
Map<String, String> params = new HashMap<>();
params.put("idcard", idc);
params.put("mobile", phone);
params.put("name", name);
Boolean result = postForm(appCode, url, params);
System.out.println(result);
return result;
}
/**
* HTTPokhttp 3.13.1
* <dependency>
* <groupId>com.squareup.okhttp3</groupId>
* <artifactId>okhttp</artifactId>
* <version>3.13.1</version>
* </dependency>
*/
public static Boolean postForm(String appCode, String url, Map<String, String> params) throws IOException {
OkHttpClient client = new OkHttpClient.Builder().build();
FormBody.Builder formbuilder = new FormBody.Builder();
Iterator<String> it = params.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
formbuilder.add(key, params.get(key));
}
FormBody body = formbuilder.build();
Request request = new Request.Builder().url(url).addHeader("Authorization", "APPCODE " + appCode).post(body).build();
Response response = client.newCall(request).execute();
System.out.println("返回状态码" + response.code() + ",message:" + response.message());
//package com.softegg.freetogo.Api.authencation;
//
//import okhttp3.FormBody;
//import okhttp3.OkHttpClient;
//import okhttp3.Request;
//import okhttp3.Response;
//import org.springframework.stereotype.Service;
//
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.Iterator;
//import java.util.Map;
//
///**
// * @description: 身份验证api
// * @author: zhanglinhao
// * @date: 2024/5/23 15:12
// */
//@Service
//public class authenticationService {
// public void authenticate(String idc, String phone, String name) throws IOException {
// String url = "https://mobile3elements.shumaidata.com/mobile/verify_real_name";
// String appCode = "15704c321ae8459bb36fcadd888d67c4";
//
// Map<String, String> params = new HashMap<>();
// params.put("idcard", idc);
// params.put("mobile", phone);
// params.put("name", name);
// String result = postForm(appCode, url, params);
// System.out.println(result);
// }
//
// /**
// * 用到的HTTP工具包okhttp 3.13.1
// * <dependency>
// * <groupId>com.squareup.okhttp3</groupId>
// * <artifactId>okhttp</artifactId>
// * <version>3.13.1</version>
// * </dependency>
// */
// public static String postForm(String appCode, String url, Map<String, String> params) throws IOException {
// OkHttpClient client = new OkHttpClient.Builder().build();
// FormBody.Builder formbuilder = new FormBody.Builder();
// Iterator<String> it = params.keySet().iterator();
// while (it.hasNext()) {
// String key = it.next();
// formbuilder.add(key, params.get(key));
// }
// FormBody body = formbuilder.build();
// Request request = new Request.Builder().url(url).addHeader("Authorization", "APPCODE " + appCode).post(body).build();
// Response response = client.newCall(request).execute();
// System.out.println("返回状态码" + response.code() + ",message:" + response.message());
// String result = response.body().string();
// return result;
return response.code() == 200;
}
}
// }
//}

@ -0,0 +1,40 @@
//package com.softegg.freetogo.Api.captcha;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.bind.annotation.RestController;
//
///**
// * @description:
// * @author: zhanglinhao
// * @date: 2024/5/24 9:54
// */
//@RestController
//@RequestMapping("/api")
//public class captchaController {
// @Autowired
// private RedisUtil redisUtil;
//
// @RequestMapping("/captcha")
// public JsonResult captcha(HttpServletRequest request, HttpServletResponse response) throws Exception {
// SpecCaptcha specCaptcha = new SpecCaptcha(130, 48, 5);
// String verCode = specCaptcha.text().toLowerCase();
// String key = UUID.randomUUID().toString();
// // 存入redis并设置过期时间为30分钟
// redisUtil.setEx(key, verCode, 30, TimeUnit.MINUTES);
// // 将key和base64返回给前端
// return JsonResult.ok().put("key", key).put("image", specCaptcha.toBase64());
// }
//
// @ResponseBody
// @PostMapping("/login")
// public JsonResult login(String username,String password,String verCode,String verKey){
// // 获取redis中的验证码
// String redisCode = redisUtil.get(verKey);
// // 判断验证码
// if (verCode==null || !redisCode.equals(verCode.trim().toLowerCase())) {
// return JsonResult.error("验证码不正确");
// }
// }
//}

@ -0,0 +1,18 @@
package com.softegg.freetogo.Api.captcha;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.GeneralPath;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Random;
import java.util.UUID;
/**
* @description:
* @author: zhanglinhao
* @date: 2024/5/24 9:27
*/
public class captchaService {
}

@ -87,13 +87,8 @@ public class DemandsServiceImpl implements DemandsService {
public List<Demands> getDemandsByPhone(String phone) {
List<Demands> demandsList = DemandsRepository.findByPhone(phone);
Iterator<Demands> iterator = demandsList.iterator();
while (iterator.hasNext()) {
Demands demand = iterator.next();
if (demand.getStatus() == 4) {
iterator.remove(); // 使用迭代器的 remove 方法
}
}
// 使用迭代器的 remove 方法
demandsList.removeIf(demand -> demand.getStatus() == 4);
return demandsList;
}

@ -43,13 +43,8 @@ public class DemandMatchServiceImpl implements DemandMatchService{
String demandEndDate = demand.getEndDate();
String demandMessage = demand.getMessage();
List<GuideService> guideServiceList = guideServiceService.getGuideServiceByCity(demand.getCity());
Iterator<GuideService> iterator = guideServiceList.iterator();
while (iterator.hasNext()) {
GuideService guideService = iterator.next();
if (guideService.getStatus() > 1) {
iterator.remove(); // 使用迭代器的 remove 方法
}
}
// 使用迭代器的 remove 方法
guideServiceList.removeIf(guideService -> guideService.getStatus() > 1);
int length = guideServiceList.size();
double[] sumScores = new double[length];
int i = 0;
@ -71,12 +66,7 @@ public class DemandMatchServiceImpl implements DemandMatchService{
list.add(new AbstractMap.SimpleEntry<>(sumScores[j], guideServiceList.get(j)));
}
// 根据sumScores的元素大小对 list 进行排序
list.sort(new Comparator<Map.Entry<Double, GuideService>>() {
@Override
public int compare(Map.Entry<Double, GuideService> o1, Map.Entry<Double, GuideService> o2) {
return o2.getKey().compareTo(o1.getKey());
}
});
list.sort((o1, o2) -> o2.getKey().compareTo(o1.getKey()));
List<GuideService> newgList = new ArrayList<>();
for (Map.Entry<Double, GuideService> entry : list) {
newgList.add(entry.getValue());
@ -95,12 +85,6 @@ public class DemandMatchServiceImpl implements DemandMatchService{
public int match(int did, int gid){
Demands demand = demandsService.getDemandById(did);
GuideService guideService = guideServiceService.getGuideServiceById(gid);
// List<Integer> guideServiceIdList = demand.getGuideServiceIdList();
// if (guideServiceIdList == null) {
// guideServiceIdList = new ArrayList<>();
// }
// guideServiceIdList.add(gid);
// demand.setGuideServiceIdList(guideServiceIdList);
List<Integer> demandIdList = guideService.getDemandIdList();
if (demandIdList == null) {
demandIdList = new ArrayList<>();
@ -267,7 +251,7 @@ public class DemandMatchServiceImpl implements DemandMatchService{
* @date: 2024/5/30 20:35
*/
public static double jaccardSimilarity(String s1, String s2) {
if (s1 == null || s2 == null || s1.isEmpty() || s2.isEmpty()) {
if (s1 == null || s2 == null ) {
return 0.0; // 如果任何一个字符串为空直接返回0
}
@ -343,7 +327,7 @@ public class DemandMatchServiceImpl implements DemandMatchService{
* @date: 2024/5/30 20:25
*/
public static double diceCoefficient(String s1, String s2) {
if (s1 == null || s2 == null || s1.isEmpty() || s2.isEmpty()) {
if (s1 == null || s2 == null ) {
return 0.0; // 如果任何一个字符串为空直接返回0
}
@ -373,10 +357,6 @@ public class DemandMatchServiceImpl implements DemandMatchService{
throw new IllegalArgumentException("Invalid input string or n-gram size");
}
if (s.isEmpty()) {
return new HashSet<>(); // 返回空集合
}
Set<String> nGrams = new HashSet<>();
for (int i = 0; i <= s.length() - n; i++) {
nGrams.add(s.substring(i, i + n));
@ -410,7 +390,7 @@ public class DemandMatchServiceImpl implements DemandMatchService{
*/
@Override
public double messageScore(String gmessage, String dmessage){
double score = 0;
double score;
double similarity1 = jaccardSimilarity(gmessage, dmessage);
double similarity2 = cosineSimilarity(gmessage, dmessage);
double similarity3 = diceCoefficient(gmessage, dmessage);

@ -19,6 +19,7 @@ import lombok.Setter;
@NoArgsConstructor
public class Evaluations {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int eid;//评价id
@Column(name = "createtime")
private String ct;//创建日期

@ -1,12 +1,10 @@
package com.softegg.freetogo.Evaluate.controller;
import com.softegg.freetogo.Debug.utils;
import com.softegg.freetogo.Evaluate.bean.Evaluations;
import com.softegg.freetogo.Evaluate.service.EvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.swing.text.html.parser.Entity;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
@ -19,7 +17,6 @@ import java.util.Map;
@RestController
@RequestMapping("/evaluate")
public class EvaluationController {
private final static utils util = new utils();
@Autowired
EvaluateService evaluateService;
@ -43,17 +40,15 @@ public class EvaluationController {
* @date: 2024/5/12 0:28
*/
@PostMapping("addEvaluation")
public int addEvaluation(@RequestBody Map<String, String> ebody) {
public void addEvaluation(@RequestBody Map<String, String> ebody) {
LocalDateTime currentTime = LocalDateTime.now();
Evaluations evaluation = new Evaluations();
System.out.println(Integer.parseInt(ebody.get("did")));
evaluation.setEid(Integer.parseInt(ebody.get("did")));
evaluation.setEid(Integer.parseInt(ebody.get("eid")));
evaluation.setEbody(ebody.get("ebody"));
evaluation.setSatisfaction(Integer.parseInt(ebody.get("satisfaction")));
evaluation.setCt(currentTime.toString());
evaluation.setMt(currentTime.toString());
evaluateService.addEvaluation(evaluation);
return 1;
}
/**
@ -69,12 +64,7 @@ public class EvaluationController {
// }
@GetMapping("getEvaluation")
public Evaluations getEvaluation(int eid) {
try{
return evaluateService.getEvaluationById(eid);}
catch (Exception e){
return new Evaluations();
}
return evaluateService.getEvaluationById(eid);
}
/**
@ -87,7 +77,7 @@ public class EvaluationController {
*/
@PostMapping("editEvaluation")
public void editEvaluation(@RequestBody Map<String, String> ebody) {
util.printInfo("接收的json:" + ebody);
System.out.println("接收的json:" + ebody);
LocalDateTime currentTime = LocalDateTime.now();
Evaluations evaluation = new Evaluations(Integer.parseInt(ebody.get("eid")), ebody.get("ct"), currentTime.toString(), ebody.get("ebody"), Integer.parseInt(ebody.get("satisfaction")));
evaluateService.editEvaluation(evaluation);
@ -119,7 +109,7 @@ public class EvaluationController {
// for (Evaluations evaluation : elist) {
// sumOfSatisfaction += evaluation.getSatisfaction();
// }
// util.printInfo("查询满意度:"+ sumOfSatisfaction);
// System.out.println("查询满意度:"+ sumOfSatisfaction);
// return Float.toString(sumOfSatisfaction /elist.size());
// }
}

@ -1,6 +1,5 @@
package com.softegg.freetogo.Evaluate.service;
import com.softegg.freetogo.Debug.utils;
import com.softegg.freetogo.Evaluate.Dao.EvaluateRepository;
import com.softegg.freetogo.Evaluate.bean.Evaluations;
import org.springframework.beans.factory.annotation.Autowired;
@ -15,7 +14,6 @@ import java.util.List;
*/
@Component
public class EvaluateServiceImpl implements EvaluateService {
private final static utils util = new utils();
@Autowired
EvaluateRepository evaluateRepository;
@ -29,7 +27,7 @@ public class EvaluateServiceImpl implements EvaluateService {
*/
@Override
public List<Evaluations> evaluationList() {
util.printInfo("查询评论");
System.out.println("查询评论");
return evaluateRepository.findAll();
}
@ -55,7 +53,7 @@ public class EvaluateServiceImpl implements EvaluateService {
*/
// @Override
// public List<Evaluations> getEListByPhone(String phone) {
// util.printInfo("查询" + phone + "的评论");
// System.out.println("查询" + phone + "的评论");
// return evaluateRepository.findByEditorPhone(phone);
// }
@ -81,7 +79,7 @@ public class EvaluateServiceImpl implements EvaluateService {
@Override
public void addEvaluation(Evaluations evaluation) {
evaluateRepository.save(evaluation);
util.printInfo("添加评论:" + evaluation.getEbody());
System.out.println("添加评论:" + evaluation.getEbody());
}
/**
@ -94,9 +92,9 @@ public class EvaluateServiceImpl implements EvaluateService {
@Override
public void editEvaluation(Evaluations evaluation) {
int eid = evaluation.getEid();
util.printInfo("编辑评论:" + eid);
System.out.println("编辑评论:" + eid);
evaluateRepository.save(evaluation);
util.printInfo("编辑成功:" + eid);
System.out.println("编辑成功:" + eid);
}
/**
@ -109,6 +107,6 @@ public class EvaluateServiceImpl implements EvaluateService {
@Override
public void deleteEvaluation(int eid) {
evaluateRepository.deleteById(eid);
util.printInfo("删除评论:" + eid);
System.out.println("删除评论:" + eid);
}
}

@ -0,0 +1,9 @@
package com.softegg.freetogo.FeedBack;
/**
* @description:
* @author: zhanglinhao
* @date: 2024/5/20 11:14
*/
public class bean {
}

@ -43,13 +43,8 @@ public class GuideMatchServiceImpl implements GuideMatchService {
String guideServiceEndDate = guideService.getEndDate();
String guideServiceMessage = guideService.getMessage();
List<Demands> dlist = demandsService.getDemandsByCity(guideService.getCity());
Iterator<Demands> iterator = dlist.iterator();
while (iterator.hasNext()) {
Demands demand = iterator.next();
if (demand.getStatus() > 1) {
iterator.remove(); // 使用迭代器的 remove 方法
}
}
// 使用迭代器的 remove 方法
dlist.removeIf(demand -> demand.getStatus() > 1);
int length = dlist.size();
double[] sumScores = new double[length];
int i = 0;
@ -71,12 +66,7 @@ public class GuideMatchServiceImpl implements GuideMatchService {
list.add(new AbstractMap.SimpleEntry<>(sumScores[j], dlist.get(j)));
}
// 根据sumScores的元素大小对 list 进行排序
list.sort(new Comparator<Map.Entry<Double, Demands>>() {
@Override
public int compare(Map.Entry<Double, Demands> o1, Map.Entry<Double, Demands> o2) {
return o2.getKey().compareTo(o1.getKey());
}
});
list.sort((o1, o2) -> o2.getKey().compareTo(o1.getKey()));
List<Demands> newdList = new ArrayList<>();
for (Map.Entry<Double, Demands> entry : list) {
newdList.add(entry.getValue());
@ -349,9 +339,6 @@ public class GuideMatchServiceImpl implements GuideMatchService {
throw new IllegalArgumentException("Invalid input string or n-gram size");
}
if (s.isEmpty()) {
return new HashSet<>(); // 返回空集合
}
Set<String> nGrams = new HashSet<>();
for (int i = 0; i <= s.length() - n; i++) {
@ -386,7 +373,7 @@ public class GuideMatchServiceImpl implements GuideMatchService {
*/
@Override
public double messageScore(String gmessage, String dmessage){
double score = 0;
double score;
double similarity1 = jaccardSimilarity(gmessage, dmessage);
double similarity2 = cosineSimilarity(gmessage, dmessage);
double similarity3 = diceCoefficient(gmessage, dmessage);

@ -91,13 +91,8 @@ public class GuideServiceServiceImpl implements GuideServiceService {
public List<GuideService> getGuideServiceByPhone(String phone) {
List<GuideService> guideServiceList = GuideServiceRepository.findByPhone(phone);
Iterator<GuideService> iterator = guideServiceList.iterator();
while (iterator.hasNext()) {
GuideService guideService = iterator.next();
if (guideService.getStatus() == 4) {
iterator.remove(); // 使用迭代器的 remove 方法
}
}
// 使用迭代器的 remove 方法
guideServiceList.removeIf(guideService -> guideService.getStatus() == 4);
return guideServiceList;
}

@ -1,6 +1,5 @@
package com.softegg.freetogo.Login.controller;
import com.softegg.freetogo.Debug.utils;
import com.softegg.freetogo.Login.service.LoginService;
import com.softegg.freetogo.User.Dao.GuidesRepository;
import org.springframework.beans.factory.annotation.Autowired;
@ -9,12 +8,6 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Map;
/**
@ -27,8 +20,6 @@ import java.util.Map;
@RequestMapping("/Login")
public class LoginController {
private final static utils util = new utils();
@Autowired
LoginService loginService;
@ -44,11 +35,11 @@ public class LoginController {
*/
@PostMapping("login")
public int Login(@RequestBody Map<String, Object> map) {
util.printInfo(map);
util.printInfo("phone:" + map.get("phone").toString());
util.printInfo("password" + map.get("password").toString());
System.out.println(map);
System.out.println("phone:" + map.get("phone").toString());
System.out.println("password" + map.get("password").toString());
int tag = loginService.loginAccount(map.get("phone").toString(), map.get("password").toString());
util.printInfo("LoginTag:" + tag);
System.out.println("LoginTag:" + tag);
return switch (tag) {
case 1000 -> 1;//登陆成功
case 1001 -> 2;//密码或账号错误
@ -69,42 +60,9 @@ public class LoginController {
*/
@PostMapping("register")
public int Register(@RequestBody Map<String, Object> map) {
try {
// 创建URL对象
// URL url = new URL("http://localhost:9000/api/authenticate?idc="+ map.get("IDCard") +"&name="+map.get("name")+"&phone="+map.get("phone"));
String baseURL = "http://localhost:9000/api/authenticate";
String name=URLEncoder.encode(map.get("name").toString(), StandardCharsets.UTF_8);;
String phone=URLEncoder.encode(map.get("phone").toString(), StandardCharsets.UTF_8);
String idc = URLEncoder.encode(map.get("IDCard").toString(), StandardCharsets.UTF_8);
URL url = new URL(baseURL+ "?idc="+idc +"&name="+name+"&phone="+phone);
// 打开连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// 设置请求方法
connection.setRequestMethod("GET");
// 获取响应码
int responseCode = connection.getResponseCode();
System.out.println("响应码: " + responseCode);
// 读取响应内容
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder content = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
// 关闭连接
in.close();
connection.disconnect();
// 输出响应内容
System.out.println("响应内容: " + content);
if(content.toString().equals("false"))
return 14;
} catch (Exception e) {
e.printStackTrace();
}
util.printInfo(map);
System.out.println(map);
int tag = loginService.registerAccount((String) map.get("name"), (String) map.get("password"), (String) map.get("phone"), (String) map.get("nickname"), (String) map.get("IDCard"));
util.printInfo("RegisterTag:" + tag);
System.out.println("RegisterTag:" + tag);
return switch (tag) {
case 1003 -> 4;//该账户已经注册
case 1004 -> 5;//注册成功

@ -0,0 +1,4 @@
package com.softegg.freetogo.Search.controller;
public class SearchController {
}

@ -0,0 +1,4 @@
package com.softegg.freetogo.Search.service;
public interface SearchService {
}

@ -0,0 +1,4 @@
package com.softegg.freetogo.Search.service;
public class SearchServiceImpl {
}

@ -1,6 +1,5 @@
package com.softegg.freetogo.User.controller;
import com.softegg.freetogo.Debug.utils;
import com.softegg.freetogo.User.bean.Guides;
import com.softegg.freetogo.User.bean.Users;
import com.softegg.freetogo.User.service.GuidesService;
@ -20,7 +19,6 @@ import java.util.Map;
//@CrossOrigin(origins = "*")
@RequestMapping("/users")
public class UsersController {
private final static utils util = new utils();
@Autowired
UsersService usersService;
@Autowired
@ -35,7 +33,7 @@ public class UsersController {
*/
@GetMapping("findAll")
public List<Users> findAll() {
util.printInfo("响应查找所有数据");
System.out.println("响应查找所有数据");
return usersService.findAll();
}
@ -58,7 +56,7 @@ public class UsersController {
int status) {
Users user = new Users(name, email, password, createtime, reputation, phone, nickname, IDCard, gender, type, status);
usersService.add(user);
util.printInfo("添加用户");
System.out.println("添加用户");
return "添加成功";
}
@ -72,7 +70,7 @@ public class UsersController {
@GetMapping("delbyid")
public String delById(int id) {
usersService.deleteById(id);
util.printInfo("通过id删除用户");
System.out.println("通过id删除用户");
return "删除成功";
}
@ -85,7 +83,7 @@ public class UsersController {
*/
@GetMapping("findbyid")
public Users getUserById(int id) {
util.printInfo("通过id获取用户数据");
System.out.println("通过id获取用户数据");
return usersService.getUserById(id);
}
@ -107,10 +105,10 @@ public class UsersController {
boolean type,
int status) {
Users User = usersService.getUserByPhone(phone);
util.printInfo(User);
System.out.println(User);
setUsers(name, email, password, createtime, reputation, phone, nickname, IDCard, gender, type, status, User);
usersService.update(User);
util.printInfo("更新用户信息:" + User);
System.out.println("更新用户信息:" + User);
return "更新成功";
}
@ -121,22 +119,13 @@ public class UsersController {
* @author: zhanglinhao
* @date: 2024/5/10 19:45
*/
@PostMapping("pupdate")
public boolean pupdate(@RequestBody Map<String, Map<String, Object>> user) {
Map<String, Object> ubody = user.get("user");
util.printInfo(ubody);
// util.printInfo(ubody.get("uid"));
Users User = new Users((int) ubody.get("uid"), (String) ubody.get("name"), (String) ubody.get("email"), (String) ubody.get("password"), (String) ubody.get("createtime"), (String) ubody.get("idcard"), (int) ubody.get("reputation"), (boolean) ubody.get("gender"), (boolean) ubody.get("membertype"), (String) ubody.get("phone"), (String) ubody.get("nickname"), (int) ubody.get("status"));
usersService.update(User);
return true;
}
@PostMapping("Pupdate")
public boolean Pupdate(@RequestBody Map<String, Users> user) {
Users ubody = user.get("user");
util.printInfo(ubody);
// util.printInfo(ubody.get("uid"));
System.out.println(ubody);
// System.out.println(ubody.get("uid"));
Users User = new Users(ubody.getUid(), ubody.getName(), ubody.getEmail(), ubody.getPassword(), ubody.getCreatetime(), ubody.getIdcard(), ubody.getReputation(), ubody.isGender(), ubody.isMembertype(), ubody.getPhone(), ubody.getNickname(), ubody.getStatus());
usersService.update(User);
return true;
@ -151,8 +140,8 @@ public class UsersController {
*/
@GetMapping("getByPhone")
public Users getByPhone(String phone) {
util.printInfo("根据手机号获取用户信息:" + phone);
util.printInfo(usersService.getUserByPhone(phone));
System.out.println("根据手机号获取用户信息:" + phone);
System.out.println(usersService.getUserByPhone(phone));
return usersService.getUserByPhone(phone);
}
@ -165,7 +154,7 @@ public class UsersController {
*/
@GetMapping("isGuide")
public boolean isGuide(String phone) {
util.printInfo("查寻是否是导游:" + phone);
System.out.println("查寻是否是导游:" + phone);
return usersService.isGuide(phone);
}
@ -178,7 +167,7 @@ public class UsersController {
*/
@GetMapping("getUid")
public int getUid(String phone) {
util.printInfo("搜索uid使用的电话:" + phone);
System.out.println("搜索uid使用的电话:" + phone);
return usersService.getIdByPhone(phone);
}
@ -192,9 +181,9 @@ public class UsersController {
*/
// @PostMapping("registerToGuide")
// public int registerToGuide(@RequestBody Map<String,Map<String,String>> grequesting) {//Map<String, Map<String, Object>> gbody) {
// util.printInfo("接收的注册请求:"+grequesting);
// System.out.println("接收的注册请求:"+grequesting);
// Map<String,String> gbody = grequesting.get("registerToGuide");
// util.printInfo("处理后的注册请求:"+gbody);
// System.out.println("处理后的注册请求:"+gbody);
// Guides guide = new Guides();
// guide.setUid(Integer.parseInt(gbody.get("uid")));
// guide.setRsd(gbody.get("rsd"));
@ -208,9 +197,9 @@ public class UsersController {
// }
@PostMapping("registerToGuide")
public int registerToGuide(@RequestBody Map<String,Guides> grequesting) {//Map<String, Map<String, Object>> gbody) {
util.printInfo(grequesting);
System.out.println(grequesting);
Guides guide = grequesting.get("registerToGuide");
util.printInfo(guide);
System.out.println(guide);
if(guidesService.registerToGuide(guide))
return 1;
else

@ -1,6 +1,5 @@
package com.softegg.freetogo.User.service;
import com.softegg.freetogo.Debug.utils;
import com.softegg.freetogo.User.Dao.GuidesRepository;
import com.softegg.freetogo.User.bean.Guides;
import com.softegg.freetogo.User.bean.Users;
@ -14,7 +13,6 @@ import org.springframework.stereotype.Component;
*/
@Component
public class GuidesServiceImpl implements GuidesService {
private final static utils util = new utils();
@Autowired
GuidesRepository guidesRepository;
@Autowired
@ -23,7 +21,7 @@ public class GuidesServiceImpl implements GuidesService {
// @Override
// public void registerToGuide(Guides guide) {
// guidesRepository.save(guide);
// util.printInfo("成功保存注册导游信息!");
// System.out.println("成功保存注册导游信息!");
// }
/**
@ -35,15 +33,15 @@ public class GuidesServiceImpl implements GuidesService {
*/
@Override
public boolean registerToGuide(Guides guide) {
util.printInfo("注册成为导游id:" + guide.getUid());
System.out.println("注册成为导游id:" + guide.getUid());
Users user = usersService.getUserById(guide.getUid());
user.setMembertype(true);
guidesRepository.save(guide);
if (user.isMembertype()) {
util.printInfo("注册成功!");
System.out.println("注册成功!");
return true;
}else{
util.printInfo("注册失败!");
System.out.println("注册失败!");
return false;
}

@ -1,6 +1,5 @@
package com.softegg.freetogo.User.service;
import com.softegg.freetogo.Debug.utils;
import com.softegg.freetogo.User.Dao.UsersRepository;
import com.softegg.freetogo.User.bean.Users;
import org.springframework.beans.factory.annotation.Autowired;
@ -15,7 +14,6 @@ import java.util.List;
*/
@Component
public class UserServiceImpl implements UsersService {
private final static utils util = new utils();
@Autowired
private UsersRepository usersRepository;
@ -27,7 +25,7 @@ public class UserServiceImpl implements UsersService {
* @date: 2024/5/9 22:52
*/
public List<Users> findAll() {
util.printInfo("查询成功");
System.out.println("查询成功");
return usersRepository.findAll();
}
@ -40,7 +38,7 @@ public class UserServiceImpl implements UsersService {
*/
public void add(Users user) {
usersRepository.save(user);
util.printInfo("添加成功:" + user);
System.out.println("添加成功:" + user);
}
/**
@ -52,7 +50,7 @@ public class UserServiceImpl implements UsersService {
*/
public void deleteById(int id) {
usersRepository.deleteById(id);
util.printInfo("删除成功:" + id);
System.out.println("删除成功:" + id);
}
/**
@ -75,7 +73,7 @@ public class UserServiceImpl implements UsersService {
*/
public void update(Users user) {
usersRepository.save(user);
util.printInfo("更新成功:");
System.out.println("更新成功:");
showInfo(user);
}
@ -88,12 +86,12 @@ public class UserServiceImpl implements UsersService {
*/
public boolean isRegister(String phone) {
Users users = usersRepository.findByPhone(phone);
util.printInfo("正在验证用户是否注册:" + users);
System.out.println("正在验证用户是否注册:" + users);
if (users == null) {
util.printInfo("用户未注册");
System.out.println("用户未注册");
return false;
} else {
util.printInfo("用户已注册");
System.out.println("用户已注册");
return true;
}
}
@ -106,7 +104,7 @@ public class UserServiceImpl implements UsersService {
* @date: 2024/5/9 22:55
*/
public Users getUserByPhone(String phone) {
util.printInfo("通过手机号查找用户:" + phone);
System.out.println("通过手机号查找用户:" + phone);
return usersRepository.findByPhone(phone);
}
@ -119,13 +117,13 @@ public class UserServiceImpl implements UsersService {
*/
@Override
public boolean isGuide(String phone) {
util.printInfo("判断是不是导游:" + phone);
System.out.println("判断是不是导游:" + phone);
Users user = getUserByPhone(phone);
if (user.isMembertype()) {
util.printInfo("是导游:" + phone);
System.out.println("是导游:" + phone);
return true;
} else {
util.printInfo("不是导游:" + phone);
System.out.println("不是导游:" + phone);
return false;
}
}
@ -141,10 +139,10 @@ public class UserServiceImpl implements UsersService {
public int getIdByPhone(String phone) {
Users user = usersRepository.findByPhone(phone);
if (user == null) {
util.printInfo("该电话号码未注册");
System.out.println("该电话号码未注册");
return -1;
} else {
util.printInfo("查询到的id:" + user.getUid());
System.out.println("查询到的id:" + user.getUid());
return user.getUid();
}
}
@ -156,16 +154,16 @@ public class UserServiceImpl implements UsersService {
*/
@Override
public void showInfo(Users user) {
util.printInfo(user.getUid());
util.printInfo(user.getName());
util.printInfo(user.getPhone());
util.printInfo(user.getPassword());
util.printInfo(user.getNickname());
util.printInfo(user.getCreatetime());
util.printInfo(user.getIdcard());
util.printInfo(user.getReputation());
util.printInfo(user.getStatus());
util.printInfo(user.isGender());
util.printInfo(user.isMembertype());
System.out.println(user.getUid());
System.out.println(user.getName());
System.out.println(user.getPhone());
System.out.println(user.getPassword());
System.out.println(user.getNickname());
System.out.println(user.getCreatetime());
System.out.println(user.getIdcard());
System.out.println(user.getReputation());
System.out.println(user.getStatus());
System.out.println(user.isGender());
System.out.println(user.isMembertype());
}
}

@ -0,0 +1,17 @@
package com.softegg.freetogo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @description
* @author:zhanglinhao
* @date:2024/5/7 23:40
*/
@RestController
public class helloController {
@GetMapping("/hello")
public String hello() {
return "hello world!";
}
}
Loading…
Cancel
Save