Commit 16c47491 by HlQ

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

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