feat: replace mybatis-plus to mybatis-flex
This commit is contained in:
@ -1,8 +1,5 @@
|
||||
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.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package day.gitlab.dolphin.module.core.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -11,10 +11,10 @@ import java.sql.Timestamp;
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("sys_core_dictionary")
|
||||
@Table("sys_core_dictionary")
|
||||
public class Dictionary {
|
||||
|
||||
@TableId
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package day.gitlab.dolphin.module.core.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -11,10 +11,10 @@ import java.sql.Timestamp;
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("sys_core_dictionary_item")
|
||||
@Table("sys_core_dictionary_item")
|
||||
public class DictionaryItem {
|
||||
|
||||
@TableId
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private String dictionaryId;
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
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 com.mybatisflex.core.BaseMapper;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import day.gitlab.dolphin.module.core.entity.DictionaryItem;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@ -12,8 +11,9 @@ import java.util.List;
|
||||
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);
|
||||
QueryWrapper wrapper = new QueryWrapper()
|
||||
.eq(DictionaryItem::getDictionaryId, dictionaryId)
|
||||
.orderBy(DictionaryItem::getSort).asc();
|
||||
return selectListByQuery(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package day.gitlab.dolphin.module.core.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import day.gitlab.dolphin.module.core.entity.Dictionary;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
||||
@ -23,17 +23,12 @@ public class DictionaryItemServiceImpl implements DictionaryItemService {
|
||||
@Override
|
||||
public List<DictionaryItemVO> tree(String dictionaryId) {
|
||||
List<DictionaryItem> records = dictionaryItemMapper.findAllByDictionaryId(dictionaryId);
|
||||
List<DictionaryItem> sortedRecords = records.stream().sorted((item1, item2) -> {
|
||||
int sort1 = item1.getSort() == null ? 0 : item1.getSort();
|
||||
int sort2 = item2.getSort() == null ? 0 : item2.getSort();
|
||||
return sort2 - sort1;
|
||||
}).toList();
|
||||
return list2tree(sortedRecords);
|
||||
return list2tree(records);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean update(DictionaryItemDTO record) {
|
||||
DictionaryItem dictionaryItem = dictionaryItemMapper.selectById(record.getId());
|
||||
DictionaryItem dictionaryItem = dictionaryItemMapper.selectOneById(record.getId());
|
||||
if (dictionaryItem == null) {
|
||||
return false;
|
||||
}
|
||||
@ -57,7 +52,7 @@ public class DictionaryItemServiceImpl implements DictionaryItemService {
|
||||
}
|
||||
dictionaryItem.setDescription(record.getDescription());
|
||||
dictionaryItem.setUpdateTime(Timestamp.from(Instant.now()));
|
||||
return dictionaryItemMapper.updateById(dictionaryItem) > 0;
|
||||
return dictionaryItemMapper.update(dictionaryItem) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -67,7 +62,7 @@ public class DictionaryItemServiceImpl implements DictionaryItemService {
|
||||
|
||||
@Override
|
||||
public Integer deleteBatch(List<String> ids) {
|
||||
return dictionaryItemMapper.deleteByIds(ids);
|
||||
return dictionaryItemMapper.deleteBatchByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
package day.gitlab.dolphin.module.core.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import day.gitlab.dolphin.common.core.util.Strings;
|
||||
import day.gitlab.dolphin.common.mybatis.util.Mappers;
|
||||
import day.gitlab.dolphin.common.web.entity.PageRequest;
|
||||
@ -31,7 +30,7 @@ public class DictionaryServiceImpl implements DictionaryService {
|
||||
@Override
|
||||
public PageResponse<DictionaryVO> paginate(PageRequest<DictionaryDTO> pageRequest) {
|
||||
Page<Dictionary> page = Mappers.page(pageRequest, dictionaryMapper, (dto) -> {
|
||||
LambdaQueryWrapper<Dictionary> wrapper = Wrappers.lambdaQuery();
|
||||
QueryWrapper wrapper = new QueryWrapper();
|
||||
if (Strings.isNotBlank(dto.getName())) {
|
||||
wrapper.like(Dictionary::getName, dto.getName());
|
||||
}
|
||||
@ -53,7 +52,7 @@ public class DictionaryServiceImpl implements DictionaryService {
|
||||
|
||||
@Override
|
||||
public boolean update(DictionaryDTO record) {
|
||||
Dictionary dictionary = dictionaryMapper.selectById(record.getId());
|
||||
Dictionary dictionary = dictionaryMapper.selectOneById(record.getId());
|
||||
if (dictionary != null) {
|
||||
if (Strings.isNotBlank(record.getName())) {
|
||||
dictionary.setName(dictionary.getName());
|
||||
@ -66,14 +65,14 @@ public class DictionaryServiceImpl implements DictionaryService {
|
||||
}
|
||||
dictionary.setDescription(record.getDescription());
|
||||
dictionary.setUpdateTime(Timestamp.from(Instant.now()));
|
||||
return dictionaryMapper.updateById(dictionary) == 1;
|
||||
return dictionaryMapper.update(dictionary) == 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(String id) {
|
||||
Dictionary dictionary = dictionaryMapper.selectById(id);
|
||||
Dictionary dictionary = dictionaryMapper.selectOneById(id);
|
||||
if (dictionary != null) {
|
||||
return dictionaryMapper.deleteById(dictionary.getId()) == 1;
|
||||
}
|
||||
@ -82,7 +81,7 @@ public class DictionaryServiceImpl implements DictionaryService {
|
||||
|
||||
@Override
|
||||
public int deleteBatch(List<String> ids) {
|
||||
return dictionaryMapper.deleteByIds(ids);
|
||||
return dictionaryMapper.deleteBatchByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user