重构项目
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()结束 添加失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
spring:
|
||||
application:
|
||||
name: lailab-toolbox
|
||||
datasource:
|
||||
url: "jdbc:mysql://localhost/db_lailab"
|
||||
username: "root"
|
||||
password: "Qian20001028"
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
server:
|
||||
port: 8080
|
||||
|
||||
mini-program:
|
||||
appid: "wx09ed3facc95abf94"
|
||||
secret: "3d20927085d4eabc7e600201fe97642c"
|
||||
|
||||
lailab:
|
||||
default-password: "123456" #新建用户默认密码
|
||||
auth-task:
|
||||
cron: "0 0/10 * * * ?"
|
||||
random-length: 6
|
||||
default-authCode: "D768ECAAB35C55ABBA071C5415D6520E"
|
||||
|
||||
mybatis:
|
||||
mapper-locations: classpath:mapper/*Mapper.xml #mapper的映射文件
|
||||
type-aliases-package: cn.lailab.toolbox.beans.domain
|
||||
# anto-commit: true
|
||||
# config-location: #置顶核心配置文件
|
||||
|
||||
logging:
|
||||
file:
|
||||
name: "./log/lailab-toolbox.log"
|
||||
level:
|
||||
org.springframework.web: info
|
||||
org.hibernate.SQL: debug
|
||||
cn.lailab: info
|
||||
logback:
|
||||
rollingpolicy:
|
||||
max-file-size: 10MB
|
||||
@@ -0,0 +1,52 @@
|
||||
spring:
|
||||
application:
|
||||
name: lailab-toolbox
|
||||
datasource:
|
||||
url: "jdbc:mysql://www.lailab.cc/db_lailab"
|
||||
username: "root"
|
||||
password: "lailab19980730mysql"
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
server:
|
||||
port: 8080
|
||||
# ssl:
|
||||
# key-store: classpath:server.pkcs12
|
||||
# key-store-password: lailab19980730key
|
||||
# key-store-type: PKCS12
|
||||
# # key-alias: myapp
|
||||
# enabled: true
|
||||
|
||||
mini-program:
|
||||
appid: "wx09ed3facc95abf94"
|
||||
secret: "3d20927085d4eabc7e600201fe97642c"
|
||||
|
||||
lailab:
|
||||
default-password: "123456" #新建用户默认密码
|
||||
auth-task:
|
||||
cron: "0 0/30 * * * ?"
|
||||
random-length: 6
|
||||
default-authCode: "D768ECAAB35C55ABBA071C5415D6520E"
|
||||
|
||||
# MyBatis 核心配置
|
||||
mybatis:
|
||||
# 1. 指定 Mapper XML 文件的位置(如果你的 Mapper 有 XML 映射文件,必须配置)
|
||||
# mapper-locations: classpath:mapper/*Mapper.xml #mapper的映射文件
|
||||
mapper-locations: classpath:mapper/**/*.xml
|
||||
# 2. 配置实体类的别名包(这样在 XML 中可以直接用类名,不用写全限定名)
|
||||
type-aliases-package: cn.lailab.toolbox.beans.domain
|
||||
# 3. 开启驼峰命名自动转换(比如数据库字段 user_name 自动映射到实体类属性 userName)
|
||||
# configuration:
|
||||
# map-underscore-to-camel-case: true
|
||||
# 可选:开启日志打印,方便调试 SQL
|
||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
logging:
|
||||
file:
|
||||
name: "./log/lailab-toolbox.log"
|
||||
level:
|
||||
org.springframework.web: info
|
||||
org.hibernate.SQL: debug
|
||||
cn.lailab: info
|
||||
logback:
|
||||
rollingpolicy:
|
||||
max-file-size: 10MB
|
||||
@@ -0,0 +1,3 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: pro
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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="cn.lailab.toolbox.mapper.AuthMapper">
|
||||
<select id="getAuthCode" resultType="String">
|
||||
select code from auth_codes where exists(
|
||||
select *
|
||||
from users
|
||||
where ((username = #{username} AND password = #{password})
|
||||
or (openId != '' AND openId = #{openId})))
|
||||
order by createTime desc
|
||||
limit 1;
|
||||
</select>
|
||||
|
||||
<select id="getAuthMd5Code" resultType="String">
|
||||
select md5code from auth_codes where exists(
|
||||
select *
|
||||
from users
|
||||
where ((username = #{username} AND password = #{password})
|
||||
or (openid != '' AND openId = #{openId})))
|
||||
order by createTime desc
|
||||
limit 1;
|
||||
</select>
|
||||
|
||||
<select id="getAuthMd5CodeInside" resultType="String">
|
||||
select md5code from auth_codes
|
||||
order by createTime desc
|
||||
limit 1;
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="addAuth" parameterType="auth">
|
||||
insert into auth_codes(code, md5code, type, useCount, createTime)
|
||||
values(#{code}, #{md5code}, #{type}, #{useCount}, #{createTime});
|
||||
</insert>
|
||||
|
||||
<update id="addUseCount" parameterType="string">
|
||||
update auth_codes set useCount = useCount + 1 where md5code = #{md5code};
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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="cn.lailab.toolbox.mapper.ParameterMapper">
|
||||
<resultMap id="base_result_map" type="cn.lailab.toolbox.beans.domain.Parameter">
|
||||
<id column="id" property="id"/>
|
||||
<result column="sort_id" property="sortId"/>
|
||||
<result column="is_system" property="isSystem"/>
|
||||
<result column="category" property="category"/>
|
||||
<result column="type" property="type"/>
|
||||
<result column="parameter_name" property="parameterName"/>
|
||||
<result column="parameter_value" property="parameterValue"/>
|
||||
<result column="description" property="description"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="create_user" property="createUser"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_user" property="updateUser"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
</resultMap>
|
||||
<sql id="base_column_list">
|
||||
id,
|
||||
sort_id,
|
||||
is_system,
|
||||
category,
|
||||
type,
|
||||
parameter_name,
|
||||
parameter_value,
|
||||
description,
|
||||
status,
|
||||
create_user,
|
||||
create_time,
|
||||
update_user,
|
||||
update_time
|
||||
</sql>
|
||||
<select id="getAllParameter" resultMap="base_result_map">
|
||||
select
|
||||
<include refid="base_column_list"/>
|
||||
from sys_parameter;
|
||||
</select>
|
||||
|
||||
<select id="getParameterByName" resultMap="base_result_map">
|
||||
select
|
||||
<include refid="base_column_list"/>
|
||||
from sys_parameter
|
||||
where parameter_name = #{parameterName};
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,87 @@
|
||||
<?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="cn.lailab.toolbox.mapper.UserMapper">
|
||||
|
||||
<sql id="base_column_list">
|
||||
id, username, password, nickName, gender,
|
||||
country,province, city, avatarUrl, openId,
|
||||
phone, email, createTime, creator, source,
|
||||
status
|
||||
</sql>
|
||||
<sql id="backup_sql">
|
||||
and #{authCode} = (select md5code from auth_codes order by createTime desc limit 1);
|
||||
</sql>
|
||||
<select id="getAllUser" resultType="user">
|
||||
select
|
||||
<include refid="base_column_list"/>
|
||||
from users
|
||||
</select>
|
||||
|
||||
<select id="getUserByOpenId" resultType="user">
|
||||
select
|
||||
<include refid="base_column_list"/>
|
||||
from users
|
||||
where openid = #{openId}
|
||||
</select>
|
||||
|
||||
<insert id="addUser" parameterType="user">
|
||||
insert into users(username, password, nickName, gender, country,
|
||||
province, city, avatarUrl, openId, phone,
|
||||
email, creator, source, status)
|
||||
values(#{username}, #{password}, #{nickName}, #{gender}, #{country},
|
||||
#{province}, #{city}, #{avatarUrl}, #{openId}, #{phone},
|
||||
#{email}, #{creator}, #{source}, #{status});
|
||||
</insert>
|
||||
|
||||
<select id="getMaxId" resultType="int">
|
||||
select ifnull(max(id),0) from users;
|
||||
</select>
|
||||
|
||||
<select id="userExist" resultType="int">
|
||||
select count(1)
|
||||
from users
|
||||
where username = #{username}
|
||||
or (openId <![CDATA[<>]]> '' and openId = #{openId})
|
||||
or (phone <![CDATA[<>]]> '' and phone = #{phone})
|
||||
or (email <![CDATA[<>]]> '' and email = #{email});
|
||||
</select>
|
||||
|
||||
<select id="login" resultType="user">
|
||||
select id, username, password, nickName, gender,
|
||||
country, province, city, avatarUrl, openId,
|
||||
phone, email, createTime,creator, source,
|
||||
status
|
||||
from users
|
||||
where (username = #{username} and password = #{password})
|
||||
or (nickName = #{nickName} and password = #{password})
|
||||
or (phone = #{phone} and password = #{password})
|
||||
or (email = #{email}) and password = #{password}
|
||||
</select>
|
||||
|
||||
<select id="loginByOpenId" resultType="user">
|
||||
select id, username, password, nickName, gender,
|
||||
country, province, city, avatarUrl, openId,
|
||||
phone, email, createTime, creator, source,
|
||||
status
|
||||
from users
|
||||
where openId = #{openId}
|
||||
</select>
|
||||
|
||||
<update id="updateUser" parameterType="user">
|
||||
update users set password=#{password}, nickName=#{nickName}, gender=#{gender},
|
||||
country=#{country}, province=#{province}, city=#{city},
|
||||
avatarUrl=#{avatarUrl}, phone=#{phone}, email=#{email},
|
||||
status=#{status}, openId=#{openId}
|
||||
where username=#{username}
|
||||
</update>
|
||||
|
||||
<update id="deleteUser" parameterType="user">
|
||||
update users set status=4
|
||||
where username=#{username};
|
||||
</update>
|
||||
|
||||
<update id="deleteUserByOpenId" parameterType="user">
|
||||
update users set status=4
|
||||
where openId=#{openId};
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -0,0 +1,6 @@
|
||||
<html>
|
||||
<body>
|
||||
<h1>hello word!!!</h1>
|
||||
<p>this is a html page</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,297 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>计算器</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
font-family: "Helvetica Neue", Arial, sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
/* 计算器容器 */
|
||||
.calculator-container {
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
height: 90vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #000;
|
||||
border-radius: 20px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 0 30px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
/* 显示区域 */
|
||||
.display {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: flex-end;
|
||||
align-items: flex-end;
|
||||
padding: 40px 30px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.input-text {
|
||||
font-size: 24px;
|
||||
margin-bottom: 10px;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.result-text {
|
||||
font-size: 40px;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
/* 按钮区域 */
|
||||
.buttons {
|
||||
flex: 2;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.btn-row {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.btn {
|
||||
flex: 1;
|
||||
margin: 5px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 20px;
|
||||
border: none;
|
||||
outline: none;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
/* 按钮样式 */
|
||||
.btn-gray {
|
||||
background-color: #a5a5a5;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.btn-num {
|
||||
background-color: #333333;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-orange {
|
||||
background-color: #ff9f0a;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* 0号按钮特殊样式 */
|
||||
.zero {
|
||||
border-radius: 50px;
|
||||
flex: 2;
|
||||
}
|
||||
|
||||
/* 响应式适配 */
|
||||
@media (max-width: 400px) {
|
||||
.calculator-container {
|
||||
height: 100vh;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.display {
|
||||
padding: 30px 20px;
|
||||
}
|
||||
|
||||
.result-text {
|
||||
font-size: 36px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="calculator-container">
|
||||
<!-- 显示区域 -->
|
||||
<div class="display">
|
||||
<div class="input-text" id="inputValue"></div>
|
||||
<div class="result-text" id="resultValue">0</div>
|
||||
</div>
|
||||
|
||||
<!-- 按钮区域 -->
|
||||
<div class="buttons">
|
||||
<!-- 第一行 -->
|
||||
<div class="btn-row">
|
||||
<button class="btn btn-gray" onclick="clearAll()">AC</button>
|
||||
<button class="btn btn-gray" onclick="deleteLast()">←</button>
|
||||
<button class="btn btn-gray" onclick="handleOperator('%')">%</button>
|
||||
<button class="btn btn-orange" onclick="handleOperator('/')">÷</button>
|
||||
</div>
|
||||
|
||||
<!-- 第二行 -->
|
||||
<div class="btn-row">
|
||||
<button class="btn btn-num" onclick="handleNumber('7')">7</button>
|
||||
<button class="btn btn-num" onclick="handleNumber('8')">8</button>
|
||||
<button class="btn btn-num" onclick="handleNumber('9')">9</button>
|
||||
<button class="btn btn-orange" onclick="handleOperator('*')">×</button>
|
||||
</div>
|
||||
|
||||
<!-- 第三行 -->
|
||||
<div class="btn-row">
|
||||
<button class="btn btn-num" onclick="handleNumber('4')">4</button>
|
||||
<button class="btn btn-num" onclick="handleNumber('5')">5</button>
|
||||
<button class="btn btn-num" onclick="handleNumber('6')">6</button>
|
||||
<button class="btn btn-orange" onclick="handleOperator('-')">-</button>
|
||||
</div>
|
||||
|
||||
<!-- 第四行 -->
|
||||
<div class="btn-row">
|
||||
<button class="btn btn-num" onclick="handleNumber('1')">1</button>
|
||||
<button class="btn btn-num" onclick="handleNumber('2')">2</button>
|
||||
<button class="btn btn-num" onclick="handleNumber('3')">3</button>
|
||||
<button class="btn btn-orange" onclick="handleOperator('+')">+</button>
|
||||
</div>
|
||||
|
||||
<!-- 第五行 -->
|
||||
<div class="btn-row">
|
||||
<button class="btn btn-num zero" onclick="handleNumber('0')">0</button>
|
||||
<button class="btn btn-num" onclick="handleNumber('.')">.</button>
|
||||
<button class="btn btn-orange" onclick="calculate()">=</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let inputValue = ''; // 输入的表达式
|
||||
let resultValue = '0'; // 计算结果
|
||||
|
||||
// 获取DOM元素
|
||||
const inputEl = document.getElementById('inputValue');
|
||||
const resultEl = document.getElementById('resultValue');
|
||||
|
||||
// 更新显示
|
||||
function updateDisplay() {
|
||||
inputEl.textContent = inputValue;
|
||||
resultEl.textContent = resultValue;
|
||||
}
|
||||
|
||||
// 清空
|
||||
function clearAll() {
|
||||
inputValue = '';
|
||||
resultValue = '0';
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
// 退格
|
||||
function deleteLast() {
|
||||
if (inputValue.length > 0) {
|
||||
inputValue = inputValue.substring(0, inputValue.length - 1);
|
||||
// 如果还有输入内容,重新计算
|
||||
if (inputValue) {
|
||||
calculateResult(inputValue);
|
||||
} else {
|
||||
resultValue = '0';
|
||||
}
|
||||
updateDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
// 处理数字输入
|
||||
function handleNumber(value) {
|
||||
// 处理小数点(只能有一个)
|
||||
if (value === '.' && inputValue.includes('.')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理开头的0
|
||||
if (inputValue === '0' && value !== '.') {
|
||||
inputValue = value;
|
||||
} else {
|
||||
inputValue += value;
|
||||
}
|
||||
|
||||
// 实时计算
|
||||
calculateResult(inputValue);
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
// 处理运算符
|
||||
function handleOperator(value) {
|
||||
const lastChar = inputValue.slice(-1);
|
||||
|
||||
// 替换运算符(如果最后一个字符是运算符)
|
||||
const operators = ['+', '-', '*', '/', '%'];
|
||||
if (operators.includes(lastChar)) {
|
||||
inputValue = inputValue.substring(0, inputValue.length - 1) + value;
|
||||
} else {
|
||||
inputValue += value;
|
||||
}
|
||||
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
// 计算结果
|
||||
function calculate() {
|
||||
calculateResult(inputValue);
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
// 核心计算方法
|
||||
function calculateResult(expression) {
|
||||
if (!expression) return;
|
||||
|
||||
// 替换乘号为js识别的*
|
||||
let exp = expression.replace(/×/g, '*');
|
||||
|
||||
try {
|
||||
// 使用eval计算(实际项目中可替换为更安全的表达式解析库)
|
||||
let result = eval(exp);
|
||||
|
||||
// 处理大数和小数
|
||||
if (result.toString().length > 10) {
|
||||
result = result.toPrecision(10);
|
||||
}
|
||||
|
||||
resultValue = result.toString();
|
||||
} catch (error) {
|
||||
resultValue = 'Error';
|
||||
console.error('计算错误:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化显示
|
||||
updateDisplay();
|
||||
|
||||
// 键盘支持(可选)
|
||||
document.addEventListener('keydown', (e) => {
|
||||
const key = e.key;
|
||||
if (/[0-9.]/.test(key)) {
|
||||
handleNumber(key);
|
||||
} else if (['+', '-', '*', '/', '%'].includes(key)) {
|
||||
handleOperator(key === '*' ? '×' : key);
|
||||
} else if (key === 'Enter' || key === '=') {
|
||||
calculate();
|
||||
} else if (key === 'Backspace') {
|
||||
deleteLast();
|
||||
} else if (key === 'Escape') {
|
||||
clearAll();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user