重构项目
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package cn.lailab.toolbox;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
//@MapperScan("cn.lailab.toolbox.mapper") // 扫描这个包下的所有Mapper接口
|
||||
@EnableScheduling
|
||||
public class LailabToolboxApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(LailabToolboxApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.lailab.toolbox.beans.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class Auth {
|
||||
private int id;
|
||||
private String code = "";
|
||||
private String md5code = "";
|
||||
private String type = "";
|
||||
private int useCount = 0;
|
||||
private Date createTime = null;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.lailab.toolbox.beans.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class Parameter {
|
||||
private int id;//参数ID
|
||||
private int sortId;//排序号
|
||||
private int isSystem;//是否系统参数(0-用户参数 1-系统参数)
|
||||
private String category;//分类分组
|
||||
private String type;//参数类型: string, number, boolean, json, text
|
||||
private String parameterName = "";//参数名称
|
||||
private String parameterValue;//参数值
|
||||
private String description ;//参数描述
|
||||
private int status;//状态: 0-禁用 1-启用
|
||||
private String createUser;//创建人
|
||||
private Date createTime;//创建时间
|
||||
private String updateUser;//更新人
|
||||
private Date updateTime ;//更新时间
|
||||
private String authCode = "";
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package cn.lailab.toolbox.beans.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class User {
|
||||
private int id;
|
||||
// private String username;
|
||||
// private String password;
|
||||
// private String nickName;
|
||||
// private int gender;
|
||||
// private String country;
|
||||
// private String province;
|
||||
// private String city;
|
||||
// private String avatarUrl;
|
||||
// private String openId;
|
||||
// private String phone;
|
||||
// private String email;
|
||||
// private Date createTime = null;
|
||||
// private String creator;
|
||||
// private int source;
|
||||
// private int status;
|
||||
// private String authCode;
|
||||
private String username ;
|
||||
private String password;
|
||||
private String nickName;
|
||||
private int gender;
|
||||
private String country;
|
||||
private String province;
|
||||
private String city;
|
||||
private String avatarUrl;
|
||||
private String openId;
|
||||
private String phone;
|
||||
private String email;
|
||||
private Date createTime;
|
||||
private String creator;
|
||||
private int source;
|
||||
private int status;
|
||||
private String authCode;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package cn.lailab.toolbox.beans.message;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Result {
|
||||
private int code;
|
||||
private String message;
|
||||
private Object data;
|
||||
private Long timestamp;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package cn.lailab.toolbox.controller;
|
||||
|
||||
import cn.lailab.toolbox.beans.domain.User;
|
||||
import cn.lailab.toolbox.service.impl.AuthServiceImpl;
|
||||
import cn.lailab.toolbox.service.impl.ResultServiceImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
@RestController
|
||||
public class AuthController {
|
||||
|
||||
@Autowired
|
||||
AuthServiceImpl authService;
|
||||
|
||||
@Autowired
|
||||
ResultServiceImpl resultService;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(AuthController.class);
|
||||
|
||||
@RequestMapping("/api/auth/getAuthCode")
|
||||
public String getAuthCode(@RequestBody User user) {
|
||||
String rst;
|
||||
logger.info("调用方法getAuthCode()开始 入参:{}", user);
|
||||
String code = authService.getAuthCode(user);
|
||||
if (code == null|| code.isEmpty()) {
|
||||
rst = resultService.error("获取授权码失败,请确认登录信息无误!","");
|
||||
}else{
|
||||
rst = resultService.success("获取授权码成功!",code);
|
||||
}
|
||||
logger.info("调用方法getAuthCode()结束 返回:{}", code);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@RequestMapping("/api/auth/getAuthMd5Code")
|
||||
public String getAuthMd5Code(@RequestBody User user) {
|
||||
String rst;
|
||||
logger.info("调用方法getAuthMd5Code()开始 入参:{}", user);
|
||||
String code = authService.getAuthMd5Code(user);
|
||||
if (code == null|| code.isEmpty()) {
|
||||
rst = resultService.error("获取授权码失败,请确认登录信息无误!","");
|
||||
}else{
|
||||
rst = resultService.success("获取授权码成功!",code);
|
||||
}
|
||||
logger.info("调用方法getAuthMd5Code()结束 返回:{}", code);
|
||||
return rst;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package cn.lailab.toolbox.controller;
|
||||
|
||||
import cn.lailab.toolbox.beans.domain.Parameter;
|
||||
import cn.lailab.toolbox.service.ParameterService;
|
||||
import cn.lailab.toolbox.service.ResultService;
|
||||
import cn.lailab.toolbox.service.impl.AuthServiceImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class ParameterController {
|
||||
|
||||
@Autowired
|
||||
private ParameterService parameterService;
|
||||
|
||||
@Autowired
|
||||
private AuthServiceImpl authService;
|
||||
|
||||
@Autowired
|
||||
private ResultService resultService;
|
||||
|
||||
@Value("${lailab.default-authCode}")
|
||||
String defaultAuthCode;
|
||||
private final Logger logger = LoggerFactory.getLogger(UserController.class);
|
||||
|
||||
|
||||
@RequestMapping("/api/parameter/getAllParameter")
|
||||
public String getAllParameter(@RequestBody Parameter parameter) {
|
||||
logger.info("调用方法getAllParameter()开始 入参:{}", parameter);
|
||||
String rst;
|
||||
if(this.checkAuth(parameter.getAuthCode())){
|
||||
List<Parameter> parameters = parameterService.getAllParameter(parameter);
|
||||
if(!parameters.isEmpty()) {
|
||||
rst = resultService.success("获取所有参数信息成功!", parameters);
|
||||
} else {
|
||||
rst = resultService.success("获取所有参数信息失败!", "");
|
||||
}
|
||||
}else{
|
||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
}
|
||||
logger.info("调用方法getAllParameter()结束 返回:{}", rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/api/parameter/getParameterByName")
|
||||
@ResponseBody
|
||||
public String getParameterByName(@RequestBody Parameter parameter){
|
||||
logger.info("调用方法getParameterByName()开始 入参:{}", parameter);
|
||||
String parameterName = parameter.getParameterName();
|
||||
String rst;
|
||||
if(parameterName == null|| parameterName.isEmpty()){
|
||||
rst = resultService.error("参数parameterName不存在,请检查入参!");
|
||||
}else {
|
||||
if(this.checkAuth(parameter.getAuthCode())){
|
||||
Parameter rstParameter = parameterService.getParameterByName(parameter);
|
||||
if (rstParameter == null) {
|
||||
rst = resultService.error("未获取参数信息!", "");
|
||||
} else {
|
||||
rst = resultService.success("获取参数信息成功!", rstParameter);
|
||||
}
|
||||
}else{
|
||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
}
|
||||
}
|
||||
logger.info("调用方法getParameterByName()结束 返回:{}", rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
public boolean checkAuth(String auth_code){
|
||||
logger.info("调用方法checkAuth()开始 入参:{}",auth_code);
|
||||
String auth_new = authService.getAuthMd5CodeInside();
|
||||
logger.info("最新授权码 {}",auth_new);
|
||||
authService.addUseCount(auth_new);
|
||||
logger.info("授权码 {} 使用次数加1",auth_new);
|
||||
boolean is_match = auth_new.equals(auth_code)||defaultAuthCode.equals(auth_code);
|
||||
logger.info("调用方法checkAuth()结束 返回:{}",is_match);
|
||||
return is_match;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.lailab.toolbox.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Controller
|
||||
public class ToolController {
|
||||
|
||||
@RequestMapping("/JiSuanQi")
|
||||
public String JiSuanQi(){
|
||||
return "tools/JiSuanQi.html";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
package cn.lailab.toolbox.controller;
|
||||
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.lailab.toolbox.beans.domain.User;
|
||||
import cn.lailab.toolbox.service.impl.AuthServiceImpl;
|
||||
import cn.lailab.toolbox.service.impl.ResultServiceImpl;
|
||||
import cn.lailab.toolbox.service.impl.UserServiceImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
UserServiceImpl userService ;
|
||||
|
||||
@Autowired
|
||||
ResultServiceImpl resultService;
|
||||
|
||||
@Autowired
|
||||
AuthServiceImpl authService;
|
||||
@Value("${lailab.default-authCode}")
|
||||
String defaultAuthCode;
|
||||
private final Logger logger = LoggerFactory.getLogger(UserController.class);
|
||||
|
||||
@RequestMapping("/api/user/getAllUser")
|
||||
@ResponseBody
|
||||
public String getAllUser(@RequestBody User user) {
|
||||
String rst;
|
||||
logger.info("调用方法getAllUser()开始 入参:{}", user);
|
||||
if(this.checkAuth(user.getAuthCode())){
|
||||
List<User> users = userService.getAllUser(user);
|
||||
if(!users.isEmpty()) {
|
||||
rst = resultService.success("获取所有用户信息成功!", users);
|
||||
}else{
|
||||
rst = resultService.error("获取所有用户信息失败!", "");
|
||||
}
|
||||
}else{
|
||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
}
|
||||
logger.info("调用方法getAllUser()结束 返回:{}", rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@RequestMapping("/api/user/getUserByOpenId")
|
||||
@ResponseBody
|
||||
public String getUserByOpenId(@RequestBody User user){
|
||||
logger.info("调用方法getUserByOpenId()开始 入参:{}", user);
|
||||
String openId = user.getOpenId();
|
||||
String rst;
|
||||
if(openId == null|| openId.isEmpty()){
|
||||
rst = resultService.error("参数code不存在,请检查入参!");
|
||||
}else {
|
||||
if(this.checkAuth(user.getAuthCode())){
|
||||
User rstUser = userService.getUserByOpenId(user);
|
||||
if (rstUser == null) {
|
||||
rst = resultService.error("未获取用户信息!", "");
|
||||
} else {
|
||||
rst = resultService.success("获取用户信息成功!", rstUser);
|
||||
}
|
||||
}else{
|
||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
}
|
||||
}
|
||||
logger.info("调用方法getUserByOpenId()结束 返回:{}", rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@RequestMapping("/api/user/addUser")
|
||||
public String addUser(@RequestBody User user){
|
||||
logger.info("调用方法addUser()开始 入参:{}",user);
|
||||
logger.info("1.检测用户是否存在(addUser)");
|
||||
int exist = userService.userExist(user);
|
||||
String rst;
|
||||
if(exist>0) {
|
||||
logger.info("2.用户已存在,不能新建用户(addUser)");
|
||||
rst = resultService.other(-2,"用户已存在!","");
|
||||
}else{
|
||||
logger.info("2.用户不存在,新建用户(addUser)");
|
||||
int code = userService.addUser(user);
|
||||
if (code > 0) {
|
||||
rst = resultService.success("添加用户信息成功!");
|
||||
} else {
|
||||
rst = resultService.error("添加用户信息失败!");
|
||||
}
|
||||
logger.info("调用方法addUser()结束 返回:{}", rst);
|
||||
}
|
||||
return rst;
|
||||
}
|
||||
|
||||
@RequestMapping("/api/user/login")
|
||||
public String login(@RequestBody User user){
|
||||
logger.info("调用方法login()开始 入参:{}",user);
|
||||
String rst;
|
||||
if(this.checkAuth(user.getAuthCode())) {
|
||||
logger.info("1.检测用户是否存在(login)");
|
||||
int exist = userService.userExist(user);
|
||||
if (exist > 0) {
|
||||
// 1.获取用户输入密码
|
||||
String str_pwd = user.getPassword();
|
||||
// 2.将密码MD5加密
|
||||
str_pwd = SecureUtil.md5(str_pwd);
|
||||
// 3.转换为大写字符
|
||||
str_pwd = str_pwd.toUpperCase();
|
||||
user.setPassword(str_pwd);
|
||||
logger.info("2.用户存在,校验密码(login)");
|
||||
User rstUser = userService.login(user);
|
||||
if (rstUser == null) {
|
||||
rst = resultService.error("登录失败,请检查密码是否正确!");
|
||||
} else {
|
||||
rst = resultService.success("登录成功!", rstUser);
|
||||
}
|
||||
} else {
|
||||
logger.info("2.用户不存在,需要注册(login)");
|
||||
rst = resultService.other(-2, "用户不存在,请进行注册!", "");
|
||||
}
|
||||
}else{
|
||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
}
|
||||
logger.info("调用方法login()结束 返回:{}", rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/api/user/loginByOpenId")
|
||||
public String loginByOpenId(@RequestBody User user){
|
||||
logger.info("loginByOpenId()开始 入参:{}",user);
|
||||
if (user.getOpenId() == null || user.getOpenId().trim().isEmpty()) {
|
||||
logger.info("参数OpenId不存在,请检查入参!");
|
||||
return resultService.error("参数OpenId不存在,请检查入参!");
|
||||
}
|
||||
String rst;
|
||||
if(this.checkAuth(user.getAuthCode())) {
|
||||
User rstUser = userService.loginByOpenId(user);
|
||||
if (rstUser == null) {
|
||||
rst = resultService.error("登录失败!");
|
||||
} else {
|
||||
rst = resultService.success("登录成功!", rstUser);
|
||||
}
|
||||
}else{
|
||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
}
|
||||
logger.info("调用方法loginByOpenId()结束 返回:{}", rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@RequestMapping("/api/user/updateUser")
|
||||
public String updateUser(@RequestBody User user){
|
||||
logger.info("调用方法updateUser()开始 入参:{}",user);
|
||||
String rst;
|
||||
if(this.checkAuth(user.getAuthCode())) {
|
||||
int code = userService.updateUser(user);
|
||||
if (code > 0) {
|
||||
rst = resultService.success("修改用户信息成功!");
|
||||
} else {
|
||||
rst = resultService.error("修改用户信息失败!");
|
||||
}
|
||||
}else{
|
||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
}
|
||||
logger.info("调用方法updateUser()结束 返回:{}", rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@RequestMapping("/api/user/deleteUser")
|
||||
public String deleteUser(@RequestBody User user){
|
||||
logger.info("调用方法deleteUser()开始 入参:{}",user);
|
||||
String rst;
|
||||
if(this.checkAuth(user.getAuthCode())) {
|
||||
logger.info("1.检测用户是否存在(deleteUser)");
|
||||
int exist = userService.userExist(user);
|
||||
if (exist > 0) {
|
||||
logger.info("2.用户存在(deleteUser)");
|
||||
int code = userService.deleteUser(user);
|
||||
if (code > 0) {
|
||||
rst = resultService.success("删除用户成功!");
|
||||
} else {
|
||||
rst = resultService.error("删除用户失败!");
|
||||
}
|
||||
} else {
|
||||
logger.info("2.用户不存在(deleteUser)");
|
||||
rst = resultService.error("用户不存在!");
|
||||
}
|
||||
}else{
|
||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
}
|
||||
logger.info("调用方法deleteUser()结束 返回:{}",rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@RequestMapping("/api/user/deleteUserByOpenId")
|
||||
public String deleteUserByOpenId(@RequestBody User user){
|
||||
logger.info("调用方法deleteUserByOpenId()开始 入参:{}",user);
|
||||
String rst;
|
||||
if(this.checkAuth(user.getAuthCode())) {
|
||||
int code = userService.deleteUserByOpenId(user);
|
||||
if (code > 0) {
|
||||
rst = resultService.success("删除用户成功!");
|
||||
} else {
|
||||
rst = resultService.error("删除用户失败!");
|
||||
}
|
||||
}else{
|
||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
}
|
||||
logger.info("调用方法deleteUserByOpenId()结束 返回:{}",rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
public boolean checkAuth(String auth_code){
|
||||
logger.info("调用方法checkAuth()开始 入参:{}",auth_code);
|
||||
String auth_new = authService.getAuthMd5CodeInside();
|
||||
logger.info("最新授权码 {}",auth_new);
|
||||
authService.addUseCount(auth_new);
|
||||
logger.info("授权码 {} 使用次数加1",auth_new);
|
||||
boolean is_match = auth_new.equals(auth_code)||defaultAuthCode.equals(auth_code);
|
||||
logger.info("调用方法checkAuth()结束 返回:{}",is_match);
|
||||
return is_match;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package cn.lailab.toolbox.controller;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.lailab.toolbox.service.impl.ResultServiceImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class WXController {
|
||||
// 获取小程序AppID
|
||||
@Value("${mini-program.appid}")
|
||||
private String appid;
|
||||
// 获取小程序Secrty
|
||||
@Value("${mini-program.secret}")
|
||||
private String secret;
|
||||
// 返回消息类
|
||||
@Autowired
|
||||
ResultServiceImpl resultService;
|
||||
// 定义日志打印类
|
||||
private final Logger logger = LoggerFactory.getLogger(WXController.class);
|
||||
// 获取微信OpenId
|
||||
@RequestMapping("/api/wx/getOpenId")
|
||||
@ResponseBody
|
||||
public String getOpenId(@RequestParam(required=false,name = "code") String code) {
|
||||
logger.info("调用方法getOpenId()开始 {}",code);
|
||||
// 拼接所需字符串
|
||||
String url = "https://api.weixin.qq.com/sns/jscode2session" +
|
||||
"?appid=" +appid +
|
||||
"&secret=" + secret + //自己的appSecret
|
||||
"&js_code=" + code +
|
||||
"&grant_type=authorization_code" +
|
||||
"&connect_redirect=1";
|
||||
|
||||
if (code == null || code.trim().isEmpty()) {
|
||||
logger.error("参数code不存在,请检查入参!");
|
||||
return resultService.error("参数code不存在,请检查入参!");
|
||||
}
|
||||
String result = HttpUtil.get(url, CharsetUtil.CHARSET_UTF_8);
|
||||
String rst = resultService.success("调用完成",result);
|
||||
logger.info("调用方法getOpenId()结束 {}",rst);
|
||||
return rst;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.lailab.toolbox.mapper;
|
||||
|
||||
import cn.lailab.toolbox.beans.domain.Auth;
|
||||
import cn.lailab.toolbox.beans.domain.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface AuthMapper {
|
||||
|
||||
String getAuthCode(User user);
|
||||
String getAuthMd5Code(User user);
|
||||
String getAuthMd5CodeInside();
|
||||
int addUseCount(String authCode);
|
||||
int addAuth(Auth auth);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package cn.lailab.toolbox.mapper;
|
||||
|
||||
import cn.lailab.toolbox.beans.domain.Parameter;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ParameterMapper {
|
||||
List<Parameter> getAllParameter(Parameter parameter);
|
||||
Parameter getParameterByName(Parameter parameter);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.lailab.toolbox.mapper;
|
||||
|
||||
import cn.lailab.toolbox.beans.domain.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
|
||||
int addUser(User user);
|
||||
|
||||
User getUserByOpenId(User user);
|
||||
|
||||
List<User> getAllUser(User user);
|
||||
|
||||
int userExist(User user);
|
||||
|
||||
User login(User user);
|
||||
|
||||
User loginByOpenId(User user);
|
||||
|
||||
int updateUser(User user);
|
||||
|
||||
int deleteUser(User user);
|
||||
|
||||
int deleteUserByOpenId(User user);
|
||||
|
||||
int getMaxId();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package cn.lailab.toolbox.service;
|
||||
|
||||
import cn.lailab.toolbox.beans.domain.Auth;
|
||||
import cn.lailab.toolbox.beans.domain.User;
|
||||
|
||||
public interface AuthService {
|
||||
String getAuthCode(User user);
|
||||
String getAuthMd5Code(User user);
|
||||
String getAuthMd5CodeInside();
|
||||
int addUseCount(String auth_code);
|
||||
int addAuth(Auth auth);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package cn.lailab.toolbox.service;
|
||||
|
||||
import cn.lailab.toolbox.beans.domain.Parameter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ParameterService {
|
||||
List<Parameter> getAllParameter(Parameter parameter);
|
||||
Parameter getParameterByName(Parameter parameter);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package cn.lailab.toolbox.service;
|
||||
|
||||
public interface ResultService {
|
||||
|
||||
String success();
|
||||
String success(String message);
|
||||
String success(String message,Object data);
|
||||
String error();
|
||||
String error(String message);
|
||||
String error(String message,Object data);
|
||||
String other(int code,String message,Object data);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package cn.lailab.toolbox.service;
|
||||
|
||||
import cn.lailab.toolbox.beans.domain.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserService {
|
||||
int addUser(User user);
|
||||
|
||||
List<User> getAllUser(User user);
|
||||
|
||||
User getUserByOpenId(User user);
|
||||
|
||||
int userExist(User user);
|
||||
|
||||
User login(User user);
|
||||
|
||||
User loginByOpenId(User user);
|
||||
|
||||
int updateUser(User user);
|
||||
|
||||
int deleteUser(User user);
|
||||
|
||||
int deleteUserByOpenId(User user);
|
||||
|
||||
int getMaxId();
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package cn.lailab.toolbox.service.impl;
|
||||
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.lailab.toolbox.beans.domain.Auth;
|
||||
import cn.lailab.toolbox.beans.domain.User;
|
||||
import cn.lailab.toolbox.mapper.AuthMapper;
|
||||
import cn.lailab.toolbox.service.AuthService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class AuthServiceImpl implements AuthService {
|
||||
|
||||
// 自动注入AuthMapper
|
||||
@Autowired
|
||||
AuthMapper authMapper;
|
||||
|
||||
// 获取最新授权码
|
||||
@Override
|
||||
public String getAuthCode(User user) {
|
||||
String str_pwd = user.getPassword();
|
||||
String str_pwd_md5 = SecureUtil.md5(str_pwd).toUpperCase();
|
||||
user.setPassword(str_pwd_md5);
|
||||
return authMapper.getAuthCode(user);
|
||||
}
|
||||
|
||||
// 获取最新MD5授权码
|
||||
@Override
|
||||
public String getAuthMd5Code(User user) {
|
||||
String str_pwd = user.getPassword();
|
||||
String str_pwd_md5 = SecureUtil.md5(str_pwd).toUpperCase();
|
||||
user.setPassword(str_pwd_md5);
|
||||
return authMapper.getAuthMd5Code(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthMd5CodeInside() {
|
||||
return authMapper.getAuthMd5CodeInside();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addUseCount(String auth_code) {
|
||||
return authMapper.addUseCount(auth_code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addAuth(Auth auth) {
|
||||
return authMapper.addAuth(auth);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.lailab.toolbox.service.impl;
|
||||
|
||||
import cn.lailab.toolbox.beans.domain.Parameter;
|
||||
import cn.lailab.toolbox.mapper.ParameterMapper;
|
||||
import cn.lailab.toolbox.service.ParameterService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ParameterImpl implements ParameterService {
|
||||
|
||||
@Autowired
|
||||
ParameterMapper parameterMapper;
|
||||
|
||||
@Override
|
||||
public List<Parameter> getAllParameter(Parameter parameter) {
|
||||
return parameterMapper.getAllParameter(parameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parameter getParameterByName(Parameter parameter) {
|
||||
return parameterMapper.getParameterByName(parameter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package cn.lailab.toolbox.service.impl;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.lailab.toolbox.beans.message.Result;
|
||||
import cn.lailab.toolbox.service.ResultService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class ResultServiceImpl implements ResultService {
|
||||
@Override
|
||||
public String other(int code, String message, Object data) {
|
||||
Result result = new Result();
|
||||
result.setCode(code);
|
||||
result.setMessage(message);
|
||||
if(data == null) result.setData("");
|
||||
result.setData(data);
|
||||
result.setTimestamp(System.currentTimeMillis());
|
||||
//return JSONUtil.toJsonPrettyStr(result);
|
||||
return JSONUtil.toJsonStr(result);
|
||||
}
|
||||
@Override
|
||||
public String success() {
|
||||
return other(0,"success","");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String success(String message) {
|
||||
return other(0,message,"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String success(String message, Object data) {
|
||||
return other(0,message,data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String error() {
|
||||
return other(-1,"error","");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String error(String message) {
|
||||
return other(-1,message,"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String error(String message, Object data) {
|
||||
return other(-1,message,data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package cn.lailab.toolbox.service.impl;
|
||||
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.lailab.toolbox.beans.domain.User;
|
||||
import cn.lailab.toolbox.mapper.UserMapper;
|
||||
import cn.lailab.toolbox.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
// 自动注入UserMapper
|
||||
@Autowired
|
||||
UserMapper userMapper;
|
||||
|
||||
// 引入默认密码
|
||||
@Value("${lailab.default-password}")
|
||||
private String defaultPassword;
|
||||
|
||||
// 增加用户
|
||||
@Override
|
||||
public int addUser(User user) {
|
||||
int maxId;
|
||||
maxId = userMapper.getMaxId();
|
||||
maxId +=1;
|
||||
// 自动生成用户名
|
||||
if(user.getUsername().isEmpty()){
|
||||
user.setUsername(String.format("%05d",maxId));
|
||||
}
|
||||
// 对用户输入的密码进行MD5加密
|
||||
if(user.getPassword().isEmpty()) {
|
||||
user.setPassword(SecureUtil.md5(defaultPassword).toUpperCase());
|
||||
}else{
|
||||
user.setPassword(SecureUtil.md5(user.getPassword()).toUpperCase());
|
||||
}
|
||||
// 创建时间赋值
|
||||
user.setCreateTime(new Date());
|
||||
return userMapper.addUser(user);
|
||||
}
|
||||
|
||||
// 通过OPenId获取用户信息
|
||||
@Override
|
||||
public User getUserByOpenId(User user) {
|
||||
return userMapper.getUserByOpenId(user);
|
||||
}
|
||||
|
||||
// 判断用户是否存在
|
||||
@Override
|
||||
public int userExist(User user) {
|
||||
return userMapper.userExist(user);
|
||||
}
|
||||
|
||||
// 用户登录
|
||||
@Override
|
||||
public User login(User user) {
|
||||
return userMapper.login(user);
|
||||
}
|
||||
|
||||
// 通过OpenId登录
|
||||
@Override
|
||||
public User loginByOpenId(User user) {
|
||||
return userMapper.loginByOpenId(user);
|
||||
}
|
||||
|
||||
// 更新用户信息
|
||||
@Override
|
||||
public int updateUser(User user) {
|
||||
// 对用户输入的密码进行MD5加密
|
||||
if(user.getPassword().isEmpty()) {
|
||||
user.setPassword(SecureUtil.md5(defaultPassword).toUpperCase());
|
||||
}else{
|
||||
user.setPassword(SecureUtil.md5(user.getPassword()).toUpperCase());
|
||||
}
|
||||
return userMapper.updateUser(user);
|
||||
}
|
||||
|
||||
// 删除用户信息
|
||||
@Override
|
||||
public int deleteUser(User user) {
|
||||
return userMapper.deleteUser(user);
|
||||
}
|
||||
|
||||
// 通过OpenId删除用户
|
||||
@Override
|
||||
public int deleteUserByOpenId(User user) {
|
||||
return userMapper.deleteUserByOpenId(user);
|
||||
}
|
||||
|
||||
// 获取所有用户
|
||||
@Override
|
||||
public List<User> getAllUser(User user) {
|
||||
return userMapper.getAllUser(user);
|
||||
}
|
||||
|
||||
// 获取最大ID号
|
||||
@Override
|
||||
public int getMaxId() {
|
||||
return userMapper.getMaxId();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package cn.lailab.toolbox.tasks;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.lailab.toolbox.beans.domain.Auth;
|
||||
import cn.lailab.toolbox.service.impl.AuthServiceImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Component
|
||||
public class AuthTask {
|
||||
private final Logger logger = LoggerFactory.getLogger(AuthTask.class);
|
||||
|
||||
@Autowired
|
||||
private AuthServiceImpl authService;
|
||||
|
||||
@Value("${lailab.auth-task.random-length}")
|
||||
private int randomLength;
|
||||
|
||||
@Scheduled(cron = "${lailab.auth-task.cron}")
|
||||
public void authTask() {
|
||||
Logger logger = LoggerFactory.getLogger(AuthTask.class);
|
||||
logger.info("调用方法authTask()开始");
|
||||
String str_random = RandomUtil.randomString(randomLength);
|
||||
logger.info("1.获取随机数 内容:{}", str_random);
|
||||
String str_md5 = SecureUtil.md5(str_random).toUpperCase();
|
||||
logger.info("2.产生Md5数据 内容:{}", str_md5);
|
||||
Auth auth = new Auth();
|
||||
auth.setCode(str_random);
|
||||
auth.setMd5code(str_md5);
|
||||
auth.setType("api");
|
||||
auth.setCreateTime(new Date());
|
||||
logger.info("3.封装Auth对象 内容:{}", auth);
|
||||
int code = authService.addAuth(auth);
|
||||
|
||||
if (code > 0) {
|
||||
logger.info("调用方法authTask()结束 添加成功!");
|
||||
}else{
|
||||
logger.info("调用方法authTask()结束 添加失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user