sharp-report中自定义报表

添加依赖

<dependency>
    <groupId>com.rick.report</groupId>
    <artifactId>sharp-report</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

创建表

sys_report.sql

create table sys_report
(
    id bigint not null comment '主键'
        primary key,
    pageable bit null,
    sidx varchar(32) null,
    sord varchar(16) null,
    name varchar(32) null,
    query_sql text not null,
    summary bit default b'0' null,
    report_column_list text null,
    query_field_list text null,
    created_by bigint null,
    created_at datetime null,
    updated_by bigint null,
    updated_at datetime null,
    is_deleted bit null
)
    comment '报表';

或者通过

tableGenerator.createTable(Report.class);

创建report

@Test
public void test0() {
   reportService.saveOrUpdate(Report.builder()
           .id(619541501440958464L)
           .name("图书报表")
           .querySql("SELECT t_book.id, t_book.title, t_person.name, sys_dict.label \"sexLabel\"\n" +
                   "FROM t_book,\n" +
                   "     t_person LEFT JOIN sys_dict on t_person.sex = sys_dict.name AND type = 'sex'\n" +
                   "WHERE t_book.person_id = t_person.id\n" +
                   "  AND t_book.title LIKE :title\n" +
                   "  AND t_person.name = :name\n" +
                   "  AND t_person.sex = :sex")
           .reportColumnList(Arrays.asList(
                   new ReportColumn("title", "书名", true),
                   new ReportColumn("name", "作者", true),
                   new ReportColumn("sexLabel", "性别")
           ))
           .queryFieldList(Arrays.asList(
                   new QueryField("title", "书名"),
                   new QueryField("name", "作者"),
                   new QueryField("sex", "性别", QueryField.Type.SELECT, "sex")
           ))
           .pageable(true)
           .summary(false)
           .sidx("title")
           .sord(SordEnum.ASC)
           .build());
}

查看页面

http://localhost:8080/reports/619541501440958464

http://xhope.top/wp-content/uploads/2022/11/report.png