feat: 新增网站配置修改功能
This commit is contained in:
parent
b30f6c2eb0
commit
dcc87cb63b
@ -17,6 +17,8 @@
|
||||
package top.charles7c.cnadmin.monitor.interceptor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@ -44,6 +46,8 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.http.HttpStatus;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
|
||||
import top.charles7c.cnadmin.auth.model.request.LoginRequest;
|
||||
@ -214,19 +218,31 @@ public class LogInterceptor implements HandlerInterceptor {
|
||||
logDO.setRequestMethod(request.getMethod());
|
||||
logDO.setRequestHeaders(this.desensitize(ServletUtil.getHeaderMap(request)));
|
||||
String requestBody = this.getRequestBody(request);
|
||||
if (StrUtil.isNotBlank(requestBody)) {
|
||||
logDO.setRequestBody(this.desensitize(
|
||||
JSONUtil.isTypeJSON(requestBody) ? JSONUtil.parseObj(requestBody) : ServletUtil.getParamMap(request)));
|
||||
}
|
||||
logDO.setClientIp(ServletUtil.getClientIP(request));
|
||||
logDO.setLocation(IpUtils.getCityInfo(logDO.getClientIp()));
|
||||
logDO.setBrowser(ServletUtils.getBrowser(request));
|
||||
logDO.setCreateUser(ObjectUtil.defaultIfNull(logDO.getCreateUser(), LoginHelper.getUserId()));
|
||||
if (null == logDO.getCreateUser() && SysConsts.LOGIN_URI.equals(request.getRequestURI())) {
|
||||
LoginRequest loginRequest = JSONUtil.toBean(requestBody, LoginRequest.class);
|
||||
logDO.setCreateUser(
|
||||
ExceptionUtils.exToNull(() -> userService.getByUsername(loginRequest.getUsername()).getId()));
|
||||
}
|
||||
if (StrUtil.isNotBlank(requestBody)) {
|
||||
if (JSONUtil.isTypeJSONObject(requestBody)) {
|
||||
requestBody = this.desensitize(JSONUtil.parseObj(requestBody));
|
||||
} else if (JSONUtil.isTypeJSONArray(requestBody)) {
|
||||
JSONArray requestBodyJsonArr = JSONUtil.parseArray(requestBody);
|
||||
List<JSONObject> requestBodyJsonObjList = new ArrayList<>(requestBodyJsonArr.size());
|
||||
for (Object requestBodyJsonObj : requestBodyJsonArr) {
|
||||
requestBodyJsonObjList
|
||||
.add(JSONUtil.parseObj(this.desensitize(JSONUtil.parseObj(requestBodyJsonObj))));
|
||||
}
|
||||
requestBody = JSONUtil.toJsonStr(requestBodyJsonObjList);
|
||||
} else {
|
||||
requestBody = this.desensitize(ServletUtil.getParamMap(request));
|
||||
}
|
||||
logDO.setRequestBody(requestBody);
|
||||
}
|
||||
logDO.setClientIp(ServletUtil.getClientIP(request));
|
||||
logDO.setLocation(IpUtils.getCityInfo(logDO.getClientIp()));
|
||||
logDO.setBrowser(ServletUtils.getBrowser(request));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.system.model.request;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.BaseRequest;
|
||||
|
||||
/**
|
||||
* 修改系统参数信息
|
||||
*
|
||||
* @author Bull-BCLS
|
||||
* @since 2023/8/26 19:38
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "修改系统参数信息")
|
||||
public class OptionRequest extends BaseRequest {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 参数键
|
||||
*/
|
||||
@Schema(description = "参数键", example = "site_title")
|
||||
@NotBlank(message = "参数键不能为空")
|
||||
@Length(max = 100, message = "参数键长度不能超过 {max} 个字符")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 参数值
|
||||
*/
|
||||
@Schema(description = "参数值", example = "ContiNew Admin")
|
||||
@NotBlank(message = "参数值不能为空")
|
||||
private String value;
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.system.model.request;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
/**
|
||||
* 重置系统参数信息
|
||||
*
|
||||
* @author Bull-BCLS
|
||||
* @since 2023/9/21 23:10
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "重置系统参数信息")
|
||||
public class ResetOptionValueRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 参数键列表
|
||||
*/
|
||||
@Schema(description = "参数键列表", example = "site_title,site_copyright")
|
||||
@NotEmpty(message = "参数键不能为空")
|
||||
private List<String> code;
|
||||
}
|
@ -19,6 +19,8 @@ package top.charles7c.cnadmin.system.service;
|
||||
import java.util.List;
|
||||
|
||||
import top.charles7c.cnadmin.system.model.query.OptionQuery;
|
||||
import top.charles7c.cnadmin.system.model.request.OptionRequest;
|
||||
import top.charles7c.cnadmin.system.model.request.ResetOptionValueRequest;
|
||||
import top.charles7c.cnadmin.system.model.vo.OptionVO;
|
||||
|
||||
/**
|
||||
@ -37,4 +39,20 @@ public interface OptionService {
|
||||
* @return 列表信息
|
||||
*/
|
||||
List<OptionVO> list(OptionQuery query);
|
||||
|
||||
/**
|
||||
* 修改系统参数
|
||||
*
|
||||
* @param request
|
||||
* 参数信息
|
||||
*/
|
||||
void update(List<OptionRequest> request);
|
||||
|
||||
/**
|
||||
* 重置系统参数
|
||||
*
|
||||
* @param request
|
||||
* 重置参数信息
|
||||
*/
|
||||
void resetValue(ResetOptionValueRequest request);
|
||||
}
|
@ -26,7 +26,10 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
|
||||
import top.charles7c.cnadmin.common.util.helper.QueryHelper;
|
||||
import top.charles7c.cnadmin.system.mapper.OptionMapper;
|
||||
import top.charles7c.cnadmin.system.model.entity.OptionDO;
|
||||
import top.charles7c.cnadmin.system.model.query.OptionQuery;
|
||||
import top.charles7c.cnadmin.system.model.request.OptionRequest;
|
||||
import top.charles7c.cnadmin.system.model.request.ResetOptionValueRequest;
|
||||
import top.charles7c.cnadmin.system.model.vo.OptionVO;
|
||||
import top.charles7c.cnadmin.system.service.OptionService;
|
||||
|
||||
@ -46,4 +49,14 @@ public class OptionServiceImpl implements OptionService {
|
||||
public List<OptionVO> list(OptionQuery query) {
|
||||
return BeanUtil.copyToList(baseMapper.selectList(QueryHelper.build(query)), OptionVO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(List<OptionRequest> request) {
|
||||
baseMapper.updateBatchById(BeanUtil.copyToList(request, OptionDO.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetValue(ResetOptionValueRequest request) {
|
||||
baseMapper.lambdaUpdate().set(OptionDO::getValue, null).in(OptionDO::getCode, request.getCode()).update();
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ export interface BasicConfigRecord {
|
||||
}
|
||||
|
||||
export interface DataRecord {
|
||||
name: string;
|
||||
name?: string;
|
||||
code: string;
|
||||
value: string;
|
||||
description?: string;
|
||||
@ -30,6 +30,10 @@ export function list(params: ListParam) {
|
||||
});
|
||||
}
|
||||
|
||||
export function save(req: DataRecord[]) {
|
||||
return axios.patch(`${BASE_URL}`, req);
|
||||
}
|
||||
|
||||
export function resetValue(params: ListParam) {
|
||||
return axios.patch(`${BASE_URL}/value`, params);
|
||||
}
|
||||
|
@ -164,6 +164,7 @@
|
||||
DataRecord,
|
||||
ListParam,
|
||||
list,
|
||||
save,
|
||||
resetValue,
|
||||
} from '@/api/system/config';
|
||||
|
||||
@ -207,18 +208,49 @@
|
||||
siteFavicon.value = dataList.value.find(
|
||||
(option) => option.code === 'site_favicon'
|
||||
);
|
||||
form.value.site_title = siteTitle.value?.value;
|
||||
form.value.site_copyright = siteCopyright.value?.value;
|
||||
form.value = {
|
||||
site_title: siteTitle.value?.value,
|
||||
site_copyright: siteCopyright.value?.value,
|
||||
site_logo: {
|
||||
url: siteLogo.value?.value,
|
||||
},
|
||||
site_favicon: {
|
||||
url: siteFavicon.value?.value,
|
||||
},
|
||||
};
|
||||
logoFile.value.url = siteLogo.value?.value;
|
||||
faviconFile.value.url = siteFavicon.value?.value;
|
||||
};
|
||||
getConfig();
|
||||
|
||||
/**
|
||||
* 取消
|
||||
*/
|
||||
const handleCancel = () => {
|
||||
isEdit.value = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
const handleSave = async () => {
|
||||
isEdit.value = false;
|
||||
const handleSave = () => {
|
||||
proxy.$refs.formRef.validate((valid: any) => {
|
||||
if (!valid) {
|
||||
const optionList: DataRecord[] = Object.entries(form.value).map(
|
||||
(item) => {
|
||||
return {
|
||||
code: item[0],
|
||||
value: item[1]?.url || item[1],
|
||||
};
|
||||
}
|
||||
);
|
||||
save(optionList).then((res) => {
|
||||
// siteConfigStore().save(data.form);
|
||||
handleCancel();
|
||||
proxy.$message.success(res.msg);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@ -315,14 +347,6 @@
|
||||
const reset = () => {
|
||||
proxy.$refs.formRef?.resetFields();
|
||||
};
|
||||
|
||||
/**
|
||||
* 取消
|
||||
*/
|
||||
const handleCancel = () => {
|
||||
isEdit.value = false;
|
||||
reset();
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
|
@ -18,19 +18,20 @@ package top.charles7c.cnadmin.webapi.controller.system;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
|
||||
import top.charles7c.cnadmin.common.model.vo.R;
|
||||
import top.charles7c.cnadmin.system.model.query.OptionQuery;
|
||||
import top.charles7c.cnadmin.system.model.request.OptionRequest;
|
||||
import top.charles7c.cnadmin.system.model.request.ResetOptionValueRequest;
|
||||
import top.charles7c.cnadmin.system.model.vo.OptionVO;
|
||||
import top.charles7c.cnadmin.system.service.OptionService;
|
||||
|
||||
@ -54,4 +55,20 @@ public class OptionController {
|
||||
public R<List<OptionVO>> list(@Validated OptionQuery query) {
|
||||
return R.ok(optionService.list(query));
|
||||
}
|
||||
|
||||
@Operation(summary = "修改系统参数", description = "修改系统参数")
|
||||
@SaCheckPermission("system:config:update")
|
||||
@PatchMapping
|
||||
public R update(@Validated @RequestBody List<OptionRequest> request) {
|
||||
optionService.update(request);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "重置系统参数", description = "重置系统参数")
|
||||
@SaCheckPermission("system:config:reset")
|
||||
@PatchMapping("/value")
|
||||
public R resetValue(@Validated @RequestBody ResetOptionValueRequest request) {
|
||||
optionService.resetValue(request);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user