diff --git a/adi-admin/src/main/java/com/moyz/adi/admin/controller/SystemConfigController.java b/adi-admin/src/main/java/com/moyz/adi/admin/controller/SystemConfigController.java index 48cdbbd..5c1252b 100644 --- a/adi-admin/src/main/java/com/moyz/adi/admin/controller/SystemConfigController.java +++ b/adi-admin/src/main/java/com/moyz/adi/admin/controller/SystemConfigController.java @@ -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 search(@RequestParam String keyword, @NotNull @Min(1) Integer currentPage, @NotNull @Min(10) Integer pageSize) { - return sysConfigService.search(keyword, currentPage, pageSize); + @PostMapping("/search") + public Page 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); } diff --git a/adi-common/src/main/java/com/moyz/adi/common/dto/SysConfigDto.java b/adi-common/src/main/java/com/moyz/adi/common/dto/SysConfigDto.java index fc93154..8df82ee 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/dto/SysConfigDto.java +++ b/adi-common/src/main/java/com/moyz/adi/common/dto/SysConfigDto.java @@ -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; } diff --git a/adi-common/src/main/java/com/moyz/adi/common/dto/SysConfigEditDto.java b/adi-common/src/main/java/com/moyz/adi/common/dto/SysConfigEditDto.java new file mode 100644 index 0000000..65db74e --- /dev/null +++ b/adi-common/src/main/java/com/moyz/adi/common/dto/SysConfigEditDto.java @@ -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; +} diff --git a/adi-common/src/main/java/com/moyz/adi/common/dto/SysConfigSearchReq.java b/adi-common/src/main/java/com/moyz/adi/common/dto/SysConfigSearchReq.java new file mode 100644 index 0000000..93232ca --- /dev/null +++ b/adi-common/src/main/java/com/moyz/adi/common/dto/SysConfigSearchReq.java @@ -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 names; +} diff --git a/adi-common/src/main/java/com/moyz/adi/common/service/SysConfigService.java b/adi-common/src/main/java/com/moyz/adi/common/service/SysConfigService.java index d2ab1cd..fa421af 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/service/SysConfigService.java +++ b/adi-common/src/main/java/com/moyz/adi/common/service/SysConfigService.java @@ -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 { 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 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 { return null; } - public Page search(String keyword, Integer currentPage, Integer pageSize) { + public Page search(SysConfigSearchReq searchReq, Integer currentPage, Integer pageSize) { LambdaQueryWrapper 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 page = baseMapper.selectPage(new Page<>(currentPage, pageSize), wrapper); + Page result = new Page<>(); + return MPPageUtil.convertToPage(page, result, SysConfigDto.class); } } diff --git a/docs/create.sql b/docs/create.sql index 74a2d98..7ee7c0c 100644 --- a/docs/create.sql +++ b/docs/create.sql @@ -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":""}');