2026-01-07
1.优化代码
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package cn.lailab.toolbox.beans.domain;
|
package cn.lailab.toolbox.beans.domain;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package cn.lailab.toolbox.beans.domain;
|
package cn.lailab.toolbox.beans.domain;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Data
|
@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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class AuthController {
|
public class AuthController {
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ public class ParameterController {
|
|||||||
String defaultAuthCode;
|
String defaultAuthCode;
|
||||||
private final Logger logger = LoggerFactory.getLogger(UserController.class);
|
private final Logger logger = LoggerFactory.getLogger(UserController.class);
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("/api/parameter/getAllParameter")
|
@RequestMapping("/api/parameter/getAllParameter")
|
||||||
public String getAllParameter(@RequestBody Parameter parameter) {
|
public String getAllParameter(@RequestBody Parameter parameter) {
|
||||||
logger.info("调用方法getAllParameter()开始 入参:{}", parameter);
|
logger.info("调用方法getAllParameter()开始 入参:{}", parameter);
|
||||||
@@ -50,7 +49,6 @@ public class ParameterController {
|
|||||||
return rst;
|
return rst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("/api/parameter/getParameterByName")
|
@RequestMapping("/api/parameter/getParameterByName")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String getParameterByName(@RequestBody Parameter parameter) {
|
public String getParameterByName(@RequestBody Parameter parameter) {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -126,7 +125,6 @@ public class UserController {
|
|||||||
return rst;
|
return rst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("/api/user/loginByOpenId")
|
@RequestMapping("/api/user/loginByOpenId")
|
||||||
public String loginByOpenId(@RequestBody User user) {
|
public String loginByOpenId(@RequestBody User user) {
|
||||||
logger.info("loginByOpenId()开始 入参:{}", user);
|
logger.info("loginByOpenId()开始 入参:{}", user);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public class WXController {
|
|||||||
ResultServiceImpl resultService;
|
ResultServiceImpl resultService;
|
||||||
// 定义日志打印类
|
// 定义日志打印类
|
||||||
private final Logger logger = LoggerFactory.getLogger(WXController.class);
|
private final Logger logger = LoggerFactory.getLogger(WXController.class);
|
||||||
|
|
||||||
// 获取微信OpenId
|
// 获取微信OpenId
|
||||||
@RequestMapping("/api/wx/getOpenId")
|
@RequestMapping("/api/wx/getOpenId")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
|||||||
@@ -8,9 +8,12 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
public interface AuthMapper {
|
public interface AuthMapper {
|
||||||
|
|
||||||
String getAuthCode(User user);
|
String getAuthCode(User user);
|
||||||
|
|
||||||
String getAuthMd5Code(User user);
|
String getAuthMd5Code(User user);
|
||||||
|
|
||||||
String getAuthMd5CodeInside();
|
String getAuthMd5CodeInside();
|
||||||
|
|
||||||
int addUseCount(String authCode);
|
int addUseCount(String authCode);
|
||||||
|
|
||||||
int addAuth(Auth auth);
|
int addAuth(Auth auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package cn.lailab.toolbox.mapper;
|
|||||||
|
|
||||||
import cn.lailab.toolbox.beans.domain.Parameter;
|
import cn.lailab.toolbox.beans.domain.Parameter;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface ParameterMapper {
|
public interface ParameterMapper {
|
||||||
List<Parameter> getAllParameter(Parameter parameter);
|
List<Parameter> getAllParameter(Parameter parameter);
|
||||||
|
|
||||||
Parameter getParameterByName(Parameter parameter);
|
Parameter getParameterByName(Parameter parameter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,10 @@ package cn.lailab.toolbox.mapper;
|
|||||||
|
|
||||||
import cn.lailab.toolbox.beans.domain.User;
|
import cn.lailab.toolbox.beans.domain.User;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface UserMapper {
|
public interface UserMapper {
|
||||||
|
|
||||||
int addUser(User user);
|
int addUser(User user);
|
||||||
|
|
||||||
User getUserByOpenId(User user);
|
User getUserByOpenId(User user);
|
||||||
|
|||||||
@@ -5,8 +5,12 @@ import cn.lailab.toolbox.beans.domain.User;
|
|||||||
|
|
||||||
public interface AuthService {
|
public interface AuthService {
|
||||||
String getAuthCode(User user);
|
String getAuthCode(User user);
|
||||||
|
|
||||||
String getAuthMd5Code(User user);
|
String getAuthMd5Code(User user);
|
||||||
|
|
||||||
String getAuthMd5CodeInside();
|
String getAuthMd5CodeInside();
|
||||||
|
|
||||||
int addUseCount(String auth_code);
|
int addUseCount(String auth_code);
|
||||||
|
|
||||||
int addAuth(Auth auth);
|
int addAuth(Auth auth);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package cn.lailab.toolbox.service;
|
package cn.lailab.toolbox.service;
|
||||||
|
|
||||||
import cn.lailab.toolbox.beans.domain.Parameter;
|
import cn.lailab.toolbox.beans.domain.Parameter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface ParameterService {
|
public interface ParameterService {
|
||||||
List<Parameter> getAllParameter(Parameter parameter);
|
List<Parameter> getAllParameter(Parameter parameter);
|
||||||
|
|
||||||
Parameter getParameterByName(Parameter parameter);
|
Parameter getParameterByName(Parameter parameter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
package cn.lailab.toolbox.service;
|
package cn.lailab.toolbox.service;
|
||||||
|
|
||||||
public interface ResultService {
|
public interface ResultService {
|
||||||
|
|
||||||
String success();
|
String success();
|
||||||
|
|
||||||
String success(String message);
|
String success(String message);
|
||||||
|
|
||||||
String success(String message, Object data);
|
String success(String message, Object data);
|
||||||
|
|
||||||
String error();
|
String error();
|
||||||
|
|
||||||
String error(String message);
|
String error(String message);
|
||||||
|
|
||||||
String error(String message, Object data);
|
String error(String message, Object data);
|
||||||
|
|
||||||
String other(int code, String message, Object data);
|
String other(int code, String message, Object data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package cn.lailab.toolbox.service;
|
package cn.lailab.toolbox.service;
|
||||||
|
|
||||||
import cn.lailab.toolbox.beans.domain.User;
|
import cn.lailab.toolbox.beans.domain.User;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface UserService {
|
public interface UserService {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import cn.lailab.toolbox.mapper.ParameterMapper;
|
|||||||
import cn.lailab.toolbox.service.ParameterService;
|
import cn.lailab.toolbox.service.ParameterService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|||||||
@@ -12,12 +12,14 @@ public class ResultServiceImpl implements ResultService {
|
|||||||
Result result = new Result();
|
Result result = new Result();
|
||||||
result.setCode(code);
|
result.setCode(code);
|
||||||
result.setMessage(message);
|
result.setMessage(message);
|
||||||
if(data == null) result.setData("");
|
if (data == null)
|
||||||
|
result.setData("");
|
||||||
result.setData(data);
|
result.setData(data);
|
||||||
result.setTimestamp(System.currentTimeMillis());
|
result.setTimestamp(System.currentTimeMillis());
|
||||||
// return JSONUtil.toJsonPrettyStr(result);
|
// return JSONUtil.toJsonPrettyStr(result);
|
||||||
return JSONUtil.toJsonStr(result);
|
return JSONUtil.toJsonStr(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String success() {
|
public String success() {
|
||||||
return other(0, "success", "");
|
return other(0, "success", "");
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import cn.lailab.toolbox.service.UserService;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -103,5 +102,4 @@ public class UserServiceImpl implements UserService {
|
|||||||
return userMapper.getMaxId();
|
return userMapper.getMaxId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
|||||||
@@ -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:
|
level:
|
||||||
org.springframework.web: info
|
org.springframework.web: info
|
||||||
org.hibernate.SQL: debug
|
org.hibernate.SQL: debug
|
||||||
cn.lailab: info
|
cn.lailab.toolbox: info
|
||||||
logback:
|
logback:
|
||||||
rollingpolicy:
|
rollingpolicy:
|
||||||
max-file-size: 10MB
|
max-file-size: 10MB
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="zh-CN">
|
<html lang="zh-CN">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>计算器</title>
|
<title>计算器</title>
|
||||||
<style>
|
<style>
|
||||||
* {
|
* {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
box-sizing: border-box;
|
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 {
|
body {
|
||||||
@@ -115,10 +116,10 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const display = document.querySelector('.display');
|
const display = document.querySelector(".display");
|
||||||
let currentValue = '0';
|
let currentValue = "0";
|
||||||
let previousValue = '';
|
let previousValue = "";
|
||||||
let operator = '';
|
let operator = "";
|
||||||
let resetDisplay = false;
|
let resetDisplay = false;
|
||||||
|
|
||||||
// 更新显示
|
// 更新显示
|
||||||
@@ -127,14 +128,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 数字按钮
|
// 数字按钮
|
||||||
document.querySelectorAll('.num-btn').forEach(btn => {
|
document.querySelectorAll(".num-btn").forEach((btn) => {
|
||||||
btn.addEventListener('click', () => {
|
btn.addEventListener("click", () => {
|
||||||
const value = btn.textContent;
|
const value = btn.textContent;
|
||||||
if (currentValue === '0' || resetDisplay) {
|
if (currentValue === "0" || resetDisplay) {
|
||||||
currentValue = value;
|
currentValue = value;
|
||||||
resetDisplay = false;
|
resetDisplay = false;
|
||||||
} else {
|
} else {
|
||||||
if (value === '.' && currentValue.includes('.')) return;
|
if (value === "." && currentValue.includes(".")) return;
|
||||||
currentValue += value;
|
currentValue += value;
|
||||||
}
|
}
|
||||||
updateDisplay();
|
updateDisplay();
|
||||||
@@ -142,9 +143,9 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 运算符按钮
|
// 运算符按钮
|
||||||
document.querySelectorAll('.op-btn').forEach(btn => {
|
document.querySelectorAll(".op-btn").forEach((btn) => {
|
||||||
btn.addEventListener('click', () => {
|
btn.addEventListener("click", () => {
|
||||||
if (btn.id === 'equals') return;
|
if (btn.id === "equals") return;
|
||||||
if (previousValue && operator && !resetDisplay) calculate();
|
if (previousValue && operator && !resetDisplay) calculate();
|
||||||
previousValue = currentValue;
|
previousValue = currentValue;
|
||||||
operator = btn.id;
|
operator = btn.id;
|
||||||
@@ -153,23 +154,25 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 等号按钮
|
// 等号按钮
|
||||||
document.getElementById('equals').addEventListener('click', calculate);
|
document.getElementById("equals").addEventListener("click", calculate);
|
||||||
|
|
||||||
// 功能按钮
|
// 功能按钮
|
||||||
document.getElementById('ac').addEventListener('click', () => {
|
document.getElementById("ac").addEventListener("click", () => {
|
||||||
currentValue = '0';
|
currentValue = "0";
|
||||||
previousValue = '';
|
previousValue = "";
|
||||||
operator = '';
|
operator = "";
|
||||||
resetDisplay = false;
|
resetDisplay = false;
|
||||||
updateDisplay();
|
updateDisplay();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('plus-minus').addEventListener('click', () => {
|
document.getElementById("plus-minus").addEventListener("click", () => {
|
||||||
currentValue = currentValue.startsWith('-') ? currentValue.slice(1) : '-' + currentValue;
|
currentValue = currentValue.startsWith("-")
|
||||||
|
? currentValue.slice(1)
|
||||||
|
: "-" + currentValue;
|
||||||
updateDisplay();
|
updateDisplay();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('percent').addEventListener('click', () => {
|
document.getElementById("percent").addEventListener("click", () => {
|
||||||
currentValue = (parseFloat(currentValue) / 100).toString();
|
currentValue = (parseFloat(currentValue) / 100).toString();
|
||||||
updateDisplay();
|
updateDisplay();
|
||||||
});
|
});
|
||||||
@@ -182,18 +185,30 @@
|
|||||||
const curr = parseFloat(currentValue);
|
const curr = parseFloat(currentValue);
|
||||||
|
|
||||||
switch (operator) {
|
switch (operator) {
|
||||||
case 'add': result = prev + curr; break;
|
case "add":
|
||||||
case 'subtract': result = prev - curr; break;
|
result = prev + curr;
|
||||||
case 'multiply': result = prev * curr; break;
|
break;
|
||||||
case 'divide': result = curr === 0 ? '错误' : prev / curr; break;
|
case "subtract":
|
||||||
default: return;
|
result = prev - curr;
|
||||||
|
break;
|
||||||
|
case "multiply":
|
||||||
|
result = prev * curr;
|
||||||
|
break;
|
||||||
|
case "divide":
|
||||||
|
result = curr === 0 ? "错误" : prev / curr;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentValue = typeof result === 'number'
|
currentValue =
|
||||||
? (result % 1 === 0 ? result.toString() : result.toFixed(6).replace(/\.?0*$/, ''))
|
typeof result === "number"
|
||||||
|
? result % 1 === 0
|
||||||
|
? result.toString()
|
||||||
|
: result.toFixed(6).replace(/\.?0*$/, "")
|
||||||
: result;
|
: result;
|
||||||
previousValue = '';
|
previousValue = "";
|
||||||
operator = '';
|
operator = "";
|
||||||
resetDisplay = true;
|
resetDisplay = true;
|
||||||
updateDisplay();
|
updateDisplay();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user