更新后端代码

pull/11/head
zhanglinhao 1 year ago
parent ded46a1389
commit d6932b75e1

@ -3,10 +3,13 @@ package com.softegg.freetogo.Evaluate.Dao;
import com.softegg.freetogo.Evaluate.bean.Evaluations; import com.softegg.freetogo.Evaluate.bean.Evaluations;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/** /**
* @description: Jpa * @description: Jpa
* @author: zhanglinhao * @author: zhanglinhao
* @date: 2024/5/10 9:27 * @date: 2024/5/10 9:27
*/ */
public interface EvaluateRepository extends JpaRepository<Evaluations, Integer> { public interface EvaluateRepository extends JpaRepository<Evaluations, Integer> {
List<Evaluations> findByEditorPhone(String phone);
} }

@ -13,5 +13,7 @@ import java.util.List;
@Service @Service
public interface evaluateService { public interface evaluateService {
List<Evaluations> evaluationList();//获取所有评论 List<Evaluations> evaluationList();//获取所有评论
List<Evaluations> getEListByPhone(String phone);//根据电话筛选评价
void addEvaluation(Evaluations evaluation);//添加评论 void addEvaluation(Evaluations evaluation);//添加评论
} }

@ -30,6 +30,18 @@ public class evaluateServiceImpl implements evaluateService {
System.out.println("查询评论"); System.out.println("查询评论");
return evaluateRepository.findAll(); 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: * @description:
@ -43,4 +55,6 @@ public class evaluateServiceImpl implements evaluateService {
evaluateRepository.save(evaluation); evaluateRepository.save(evaluation);
System.out.println("添加评论" + evaluation.getEbody()); System.out.println("添加评论" + evaluation.getEbody());
} }
} }

@ -34,15 +34,16 @@ public class LoginController {
System.out.println(map); System.out.println(map);
System.out.println("phone:"+map.get("phone").toString()); System.out.println("phone:"+map.get("phone").toString());
System.out.println("password"+map.get("password").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); System.out.println("LoginTag:"+tag);
return switch (tag) { return switch (tag) {
case 1000 -> 1;//登陆成功 case 1000 -> 1;//登陆成功
case 1001 -> 2;//密码或账号错误 case 1001 -> 2;//密码或账号错误
case 1002 -> 3;//该账户未注册 case 1002 -> 3;//该账户未注册
case 1005 -> 4;//未输入账号密码 case 1005 -> 6;//未输入账号密码
case 1006 -> 6;//未输入账号 case 1006 -> 7;//未输入账号
case 1007 -> 7;//未输入密码 case 1007 -> 8;//未输入密码
case 1008 -> 9;//身份证输入错误
default -> 0; default -> 0;
}; };
} }
@ -56,7 +57,8 @@ public class LoginController {
*/ */
@PostMapping("register") @PostMapping("register")
public int Register(@RequestBody Map<String, Object> map) { public int Register(@RequestBody Map<String, Object> 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); System.out.println("RegisterTag:"+tag);
return switch (tag) { return switch (tag) {
case 1003 -> 4;//该账户已经注册 case 1003 -> 4;//该账户已经注册

@ -10,17 +10,11 @@ import org.springframework.stereotype.Service;
@Service @Service
public interface LoginService { public interface LoginService {
int loginAccount(String phone, String password);//登录 int loginAccount(String phone, String password);//登录
int registerAccount(String phone, String password); // int registerAccount(String phone, String password);
// int registerAccount(String name, int registerAccount(String name,
// String email, String password,
// String password, String phone,
// String createtime, String nickname,
// int reputation, String IDCard);//注册
// String phone,
// String nickname,
// String IDCard,
// boolean gender,
// boolean type,
// int status);//注册
} }

@ -5,6 +5,7 @@ import com.softegg.freetogo.User.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.Objects; import java.util.Objects;
/** /**
@ -44,22 +45,43 @@ public class LoginServiceImpl implements LoginService {
/** /**
* @description: * @description:
* @param: phone * @param: name
* @param: password * @param: password
* @param: phone
* @param: nickname
* @param: IDCard
* @return: int * @return: int
* @author: zhanglinhao * @author: zhanglinhao
* @date: 2024/5/9 22:47 * @date: 2024/5/11 15:57
*/ */
@Override @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)) if (usersService.isRegister(phone))
return 1003;//该账户已经注册 return 1003;//该账户已经注册
else if(IDCard.length()!=18)
return 1008;//身份证输入错误
else { else {
LocalDateTime currentTime = LocalDateTime.now();
System.out.println("注册信息:姓名:"+name+"密码:"+password+"电话:"+phone+"昵称:"+nickname+"身份证:"+IDCard);
Users user = new Users(); Users user = new Users();
user.setPhone(phone); user.setPhone(phone);
user.setPassword(password); 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); usersService.add(user);
return 1004;//注册成功 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
Loading…
Cancel
Save