From 5e37650982b261514e38abfe32da1679b1478043 Mon Sep 17 00:00:00 2001 From: zhanglinhao <1260788704@qq.com> Date: Sun, 12 May 2024 00:39:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AF=84=E4=BB=B7=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/后端/java/Configurer.java | 2 +- .../controller/EvaluationController.java | 58 +++++++++++++++++++ .../Evaluate/service/evaluateService.java | 7 ++- .../Evaluate/service/evaluateServiceImpl.java | 38 +++++++++++- src/后端/java/FreeToGoApplication.java | 2 - .../Login/controller/LoginController.java | 10 ++-- .../java/Login/service/LoginServiceImpl.java | 19 +++--- .../java/User/controller/UsersController.java | 18 ++++-- .../java/User/service/UserServiceImpl.java | 10 ++-- src/后端/java/helloController.java | 2 +- 10 files changed, 135 insertions(+), 31 deletions(-) create mode 100644 src/后端/java/Evaluate/controller/EvaluationController.java diff --git a/src/后端/java/Configurer.java b/src/后端/java/Configurer.java index bc6485f..eda6025 100644 --- a/src/后端/java/Configurer.java +++ b/src/后端/java/Configurer.java @@ -18,7 +18,7 @@ public class Configurer implements WebMvcConfigurer { .allowCredentials(true) //放行哪些原始域 .allowedOriginPatterns("*") - .allowedMethods(new String[]{"GET", "POST", "PUT", "DELETE"}) + .allowedMethods("GET", "POST", "PUT", "DELETE") .allowedHeaders("*") .exposedHeaders("*"); } diff --git a/src/后端/java/Evaluate/controller/EvaluationController.java b/src/后端/java/Evaluate/controller/EvaluationController.java new file mode 100644 index 0000000..26f12db --- /dev/null +++ b/src/后端/java/Evaluate/controller/EvaluationController.java @@ -0,0 +1,58 @@ +package com.softegg.freetogo.Evaluate.controller; + +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 java.util.List; +import java.util.Map; + +/** + * @description: 对评价的操作 + * @author: zhanglinhao + * @date: 2024/5/11 17:33 + */ +@RestController +@RequestMapping("/evaluate") +public class EvaluationController { + @Autowired + EvaluateService evaluateService; + + /** + * @description: 获取所有需求 + * @param: null + * @return: java.util.List + * @author: zhanglinhao + * @date: 2024/5/12 0:11 + */ + @GetMapping("findAllEvaluation") + public List findAllEvaluation() { + return evaluateService.evaluationList(); + } + + /** + * @description: 添加评价 + * @param: ebody + * @return: void + * @author: zhanglinhao + * @date: 2024/5/12 0:28 + */ + @PostMapping("addEvaluation") + public void addEvaluation(@RequestBody Map ebody) { + Evaluations evaluation = ebody.get("evaluation"); + evaluateService.addEvaluation(evaluation); + } + + /** + * @description: 通过手机获取评价 + * @param: phone + * @return: java.util.List + * @author: zhanglinhao + * @date: 2024/5/12 0:30 + */ + @GetMapping("evaluationByPhone") + public List evaluationByPhone(String phone) { + return evaluateService.getEListByPhone(phone); + } +} diff --git a/src/后端/java/Evaluate/service/evaluateService.java b/src/后端/java/Evaluate/service/evaluateService.java index e833253..2276f83 100644 --- a/src/后端/java/Evaluate/service/evaluateService.java +++ b/src/后端/java/Evaluate/service/evaluateService.java @@ -11,9 +11,14 @@ import java.util.List; * @date:2024/5/10 8:52 */ @Service -public interface evaluateService { +public interface EvaluateService { List evaluationList();//获取所有评论 + List getEListByPhone(String phone);//根据电话筛选评价 + void addEvaluation(Evaluations evaluation);//添加评论 + void editEvaluation(int eid, String ebody);//编辑评论 + + void deleteEvaluation(int eid);//删除评论 } diff --git a/src/后端/java/Evaluate/service/evaluateServiceImpl.java b/src/后端/java/Evaluate/service/evaluateServiceImpl.java index 507c6f8..26dfcdf 100644 --- a/src/后端/java/Evaluate/service/evaluateServiceImpl.java +++ b/src/后端/java/Evaluate/service/evaluateServiceImpl.java @@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; +import java.util.Optional; /** * @description: @@ -13,7 +14,7 @@ import java.util.List; * @date:2024/5/10 9:25 */ @Component -public class evaluateServiceImpl implements evaluateService { +public class EvaluateServiceImpl implements EvaluateService { @Autowired EvaluateRepository evaluateRepository; @@ -30,6 +31,7 @@ public class evaluateServiceImpl implements evaluateService { System.out.println("查询评论"); return evaluateRepository.findAll(); } + /** * @description: 根据电话筛选评价 * @param: phone @@ -39,7 +41,7 @@ public class evaluateServiceImpl implements evaluateService { */ @Override public List getEListByPhone(String phone) { - System.out.println("查询"+phone+"的评论"); + System.out.println("查询" + phone + "的评论"); return evaluateRepository.findByEditorPhone(phone); } @@ -56,5 +58,37 @@ public class evaluateServiceImpl implements evaluateService { System.out.println("添加评论" + evaluation.getEbody()); } + /** + * @description: 编辑评论 + * @param: eid + * @return: void + * @author: zhanglinhao + * @date: 2024/5/11 17:10 + */ + @Override + public void editEvaluation(int eid, String ebody) { + System.out.println("编辑评论:" + eid); + Optional opt = evaluateRepository.findById(eid); + if (opt.isPresent()) { + Evaluations evaluation = opt.get(); + evaluation.setEbody(ebody); + evaluateRepository.save(evaluation); + System.out.println("编辑成功:" + eid); + } + } + + /** + * @description: 删除评论 + * @param: eid + * @return: void + * @author: zhanglinhao + * @date: 2024/5/11 17:28 + */ + @Override + public void deleteEvaluation(int eid) { + evaluateRepository.deleteById(eid); + System.out.println("删除评论:" + eid); + } + } diff --git a/src/后端/java/FreeToGoApplication.java b/src/后端/java/FreeToGoApplication.java index ff3f68c..ee65fcb 100644 --- a/src/后端/java/FreeToGoApplication.java +++ b/src/后端/java/FreeToGoApplication.java @@ -1,9 +1,7 @@ package com.softegg.freetogo; -import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.domain.EntityScan; @SpringBootApplication public class FreeToGoApplication { diff --git a/src/后端/java/Login/controller/LoginController.java b/src/后端/java/Login/controller/LoginController.java index 8b5c5fc..372656c 100644 --- a/src/后端/java/Login/controller/LoginController.java +++ b/src/后端/java/Login/controller/LoginController.java @@ -32,10 +32,10 @@ public class LoginController { @PostMapping("login") public int Login(@RequestBody Map map) { System.out.println(map); - System.out.println("phone:"+map.get("phone").toString()); - System.out.println("password"+map.get("password").toString()); + System.out.println("phone:" + map.get("phone").toString()); + System.out.println("password" + map.get("password").toString()); int tag = loginService.loginAccount(map.get("name").toString(), map.get("password").toString()); - System.out.println("LoginTag:"+tag); + System.out.println("LoginTag:" + tag); return switch (tag) { case 1000 -> 1;//登陆成功 case 1001 -> 2;//密码或账号错误 @@ -58,8 +58,8 @@ public class LoginController { @PostMapping("register") public int Register(@RequestBody Map 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")); - System.out.println("RegisterTag:"+tag); + int tag = loginService.registerAccount((String) map.get("name"), (String) map.get("password"), (String) map.get("phone"), (String) map.get("nickname"), (String) map.get("IDCard")); + System.out.println("RegisterTag:" + tag); return switch (tag) { case 1003 -> 4;//该账户已经注册 case 1004 -> 5;//注册成功 diff --git a/src/后端/java/Login/service/LoginServiceImpl.java b/src/后端/java/Login/service/LoginServiceImpl.java index 9c61ccc..007b93b 100644 --- a/src/后端/java/Login/service/LoginServiceImpl.java +++ b/src/后端/java/Login/service/LoginServiceImpl.java @@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.time.LocalDateTime; -import java.util.Objects; /** * @description:登录服务实现类 @@ -28,11 +27,11 @@ public class LoginServiceImpl implements LoginService { */ @Override public int loginAccount(String phone, String password) { - if(phone.isEmpty() && password.isEmpty()) + if (phone.isEmpty() && password.isEmpty()) return 1005;//未输入账号密码 - else if(phone.isEmpty()) + else if (phone.isEmpty()) return 1006;//未输入账号 - else if(password.isEmpty()) + else if (password.isEmpty()) return 1007;//未输入密码 if (usersService.isRegister(phone)) { if (usersService.getUserByPhone(phone).getPassword().equals(password)) @@ -62,26 +61,26 @@ public class LoginServiceImpl implements LoginService { String IDCard) { if (usersService.isRegister(phone)) return 1003;//该账户已经注册 - else if(IDCard.length()!=18) + else if (IDCard.length() != 18) return 1008;//身份证输入错误 else { LocalDateTime currentTime = LocalDateTime.now(); - System.out.println("注册信息:姓名:"+name+"密码:"+password+"电话:"+phone+"昵称:"+nickname+"身份证:"+IDCard); + System.out.println("注册信息:姓名:" + name + "密码:" + password + "电话:" + phone + "昵称:" + nickname + "身份证:" + IDCard); Users user = new Users(); user.setPhone(phone); user.setPassword(password); user.setNickname(nickname); user.setIDCard(IDCard); user.setName(name); - user.setCreatetime((currentTime.getYear()+"-"+currentTime.getMonthValue()+"-"+currentTime.getDayOfMonth())); + user.setCreatetime((currentTime.getYear() + "-" + currentTime.getMonthValue() + "-" + currentTime.getDayOfMonth())); user.setGender(isMale(IDCard)); usersService.add(user); return 1004;//注册成功 } } - boolean isMale(String IDCard){ - System.out.println("根据身份证判断性别:"+IDCard+" 第17位:"+IDCard.charAt(16)); - return (int)IDCard.charAt(16) % 2 != 0; + boolean isMale(String IDCard) { + System.out.println("根据身份证判断性别:" + IDCard + " 第17位:" + IDCard.charAt(16)); + return (int) IDCard.charAt(16) % 2 != 0; } } diff --git a/src/后端/java/User/controller/UsersController.java b/src/后端/java/User/controller/UsersController.java index 5a6ac4b..6dd1ccd 100644 --- a/src/后端/java/User/controller/UsersController.java +++ b/src/后端/java/User/controller/UsersController.java @@ -15,7 +15,7 @@ import java.util.Map; */ @RestController //@CrossOrigin(origins = "*") -@RequestMapping("/users") +@RequestMapping("/Users") public class UsersController { @Autowired private UsersService usersService; @@ -140,11 +140,21 @@ public class UsersController { * @date: 2024/5/10 19:45 */ @PostMapping("pupdate") - public boolean pupdate(@RequestBody Map> user) { - Map ubody = user.get("user"); + public boolean pupdate(@RequestBody Map> user) { + Map ubody = user.get("user"); // System.out.println(ubody); // System.out.println(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")); + 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 user) { + Users ubody = user.get("user"); + 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; } diff --git a/src/后端/java/User/service/UserServiceImpl.java b/src/后端/java/User/service/UserServiceImpl.java index 9c19fac..3150ef5 100644 --- a/src/后端/java/User/service/UserServiceImpl.java +++ b/src/后端/java/User/service/UserServiceImpl.java @@ -38,7 +38,7 @@ public class UserServiceImpl implements UsersService { */ public void add(Users user) { usersRepository.save(user); - System.out.println("添加成功:"+user); + System.out.println("添加成功:" + user); } /** @@ -50,7 +50,7 @@ public class UserServiceImpl implements UsersService { */ public void deleteById(int id) { usersRepository.deleteById(id); - System.out.println("删除成功:"+id); + System.out.println("删除成功:" + id); } /** @@ -73,7 +73,7 @@ public class UserServiceImpl implements UsersService { */ public void update(Users user) { usersRepository.save(user); - System.out.println("更新成功:"+user); + System.out.println("更新成功:" + user); } /** @@ -85,7 +85,7 @@ public class UserServiceImpl implements UsersService { */ public boolean isRegister(String phone) { Users users = usersRepository.findByPhone(phone); - System.out.println("正在验证用户是否注册:"+users); + System.out.println("正在验证用户是否注册:" + users); return users != null; } @@ -97,7 +97,7 @@ public class UserServiceImpl implements UsersService { * @date: 2024/5/9 22:55 */ public Users getUserByPhone(String phone) { - System.out.println("通过手机号查找用户:"+phone); + System.out.println("通过手机号查找用户:" + phone); return usersRepository.findByPhone(phone); } } diff --git a/src/后端/java/helloController.java b/src/后端/java/helloController.java index 2fcc29d..15947c5 100644 --- a/src/后端/java/helloController.java +++ b/src/后端/java/helloController.java @@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController public class helloController { @GetMapping("/hello") - public String hello(){ + public String hello() { return "hello world!"; } }