feat: replace mybatis-plus to mybatis-flex
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user