重构项目
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user