1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

User相关逻辑移动到user微服务下(可以运行但是需要修改);数据库user表字段调整

This commit is contained in:
程序员小墨 2022-11-06 00:51:57 +08:00
parent 7ec7fc1e4f
commit 267e340ce8
22 changed files with 505 additions and 517 deletions

View File

@ -172,7 +172,7 @@
### 后端 ### 后端
#### 启动nacos #### 1.启动nacos
Nacos下载地址https://github.com/alibaba/nacos/releases/tag/2.1.2 Nacos下载地址https://github.com/alibaba/nacos/releases/tag/2.1.2
@ -190,6 +190,8 @@ startup.cmd -m standalone
Nacos后台默认用户名密码都是**nacos** Nacos后台默认用户名密码都是**nacos**
#### 2.启动各个微服务
### 前端 ### 前端

1
TODOs.md Normal file
View File

@ -0,0 +1 @@
数据库中的User表字段有修改需要在后端代码中同步进行修改

View File

@ -15,6 +15,13 @@ spring:
enabled: true enabled: true
lower-case-service-id: true lower-case-service-id: true
routes: routes:
- id: user
uri: lb://microservice-provider-user
predicates:
- Path=/user/**
filters:
- StripPrefix=1
- id: test1 - id: test1
uri: lb://microservice-provider-test uri: lb://microservice-provider-test
predicates: predicates:

View File

@ -1,4 +1,4 @@
package com.cxyxiaomo.epp.pojo; package com.cxyxiaomo.epp.common;
import lombok.Data; import lombok.Data;

View File

@ -1,7 +1,7 @@
package com.cxyxiaomo.epp.index.controller; package com.cxyxiaomo.epp.index.controller;
import com.cxyxiaomo.epp.pojo.Apply; import com.cxyxiaomo.epp.pojo.Apply;
import com.cxyxiaomo.epp.pojo.Res; import com.cxyxiaomo.epp.common.Res;
import com.cxyxiaomo.epp.index.service.ApplyService; import com.cxyxiaomo.epp.index.service.ApplyService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;

View File

@ -1,7 +1,7 @@
package com.cxyxiaomo.epp.index.controller; package com.cxyxiaomo.epp.index.controller;
import com.cxyxiaomo.epp.pojo.Notice; import com.cxyxiaomo.epp.pojo.Notice;
import com.cxyxiaomo.epp.pojo.Res; import com.cxyxiaomo.epp.common.Res;
import com.cxyxiaomo.epp.index.service.NoticeService; import com.cxyxiaomo.epp.index.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;

View File

@ -1,6 +1,6 @@
package com.cxyxiaomo.epp.index.controller; package com.cxyxiaomo.epp.index.controller;
import com.cxyxiaomo.epp.pojo.Res; import com.cxyxiaomo.epp.common.Res;
import com.cxyxiaomo.epp.index.service.OtherService; import com.cxyxiaomo.epp.index.service.OtherService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;

View File

@ -1,7 +1,7 @@
package com.cxyxiaomo.epp.index.controller; package com.cxyxiaomo.epp.index.controller;
import com.cxyxiaomo.epp.pojo.Report; import com.cxyxiaomo.epp.pojo.Report;
import com.cxyxiaomo.epp.pojo.Res; import com.cxyxiaomo.epp.common.Res;
import com.cxyxiaomo.epp.index.service.ReportService; import com.cxyxiaomo.epp.index.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;

View File

@ -1,87 +0,0 @@
package com.cxyxiaomo.epp.index.controller;
import com.cxyxiaomo.epp.pojo.Res;
import com.cxyxiaomo.epp.pojo.User;
import com.cxyxiaomo.epp.index.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/login")
@ResponseBody
public Res login(String username, String password){
User user = userService.getUserByUsername(username);
if (user!=null){
if (user.getPassword().equals(password)){
return Res.success(user);
}else {
return Res.error("密码错误");
}
}else{
return Res.error("该用户名不存在");
}
}
@RequestMapping("/person")
@ResponseBody
public User person(String username){
return userService.getUserByUsername(username);
}
@RequestMapping("/updateImg")
@ResponseBody
public String updateImg(Integer id,String img){
if (userService.updateImg(id,img) != 0){
return "修改成功";
}else{
return "修改失败";
}
}
@RequestMapping("/updPwd")
@ResponseBody
public String updPwd(String username,String pwd1,String pwd2){
User user = userService.getUserByUsername(username);
if (user.getPassword().equals(pwd1)){
userService.updPwd(username, pwd2);
return "请重新登录";
}else {
return "原密码错误";
}
}
@RequestMapping("/redCodeList")
@ResponseBody
public Res redCodeList(){
return Res.success(userService.redCodeList());
}
@RequestMapping("/redCodeList2")
@ResponseBody
public Res redCodeList2(){
return Res.success(userService.redCodeList2());
}
@RequestMapping("/addUser")
@ResponseBody
public Res addUser(String username,String name,Integer role){
User user = new User();
user.setUsername(username);
user.setPassword(username);
user.setName(name);
if (role == 2){
user.setStu_id(username);
}
user.setRole(role);
return Res.success(userService.addUser(user));
}
}

View File

@ -1,28 +0,0 @@
package com.cxyxiaomo.epp.index.dao;
import com.cxyxiaomo.epp.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface UserDao {
List<User> selectAll();
User getUser(String username,String role);
User getUserByUsername(String username);
int updateImg(Integer id,String img);
int updPwd(String username, String pwd2);
int updState(Integer id, String date);
List<User> redCodeList();
List<User> redCodeList2();
int addUser(User user);
}

View File

@ -1,7 +1,6 @@
package com.cxyxiaomo.epp.index.service; package com.cxyxiaomo.epp.index.service;
import com.cxyxiaomo.epp.index.dao.ReportDao; import com.cxyxiaomo.epp.index.dao.ReportDao;
import com.cxyxiaomo.epp.index.dao.UserDao;
import com.cxyxiaomo.epp.pojo.Report; import com.cxyxiaomo.epp.pojo.Report;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -15,21 +14,24 @@ public class ReportServiceImpl implements ReportService {
@Autowired @Autowired
private ReportDao reportDao; private ReportDao reportDao;
@Autowired
private UserDao userDao; // TODO
// @Autowired
// private UserDao userDao;
@Override @Override
public int doReport(Report report) { public int doReport(Report report) {
if(!report.getNormal().equals("发热") || !report.getIsolation().equals("无需隔离")){ // TODO
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); // if(!report.getNormal().equals("发热") || !report.getIsolation().equals("无需隔离")){
String date = formatter.format(new Date()) ; // SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
// 修改用户状态 // String date = formatter.format(new Date()) ;
userDao.updState(report.getUser_id(),date); // // 修改用户状态
}else{ // userDao.updState(report.getUser_id(),date);
userDao.updState(report.getUser_id(),"1999-01-01"); // }else{
} // userDao.updState(report.getUser_id(),"1999-01-01");
return reportDao.doReport(report); // }
// return reportDao.doReport(report);
return 0;
} }
@Override @Override

View File

@ -1,23 +0,0 @@
package com.cxyxiaomo.epp.index.service;
import com.cxyxiaomo.epp.pojo.User;
import java.util.List;
public interface UserService {
User getUser(String username, String role);
User getUserByUsername(String username);
int updateImg(Integer id,String img);
int updPwd(String username,String pwd2);
List<User> redCodeList();
List<User> redCodeList2();
String addUser(User user);
}

View File

@ -1,55 +0,0 @@
package com.cxyxiaomo.epp.index.service;
import com.cxyxiaomo.epp.index.dao.UserDao;
import com.cxyxiaomo.epp.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
@Override
public User getUser(String username, String role) {
return userDao.getUser(username, role);
}
@Override
public User getUserByUsername(String username) {
return userDao.getUserByUsername(username);
}
@Override
public int updateImg(Integer id, String img) {
return userDao.updateImg(id,img);
}
@Override
public int updPwd(String username, String pwd2) {
return userDao.updPwd(username, pwd2);
}
@Override
public List<User> redCodeList() {
return userDao.redCodeList();
}
@Override
public List<User> redCodeList2() {
return userDao.redCodeList2();
}
@Override
public String addUser(User user) {
if (userDao.getUserByUsername(user.getUsername()) == null){
userDao.addUser(user);
return "添加成功";
}else{
return "该用户已存在";
}
}
}

View File

@ -1,6 +1,6 @@
package com.cxyxiaomo.epp.visitor.controller; package com.cxyxiaomo.epp.visitor.controller;
import com.cxyxiaomo.epp.pojo.Res; import com.cxyxiaomo.epp.common.Res;
import com.cxyxiaomo.epp.visitor.service.VisitorService; import com.cxyxiaomo.epp.visitor.service.VisitorService;
import com.cxyxiaomo.epp.pojo.Visitor; import com.cxyxiaomo.epp.pojo.Visitor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,38 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cxyxiaomo.epp.index.dao.UserDao">
<insert id="addUser">
insert into user
(username, name, password, role, stu_id) values
(#{username},#{name},#{password},#{role},#{stu_id})
</insert>
<update id="updateImg">
update user set img = #{img}
where id = #{id}
</update>
<update id="updPwd">
update user set password = #{pwd2}
where username = #{username}
</update>
<update id="updState">
update user set state = #{date}
where id = #{id}
</update>
<select id="selectAll" resultType="com.cxyxiaomo.epp.pojo.User">
select * from `user`
</select>
<select id="getUserByUsername" resultType="com.cxyxiaomo.epp.pojo.User">
select * from user where username = #{username}
</select>
<select id="getUser" resultType="com.cxyxiaomo.epp.pojo.User">
select * from user where username = #{username} and role_id = #{role}
</select>
<select id="redCodeList" resultType="com.cxyxiaomo.epp.pojo.User">
select name,stu_id from user where TO_DAYS(NOW( )) != TO_DAYS(state) and role = 2
</select>
<select id="redCodeList2" resultType="com.cxyxiaomo.epp.pojo.User">
select name,stu_id from user where state = "1999-01-01"
</select>
</mapper>

View File

@ -1,32 +1,87 @@
package com.cxyxiaomo.epp.controller; package com.cxyxiaomo.epp.controller;
import com.cxyxiaomo.epp.common.Res;
import com.cxyxiaomo.epp.pojo.User; import com.cxyxiaomo.epp.pojo.User;
import com.cxyxiaomo.epp.service.UserServiceImpl; import com.cxyxiaomo.epp.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List; @Controller
@RequestMapping("/user")
// 提供 restful 服务
@RestController
public class UserController { public class UserController {
@Autowired @Autowired
private UserServiceImpl userService; private UserServiceImpl userService;
@PostMapping("/user/add") @RequestMapping("/login")
public boolean addUser(User user) { @ResponseBody
return userService.addUser(user); public Res login(String username, String password){
User user = userService.getUserByUsername(username);
if (user!=null){
if (user.getPassword().equals(password)){
return Res.success(user);
}else {
return Res.error("密码错误");
}
}else{
return Res.error("该用户名不存在");
}
} }
@GetMapping("/user/get/{id}") @RequestMapping("/person")
public User getUserById(@PathVariable("id") Long id) { @ResponseBody
return userService.getUserById(id); public User person(String username){
return userService.getUserByUsername(username);
} }
@GetMapping("/user/list") @RequestMapping("/updateImg")
public List<User> addUser() { @ResponseBody
return userService.getUserList(); public String updateImg(Integer id,String img){
if (userService.updateImg(id,img) != 0){
return "修改成功";
}else{
return "修改失败";
}
}
@RequestMapping("/updPwd")
@ResponseBody
public String updPwd(String username,String pwd1,String pwd2){
User user = userService.getUserByUsername(username);
if (user.getPassword().equals(pwd1)){
userService.updPwd(username, pwd2);
return "请重新登录";
}else {
return "原密码错误";
}
}
@RequestMapping("/redCodeList")
@ResponseBody
public Res redCodeList(){
return Res.success(userService.redCodeList());
}
@RequestMapping("/redCodeList2")
@ResponseBody
public Res redCodeList2(){
return Res.success(userService.redCodeList2());
}
@RequestMapping("/addUser")
@ResponseBody
public Res addUser(String username,String name,Integer role){
User user = new User();
user.setUsername(username);
user.setPassword(username);
user.setName(name);
if (role == 2){
user.setStu_id(username);
}
user.setRole(role);
return Res.success(userService.addUser(user));
} }
} }

View File

@ -0,0 +1,32 @@
package com.cxyxiaomo.epp.controller;
import com.cxyxiaomo.epp.pojo.User;
import com.cxyxiaomo.epp.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
// 提供 restful 服务
@RestController
public class UserControllerOld {
@Autowired
private UserServiceImpl userService;
@PostMapping("/user/add")
public boolean addUser(User user) {
return userService.addUser(user);
}
@GetMapping("/user/get/{id}")
public User getUserById(@PathVariable("id") Long id) {
return userService.getUserById(id);
}
@GetMapping("/user/list")
public List<User> addUser() {
return userService.getUserList();
}
}

View File

@ -15,4 +15,25 @@ public interface UserDao {
public User getUserById(Long id); public User getUserById(Long id);
public List<User> getUserList(); public List<User> getUserList();
List<User> selectAll();
User getUser(String username,String role);
User getUserByUsername(String username);
int updateImg(Integer id,String img);
int updPwd(String username, String pwd2);
int updState(Integer id, String date);
List<User> redCodeList();
List<User> redCodeList2();
int addUser2(User user);
} }

View File

@ -11,4 +11,23 @@ public interface UserService {
public User getUserById(Long id); public User getUserById(Long id);
public List<User> getUserList(); public List<User> getUserList();
User getUser(String username, String role);
User getUserByUsername(String username);
int updateImg(Integer id,String img);
int updPwd(String username,String pwd2);
List<User> redCodeList();
List<User> redCodeList2();
String addUser2(User user);
} }

View File

@ -27,4 +27,48 @@ public class UserServiceImpl implements UserService {
public List<User> getUserList() { public List<User> getUserList() {
return userDao.getUserList(); return userDao.getUserList();
} }
@Override
public User getUser(String username, String role) {
return userDao.getUser(username, role);
}
@Override
public User getUserByUsername(String username) {
return userDao.getUserByUsername(username);
}
@Override
public int updateImg(Integer id, String img) {
return userDao.updateImg(id,img);
}
@Override
public int updPwd(String username, String pwd2) {
return userDao.updPwd(username, pwd2);
}
@Override
public List<User> redCodeList() {
return userDao.redCodeList();
}
@Override
public List<User> redCodeList2() {
return userDao.redCodeList2();
}
@Override
public String addUser2(User user) {
if (userDao.getUserByUsername(user.getUsername()) == null){
userDao.addUser2(user);
return "添加成功";
}else{
return "该用户已存在";
}
}
} }

View File

@ -17,4 +17,40 @@
<select id="getUserList" resultType="com.cxyxiaomo.epp.pojo.User"> <select id="getUserList" resultType="com.cxyxiaomo.epp.pojo.User">
SELECT * FROM user SELECT * FROM user
</select> </select>
<insert id="addUser2">
insert into user
(username, name, password, role, stu_id) values
(#{username},#{name},#{password},#{role},#{stu_id})
</insert>
<update id="updateImg">
update user set img = #{img}
where id = #{id}
</update>
<update id="updPwd">
update user set password = #{pwd2}
where username = #{username}
</update>
<update id="updState">
update user set state = #{date}
where id = #{id}
</update>
<select id="selectAll" resultType="com.cxyxiaomo.epp.pojo.User">
select * from `user`
</select>
<select id="getUserByUsername" resultType="com.cxyxiaomo.epp.pojo.User">
select * from user where username = #{username}
</select>
<select id="getUser" resultType="com.cxyxiaomo.epp.pojo.User">
select * from user where username = #{username} and role_id = #{role}
</select>
<select id="redCodeList" resultType="com.cxyxiaomo.epp.pojo.User">
select name,stu_id from user where TO_DAYS(NOW( )) != TO_DAYS(state) and role = 2
</select>
<select id="redCodeList2" resultType="com.cxyxiaomo.epp.pojo.User">
select name,stu_id from user where state = "1999-01-01"
</select>
</mapper> </mapper>

File diff suppressed because one or more lines are too long