mirror of
https://github.com/blossom-editor/blossom
synced 2024-11-17 22:48:03 +08:00
fix:初始化参数失败后获取参数产生的空指针异常(#10)
This commit is contained in:
parent
a636c26664
commit
1826b4a83c
@ -2,22 +2,22 @@ package com.blossom.backend.base.param;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.blossom.backend.base.param.pojo.ParamEntity;
|
||||
import com.blossom.backend.base.param.pojo.ParamReq;
|
||||
import com.blossom.common.base.exception.XzException404;
|
||||
import com.blossom.common.base.exception.XzException500;
|
||||
import com.blossom.common.base.util.BeanUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -48,8 +48,15 @@ public class ParamService extends ServiceImpl<ParamMapper, ParamEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数名称获取参数
|
||||
*
|
||||
* @param name 参数名称
|
||||
*/
|
||||
public ParamEntity getValue(ParamEnum name) {
|
||||
return CACHE.get(name.name());
|
||||
ParamEntity param = CACHE.get(name.name());
|
||||
XzException500.throwBy(ObjUtil.isNull(param), String.format("缺失系统参数[%s], 请检查系统参数配置", name.name()));
|
||||
return param;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,6 +73,7 @@ public class ParamService extends ServiceImpl<ParamMapper, ParamEntity> {
|
||||
Map<String, String> result = new HashMap<>(names.length);
|
||||
for (ParamEnum name : names) {
|
||||
ParamEntity param = BeanUtil.toObj(CACHE.get(name.name()), ParamEntity.class);
|
||||
XzException500.throwBy(ObjUtil.isNull(param), "缺失所有系统参数, 请检查系统参数[BASE_SYS_PARAM]中是否包含数据");
|
||||
if (masking && name.getMasking()) {
|
||||
param.setParamValue(StrUtil.hide(param.getParamValue(), 0, Math.min(param.getParamValue().length(), name.getMaskingLength())));
|
||||
}
|
||||
@ -75,7 +83,7 @@ public class ParamService extends ServiceImpl<ParamMapper, ParamEntity> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* 修改参数
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long update(ParamReq req) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.blossom.backend.thirdparty.hefeng;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.blossom.common.base.pojo.R;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -23,7 +24,10 @@ public class WeatherController {
|
||||
* 获取天气信息
|
||||
*/
|
||||
@GetMapping
|
||||
public R<HeWeatherDTO> weather(@RequestParam("location")String location) {
|
||||
public R<HeWeatherDTO> weather(@RequestParam(value = "location",required = false)String location) {
|
||||
if (StrUtil.isBlank(location)) {
|
||||
return R.ok(new HeWeatherDTO());
|
||||
}
|
||||
return R.ok(weatherManager.findWeatherAll(location));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user