2026-01-07
1.优化代码
This commit is contained in:
@@ -1,23 +1,22 @@
|
||||
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 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;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cn.lailab.toolbox.beans.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
|
||||
@@ -10,7 +10,6 @@ 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 {
|
||||
|
||||
@@ -27,10 +26,10 @@ public class AuthController {
|
||||
String rst;
|
||||
logger.info("调用方法getAuthCode()开始 入参:{}", user);
|
||||
String code = authService.getAuthCode(user);
|
||||
if (code == null|| code.isEmpty()) {
|
||||
rst = resultService.error("获取授权码失败,请确认登录信息无误!","");
|
||||
}else{
|
||||
rst = resultService.success("获取授权码成功!",code);
|
||||
if (code == null || code.isEmpty()) {
|
||||
rst = resultService.error("获取授权码失败,请确认登录信息无误!", "");
|
||||
} else {
|
||||
rst = resultService.success("获取授权码成功!", code);
|
||||
}
|
||||
logger.info("调用方法getAuthCode()结束 返回:{}", code);
|
||||
return rst;
|
||||
@@ -41,10 +40,10 @@ public class AuthController {
|
||||
String rst;
|
||||
logger.info("调用方法getAuthMd5Code()开始 入参:{}", user);
|
||||
String code = authService.getAuthMd5Code(user);
|
||||
if (code == null|| code.isEmpty()) {
|
||||
rst = resultService.error("获取授权码失败,请确认登录信息无误!","");
|
||||
}else{
|
||||
rst = resultService.success("获取授权码成功!",code);
|
||||
if (code == null || code.isEmpty()) {
|
||||
rst = resultService.error("获取授权码失败,请确认登录信息无误!", "");
|
||||
} else {
|
||||
rst = resultService.success("获取授权码成功!", code);
|
||||
}
|
||||
logger.info("调用方法getAuthMd5Code()结束 返回:{}", code);
|
||||
return rst;
|
||||
|
||||
@@ -31,58 +31,56 @@ public class ParameterController {
|
||||
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())){
|
||||
if (this.checkAuth(parameter.getAuthCode())) {
|
||||
List<Parameter> parameters = parameterService.getAllParameter(parameter);
|
||||
if(!parameters.isEmpty()) {
|
||||
if (!parameters.isEmpty()) {
|
||||
rst = resultService.success("获取所有参数信息成功!", parameters);
|
||||
} else {
|
||||
rst = resultService.success("获取所有参数信息失败!", "");
|
||||
}
|
||||
}else{
|
||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
} else {
|
||||
rst = resultService.other(-2, "授权信息有误或已过期,请更换后重新尝试!", "");
|
||||
}
|
||||
logger.info("调用方法getAllParameter()结束 返回:{}", rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/api/parameter/getParameterByName")
|
||||
@ResponseBody
|
||||
public String getParameterByName(@RequestBody Parameter parameter){
|
||||
public String getParameterByName(@RequestBody Parameter parameter) {
|
||||
logger.info("调用方法getParameterByName()开始 入参:{}", parameter);
|
||||
String parameterName = parameter.getParameterName();
|
||||
String rst;
|
||||
if(parameterName == null|| parameterName.isEmpty()){
|
||||
if (parameterName == null || parameterName.isEmpty()) {
|
||||
rst = resultService.error("参数parameterName不存在,请检查入参!");
|
||||
}else {
|
||||
if(this.checkAuth(parameter.getAuthCode())){
|
||||
} 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,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
} else {
|
||||
rst = resultService.other(-2, "授权信息有误或已过期,请更换后重新尝试!", "");
|
||||
}
|
||||
}
|
||||
logger.info("调用方法getParameterByName()结束 返回:{}", rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
public boolean checkAuth(String auth_code){
|
||||
logger.info("调用方法checkAuth()开始 入参:{}",auth_code);
|
||||
public boolean checkAuth(String auth_code) {
|
||||
logger.info("调用方法checkAuth()开始 入参:{}", auth_code);
|
||||
String auth_new = authService.getAuthMd5CodeInside();
|
||||
logger.info("最新授权码 {}",auth_new);
|
||||
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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
public class ToolController {
|
||||
|
||||
@RequestMapping("/JiSuanQi")
|
||||
public String JiSuanQi(){
|
||||
public String JiSuanQi() {
|
||||
return "tools/JiSuanQi/JiSuanQi.html";
|
||||
}
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index(){
|
||||
public String index() {
|
||||
return "index.html";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,14 +10,13 @@ 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 ;
|
||||
UserServiceImpl userService;
|
||||
|
||||
@Autowired
|
||||
ResultServiceImpl resultService;
|
||||
@@ -33,15 +32,15 @@ public class UserController {
|
||||
public String getAllUser(@RequestBody User user) {
|
||||
String rst;
|
||||
logger.info("调用方法getAllUser()开始 入参:{}", user);
|
||||
if(this.checkAuth(user.getAuthCode())){
|
||||
if (this.checkAuth(user.getAuthCode())) {
|
||||
List<User> users = userService.getAllUser(user);
|
||||
if(!users.isEmpty()) {
|
||||
if (!users.isEmpty()) {
|
||||
rst = resultService.success("获取所有用户信息成功!", users);
|
||||
}else{
|
||||
} else {
|
||||
rst = resultService.error("获取所有用户信息失败!", "");
|
||||
}
|
||||
}else{
|
||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
} else {
|
||||
rst = resultService.other(-2, "授权信息有误或已过期,请更换后重新尝试!", "");
|
||||
}
|
||||
logger.info("调用方法getAllUser()结束 返回:{}", rst);
|
||||
return rst;
|
||||
@@ -49,22 +48,22 @@ public class UserController {
|
||||
|
||||
@RequestMapping("/api/user/getUserByOpenId")
|
||||
@ResponseBody
|
||||
public String getUserByOpenId(@RequestBody User user){
|
||||
public String getUserByOpenId(@RequestBody User user) {
|
||||
logger.info("调用方法getUserByOpenId()开始 入参:{}", user);
|
||||
String openId = user.getOpenId();
|
||||
String rst;
|
||||
if(openId == null|| openId.isEmpty()){
|
||||
if (openId == null || openId.isEmpty()) {
|
||||
rst = resultService.error("参数code不存在,请检查入参!");
|
||||
}else {
|
||||
if(this.checkAuth(user.getAuthCode())){
|
||||
} 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,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
} else {
|
||||
rst = resultService.other(-2, "授权信息有误或已过期,请更换后重新尝试!", "");
|
||||
}
|
||||
}
|
||||
logger.info("调用方法getUserByOpenId()结束 返回:{}", rst);
|
||||
@@ -72,15 +71,15 @@ public class UserController {
|
||||
}
|
||||
|
||||
@RequestMapping("/api/user/addUser")
|
||||
public String addUser(@RequestBody User user){
|
||||
logger.info("调用方法addUser()开始 入参:{}",user);
|
||||
public String addUser(@RequestBody User user) {
|
||||
logger.info("调用方法addUser()开始 入参:{}", user);
|
||||
logger.info("1.检测用户是否存在(addUser)");
|
||||
int exist = userService.userExist(user);
|
||||
String rst;
|
||||
if(exist>0) {
|
||||
if (exist > 0) {
|
||||
logger.info("2.用户已存在,不能新建用户(addUser)");
|
||||
rst = resultService.other(-2,"用户已存在!","");
|
||||
}else{
|
||||
rst = resultService.other(-2, "用户已存在!", "");
|
||||
} else {
|
||||
logger.info("2.用户不存在,新建用户(addUser)");
|
||||
int code = userService.addUser(user);
|
||||
if (code > 0) {
|
||||
@@ -94,10 +93,10 @@ public class UserController {
|
||||
}
|
||||
|
||||
@RequestMapping("/api/user/login")
|
||||
public String login(@RequestBody User user){
|
||||
logger.info("调用方法login()开始 入参:{}",user);
|
||||
public String login(@RequestBody User user) {
|
||||
logger.info("调用方法login()开始 入参:{}", user);
|
||||
String rst;
|
||||
if(this.checkAuth(user.getAuthCode())) {
|
||||
if (this.checkAuth(user.getAuthCode())) {
|
||||
logger.info("1.检测用户是否存在(login)");
|
||||
int exist = userService.userExist(user);
|
||||
if (exist > 0) {
|
||||
@@ -119,59 +118,58 @@ public class UserController {
|
||||
logger.info("2.用户不存在,需要注册(login)");
|
||||
rst = resultService.other(-2, "用户不存在,请进行注册!", "");
|
||||
}
|
||||
}else{
|
||||
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);
|
||||
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())) {
|
||||
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,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
} 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);
|
||||
public String updateUser(@RequestBody User user) {
|
||||
logger.info("调用方法updateUser()开始 入参:{}", user);
|
||||
String rst;
|
||||
if(this.checkAuth(user.getAuthCode())) {
|
||||
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,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
} 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);
|
||||
public String deleteUser(@RequestBody User user) {
|
||||
logger.info("调用方法deleteUser()开始 入参:{}", user);
|
||||
String rst;
|
||||
if(this.checkAuth(user.getAuthCode())) {
|
||||
if (this.checkAuth(user.getAuthCode())) {
|
||||
logger.info("1.检测用户是否存在(deleteUser)");
|
||||
int exist = userService.userExist(user);
|
||||
if (exist > 0) {
|
||||
@@ -186,39 +184,39 @@ public class UserController {
|
||||
logger.info("2.用户不存在(deleteUser)");
|
||||
rst = resultService.error("用户不存在!");
|
||||
}
|
||||
}else{
|
||||
rst = resultService.other(-2,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
} else {
|
||||
rst = resultService.other(-2, "授权信息有误或已过期,请更换后重新尝试!", "");
|
||||
}
|
||||
logger.info("调用方法deleteUser()结束 返回:{}",rst);
|
||||
logger.info("调用方法deleteUser()结束 返回:{}", rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@RequestMapping("/api/user/deleteUserByOpenId")
|
||||
public String deleteUserByOpenId(@RequestBody User user){
|
||||
logger.info("调用方法deleteUserByOpenId()开始 入参:{}",user);
|
||||
public String deleteUserByOpenId(@RequestBody User user) {
|
||||
logger.info("调用方法deleteUserByOpenId()开始 入参:{}", user);
|
||||
String rst;
|
||||
if(this.checkAuth(user.getAuthCode())) {
|
||||
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,"授权信息有误或已过期,请更换后重新尝试!","");
|
||||
} else {
|
||||
rst = resultService.other(-2, "授权信息有误或已过期,请更换后重新尝试!", "");
|
||||
}
|
||||
logger.info("调用方法deleteUserByOpenId()结束 返回:{}",rst);
|
||||
logger.info("调用方法deleteUserByOpenId()结束 返回:{}", rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
public boolean checkAuth(String auth_code){
|
||||
logger.info("调用方法checkAuth()开始 入参:{}",auth_code);
|
||||
public boolean checkAuth(String auth_code) {
|
||||
logger.info("调用方法checkAuth()开始 入参:{}", auth_code);
|
||||
String auth_new = authService.getAuthMd5CodeInside();
|
||||
logger.info("最新授权码 {}",auth_new);
|
||||
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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,15 +25,16 @@ public class WXController {
|
||||
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);
|
||||
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
|
||||
"?appid=" + appid +
|
||||
"&secret=" + secret + // 自己的appSecret
|
||||
"&js_code=" + code +
|
||||
"&grant_type=authorization_code" +
|
||||
"&connect_redirect=1";
|
||||
@@ -43,8 +44,8 @@ public class WXController {
|
||||
return resultService.error("参数code不存在,请检查入参!");
|
||||
}
|
||||
String result = HttpUtil.get(url, CharsetUtil.CHARSET_UTF_8);
|
||||
String rst = resultService.success("调用完成",result);
|
||||
logger.info("调用方法getOpenId()结束 {}",rst);
|
||||
String rst = resultService.success("调用完成", result);
|
||||
logger.info("调用方法getOpenId()结束 {}", rst);
|
||||
return rst;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,12 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
public interface AuthMapper {
|
||||
|
||||
String getAuthCode(User user);
|
||||
|
||||
String getAuthMd5Code(User user);
|
||||
|
||||
String getAuthMd5CodeInside();
|
||||
|
||||
int addUseCount(String authCode);
|
||||
|
||||
int addAuth(Auth auth);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ 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);
|
||||
}
|
||||
|
||||
@@ -2,12 +2,10 @@ 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);
|
||||
|
||||
@@ -5,8 +5,12 @@ 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);
|
||||
}
|
||||
|
||||
@@ -1,10 +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);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package cn.lailab.toolbox.service;
|
||||
|
||||
public interface ResultService {
|
||||
|
||||
String success();
|
||||
|
||||
String success(String message);
|
||||
String success(String message,Object data);
|
||||
|
||||
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);
|
||||
|
||||
String error(String message, Object data);
|
||||
|
||||
String other(int code, String message, Object data);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cn.lailab.toolbox.service;
|
||||
|
||||
import cn.lailab.toolbox.beans.domain.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
@@ -5,7 +5,6 @@ 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
|
||||
|
||||
@@ -12,39 +12,41 @@ public class ResultServiceImpl implements ResultService {
|
||||
Result result = new Result();
|
||||
result.setCode(code);
|
||||
result.setMessage(message);
|
||||
if(data == null) result.setData("");
|
||||
if (data == null)
|
||||
result.setData("");
|
||||
result.setData(data);
|
||||
result.setTimestamp(System.currentTimeMillis());
|
||||
//return JSONUtil.toJsonPrettyStr(result);
|
||||
// return JSONUtil.toJsonPrettyStr(result);
|
||||
return JSONUtil.toJsonStr(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String success() {
|
||||
return other(0,"success","");
|
||||
return other(0, "success", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String success(String message) {
|
||||
return other(0,message,"");
|
||||
return other(0, message, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String success(String message, Object data) {
|
||||
return other(0,message,data);
|
||||
return other(0, message, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String error() {
|
||||
return other(-1,"error","");
|
||||
return other(-1, "error", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String error(String message) {
|
||||
return other(-1,message,"");
|
||||
return other(-1, message, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String error(String message, Object data) {
|
||||
return other(-1,message,data);
|
||||
return other(-1, message, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ 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;
|
||||
|
||||
@@ -27,15 +26,15 @@ public class UserServiceImpl implements UserService {
|
||||
public int addUser(User user) {
|
||||
int maxId;
|
||||
maxId = userMapper.getMaxId();
|
||||
maxId +=1;
|
||||
maxId += 1;
|
||||
// 自动生成用户名
|
||||
if(user.getUsername().isEmpty()){
|
||||
user.setUsername(String.format("%05d",maxId));
|
||||
if (user.getUsername().isEmpty()) {
|
||||
user.setUsername(String.format("%05d", maxId));
|
||||
}
|
||||
// 对用户输入的密码进行MD5加密
|
||||
if(user.getPassword().isEmpty()) {
|
||||
if (user.getPassword().isEmpty()) {
|
||||
user.setPassword(SecureUtil.md5(defaultPassword).toUpperCase());
|
||||
}else{
|
||||
} else {
|
||||
user.setPassword(SecureUtil.md5(user.getPassword()).toUpperCase());
|
||||
}
|
||||
// 创建时间赋值
|
||||
@@ -71,9 +70,9 @@ public class UserServiceImpl implements UserService {
|
||||
@Override
|
||||
public int updateUser(User user) {
|
||||
// 对用户输入的密码进行MD5加密
|
||||
if(user.getPassword().isEmpty()) {
|
||||
if (user.getPassword().isEmpty()) {
|
||||
user.setPassword(SecureUtil.md5(defaultPassword).toUpperCase());
|
||||
}else{
|
||||
} else {
|
||||
user.setPassword(SecureUtil.md5(user.getPassword()).toUpperCase());
|
||||
}
|
||||
return userMapper.updateUser(user);
|
||||
@@ -103,5 +102,4 @@ public class UserServiceImpl implements UserService {
|
||||
return userMapper.getMaxId();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ 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
|
||||
@@ -40,7 +39,7 @@ public class AuthTask {
|
||||
|
||||
if (code > 0) {
|
||||
logger.info("调用方法authTask()结束 添加成功!");
|
||||
}else{
|
||||
} else {
|
||||
logger.info("调用方法authTask()结束 添加失败!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{"properties": [{
|
||||
"name": "mybatis.mapper-locations",
|
||||
"type": "java.lang.String",
|
||||
"description": "A description for 'mybatis.mapper-locations'"
|
||||
}]}{"properties": [{
|
||||
"name": "mybatis.mapper-locations",
|
||||
"type": "java.lang.String",
|
||||
"description": "A description for 'mybatis.mapper-locations'"
|
||||
}]}
|
||||
@@ -33,7 +33,7 @@ logging:
|
||||
level:
|
||||
org.springframework.web: info
|
||||
org.hibernate.SQL: debug
|
||||
cn.lailab: info
|
||||
cn.lailab.toolbox: info
|
||||
logback:
|
||||
rollingpolicy:
|
||||
max-file-size: 10MB
|
||||
@@ -37,7 +37,7 @@ mybatis:
|
||||
# 3. 开启驼峰命名自动转换(比如数据库字段 user_name 自动映射到实体类属性 userName)
|
||||
# configuration:
|
||||
# map-underscore-to-camel-case: true
|
||||
# 可选:开启日志打印,方便调试 SQL
|
||||
# 可选:开启日志打印,方便调试 SQL
|
||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
logging:
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<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: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||
font-family:
|
||||
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
@@ -85,8 +86,8 @@
|
||||
grid-column: span 2;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
</head>
|
||||
<body>
|
||||
<div class="display">0</div>
|
||||
<div class="buttons">
|
||||
<button class="func-btn" id="ac">AC</button>
|
||||
@@ -115,10 +116,10 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const display = document.querySelector('.display');
|
||||
let currentValue = '0';
|
||||
let previousValue = '';
|
||||
let operator = '';
|
||||
const display = document.querySelector(".display");
|
||||
let currentValue = "0";
|
||||
let previousValue = "";
|
||||
let operator = "";
|
||||
let resetDisplay = false;
|
||||
|
||||
// 更新显示
|
||||
@@ -127,14 +128,14 @@
|
||||
}
|
||||
|
||||
// 数字按钮
|
||||
document.querySelectorAll('.num-btn').forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
document.querySelectorAll(".num-btn").forEach((btn) => {
|
||||
btn.addEventListener("click", () => {
|
||||
const value = btn.textContent;
|
||||
if (currentValue === '0' || resetDisplay) {
|
||||
if (currentValue === "0" || resetDisplay) {
|
||||
currentValue = value;
|
||||
resetDisplay = false;
|
||||
} else {
|
||||
if (value === '.' && currentValue.includes('.')) return;
|
||||
if (value === "." && currentValue.includes(".")) return;
|
||||
currentValue += value;
|
||||
}
|
||||
updateDisplay();
|
||||
@@ -142,9 +143,9 @@
|
||||
});
|
||||
|
||||
// 运算符按钮
|
||||
document.querySelectorAll('.op-btn').forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
if (btn.id === 'equals') return;
|
||||
document.querySelectorAll(".op-btn").forEach((btn) => {
|
||||
btn.addEventListener("click", () => {
|
||||
if (btn.id === "equals") return;
|
||||
if (previousValue && operator && !resetDisplay) calculate();
|
||||
previousValue = currentValue;
|
||||
operator = btn.id;
|
||||
@@ -153,23 +154,25 @@
|
||||
});
|
||||
|
||||
// 等号按钮
|
||||
document.getElementById('equals').addEventListener('click', calculate);
|
||||
document.getElementById("equals").addEventListener("click", calculate);
|
||||
|
||||
// 功能按钮
|
||||
document.getElementById('ac').addEventListener('click', () => {
|
||||
currentValue = '0';
|
||||
previousValue = '';
|
||||
operator = '';
|
||||
document.getElementById("ac").addEventListener("click", () => {
|
||||
currentValue = "0";
|
||||
previousValue = "";
|
||||
operator = "";
|
||||
resetDisplay = false;
|
||||
updateDisplay();
|
||||
});
|
||||
|
||||
document.getElementById('plus-minus').addEventListener('click', () => {
|
||||
currentValue = currentValue.startsWith('-') ? currentValue.slice(1) : '-' + currentValue;
|
||||
document.getElementById("plus-minus").addEventListener("click", () => {
|
||||
currentValue = currentValue.startsWith("-")
|
||||
? currentValue.slice(1)
|
||||
: "-" + currentValue;
|
||||
updateDisplay();
|
||||
});
|
||||
|
||||
document.getElementById('percent').addEventListener('click', () => {
|
||||
document.getElementById("percent").addEventListener("click", () => {
|
||||
currentValue = (parseFloat(currentValue) / 100).toString();
|
||||
updateDisplay();
|
||||
});
|
||||
@@ -182,21 +185,33 @@
|
||||
const curr = parseFloat(currentValue);
|
||||
|
||||
switch (operator) {
|
||||
case 'add': result = prev + curr; break;
|
||||
case 'subtract': result = prev - curr; break;
|
||||
case 'multiply': result = prev * curr; break;
|
||||
case 'divide': result = curr === 0 ? '错误' : prev / curr; break;
|
||||
default: return;
|
||||
case "add":
|
||||
result = prev + curr;
|
||||
break;
|
||||
case "subtract":
|
||||
result = prev - curr;
|
||||
break;
|
||||
case "multiply":
|
||||
result = prev * curr;
|
||||
break;
|
||||
case "divide":
|
||||
result = curr === 0 ? "错误" : prev / curr;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
currentValue = typeof result === 'number'
|
||||
? (result % 1 === 0 ? result.toString() : result.toFixed(6).replace(/\.?0*$/, ''))
|
||||
currentValue =
|
||||
typeof result === "number"
|
||||
? result % 1 === 0
|
||||
? result.toString()
|
||||
: result.toFixed(6).replace(/\.?0*$/, "")
|
||||
: result;
|
||||
previousValue = '';
|
||||
operator = '';
|
||||
previousValue = "";
|
||||
operator = "";
|
||||
resetDisplay = true;
|
||||
updateDisplay();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user