blinkfox / fenix

This is an extension library to the Spring Data JPA complex or dynamic SQL query. 这是一个比 MyBatis 更加强大的 Spring Data JPA 扩展库,为解决复杂动态 JPQL (或 SQL) 而生。https://blinkfox.github.io/fenix
https://blinkfox.github.io/fenix
Apache License 2.0
346 stars 72 forks source link

不支持union关键字 #51

Closed yidasanqian closed 2 years ago

yidasanqian commented 3 years ago

unexpected token: UNION

provider:

Fenix.start()
                    .select("t1.orgName as orgName, t1.orgType as orgType, t3.mchName as mchName")
                    .from("OrgInfo").as("t1")
                    .leftJoin("OrgHospital").as("t2")
                    .on("t1.orgId = t2.hospitalId")
                    .leftJoin("Mch").as("t3")
                    .on("t2.mchId = t3.mchId")
                    .whereDynamic()
                    .andLike("t3.mchName", params.getMchName(), StringUtils.hasText(params.getMchName()))
                    .andLike("t1.orgName", params.getOrgName(), StringUtils.hasText(params.getOrgName()))
                    .andEqual("t1.orgType", params.getOrgType(), Objects.nonNull(params.getOrgType()))
                    .andEqual("t1.status", params.getStatus(), Objects.nonNull(params.getStatus()))
                    .between("t1.createDt", params.getStart(), params.getEnd(), params.getStart() != null && params.getEnd() != null)
                    .union()
                    .select("t1.orgName as orgName, t1.orgType as orgType, t3.mchName as mchName")
                    .from("OrgInfo").as("t1")
                    .leftJoin("OrgDrugstore").as("t2")
                    .on("t1.orgId = t2.storeId")
                    .leftJoin("Mch").as("t3")
                    .on("t2.mchId = t3.mchId")
                    .whereDynamic()
                    .andLike("t3.mchName", params.getMchName(), StringUtils.hasText(params.getMchName()))
                    .andLike("t1.orgName", params.getOrgName(), StringUtils.hasText(params.getOrgName()))
                    .andEqual("t1.orgType", params.getOrgType(), Objects.nonNull(params.getOrgType()))
                    .andEqual("t1.status", params.getStatus(), Objects.nonNull(params.getStatus()))
                    .between("t1.createDt", params.getStart(), params.getEnd(), params.getStart() != null && params.getEnd() != null)
                    .end()
                    .setResultTypeClass(OrgInfoVo.class);
blinkfox commented 2 years ago

@yidasanqian 这个 SQL 点复杂,你得看看生成的 SQL 结果字符串是长啥样的,比较长的 SQL 一般都建议写到 XML 里面的,不然,后续不好维护。

blinkfox commented 2 years ago

长久未回复,将关闭此 issue