编写了数据字典的增删改查

master
冷调 2024-08-22 18:32:06 +08:00
parent d771ab6505
commit d5c5d390ed
21 changed files with 384 additions and 53 deletions

View File

@ -5,12 +5,15 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.source.domain.resp.DictDataResp;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.List;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
@ -47,4 +50,14 @@ public class DictType extends BaseEntity {
*/
@Excel(name = "数据源ID")
private Integer assetId;
public DictDataResp toDataDictResp(List<DictData> list) {
return DictDataResp.builder()
.id(this.getId())
.dictName(this.getDictName())
.dictType(this.getDictType())
.assetId(this.getAssetId())
.dictData(list)
.build();
}
}

View File

@ -0,0 +1,30 @@
package com.muyu.source.domain.req;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-22-17:28
* @ Version1.0
* @ Description
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DictTypeReq {
/**
* id
*/
@Schema(type = "Integer",defaultValue = "1",description = "数据源id")
private Integer assetId;
/**
*
*/
@Schema(type = "String",defaultValue = "字典类型",description = "字典类型")
private String dictType;
}

View File

@ -0,0 +1,54 @@
package com.muyu.source.domain.resp;
import com.muyu.source.domain.DictData;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-22-17:28
* @ Version1.0
* @ Description
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class DictDataResp {
/**
*
*/
@Schema(type = "Long",defaultValue = "主键",description = "主键")
private Long id;
/**
*
*/
@Schema(type = "String",defaultValue = "字典名称",description = "字典名称")
private String dictName;
/**
*
*/
@Schema(type = "String",defaultValue = "字典类型",description = "字典类型")
private String dictType;
/**
*
*/
@Schema(type = "String",defaultValue = "数据源编号",description = "数据源编号")
private Integer assetId;
/**
*
*/
@Schema(type = "List",defaultValue = "字典数据集合",description = "字典数据集合")
private List<DictData> dictData;
}

View File

