mybatis plus wrapper.orderBy 自定义排序 自定义sql 多字段拼接

@Override
	public List<BuildListVo> getBuildListLike(Long estateId, Long courtId, String buildName) {
		//QueryWrapper  queryWrapper  = new QueryWrapper();
		LambdaQueryWrapper<Build> wrapper = new LambdaQueryWrapper<>();
		if(estateId != null){
			wrapper.eq(Build::getEstateId, estateId);
		}
		if(courtId != null){
			wrapper.eq(Build::getCourtId, courtId);
		}else{
			wrapper.isNull(Build::getCourtId);
		}
		if(StringUtils.isNotBlank(buildName)){
			wrapper.like(Build::getBuildName, buildName);
		}
		wrapper.orderByDesc(Build::getBuildName);
		List<Build> list = baseMapper.selectList(wrapper);
		List<BuildListVo> buildListVoList = new ArrayList<>();
		for(Build build : list){
			BuildListVo buildListVo = new BuildListVo();
			BeanUtils.copyProperties(build,buildListVo);
			if(buildListVo.getEstateId() != null){
				Estate estate = estateMapper.selectById(buildListVo.getEstateId());
				buildListVo.setEstateName(estate.getEstateName());
			}
			if(buildListVo.getCourtId() != null){
				Court court = courtMapper.selectById(buildListVo.getCourtId());
				buildListVo.setCourtName(court.getCourtName());
			}
			buildListVoList.add(buildListVo);
		}

		return buildListVoList;
	}
	@Override
	public List<BuildListVo> getBuildListLike(Long estateId, Long courtId, String buildName) {
		//QueryWrapper  queryWrapper  = new QueryWrapper();
		QueryWrapper<Build> wrapper = new QueryWrapper<>();
		if(estateId != null){
			wrapper.eq("estate_id", estateId);
		}
		if(courtId != null){
			wrapper.eq("court_id", courtId);
		}else{
			wrapper.isNull("court_id");
		}
		if(StringUtils.isNotBlank(buildName)){
			wrapper.like("build_name", buildName);
		}
		wrapper.orderByAsc("CAST(build_name as int)");
		wrapper.orderByAsc("build_name");
		List<Build> list = baseMapper.selectList(wrapper);
		List<BuildListVo> buildListVoList = new ArrayList<>();
		for(Build build : list){
			BuildListVo buildListVo = new BuildListVo();
			BeanUtils.copyProperties(build,buildListVo);
			if(buildListVo.getEstateId() != null){
				Estate estate = estateMapper.selectById(buildListVo.getEstateId());
				buildListVo.setEstateName(estate.getEstateName());
			}
			if(buildListVo.getCourtId() != null){
				Court court = courtMapper.selectById(buildListVo.getCourtId());
				buildListVo.setCourtName(court.getCourtName());
			}
			buildListVoList.add(buildListVo);
		}

		return buildListVoList;
	}
	<select id="getBuildListByCourt" resultType="com.easy.hotel.pms.api.vo.BuildListVo">
		select
		e.estate_id ,
		e.estate_name,
		e.community_code,
		b.build_type,
		b.build_id,
		b.build_name,
		cour.court_id,
		cour.court_name,
		CAST(cour.court_name as int)  as courtIntSort,
		CAST(b.build_name as int) as buildIntSort
		from build b
		left join court cour on b.court_id = cour.court_id
		inner join estate e on b.estate_id = e.estate_id
		<where>
			and b.estate_id = #{estateId}
			and b.del_flag = 0
			and e.del_flag = 0
			<if test="courtId != null">
				and b.court_id = #{courtId}
			</if>
			<if test="courtId == null">
				and b.court_id is null
			</if>
			<if test="buildName != null and buildName != ''">
				and (
				b.build_name like concat( '%', #{buildName}, '%')
				or cour.court_name like concat( '%', #{buildName}, '%')
				or e.estate_name like concat( '%', #{buildName}, '%')
				)
			</if>
		</where>
		GROUP BY b.build_id
		order by e.community_code,  e.estate_id,  courtIntSort  , cour.court_name ,  buildIntSort  ,   b.build_name
	</select>

	<select id="getEstateCourtList" resultType="com.easy.hotel.pms.api.vo.EstateListVo">
		select
		e.estate_id,
		e.estate_no,
		e.estate_name,
		e.community_code,
		cour.court_id ,
		cour.court_name,
		CAST(cour.court_name as int) as courSort
		from estate e
		left join court cour on  cour.estate_id = e.estate_id
		<where>
			and e.del_flag = 0
			and e.community_code = #{communityCode}
			<if test="estateName != null and estateName != ''">
				and (
				e.estate_name like concat( '%', #{estateName}, '%')
				or cour.court_name like concat( '%', #{estateName}, '%')
				)
			</if>
			<if test="estateIdList != null and estateIdList.size() > 0">
				and e.estate_id in
				<foreach collection="estateIdList" item="item" index="index" open="(" separator="," close=")">
					#{item}
				</foreach>
			</if>
		</where>
		order by e.community_code ,e.estate_name ,  courSort , cour.court_name
	</select>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值