字典
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());
|
||||
|
||||
Reference in New Issue
Block a user