业务逻辑
查询用户数据时携带用户所管理小区的名称List< String >
用户与管理的小区是一对多的关系
查询返回实体类
@Data
public class UserVo{
private Long userId;
private String loginName;
private String userName;
private String password;
private Integer userTypeEnum;
private String email;
private String phone;
private Integer sexEnum;
private String avatar;
private Integer statusEnum;
private Integer deleteFlag;
private String loginIp;
private LocalDateTime loginDate;
private Long companyId;
private String companyName;
private String remark;
/**
* 根据小区id查询
*/
private Long estateId;
private List<String> estateNameList;
mapper.xml
<resultMap id="BaseResultMap" type="com.yiju.modules.system.user.pojo.entity.UserVo">
<collection property="estateNameList" ofType="java.lang.String" javaType="java.util.List" select="getEstateName" column="user_id">
<result column="estateNameList"/>
</collection>
</resultMap>
<select id="userVoList" resultMap="BaseResultMap">
SELECT
distinct(t1.user_id) userId,
t1.*,
t2.company_name
FROM
sys_user t1
LEFT JOIN charge_company t2 ON t1.company_id = t2.company_id
left join charge_user_estate t3 on t1.user_id=t3.user_id
</select>
<select id="getEstateName" parameterType="java.lang.Long" resultType="java.lang.String" >
select t4.house_estate_name estateNameList
from charge_user_estate t3
inner join charge_base_estate t4 on t3.estate_id=t4.house_estate_id
where t3.user_id=#{user_id}
</select>
mapper.java
public interface UserMapper extends BaseMapper<User> {
List<UserVo> userVoList();
}