高效率条件构造器 mybatisplus

当查询条件很多时条件构造器可以让你不用写那么多Service查询条件

根据条件构造器查询总条数

    @Override
    public Integer getFundFlowCount(FundFlowReq req) throws KeynesException {
        if (null == req) {
            throw new KeynesException(KeynesExceptionEnum.MISSING_PARAMS);
        }
        Wrapper<FundFlow> wrapper = this.buildConditions(req);
        Integer count;
        try {
            count = fundFlowMapper.selectCount(wrapper);
        } catch (Exception e){
            throw new KeynesException(KeynesExceptionEnum.QUERY_FAILED);
        }
        return count;
    }

条件构造器


    private Wrapper<FundFlow> buildConditions(FundFlowReq req) {
        Wrapper<FundFlow> wrapper = new EntityWrapper<>();
        if (StringUtils.isNotBlank(req.getFlowCode())) {
            wrapper.eq("flow_code", req.getFlowCode());
        }
        if (req.getStatus()!=null) {
            wrapper.eq("status", req.getStatus());
        }
        if (StringUtils.isNotBlank(req.getFundProCode())) {
            wrapper.eq("fund_pro_code", req.getFundProCode());
        }
        if (StringUtils.isNotBlank(req.getOidFundno())) {
            wrapper.eq("oid_fundno", req.getOidFundno());
        }
        if (StringUtils.isNotBlank(req.getUserType())) {
            wrapper.eq("user_type", req.getUserType());
        }
        return wrapper;
    }

根据总条数和条件构造器分页查询

    @Override
    public List<FundFlowVO> getFundFlowList(FundFlowReq req) throws KeynesException {
        if (null == req) {
            throw new KeynesException(KeynesExceptionEnum.MISSING_PARAMS);
        }
        //构造分页对象
        Page page = new Page(req.getCurrPage(), req.getPageSize());
        Wrapper<FundFlow> wrapper = this.buildConditions(req);
        List<FundFlowVO> list;
        try {
            List<FundFlow> fundList = fundFlowMapper.selectPage(page, wrapper);
            list = zDozerBeanUtil.convertList(fundList, FundFlowVO.class);
        } catch (Exception e) {
            //数据查询失败
            throw new KeynesException(KeynesExceptionEnum.QUERY_FAILED);
        }
        return list;
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值