Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(choasblade-box): sql兼容mysql8.0 #137

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ public interface ApplicationDeviceMapper extends BaseMapper<ApplicationDeviceDO>


@Select("<script>" +
"select tmp.* from ( " +
"select tmp.* from (" +
"SELECT t.* FROM t_chaos_application_device t where t.id in ( " +
"select " +
"ad.* " +
"max(ad.id) " +
"from t_chaos_application_device ad WHERE 1=1 " +
"<if test='null != query.appId and query.appId != \"\" '>" +
"AND ad.app_id = #{query.appId} " +
Expand Down Expand Up @@ -55,7 +56,7 @@ public interface ApplicationDeviceMapper extends BaseMapper<ApplicationDeviceDO>
")" +
"</if>" +
"group by ad.private_ip " +
") tmp " +
")) tmp " +
"ORDER BY tmp.gmt_create DESC" +
"</script>")
IPage<ApplicationDeviceDO> selectPageByTagsForHost(IPage<ApplicationDeviceDO> page, @Param("query") ApplicationDeviceQuery query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

/**
* @author haibin
Expand Down Expand Up @@ -354,6 +354,7 @@ public ApplicationDeviceDO findByConfigurationId(String configurationIds) {

public List<ApplicationDeviceDO> findUserDeviceGroupByAppId(String userId,List<Long> appIds) {
QueryWrapper<ApplicationDeviceDO> queryWrapper = new QueryWrapper<>();
queryWrapper.select("max(id) id");
queryWrapper.eq("status", DeviceStatus.ONLINE.getStatus());
queryWrapper.eq("is_deleted", 0);
if (CollectionUtil.isNullOrEmpty(appIds)) {
Expand All @@ -362,7 +363,19 @@ public List<ApplicationDeviceDO> findUserDeviceGroupByAppId(String userId,List<L
queryWrapper.and(wrapper -> wrapper.eq("user_id", userId).or().in("app_id", appIds));
}
queryWrapper.groupBy("app_id");
return applicationDeviceMapper.selectList(queryWrapper);
List<ApplicationDeviceDO> applicationDeviceIdList = applicationDeviceMapper.selectList(queryWrapper);
if (CollectionUtil.isNullOrEmpty(applicationDeviceIdList)) {
return Lists.newArrayList();
}
return applicationDeviceMapper.selectList(
new QueryWrapper<ApplicationDeviceDO>()
.lambda()
.in(ApplicationDeviceDO::getId,
applicationDeviceIdList
.stream()
.map(ApplicationDeviceDO::getId)
.filter(Objects::nonNull)
.collect(Collectors.toList())));
}

public List<ApplicationDeviceDO> findByClusterId(String user_id, String clusterId, boolean online) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* @author sunju
Expand Down Expand Up @@ -157,13 +158,16 @@ public PageableResponse<SceneAuthorizedDO> getAuthorizedRecords(
}

public List<SceneAuthorizedDO> getAuthorizedRecordsGroupBy(SceneAuthorizedQueryRequest query) {
return sceneAuthorizedMapper.selectList(buildQueryWrapper(query)
.groupBy(
"function_id"
)
.orderByDesc(
"function_create_time"
));
List<SceneAuthorizedDO> sceneAuthorizedDoList = sceneAuthorizedMapper.selectList(buildQueryWrapper(query)
.select("max(id) id")
.groupBy(
"function_id"
));
if (CollectionUtil.isNullOrEmpty(sceneAuthorizedDoList)) {
return Lists.newArrayList();
}
List<Long> collect = sceneAuthorizedDoList.stream().map(SceneAuthorizedDO::getId).filter(Objects::nonNull).collect(Collectors.toList());
return sceneAuthorizedMapper.selectList(new QueryWrapper<SceneAuthorizedDO>().lambda().in(SceneAuthorizedDO::getId, collect));
}

private QueryWrapper<SceneAuthorizedDO> buildQueryWrapper(
Expand Down