use of com.baomidou.mybatisplus.core.conditions.Wrapper in project doorkeeper by limbo-world.
the class GroupRoleService method batchUpdate.
@Transactional
public void batchUpdate(Long groupId, GroupRoleBatchUpdateParam param) {
switch(param.getType()) {
case // 新增
SAVE:
if (CollectionUtils.isEmpty(param.getRoles())) {
return;
}
List<GroupRolePO> addGroupRoles = new ArrayList<>();
for (GroupRoleAddParam role : param.getRoles()) {
GroupRolePO groupRole = new GroupRolePO();
groupRole.setGroupId(groupId);
groupRole.setRoleId(role.getRoleId());
groupRole.setIsExtend(role.getIsExtend());
addGroupRoles.add(groupRole);
}
groupRoleMapper.batchInsertIgnore(addGroupRoles);
break;
case // 删除
DELETE:
if (CollectionUtils.isEmpty(param.getRoleIds())) {
return;
}
groupRoleMapper.delete(Wrappers.<GroupRolePO>lambdaQuery().eq(GroupRolePO::getGroupId, groupId).in(GroupRolePO::getRoleId, param.getRoleIds()));
break;
case // 更新
UPDATE:
if (CollectionUtils.isEmpty(param.getRoles())) {
return;
}
List<Wrapper<GroupRolePO>> updateWrappers = new ArrayList<>();
for (GroupRoleAddParam role : param.getRoles()) {
updateWrappers.add(Wrappers.<GroupRolePO>lambdaUpdate().set(GroupRolePO::getIsExtend, role.getIsExtend()).eq(GroupRolePO::getGroupId, groupId).eq(GroupRolePO::getRoleId, role.getRoleId()));
}
MyBatisPlusUtils.batchUpdate(updateWrappers, GroupRolePO.class);
break;
default:
break;
}
}
use of com.baomidou.mybatisplus.core.conditions.Wrapper in project dynamic-threadpool by acmenlt.
the class UserServiceImpl method getUser.
@Override
public UserRespDTO getUser(UserReqDTO reqDTO) {
Wrapper queryWrapper = Wrappers.lambdaQuery(UserInfo.class).eq(UserInfo::getUserName, reqDTO.getUserName());
UserInfo userInfo = userMapper.selectOne(queryWrapper);
UserRespDTO respUser = Optional.ofNullable(userInfo).map(each -> BeanUtil.toBean(each, UserRespDTO.class)).orElseThrow(() -> new ServiceException("查询无此用户, 可以尝试清空缓存或退出登录."));
return respUser;
}
use of com.baomidou.mybatisplus.core.conditions.Wrapper in project chao-cloud by chaojunzi.
the class MybatisUtil method buildSql.
/**
* 根据wrapper生成sql 如:a=1 and b=2
*
* @param <T> 实体类型
* @param wrapper 条件
* @param beanClass bean类型
* @return sql条件
*/
static <T> String buildSql(LambdaQueryWrapper<T> wrapper, Class<T> beanClass) {
// 判断bean是否加载
TableInfo info = FunctionUtil.buildTableInfo(beanClass);
Assert.notNull(info, "无效的数据实体 beanClass={}", beanClass.getName());
String targetSql = wrapper.getTargetSql();
if (StrUtil.isBlank(targetSql)) {
return null;
}
int count = StrUtil.count(targetSql, MybatisConstant.ASK);
Map<String, Object> valuePairs = wrapper.getParamNameValuePairs();
Object[] vals = //
IntStream.range(1, count + 1).mapToObj(i -> {
Object obj = valuePairs.get("MPGENVAL" + i);
if (obj instanceof Date) {
obj = DateUtil.formatDateTime((Date) obj);
}
return obj;
}).toArray();
// 去掉首尾括号
return StrUtil.format(StrUtil.replace(targetSql, MybatisConstant.ASK, "'{}'"), vals);
}
use of com.baomidou.mybatisplus.core.conditions.Wrapper in project diboot by dibo-software.
the class ProtectInterceptor method intercept.
@Override
public Object intercept(Invocation invocation) throws Throwable {
Object[] args = invocation.getArgs();
if (args.length > 1) {
MappedStatement mappedStatement = (MappedStatement) args[0];
SqlCommandType sqlType = mappedStatement.getSqlCommandType();
if (SqlCommandType.INSERT == sqlType || SqlCommandType.UPDATE == sqlType) {
Object entity = args[1];
Configuration config = mappedStatement.getConfiguration();
if (entity instanceof Map) {
Set<Integer> set = new HashSet<>();
for (Map.Entry<?, ?> entry : ((Map<?, ?>) entity).entrySet()) {
Object value = entry.getValue();
if (value == null || value instanceof Wrapper || set.contains(value.hashCode())) {
continue;
}
set.add(value.hashCode());
if (value instanceof List) {
for (Object obj : (List<?>) value) {
if (!encryptor(config, obj, IEncryptStrategy::encrypt)) {
break;
}
}
} else {
encryptor(config, value, IEncryptStrategy::encrypt);
}
}
} else {
encryptor(config, entity, IEncryptStrategy::encrypt);
}
}
return invocation.proceed();
} else {
ResultSetHandler resultSetHandler = (ResultSetHandler) invocation.getTarget();
Field field = resultSetHandler.getClass().getDeclaredField("mappedStatement");
field.setAccessible(true);
List<?> list = (List<?>) invocation.proceed();
if (list.isEmpty()) {
return list;
}
Configuration config = ((MappedStatement) field.get(resultSetHandler)).getConfiguration();
for (Object obj : list) {
if (!encryptor(config, obj, IEncryptStrategy::decrypt)) {
break;
}
}
return list;
}
}
use of com.baomidou.mybatisplus.core.conditions.Wrapper in project hippo4j by longtai-cn.
the class UserServiceImpl method getUser.
@Override
public UserRespDTO getUser(UserReqDTO reqDTO) {
Wrapper queryWrapper = Wrappers.lambdaQuery(UserInfo.class).eq(UserInfo::getUserName, reqDTO.getUserName());
UserInfo userInfo = userMapper.selectOne(queryWrapper);
UserRespDTO respUser = Optional.ofNullable(userInfo).map(each -> BeanUtil.toBean(each, UserRespDTO.class)).orElseThrow(() -> new ServiceException("查询无此用户, 可以尝试清空缓存或退出登录."));
return respUser;
}
Aggregations