feat: 项目结构重构
This commit is contained in:
@ -1,6 +0,0 @@
|
||||
package day.gitlab.dolphin.core.constants;
|
||||
|
||||
public class Exceptions {
|
||||
|
||||
public static final String FIELD_REQUIRED = "00020101";
|
||||
}
|
||||
@ -1,65 +0,0 @@
|
||||
package day.gitlab.dolphin.core.controller;
|
||||
|
||||
import day.gitlab.dolphin.common.core.entity.PageResponse;
|
||||
import day.gitlab.dolphin.common.core.entity.QueryPageRequest;
|
||||
import day.gitlab.dolphin.common.core.entity.Result;
|
||||
import day.gitlab.dolphin.common.security.annotation.AuthorityCheck;
|
||||
import day.gitlab.dolphin.common.security.annotation.AuthorityType;
|
||||
import day.gitlab.dolphin.core.entity.dto.DictionaryDTO;
|
||||
import day.gitlab.dolphin.core.entity.vo.DictionaryVO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import day.gitlab.dolphin.core.service.DictionaryService;
|
||||
|
||||
/**
|
||||
* 字典 控制层。
|
||||
*
|
||||
* @author jiangyc
|
||||
* @since 2025-11-28
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/dictionary")
|
||||
public class DictionaryController {
|
||||
|
||||
@Resource
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
/**
|
||||
* 分页查询字典。
|
||||
*
|
||||
* @param pageRequest 分页请求参数
|
||||
* @return 分页对象
|
||||
*/
|
||||
@PostMapping("page")
|
||||
public Result<PageResponse<DictionaryVO>> page(@RequestBody QueryPageRequest<DictionaryDTO> pageRequest) {
|
||||
return Result.success(dictionaryService.page(pageRequest));
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@AuthorityCheck(type = AuthorityType.OR, value = {"ROLE00001"})
|
||||
public Result<Void> add(@RequestBody DictionaryDTO dictionaryDTO) {
|
||||
dictionaryService.add(dictionaryDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("edit")
|
||||
@AuthorityCheck(type = AuthorityType.OR, value = {"ROLE00001"})
|
||||
public Result<Void> edit(@RequestBody DictionaryDTO dictionaryDTO) {
|
||||
dictionaryService.edit(dictionaryDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("delete")
|
||||
@AuthorityCheck(type = AuthorityType.OR, value = {"ROLE00001"})
|
||||
public Result<Void> delete(@RequestBody DictionaryDTO dictionaryDTO) {
|
||||
dictionaryService.delete(dictionaryDTO.getId());
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("deleteBatch")
|
||||
@AuthorityCheck(type = AuthorityType.OR, value = {"ROLE00001"})
|
||||
public Result<Void> deleteBatch(@RequestBody DictionaryDTO dictionaryDTO) {
|
||||
dictionaryService.deleteBatch(dictionaryDTO.getIds());
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
package day.gitlab.dolphin.core.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 字典项 控制层。
|
||||
*
|
||||
* @author jiangyc
|
||||
* @since 2025-11-28
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/dictionaryItem")
|
||||
public class DictionaryItemController {
|
||||
}
|
||||
@ -1,68 +0,0 @@
|
||||
package day.gitlab.dolphin.core.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 字典 实体类。
|
||||
*
|
||||
* @author jiangyc
|
||||
* @since 2025-11-28
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("sys_core_dictionary")
|
||||
public class Dictionary implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 字典代码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 字典类型: enum-枚举、tree-树型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 字典描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Timestamp createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Timestamp updateTime;
|
||||
|
||||
}
|
||||
@ -1,77 +0,0 @@
|
||||
package day.gitlab.dolphin.core.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 字典项 实体类。
|
||||
*
|
||||
* @author jiangyc
|
||||
* @since 2025-11-28
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("sys_core_dictionary_item")
|
||||
public class DictionaryItem implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 字典ID
|
||||
*/
|
||||
private String dictionaryId;
|
||||
|
||||
/**
|
||||
* 父级ID,如果为空则为根节点
|
||||
*/
|
||||
private String parentId;
|
||||
|
||||
/**
|
||||
* 字典项名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 字典项代码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 字典项排序,升序排列
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 字典项描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Timestamp createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Timestamp updateTime;
|
||||
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package day.gitlab.dolphin.core.entity.dto;
|
||||
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DictionarySearchParamsDTO {
|
||||
|
||||
@Min(1)
|
||||
@NotNull
|
||||
private Long current;
|
||||
|
||||
@Min(1)
|
||||
@NotNull
|
||||
private Long size;
|
||||
|
||||
private String name;
|
||||
|
||||
private String code;
|
||||
|
||||
private String type;
|
||||
}
|
||||
@ -1,92 +0,0 @@
|
||||
package day.gitlab.dolphin.core.entity.table;
|
||||
|
||||
import com.mybatisflex.core.query.QueryColumn;
|
||||
import com.mybatisflex.core.table.TableDef;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 字典项 表定义层。
|
||||
*
|
||||
* @author jiangyc
|
||||
* @since 2025-11-28
|
||||
*/
|
||||
public class DictionaryItemTableDef extends TableDef {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 字典项
|
||||
*/
|
||||
public static final DictionaryItemTableDef DICTIONARY_ITEM = new DictionaryItemTableDef();
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
public final QueryColumn ID = new QueryColumn(this, "id");
|
||||
|
||||
/**
|
||||
* 字典项代码
|
||||
*/
|
||||
public final QueryColumn CODE = new QueryColumn(this, "code");
|
||||
|
||||
/**
|
||||
* 字典项名称
|
||||
*/
|
||||
public final QueryColumn NAME = new QueryColumn(this, "name");
|
||||
|
||||
/**
|
||||
* 字典项排序,升序排列
|
||||
*/
|
||||
public final QueryColumn SORT = new QueryColumn(this, "sort");
|
||||
|
||||
/**
|
||||
* 父级ID,如果为空则为根节点
|
||||
*/
|
||||
public final QueryColumn PARENT_ID = new QueryColumn(this, "parent_id");
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
public final QueryColumn CREATE_TIME = new QueryColumn(this, "create_time");
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
public final QueryColumn UPDATE_TIME = new QueryColumn(this, "update_time");
|
||||
|
||||
/**
|
||||
* 字典项描述
|
||||
*/
|
||||
public final QueryColumn DESCRIPTION = new QueryColumn(this, "description");
|
||||
|
||||
/**
|
||||
* 字典ID
|
||||
*/
|
||||
public final QueryColumn DICTIONARY_ID = new QueryColumn(this, "dictionary_id");
|
||||
|
||||
/**
|
||||
* 所有字段。
|
||||
*/
|
||||
public final QueryColumn ALL_COLUMNS = new QueryColumn(this, "*");
|
||||
|
||||
/**
|
||||
* 默认字段,不包含逻辑删除或者 large 等字段。
|
||||
*/
|
||||
public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{ID, DICTIONARY_ID, PARENT_ID, NAME, CODE, SORT, DESCRIPTION, CREATE_TIME, UPDATE_TIME};
|
||||
|
||||
public DictionaryItemTableDef() {
|
||||
super("", "sys_core_dictionary_item");
|
||||
}
|
||||
|
||||
private DictionaryItemTableDef(String schema, String name, String alisa) {
|
||||
super(schema, name, alisa);
|
||||
}
|
||||
|
||||
public DictionaryItemTableDef as(String alias) {
|
||||
String key = getNameWithSchema() + "." + alias;
|
||||
return getCache(key, k -> new DictionaryItemTableDef("", "sys_core_dictionary_item", alias));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,82 +0,0 @@
|
||||
package day.gitlab.dolphin.core.entity.table;
|
||||
|
||||
import com.mybatisflex.core.query.QueryColumn;
|
||||
import com.mybatisflex.core.table.TableDef;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 字典 表定义层。
|
||||
*
|
||||
* @author jiangyc
|
||||
* @since 2025-11-28
|
||||
*/
|
||||
public class DictionaryTableDef extends TableDef {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 字典
|
||||
*/
|
||||
public static final DictionaryTableDef DICTIONARY = new DictionaryTableDef();
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
public final QueryColumn ID = new QueryColumn(this, "id");
|
||||
|
||||
/**
|
||||
* 字典代码
|
||||
*/
|
||||
public final QueryColumn CODE = new QueryColumn(this, "code");
|
||||
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
public final QueryColumn NAME = new QueryColumn(this, "name");
|
||||
|
||||
/**
|
||||
* 字典类型: enum-枚举、tree-树型
|
||||
*/
|
||||
public final QueryColumn TYPE = new QueryColumn(this, "type");
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
public final QueryColumn CREATE_TIME = new QueryColumn(this, "create_time");
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
public final QueryColumn UPDATE_TIME = new QueryColumn(this, "update_time");
|
||||
|
||||
/**
|
||||
* 字典描述
|
||||
*/
|
||||
public final QueryColumn DESCRIPTION = new QueryColumn(this, "description");
|
||||
|
||||
/**
|
||||
* 所有字段。
|
||||
*/
|
||||
public final QueryColumn ALL_COLUMNS = new QueryColumn(this, "*");
|
||||
|
||||
/**
|
||||
* 默认字段,不包含逻辑删除或者 large 等字段。
|
||||
*/
|
||||
public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{ID, NAME, CODE, TYPE, DESCRIPTION, CREATE_TIME, UPDATE_TIME};
|
||||
|
||||
public DictionaryTableDef() {
|
||||
super("", "sys_core_dictionary");
|
||||
}
|
||||
|
||||
private DictionaryTableDef(String schema, String name, String alisa) {
|
||||
super(schema, name, alisa);
|
||||
}
|
||||
|
||||
public DictionaryTableDef as(String alias) {
|
||||
String key = getNameWithSchema() + "." + alias;
|
||||
return getCache(key, k -> new DictionaryTableDef("", "sys_core_dictionary", alias));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
package day.gitlab.dolphin.core.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import day.gitlab.dolphin.core.entity.DictionaryItem;
|
||||
|
||||
/**
|
||||
* 字典项 映射层。
|
||||
*
|
||||
* @author jiangyc
|
||||
* @since 2025-11-28
|
||||
*/
|
||||
@Mapper
|
||||
public interface DictionaryItemMapper extends BaseMapper<DictionaryItem> {
|
||||
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
package day.gitlab.dolphin.core.mapper;
|
||||
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import day.gitlab.dolphin.common.core.entity.QueryPageRequest;
|
||||
import day.gitlab.dolphin.common.mybatis.Pages;
|
||||
import day.gitlab.dolphin.core.entity.dto.DictionaryDTO;
|
||||
import day.gitlab.dolphin.core.entity.table.DictionaryTableDef;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import day.gitlab.dolphin.core.entity.Dictionary;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* 字典 映射层。
|
||||
*
|
||||
* @author jiangyc
|
||||
* @since 2025-11-28
|
||||
*/
|
||||
@Mapper
|
||||
public interface DictionaryMapper extends BaseMapper<Dictionary> {
|
||||
|
||||
default Page<Dictionary> page(QueryPageRequest<DictionaryDTO> pageRequest) {
|
||||
return Pages.paginate(this, pageRequest, (dict, wrapper) -> {
|
||||
if (StringUtils.hasText(dict.getName())) {
|
||||
wrapper.and(DictionaryTableDef.DICTIONARY.NAME.like(dict.getName()));
|
||||
}
|
||||
if (StringUtils.hasText(dict.getCode())) {
|
||||
wrapper.and(DictionaryTableDef.DICTIONARY.CODE.like(dict.getCode()));
|
||||
}
|
||||
if (StringUtils.hasText(dict.getType())) {
|
||||
wrapper.and(DictionaryTableDef.DICTIONARY.TYPE.eq(dict.getType()));
|
||||
}
|
||||
|
||||
return wrapper;
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
package day.gitlab.dolphin.core.service;
|
||||
|
||||
/**
|
||||
* 字典项 服务层。
|
||||
*
|
||||
* @author jiangyc
|
||||
* @since 2025-11-28
|
||||
*/
|
||||
public interface DictionaryItemService {
|
||||
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package day.gitlab.dolphin.core.service;
|
||||
|
||||
import day.gitlab.dolphin.common.core.entity.PageResponse;
|
||||
import day.gitlab.dolphin.common.core.entity.QueryPageRequest;
|
||||
import day.gitlab.dolphin.core.entity.dto.DictionaryDTO;
|
||||
import day.gitlab.dolphin.core.entity.vo.DictionaryVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典 服务层。
|
||||
*
|
||||
* @author jiangyc
|
||||
* @since 2025-11-28
|
||||
*/
|
||||
public interface DictionaryService {
|
||||
|
||||
PageResponse<DictionaryVO> page(QueryPageRequest<DictionaryDTO> pageRequest);
|
||||
|
||||
void add(DictionaryDTO dictionaryDTO);
|
||||
|
||||
void edit(DictionaryDTO dictionaryDTO);
|
||||
|
||||
void delete(String id);
|
||||
|
||||
void deleteBatch(List<String> ids);
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
package day.gitlab.dolphin.core.service.impl;
|
||||
|
||||
import day.gitlab.dolphin.core.service.DictionaryItemService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 字典项 服务层实现。
|
||||
*
|
||||
* @author jiangyc
|
||||
* @since 2025-11-28
|
||||
*/
|
||||
@Service
|
||||
public class DictionaryItemServiceImpl implements DictionaryItemService {
|
||||
|
||||
}
|
||||
@ -1,112 +0,0 @@
|
||||
package day.gitlab.dolphin.core.service.impl;
|
||||
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import day.gitlab.dolphin.common.core.entity.PageResponse;
|
||||
import day.gitlab.dolphin.common.core.entity.QueryPageRequest;
|
||||
import day.gitlab.dolphin.common.core.i18n.MessagesHelper;
|
||||
import day.gitlab.dolphin.common.mybatis.Pages;
|
||||
import day.gitlab.dolphin.core.constants.Exceptions;
|
||||
import day.gitlab.dolphin.core.entity.Dictionary;
|
||||
import day.gitlab.dolphin.core.entity.dto.DictionaryDTO;
|
||||
import day.gitlab.dolphin.core.entity.vo.DictionaryVO;
|
||||
import day.gitlab.dolphin.core.mapper.DictionaryMapper;
|
||||
import day.gitlab.dolphin.core.service.DictionaryService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典 服务层实现。
|
||||
*
|
||||
* @author jiangyc
|
||||
* @since 2025-11-28
|
||||
*/
|
||||
@Service
|
||||
public class DictionaryServiceImpl implements DictionaryService {
|
||||
|
||||
@Resource
|
||||
private DictionaryMapper dictionaryMapper;
|
||||
|
||||
@Resource
|
||||
private MessagesHelper messagesHelper;
|
||||
|
||||
@Override
|
||||
public PageResponse<DictionaryVO> page(QueryPageRequest<DictionaryDTO> pageRequest) {
|
||||
Page<Dictionary> page = dictionaryMapper.page(pageRequest);
|
||||
|
||||
return Pages.toPageResponse(page, (rec) -> {
|
||||
DictionaryVO vo = new DictionaryVO();
|
||||
vo.setId(rec.getId());
|
||||
vo.setName(rec.getName());
|
||||
vo.setCode(rec.getCode());
|
||||
vo.setType(rec.getType());
|
||||
vo.setDescription(rec.getDescription());
|
||||
vo.setCreateTime(rec.getCreateTime());
|
||||
vo.setUpdateTime(rec.getUpdateTime());
|
||||
return vo;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(DictionaryDTO dictionaryDTO) {
|
||||
validate(dictionaryDTO);
|
||||
|
||||
Dictionary dict = Dictionary.builder()
|
||||
.name(dictionaryDTO.getName())
|
||||
.code(dictionaryDTO.getCode())
|
||||
.type(dictionaryDTO.getType())
|
||||
.description(dictionaryDTO.getDescription())
|
||||
.createTime(Timestamp.from(Instant.now()))
|
||||
.updateTime(Timestamp.from(Instant.now()))
|
||||
.build();
|
||||
dictionaryMapper.insert(dict);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edit(DictionaryDTO dictionaryDTO) {
|
||||
validate(dictionaryDTO);
|
||||
|
||||
Dictionary dict = Dictionary.builder()
|
||||
.id(dictionaryDTO.getId())
|
||||
.name(dictionaryDTO.getName())
|
||||
.code(dictionaryDTO.getCode())
|
||||
.type(dictionaryDTO.getType())
|
||||
.description(dictionaryDTO.getDescription())
|
||||
.updateTime(Timestamp.from(Instant.now()))
|
||||
.build();
|
||||
dictionaryMapper.update(dict);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String id) {
|
||||
dictionaryMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBatch(List<String> ids) {
|
||||
dictionaryMapper.deleteBatchByIds(ids);
|
||||
}
|
||||
|
||||
private void validate(DictionaryDTO dictionaryDTO) {
|
||||
List<String> fields = new ArrayList<>();
|
||||
|
||||
if (!StringUtils.hasText(dictionaryDTO.getName())) {
|
||||
fields.add("name");
|
||||
}
|
||||
if (!StringUtils.hasText(dictionaryDTO.getCode())) {
|
||||
fields.add("code");
|
||||
}
|
||||
if (!StringUtils.hasText(dictionaryDTO.getType())) {
|
||||
fields.add("type");
|
||||
}
|
||||
|
||||
if (!fields.isEmpty()) {
|
||||
throw messagesHelper.newBusinessException(Exceptions.FIELD_REQUIRED, String.join(",", fields));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package day.gitlab.dolphin.module.core.controller;
|
||||
|
||||
import day.gitlab.dolphin.common.web.entity.ApiResponse;
|
||||
import day.gitlab.dolphin.common.web.entity.PageRequest;
|
||||
import day.gitlab.dolphin.common.web.entity.PageResponse;
|
||||
import day.gitlab.dolphin.module.core.controller.dto.DictionaryDTO;
|
||||
import day.gitlab.dolphin.module.core.controller.vo.DictionaryVO;
|
||||
import day.gitlab.dolphin.module.core.service.DictionaryService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/dictionary")
|
||||
public class DictionaryController {
|
||||
|
||||
private final DictionaryService dictionaryService;
|
||||
|
||||
@PostMapping("/paginate")
|
||||
public ApiResponse<PageResponse<DictionaryVO>> paginate(@RequestBody PageRequest<DictionaryDTO> pageRequest) {
|
||||
return ApiResponse.success(dictionaryService.paginate(pageRequest));
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ApiResponse<Boolean> update(@RequestBody DictionaryDTO record) {
|
||||
return ApiResponse.success(dictionaryService.update(record));
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public ApiResponse<Boolean> delete(@RequestBody DictionaryDTO record) {
|
||||
return ApiResponse.success(dictionaryService.delete(record));
|
||||
}
|
||||
|
||||
@PostMapping("/insert")
|
||||
public ApiResponse<Boolean> insert(@RequestBody DictionaryDTO record) {
|
||||
return ApiResponse.success(dictionaryService.insert(record));
|
||||
}
|
||||
}
|
||||
@ -1,14 +1,10 @@
|
||||
package day.gitlab.dolphin.core.entity.dto;
|
||||
package day.gitlab.dolphin.module.core.controller.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DictionaryDTO {
|
||||
@ -22,6 +18,4 @@ public class DictionaryDTO {
|
||||
private String type;
|
||||
|
||||
private String description;
|
||||
|
||||
private List<String> ids;
|
||||
}
|
||||
@ -1,14 +1,15 @@
|
||||
package day.gitlab.dolphin.core.entity.vo;
|
||||
package day.gitlab.dolphin.module.core.controller.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DictionaryVO {
|
||||
@ -0,0 +1,31 @@
|
||||
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")
|
||||
public class Dictionary {
|
||||
|
||||
@TableId
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String code;
|
||||
|
||||
private String type;
|
||||
|
||||
private String description;
|
||||
|
||||
private Timestamp createTime;
|
||||
|
||||
private Timestamp updateTime;
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package day.gitlab.dolphin.module.core.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import day.gitlab.dolphin.module.core.entity.Dictionary;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface DictionaryMapper extends BaseMapper<Dictionary> {
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package day.gitlab.dolphin.module.core.service;
|
||||
|
||||
import day.gitlab.dolphin.common.web.entity.PageRequest;
|
||||
import day.gitlab.dolphin.common.web.entity.PageResponse;
|
||||
import day.gitlab.dolphin.module.core.controller.dto.DictionaryDTO;
|
||||
import day.gitlab.dolphin.module.core.controller.vo.DictionaryVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DictionaryService {
|
||||
|
||||
PageResponse<DictionaryVO> paginate(PageRequest<DictionaryDTO> pageRequest);
|
||||
|
||||
boolean update(DictionaryDTO record);
|
||||
|
||||
boolean delete(DictionaryDTO record);
|
||||
|
||||
boolean insert(DictionaryDTO record);
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
package day.gitlab.dolphin.module.core.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import day.gitlab.dolphin.common.core.util.Strings;
|
||||
import day.gitlab.dolphin.common.mybatis.util.Pages;
|
||||
import day.gitlab.dolphin.common.web.entity.PageRequest;
|
||||
import day.gitlab.dolphin.common.web.entity.PageResponse;
|
||||
import day.gitlab.dolphin.module.core.controller.dto.DictionaryDTO;
|
||||
import day.gitlab.dolphin.module.core.controller.vo.DictionaryVO;
|
||||
import day.gitlab.dolphin.module.core.entity.Dictionary;
|
||||
import day.gitlab.dolphin.module.core.mapper.DictionaryMapper;
|
||||
import day.gitlab.dolphin.module.core.service.DictionaryService;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DictionaryServiceImpl implements DictionaryService {
|
||||
|
||||
@NonNull
|
||||
private final DictionaryMapper dictionaryMapper;
|
||||
|
||||
@Override
|
||||
public PageResponse<DictionaryVO> paginate(PageRequest<DictionaryDTO> pageRequest) {
|
||||
Page<Dictionary> paginate = Pages.paginate(pageRequest, dictionaryMapper, (dto, wrapper) -> {
|
||||
if (Strings.isNotBlank(dto.getName())) {
|
||||
wrapper.like("name", dto.getName());
|
||||
}
|
||||
if (Strings.isNotBlank(dto.getCode())) {
|
||||
wrapper.eq("code", dto.getCode());
|
||||
}
|
||||
if (Strings.isNotBlank(dto.getType())) {
|
||||
wrapper.eq("type", dto.getType());
|
||||
}
|
||||
|
||||
return wrapper;
|
||||
});
|
||||
|
||||
return Pages.toPageResponse(paginate, (record) -> {
|
||||
DictionaryVO dictionaryVO = new DictionaryVO();
|
||||
BeanUtils.copyProperties(record, dictionaryVO);
|
||||
return dictionaryVO;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(DictionaryDTO record) {
|
||||
Dictionary dictionary = dictionaryMapper.selectById(record.getId());
|
||||
if (dictionary != null) {
|
||||
if (Strings.isNotBlank(dictionary.getName())) {
|
||||
dictionary.setName(dictionary.getName());
|
||||
}
|
||||
if (Strings.isNotBlank(dictionary.getCode())) {
|
||||
dictionary.setCode(dictionary.getCode());
|
||||
}
|
||||
if (Strings.isNotBlank(dictionary.getType())) {
|
||||
dictionary.setType(dictionary.getType());
|
||||
}
|
||||
if (Strings.isNotBlank(dictionary.getDescription())) {
|
||||
dictionary.setDescription(dictionary.getDescription());
|
||||
}
|
||||
dictionary.setUpdateTime(Timestamp.from(Instant.now()));
|
||||
return dictionaryMapper.updateById(dictionary) == 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(DictionaryDTO record) {
|
||||
Dictionary dictionary = dictionaryMapper.selectById(record.getId());
|
||||
if (dictionary != null) {
|
||||
return dictionaryMapper.deleteById(dictionary.getId()) == 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insert(DictionaryDTO record) {
|
||||
Dictionary dictionary = new Dictionary();
|
||||
BeanUtils.copyProperties(record, dictionary);
|
||||
dictionary.setCreateTime(Timestamp.from(Instant.now()));
|
||||
dictionary.setUpdateTime(Timestamp.from(Instant.now()));
|
||||
return dictionaryMapper.insert(dictionary) == 1;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
<?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="day.gitlab.dolphin.module.core.mapper.DictionaryMapper">
|
||||
<!--
|
||||
<resultMap id="BaseResultMap" type="day.gitlab.dolphin.module.core.entity.Dictionary">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="name" property="name" jdbcType="VARCHAR"/>
|
||||
<result column="code" property="code" jdbcType="VARCHAR"/>
|
||||
<result column="type" property="type" jdbcType="VARCHAR"/>
|
||||
<result column="description" property="description" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert" parameterType="day.gitlab.dolphin.module.core.entity.Dictionary">
|
||||
INSERT INTO sys_core_dictionary(id, name, code, type, description)
|
||||
VALUES (
|
||||
#{id, jdbcType=VARCHAR},
|
||||
#{name, jdbcType=VARCHAR},
|
||||
#{code, jdbcType=VARCHAR},
|
||||
#{type, jdbcType=VARCHAR},
|
||||
#{description, jdbcType=VARCHAR}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<delete id="delete" parameterType="java.lang.String">
|
||||
DELETE FROM sys_core_dictionary
|
||||
WHERE id = #{id, jdbcType=VARCHAR}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteBatch" parameterType="java.util.List">
|
||||
DELETE FROM sys_core_dictionary
|
||||
WHERE id IN
|
||||
<foreach collection="list" item="id" open="(" separator=", " close=")">
|
||||
#{id, jdbcType=VARCHAR}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<update id="update" parameterType="day.gitlab.dolphin.module.core.entity.Dictionary">
|
||||
UPDATE sys_core_dictionary
|
||||
<set>
|
||||
<if test="name != null and name != ''">
|
||||
name = #{name, jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="code != null and code != ''">
|
||||
code = #{code, jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="type != null and type != ''">
|
||||
type = #{type, jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="description != null">
|
||||
description = #{description, jdbcType=VARCHAR},
|
||||
</if>
|
||||
update_time = CURRENT_TIMESTAMP
|
||||
</set>
|
||||
WHERE id = #{id, jdbcType=VARCHAR}
|
||||
</update>-->
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user