字典
This commit is contained in:
@@ -40,7 +40,7 @@ import java.util.Map;
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "系统:字典详情管理")
|
||||
@RequestMapping("/api/dictDetail")
|
||||
@RequestMapping("/api/dictDetail2")
|
||||
public class DictDetailController {
|
||||
private final DictDetailService dictDetailService;
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.nl.system.controller.dict;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.system.service.dict.ISysDictService;
|
||||
@@ -29,18 +31,18 @@ import java.util.Set;
|
||||
* @since 2022-12-14
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/dict")
|
||||
public class SysDictController {
|
||||
|
||||
@Autowired
|
||||
private ISysDictService dictService;
|
||||
private final ISysDictService dictService;
|
||||
|
||||
@Log("查询字典")
|
||||
@GetMapping
|
||||
@ApiOperation("查询字典")
|
||||
// @SaCheckPermission("dict:list")
|
||||
public ResponseEntity<Object> query(@RequestParam Map whereJson, PageQuery pageable){
|
||||
return new ResponseEntity<>(dictService.queryAll(whereJson,pageable), HttpStatus.OK);
|
||||
return new ResponseEntity<>(TableDataInfo.build(dictService.queryAll(whereJson,pageable)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增字典")
|
||||
@@ -65,16 +67,16 @@ public class SysDictController {
|
||||
@ApiOperation("删除字典")
|
||||
@DeleteMapping
|
||||
// @SaCheckPermission("dict:del")
|
||||
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
|
||||
public ResponseEntity<Object> delete(@RequestBody Set<String> ids){
|
||||
dictService.deleteBatchByIds(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/dictDetail")
|
||||
@ApiOperation("查询字典详情")
|
||||
public ResponseEntity<Object> queryDetails(Map criteria, PageQuery pageable){
|
||||
public ResponseEntity<Object> queryDetails(@RequestParam Map criteria, PageQuery pageable){
|
||||
DictQuery dictQuery = JSONObject.parseObject(JSONObject.toJSONString(criteria), DictQuery.class);
|
||||
return new ResponseEntity<>(dictService.queryAllDetail(dictQuery,pageable),HttpStatus.OK);
|
||||
return new ResponseEntity<>(TableDataInfo.build(dictService.queryAllDetail(dictQuery,pageable)),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("查询多个字典详情")
|
||||
|
||||
@@ -45,7 +45,7 @@ public interface ISysDictService extends IService<Dict> {
|
||||
* 通过id批量删除字典
|
||||
* @param ids
|
||||
*/
|
||||
void deleteBatchByIds(Set<Long> ids);
|
||||
void deleteBatchByIds(Set<String> ids);
|
||||
|
||||
/**
|
||||
* 分页查询获取字典明细
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.nl.system.service.dict.dao;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
@@ -26,8 +27,8 @@ public class Dict implements Serializable {
|
||||
/**
|
||||
* 字典标识
|
||||
*/
|
||||
@TableId
|
||||
private Long dictId;
|
||||
@TableId(value = "dict_id")
|
||||
private String dictId;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
@@ -104,5 +105,4 @@ public class Dict implements Serializable {
|
||||
*/
|
||||
private String updateTime;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.system.service.dict.dao.mapper.SysDictMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -11,5 +11,8 @@ import org.nl.system.service.dict.dao.Dict;
|
||||
*/
|
||||
@Data
|
||||
public class DictQuery extends BaseQuery<Dict> {
|
||||
private String code;
|
||||
|
||||
private String dictName;
|
||||
private String dictId;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.utils.SecurityUtils;
|
||||
@@ -23,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -33,21 +35,22 @@ import java.util.Set;
|
||||
* @since 2022-12-14
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, Dict> implements ISysDictService {
|
||||
|
||||
@Autowired
|
||||
private SysDictMapper sysDictMapper;
|
||||
private final SysDictMapper sysDictMapper;
|
||||
|
||||
@Override
|
||||
public IPage<Dict> queryAll(Map whereJson, PageQuery page) {
|
||||
String blurry = null;
|
||||
if (ObjectUtil.isNotEmpty(whereJson.get("blurry"))) blurry = whereJson.get("blurry").toString();
|
||||
LambdaQueryWrapper<Dict> lam = new LambdaQueryWrapper<>();
|
||||
lam.like(ObjectUtil.isNotEmpty(blurry), Dict::getCode, blurry)
|
||||
IPage<Dict> pages = this.page(new Page<>(page.getPage(), page.getSize()), new QueryWrapper<Dict>()
|
||||
.select("MAX(dict_id) AS dictId, code, name")
|
||||
.lambda()
|
||||
.like(ObjectUtil.isNotEmpty(blurry), Dict::getCode, blurry)
|
||||
.or(ObjectUtil.isNotEmpty(blurry))
|
||||
.like(ObjectUtil.isNotEmpty(blurry), Dict::getName, blurry);
|
||||
IPage<Dict> pages = new Page<>(page.getPage(), page.getSize());
|
||||
sysDictMapper.selectPage(pages, lam);
|
||||
.like(ObjectUtil.isNotEmpty(blurry), Dict::getName, blurry)
|
||||
.groupBy(Dict::getCode, Dict::getName));
|
||||
return pages;
|
||||
}
|
||||
|
||||
@@ -57,10 +60,10 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, Dict> impleme
|
||||
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||
String nickName = SecurityUtils.getCurrentNickName();
|
||||
String date = DateUtil.now();
|
||||
Dict oldDict = sysDictMapper.selectOne(new LambdaQueryWrapper<Dict>()
|
||||
List<Dict> oldDict = sysDictMapper.selectList(new LambdaQueryWrapper<Dict>()
|
||||
.eq(ObjectUtil.isNotEmpty(dict.getCode()), Dict::getCode, dict.getCode()));
|
||||
if (ObjectUtil.isNotEmpty(oldDict)) throw new BadRequestException("字典[" + dict.getCode() + "]已存在");
|
||||
dict.setDictId(IdUtil.getSnowflake(1, 1).nextId());
|
||||
dict.setDictId(IdUtil.getSnowflake(1, 1).nextIdStr());
|
||||
dict.setCreateId(currentUserId);
|
||||
dict.setCreateName(nickName);
|
||||
dict.setCreateTime(date);
|
||||
@@ -73,9 +76,10 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, Dict> impleme
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateDict(Dict dto) {
|
||||
Dict dict1 = sysDictMapper.selectOne(new LambdaQueryWrapper<Dict>().eq(Dict::getCode, dto.getCode()));
|
||||
if (ObjectUtil.isNotEmpty(dict1)) throw new BadRequestException("字典[" + dict1.getCode() + "]已存在");
|
||||
Dict dict = sysDictMapper.selectById(dto.getDictId());
|
||||
List<Dict> dictList = sysDictMapper.selectList(new LambdaQueryWrapper<Dict>().eq(Dict::getCode, dto.getCode()));
|
||||
if (ObjectUtil.isNotEmpty(dictList) && !dto.getCode().equals(dict.getCode()))
|
||||
throw new BadRequestException("字典[" + dto.getCode() + "]已存在");
|
||||
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||
String currentNickName = SecurityUtils.getCurrentNickName();
|
||||
// 根据code获取所有字典
|
||||
@@ -92,15 +96,21 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, Dict> impleme
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteBatchByIds(Set<Long> ids) {
|
||||
sysDictMapper.deleteBatchIds(ids);
|
||||
public void deleteBatchByIds(Set<String> ids) {
|
||||
// 查找code删除
|
||||
ids.forEach(id -> {
|
||||
String code = sysDictMapper.selectById(id).getCode();
|
||||
sysDictMapper.delete(new LambdaQueryWrapper<Dict>().eq(Dict::getCode, code));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<Dict> queryAllDetail(DictQuery criteria, PageQuery pageable) {
|
||||
QueryWrapper<Dict> queryWrapper = criteria.build();
|
||||
Page<Dict> page = this.page(pageable.build(), queryWrapper);
|
||||
return page;
|
||||
public IPage<Dict> queryAllDetail(DictQuery criteria, PageQuery page) {
|
||||
LambdaQueryWrapper<Dict> lam = new LambdaQueryWrapper<>();
|
||||
lam.eq(Dict::getCode, criteria.getCode()).isNotNull(Dict::getLabel).ne(Dict::getLabel, "");
|
||||
IPage<Dict> pages = new Page<>(page.getPage(), page.getSize());
|
||||
sysDictMapper.selectPage(pages, lam);
|
||||
return pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -122,6 +132,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, Dict> impleme
|
||||
Dict selectOne = sysDictMapper.selectOne(new LambdaQueryWrapper<Dict>().eq(Dict::getCode, dict.getCode()));
|
||||
if (ObjectUtil.isEmpty(selectOne.getLabel())) {
|
||||
// 空就赋值
|
||||
selectOne.setCode(dict.getCode());
|
||||
selectOne.setLabel(dict.getLabel());
|
||||
selectOne.setValue(dict.getValue());
|
||||
selectOne.setDictSort(dict.getDictSort());
|
||||
@@ -133,7 +144,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, Dict> impleme
|
||||
return;
|
||||
}
|
||||
// 插入新的数据
|
||||
dict.setDictId(IdUtil.getSnowflake(1, 1).nextId());
|
||||
dict.setDictId(IdUtil.getSnowflake(1, 1).nextIdStr());
|
||||
dict.setCode(selectOne.getCode());
|
||||
dict.setName(selectOne.getName());
|
||||
dict.setCreateId(SecurityUtils.getCurrentUserId());
|
||||
@@ -151,9 +162,9 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, Dict> impleme
|
||||
Dict dict = sysDictMapper.selectById(resources.getDictId());
|
||||
if (ObjectUtil.isEmpty(dict)) throw new BadRequestException("被删除或无权限,操作失败!");
|
||||
// 校验是否已经有标签
|
||||
Dict one = sysDictMapper.selectOne(new LambdaQueryWrapper<Dict>().eq(Dict::getLabel, dict.getLabel())
|
||||
.eq(Dict::getCode, dict.getCode()));
|
||||
if (ObjectUtil.isNotEmpty(one)) throw new BadRequestException("标签[" + dict.getLabel() + "]已存在");
|
||||
List<Dict> dictList = sysDictMapper.selectList(new LambdaQueryWrapper<Dict>().eq(Dict::getLabel, resources.getLabel())
|
||||
.eq(Dict::getCode, resources.getCode()));
|
||||
if (ObjectUtil.isNotEmpty(dictList) && !resources.getLabel().equals(dict.getLabel())) throw new BadRequestException("标签[" + dict.getLabel() + "]已存在");
|
||||
resources.setUpdateId(SecurityUtils.getCurrentUserId());
|
||||
resources.setUpdateName(SecurityUtils.getCurrentNickName());
|
||||
resources.setUpdateTime(DateUtil.now());
|
||||
|
||||
@@ -7,7 +7,7 @@ export function get(dictName) {
|
||||
size: 9999
|
||||
}
|
||||
return request({
|
||||
url: 'api/dictDetail',
|
||||
url: 'api/dict/dictDetail',
|
||||
method: 'get',
|
||||
params
|
||||
})
|
||||
@@ -20,7 +20,7 @@ export function getDictMap(dictName) {
|
||||
size: 9999
|
||||
}
|
||||
return request({
|
||||
url: 'api/dictDetail/map',
|
||||
url: 'api/dict/dictDetail/map',
|
||||
method: 'get',
|
||||
params
|
||||
})
|
||||
@@ -28,7 +28,7 @@ export function getDictMap(dictName) {
|
||||
|
||||
export function add(data) {
|
||||
return request({
|
||||
url: 'api/dictDetail',
|
||||
url: 'api/dict/dictDetail',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
@@ -36,14 +36,14 @@ export function add(data) {
|
||||
|
||||
export function del(id) {
|
||||
return request({
|
||||
url: 'api/dictDetail/' + id,
|
||||
url: 'api/dict/dictDetail/' + id,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
export function edit(data) {
|
||||
return request({
|
||||
url: 'api/dictDetail',
|
||||
url: 'api/dict/dictDetail',
|
||||
method: 'put',
|
||||
data
|
||||
})
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
</el-form-item>
|
||||
<el-form-item label="排序" prop="dict_sort">
|
||||
<el-input-number
|
||||
v-model.number="form.dict_sort"
|
||||
v-model.number="form.dictSort"
|
||||
:min="0"
|
||||
:max="999"
|
||||
controls-position="right"
|
||||
@@ -74,7 +74,7 @@
|
||||
</el-table-column>
|
||||
<el-table-column prop="label" label="字典标签" align="center" width="120" show-overflow-tooltip />
|
||||
<el-table-column prop="value" label="字典值" align="center" width="60" />
|
||||
<el-table-column prop="dict_sort" label="排序" align="center" width="65" />
|
||||
<el-table-column prop="dictSort" label="排序" align="center" width="65" />
|
||||
<el-table-column prop="para1" label="参数1" align="center" width="65" />
|
||||
<el-table-column prop="para2" label="参数2" align="center" width="65" />
|
||||
<el-table-column prop="para3" label="参数3" align="center" width="65" />
|
||||
@@ -106,7 +106,7 @@ import pagination from '@crud/Pagination'
|
||||
import rrOperation from '@crud/RR.operation'
|
||||
import udOperation from '@crud/UD.operation'
|
||||
|
||||
const defaultForm = { dict_id: null, code: null, name: null, label: null, value: null, dict_sort: null, dict_type: null, para1: null, para2: null, para3: null, create_id: null, create_name: null, create_time: null, update_optid: null, update_optname: null, update_time: null }
|
||||
const defaultForm = { dictId: null, name: null, label: null, value: null, dictSort: null, dictType: null, para1: null, para2: null, para3: null, createId: null, createName: null, createTime: null, updateId: null, updateName: null, updateTime: null }
|
||||
|
||||
export default {
|
||||
components: { pagination, rrOperation, udOperation },
|
||||
@@ -114,10 +114,10 @@ export default {
|
||||
return [
|
||||
CRUD({
|
||||
title: '字典详情',
|
||||
url: 'api/dictDetail',
|
||||
url: 'api/dict/dictDetail',
|
||||
query: { code: '' },
|
||||
idField: 'dict_id',
|
||||
sort: ['dict_sort,asc', 'dict_id,desc'],
|
||||
idField: 'dictId',
|
||||
sort: ['dictSort,asc', 'dictId,desc'],
|
||||
crudMethod: { ...crudDictDetail },
|
||||
optShow: {
|
||||
add: true,
|
||||
@@ -133,11 +133,11 @@ export default {
|
||||
presenter(),
|
||||
header(),
|
||||
form(function() {
|
||||
return Object.assign({ dict: { dict_id: this.dict_id }}, defaultForm)
|
||||
return Object.assign({ dict: { dictId: this.dictId }}, defaultForm)
|
||||
})],
|
||||
data() {
|
||||
return {
|
||||
dict_id: null,
|
||||
dictId: null,
|
||||
rules: {
|
||||
label: [
|
||||
{ required: true, message: '请输入字典标签', trigger: 'blur' }
|
||||
@@ -145,7 +145,7 @@ export default {
|
||||
value: [
|
||||
{ required: true, message: '请输入字典值', trigger: 'blur' }
|
||||
],
|
||||
dict_sort: [
|
||||
dictSort: [
|
||||
{ required: true, message: '请输入序号', trigger: 'blur', type: 'number' }
|
||||
]
|
||||
},
|
||||
|
||||
@@ -86,14 +86,14 @@ import pagination from '@crud/Pagination'
|
||||
import rrOperation from '@crud/RR.operation'
|
||||
import udOperation from '@crud/UD.operation'
|
||||
|
||||
const defaultForm = { dict_id: null, code: null, name: null, label: null, value: null, dict_sort: null, dict_type: null, para1: null, para2: null, para3: null, create_id: null, create_name: null, create_time: null, update_optid: null, update_optname: null, update_time: null }
|
||||
const defaultForm = { dictId: null, code: null, name: null, label: null, value: null, dictSort: null, dictType: null, para1: null, para2: null, para3: null, createId: null, createName: null, createTime: null, updateId: null, updateName: null, updateTime: null }
|
||||
|
||||
export default {
|
||||
name: 'Dict',
|
||||
components: { crudOperation, pagination, rrOperation, udOperation, dictDetail },
|
||||
cruds() {
|
||||
return [
|
||||
CRUD({ title: '字典', url: 'api/dict', idField: 'dict_id', crudMethod: { ...crudDict }})
|
||||
CRUD({ title: '字典', url: 'api/dict', idField: 'dictId', crudMethod: { ...crudDict }})
|
||||
]
|
||||
},
|
||||
mixins: [presenter(), header(), form(defaultForm)],
|
||||
@@ -128,7 +128,7 @@ export default {
|
||||
handleCurrentChange(val) {
|
||||
if (val) {
|
||||
this.$refs.dictDetail.query.code = val.code
|
||||
this.$refs.dictDetail.form.dictCode = val.code
|
||||
this.$refs.dictDetail.form.code = val.code
|
||||
this.$refs.dictDetail.crud.toQuery()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user