package top.peng.answerbi.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import top.peng.answerbi.constant.CommonConstant; import top.peng.answerbi.model.dto.chart.ChartQueryRequest; import top.peng.answerbi.model.entity.Chart; import top.peng.answerbi.service.ChartService; import top.peng.answerbi.mapper.ChartMapper; import org.springframework.stereotype.Service; import top.peng.answerbi.utils.SqlUtils; /** * @author yunpeng.zhang * @description 针对表【chart(图表信息表)】的数据库操作Service实现 * @createDate 2023-07-10 16:45:42 */ @Service public class ChartServiceImpl extends ServiceImpl implements ChartService{ /** * 获取查询条件 * * @param chartQueryRequest@return */ @Override public QueryWrapper getQueryWrapper(ChartQueryRequest chartQueryRequest) { QueryWrapper queryWrapper = new QueryWrapper<>(); if (chartQueryRequest == null) { return queryWrapper; } Long id = chartQueryRequest.getId(); String chartName = chartQueryRequest.getChartName(); String goal = chartQueryRequest.getGoal(); String chartType = chartQueryRequest.getChartType(); Long userId = chartQueryRequest.getUserId(); String sortField = chartQueryRequest.getSortField(); String sortOrder = chartQueryRequest.getSortOrder(); queryWrapper.eq(id != null && id > 0, "id", id); queryWrapper.eq(StringUtils.isNotBlank(chartName), "chart_name", goal); queryWrapper.eq(StringUtils.isNotBlank(goal), "goal", goal); queryWrapper.eq(StringUtils.isNotBlank(chartType), "chart_type", chartType); queryWrapper.eq(ObjectUtils.isNotEmpty(userId), "user_id", userId); queryWrapper.eq("deleted_flag", false); queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC), sortField); return queryWrapper; } }