Files
lailab-toolbox-server/src/main/java/cn/lailab/toolbox/controller/ParameterController.java
T
2026-01-15 15:17:05 +00:00

89 lines
3.5 KiB
Java

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.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;
}
}