mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 04:39:00 +08:00
refactor(core): 适配 mybatis-plus 3.5.9
This commit is contained in:
1 parent
95bb029175
commit
79c8a64ed4
11 files changed
+156
-156
No files matched your search
@@ -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>
|
||||
|
||||
+67
-50
@@ -28,10 +28,13 @@ import com.pig4cloud.pigx.app.mapper.AppSocialDetailsMapper;
|
||||
import com.pig4cloud.pigx.app.service.AppUserService;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.LoginTypeEnum;
|
||||
import com.pig4cloud.pigx.common.core.exception.CheckedException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019年11月02日
|
||||
@@ -43,63 +46,77 @@ import org.springframework.stereotype.Component;
|
||||
@AllArgsConstructor
|
||||
public class MiniAppLoginHandler extends AbstractLoginHandler {
|
||||
|
||||
private final AppUserService appUserService;
|
||||
private final AppUserService appUserService;
|
||||
|
||||
private final AppSocialDetailsMapper appSocialDetailsMapper;
|
||||
private final AppSocialDetailsMapper appSocialDetailsMapper;
|
||||
|
||||
/**
|
||||
* 小程序登录传入code
|
||||
* <p>
|
||||
* 通过code 调用qq 获取唯一标识
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String identify(String code) {
|
||||
AppSocialDetails condition = new AppSocialDetails();
|
||||
condition.setType(LoginTypeEnum.MINI_APP.getType());
|
||||
AppSocialDetails socialDetails = appSocialDetailsMapper.selectOne(new QueryWrapper<>(condition));
|
||||
/**
|
||||
* 小程序登录传入code
|
||||
* <p>
|
||||
* 通过code 调用qq 获取唯一标识
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String identify(String code) {
|
||||
AppSocialDetails condition = new AppSocialDetails();
|
||||
condition.setType(LoginTypeEnum.MINI_APP.getType());
|
||||
AppSocialDetails socialDetails = appSocialDetailsMapper.selectOne(new QueryWrapper<>(condition));
|
||||
|
||||
String url = String.format(SecurityConstants.MINI_APP_AUTHORIZATION_CODE_URL, socialDetails.getAppId(),
|
||||
socialDetails.getAppSecret(), code);
|
||||
String result = HttpUtil.get(url);
|
||||
log.debug("微信小程序响应报文:{}", result);
|
||||
String url = String.format(SecurityConstants.MINI_APP_AUTHORIZATION_CODE_URL, socialDetails.getAppId(),
|
||||
socialDetails.getAppSecret(), code);
|
||||
String result = HttpUtil.get(url);
|
||||
log.debug("微信小程序响应报文:{}", result);
|
||||
|
||||
Object obj = JSONUtil.parseObj(result).get("openid");
|
||||
return obj.toString();
|
||||
}
|
||||
if (JSONUtil.parseObj(result).containsKey("openid")) {
|
||||
return JSONUtil.parseObj(result).get("openid").toString();
|
||||
} else {
|
||||
log.error("微信小程序登录失败:{}", result);
|
||||
throw new CheckedException("微信小程序登录失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* openId 获取用户信息
|
||||
* @param openId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AppUserInfo info(String openId) {
|
||||
AppUser user = appUserService.getOne(Wrappers.<AppUser>query().lambda().eq(AppUser::getWxOpenid, openId));
|
||||
/**
|
||||
* openId 获取用户信息
|
||||
*
|
||||
* @param openId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AppUserInfo info(String openId) {
|
||||
AppUser user = appUserService.getOne(Wrappers.<AppUser>query().lambda().eq(AppUser::getWxOpenid, openId));
|
||||
|
||||
if (user == null) {
|
||||
log.info("微信小程序未绑定:{},创建新的用户", openId);
|
||||
return createAndSaveAppUserInfo(openId);
|
||||
}
|
||||
return appUserService.findUserInfo(user);
|
||||
}
|
||||
// 未注册用户自动注册
|
||||
if (Objects.isNull(user)) {
|
||||
log.info("微信小程序未绑定:{},创建新的用户", openId);
|
||||
AppUser appUser = new AppUser();
|
||||
appUser.setWxOpenid(openId);
|
||||
appUser.setUsername(openId);
|
||||
appUser.setCreateBy(openId);
|
||||
appUser.setUpdateBy(openId);
|
||||
appUserService.saveOrUpdate(appUser);
|
||||
|
||||
/**
|
||||
* 绑定逻辑
|
||||
* @param user 用户实体
|
||||
* @param identify 渠道返回唯一标识
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean bind(AppUser user, String identify) {
|
||||
user.setWxOpenid(identify);
|
||||
appUserService.updateById(user);
|
||||
return true;
|
||||
}
|
||||
AppUserInfo appUserDTO = new AppUserInfo();
|
||||
appUserDTO.setAppUser(appUser);
|
||||
return appUserDTO;
|
||||
}
|
||||
|
||||
private AppUserInfo createAndSaveAppUserInfo(String openId) {
|
||||
return appUserService.saveOrUpdateByLoginType(LoginTypeEnum.MINI_APP, openId);
|
||||
}
|
||||
return appUserService.findUserInfo(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定逻辑
|
||||
*
|
||||
* @param user 用户实体
|
||||
* @param identify 渠道返回唯一标识
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean bind(AppUser user, String identify) {
|
||||
user.setWxOpenid(identify);
|
||||
appUserService.updateById(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+16
-11
@@ -20,12 +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 com.pig4cloud.pigx.common.core.constant.enums.LoginTypeEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/11/18
|
||||
@@ -56,21 +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) {
|
||||
return appUserService.saveOrUpdateByLoginType(LoginTypeEnum.APPSMS, phone);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定逻辑
|
||||
|
||||
+10
-13
@@ -25,7 +25,6 @@ import com.pig4cloud.pigx.app.api.dto.AppUserInfo;
|
||||
import com.pig4cloud.pigx.app.api.entity.AppUser;
|
||||
import com.pig4cloud.pigx.app.api.vo.AppUserExcelVO;
|
||||
import com.pig4cloud.pigx.app.api.vo.AppUserVO;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.LoginTypeEnum;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import org.springframework.validation.BindingResult;
|
||||
|
||||
@@ -39,26 +38,24 @@ import java.util.List;
|
||||
*/
|
||||
public interface AppUserService extends IService<AppUser> {
|
||||
|
||||
Boolean updateUser(AppUserDTO appUser);
|
||||
Boolean updateUser(AppUserDTO appUser);
|
||||
|
||||
Boolean saveUser(AppUserDTO appUser);
|
||||
Boolean saveUser(AppUserDTO appUser);
|
||||
|
||||
List<AppUserExcelVO> listUser(AppUserDTO appUser);
|
||||
List<AppUserExcelVO> listUser(AppUserDTO appUser);
|
||||
|
||||
IPage getUsersWithRolePage(Page page, AppUserDTO appUserDTO);
|
||||
IPage getUsersWithRolePage(Page page, AppUserDTO appUserDTO);
|
||||
|
||||
AppUserInfo findUserInfo(AppUser user);
|
||||
AppUserInfo findUserInfo(AppUser user);
|
||||
|
||||
R updateUserInfo(AppUserDTO userDto);
|
||||
R updateUserInfo(AppUserDTO userDto);
|
||||
|
||||
AppUserVO selectUserVoById(Long userId);
|
||||
AppUserVO selectUserVoById(Long userId);
|
||||
|
||||
Boolean deleteAppUserByIds(Long[] ids);
|
||||
Boolean deleteAppUserByIds(Long[] ids);
|
||||
|
||||
R importUser(List<AppUserExcelVO> excelVOList, BindingResult bindingResult);
|
||||
R importUser(List<AppUserExcelVO> excelVOList, BindingResult bindingResult);
|
||||
|
||||
R registerAppUser(AppUserDTO appUser);
|
||||
|
||||
AppUserInfo saveOrUpdateByLoginType(LoginTypeEnum loginType, String userName);
|
||||
R registerAppUser(AppUserDTO appUser);
|
||||
|
||||
}
|
||||
+13
-10
@@ -16,18 +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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+4
-29
@@ -24,7 +24,6 @@ import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.admin.api.constant.UserStateEnum;
|
||||
import com.pig4cloud.pigx.app.api.dto.AppUserDTO;
|
||||
import com.pig4cloud.pigx.app.api.dto.AppUserInfo;
|
||||
import com.pig4cloud.pigx.app.api.entity.AppRole;
|
||||
@@ -160,7 +159,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
AppUserInfo info = new AppUserInfo();
|
||||
info.setAppUser(user);
|
||||
// 设置角色列表 (ID)
|
||||
List<Long> roleIds = appRoleService.findRolesByUserId(user.getUserId()).stream().map(AppRole::getRoleId)
|
||||
List<Long> roleIds = appRoleService.findRolesByUserId(user.getUserId())
|
||||
.stream()
|
||||
.map(AppRole::getRoleId)
|
||||
.collect(Collectors.toList());
|
||||
info.setRoles(ArrayUtil.toArray(roleIds, Long.class));
|
||||
|
||||
@@ -240,7 +241,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
AppUser app = new AppUser();
|
||||
BeanUtils.copyProperties(appUser, app);
|
||||
appUser.setUsername(app.getPhone());
|
||||
appUser.setDelFlag(UserStateEnum.NORMAL.getCode());
|
||||
appUser.setDelFlag(CommonConstants.STATUS_NORMAL);
|
||||
appUser.setPassword(ENCODER.encode(appUser.getPassword()));
|
||||
baseMapper.insert(appUser);
|
||||
return null;
|
||||
@@ -314,30 +315,4 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
this.saveUser(userDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppUserInfo saveOrUpdateByLoginType(LoginTypeEnum loginType, String userName) {
|
||||
// 创建Entity对象
|
||||
AppUser appUser = new AppUser();
|
||||
appUser.setUsername(userName);
|
||||
appUser.setCreateBy(userName);
|
||||
appUser.setUpdateBy(userName);
|
||||
// 根据登陆类型赋值,并执行saveOrUpdate方法
|
||||
switch (loginType) {
|
||||
case APPSMS:
|
||||
appUser.setPhone(userName);
|
||||
this.saveOrUpdate(appUser, Wrappers.<AppUser>lambdaQuery().eq(AppUser::getPhone, userName));
|
||||
break;
|
||||
case MINI_APP:
|
||||
appUser.setWxOpenid(userName);
|
||||
this.saveOrUpdate(appUser, Wrappers.<AppUser>lambdaQuery().eq(AppUser::getUsername, userName));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// 返回封装DTO
|
||||
AppUserInfo appUserDTO = new AppUserInfo();
|
||||
appUserDTO.setAppUser(appUser);
|
||||
return appUserDTO;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,11 +18,11 @@
|
||||
|
||||
<properties>
|
||||
<pigx.version>5.6.0</pigx.version>
|
||||
<mybatis-plus.version>3.5.7</mybatis-plus.version>
|
||||
<mybatis-plus-join.version>1.4.13</mybatis-plus-join.version>
|
||||
<mybatis-plus.version>3.5.9</mybatis-plus.version>
|
||||
<mybatis-plus-join.version>1.5.2</mybatis-plus-join.version>
|
||||
<dynamic-ds.version>4.3.1</dynamic-ds.version>
|
||||
<druid.version>1.2.20</druid.version>
|
||||
<hutool.version>5.8.31</hutool.version>
|
||||
<hutool.version>5.8.33</hutool.version>
|
||||
<mysql.connector.version>8.0.33</mysql.connector.version>
|
||||
<oracle.version>21.3.0.0</oracle.version>
|
||||
<sqlserver.version>8.4.1.jre8</sqlserver.version>
|
||||
@@ -216,18 +216,6 @@
|
||||
<artifactId>seata-serializer-kryo</artifactId>
|
||||
<version>${seata.version}</version>
|
||||
</dependency>
|
||||
<!--mybatis plus extension,包含了mybatis plus core-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-extension</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<!--mybatis-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
|
||||
@@ -498,6 +486,14 @@
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!--mybatis plus extension,包含了mybatis plus core-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-bom</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!--hutool bom-->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
|
||||
@@ -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>
|
||||
|
||||
+26
-23
@@ -16,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);
|
||||
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
@@ -57,8 +57,7 @@
|
||||
<jaxb.version>2.3.5</jaxb.version>
|
||||
<jimu.version>1.6.5</jimu.version>
|
||||
<aws.version>1.12.261</aws.version>
|
||||
<ureport.version>2.2.9</ureport.version>
|
||||
<xxl.job.version>2.4.0</xxl.job.version>
|
||||
<xxl.job.version>2.4.2</xxl.job.version>
|
||||
<flowable.version>6.8.0</flowable.version>
|
||||
<docker.registry>172.17.0.111</docker.registry>
|
||||
<docker.host>http://172.17.0.111:2375</docker.host>
|
||||
|
||||
Reference in new issue
Block a user