@ -14,12 +14,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-21-19:05
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Log4j2
@RestController
@ -32,8 +32,10 @@ public class ChildrenController {
@Autowired
private ChildrenService childrenService;
/**
*
*
* @param id id
* @return
*/
@ -46,6 +48,7 @@ public class ChildrenController {
/**
*
*
* @param id ID
* @return
*/

View File

@ -18,12 +18,12 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-20-18:34
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Log4j2
@RestController
@ -43,6 +43,7 @@ public class DataSourceController extends BaseController {
/**
* ID
*
* @param id ID
* @return
*/
@ -55,6 +56,7 @@ public class DataSourceController extends BaseController {
/**
*
*
* @param dataSourceQueryReq
* @return
*/
@ -67,6 +69,7 @@ public class DataSourceController extends BaseController {
/**
*
*
* @param dataSource
* @param response response
*/
@ -80,6 +83,7 @@ public class DataSourceController extends BaseController {
/**
*
*
* @param id ID
* @return
*/
@ -88,6 +92,7 @@ public class DataSourceController extends BaseController {
public Result<DataSource> getById(@PathVariable("id") Long id) {
return Result.success(dataSourceService.getById(id));
}
/**
*
*
@ -103,6 +108,7 @@ public class DataSourceController extends BaseController {
/**
*
*
* @param dataSource
* @return
*/
@ -115,6 +121,7 @@ public class DataSourceController extends BaseController {
/**
*
*
* @param dataSource
* @return
*/
@ -127,6 +134,7 @@ public class DataSourceController extends BaseController {
/**
*
*
* @param id
* @return
*/
@ -138,6 +146,4 @@ public class DataSourceController extends BaseController {
}
}

View File

@ -26,11 +26,13 @@ public class DictDataController {
public DictDataController() {
log.info("forest扫描路径:{}", ForestScannerRegister.getBasePackages());
}
@Autowired
private DictDataService dictDataService;
/**
*
*
* @param dictData
* @return
*/
@ -43,6 +45,7 @@ public class DictDataController {
/**
*
*
* @param dictData
* @return
*/
@ -55,6 +58,7 @@ public class DictDataController {
/**
*
*
* @param id ID
* @return
*/

View File

@ -0,0 +1,99 @@
package com.muyu.source.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dtflys.forest.springboot.annotation.ForestScannerRegister;
import com.muyu.common.core.domain.Result;
import com.muyu.source.domain.DictData;
import com.muyu.source.domain.DictType;
import com.muyu.source.domain.req.DictTypeReq;
import com.muyu.source.domain.resp.DictDataResp;
import com.muyu.source.service.DictDataService;
import com.muyu.source.service.DictTypeService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-22-17:21
* @ Version1.0
* @ Description
*/
@Log4j2
@RestController
@RequestMapping("/dict_type")
public class DictTypeController {
public DictTypeController() {
log.info("forest扫描路径:{}", ForestScannerRegister.getBasePackages());
}
@Autowired
private DictDataService dictDataService;
@Autowired
private DictTypeService dictTypeService;
/**
* id
*
* @param id id
* @return
*/
@GetMapping("/getDictDataList/{id}")
@Operation(summary = "查询字典数据", description = "根据字典类型id查询字典数据")
public Result<List<DictDataResp>> getDictDataList(@PathVariable("id") Integer id) {
List<DictDataResp> dictDataRespList = dictTypeService.getDictDataList(id);
return Result.success(dictDataRespList);
}
/**
*
*
* @param dictTypeReq
* @return
*/
@PostMapping("/getDictData")
@Operation(summary = "查询字典数据列表", description = "根据对象查询字典数据列表")
public Result getDictData(@RequestBody DictTypeReq dictTypeReq) {
List<DictData> dictData = dictTypeService.getDictData(dictTypeReq);
return Result.success(dictData);
}
/**
*
*
* @param dictType
* @return
*/
@PostMapping("/addDictType")
@Operation(summary = "添加字典类型", description = "添加字典类型")
public Result addDictType(@RequestBody DictType dictType) {
dictTypeService.save(dictType);
return Result.success();
}
/**
*
*
* @param id id
* @return
*/
@GetMapping("/delDictType/{id}")
@Operation(summary = "删除字典类型", description = "根据ID删除字典类型")
public Result delDictType(@PathVariable("id") Long id) {
// 删除字典类型
dictTypeService.removeById(id);
// 删除相对应的字典数据
dictDataService.remove(new LambdaQueryWrapper<>() {{
eq(DictData::getDictTypeId, id);
}});
return Result.success();
}
}

View File

@ -14,12 +14,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-21-19:51
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Log4j2
@RestController
@ -35,6 +35,7 @@ public class TableDataController {
/**
* id
*
* @param id id
* @return
*/
@ -46,6 +47,7 @@ public class TableDataController {
/**
*
*
* @param id ID
* @return
*/
@ -57,5 +59,4 @@ public class TableDataController {
}
}

View File

@ -5,12 +5,12 @@ import com.muyu.source.domain.Children;
import org.apache.ibatis.annotations.Mapper;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-21-19:06
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Mapper
public interface ChildrenMapper extends BaseMapper<Children> {

View File

@ -5,12 +5,12 @@ import com.muyu.source.domain.DataSource;
import org.apache.ibatis.annotations.Mapper;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-20-20:03
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Mapper
public interface DataSourceMapper extends BaseMapper<DataSource> {

View File

@ -0,0 +1,17 @@
package com.muyu.source.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.source.domain.DictType;
import org.apache.ibatis.annotations.Mapper;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-22-17:23
* @ Version1.0
* @ Description
*/
@Mapper
public interface DictTypeMapper extends BaseMapper<DictType> {
}

View File

@ -5,12 +5,12 @@ import com.muyu.source.domain.TableData;
import org.apache.ibatis.annotations.Mapper;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-21-19:52
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Mapper
public interface TableDataMapper extends BaseMapper<TableData> {

View File

@ -6,12 +6,12 @@ import com.muyu.source.domain.Children;
import java.util.List;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-21-19:07
* @ Version1.0
* @ Description
* @author Lenovo
*/
public interface ChildrenService extends IService<Children> {

View File

@ -6,17 +6,18 @@ import com.muyu.source.domain.DataSource;
import java.util.List;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-20-20:06
* @ Version1.0
* @ Description
* @author Lenovo
*/
public interface DataSourceService extends IService<DataSource> {
/**
*
*
* @param dataSource
* @return
*/

View File

@ -4,12 +4,12 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.source.domain.DictData;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-22-17:14
* @ Version1.0
* @ Description
* @author Lenovo
*/
public interface DictDataService extends IService<DictData> {
}

View File

@ -0,0 +1,35 @@
package com.muyu.source.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.source.domain.DictData;
import com.muyu.source.domain.DictType;
import com.muyu.source.domain.req.DictTypeReq;
import com.muyu.source.domain.resp.DictDataResp;
import java.util.List;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-22-17:24
* @ Version1.0
* @ Description
*/
public interface DictTypeService extends IService<DictType> {
/**
* id
*
* @param id id
* @return
*/
List<DictDataResp> getDictDataList(Integer id);
/**
*
*
* @param dictTypeReq
* @return
*/
List<DictData> getDictData(DictTypeReq dictTypeReq);
}

View File

@ -12,12 +12,12 @@ import java.util.stream.IntStream;
import java.util.stream.LongStream;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-21-19:08
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Service
public class ChildrenServiceImpl extends ServiceImpl<ChildrenMapper, Children> implements ChildrenService {

View File

@ -12,12 +12,12 @@ import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-20-20:06
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Service
public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSource> implements DataSourceService {
@ -25,6 +25,7 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
/**
*
*
* @param dataSource
* @return
*/

View File

@ -0,0 +1,67 @@
package com.muyu.source.service.Impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.source.domain.DictData;
import com.muyu.source.domain.DictType;
import com.muyu.source.domain.req.DictTypeReq;
import com.muyu.source.domain.resp.DictDataResp;
import com.muyu.source.mapper.DictTypeMapper;
import com.muyu.source.service.DictDataService;
import com.muyu.source.service.DictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-22-17:24
* @ Version1.0
* @ Description
*/
@Service
public class DictTypeServiceImpl extends ServiceImpl<DictTypeMapper, DictType> implements DictTypeService {
@Autowired
private DictDataService dictDataService;
/**
* id
*
* @param id id
* @return
*/
@Override
public List<DictDataResp> getDictDataList(Integer id) {
List<DictType> dictTypeList = list(new LambdaQueryWrapper<>() {{
eq(DictType::getAssetId, id);
}});
List<DictDataResp> dictDataRespList = dictTypeList.stream().map(dictType -> {
List<DictData> dictDataList = dictDataService.list(new LambdaQueryWrapper<>() {{
eq(DictData::getDictTypeId, dictType.getId());
}});
return dictType.toDataDictResp(dictDataList);
}).toList();
return dictDataRespList;
}
/**
*
*
* @param dictTypeReq
* @return
*/
@Override
public List<DictData> getDictData(DictTypeReq dictTypeReq) {
DictType dictType = this.getOne(new LambdaQueryWrapper<>() {{
eq(DictType::getAssetId, dictTypeReq.getAssetId());
eq(DictType::getDictType, dictTypeReq.getDictType());
}});
List<DictData> dictData = dictDataService.list(new LambdaQueryWrapper<>() {{
eq(DictData::getDictTypeId, dictType.getId());
}});
return dictData;
}
}

View File

@ -7,12 +7,12 @@ import com.muyu.source.service.TableDataService;
import org.springframework.stereotype.Service;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-21-19:53
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Service
public class TableDataServiceImpl extends ServiceImpl<TableDataMapper, TableData> implements TableDataService {

View File

@ -4,12 +4,12 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.source.domain.TableData;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-08-21-19:53
* @ Version1.0
* @ Description
* @author Lenovo
*/
public interface TableDataService extends IService<TableData> {
}