LambdaQueryWrapper<Table> wrapper = new LambdaQueryWrapper<>();
String finalName = name;
String finalOrgCodeLast = orgCodeLast;
// 1.根据更新时间降序
// 2.如果业务类别不为空(前提),根据业务类别查询
// 3.如果协同状态为9(前提),则协同状态条件不生效
// 4.查询类型等于2(前提)查询发送列表(系统标识为fs)
// 5.查询类型不等于2(前提)查询发送列表(系统标识不为fs)
// 6.如果名称不为空(前提)根据名称模糊查询
// 7.如果组织机构代码不为空(前提),根据组织机构代码右模糊查询发送单位代码或者接受单位代码
// 8.若果登录人的名字不为空(前提),登录人如果是移送人或者是案件的主办人(在这些案件中)
wrapper.orderByDesc(Table::getUpdateTime)
.eq(StringUtils.isNotBlank(searchDto.getYwlb()), Table::getYwlb, searchDto.getYwlb())
.eq(searchDto.getXtStatus() != 9, Table::getXtStatus, searchDto.getXtStatus())
.eq(searchDto.getQueryType() == 2, Table::getXtbs, "fs")
.ne(searchDto.getQueryType() == 1, Table::getXtbs, "fs")
.like(StringUtils.isNotBlank(searchDto.getMc()), Table::getMc, searchDto.getMc())
.and(StringUtils.isNotBlank(finalOrgCodeLast),con -> con.likeRight(Table::getFsdwbh, finalOrgCodeLast).or().likeRight(Table::getJsdwbh, finalOrgCodeLast))
.and(StringUtils.isNotBlank(finalName), con -> con.eq(Table::getYsr, finalName).or(!CollectionUtils.isEmpty(ajbhSet)).in(Table::getPttyah, ajbhSet));
2、对应的MyBatis代码
<!-- 列表查询 -->
<select id="queryXtlb" parameterType="com.dsp.entity.dto.SearchDto" resultType="com.dsp.entity.vo.SearchVO">
select
id , YWLB as ywlb, JSDWMC as jsdwmc, FSDWMC as fsdwmc, YSR as ysr,
update_time as updateTime, xt_status as xtStatus,MC as mc, XTBS as xtbs
from table
<where>
<!-- 系统标识(fs为发送列表) -->
<if test="searchDto.queryType == 2">
and XTBS = 'fs'
</if>
<if test="searchDto.queryType == 1">
and XTBS != 'fs'
</if>
<!-- 流程 -->
<if test="searchDto.ywlb != null and searchDto.ywlb != ''">
and YWLB = #{searchDto.ywlb}
</if>
<!-- 案件名称 -->
<if test="searchDto.mc != null and searchDto.mc != ''">
and MC like CONCAT('%',#{searchDto.mc},'%')
</if>
<!-- 协同状态 -->
<if test="searchDto.xtStatus != 9">
and xt_status = #{searchDto.xtStatus}
</if>
<!-- 发送、接收单位编号,右模糊查询:根据角色权限截取包含前面几位的-->
<if test="searchDto.orgCode != null and searchDto.orgCode != ''">
and (
FSDWBH like CONCAT(#{searchDto.orgCode},'%')
or
JSDWBH like CONCAT(#{searchDto.orgCode},'%')
)
</if>
<!-- 移送人、案件主协办人 -->
<if test="searchDto.ysr != null and searchDto.ysr != '' and searchDto.ajbhList != null">
and (
YSR = #{searchDto.ysr}
or
PTTYAH in
<foreach collection="searchDto.ajbhList" item="ajbh" index="index" open="(" close=")" separator=",">
#{ajbh}
</foreach>
)
</if>
</where>
order by update_time desc
</select>