Commit 16c47491 by HlQ

[add] 字典管理相关接口更新

1 parent 737cb2cc
......@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.hutool.core.lang.Assert;
import org.springframework.web.bind.annotation.*;
import vion.dto.DictionaryDTO;
import vion.dto.DictionaryTypeDTO;
......@@ -23,56 +24,83 @@ public class DictionaryController {
private final IDictionaryTypeService dictionaryTypeService;
private final Converter converter;
@GetMapping("/dictionarys")
@GetMapping("/dictionary")
@SaCheckPermission(value = "dict:list", orRole = "admin")
public Page<Dictionary> getDictionaryList(DictionaryDTO data) {
return dictionaryService.lambdaQuery(converter.convert(data, Dictionary.class))
.page(Page.of(data.getPageNum(), data.getPageSize()));
}
@GetMapping("/dictionary")
@GetMapping("/dictionary/{id}")
@SaCheckPermission(value = "dict:query", orRole = "admin")
public Object getDictionaryById(Long id) {
public Dictionary getDictionaryById(@PathVariable Long id) {
return dictionaryService.getById(id);
}
@PostMapping("/dictionary")
@SaCheckPermission(value = "dict:editAndSave", orRole = "admin")
public String saveOrUpdateDictionary(@RequestBody DictionaryDTO data) {
Dictionary dictionary = converter.convert(data, Dictionary.class);
return dictionaryService.saveOrUpdate(dictionary) ? "成功" : "失败";
@SaCheckPermission(value = "dict:save", orRole = "admin")
public String save(@RequestBody DictionaryDTO data) {
return dictionaryService.save(data);
}
@PostMapping("/dictionary/{id}")
@SaCheckPermission(value = "dict:edit", orRole = "admin")
public String update(@PathVariable Long id, @RequestBody DictionaryDTO data) {
data.setId(id);
return dictionaryService.update(data);
}
@DeleteMapping("/dictionary/{id}")
@SaCheckPermission(value = "dict:remove", orRole = "admin")
public String remove(@PathVariable Long id, @RequestBody DictionaryDTO data) {
Assert.notNull(data.getType(), "字典项 type 不能为空");
Assert.notNull(data.getKey(), "字典项 key 不能为空");
data.setId(id);
return dictionaryService.remove(id, data);
}
@GetMapping("/dictionaryTypes")
@GetMapping("/dictionaryType")
@SaCheckPermission(value = "dict:type:list", orRole = "admin")
public Page<DictionaryType> getDictionaryTypeList(DictionaryTypeDTO data) {
return dictionaryTypeService.lambdaQuery(converter.convert(data, DictionaryType.class))
.page(Page.of(data.getPageNum(), data.getPageSize()));
}
@GetMapping("/dictionaryType")
@GetMapping("/dictionaryType/{id}")
@SaCheckPermission(value = "dict:type:query", orRole = "admin")
public Object getDictionaryTypeById(@RequestParam Integer id) {
public DictionaryType getDictionaryTypeById(@PathVariable Long id) {
return dictionaryTypeService.getById(id);
}
@PostMapping("/dictionaryType")
@SaCheckPermission(value = "dict:type:editAndSave", orRole = "admin")
public String saveOrUpdateDictionaryType(@RequestBody DictionaryTypeDTO data) {
@SaCheckPermission(value = "dict:type:save", orRole = "admin")
public String saveDictionaryType(@RequestBody DictionaryTypeDTO data) {
DictionaryType dictionaryType = converter.convert(data, DictionaryType.class);
return dictionaryTypeService.save(dictionaryType) ? "成功" : "失败";
}
@PostMapping("/dictionaryType/{id}")
@SaCheckPermission(value = "dict:type:edit", orRole = "admin")
public String updateDictionaryType(@PathVariable Long id, @RequestBody DictionaryTypeDTO data) {
data.setId(id);
DictionaryType dictionaryType = converter.convert(data, DictionaryType.class);
return dictionaryTypeService.saveOrUpdate(dictionaryType) ? "成功" : "失败";
return dictionaryTypeService.updateById(dictionaryType) ? "成功" : "失败";
}
@DeleteMapping("/dictionaryType/{id}")
@SaCheckPermission(value = "dict:type:remove", orRole = "admin")
public String removeDictionaryType(@PathVariable Long id, @RequestBody DictionaryTypeDTO data) {
Assert.notNull(data.getType(), "字典 type 不能为空");
return dictionaryTypeService.remove(id, data);
}
/**
* 同步字典到 Redis
* 目前字典接口未使用,添加字典和字典项是直接在数据库中添加的,所以需要手动同步到 Redis
*
* @return java.lang.String
*/
@GetMapping("/dict/sync")
@SaCheckPermission(value = "dict:sync", orRole = "admin")
// todo 未加权限
public String syncDict() {
dictionaryService.syncDict();
return "同步成功";
......
......@@ -9,6 +9,7 @@ public class DictionaryDTO extends BaseDTO {
private Long id;
private String type;
private Long typeId;
private Integer key;
private String value;
private String remark;
......
......@@ -21,6 +21,7 @@ public class Dictionary {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
private String type;
private Long typeId;
private Integer key;
private String value;
private String remark;
......
package vion.service;
import com.github.yulichang.base.MPJBaseService;
import vion.dto.DictionaryDTO;
import vion.model.Dictionary;
public interface IDictionaryService extends MPJBaseService<Dictionary> {
String save(DictionaryDTO data);
String update(DictionaryDTO data);
String remove(Long id, DictionaryDTO data);
void syncDict();
}
package vion.service;
import com.github.yulichang.base.MPJBaseService;
import vion.dto.DictionaryTypeDTO;
import vion.model.DictionaryType;
public interface IDictionaryTypeService extends MPJBaseService<DictionaryType> {
String remove(Long id, DictionaryTypeDTO data);
}
package vion.service.impl;
import com.github.yulichang.base.MPJBaseServiceImpl;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.dromara.hutool.core.lang.Opt;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;
import vion.constant.RedisKeyEnum;
import vion.dto.DictionaryDTO;
import vion.mapper.DictionaryMapper;
import vion.model.Dictionary;
import vion.service.IDictionaryService;
......@@ -17,6 +19,30 @@ import java.util.stream.Collectors;
public class DictionaryServiceImpl extends MPJBaseServiceImpl<DictionaryMapper, Dictionary> implements IDictionaryService {
private final RedissonClient redissonClient;
private final Converter converter;
@Override
public String save(DictionaryDTO data) {
Dictionary dictionary = converter.convert(data, Dictionary.class);
redissonClient.getMap(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.getValByKey(dictionary.getType()))
.put(dictionary.getKey(), dictionary.getValue());
return this.save(dictionary) ? "成功" : "失败";
}
@Override
public String update(DictionaryDTO data) {
Dictionary dictionary = converter.convert(data, Dictionary.class);
redissonClient.getMap(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.getValByKey(dictionary.getType()))
.put(dictionary.getKey(), dictionary.getValue());
return this.updateById(dictionary) ? "成功" : "失败";
}
@Override
public String remove(Long id, DictionaryDTO data) {
redissonClient.getMap(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.getValByKey(data.getType()))
.remove(data.getKey());
return this.removeById(id) ? "成功" : "失败";
}
@Override
public void syncDict() {
......
package vion.service.impl;
import com.github.yulichang.base.MPJBaseServiceImpl;
import lombok.RequiredArgsConstructor;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;
import vion.constant.RedisKeyEnum;
import vion.dto.DictionaryTypeDTO;
import vion.mapper.DictionaryTypeMapper;
import vion.model.DictionaryType;
import vion.service.IDictionaryTypeService;
@Service
@RequiredArgsConstructor
public class DictionaryTypeServiceImpl extends MPJBaseServiceImpl<DictionaryTypeMapper, DictionaryType> implements IDictionaryTypeService {
private final RedissonClient redissonClient;
@Override
public String remove(Long id, DictionaryTypeDTO data) {
redissonClient.getMap(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.getValByKey(data.getType())).delete();
return this.removeById(id) ? "成功": "失败";
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!