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

Merge branch 'backend'

This commit is contained in:
程序员小墨 2022-11-21 22:06:34 +08:00
commit 2a147b39a5
23 changed files with 517 additions and 519 deletions

2
.gitignore vendored
View File

@ -13,3 +13,5 @@
# 自定义
.vscode
ignore/*

View File

@ -170,9 +170,9 @@
## 启动项目
### 后端
### Step1. 启动项目后端
#### 启动nacos
#### 1.启动nacos
Nacos下载地址https://github.com/alibaba/nacos/releases/tag/2.1.2
@ -190,9 +190,17 @@ startup.cmd -m standalone
Nacos后台默认用户名密码都是**nacos**
#### 2.启动MySQL
### 前端
#### 3.启动各个微服务
### Step2. 启动项目前端
#### 1.启动后台管理员项目
代码克隆下来后,第一次需要安装依赖
@ -209,7 +217,9 @@ cnpm install
npm run serve
```
#### 2.小程序打包
待更新

1
TODOs.md Normal file
View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
package com.cxyxiaomo.epp.index.controller;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

View File

@ -1,7 +1,7 @@
package com.cxyxiaomo.epp.index.controller;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

View File

@ -1,6 +1,6 @@
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

View File

@ -1,7 +1,7 @@
package com.cxyxiaomo.epp.index.controller;
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 org.springframework.beans.factory.annotation.Autowired;
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;
import com.cxyxiaomo.epp.index.dao.ReportDao;
import com.cxyxiaomo.epp.index.dao.UserDao;
import com.cxyxiaomo.epp.pojo.Report;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -15,21 +14,24 @@ public class ReportServiceImpl implements ReportService {
@Autowired
private ReportDao reportDao;
@Autowired
private UserDao userDao;
// TODO
// @Autowired
// private UserDao userDao;
@Override
public int doReport(Report report) {
if(!report.getNormal().equals("发热") || !report.getIsolation().equals("无需隔离")){
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(),"1999-01-01");
}
return reportDao.doReport(report);
// TODO
// if(!report.getNormal().equals("发热") || !report.getIsolation().equals("无需隔离")){
// 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(),"1999-01-01");
// }
// return reportDao.doReport(report);
return 0;
}
@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;
import com.cxyxiaomo.epp.pojo.Res;
import com.cxyxiaomo.epp.common.Res;
import com.cxyxiaomo.epp.visitor.service.VisitorService;
import com.cxyxiaomo.epp.pojo.Visitor;
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;
import com.cxyxiaomo.epp.common.Res;
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 org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
// 提供 restful 服务
@RestController
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserServiceImpl userService;
@PostMapping("/user/add")
public boolean addUser(User user) {
return userService.addUser(user);
@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("该用户名不存在");
}
}
@GetMapping("/user/get/{id}")
public User getUserById(@PathVariable("id") Long id) {
return userService.getUserById(id);
@RequestMapping("/person")
@ResponseBody
public User person(String username){
return userService.getUserByUsername(username);
}
@GetMapping("/user/list")
public List<User> addUser() {
return userService.getUserList();
@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

@ -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 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 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() {
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 * FROM user
</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>

File diff suppressed because one or more lines are too long