feat: replace mybatis-plus to mybatis-flex
This commit is contained in:
@ -24,15 +24,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webmvc</artifactId>
|
||||
</dependency>
|
||||
<!-- MyBatis -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot4-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
|
||||
@ -21,7 +21,7 @@ public class AuthorizationProviderImpl implements AuthenticationProvider {
|
||||
|
||||
@Override
|
||||
public UserPrincipal getUserPrincipal(String userId) {
|
||||
User user = userMapper.selectById(userId);
|
||||
User user = userMapper.selectOneById(userId);
|
||||
Objects.requireNonNull(user);
|
||||
|
||||
return UserPrincipal.builder()
|
||||
|
||||
@ -30,8 +30,8 @@
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot4-starter</artifactId>
|
||||
<groupId>com.jiangyc</groupId>
|
||||
<artifactId>mybatis-flex-spring-boot4-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
package day.gitlab.dolphin.common.mybatis.config;
|
||||
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.core.FlexGlobalConfig;
|
||||
import com.mybatisflex.core.audit.AuditManager;
|
||||
import com.mybatisflex.core.keygen.KeyGeneratorFactory;
|
||||
import com.mybatisflex.spring.boot.MyBatisFlexCustomizer;
|
||||
import day.gitlab.dolphin.common.mybatis.util.UUIDv7Generator;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class MyBatisFlexConfiguration implements MyBatisFlexCustomizer {
|
||||
|
||||
static {
|
||||
AuditManager.setAuditEnable(true);
|
||||
|
||||
KeyGeneratorFactory.register("uuidv7", new UUIDv7Generator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(FlexGlobalConfig globalConfig) {
|
||||
FlexGlobalConfig.KeyConfig keyConfig = new FlexGlobalConfig.KeyConfig();
|
||||
keyConfig.setKeyType(KeyType.Sequence);
|
||||
keyConfig.setValue("uuidv7");
|
||||
keyConfig.setBefore(true);
|
||||
globalConfig.setKeyConfig(keyConfig);
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
package day.gitlab.dolphin.common.mybatis.util;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import day.gitlab.dolphin.common.web.entity.PageRequest;
|
||||
import day.gitlab.dolphin.common.web.entity.PageResponse;
|
||||
|
||||
@ -13,24 +13,16 @@ public class Mappers {
|
||||
|
||||
public static <T, E> Page<E> page(PageRequest<T> pageRequest,
|
||||
BaseMapper<E> mapper,
|
||||
Function<T, LambdaQueryWrapper<E>> function) {
|
||||
Page<E> reqPage = toPage(pageRequest);
|
||||
LambdaQueryWrapper<E> wrapper = function.apply(pageRequest.getQuery());
|
||||
Function<T, QueryWrapper> function) {
|
||||
Page<E> reqPage = Page.of(pageRequest.getPageIndex(), pageRequest.getPageSize());
|
||||
QueryWrapper wrapper = function.apply(pageRequest.getQuery());
|
||||
|
||||
Page<E> resPage = mapper.selectPage(reqPage, wrapper);
|
||||
Long count = mapper.selectCount(wrapper);
|
||||
resPage.setTotal(count);
|
||||
|
||||
return resPage;
|
||||
}
|
||||
|
||||
public static <T, E> Page<E> toPage(PageRequest<T> pageRequest) {
|
||||
return new Page<>(pageRequest.getPageIndex(), pageRequest.getPageSize());
|
||||
return mapper.paginate(reqPage, wrapper);
|
||||
}
|
||||
|
||||
public static <T, E> PageResponse<E> mapPage(Page<T> page, Function<T, E> mapper) {
|
||||
List<E> records = page.getRecords().stream().map(mapper).toList();
|
||||
|
||||
return new PageResponse<>(page.getCurrent(), page.getSize(), page.getTotal(), records);
|
||||
return new PageResponse<>(page.getPageNumber(), page.getPageSize(), page.getTotalRow(), records);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,20 +1,17 @@
|
||||
package day.gitlab.dolphin.common.mybatis.util;
|
||||
|
||||
import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
|
||||
import com.mybatisflex.core.keygen.IKeyGenerator;
|
||||
import day.gitlab.dolphin.common.core.util.UUIDv7;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
@Component
|
||||
public class UUIDv7Generator extends DefaultIdentifierGenerator {
|
||||
public class UUIDv7Generator implements IKeyGenerator {
|
||||
|
||||
public UUIDv7Generator() {
|
||||
super((InetAddress) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nextUUID(Object entity) {
|
||||
public Object generate(Object entity, String keyColumn) {
|
||||
return UUIDv7.randomUUID().toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,20 +1,21 @@
|
||||
package day.gitlab.dolphin.module.rbac.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.util.Date;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 部门表
|
||||
*/
|
||||
@Data
|
||||
@TableName(value ="sys_rbac_department")
|
||||
@Table(value ="sys_rbac_department")
|
||||
public class Department {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,20 +1,21 @@
|
||||
package day.gitlab.dolphin.module.rbac.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.util.Date;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 区划项
|
||||
*/
|
||||
@Data
|
||||
@TableName(value ="sys_rbac_region")
|
||||
@Table(value ="sys_rbac_region")
|
||||
public class Region {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,20 +1,21 @@
|
||||
package day.gitlab.dolphin.module.rbac.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.util.Date;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 角色表
|
||||
*/
|
||||
@Data
|
||||
@TableName(value ="sys_rbac_role")
|
||||
@Table(value ="sys_rbac_role")
|
||||
public class Role {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package day.gitlab.dolphin.module.rbac.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.util.Date;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import day.gitlab.dolphin.module.rbac.enums.UserEnabled;
|
||||
import lombok.Data;
|
||||
|
||||
@ -11,12 +11,12 @@ import lombok.Data;
|
||||
* 用户表
|
||||
*/
|
||||
@Data
|
||||
@TableName(value ="sys_rbac_user")
|
||||
@Table(value ="sys_rbac_user")
|
||||
public class User {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,16 +1,17 @@
|
||||
package day.gitlab.dolphin.module.rbac.enums;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IEnum;
|
||||
import com.mybatisflex.annotation.EnumValue;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum UserEnabled implements IEnum<String> {
|
||||
public enum UserEnabled {
|
||||
|
||||
ENABLED("1"),
|
||||
DISABLED("0");
|
||||
|
||||
@EnumValue
|
||||
private final String value;
|
||||
|
||||
public static UserEnabled fromValue(String value) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package day.gitlab.dolphin.module.rbac.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import day.gitlab.dolphin.module.rbac.entity.Department;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
package day.gitlab.dolphin.module.rbac.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import day.gitlab.dolphin.module.rbac.entity.Region;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
@ -13,8 +12,8 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
public interface RegionMapper extends BaseMapper<Region> {
|
||||
|
||||
default Region findByCode(String code) {
|
||||
LambdaQueryWrapper<Region> wrapper = Wrappers.<Region>lambdaQuery().eq(Region::getCode, code);
|
||||
return selectOne(wrapper);
|
||||
QueryWrapper wrapper = new QueryWrapper().eq(Region::getCode, code);
|
||||
return selectOneByQuery(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package day.gitlab.dolphin.module.rbac.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import day.gitlab.dolphin.module.rbac.entity.Role;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
package day.gitlab.dolphin.module.rbac.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import day.gitlab.dolphin.module.rbac.entity.User;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
@ -13,9 +12,8 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
|
||||
default User findByUsername(String username) {
|
||||
LambdaQueryWrapper<User> wrapper = Wrappers.<User>lambdaQuery()
|
||||
.eq(User::getUsername, username);
|
||||
return selectOne(wrapper);
|
||||
QueryWrapper wrapper = new QueryWrapper().eq(User::getUsername, username);
|
||||
return selectOneByQuery(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
package day.gitlab.dolphin.module.rbac.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;
|
||||
@ -32,7 +31,7 @@ public class DepartmentServiceImpl implements DepartmentService {
|
||||
@Override
|
||||
public PageResponse<DepartmentVO> paginate(PageRequest<DepartmentDTO> pageRequest) {
|
||||
Page<Department> resPage = Mappers.page(pageRequest, departmentMapper, dto -> {
|
||||
LambdaQueryWrapper<Department> wrapper = Wrappers.lambdaQuery();
|
||||
QueryWrapper wrapper = new QueryWrapper();
|
||||
if (Strings.isNotBlank(dto.getRegionId())) {
|
||||
wrapper.eq(Department::getRegionId, dto.getRegionId());
|
||||
}
|
||||
@ -52,7 +51,7 @@ public class DepartmentServiceImpl implements DepartmentService {
|
||||
return departmentVO;
|
||||
});
|
||||
|
||||
LambdaQueryWrapper<Department> wrapper = new LambdaQueryWrapper<>();
|
||||
QueryWrapper wrapper = new QueryWrapper();
|
||||
DepartmentDTO dto = pageRequest.getQuery();
|
||||
if (Strings.isNotBlank(dto.getRegionId())) {
|
||||
wrapper.eq(Department::getRegionId, dto.getRegionId());
|
||||
@ -63,7 +62,7 @@ public class DepartmentServiceImpl implements DepartmentService {
|
||||
if (Strings.isNotBlank(dto.getCode())) {
|
||||
wrapper.eq(Department::getCode, dto.getCode());
|
||||
}
|
||||
List<Department> departments = departmentMapper.selectList(wrapper);
|
||||
List<Department> departments = departmentMapper.selectListByQuery(wrapper);
|
||||
pageResponse.getRecords().forEach(record -> {
|
||||
list2tree(record, departments);
|
||||
});
|
||||
@ -73,7 +72,7 @@ public class DepartmentServiceImpl implements DepartmentService {
|
||||
|
||||
@Override
|
||||
public boolean update(DepartmentDTO record) {
|
||||
Department department = departmentMapper.selectById(record.getId());
|
||||
Department department = departmentMapper.selectOneById(record.getId());
|
||||
if (department != null) {
|
||||
department.setRegionId(record.getRegionId());
|
||||
department.setParentId(record.getParentId());
|
||||
@ -82,14 +81,14 @@ public class DepartmentServiceImpl implements DepartmentService {
|
||||
department.setSort(record.getSort());
|
||||
department.setDescription(record.getDescription());
|
||||
department.setUpdateTime(Timestamp.from(Instant.now()));
|
||||
return departmentMapper.updateById(department) == 1;
|
||||
return departmentMapper.update(department) == 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(String id) {
|
||||
Department department = departmentMapper.selectById(id);
|
||||
Department department = departmentMapper.selectOneById(id);
|
||||
if (department != null) {
|
||||
return departmentMapper.deleteById(department.getId()) == 1;
|
||||
}
|
||||
@ -98,7 +97,7 @@ public class DepartmentServiceImpl implements DepartmentService {
|
||||
|
||||
@Override
|
||||
public int deleteBatch(List<String> ids) {
|
||||
return departmentMapper.deleteByIds(ids);
|
||||
return departmentMapper.deleteBatchByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
package day.gitlab.dolphin.module.rbac.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;
|
||||
@ -32,7 +31,7 @@ public class RegionServiceImpl implements RegionService {
|
||||
@Override
|
||||
public PageResponse<RegionVO> paginate(PageRequest<RegionDTO> pageRequest) {
|
||||
Page<Region> resPage = Mappers.page(pageRequest, regionMapper, dto -> {
|
||||
LambdaQueryWrapper<Region> wrapper = Wrappers.lambdaQuery();
|
||||
QueryWrapper wrapper = new QueryWrapper();
|
||||
if (Strings.isNotBlank(dto.getName())) {
|
||||
wrapper.like(Region::getName, dto.getName());
|
||||
}
|
||||
@ -44,12 +43,12 @@ public class RegionServiceImpl implements RegionService {
|
||||
});
|
||||
|
||||
PageResponse<RegionVO> pageResponse = Mappers.mapPage(resPage, (record) -> {
|
||||
RegionVO dictionaryVO = new RegionVO();
|
||||
BeanUtils.copyProperties(record, dictionaryVO);
|
||||
return dictionaryVO;
|
||||
RegionVO regionVO = new RegionVO();
|
||||
BeanUtils.copyProperties(record, regionVO);
|
||||
return regionVO;
|
||||
});
|
||||
|
||||
LambdaQueryWrapper<Region> wrapper = new LambdaQueryWrapper<>();
|
||||
QueryWrapper wrapper = new QueryWrapper();
|
||||
RegionDTO dto = pageRequest.getQuery();
|
||||
if (Strings.isNotBlank(dto.getName())) {
|
||||
wrapper.like(Region::getName, dto.getName());
|
||||
@ -57,7 +56,7 @@ public class RegionServiceImpl implements RegionService {
|
||||
if (Strings.isNotBlank(dto.getCode())) {
|
||||
wrapper.eq(Region::getCode, dto.getCode());
|
||||
}
|
||||
List<Region> regions = regionMapper.selectList(wrapper);
|
||||
List<Region> regions = regionMapper.selectListByQuery(wrapper);
|
||||
pageResponse.getRecords().forEach(record -> {
|
||||
list2tree(record, regions);
|
||||
});
|
||||
@ -67,7 +66,7 @@ public class RegionServiceImpl implements RegionService {
|
||||
|
||||
@Override
|
||||
public boolean update(RegionDTO record) {
|
||||
Region region = regionMapper.selectById(record.getId());
|
||||
Region region = regionMapper.selectOneById(record.getId());
|
||||
if (region != null) {
|
||||
region.setParentId(record.getParentId());
|
||||
region.setParentCode(record.getParentCode());
|
||||
@ -83,23 +82,23 @@ public class RegionServiceImpl implements RegionService {
|
||||
region.setSort(record.getSort() == null ? 0 : record.getSort());
|
||||
region.setDescription(record.getDescription());
|
||||
region.setUpdateTime(Timestamp.from(Instant.now()));
|
||||
return regionMapper.updateById(region) == 1;
|
||||
return regionMapper.update(region) == 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(String id) {
|
||||
Region dictionary = regionMapper.selectById(id);
|
||||
if (dictionary != null) {
|
||||
return regionMapper.deleteById(dictionary.getId()) == 1;
|
||||
Region region = regionMapper.selectOneById(id);
|
||||
if (region != null) {
|
||||
return regionMapper.deleteById(region.getId()) == 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteBatch(List<String> ids) {
|
||||
return regionMapper.deleteByIds(ids);
|
||||
return regionMapper.deleteBatchByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -118,26 +117,11 @@ public class RegionServiceImpl implements RegionService {
|
||||
|
||||
dbRegion.setRootId(dbRegion.getId());
|
||||
dbRegion.setRootCode(dbRegion.getCode());
|
||||
return regionMapper.updateById(dbRegion) == 1;
|
||||
return regionMapper.update(dbRegion) == 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private List<RegionVO> list2tree(List<Region> records) {
|
||||
List<RegionVO> root = records.stream()
|
||||
.filter(rec -> Strings.isBlank(rec.getParentId()))
|
||||
.map(rec -> {
|
||||
RegionVO vo = new RegionVO();
|
||||
BeanUtils.copyProperties(rec, vo);
|
||||
return vo;
|
||||
})
|
||||
.toList();
|
||||
for (RegionVO parent : root) {
|
||||
list2tree(parent, records);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
private void list2tree(RegionVO parent, List<Region> records) {
|
||||
List<RegionVO> children = records.stream()
|
||||
.filter(rec -> parent.getId().equals(rec.getParentId()))
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
package day.gitlab.dolphin.module.rbac.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;
|
||||
@ -32,7 +31,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
@Override
|
||||
public PageResponse<RoleVO> paginate(PageRequest<RoleDTO> pageRequest) {
|
||||
Page<Role> resPage = Mappers.page(pageRequest, roleMapper, dto -> {
|
||||
LambdaQueryWrapper<Role> wrapper = Wrappers.lambdaQuery();
|
||||
QueryWrapper wrapper = new QueryWrapper();
|
||||
if (Strings.isNotBlank(dto.getName())) {
|
||||
wrapper.like(Role::getName, dto.getName());
|
||||
}
|
||||
@ -51,21 +50,21 @@ public class RoleServiceImpl implements RoleService {
|
||||
|
||||
@Override
|
||||
public boolean update(RoleDTO record) {
|
||||
Role role = roleMapper.selectById(record.getId());
|
||||
Role role = roleMapper.selectOneById(record.getId());
|
||||
if (role != null) {
|
||||
role.setName(record.getName());
|
||||
role.setCode(record.getCode());
|
||||
role.setSort(record.getSort());
|
||||
role.setDescription(record.getDescription());
|
||||
role.setUpdateTime(Timestamp.from(Instant.now()));
|
||||
return roleMapper.updateById(role) == 1;
|
||||
return roleMapper.update(role) == 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(String id) {
|
||||
Role role = roleMapper.selectById(id);
|
||||
Role role = roleMapper.selectOneById(id);
|
||||
if (role != null) {
|
||||
return roleMapper.deleteById(role.getId()) == 1;
|
||||
}
|
||||
@ -74,7 +73,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
|
||||
@Override
|
||||
public int deleteBatch(List<String> ids) {
|
||||
return roleMapper.deleteByIds(ids);
|
||||
return roleMapper.deleteBatchByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
package day.gitlab.dolphin.module.rbac.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;
|
||||
@ -33,7 +32,7 @@ public class UserServiceImpl implements UserService {
|
||||
@Override
|
||||
public PageResponse<UserVO> paginate(PageRequest<UserDTO> pageRequest) {
|
||||
Page<User> resPage = Mappers.page(pageRequest, userMapper, dto -> {
|
||||
LambdaQueryWrapper<User> wrapper = Wrappers.lambdaQuery();
|
||||
QueryWrapper wrapper = new QueryWrapper();
|
||||
if (Strings.isNotBlank(dto.getUsername())) {
|
||||
wrapper.like(User::getUsername, dto.getUsername());
|
||||
}
|
||||
@ -52,21 +51,21 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
@Override
|
||||
public boolean update(UserDTO record) {
|
||||
User user = userMapper.selectById(record.getId());
|
||||
User user = userMapper.selectOneById(record.getId());
|
||||
if (user != null) {
|
||||
user.setUsername(record.getUsername());
|
||||
user.setNickname(record.getNickname());
|
||||
user.setEnabled(UserEnabled.fromValue(record.getEnabled()));
|
||||
user.setDescription(record.getDescription());
|
||||
user.setUpdateTime(Timestamp.from(Instant.now()));
|
||||
return userMapper.updateById(user) == 1;
|
||||
return userMapper.update(user) == 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(String id) {
|
||||
User user = userMapper.selectById(id);
|
||||
User user = userMapper.selectOneById(id);
|
||||
if (user != null) {
|
||||
return userMapper.deleteById(user.getId()) == 1;
|
||||
}
|
||||
@ -75,7 +74,7 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
@Override
|
||||
public int deleteBatch(List<String> ids) {
|
||||
return userMapper.deleteByIds(ids);
|
||||
return userMapper.deleteBatchByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
8
pom.xml
8
pom.xml
@ -26,7 +26,7 @@
|
||||
<spring-boot.version>4.0.0</spring-boot.version>
|
||||
<!-- MyBatis -->
|
||||
<mybatis-spring.version>4.0.0</mybatis-spring.version>
|
||||
<mybatis-plus.version>3.5.15</mybatis-plus.version>
|
||||
<mybtis-flex.version>1.11.4</mybtis-flex.version>
|
||||
<!-- JWT -->
|
||||
<jjwt.version>0.13.0</jjwt.version>
|
||||
</properties>
|
||||
@ -55,9 +55,9 @@
|
||||
<version>${mybatis-spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot4-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
<groupId>com.jiangyc</groupId>
|
||||
<artifactId>mybatis-flex-spring-boot4-starter</artifactId>
|
||||
<version>${mybtis-flex.version}</version>
|
||||
</dependency>
|
||||
<!-- JWT -->
|
||||
<dependency>
|
||||
|
||||
Reference in New Issue
Block a user