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

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

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