提交 c6b6f944 authored 作者: 吕本才's avatar 吕本才

feat(report): 重构QuickBI报表嵌入ticket查询逻辑

上级 5219fadc
......@@ -8,6 +8,7 @@ import com.sfa.common.core.web.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.security.RolesAllowed;
import java.util.List;
/**
......@@ -38,14 +39,15 @@ public class ExtraReportQuickbiEmbedController extends BaseController {
}
@GetMapping("/{id}")
// @ApiOperation("根据ID查询QuickBI报表嵌入信息")
public R<ExtraReportQuickbiEmbedVo> getById(@PathVariable Long id) {
ExtraReportQuickbiEmbedVo vo = extraReportQuickbiEmbedService.getById(id);
public R<ExtraReportQuickbiEmbedVo> getById(@PathVariable String pageId) {
ExtraReportQuickbiEmbedVo vo = extraReportQuickbiEmbedService.getByPageId(pageId);
return vo != null ? R.ok(vo) : R.fail("记录不存在");
}
@GetMapping("/page/{pageId}")
// @ApiOperation("根据pageId查询QuickBI报表嵌入信息")
@RolesAllowed(value = {"ROLE_ADMIN",})
public R<ExtraReportQuickbiEmbedVo> getByPageId(@PathVariable String pageId) {
ExtraReportQuickbiEmbedVo vo = extraReportQuickbiEmbedService.getByPageId(pageId);
return vo != null ? R.ok(vo) : R.fail("记录不存在");
......@@ -74,7 +76,7 @@ public class ExtraReportQuickbiEmbedController extends BaseController {
* @return accessTicket
*/
@GetMapping("/accessTicket")
public R<ExtraReportQuickbiEmbedVo> queryAccessTicket(Long id) {
return R.ok(extraReportQuickbiEmbedService.queryAccessTicket(id));
public R<ExtraReportQuickbiEmbedVo> queryAccessTicket(String pageId) {
return R.ok(extraReportQuickbiEmbedService.queryAccessTicket(pageId));
}
}
package com.link.report.domain.dao;
import com.link.report.domain.entity.ExtraReportQuickbiEmbed;
import com.link.report.domain.wq.ExtraReportQuickbiEmbedWq;
import java.util.List;
......@@ -11,7 +12,7 @@ public interface ExtraReportQuickbiEmbedDao {
ExtraReportQuickbiEmbed selectById(Long id);
ExtraReportQuickbiEmbed selectByPageId(String pageId);
ExtraReportQuickbiEmbed selectOne(ExtraReportQuickbiEmbedWq pageId);
List<ExtraReportQuickbiEmbed> selectAll();
......
package com.link.report.domain.dao.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.link.report.domain.dao.ExtraReportQuickbiEmbedDao;
import com.link.report.domain.entity.ExtraReportQuickbiEmbed;
import com.link.report.domain.mapper.ExtraReportQuickbiEmbedMapper;
import com.link.report.domain.wq.ExtraReportQuickbiEmbedWq;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
......@@ -55,13 +57,13 @@ public class ExtraReportQuickbiEmbedDaoImpl implements ExtraReportQuickbiEmbedDa
/**
* 根据pageId查询报表嵌入信息
*
* @param pageId QuickBI报表唯一标识ID
* @param extraReportQuickbiEmbedWq QuickBI报表嵌入查询参数
* @return 报表嵌入信息实体
*/
@Override
public ExtraReportQuickbiEmbed selectByPageId(String pageId) {
QueryWrapper<ExtraReportQuickbiEmbed> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("page_id", pageId); // 匹配数据库字段page_id
public ExtraReportQuickbiEmbed selectOne(ExtraReportQuickbiEmbedWq extraReportQuickbiEmbedWq) {
LambdaQueryWrapper<ExtraReportQuickbiEmbed> queryWrapper = new LambdaQueryWrapper<ExtraReportQuickbiEmbed>();
queryWrapper.eq(ObjectUtil.isNotEmpty(extraReportQuickbiEmbedWq.getPageId()), ExtraReportQuickbiEmbed::getPageId, extraReportQuickbiEmbedWq.getPageId());
return extraReportQuickbiEmbedMapper.selectOne(queryWrapper);
}
......
package com.link.report.domain.wq;
import lombok.Data;
/**
* QuickBI报表嵌入信息
*/
@Data
public class ExtraReportQuickbiEmbedWq {
private String pageId;
private Long id;
private String accessTicket;
}
......@@ -71,7 +71,6 @@ public class ExtraReportQuickbiEmbedVo implements Serializable {
public static ExtraReportQuickbiEmbedVo convertEntityToVo(ExtraReportQuickbiEmbed entity) {
ExtraReportQuickbiEmbedVo vo = new ExtraReportQuickbiEmbedVo();
// 设置属性值...
vo.setId(entity.getId());
vo.setName(entity.getName());
vo.setPreviewUrl(entity.getPreviewUrl());
......
......@@ -42,5 +42,5 @@ public interface ExtraReportQuickbiEmbedService extends IService<ExtraReportQuic
*/
boolean deleteById(Long id);
ExtraReportQuickbiEmbedVo queryAccessTicket(Long id);
ExtraReportQuickbiEmbedVo queryAccessTicket(String pageId);
}
......@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.link.report.config.ExtraQuickBiConfig;
import com.link.report.domain.dao.ExtraReportQuickbiEmbedDao;
import com.link.report.domain.entity.ExtraReportQuickbiEmbed;
import com.link.report.domain.wq.ExtraReportQuickbiEmbedWq;
import com.link.report.pojo.request.ExtraReportQuickbiEmbedBo;
import com.link.report.pojo.response.ExtraReportQuickbiEmbedVo;
import com.link.report.service.query.ExtraReportQuickbiEmbedService;
......@@ -34,8 +35,8 @@ import java.util.stream.Collectors;
public class ExtraReportQuickbiEmbedServiceImpl implements ExtraReportQuickbiEmbedService {
@Resource
private final ExtraReportQuickbiEmbedDao extraReportQuickbiEmbedDao;
@Resource
private final ExtraReportQuickbiEmbedDao extraReportQuickbiEmbedDao;
@Resource
private ExtraQuickBiConfig extraQuickBiConfig;
......@@ -93,7 +94,9 @@ public class ExtraReportQuickbiEmbedServiceImpl implements ExtraReportQuickbiEmb
*/
@Override
public ExtraReportQuickbiEmbedVo getByPageId(String pageId) {
ExtraReportQuickbiEmbed entity = extraReportQuickbiEmbedDao.selectByPageId(pageId);
ExtraReportQuickbiEmbedWq extraReportQuickbiEmbedWq = new ExtraReportQuickbiEmbedWq();
extraReportQuickbiEmbedWq.setPageId(pageId);
ExtraReportQuickbiEmbed entity = extraReportQuickbiEmbedDao.selectOne(extraReportQuickbiEmbedWq);
return entity != null ? ExtraReportQuickbiEmbedVo.convertEntityToVo(entity) : null;
}
......@@ -124,11 +127,13 @@ public class ExtraReportQuickbiEmbedServiceImpl implements ExtraReportQuickbiEmb
}
@Override
public ExtraReportQuickbiEmbedVo queryAccessTicket(Long id) {
public ExtraReportQuickbiEmbedVo queryAccessTicket(String pageId) {
// 查询workId
ExtraReportQuickbiEmbed entity = extraReportQuickbiEmbedDao.selectById(id);
ExtraReportQuickbiEmbedWq wq = new ExtraReportQuickbiEmbedWq();
wq.setPageId(pageId);
ExtraReportQuickbiEmbed entity = extraReportQuickbiEmbedDao.selectOne(wq);
if (entity == null) {
log.error("记录不存在,id:{}", id);
log.error("记录不存在, pageId:{}", pageId);
throw new ServiceException("记录不存在");
}
String workId = entity.getPageId();
......@@ -145,6 +150,7 @@ public class ExtraReportQuickbiEmbedServiceImpl implements ExtraReportQuickbiEmb
/**
* 检查accessTicket
* 缓存中不存在则从QuickBI获取accessTicket
*
* @param workId
* @return
*/
......@@ -167,7 +173,7 @@ public class ExtraReportQuickbiEmbedServiceImpl implements ExtraReportQuickbiEmb
JSONObject jsonObject = JSONObject.parseObject(body);
String code = jsonObject.getString("code");
if (ObjectUtil.isEmpty(code) || !code.equals("0")){
if (ObjectUtil.isEmpty(code) || !code.equals("0")) {
throw new ServiceException("获取accessTicket失败");
}
String accessTicketNew = jsonObject.getJSONObject("data").getString("accessTicket");
......@@ -178,8 +184,8 @@ public class ExtraReportQuickbiEmbedServiceImpl implements ExtraReportQuickbiEmb
return accessTicketNew;
}
private String getRedisKey(String workId) {
return "extra:report:quickbi:accessTicket:" + workId ;
private String getRedisKey(String workId) {
return "extra:report:quickbi:accessTicket:" + workId;
}
// 对象转换方法
......@@ -195,7 +201,6 @@ public class ExtraReportQuickbiEmbedServiceImpl implements ExtraReportQuickbiEmb
}
@Override
public boolean saveBatch(Collection<ExtraReportQuickbiEmbed> entityList, int batchSize) {
return false;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论