增加:管理员->系统管理模块接口

This commit is contained in:
moyangzhan 2024-06-11 19:11:11 +08:00
parent 8076c0cafa
commit feaa50fb77
6 changed files with 64 additions and 26 deletions

View File

@ -2,8 +2,9 @@ package com.moyz.adi.admin.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moyz.adi.common.dto.SysConfigDto;
import com.moyz.adi.common.dto.SysConfigEditDto;
import com.moyz.adi.common.dto.SysConfigSearchReq;
import com.moyz.adi.common.entity.SysConfig;
import com.moyz.adi.common.service.KnowledgeBaseService;
import com.moyz.adi.common.service.SysConfigService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.Min;
@ -11,6 +12,8 @@ import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/admin/sys-config")
@Validated
@ -19,13 +22,13 @@ public class SystemConfigController {
@Resource
private SysConfigService sysConfigService;
@GetMapping("/search")
public Page<SysConfig> search(@RequestParam String keyword, @NotNull @Min(1) Integer currentPage, @NotNull @Min(10) Integer pageSize) {
return sysConfigService.search(keyword, currentPage, pageSize);
@PostMapping("/search")
public Page<SysConfigDto> search(@RequestBody SysConfigSearchReq searchReq, @NotNull @Min(1) Integer currentPage, @NotNull @Min(10) Integer pageSize) {
return sysConfigService.search(searchReq, currentPage, pageSize);
}
@PostMapping("/edit")
public void edit(@Validated @RequestBody SysConfigDto sysConfigDto) {
public void edit(@Validated @RequestBody SysConfigEditDto sysConfigDto) {
sysConfigService.edit(sysConfigDto);
}

View File

@ -1,18 +1,9 @@
package com.moyz.adi.common.dto;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.springframework.validation.annotation.Validated;
@Data
@Validated
public class SysConfigDto {
@Min(1)
private Long id;
@NotBlank
private String name;
@NotBlank
private String value;
}

View File

@ -0,0 +1,14 @@
package com.moyz.adi.common.dto;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.springframework.validation.annotation.Validated;
@Data
@Validated
public class SysConfigEditDto {
@NotBlank
private String name;
@NotBlank
private String value;
}

View File

@ -0,0 +1,11 @@
package com.moyz.adi.common.dto;
import lombok.Data;
import java.util.List;
@Data
public class SysConfigSearchReq {
private String keyword;
private List<String> names;
}

View File

@ -5,12 +5,18 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moyz.adi.common.cosntant.AdiConstant;
import com.moyz.adi.common.dto.SysConfigDto;
import com.moyz.adi.common.dto.SysConfigEditDto;
import com.moyz.adi.common.dto.SysConfigSearchReq;
import com.moyz.adi.common.entity.SysConfig;
import com.moyz.adi.common.enums.ErrorEnum;
import com.moyz.adi.common.exception.BaseException;
import com.moyz.adi.common.mapper.SysConfigMapper;
import com.moyz.adi.common.util.JsonUtil;
import com.moyz.adi.common.util.LocalCache;
import com.moyz.adi.common.util.MPPageUtil;
import com.moyz.adi.common.vo.RequestRateLimit;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Scheduled;
@ -54,10 +60,18 @@ public class SysConfigService extends ServiceImpl<SysConfigMapper, SysConfig> {
LocalCache.IMAGE_RATE_LIMIT_CONFIG.setType(RequestRateLimit.TYPE_IMAGE);
}
public void edit(SysConfigDto sysConfigDto) {
SysConfig sysConfig = new SysConfig();
BeanUtils.copyProperties(sysConfigDto, sysConfig);
baseMapper.updateById(sysConfig);
public void edit(SysConfigEditDto sysConfigDto) {
LambdaQueryWrapper<SysConfig> lambdaQueryWrapper = new LambdaQueryWrapper();
lambdaQueryWrapper.eq(SysConfig::getName, sysConfigDto.getName());
lambdaQueryWrapper.eq(SysConfig::getIsDeleted, false);
SysConfig existOne = baseMapper.selectOne(lambdaQueryWrapper);
if (null == existOne) {
throw new BaseException(ErrorEnum.A_DATA_NOT_FOUND);
}
SysConfig updateOne = new SysConfig();
updateOne.setId(existOne.getId());
updateOne.setValue(sysConfigDto.getValue());
baseMapper.updateById(updateOne);
reload();
}
@ -88,13 +102,18 @@ public class SysConfigService extends ServiceImpl<SysConfigMapper, SysConfig> {
return null;
}
public Page<SysConfig> search(String keyword, Integer currentPage, Integer pageSize) {
public Page<SysConfigDto> search(SysConfigSearchReq searchReq, Integer currentPage, Integer pageSize) {
LambdaQueryWrapper<SysConfig> wrapper = new LambdaQueryWrapper<>();
if (StringUtils.isNotBlank(keyword)) {
wrapper.like(SysConfig::getName, keyword);
if (StringUtils.isNotBlank(searchReq.getKeyword())) {
wrapper.like(SysConfig::getName, searchReq.getKeyword());
}
if (CollectionUtils.isNotEmpty(searchReq.getNames())) {
wrapper.in(SysConfig::getName, searchReq.getNames());
}
wrapper.eq(SysConfig::getIsDeleted, false);
return baseMapper.selectPage(new Page<>(currentPage, pageSize), wrapper);
Page<SysConfig> page = baseMapper.selectPage(new Page<>(currentPage, pageSize), wrapper);
Page<SysConfigDto> result = new Page<>();
return MPPageUtil.convertToPage(page, result, SysConfigDto.class);
}
}

View File

@ -403,13 +403,13 @@ create trigger trigger_ai_model
execute procedure update_modified_column();
INSERT INTO adi_sys_config (name, value)
VALUES ('openai_setting', '{"secret_key":"","models":[]}');
VALUES ('openai_setting', '{"secret_key":""}');
INSERT INTO adi_sys_config (name, value)
VALUES ('dashscope_setting', '{"api_key":"","models":[]}');
VALUES ('dashscope_setting', '{"api_key":""}');
INSERT INTO adi_sys_config (name, value)
VALUES ('qianfan_setting', '{"api_key":"","secret_key":"","models":[]}');
VALUES ('qianfan_setting', '{"api_key":"","secret_key":""}');
INSERT INTO adi_sys_config (name, value)
VALUES ('ollama_setting', '{"base_url":"","models":[]}');
VALUES ('ollama_setting', '{"base_url":""}');
INSERT INTO adi_sys_config (name, value)
VALUES ('google_setting',
'{"url":"https://www.googleapis.com/customsearch/v1","key":"","cx":""}');