2026-01-07

1.优化代码
This commit is contained in:
2026-01-17 13:21:46 +08:00
parent 7050446b7a
commit 1040b383dd
24 changed files with 334 additions and 309 deletions
@@ -1,7 +1,6 @@
package cn.lailab.toolbox.beans.domain;
import lombok.Data;
import java.util.Date;
@Data
@@ -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 {
@@ -31,7 +31,6 @@ 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);
@@ -50,7 +49,6 @@ public class ParameterController {
return rst;
}
@RequestMapping("/api/parameter/getParameterByName")
@ResponseBody
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.Value;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@@ -126,7 +125,6 @@ public class UserController {
return rst;
}
@RequestMapping("/api/user/loginByOpenId")
public String loginByOpenId(@RequestBody User user) {
logger.info("loginByOpenId()开始 入参:{}", user);
@@ -25,6 +25,7 @@ public class WXController {
ResultServiceImpl resultService;
// 定义日志打印类
private final Logger logger = LoggerFactory.getLogger(WXController.class);
// 获取微信OpenId
@RequestMapping("/api/wx/getOpenId")
@ResponseBody
@@ -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 error();
String error(String message);
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,12 +12,14 @@ 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.toJsonStr(result);
}
@Override
public String 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.Value;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@@ -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
@@ -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'"
}]}
+1 -1
View File
@@ -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
@@ -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">
<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 {
@@ -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,18 +185,30 @@
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();
}