🎉 修复字典的bug
This commit is contained in:
parent
48fe70644b
commit
18babfda4e
|
|
@ -17,6 +17,7 @@ package org.springblade.system.controller;
|
|||
|
||||
import io.swagger.annotations.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.common.cache.CacheNames;
|
||||
import org.springblade.core.boot.ctrl.BladeController;
|
||||
import org.springblade.core.mp.support.Condition;
|
||||
import org.springblade.core.tool.api.R;
|
||||
|
|
@ -26,6 +27,7 @@ import org.springblade.system.entity.Dict;
|
|||
import org.springblade.system.service.IDictService;
|
||||
import org.springblade.system.vo.DictVO;
|
||||
import org.springblade.system.wrapper.DictWrapper;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
|
|
@ -92,7 +94,7 @@ public class DictController extends BladeController {
|
|||
@PostMapping("/submit")
|
||||
@ApiOperation(value = "新增或修改", notes = "传入dict", position = 6)
|
||||
public R submit(@Valid @RequestBody Dict dict) {
|
||||
return R.status(dictService.saveOrUpdate(dict));
|
||||
return R.status(dictService.submit(dict));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -100,6 +102,7 @@ public class DictController extends BladeController {
|
|||
* 删除
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@CacheEvict(cacheNames = {CacheNames.DICT_LIST, CacheNames.DICT_VALUE})
|
||||
@ApiOperation(value = "物理删除", notes = "传入ids", position = 7)
|
||||
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
||||
return R.status(dictService.removeByIds(Func.toIntList(ids)));
|
||||
|
|
|
|||
|
|
@ -63,4 +63,11 @@ public interface IDictService extends IService<Dict> {
|
|||
*/
|
||||
List<Dict> getList(String code);
|
||||
|
||||
/**
|
||||
* 新增或修改
|
||||
* @param dict
|
||||
* @return
|
||||
*/
|
||||
boolean submit(Dict dict);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,10 @@
|
|||
*/
|
||||
package org.springblade.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.exceptions.ApiException;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springblade.core.tool.node.ForestNodeMerger;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
|
|
@ -24,6 +27,7 @@ import org.springblade.system.entity.Dict;
|
|||
import org.springblade.system.mapper.DictMapper;
|
||||
import org.springblade.system.service.IDictService;
|
||||
import org.springblade.system.vo.DictVO;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -54,8 +58,7 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements ID
|
|||
@Override
|
||||
@Cacheable(cacheNames = DICT_VALUE, key = "#code+'_'+#dictKey")
|
||||
public String getValue(String code, Integer dictKey) {
|
||||
String value = Func.toStr(baseMapper.getValue(code, dictKey), StringPool.EMPTY);
|
||||
return value;
|
||||
return Func.toStr(baseMapper.getValue(code, dictKey), StringPool.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -64,4 +67,15 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements ID
|
|||
return baseMapper.getList(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(cacheNames = {DICT_LIST, DICT_VALUE})
|
||||
public boolean submit(Dict dict) {
|
||||
LambdaQueryWrapper<Dict> lqw = Wrappers.<Dict>query().lambda().eq(Dict::getCode, dict.getCode()).eq(Dict::getDictKey, dict.getDictKey());
|
||||
Integer cnt = baseMapper.selectCount((Func.isEmpty(dict.getId())) ? lqw : lqw.notIn(Dict::getId, dict.getId()));
|
||||
if (cnt > 0) {
|
||||
throw new ApiException("当前字典键值已存在!");
|
||||
}
|
||||
return saveOrUpdate(dict);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user