From ded46a1389800cd6e4329c676febc5d3aeb27cbe Mon Sep 17 00:00:00 2001 From: zhanglinhao <1260788704@qq.com> Date: Sat, 11 May 2024 16:43:27 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E4=BB=93=E5=BA=93=E5=AD=98=E5=82=A8=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/后端/java/Login/LoginController.java | 42 ---------- src/后端/java/Login/LoginService.java | 16 ---- src/后端/java/Login/LoginServiceImpl.java | 52 ------------- src/后端/java/UserServiceImpl.java | 51 ------------ src/后端/java/Users.java | 44 ----------- src/后端/java/UsersController.java | 86 --------------------- src/后端/java/UsersRepository.java | 16 ---- src/后端/java/UsersService.java | 22 ------ 8 files changed, 329 deletions(-) delete mode 100644 src/后端/java/Login/LoginController.java delete mode 100644 src/后端/java/Login/LoginService.java delete mode 100644 src/后端/java/Login/LoginServiceImpl.java delete mode 100644 src/后端/java/UserServiceImpl.java delete mode 100644 src/后端/java/Users.java delete mode 100644 src/后端/java/UsersController.java delete mode 100644 src/后端/java/UsersRepository.java delete mode 100644 src/后端/java/UsersService.java diff --git a/src/后端/java/Login/LoginController.java b/src/后端/java/Login/LoginController.java deleted file mode 100644 index 2b48b2f..0000000 --- a/src/后端/java/Login/LoginController.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.softegg.freetogo.Login; - -import org.apache.ibatis.annotations.Param; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import java.util.Map; - -/** - * @description: - * @author:zhanglinhao - * @date:2024/5/9 9:35 - */ -@RestController -//@CrossOrigin(origins = "*") -@RequestMapping("/Login") -public class LoginController { - @Autowired - LoginService loginService; - - @PostMapping("login") - public String Login(@RequestBody Map map){ - System.out.println(map); - System.out.println(map.get("username").toString()); - System.out.println(map.get("password").toString()); - return switch (loginService.loginAccount( map.get("username").toString(), map.get("password").toString())) { - case 1000 -> "登陆成功"; - case 1001 -> "密码错误"; - case 1002 -> "未注册"; - default -> null; - }; - } - - @PostMapping("register") - public String Register(@RequestBody Map map){ - return switch (loginService.registerAccount(map.get("username").toString(), map.get("password").toString())) { - case 1003 -> "已注册"; - case 1004 -> "注册成功"; - default -> null; - }; - } -} diff --git a/src/后端/java/Login/LoginService.java b/src/后端/java/Login/LoginService.java deleted file mode 100644 index 340d66d..0000000 --- a/src/后端/java/Login/LoginService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.softegg.freetogo.Login; - -import jakarta.annotation.Resource; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Service; - -/** - * @description: - * @author:zhanglinhao - * @date:2024/5/9 8:37 - */ -@Service -public interface LoginService { - int loginAccount(String phone,String password); - int registerAccount(String phone,String password); -} diff --git a/src/后端/java/Login/LoginServiceImpl.java b/src/后端/java/Login/LoginServiceImpl.java deleted file mode 100644 index b8c419f..0000000 --- a/src/后端/java/Login/LoginServiceImpl.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.softegg.freetogo.Login; - -import com.softegg.freetogo.Users; -import com.softegg.freetogo.UsersService; -import org.apache.ibatis.annotations.Param; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -/** - * @description: - * @author:zhanglinhao - * @date:2024/5/9 9:33 - */ -@Component -public class LoginServiceImpl implements LoginService{ - @Autowired - UsersService usersService; - /** - * @param phone - * @param password - * @return - */ - @Override - public int loginAccount(String phone,String password){ - if(usersService.isRegister(phone)){ - if(usersService.getUserByPhone(phone).getPassword().equals(password)) - return 1000; - else - return 1001; - } - else - return 1002; - } - - /** - * @param phone - * @param password - * @return - */ - @Override - public int registerAccount(String phone,String password) { - if (usersService.isRegister(phone)) - return 1003; - else { - Users user = new Users(); - user.setPhone(phone); - user.setPassword(password); - usersService.add(user); - return 1004; - } - } -} diff --git a/src/后端/java/UserServiceImpl.java b/src/后端/java/UserServiceImpl.java deleted file mode 100644 index 3ec488f..0000000 --- a/src/后端/java/UserServiceImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.softegg.freetogo; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - * @description:UsersService接口实现类 - * @author:zhanglinhao - * @date:2024/5/8 8:50 - */ -@Component -public class UserServiceImpl implements UsersService{ - @Autowired - private UsersRepository usersRepository; - - public List findAll(){ - System.out.println("查询成功"); - return usersRepository.findAll(); - } - - public void add(Users user){ - usersRepository.save(user); - System.out.println("添加成功"); - } - - public void deleteById(int id){ - usersRepository.deleteById(id); - System.out.println("删除成功"); - } - - public Users getUserById(int id) { - return usersRepository.findById(id).orElse(null); - } - - public void update(Users user){ - usersRepository.save(user); - System.out.println("更新成功"); - } - - public boolean isRegister(String phone){ - Users users = usersRepository.findByPhone(phone); - System.out.println(users); - return users != null; - } - - public Users getUserByPhone(String phone){ - return usersRepository.findByPhone(phone); - } -} diff --git a/src/后端/java/Users.java b/src/后端/java/Users.java deleted file mode 100644 index 0110a2b..0000000 --- a/src/后端/java/Users.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.softegg.freetogo; - -import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -/** - * @description:数据库中表users的对应实体类 - * @author:zhanglinhao - * @date:2024/5/7 15:36 - */ -@Entity -@Table(name="users") -@Setter -@Getter -@NoArgsConstructor -@AllArgsConstructor -public class Users { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer uid; - @Column - private String name; - @Column - private String email; - @Column - private String password; - @Column - private String createtime; - @Column - private String IDCard; - @Column - private int reputation; - @Column - private boolean gender; - @Column - private boolean membertype; - @Column - private String phone; - @Column - private String nickname; -} diff --git a/src/后端/java/UsersController.java b/src/后端/java/UsersController.java deleted file mode 100644 index 97379d5..0000000 --- a/src/后端/java/UsersController.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.softegg.freetogo; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.List; - -/** - * @description: - * @author:zhanglinhao - * @date:2024/5/8 8:28 - */ -@RestController -//@CrossOrigin(origins = "*") -@RequestMapping("/users") -public class UsersController { - @Autowired - private UsersService usersService; - - @GetMapping("findAll") - public List findAll() { - return usersService.findAll(); - } - - @GetMapping("add") - public String add(String name, - String email, - String psw, - String ct, - int rpt, - String phone, - String nkn, - String idc, - boolean gender, - boolean type) { - Users user = new Users(); - setUsers(name, email, psw, ct, rpt, phone, nkn, idc, gender, type, user); - usersService.add(user); - return "添加成功"; - } - - @GetMapping("delbyid") - public String delById(int id) { - usersService.deleteById(id); - return "删除成功"; - } - - @GetMapping("findbyid") - public Users getUserById(int id) { - return usersService.getUserById(id); - } - - @GetMapping("update") - public String update(int id, - String name, - String email, - String psw, - String ct, - int rpt, - String phone, - String nkn, - String idc, - boolean gender, - boolean type){ - Users user = usersService.getUserById(id); - setUsers(name, email, psw, ct, rpt, phone, nkn, idc, gender, type, user); - usersService.update(user); - return "更新成功"; - } - - private void setUsers(String name, String email, String psw, String ct, int rpt, String phone, String nkn, String idc, boolean gender, boolean type, Users user) { - user.setName(name); - user.setGender(gender); - user.setPassword(psw); - user.setEmail(email); - user.setReputation(rpt); - user.setMembertype(type); - user.setCreatetime(ct); - user.setPhone(phone); - user.setNickname(nkn); - user.setIDCard(idc); - } -} diff --git a/src/后端/java/UsersRepository.java b/src/后端/java/UsersRepository.java deleted file mode 100644 index 27e9e19..0000000 --- a/src/后端/java/UsersRepository.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.softegg.freetogo; - -import org.apache.ibatis.annotations.Param; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; -/** - * @description:继承Jpa数据库接口类 - * @author:zhanglinhao - * @date:2024/5/8 8:50 - */ -public interface UsersRepository extends JpaRepository { -// @Query(value = "select * from users where phone = ?1",nativeQuery = true) - Users findByPhone(String phone); -} diff --git a/src/后端/java/UsersService.java b/src/后端/java/UsersService.java deleted file mode 100644 index 31869aa..0000000 --- a/src/后端/java/UsersService.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.softegg.freetogo; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - * @description:Service接口类 - * @author:zhanglinhaon - * @date:2024/5/7 16:06 - */ - -public interface UsersService { - List findAll(); - void add(Users user); - void deleteById(int id); - Users getUserById(int id); - void update(Users user); - boolean isRegister(String phone); - Users getUserByPhone(String phone); -} -- 2.34.1 From d6932b75e15c1bfa962c999c1d4ab90baa5679f7 Mon Sep 17 00:00:00 2001 From: zhanglinhao <1260788704@qq.com> Date: Sat, 11 May 2024 16:44:13 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Evaluate/Dao/EvaluateRepository.java | 3 ++ .../Evaluate/service/evaluateService.java | 2 ++ .../Evaluate/service/evaluateServiceImpl.java | 14 ++++++++++ .../Login/controller/LoginController.java | 12 ++++---- .../java/Login/service/LoginService.java | 18 ++++-------- .../java/Login/service/LoginServiceImpl.java | 28 +++++++++++++++++-- src/后端/java/Login/返回码.txt | 9 ++++++ 7 files changed, 66 insertions(+), 20 deletions(-) create mode 100644 src/后端/java/Login/返回码.txt diff --git a/src/后端/java/Evaluate/Dao/EvaluateRepository.java b/src/后端/java/Evaluate/Dao/EvaluateRepository.java index 4700ad4..60b0104 100644 --- a/src/后端/java/Evaluate/Dao/EvaluateRepository.java +++ b/src/后端/java/Evaluate/Dao/EvaluateRepository.java @@ -3,10 +3,13 @@ package com.softegg.freetogo.Evaluate.Dao; import com.softegg.freetogo.Evaluate.bean.Evaluations; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + /** * @description: 继承Jpa数据库接口类 * @author: zhanglinhao * @date: 2024/5/10 9:27 */ public interface EvaluateRepository extends JpaRepository { + List findByEditorPhone(String phone); } diff --git a/src/后端/java/Evaluate/service/evaluateService.java b/src/后端/java/Evaluate/service/evaluateService.java index 88e167e..e833253 100644 --- a/src/后端/java/Evaluate/service/evaluateService.java +++ b/src/后端/java/Evaluate/service/evaluateService.java @@ -13,5 +13,7 @@ import java.util.List; @Service public interface evaluateService { List evaluationList();//获取所有评论 + List getEListByPhone(String phone);//根据电话筛选评价 void addEvaluation(Evaluations evaluation);//添加评论 + } diff --git a/src/后端/java/Evaluate/service/evaluateServiceImpl.java b/src/后端/java/Evaluate/service/evaluateServiceImpl.java index 9404172..507c6f8 100644 --- a/src/后端/java/Evaluate/service/evaluateServiceImpl.java +++ b/src/后端/java/Evaluate/service/evaluateServiceImpl.java @@ -30,6 +30,18 @@ public class evaluateServiceImpl implements evaluateService { System.out.println("查询评论"); return evaluateRepository.findAll(); } + /** + * @description: 根据电话筛选评价 + * @param: phone + * @return: java.util.List + * @author: zhanglinhao + * @date: 2024/5/11 16:28 + */ + @Override + public List getEListByPhone(String phone) { + System.out.println("查询"+phone+"的评论"); + return evaluateRepository.findByEditorPhone(phone); + } /** * @description: 添加评论 @@ -43,4 +55,6 @@ public class evaluateServiceImpl implements evaluateService { evaluateRepository.save(evaluation); System.out.println("添加评论" + evaluation.getEbody()); } + + } diff --git a/src/后端/java/Login/controller/LoginController.java b/src/后端/java/Login/controller/LoginController.java index ad174e4..8b5c5fc 100644 --- a/src/后端/java/Login/controller/LoginController.java +++ b/src/后端/java/Login/controller/LoginController.java @@ -34,15 +34,16 @@ public class LoginController { 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()); + int tag = loginService.loginAccount(map.get("name").toString(), map.get("password").toString()); System.out.println("LoginTag:"+tag); return switch (tag) { case 1000 -> 1;//登陆成功 case 1001 -> 2;//密码或账号错误 case 1002 -> 3;//该账户未注册 - case 1005 -> 4;//未输入账号密码 - case 1006 -> 6;//未输入账号 - case 1007 -> 7;//未输入密码 + case 1005 -> 6;//未输入账号密码 + case 1006 -> 7;//未输入账号 + case 1007 -> 8;//未输入密码 + case 1008 -> 9;//身份证输入错误 default -> 0; }; } @@ -56,7 +57,8 @@ public class LoginController { */ @PostMapping("register") public int Register(@RequestBody Map map) { - int tag = loginService.registerAccount(map.get("username").toString(), map.get("password").toString()); + 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); return switch (tag) { case 1003 -> 4;//该账户已经注册 diff --git a/src/后端/java/Login/service/LoginService.java b/src/后端/java/Login/service/LoginService.java index 10b599c..ba67c50 100644 --- a/src/后端/java/Login/service/LoginService.java +++ b/src/后端/java/Login/service/LoginService.java @@ -10,17 +10,11 @@ import org.springframework.stereotype.Service; @Service public interface LoginService { int loginAccount(String phone, String password);//登录 - int registerAccount(String phone, String password); +// int registerAccount(String phone, String password); -// int registerAccount(String name, -// String email, -// String password, -// String createtime, -// int reputation, -// String phone, -// String nickname, -// String IDCard, -// boolean gender, -// boolean type, -// int status);//注册 + int registerAccount(String name, + String password, + String phone, + String nickname, + String IDCard);//注册 } diff --git a/src/后端/java/Login/service/LoginServiceImpl.java b/src/后端/java/Login/service/LoginServiceImpl.java index c276f6e..9c61ccc 100644 --- a/src/后端/java/Login/service/LoginServiceImpl.java +++ b/src/后端/java/Login/service/LoginServiceImpl.java @@ -5,6 +5,7 @@ import com.softegg.freetogo.User.service.UsersService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; import java.util.Objects; /** @@ -44,22 +45,43 @@ public class LoginServiceImpl implements LoginService { /** * @description: 注册接口实现函数,根据返回码进行操作 - * @param: phone + * @param: name * @param: password + * @param: phone + * @param: nickname + * @param: IDCard * @return: int * @author: zhanglinhao - * @date: 2024/5/9 22:47 + * @date: 2024/5/11 15:57 */ @Override - public int registerAccount(String phone, String password) { + public int registerAccount(String name, + String password, + String phone, + String nickname, + String IDCard) { if (usersService.isRegister(phone)) return 1003;//该账户已经注册 + else if(IDCard.length()!=18) + return 1008;//身份证输入错误 else { + LocalDateTime currentTime = LocalDateTime.now(); + 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.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; + } } diff --git a/src/后端/java/Login/返回码.txt b/src/后端/java/Login/返回码.txt new file mode 100644 index 0000000..d967fb2 --- /dev/null +++ b/src/后端/java/Login/返回码.txt @@ -0,0 +1,9 @@ +1000->1 登录成功 +1001->2 密码或账号错误 +1002->3 该账户未注册 +1003->4 该账户已经注册 +1004->5 注册成功 +1005->6 未输入账号密码 +1006->7 未输入账号 +1007->8 身份证输入错误 +1008->9 \ No newline at end of file -- 2.34.1 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 3/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AF=84=E4=BB=B7?= =?UTF-8?q?=E6=8E=A7=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!"; } } -- 2.34.1 From 15c58339fc7280d5e1e446809899669556d33320 Mon Sep 17 00:00:00 2001 From: zhanglinhao <1260788704@qq.com> Date: Mon, 13 May 2024 09:28:03 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AF=84=E4=BB=B7control?= =?UTF-8?q?ler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/Evaluate/Dao/EvaluateRepository.java | 2 + .../java/Evaluate/bean/Evaluations.java | 18 ++++---- .../controller/EvaluationController.java | 45 ++++++++++++++++++- .../Evaluate/service/evaluateService.java | 2 + .../Evaluate/service/evaluateServiceImpl.java | 14 +++++- .../java/User/controller/UsersController.java | 2 +- 6 files changed, 71 insertions(+), 12 deletions(-) diff --git a/src/后端/java/Evaluate/Dao/EvaluateRepository.java b/src/后端/java/Evaluate/Dao/EvaluateRepository.java index 60b0104..94a675a 100644 --- a/src/后端/java/Evaluate/Dao/EvaluateRepository.java +++ b/src/后端/java/Evaluate/Dao/EvaluateRepository.java @@ -12,4 +12,6 @@ import java.util.List; */ public interface EvaluateRepository extends JpaRepository { List findByEditorPhone(String phone); + + List findByEditedPhone(String phone); } diff --git a/src/后端/java/Evaluate/bean/Evaluations.java b/src/后端/java/Evaluate/bean/Evaluations.java index e1ac580..d90b359 100644 --- a/src/后端/java/Evaluate/bean/Evaluations.java +++ b/src/后端/java/Evaluate/bean/Evaluations.java @@ -20,19 +20,21 @@ import lombok.Setter; public class Evaluations { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private int eid; + private int eid;//评价id @Column(name = "etorname") - private String editorName; + private String editorName;//评价者姓名 @Column(name = "etorphone") - private String editorPhone; + private String editorPhone;//评价者电话 @Column(name = "etedname") - private String editedName; + private String editedName;//被评价者姓名 @Column(name = "etedphone") - private String editedPhone; + private String editedPhone;//被评价者电话 @Column(name = "createtime") - private String ct; + private String ct;//创建日期 @Column(name = "modifytime") - private String mt; + private String mt;//编辑日期 @Column - private String ebody; + private String ebody;//评价本体 + @Column + private int satisfaction;//满意度整数1-5 } diff --git a/src/后端/java/Evaluate/controller/EvaluationController.java b/src/后端/java/Evaluate/controller/EvaluationController.java index 26f12db..0fa15e9 100644 --- a/src/后端/java/Evaluate/controller/EvaluationController.java +++ b/src/后端/java/Evaluate/controller/EvaluationController.java @@ -45,7 +45,7 @@ public class EvaluationController { } /** - * @description: 通过手机获取评价 + * @description: 获取该用户对别人的评价 * @param: phone * @return: java.util.List * @author: zhanglinhao @@ -55,4 +55,47 @@ public class EvaluationController { public List evaluationByPhone(String phone) { return evaluateService.getEListByPhone(phone); } + + /** + * @description: 编辑评论 + * @param: eid + * @param: ebody + * @return: void + * @author: zhanglinhao + * @date: 2024/5/12 13:31 + */ + @GetMapping("editEvaluation") + public void editEvaluation(int eid, String ebody) { + evaluateService.editEvaluation(eid, ebody); + } + + /** + * @description: 删除评论 + * @param: eid + * @return: void + * @author: zhanglinhao + * @date: 2024/5/12 13:32 + */ + @GetMapping("deleteEvaluation") + public void deleteEvaluation(int eid) { + evaluateService.deleteEvaluation(eid); + } + + /** + * @description: 获取该用户的受满意程度 + * @param: phone + * @return: int + * @author: zhanglinhao + * @date: 2024/5/12 13:39 + */ + @GetMapping("getSatisfaction") + public String getSatisfaction(String phone) { + List elist = evaluateService.getEvaluatedByPhone(phone); + float sumOfSatisfaction = 0; + for (Evaluations evaluation : elist) { + sumOfSatisfaction += evaluation.getSatisfaction(); + } + System.out.println("查询满意度:"+ sumOfSatisfaction); + return Float.toString(sumOfSatisfaction /elist.size()); + } } diff --git a/src/后端/java/Evaluate/service/evaluateService.java b/src/后端/java/Evaluate/service/evaluateService.java index 2276f83..1c1abca 100644 --- a/src/后端/java/Evaluate/service/evaluateService.java +++ b/src/后端/java/Evaluate/service/evaluateService.java @@ -16,6 +16,8 @@ public interface EvaluateService { List getEListByPhone(String phone);//根据电话筛选评价 + List getEvaluatedByPhone(String phone); + void addEvaluation(Evaluations evaluation);//添加评论 void editEvaluation(int eid, String ebody);//编辑评论 diff --git a/src/后端/java/Evaluate/service/evaluateServiceImpl.java b/src/后端/java/Evaluate/service/evaluateServiceImpl.java index 26dfcdf..283563a 100644 --- a/src/后端/java/Evaluate/service/evaluateServiceImpl.java +++ b/src/后端/java/Evaluate/service/evaluateServiceImpl.java @@ -45,6 +45,18 @@ public class EvaluateServiceImpl implements EvaluateService { return evaluateRepository.findByEditorPhone(phone); } + /** + * @description: 获取该用户所有被他人评价的评价 + * @param: phone + * @return: java.util.List + * @author: zhanglinhao + * @date: 2024/5/12 21:21 + */ + @Override + public List getEvaluatedByPhone(String phone) { + return evaluateRepository.findByEditedPhone(phone); + } + /** * @description: 添加评论 * @param: evaluation @@ -89,6 +101,4 @@ public class EvaluateServiceImpl implements EvaluateService { evaluateRepository.deleteById(eid); System.out.println("删除评论:" + eid); } - - } diff --git a/src/后端/java/User/controller/UsersController.java b/src/后端/java/User/controller/UsersController.java index 6dd1ccd..f2b1e4c 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; -- 2.34.1