1、MyBatis-Plus 之LambdaQueryWrapper 实现eq/ne/and/or/in/like/RightLike/orderby +条件判断查询

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>

 

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值