集成 Go-View 大屏设计器
parent
c3f95aa9ee
commit
1b6124a0db
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@
|
||||
package cn.iocoder.yudao.module.report.controller.admin.ajreport;
|
||||
@ -0,0 +1,77 @@
|
||||
package cn.iocoder.yudao.module.report.controller.admin.goview;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.report.controller.admin.goview.vo.project.GoViewProjectCreateReqVO;
|
||||
import cn.iocoder.yudao.module.report.controller.admin.goview.vo.project.GoViewProjectRespVO;
|
||||
import cn.iocoder.yudao.module.report.controller.admin.goview.vo.project.GoViewProjectUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.report.convert.goview.GoViewProjectConvert;
|
||||
import cn.iocoder.yudao.module.report.dal.dataobject.goview.GoViewProjectDO;
|
||||
import cn.iocoder.yudao.module.report.service.goview.GoViewProjectService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
@Tag(name = "管理后台 - GoView 项目")
|
||||
@RestController
|
||||
@RequestMapping("/report/go-view/project")
|
||||
@Validated
|
||||
public class GoViewProjectController {
|
||||
|
||||
@Resource
|
||||
private GoViewProjectService goViewProjectService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建项目")
|
||||
@PreAuthorize("@ss.hasPermission('report:go-view-project:create')")
|
||||
public CommonResult<Long> createProject(@Valid @RequestBody GoViewProjectCreateReqVO createReqVO) {
|
||||
return success(goViewProjectService.createProject(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新项目")
|
||||
@PreAuthorize("@ss.hasPermission('report:go-view-project:update')")
|
||||
public CommonResult<Boolean> updateProject(@Valid @RequestBody GoViewProjectUpdateReqVO updateReqVO) {
|
||||
goViewProjectService.updateProject(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除 GoView 项目")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('report:go-view-project:delete')")
|
||||
public CommonResult<Boolean> deleteProject(@RequestParam("id") Long id) {
|
||||
goViewProjectService.deleteProject(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得项目")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('report:go-view-project:query')")
|
||||
public CommonResult<GoViewProjectRespVO> getProject(@RequestParam("id") Long id) {
|
||||
GoViewProjectDO project = goViewProjectService.getProject(id);
|
||||
return success(GoViewProjectConvert.INSTANCE.convert(project));
|
||||
}
|
||||
|
||||
@GetMapping("/my-page")
|
||||
@Operation(summary = "获得我的项目分页")
|
||||
@PreAuthorize("@ss.hasPermission('report:go-view-project:query')")
|
||||
public CommonResult<PageResult<GoViewProjectRespVO>> getMyProjectPage(@Valid PageParam pageVO) {
|
||||
PageResult<GoViewProjectDO> pageResult = goViewProjectService.getMyProjectPage(
|
||||
pageVO, getLoginUserId());
|
||||
return success(GoViewProjectConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package cn.iocoder.yudao.module.report.controller.admin.goview.vo.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
@Schema(description = "管理后台 - GoView 使用 SQL 查询数据 Request VO")
|
||||
@Data
|
||||
public class GoViewDataGetBySqlReqVO {
|
||||
|
||||
@Schema(description = "SQL 语句", required = true, example = "SELECT * FROM user")
|
||||
@NotEmpty(message = "SQL 语句不能为空")
|
||||
private String sql;
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package cn.iocoder.yudao.module.report.controller.admin.goview.vo.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Schema(description = "管理后台 - GoView 数据 Response VO")
|
||||
@Data
|
||||
public class GoViewDataRespVO {
|
||||
|
||||
@Schema(description = "数据维度", required = true, example = "['product', 'data1', 'data2']")
|
||||
private List<String> dimensions;
|
||||
|
||||
@Schema(description = "数据明细列表", required = true)
|
||||
private List<Map<String, Object>> source;
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package cn.iocoder.yudao.module.report.controller.admin.goview.vo.project;
|
||||
|
||||
import lombok.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - GoView 项目创建 Request VO")
|
||||
@Data
|
||||
public class GoViewProjectCreateReqVO {
|
||||
|
||||
@Schema(description = "项目名称", required = true, example = "王五")
|
||||
@NotEmpty(message = "项目名称不能为空")
|
||||
private String name;
|
||||
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package cn.iocoder.yudao.module.report.controller.admin.goview.vo.project;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - GoView 项目 Response VO")
|
||||
@Data
|
||||
public class GoViewProjectRespVO {
|
||||
|
||||
@Schema(description = "编号", required = true, example = "18993")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "项目名称", required = true, example = "王五")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "发布状态", required = true, example = "1")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "报表内容") // JSON 格式
|
||||
private String content;
|
||||
|
||||
@Schema(description = "预览图片 URL", example = "https://www.iocoder.cn")
|
||||
private String picUrl;
|
||||
|
||||
@Schema(description = "项目备注", example = "你猜")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "创建人编号", required = true, example = "1024")
|
||||
private String creator;
|
||||
|
||||
@Schema(description = "创建时间", required = true)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package cn.iocoder.yudao.module.report.controller.admin.goview.vo.project;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - GoView 项目更新 Request VO")
|
||||
@Data
|
||||
public class GoViewProjectUpdateReqVO {
|
||||
|
||||
@Schema(description = "编号", required = true, example = "18993")
|
||||
@NotNull(message = "编号不能为空")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "项目名称", required = true, example = "王五")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "发布状态", required = true, example = "1")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "发布状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "报表内容") // JSON 格式
|
||||
private String content;
|
||||
|
||||
@Schema(description = "预览图片 URL", example = "https://www.iocoder.cn")
|
||||
private String picUrl;
|
||||
|
||||
@Schema(description = "项目备注", example = "你猜")
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package cn.iocoder.yudao.module.report.convert.goview;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.report.controller.admin.goview.vo.project.GoViewProjectCreateReqVO;
|
||||
import cn.iocoder.yudao.module.report.controller.admin.goview.vo.project.GoViewProjectRespVO;
|
||||
import cn.iocoder.yudao.module.report.controller.admin.goview.vo.project.GoViewProjectUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.report.dal.dataobject.goview.GoViewProjectDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface GoViewProjectConvert {
|
||||
|
||||
GoViewProjectConvert INSTANCE = Mappers.getMapper(GoViewProjectConvert.class);
|
||||
|
||||
GoViewProjectDO convert(GoViewProjectCreateReqVO bean);
|
||||
|
||||
GoViewProjectDO convert(GoViewProjectUpdateReqVO bean);
|
||||
|
||||
GoViewProjectRespVO convert(GoViewProjectDO bean);
|
||||
|
||||
PageResult<GoViewProjectRespVO> convertPage(PageResult<GoViewProjectDO> page);
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package cn.iocoder.yudao.module.report.dal.mysql.goview;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.report.dal.dataobject.goview.GoViewProjectDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface GoViewProjectMapper extends BaseMapperX<GoViewProjectDO> {
|
||||
|
||||
default PageResult<GoViewProjectDO> selectPage(PageParam reqVO, Long userId) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<GoViewProjectDO>()
|
||||
.eq(GoViewProjectDO::getCreator, userId)
|
||||
.orderByDesc(GoViewProjectDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
4
yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/jmreport/config/JmReportConfiguration.java → yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/jmreport/config/JmReportConfiguration.java
4
yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/jmreport/config/JmReportConfiguration.java → yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/jmreport/config/JmReportConfiguration.java
@ -1,8 +1,8 @@
|
||||
package cn.iocoder.yudao.module.visualization.framework.jmreport.config;
|
||||
package cn.iocoder.yudao.module.report.framework.jmreport.config;
|
||||
|
||||
import cn.iocoder.yudao.framework.security.config.SecurityProperties;
|
||||
import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi;
|
||||
import cn.iocoder.yudao.module.visualization.framework.jmreport.core.service.JmReportTokenServiceImpl;
|
||||
import cn.iocoder.yudao.module.report.framework.jmreport.core.service.JmReportTokenServiceImpl;
|
||||
import org.jeecg.modules.jmreport.api.JmReportTokenServiceI;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
2
yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/jmreport/core/service/JmReportTokenServiceImpl.java → yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/jmreport/core/service/JmReportTokenServiceImpl.java
2
yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/jmreport/core/service/JmReportTokenServiceImpl.java → yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/jmreport/core/service/JmReportTokenServiceImpl.java
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.module.visualization.framework.jmreport.core.service;
|
||||
package cn.iocoder.yudao.module.report.framework.jmreport.core.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 属于 report 模块的 framework 封装
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
package cn.iocoder.yudao.module.report.framework;
|
||||
8
yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/security/config/SecurityConfiguration.java → yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/SecurityConfiguration.java
8
yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/security/config/SecurityConfiguration.java → yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/SecurityConfiguration.java
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* 占位
|
||||
*/
|
||||
package cn.iocoder.yudao.module.report.framework.security.core;
|
||||
@ -0,0 +1,20 @@
|
||||
package cn.iocoder.yudao.module.report.service.goview;
|
||||
|
||||
import cn.iocoder.yudao.module.report.controller.admin.goview.vo.data.GoViewDataRespVO;
|
||||
|
||||
/**
|
||||
* GoView 数据 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface GoViewDataService {
|
||||
|
||||
/**
|
||||
* 使用 SQL 查询数据
|
||||
*
|
||||
* @param sql SQL 语句
|
||||
* @return 数据
|
||||
*/
|
||||
GoViewDataRespVO getDataBySQL(String sql);
|
||||
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
package cn.iocoder.yudao.module.report.service.goview;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.report.controller.admin.goview.vo.project.GoViewProjectCreateReqVO;
|
||||
import cn.iocoder.yudao.module.report.controller.admin.goview.vo.project.GoViewProjectUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.report.dal.dataobject.goview.GoViewProjectDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* GoView 项目 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface GoViewProjectService {
|
||||
|
||||
/**
|
||||
* 创建项目
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createProject(@Valid GoViewProjectCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新项目
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateProject(@Valid GoViewProjectUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除项目
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteProject(Long id);
|
||||
|
||||
/**
|
||||
* 获得项目
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 项目
|
||||
*/
|
||||
GoViewProjectDO getProject(Long id);
|
||||
|
||||
/**
|
||||
* 获得我的项目分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @param userId 用户编号
|
||||
* @return GoView 项目分页
|
||||
*/
|
||||
PageResult<GoViewProjectDO> getMyProjectPage(PageParam pageReqVO, Long userId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
package cn.iocoder.yudao.module.report.service.goview;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.report.controller.admin.goview.vo.project.GoViewProjectCreateReqVO;
|
||||
import cn.iocoder.yudao.module.report.controller.admin.goview.vo.project.GoViewProjectUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.report.convert.goview.GoViewProjectConvert;
|
||||
import cn.iocoder.yudao.module.report.dal.dataobject.goview.GoViewProjectDO;
|
||||
import cn.iocoder.yudao.module.report.dal.mysql.goview.GoViewProjectMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.GO_VIEW_PROJECT_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* GoView 项目 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class GoViewProjectServiceImpl implements GoViewProjectService {
|
||||
|
||||
@Resource
|
||||
private GoViewProjectMapper goViewProjectMapper;
|
||||
|
||||
@Override
|
||||
public Long createProject(GoViewProjectCreateReqVO createReqVO) {
|
||||
// 插入
|
||||
GoViewProjectDO goViewProject = GoViewProjectConvert.INSTANCE.convert(createReqVO)
|
||||
.setStatus(CommonStatusEnum.DISABLE.getStatus());
|
||||
goViewProjectMapper.insert(goViewProject);
|
||||
// 返回
|
||||
return goViewProject.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProject(GoViewProjectUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateProjectExists(updateReqVO.getId());
|
||||
// 更新
|
||||
GoViewProjectDO updateObj = GoViewProjectConvert.INSTANCE.convert(updateReqVO);
|
||||
goViewProjectMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteProject(Long id) {
|
||||
// 校验存在
|
||||
validateProjectExists(id);
|
||||
// 删除
|
||||
goViewProjectMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateProjectExists(Long id) {
|
||||
if (goViewProjectMapper.selectById(id) == null) {
|
||||
throw exception(GO_VIEW_PROJECT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GoViewProjectDO getProject(Long id) {
|
||||
return goViewProjectMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<GoViewProjectDO> getMyProjectPage(PageParam pageReqVO, Long userId) {
|
||||
return goViewProjectMapper.selectPage(pageReqVO, userId);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
package cn.iocoder.yudao.module.report.service.goview;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.report.controller.admin.goview.vo.data.GoViewDataRespVO;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
||||
import org.springframework.jdbc.support.rowset.SqlRowSetMetaData;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@Import(GoViewDataServiceImpl.class)
|
||||
public class GoViewDataServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private GoViewDataServiceImpl goViewDataService;
|
||||
|
||||
@MockBean
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Test
|
||||
public void testGetDataBySQL() {
|
||||
// 准备参数
|
||||
String sql = "SELECT id, name FROM system_users";
|
||||
// mock 方法
|
||||
SqlRowSet sqlRowSet = mock(SqlRowSet.class);
|
||||
when(jdbcTemplate.queryForRowSet(eq(sql))).thenReturn(sqlRowSet);
|
||||
// mock 元数据
|
||||
SqlRowSetMetaData metaData = mock(SqlRowSetMetaData.class);
|
||||
when(sqlRowSet.getMetaData()).thenReturn(metaData);
|
||||
when(metaData.getColumnNames()).thenReturn(new String[]{"id", "name"});
|
||||
// mock 数据明细
|
||||
when(sqlRowSet.next()).thenReturn(true).thenReturn(true).thenReturn(false);
|
||||
when(sqlRowSet.getObject("id")).thenReturn(1L).thenReturn(2L);
|
||||
when(sqlRowSet.getObject("name")).thenReturn("芋道源码").thenReturn("芋道");
|
||||
|
||||
// 调用
|
||||
GoViewDataRespVO dataBySQL = goViewDataService.getDataBySQL(sql);
|
||||
// 断言
|
||||
assertEquals(Arrays.asList("id", "name"), dataBySQL.getDimensions());
|
||||
assertEquals(2, dataBySQL.getDimensions().size());
|
||||
assertEquals(2, dataBySQL.getSource().get(0).size());
|
||||
assertEquals(1L, dataBySQL.getSource().get(0).get("id"));
|
||||
assertEquals("芋道源码", dataBySQL.getSource().get(0).get("name"));
|
||||
assertEquals(2, dataBySQL.getSource().get(1).size());
|
||||
assertEquals(2L, dataBySQL.getSource().get(1).get("id"));
|
||||
assertEquals("芋道", dataBySQL.getSource().get(1).get("name"));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,135 @@
|
||||
package cn.iocoder.yudao.module.report.service.goview;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.report.controller.admin.goview.vo.project.GoViewProjectCreateReqVO;
|
||||
import cn.iocoder.yudao.module.report.controller.admin.goview.vo.project.GoViewProjectUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.report.dal.dataobject.goview.GoViewProjectDO;
|
||||
import cn.iocoder.yudao.module.report.dal.mysql.goview.GoViewProjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.GO_VIEW_PROJECT_NOT_EXISTS;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* {@link GoViewProjectServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Import(GoViewProjectServiceImpl.class)
|
||||
public class GoViewProjectServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private GoViewProjectServiceImpl goViewProjectService;
|
||||
|
||||
@Resource
|
||||
private GoViewProjectMapper goViewProjectMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateProject_success() {
|
||||
// 准备参数
|
||||
GoViewProjectCreateReqVO reqVO = randomPojo(GoViewProjectCreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long goViewProjectId = goViewProjectService.createProject(reqVO);
|
||||
// 断言
|
||||
assertNotNull(goViewProjectId);
|
||||
// 校验记录的属性是否正确
|
||||
GoViewProjectDO goViewProject = goViewProjectMapper.selectById(goViewProjectId);
|
||||
assertPojoEquals(reqVO, goViewProject);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateProject_success() {
|
||||
// mock 数据
|
||||
GoViewProjectDO dbGoViewProject = randomPojo(GoViewProjectDO.class);
|
||||
goViewProjectMapper.insert(dbGoViewProject);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
GoViewProjectUpdateReqVO reqVO = randomPojo(GoViewProjectUpdateReqVO.class, o -> {
|
||||
o.setId(dbGoViewProject.getId()); // 设置更新的 ID
|
||||
o.setStatus(randomCommonStatus());
|
||||
});
|
||||
|
||||
// 调用
|
||||
goViewProjectService.updateProject(reqVO);
|
||||
// 校验是否更新正确
|
||||
GoViewProjectDO goViewProject = goViewProjectMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, goViewProject);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateProject_notExists() {
|
||||
// 准备参数
|
||||
GoViewProjectUpdateReqVO reqVO = randomPojo(GoViewProjectUpdateReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> goViewProjectService.updateProject(reqVO), GO_VIEW_PROJECT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteProject_success() {
|
||||
// mock 数据
|
||||
GoViewProjectDO dbGoViewProject = randomPojo(GoViewProjectDO.class);
|
||||
goViewProjectMapper.insert(dbGoViewProject);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbGoViewProject.getId();
|
||||
|
||||
// 调用
|
||||
goViewProjectService.deleteProject(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(goViewProjectMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteProject_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> goViewProjectService.deleteProject(id), GO_VIEW_PROJECT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProject() {
|
||||
// mock 数据
|
||||
GoViewProjectDO dbGoViewProject = randomPojo(GoViewProjectDO.class);
|
||||
goViewProjectMapper.insert(dbGoViewProject);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbGoViewProject.getId();
|
||||
|
||||
// 调用
|
||||
GoViewProjectDO goViewProject = goViewProjectService.getProject(id);
|
||||
// 断言
|
||||
assertPojoEquals(dbGoViewProject, goViewProject);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMyGoViewProjectPage() {
|
||||
// mock 数据
|
||||
GoViewProjectDO dbGoViewProject = randomPojo(GoViewProjectDO.class, o -> { // 等会查询到
|
||||
o.setCreator("1");
|
||||
});
|
||||
goViewProjectMapper.insert(dbGoViewProject);
|
||||
// 测试 userId 不匹配
|
||||
goViewProjectMapper.insert(cloneIgnoreId(dbGoViewProject, o -> o.setCreator("2")));
|
||||
// 准备参数
|
||||
PageParam reqVO = new PageParam();
|
||||
Long userId = 1L;
|
||||
|
||||
// 调用
|
||||
PageResult<GoViewProjectDO> pageResult = goViewProjectService.getMyProjectPage(reqVO, userId);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbGoViewProject, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
<configuration>
|
||||
<!-- 引用 Spring Boot 的 logback 基础配置 -->
|
||||
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
|
||||
</configuration>
|
||||
@ -0,0 +1 @@
|
||||
DELETE FROM "report_go_view_project";
|
||||
@ -0,0 +1,14 @@
|
||||
CREATE TABLE IF NOT EXISTS "report_go_view_project" (
|
||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"name" varchar NOT NULL,
|
||||
"pic_url" varchar,
|
||||
"content" varchar,
|
||||
"status" varchar NOT NULL,
|
||||
"remark" varchar,
|
||||
"creator" varchar DEFAULT '',
|
||||
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar DEFAULT '',
|
||||
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT 'GoView 项目表';
|
||||
@ -1,6 +0,0 @@
|
||||
/**
|
||||
* 属于 visualization 模块的 framework 封装
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
package cn.iocoder.yudao.module.visualization.framework;
|
||||
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* 占位
|
||||
*/
|
||||
package cn.iocoder.yudao.module.visualization.framework.security.core;
|
||||
@ -0,0 +1,8 @@
|
||||
<template>
|
||||
<ContentWrap>
|
||||
<IFrame :src="src" />
|
||||
</ContentWrap>
|
||||
</template>
|
||||
<script setup lang="ts" name="GoView">
|
||||
const src = 'http://127.0.0.1:3000'
|
||||
</script>
|
||||
@ -0,0 +1,18 @@
|
||||
<template>
|
||||
<div>
|
||||
<doc-alert title="大屏设计器" url="https://doc.iocoder.cn/report/" />
|
||||
<i-frame :src="url" />
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import iFrame from "@/components/iFrame/index";
|
||||
export default {
|
||||
name: "GoView",
|
||||
components: { iFrame },
|
||||
data() {
|
||||
return {
|
||||
url: 'http://127.0.0.1:3000',
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
Loading…
Reference in New Issue