feat: 数据字典相关接口提交
This commit is contained in:
@ -33,7 +33,12 @@ public class DictionaryController {
|
|||||||
|
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
public ApiResponse<Boolean> delete(@RequestBody DictionaryDTO record) {
|
public ApiResponse<Boolean> delete(@RequestBody DictionaryDTO record) {
|
||||||
return ApiResponse.success(dictionaryService.delete(record));
|
return ApiResponse.success(dictionaryService.delete(record.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/deleteBatch")
|
||||||
|
public ApiResponse<Integer> deleteBatch(@RequestBody DictionaryDTO record) {
|
||||||
|
return ApiResponse.success(dictionaryService.deleteBatch(record.getIds()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/insert")
|
@PostMapping("/insert")
|
||||||
|
|||||||
@ -0,0 +1,43 @@
|
|||||||
|
package day.gitlab.dolphin.module.core.controller;
|
||||||
|
|
||||||
|
import day.gitlab.dolphin.common.web.entity.ApiResponse;
|
||||||
|
import day.gitlab.dolphin.module.core.controller.dto.DictionaryItemDTO;
|
||||||
|
import day.gitlab.dolphin.module.core.controller.vo.DictionaryItemVO;
|
||||||
|
import day.gitlab.dolphin.module.core.service.DictionaryItemService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/dictionaryItem")
|
||||||
|
public class DictionaryItemController {
|
||||||
|
|
||||||
|
private final DictionaryItemService dictionaryItemService;
|
||||||
|
|
||||||
|
@GetMapping("/tree")
|
||||||
|
public ApiResponse<List<DictionaryItemVO>> tree(DictionaryItemDTO record) {
|
||||||
|
return ApiResponse.success(dictionaryItemService.tree(record.getDictionaryId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/update")
|
||||||
|
public ApiResponse<Boolean> update(@RequestBody DictionaryItemDTO record) {
|
||||||
|
return ApiResponse.success(dictionaryItemService.update(record));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public ApiResponse<Boolean> delete(@RequestBody DictionaryItemDTO record) {
|
||||||
|
return ApiResponse.success(dictionaryItemService.delete(record.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/deleteBatch")
|
||||||
|
public ApiResponse<Integer> deleteBatch(@RequestBody DictionaryItemDTO record) {
|
||||||
|
return ApiResponse.success(dictionaryItemService.deleteBatch(record.getIds()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/insert")
|
||||||
|
public ApiResponse<Boolean> insert(@RequestBody DictionaryItemDTO record) {
|
||||||
|
return ApiResponse.success(dictionaryItemService.insert(record));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@ -18,4 +20,6 @@ public class DictionaryDTO {
|
|||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
private List<String> ids;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,29 @@
|
|||||||
|
package day.gitlab.dolphin.module.core.controller.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DictionaryItemDTO {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private String dictionaryId;
|
||||||
|
|
||||||
|
private String parentId;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private List<String> ids;
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
package day.gitlab.dolphin.module.core.controller.vo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DictionaryItemVO {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private String dictionaryId;
|
||||||
|
|
||||||
|
private String parentId;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private Timestamp createTime;
|
||||||
|
|
||||||
|
private Timestamp updateTime;
|
||||||
|
|
||||||
|
private List<DictionaryItemVO> children;
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package day.gitlab.dolphin.module.core.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@TableName("sys_core_dictionary_item")
|
||||||
|
public class DictionaryItem {
|
||||||
|
|
||||||
|
@TableId
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private String dictionaryId;
|
||||||
|
|
||||||
|
private String parentId;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private Timestamp createTime;
|
||||||
|
|
||||||
|
private Timestamp updateTime;
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
package day.gitlab.dolphin.module.core.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import day.gitlab.dolphin.module.core.entity.DictionaryItem;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface DictionaryItemMapper extends BaseMapper<DictionaryItem> {
|
||||||
|
|
||||||
|
default List<DictionaryItem> findAllByDictionaryId(String dictionaryId) {
|
||||||
|
LambdaQueryWrapper<DictionaryItem> wrapper = Wrappers.<DictionaryItem>lambdaQuery()
|
||||||
|
.eq(DictionaryItem::getDictionaryId, dictionaryId);
|
||||||
|
return selectList(wrapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
package day.gitlab.dolphin.module.core.service;
|
||||||
|
|
||||||
|
import day.gitlab.dolphin.module.core.controller.dto.DictionaryItemDTO;
|
||||||
|
import day.gitlab.dolphin.module.core.controller.vo.DictionaryItemVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface DictionaryItemService {
|
||||||
|
|
||||||
|
List<DictionaryItemVO> tree(String dictionaryId);
|
||||||
|
|
||||||
|
Boolean update(DictionaryItemDTO record);
|
||||||
|
|
||||||
|
Boolean delete(String id);
|
||||||
|
|
||||||
|
Integer deleteBatch(List<String> ids);
|
||||||
|
|
||||||
|
Boolean insert(DictionaryItemDTO record);
|
||||||
|
}
|
||||||
@ -13,7 +13,9 @@ public interface DictionaryService {
|
|||||||
|
|
||||||
boolean update(DictionaryDTO record);
|
boolean update(DictionaryDTO record);
|
||||||
|
|
||||||
boolean delete(DictionaryDTO record);
|
boolean delete(String id);
|
||||||
|
|
||||||
|
int deleteBatch(List<String> ids);
|
||||||
|
|
||||||
boolean insert(DictionaryDTO record);
|
boolean insert(DictionaryDTO record);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,109 @@
|
|||||||
|
package day.gitlab.dolphin.module.core.service.impl;
|
||||||
|
|
||||||
|
import day.gitlab.dolphin.common.core.util.Strings;
|
||||||
|
import day.gitlab.dolphin.module.core.controller.dto.DictionaryItemDTO;
|
||||||
|
import day.gitlab.dolphin.module.core.controller.vo.DictionaryItemVO;
|
||||||
|
import day.gitlab.dolphin.module.core.entity.DictionaryItem;
|
||||||
|
import day.gitlab.dolphin.module.core.mapper.DictionaryItemMapper;
|
||||||
|
import day.gitlab.dolphin.module.core.service.DictionaryItemService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DictionaryItemServiceImpl implements DictionaryItemService {
|
||||||
|
|
||||||
|
private final DictionaryItemMapper dictionaryItemMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DictionaryItemVO> tree(String dictionaryId) {
|
||||||
|
List<DictionaryItem> records = dictionaryItemMapper.findAllByDictionaryId(dictionaryId);
|
||||||
|
return list2tree(records);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean update(DictionaryItemDTO record) {
|
||||||
|
DictionaryItem dictionaryItem = dictionaryItemMapper.selectById(record.getId());
|
||||||
|
if (dictionaryItem == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Strings.isNotBlank(record.getDictionaryId())) {
|
||||||
|
dictionaryItem.setDictionaryId(record.getDictionaryId());
|
||||||
|
}
|
||||||
|
if (Strings.isNotBlank(record.getParentId())) {
|
||||||
|
dictionaryItem.setParentId(record.getParentId());
|
||||||
|
}
|
||||||
|
if (Strings.isNotBlank(record.getName())) {
|
||||||
|
dictionaryItem.setName(record.getName());
|
||||||
|
}
|
||||||
|
if (Strings.isNotBlank(record.getCode())) {
|
||||||
|
dictionaryItem.setCode(record.getCode());
|
||||||
|
}
|
||||||
|
if (record.getSort() == null) {
|
||||||
|
dictionaryItem.setSort(0);
|
||||||
|
}
|
||||||
|
if (Strings.isNotBlank(record.getDescription())) {
|
||||||
|
dictionaryItem.setDescription(record.getDescription());
|
||||||
|
}
|
||||||
|
dictionaryItem.setUpdateTime(Timestamp.from(Instant.now()));
|
||||||
|
return dictionaryItemMapper.updateById(dictionaryItem) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean delete(String id) {
|
||||||
|
return dictionaryItemMapper.deleteById(id) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer deleteBatch(List<String> ids) {
|
||||||
|
return dictionaryItemMapper.deleteByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean insert(DictionaryItemDTO record) {
|
||||||
|
DictionaryItem dictionaryItem = new DictionaryItem();
|
||||||
|
BeanUtils.copyProperties(record, dictionaryItem);
|
||||||
|
dictionaryItem.setId(null);
|
||||||
|
dictionaryItem.setCreateTime(Timestamp.from(Instant.now()));
|
||||||
|
dictionaryItem.setUpdateTime(Timestamp.from(Instant.now()));
|
||||||
|
|
||||||
|
return dictionaryItemMapper.insert(dictionaryItem) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DictionaryItemVO> list2tree(List<DictionaryItem> records) {
|
||||||
|
List<DictionaryItemVO> root = records.stream()
|
||||||
|
.filter(rec -> Strings.isBlank(rec.getParentId()))
|
||||||
|
.map(rec -> {
|
||||||
|
DictionaryItemVO vo = new DictionaryItemVO();
|
||||||
|
BeanUtils.copyProperties(rec, vo);
|
||||||
|
return vo;
|
||||||
|
})
|
||||||
|
.toList();
|
||||||
|
for (DictionaryItemVO parent : root) {
|
||||||
|
list2tree(parent, records);
|
||||||
|
}
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void list2tree(DictionaryItemVO parent, List<DictionaryItem> records) {
|
||||||
|
List<DictionaryItemVO> children = records.stream()
|
||||||
|
.filter(rec -> parent.getId().equals(rec.getParentId()))
|
||||||
|
.map(rec -> {
|
||||||
|
DictionaryItemVO vo = new DictionaryItemVO();
|
||||||
|
BeanUtils.copyProperties(rec, vo);
|
||||||
|
return vo;
|
||||||
|
})
|
||||||
|
.toList();
|
||||||
|
parent.setChildren(children);
|
||||||
|
|
||||||
|
for (DictionaryItemVO child : children) {
|
||||||
|
list2tree(child, records);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@ -71,18 +72,24 @@ public class DictionaryServiceImpl implements DictionaryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean delete(DictionaryDTO record) {
|
public boolean delete(String id) {
|
||||||
Dictionary dictionary = dictionaryMapper.selectById(record.getId());
|
Dictionary dictionary = dictionaryMapper.selectById(id);
|
||||||
if (dictionary != null) {
|
if (dictionary != null) {
|
||||||
return dictionaryMapper.deleteById(dictionary.getId()) == 1;
|
return dictionaryMapper.deleteById(dictionary.getId()) == 1;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deleteBatch(List<String> ids) {
|
||||||
|
return dictionaryMapper.deleteByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean insert(DictionaryDTO record) {
|
public boolean insert(DictionaryDTO record) {
|
||||||
Dictionary dictionary = new Dictionary();
|
Dictionary dictionary = new Dictionary();
|
||||||
BeanUtils.copyProperties(record, dictionary);
|
BeanUtils.copyProperties(record, dictionary);
|
||||||
|
dictionary.setId(null);
|
||||||
dictionary.setCreateTime(Timestamp.from(Instant.now()));
|
dictionary.setCreateTime(Timestamp.from(Instant.now()));
|
||||||
dictionary.setUpdateTime(Timestamp.from(Instant.now()));
|
dictionary.setUpdateTime(Timestamp.from(Instant.now()));
|
||||||
return dictionaryMapper.insert(dictionary) == 1;
|
return dictionaryMapper.insert(dictionary) == 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user