更新代码 #12

Closed
mwxbgi697 wants to merge 4 commits from zhanglinhao_branch into develop

@ -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("*");
}

@ -3,10 +3,15 @@ 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<Evaluations, Integer> {
List<Evaluations> findByEditorPhone(String phone);
List<Evaluations> findByEditedPhone(String phone);
}

@ -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
}

@ -0,0 +1,101 @@
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<com.softegg.freetogo.Evaluate.bean.Evaluations>
* @author: zhanglinhao
* @date: 2024/5/12 0:11
*/
@GetMapping("findAllEvaluation")
public List<Evaluations> findAllEvaluation() {
return evaluateService.evaluationList();
}
/**
* @description:
* @param: ebody
* @return: void
* @author: zhanglinhao
* @date: 2024/5/12 0:28
*/
@PostMapping("addEvaluation")
public void addEvaluation(@RequestBody Map<String, Evaluations> ebody) {
Evaluations evaluation = ebody.get("evaluation");
evaluateService.addEvaluation(evaluation);
}
/**
* @description:
* @param: phone
* @return: java.util.List<com.softegg.freetogo.Evaluate.bean.Evaluations>
* @author: zhanglinhao
* @date: 2024/5/12 0:30
*/
@GetMapping("evaluationByPhone")
public List<Evaluations> 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<Evaluations> elist = evaluateService.getEvaluatedByPhone(phone);
float sumOfSatisfaction = 0;
for (Evaluations evaluation : elist) {
sumOfSatisfaction += evaluation.getSatisfaction();
}
System.out.println("查询满意度:"+ sumOfSatisfaction);
return Float.toString(sumOfSatisfaction /elist.size());
}
}

@ -11,7 +11,16 @@ import java.util.List;
* @date:2024/5/10 8:52
*/
@Service
public interface evaluateService {
public interface EvaluateService {
List<Evaluations> evaluationList();//获取所有评论
List<Evaluations> getEListByPhone(String phone);//根据电话筛选评价
List<Evaluations> getEvaluatedByPhone(String phone);
void addEvaluation(Evaluations evaluation);//添加评论
void editEvaluation(int eid, String ebody);//编辑评论
void deleteEvaluation(int eid);//删除评论
}

@ -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;
@ -31,6 +32,31 @@ public class evaluateServiceImpl implements evaluateService {
return evaluateRepository.findAll();
}
/**
* @description:
* @param: phone
* @return: java.util.List<com.softegg.freetogo.Evaluate.bean.Evaluations>
* @author: zhanglinhao
* @date: 2024/5/11 16:28
*/
@Override
public List<Evaluations> getEListByPhone(String phone) {
System.out.println("查询" + phone + "的评论");
return evaluateRepository.findByEditorPhone(phone);
}
/**
* @description:
* @param: phone
* @return: java.util.List<com.softegg.freetogo.Evaluate.bean.Evaluations>
* @author: zhanglinhao
* @date: 2024/5/12 21:21
*/
@Override
public List<Evaluations> getEvaluatedByPhone(String phone) {
return evaluateRepository.findByEditedPhone(phone);
}
/**
* @description:
* @param: evaluation
@ -43,4 +69,36 @@ public class evaluateServiceImpl implements evaluateService {
evaluateRepository.save(evaluation);
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<Evaluations> 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);
}
}

@ -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 {

@ -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<String,Object> 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<String,Object> map){
return switch (loginService.registerAccount(map.get("username").toString(), map.get("password").toString())) {
case 1003 -> "已注册";
case 1004 -> "注册成功";
default -> 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);
}

@ -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;
}
}
}

@ -32,17 +32,18 @@ public class LoginController {
@PostMapping("login")
public int Login(@RequestBody Map<String, Object> map) {
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());
System.out.println("LoginTag:"+tag);
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);
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,8 +57,9 @@ public class LoginController {
*/
@PostMapping("register")
public int Register(@RequestBody Map<String, Object> map) {
int tag = loginService.registerAccount(map.get("username").toString(), map.get("password").toString());
System.out.println("RegisterTag:"+tag);
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;//该账户已经注册
case 1004 -> 5;//注册成功

@ -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);//注册
}

@ -5,7 +5,7 @@ import com.softegg.freetogo.User.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Objects;
import java.time.LocalDateTime;
/**
* @description:
@ -27,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))
@ -44,22 +44,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;
}
}

@ -0,0 +1,9 @@
1000->1 登录成功
1001->2 密码或账号错误
1002->3 该账户未注册
1003->4 该账户已经注册
1004->5 注册成功
1005->6 未输入账号密码
1006->7 未输入账号
1007->8 身份证输入错误
1008->9

@ -140,11 +140,21 @@ public class UsersController {
* @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");
public boolean pupdate(@RequestBody Map<String, Map<String, Object>> user) {
Map<String, Object> 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<String, Users> 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;
}

@ -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);
}
}

@ -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<Users> 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);
}
}

@ -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;
}

@ -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<Users> 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);
}
}

@ -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<Users, Integer> {
// @Query(value = "select * from users where phone = ?1",nativeQuery = true)
Users findByPhone(String phone);
}

@ -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<Users> 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);
}

@ -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!";
}
}

Loading…
Cancel
Save