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

后端用户登录接口完成

This commit is contained in:
程序员小墨 2022-11-23 20:37:35 +08:00
parent 46743b31b5
commit ac885b813f
64 changed files with 282 additions and 419 deletions

View File

@ -17,16 +17,25 @@ server.on("request", (req, res) => {
let result = {};
if (req.url.startsWith('/user/login')) {
result = {
code: 200,
status: 'success',
success: true,
msg: "登录成功",
data: {
userInfo: {
username: "张三",
userType: "user" // "admin" "user"
"id": 1,
"username": "root",
"realname": "管理员",
"idNumber": null,
"phoneNumber": null,
"role": 1,
"buildingId": null,
"doorplate": null,
"permission": "0",
"permissionTime": null
}
// status: 'failed',
}
// success: false,
// msg: "用户名或密码不正确",
// userInfo: null
// data: null
};
} else {
result = {

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
<file url="file://$PROJECT_DIR$/microservice-common/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/microservice-common/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/microservice-gateway/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/microservice-gateway/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/microservice-pojo/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/microservice-pojo/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/microservice-provider-miniprogram-8080/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/microservice-provider-miniprogram-8080/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/microservice-provider-test-8011/src/main/java" charset="UTF-8" />

View File

@ -6,6 +6,7 @@
<list>
<option value="$PROJECT_DIR$/pom.xml" />
<option value="$PROJECT_DIR$/microservice-api/pom.xml" />
<option value="$PROJECT_DIR$/microservice-common/pom.xml" />
</list>
</option>
</component>

View File

@ -2,7 +2,7 @@
<configuration default="false" name="Gateway" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
<option name="ACTIVE_PROFILES" />
<module name="microservice-gateway" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.cxyxiaomo.epp.Gateway" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.cxyxiaomo.epp.gateway.Gateway" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.cxyxiaomo.epp.*" />

View File

@ -2,7 +2,7 @@
<configuration default="false" name="MiniProgram" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
<option name="ACTIVE_PROFILES" />
<module name="microservice-provider-miniprogram-8080" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.cxyxiaomo.epp.Application" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.cxyxiaomo.epp.miniprogram.Application" />
<method v="2">
<option name="Make" enabled="true" />
</method>

View File

@ -2,7 +2,7 @@
<configuration default="false" name="TestProvider" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
<option name="ACTIVE_PROFILES" />
<module name="microservice-provider-test-8011" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.cxyxiaomo.epp.TestProvider" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.cxyxiaomo.epp.test.TestProvider" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.cxyxiaomo.epp.*" />

View File

@ -5,7 +5,7 @@
<env name="--spring.profiles.active" value="remote" />
</envs>
<module name="microservice-provider-user-8001" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.cxyxiaomo.epp.UserProvider" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.cxyxiaomo.epp.user.UserProvider" />
<option name="WORKING_DIRECTORY" value="file://$MODULE_WORKING_DIR$" />
<extension name="coverage">
<pattern>

View File

@ -9,7 +9,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>microservice-pojo</artifactId>
<artifactId>microservice-common</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -24,10 +24,9 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.3.22</version>
</dependency>
</dependencies>
</project>

View File

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

View File

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

View File

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

View File

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

View File

@ -1,10 +1,11 @@
package com.cxyxiaomo.epp.pojo;
package com.cxyxiaomo.epp.common.pojo;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
// 数据库关系映射
@ -15,10 +16,13 @@ import java.io.Serializable;
public class User implements Serializable {
private Integer id;
private String username;
private String name;
private String password;
private String img;
private String stu_id;
private String realname;
private String idNumber;
private String phoneNumber;
private Integer role;
private String state;
private String buildingId;
private String doorplate;
private String permission;
private LocalDateTime permissionTime;
}

View File

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

View File

@ -1,9 +1,10 @@
package com.cxyxiaomo.epp.common;
package com.cxyxiaomo.epp.common.response;
import lombok.Data;
@Data
public class Res<T> {
private Boolean success;
private String msg;
private T data;
@ -14,21 +15,24 @@ public class Res<T> {
this.data = data;
}
public static Res success(){
public static Res success() {
Res res = new Res<>();
res.setMsg("成功");
res.setMsg("操作成功");
res.setSuccess(true);
return res;
}
public static <T> Res<T> success(T data){
public static <T> Res<T> success(T data) {
Res<T> res = new Res<>(data);
res.setMsg("成功");
res.setMsg("操作成功");
res.setSuccess(true);
return res;
}
public static Res error(String msg){
public static Res error(String msg) {
Res res = new Res<>();
res.setMsg(msg);
res.setSuccess(false);
return res;
}
}

View File

@ -0,0 +1,11 @@
package com.cxyxiaomo.epp.common.utils;
import org.springframework.util.DigestUtils;
import java.io.UnsupportedEncodingException;
public class Hash {
public String getMd5(String text) throws UnsupportedEncodingException {
return DigestUtils.md5DigestAsHex(text.getBytes("utf-8"));
}
}

View File

@ -0,0 +1,38 @@
package com.cxyxiaomo.epp.common.vo;
import com.cxyxiaomo.epp.common.pojo.User;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import java.io.Serializable;
import java.time.LocalDateTime;
// 数据库关系映射
@Data
@NoArgsConstructor
@Accessors(chain = true) // 链式写法
// 微服务必须要实现Serializable
public class UserVO implements Serializable {
private Integer id;
private String username;
private String realname;
private String idNumber;
private String phoneNumber;
private Integer role;
private String buildingId;
private String doorplate;
private String permission;
private LocalDateTime permissionTime;
public static UserVO convertFrom(User user) {
if (user == null) {
return null;
}
UserVO userVO = new UserVO();
BeanUtils.copyProperties(user, userVO);
return userVO;
}
}

View File

@ -1,4 +1,4 @@
package com.cxyxiaomo.epp;
package com.cxyxiaomo.epp.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

View File

@ -1,4 +1,4 @@
package com.cxyxiaomo.epp.controller;
package com.cxyxiaomo.epp.gateway.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

View File

@ -19,8 +19,7 @@ spring:
uri: lb://microservice-provider-user
predicates:
- Path=/user/**
filters:
- StripPrefix=1
- Method=GET,POST
- id: test1
uri: lb://microservice-provider-test

View File

@ -1,4 +1,4 @@
package com.cxyxiaomo.epp;
package com.cxyxiaomo.epp.gateway;
import static org.junit.Assert.assertTrue;

View File

@ -1,4 +1,4 @@
package com.cxyxiaomo.epp;
package com.cxyxiaomo.epp.miniprogram;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

View File

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

View File

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

View File

@ -1,7 +1,7 @@
package com.cxyxiaomo.epp.index.controller;
package com.cxyxiaomo.epp.miniprogram.index.controller;
import com.cxyxiaomo.epp.common.Res;
import com.cxyxiaomo.epp.index.service.OtherService;
import com.cxyxiaomo.epp.common.response.Res;
import com.cxyxiaomo.epp.miniprogram.index.service.OtherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

View File

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

View File

@ -1,6 +1,6 @@
package com.cxyxiaomo.epp.index.dao;
package com.cxyxiaomo.epp.miniprogram.index.dao;
import com.cxyxiaomo.epp.pojo.Apply;
import com.cxyxiaomo.epp.common.pojo.Apply;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;

View File

@ -1,6 +1,6 @@
package com.cxyxiaomo.epp.index.dao;
package com.cxyxiaomo.epp.miniprogram.index.dao;
import com.cxyxiaomo.epp.pojo.Notice;
import com.cxyxiaomo.epp.common.pojo.Notice;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;

View File

@ -1,6 +1,6 @@
package com.cxyxiaomo.epp.index.dao;
package com.cxyxiaomo.epp.miniprogram.index.dao;
import com.cxyxiaomo.epp.pojo.Feedback;
import com.cxyxiaomo.epp.common.pojo.Feedback;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;

View File

@ -1,6 +1,6 @@
package com.cxyxiaomo.epp.index.dao;
package com.cxyxiaomo.epp.miniprogram.index.dao;
import com.cxyxiaomo.epp.pojo.Report;
import com.cxyxiaomo.epp.common.pojo.Report;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;

View File

@ -1,6 +1,6 @@
package com.cxyxiaomo.epp.index.service;
package com.cxyxiaomo.epp.miniprogram.index.service;
import com.cxyxiaomo.epp.pojo.Apply;
import com.cxyxiaomo.epp.common.pojo.Apply;
import java.util.List;

View File

@ -1,7 +1,7 @@
package com.cxyxiaomo.epp.index.service;
package com.cxyxiaomo.epp.miniprogram.index.service;
import com.cxyxiaomo.epp.index.dao.ApplyDao;
import com.cxyxiaomo.epp.pojo.Apply;
import com.cxyxiaomo.epp.common.pojo.Apply;
import com.cxyxiaomo.epp.miniprogram.index.dao.ApplyDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

View File

@ -1,6 +1,6 @@
package com.cxyxiaomo.epp.index.service;
package com.cxyxiaomo.epp.miniprogram.index.service;
import com.cxyxiaomo.epp.pojo.Notice;
import com.cxyxiaomo.epp.common.pojo.Notice;
import java.util.List;

View File

@ -1,7 +1,7 @@
package com.cxyxiaomo.epp.index.service;
package com.cxyxiaomo.epp.miniprogram.index.service;
import com.cxyxiaomo.epp.index.dao.NoticeDao;
import com.cxyxiaomo.epp.pojo.Notice;
import com.cxyxiaomo.epp.common.pojo.Notice;
import com.cxyxiaomo.epp.miniprogram.index.dao.NoticeDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

View File

@ -1,6 +1,6 @@
package com.cxyxiaomo.epp.index.service;
package com.cxyxiaomo.epp.miniprogram.index.service;
import com.cxyxiaomo.epp.pojo.Feedback;
import com.cxyxiaomo.epp.common.pojo.Feedback;
import java.util.List;

View File

@ -1,7 +1,7 @@
package com.cxyxiaomo.epp.index.service;
package com.cxyxiaomo.epp.miniprogram.index.service;
import com.cxyxiaomo.epp.index.dao.OtherDao;
import com.cxyxiaomo.epp.pojo.Feedback;
import com.cxyxiaomo.epp.common.pojo.Feedback;
import com.cxyxiaomo.epp.miniprogram.index.dao.OtherDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

View File

@ -1,6 +1,6 @@
package com.cxyxiaomo.epp.index.service;
package com.cxyxiaomo.epp.miniprogram.index.service;
import com.cxyxiaomo.epp.pojo.Report;
import com.cxyxiaomo.epp.common.pojo.Report;
import java.util.List;

View File

@ -1,12 +1,10 @@
package com.cxyxiaomo.epp.index.service;
package com.cxyxiaomo.epp.miniprogram.index.service;
import com.cxyxiaomo.epp.index.dao.ReportDao;
import com.cxyxiaomo.epp.pojo.Report;
import com.cxyxiaomo.epp.common.pojo.Report;
import com.cxyxiaomo.epp.miniprogram.index.dao.ReportDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Service

View File

@ -1,8 +1,8 @@
package com.cxyxiaomo.epp.visitor.controller;
package com.cxyxiaomo.epp.miniprogram.visitor.controller;
import com.cxyxiaomo.epp.common.Res;
import com.cxyxiaomo.epp.visitor.service.VisitorService;
import com.cxyxiaomo.epp.pojo.Visitor;
import com.cxyxiaomo.epp.common.response.Res;
import com.cxyxiaomo.epp.miniprogram.visitor.service.VisitorService;
import com.cxyxiaomo.epp.common.pojo.Visitor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

View File

@ -1,6 +1,6 @@
package com.cxyxiaomo.epp.visitor.dao;
package com.cxyxiaomo.epp.miniprogram.visitor.dao;
import com.cxyxiaomo.epp.pojo.Visitor;
import com.cxyxiaomo.epp.common.pojo.Visitor;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;

View File

@ -1,6 +1,6 @@
package com.cxyxiaomo.epp.visitor.service;
package com.cxyxiaomo.epp.miniprogram.visitor.service;
import com.cxyxiaomo.epp.pojo.Visitor;
import com.cxyxiaomo.epp.common.pojo.Visitor;
import java.util.List;

View File

@ -1,8 +1,8 @@
package com.cxyxiaomo.epp.visitor.service.impl;
package com.cxyxiaomo.epp.miniprogram.visitor.service.impl;
import com.cxyxiaomo.epp.pojo.Visitor;
import com.cxyxiaomo.epp.visitor.service.VisitorService;
import com.cxyxiaomo.epp.visitor.dao.VisitorDao;
import com.cxyxiaomo.epp.common.pojo.Visitor;
import com.cxyxiaomo.epp.miniprogram.visitor.service.VisitorService;
import com.cxyxiaomo.epp.miniprogram.visitor.dao.VisitorDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

View File

@ -15,12 +15,12 @@
<select id="lastApply" resultType="java.lang.Integer">
select * from apply where stu_id = #{id} and state = 0 limit 1
</select>
<select id="applyListNoReplay" resultType="com.cxyxiaomo.epp.pojo.Apply">
<select id="applyListNoReplay" resultType="com.cxyxiaomo.epp.common.pojo.Apply">
select a.*,u.name,u.stu_id as stuId from apply a
left join user u on a.stu_id = u.id
where a.state = 0
</select>
<select id="myApply" resultType="com.cxyxiaomo.epp.pojo.Apply">
<select id="myApply" resultType="com.cxyxiaomo.epp.common.pojo.Apply">
select a.*,u.name,u.stu_id as stuId from apply a
left join user u on a.stu_id = u.id
where a.stu_id = #{id}

View File

@ -10,7 +10,7 @@
<delete id="delNotice">
delete from notice where id = #{id}
</delete>
<select id="noticeList" resultType="com.cxyxiaomo.epp.pojo.Notice">
<select id="noticeList" resultType="com.cxyxiaomo.epp.common.pojo.Notice">
select * from notice order by time desc
<if test="limit!= ''">
limit ${limit}

View File

@ -11,7 +11,7 @@
update feedback set reply = #{replay}
where id = #{id}
</update>
<select id="feedbackList" resultType="com.cxyxiaomo.epp.pojo.Feedback">
<select id="feedbackList" resultType="com.cxyxiaomo.epp.common.pojo.Feedback">
select * from feedback
<where>
<if test="id != null">
@ -19,7 +19,7 @@
</if>
</where>
</select>
<select id="feedbackListNoReplay" resultType="com.cxyxiaomo.epp.pojo.Feedback">
<select id="feedbackListNoReplay" resultType="com.cxyxiaomo.epp.common.pojo.Feedback">
select * from feedback where reply is null
</select>
</mapper>

View File

@ -11,7 +11,7 @@
(#{user_id},#{name},#{address},#{time},#{normal},#{yes_noon_temp},
#{yes_night_temp},#{today_morning_temp},#{isolation})
</insert>
<select id="myReport" resultType="com.cxyxiaomo.epp.pojo.Report">
<select id="myReport" resultType="com.cxyxiaomo.epp.common.pojo.Report">
select name,time,normal,address from report where user_id = #{id}
order by time desc
</select>

View File

@ -19,7 +19,7 @@
<select id="showMyVisitor" resultType="java.lang.Integer">
select state from visitor where phone = #{phone} and TO_DAYS(NOW( )) - TO_DAYS(time) = 0
</select>
<select id="showVisitorList" resultType="com.cxyxiaomo.epp.pojo.Visitor">
<select id="showVisitorList" resultType="com.cxyxiaomo.epp.common.pojo.Visitor">
select * from visitor where state = 0
</select>
</mapper>

View File

@ -1,4 +1,4 @@
package com.cxyxiaomo.epp;
package com.cxyxiaomo.epp.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

View File

@ -21,7 +21,7 @@
<!-- 实体类 -->
<dependency>
<groupId>com.cxyxiaomo</groupId>
<artifactId>microservice-pojo</artifactId>
<artifactId>microservice-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- mybatis -->

View File

@ -1,87 +0,0 @@
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.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserServiceImpl 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,32 +0,0 @@
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

@ -1,39 +0,0 @@
package com.cxyxiaomo.epp.dao;
import com.cxyxiaomo.epp.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Mapper
@Repository
public interface UserDao {
public boolean addUser(User user);
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

@ -1,33 +0,0 @@
package com.cxyxiaomo.epp.service;
import com.cxyxiaomo.epp.pojo.User;
import java.util.List;
public interface UserService {
public boolean addUser(User user);
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

@ -1,74 +0,0 @@
package com.cxyxiaomo.epp.service;
import com.cxyxiaomo.epp.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 boolean addUser(User user) {
return userDao.addUser(user);
}
@Override
public User getUserById(Long id) {
return userDao.getUserById(id);
}
@Override
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

@ -1,4 +1,4 @@
package com.cxyxiaomo.epp;
package com.cxyxiaomo.epp.user;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

View File

@ -0,0 +1,62 @@
package com.cxyxiaomo.epp.user.controller;
import com.cxyxiaomo.epp.common.pojo.User;
import com.cxyxiaomo.epp.common.response.Res;
import com.cxyxiaomo.epp.common.vo.UserVO;
import com.cxyxiaomo.epp.user.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserServiceImpl userService;
// @RequestMapping("/login")
@PostMapping("/login")
@ResponseBody
public Res login(String username, String password) {
User user = userService.getUserByUsername(username);
if (user != null) {
String passwordHash = user.getPassword();
if (passwordHash.equals(password)) {
HashMap<String, Object> map = new HashMap<>();
map.put("userInfo", UserVO.convertFrom(user));
return Res.success(map);
} else {
return Res.error("用户名或密码不正确");
}
} else {
return Res.error("用户不存在");
}
}
@RequestMapping("/person")
@ResponseBody
public User person(String username) {
return null;
// return userService.getUserByUsername(username);
}
@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));
return null;
}
}

View File

@ -0,0 +1,16 @@
package com.cxyxiaomo.epp.user.dao;
import com.cxyxiaomo.epp.common.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
@Mapper
@Repository
public interface UserDao {
public boolean addUser(User user);
public User getUserById(Long id);
User getUserByUsername(String username);
}

View File

@ -0,0 +1,8 @@
package com.cxyxiaomo.epp.user.service;
import com.cxyxiaomo.epp.common.pojo.User;
public interface UserService {
User getUserByUsername(String username);
}

View File

@ -0,0 +1,18 @@
package com.cxyxiaomo.epp.user.service;
import com.cxyxiaomo.epp.common.pojo.User;
import com.cxyxiaomo.epp.user.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
@Override
public User getUserByUsername(String username) {
return userDao.getUserByUsername(username);
}
}

View File

@ -2,55 +2,16 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cxyxiaomo.epp.dao.UserDao">
<insert id="addUser" parameterType="com.cxyxiaomo.epp.pojo.User">
<mapper namespace="com.cxyxiaomo.epp.user.dao.UserDao">
<insert id="addUser" parameterType="com.cxyxiaomo.epp.common.pojo.User">
INSERT INTO user (username, password)
VALUES (#{username}, #{password})
</insert>
<select id="getUserById" parameterType="java.lang.Long" resultType="com.cxyxiaomo.epp.pojo.User">
<select id="getUserById" parameterType="java.lang.Long" resultType="com.cxyxiaomo.epp.common.pojo.User">
SELECT * FROM user
WHERE id = #{id}
</select>
<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 id="getUserByUsername" resultType="com.cxyxiaomo.epp.common.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,4 +1,4 @@
package com.cxyxiaomo.epp;
package com.cxyxiaomo.epp.user;
import static org.junit.Assert.assertTrue;

View File

@ -14,7 +14,7 @@
<packaging>pom</packaging>
<modules>
<module>microservice-gateway</module>
<module>microservice-pojo</module>
<module>microservice-common</module>
<module>microservice-provider-user-8001</module>
<module>microservice-provider-miniprogram-8080</module>
<module>microservice-provider-test-8011</module>