添加字典功能及初始化数据
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
package com.emotion.controller;
|
||||
|
||||
import com.emotion.service.DictionaryService;
|
||||
import com.emotion.dto.request.dictionary.DictionaryCreateRequest;
|
||||
import com.emotion.dto.request.dictionary.DictionaryPageRequest;
|
||||
import com.emotion.dto.request.dictionary.DictionaryUpdateRequest;
|
||||
import com.emotion.dto.response.dictionary.DictionaryResponse;
|
||||
import com.emotion.common.PageResult;
|
||||
import com.emotion.common.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典Controller
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-12-22
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/dictionary")
|
||||
public class DictionaryController {
|
||||
|
||||
@Autowired
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
/**
|
||||
* 创建字典
|
||||
*
|
||||
* @param request 创建请求
|
||||
* @return 创建结果
|
||||
*/
|
||||
@PostMapping
|
||||
public Result<DictionaryResponse> createDictionary(@Validated @RequestBody DictionaryCreateRequest request) {
|
||||
return dictionaryService.createDictionary(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新字典
|
||||
*
|
||||
* @param request 更新请求
|
||||
* @return 更新结果
|
||||
*/
|
||||
@PutMapping
|
||||
public Result<DictionaryResponse> updateDictionary(@Validated @RequestBody DictionaryUpdateRequest request) {
|
||||
return dictionaryService.updateDictionary(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除字典
|
||||
*
|
||||
* @param id 字典ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping("/delete")
|
||||
public Result<Void> deleteDictionary(@RequestParam String id) {
|
||||
return dictionaryService.deleteDictionary(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典详情
|
||||
*
|
||||
* @param id 字典ID
|
||||
* @return 字典详情
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
public Result<DictionaryResponse> getDictionary(@RequestParam String id) {
|
||||
return dictionaryService.getDictionary(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询字典
|
||||
*
|
||||
* @param request 分页请求
|
||||
* @return 分页结果
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public Result<PageResult<DictionaryResponse>> listDictionaries(DictionaryPageRequest request) {
|
||||
return dictionaryService.listDictionaries(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型查询字典集合
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @return 字典集合
|
||||
*/
|
||||
@GetMapping("/byType")
|
||||
public Result<List<DictionaryResponse>> getDictionariesByType(@RequestParam String dictType) {
|
||||
return dictionaryService.getDictionariesByType(dictType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型查询启用的字典集合
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @return 启用的字典集合
|
||||
*/
|
||||
@GetMapping("/enabledByType")
|
||||
public Result<List<DictionaryResponse>> getEnabledDictionariesByType(@RequestParam String dictType) {
|
||||
return dictionaryService.getEnabledDictionariesByType(dictType);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user