refactor(core): 适配 mybatis-plus 3.5.9

This commit is contained in:
冷冷 committed 2024-11-24 18:04:22 +08:00
1 parent 0d9461d036
commit 10e5234e34
7 files changed
+78 -72

No files matched your search

+1 -1
View File
@@ -21,7 +21,7 @@
<!--mybatis plus extension,包含了mybatis plus core-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
<artifactId>mybatis-plus-spring</artifactId>
</dependency>
<!--feign 工具类-->
<dependency>
@@ -33,6 +33,8 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Objects;
/**
* @author lengleng
* @date 2019年11月02日
@@ -85,10 +87,21 @@ public class MiniAppLoginHandler extends AbstractLoginHandler {
public AppUserInfo info(String openId) {
AppUser user = appUserService.getOne(Wrappers.<AppUser>query().lambda().eq(AppUser::getWxOpenid, openId));
if (user == null) {
// 未注册用户自动注册
if (Objects.isNull(user)) {
log.info("微信小程序未绑定:{},创建新的用户", openId);
return createAndSaveAppUserInfo(openId);
AppUser appUser = new AppUser();
appUser.setWxOpenid(openId);
appUser.setUsername(openId);
appUser.setCreateBy(openId);
appUser.setUpdateBy(openId);
appUserService.saveOrUpdate(appUser);
AppUserInfo appUserDTO = new AppUserInfo();
appUserDTO.setAppUser(appUser);
return appUserDTO;
}
return appUserService.findUserInfo(user);
}
@@ -106,17 +119,4 @@ public class MiniAppLoginHandler extends AbstractLoginHandler {
return true;
}
private AppUserInfo createAndSaveAppUserInfo(String openId) {
AppUser appUser = new AppUser();
appUser.setWxOpenid(openId);
appUser.setUsername(openId);
appUser.setCreateBy(openId);
appUser.setUpdateBy(openId);
appUserService.saveOrUpdate(appUser, Wrappers.<AppUser>lambdaQuery().eq(AppUser::getUsername, openId));
AppUserInfo appUserDTO = new AppUserInfo();
appUserDTO.setAppUser(appUser);
return appUserDTO;
}
}
@@ -20,11 +20,14 @@ package com.pig4cloud.pigx.app.handler;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pig4cloud.pigx.app.api.dto.AppUserInfo;
import com.pig4cloud.pigx.app.api.entity.AppUser;
import com.pig4cloud.pigx.app.mapper.AppUserMapper;
import com.pig4cloud.pigx.app.service.AppUserService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Objects;
/**
* @author lengleng
* @date 2018/11/18
@@ -55,30 +58,24 @@ public class SmsLoginHandler extends AbstractLoginHandler {
public AppUserInfo info(String identify) {
AppUser user = appUserService.getOne(Wrappers.<AppUser>query().lambda().eq(AppUser::getPhone, identify));
if (user == null) {
// 未注册用户自动注册
if (Objects.isNull(user)) {
log.info("手机号未注册:{}", identify);
return createAndSaveAppUserInfo(identify);
AppUser appUser = new AppUser();
appUser.setUsername(identify);
appUser.setPhone(identify);
appUser.setCreateBy(identify);
appUser.setUpdateBy(identify);
appUserService.save(appUser);
AppUserInfo appUserDTO = new AppUserInfo();
appUserDTO.setAppUser(appUser);
return appUserDTO;
}
// 返回用户信息
return appUserService.findUserInfo(user);
}
/**
* 创建并插入用户
* @param identify
* @return
*/
private AppUserInfo createAndSaveAppUserInfo(String phone) {
AppUser appUser = new AppUser();
appUser.setUsername(phone);
appUser.setPhone(phone);
appUser.setCreateBy(phone);
appUser.setUpdateBy(phone);
appUserService.saveOrUpdate(appUser, Wrappers.<AppUser>lambdaQuery().eq(AppUser::getPhone, phone));
AppUserInfo appUserDTO = new AppUserInfo();
appUserDTO.setAppUser(appUser);
return appUserDTO;
}
/**
* 绑定逻辑
@@ -16,19 +16,21 @@ import org.springframework.stereotype.Service;
*/
@Service
public class AppArticleCollectServiceImpl extends ServiceImpl<AppArticleCollectMapper, AppArticleCollectEntity>
implements AppArticleCollectService {
implements AppArticleCollectService {
@Override
public Boolean saveArticleCollect(AppArticleCollectEntity appArticleCollect) {
Long id = SecurityUtils.getUser().getId();
appArticleCollect.setUserId(id);
@Override
public Boolean saveArticleCollect(AppArticleCollectEntity appArticleCollect) {
Long id = SecurityUtils.getUser().getId();
appArticleCollect.setUserId(id);
this.saveOrUpdate(appArticleCollect,
Wrappers.<AppArticleCollectEntity>lambdaQuery()
.eq(AppArticleCollectEntity::getUserId, id)
.eq(AppArticleCollectEntity::getArticleId, appArticleCollect.getArticleId()));
if (baseMapper.exists(Wrappers.<AppArticleCollectEntity>lambdaQuery()
.eq(AppArticleCollectEntity::getUserId, id)
.eq(AppArticleCollectEntity::getArticleId, appArticleCollect.getArticleId()))) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}
return this.save(appArticleCollect);
}
}
+6 -1
View File
@@ -42,7 +42,12 @@
<!--mybatis plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
<artifactId>mybatis-plus-spring</artifactId>
</dependency>
<!-- mybatis-plus 3.5.9 需要单独引入此依赖-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-jsqlparser</artifactId>
</dependency>
<!-- 连表查询依赖 -->
<dependency>
@@ -1,7 +1,6 @@
package com.pig4cloud.pigx.common.data.datascope;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.github.yulichang.base.MPJBaseMapper;
@@ -17,30 +16,33 @@ import java.util.List;
*/
public interface PigxBaseMapper<T> extends MPJBaseMapper<T> {
/**
* 根据 entity 条件,查询全部记录
* @param queryWrapper 实体对象封装操作类(可以为 null)
* @param scope 数据权限范围
* @return List<T>
*/
List<T> selectListByScope(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper, DataScope scope);
/**
* 根据 entity 条件,查询全部记录
*
* @param queryWrapper 实体对象封装操作类(可以为 null)
* @param scope 数据权限范围
* @return List<T>
*/
List<T> selectListByScope(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper, DataScope scope);
/**
* 根据 entity 条件,查询全部记录(并翻页)
* @param page 分页查询条件(可以为 RowBounds.DEFAULT)
* @param queryWrapper 实体对象封装操作类(可以为 null)
* @param scope 数据权限范围
* @return Page
*/
<E extends IPage<T>> E selectPageByScope(E page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper,
DataScope scope);
/**
* 根据 entity 条件,查询全部记录(并翻页)
*
* @param page 分页查询条件(可以为 RowBounds.DEFAULT)
* @param queryWrapper 实体对象封装操作类(可以为 null)
* @param scope 数据权限范围
* @return Page
*/
<E extends IPage<T>> E selectPageByScope(E page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper,
DataScope scope);
/**
* 根据 Wrapper 条件,查询总记录数
* @param queryWrapper 实体对象封装操作类(可以为 null)
* @param scope 数据权限范围
* @return Integer
*/
Long selectCountByScope(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper, DataScope scope);
/**
* 根据 Wrapper 条件,查询总记录数
*
* @param queryWrapper 实体对象封装操作类(可以为 null)
* @param scope 数据权限范围
* @return Integer
*/
Long selectCountByScope(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper, DataScope scope);
}
+1 -1
View File
@@ -47,7 +47,7 @@
<!--mybatis plus extension,包含了mybatis plus core-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
<artifactId>mybatis-plus-spring</artifactId>
</dependency>
<!--feign 工具类-->
<dependency>