字典值查询

pull/3/head
caolin 2023-08-13 00:46:18 +08:00
parent 15462ce0ba
commit 773a323d84
5 changed files with 94 additions and 4 deletions

View File

@ -6,8 +6,16 @@ package com.jwl.driver.server.constant;
public class Constants { public class Constants {
//短信验证码redis存储的前缀
public static String MESSAGE_CODE_PREFIX = "code_"; public static String MESSAGE_CODE_PREFIX = "code_";
//短信验证码的模板
public static String MESSAGE_TEMPLATE = "SMS_198880447"; public static String MESSAGE_TEMPLATE = "SMS_198880447";
//是否有效-有效
public static String IS_ACTIVE_TRUE = "0";
//是否有效-无效
public static String IS_ACTIVE_FALSE = "1";
} }

View File

@ -1,9 +1,17 @@
package com.jwl.driver.server.controller; package com.jwl.driver.server.controller;
import org.springframework.web.bind.annotation.RequestMapping; import cn.hutool.core.util.StrUtil;
import com.jwl.driver.server.response.BaseResponse;
import com.jwl.driver.server.service.ITdSysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller; import java.util.Arrays;
import java.util.Map;
/** /**
* <p> * <p>
@ -13,8 +21,33 @@ import org.springframework.stereotype.Controller;
* @author Automated procedures * @author Automated procedures
* @since 2023-08-10 * @since 2023-08-10
*/ */
@Controller @Api(tags = "字典值配置")
@RequestMapping("//tdSysConfig") @RestController
@RequestMapping("/tdSysConfig")
@Slf4j
public class TdSysConfigController { public class TdSysConfigController {
@Autowired
private ITdSysConfigService configService;
/**
* keycarTypeId,carTypeId-1
*/
@ApiOperation("根据配置key和carTypeId获取配置信息,配置与车型无关则carTypeId为-1")
@GetMapping(value = "/queryConfigByKey")
public BaseResponse queryConfigByKey(@RequestParam("configKey") String configKey,@RequestParam("carTypeId") Integer carTypeId) {
return BaseResponse.success(configService.queryConfigByKey(configKey,carTypeId));
}
/**
* keycarTypeId,carTypeId-1
*/
@ApiOperation("根据配置key获取配置值")
@GetMapping(value = "/queryConfigValueByKey")
public BaseResponse<String> queryConfigValueByKey(@RequestParam("configKey") String configKey,@RequestParam("carTypeId") Integer carTypeId) {
return BaseResponse.success(configService.queryConfigValueByKey(configKey,carTypeId));
}
} }

View File

@ -38,6 +38,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(BusinessException.class) @ExceptionHandler(BusinessException.class)
public BaseResponse<?> businessException(BusinessException e) { public BaseResponse<?> businessException(BusinessException e) {
e.printStackTrace();
return BaseResponse.fail(e.getCode(), null, e.getMessage()); return BaseResponse.fail(e.getCode(), null, e.getMessage());
} }
@ -48,6 +49,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
public BaseResponse<?> exception(Exception e) { public BaseResponse<?> exception(Exception e) {
e.printStackTrace();
return BaseResponse.fail(StatusEnum.FAIL.getCode(), null, null); return BaseResponse.fail(StatusEnum.FAIL.getCode(), null, null);
} }
} }

View File

@ -13,4 +13,19 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/ */
public interface ITdSysConfigService extends IService<TdSysConfig> { public interface ITdSysConfigService extends IService<TdSysConfig> {
/**
* keycarTypeId,carTypeId-1
* @param configKey
* @param carTypeId
* @return
*/
TdSysConfig queryConfigByKey(String configKey, Integer carTypeId);
/**
* keycarTypeId,carTypeId-1
* @param configKey
* @param carTypeId
* @return
*/
String queryConfigValueByKey(String configKey,Integer carTypeId);
} }

View File

@ -1,11 +1,17 @@
package com.jwl.driver.server.service.impl; package com.jwl.driver.server.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jwl.driver.server.constant.Constants;
import com.jwl.driver.server.entity.TdSysConfig; import com.jwl.driver.server.entity.TdSysConfig;
import com.jwl.driver.server.mapper.TdSysConfigMapper; import com.jwl.driver.server.mapper.TdSysConfigMapper;
import com.jwl.driver.server.service.ITdSysConfigService; import com.jwl.driver.server.service.ITdSysConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
/** /**
* <p> * <p>
* ; * ;
@ -15,6 +21,32 @@ import org.springframework.stereotype.Service;
* @since 2023-08-10 * @since 2023-08-10
*/ */
@Service @Service
@Slf4j
public class TdSysConfigServiceImpl extends ServiceImpl<TdSysConfigMapper, TdSysConfig> implements ITdSysConfigService { public class TdSysConfigServiceImpl extends ServiceImpl<TdSysConfigMapper, TdSysConfig> implements ITdSysConfigService {
@Override
public TdSysConfig queryConfigByKey(String configKey, Integer carTypeId) {
log.info("获取系统配置参数configKey{}", configKey);
LocalDateTime now = LocalDateTime.now();
LambdaQueryWrapper<TdSysConfig> queryWrapper = new QueryWrapper<TdSysConfig>().lambda()
.eq(TdSysConfig::getCarTypeId,carTypeId)
.eq(TdSysConfig::getConfigKey, configKey)
.eq(TdSysConfig::getIsActive, Constants.IS_ACTIVE_TRUE);
return getOne(queryWrapper);
}
@Override
public String queryConfigValueByKey(String configKey, Integer carTypeId) {
log.info("获取系统配置参数configKey{}", configKey);
LocalDateTime now = LocalDateTime.now();
LambdaQueryWrapper<TdSysConfig> queryWrapper = new QueryWrapper<TdSysConfig>().lambda()
.eq(TdSysConfig::getCarTypeId,carTypeId)
.eq(TdSysConfig::getConfigKey, configKey)
.eq(TdSysConfig::getIsActive, Constants.IS_ACTIVE_TRUE);
TdSysConfig config = getOne(queryWrapper);
if(null == config) {
return null;
}
return config.getConfigValue();
}
} }