代码示例:
Page<Handling> finPage(@Param("page") Page<Handling> page,@Param(Constants.WRAPPER) QueryWrapper<Handling> qw);
<select id="finPage" resultType="com.zw.zwzc.module.business.entity.Handling"> select * from ( SELECT a.*, b.user_name, c.area_code, c.dept_name, d.implement_name, d.event_type, ap.applicant_name, ha.handler_name, if(a.applicant_id is null, "N", "Y") is_to_do FROM handling a LEFT JOIN sys_user b ON b.user_id = a.user_id LEFT JOIN sys_dept c ON c.dept_id = b.dept_id left join event_implementation d on d.event_id = a.event_id left join applicant ap on ap.applicant_id = a.applicant_id left join handler ha on ha.handler_id = a.handler_id ) tab ${ew.customSqlSegment} </select>
条件设置:
@Override public Page<Handling> findPage(Page<Handling> page, Handling en) throws Exception { QueryWrapper<Handling> qw = new QueryWrapper<>(); //区分代办查询和已办查询(如果不传状态 默认查询代办[去除办理成功数据]) if (StrUtil.isNotEmpty(en.getState())) { qw.eq("tab.state", en.getAreaCode()); }else { qw.ne("tab.state", CommonConstant.SUCCESS); } // 办件查询添加环节筛选需求 if (StrUtil.isNotEmpty(en.getBusinessTacheId())) { qw.eq("tab.business_tache_id", en.getBusinessTacheId()); } if (StrUtil.isNotEmpty(en.getAreaCode())) { qw.eq("tab.area_code", en.getAreaCode()); } if (StrUtil.isNotEmpty(en.getUserName())) { qw.eq("tab.user_name", en.getUserName()); } if (StrUtil.isNotEmpty(en.getDeptName())) { qw.eq("tab.dept_name", en.getDeptName()); } if (StrUtil.isNotEmpty(en.getEventType())) { qw.eq("tab.event_type", en.getEventType()); } if (StrUtil.isNotEmpty(en.getSearch())) { qw.like("tab.applicant_name", en.getSearch()).or().like("tab.implement_name", en.getSearch()); } if (en.getStartDate() != null && !en.getStartDate().equals("")) { qw.ge("tab.start_date", en.getStartDate()); } if (en.getEndDate() != null && !en.getEndDate().equals("")) { qw.le("tab.start_date", en.getEndDate()); } if (StringUtils.isNotBlank(en.getIsOneThing())) { qw.eq("tab.is_one_thing", en.getIsOneThing()); } if (StringUtils.isNotBlank(en.getIsTongBan())) { qw.eq("tab.is_tong_ban", en.getIsTongBan()); } Page<Handling> handlingPage = baseMapper.finPage(page, qw); //翻译state字段 dictItemService.setDescByValue(handlingPage.getRecords(),"state","stateName","handling_state"); //添加时限信息 addTimeLimitDesc(handlingPage); return handlingPage; }
可以少在XML里面写条件了