@@ -0,0 +1,17 @@ | |||
package com.tuoheng.admin.conver; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.vo.UserPageListVo; | |||
import org.mapstruct.Mapper; | |||
import org.mapstruct.factory.Mappers; | |||
import java.util.List; | |||
@Mapper | |||
public interface UserConverMapper { | |||
UserConverMapper INSTANCE = Mappers.getMapper(UserConverMapper.class); | |||
List<UserPageListVo> fromUserListToUserPageVoList(List<User> userList); | |||
} |
@@ -1,7 +1,13 @@ | |||
package com.tuoheng.admin.mapper; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.tuoheng.admin.entity.InspectionFileExtend; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.request.inspectionfile.QueryInspectionFilePageListRequest; | |||
import com.tuoheng.admin.request.user.QueryUserPageListRequest; | |||
import org.apache.ibatis.annotations.Param; | |||
import java.util.Map; | |||
@@ -16,4 +22,12 @@ public interface UserMapper extends BaseMapper<User> { | |||
Integer updateByIdList(Map<String, Object> map); | |||
/** | |||
* 查询任务问题分页列表 | |||
* | |||
* @param request 巡检任务查询实体 | |||
* @return 巡检任务集合 | |||
*/ | |||
Page<User> selectPageList(@Param("page") IPage page, @Param("request") QueryUserPageListRequest request); | |||
} |
@@ -9,6 +9,11 @@ import lombok.Data; | |||
@Data | |||
public class QueryUserPageListRequest extends BaseQuery { | |||
/** | |||
* 租户ID | |||
*/ | |||
private String tenantId; | |||
/** | |||
* 用户账号 | |||
*/ | |||
@@ -19,26 +24,6 @@ public class QueryUserPageListRequest extends BaseQuery { | |||
*/ | |||
private String realname; | |||
/** | |||
* 性别:1男 2女 3保密 | |||
*/ | |||
private Integer gender; | |||
/** | |||
* 终端 1 web端 2 小程序端 | |||
*/ | |||
private Integer terminalType; | |||
/** | |||
* 用户类型 | |||
*/ | |||
private Integer type; | |||
/** | |||
* 用户状态:1在用 2停用 | |||
*/ | |||
private Integer status; | |||
/** | |||
* 角色ID | |||
*/ |
@@ -1,19 +1,33 @@ | |||
package com.tuoheng.admin.service.user.query; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.conver.InspectionFileConverMapper; | |||
import com.tuoheng.admin.conver.UserConverMapper; | |||
import com.tuoheng.admin.entity.*; | |||
import com.tuoheng.admin.mapper.DeptMapper; | |||
import com.tuoheng.admin.mapper.RoleMapper; | |||
import com.tuoheng.admin.mapper.UserMapper; | |||
import com.tuoheng.admin.request.user.QueryUserPageListRequest; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.admin.vo.InspectionFilePageListByInspectionIdVo; | |||
import com.tuoheng.admin.vo.UserPageListVo; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.function.Function; | |||
import java.util.stream.Collectors; | |||
/** | |||
* 查询用户分页列表业务层处理 | |||
* | |||
@@ -31,6 +45,9 @@ public class QueryUserPageListService { | |||
@Autowired | |||
private DeptMapper deptMapper; | |||
@Autowired | |||
private RoleMapper roleMapper; | |||
/** | |||
* 获取部门树形列表 | |||
* | |||
@@ -45,17 +62,29 @@ public class QueryUserPageListService { | |||
} | |||
String tenantId = CurrentUserUtil.getTenantId(); | |||
QueryWrapper<User> queryWrapper = this.buildQueryWrapper(request); | |||
request.setTenantId(tenantId); | |||
// 查询分页数据 | |||
IPage<User> page = new Page<>(request.getPage(), request.getLimit()); | |||
IPage<User> pageData = userMapper.selectPage(page, queryWrapper); | |||
IPage<User> pageData = userMapper.selectPageList(page, request); | |||
// if (CollectionUtil.isEmpty(pageData)) { | |||
// log.info("查询用户分页列表业务:获取用户列表为空"); | |||
// } | |||
return JsonResult.success(); | |||
if (null == pageData || pageData.getTotal() == 0) { | |||
log.info("获取任务分页列表为空"); | |||
return JsonResult.success(); | |||
} | |||
// 构造返回结果对象 | |||
List<UserPageListVo> userPageListVoList = this.buildUserPageListVoList(pageData.getRecords()); | |||
// 重写返回结果对象 | |||
IPage<UserPageListVo> userPageListVoPageData = new Page<>(); | |||
userPageListVoPageData.setPages(pageData.getPages()); | |||
userPageListVoPageData.setCurrent(pageData.getCurrent()); | |||
userPageListVoPageData.setSize(pageData.getSize()); | |||
userPageListVoPageData.setTotal(pageData.getTotal()); | |||
userPageListVoPageData.setRecords(userPageListVoList); | |||
return JsonResult.success(userPageListVoPageData); | |||
} | |||
/** | |||
@@ -65,38 +94,80 @@ public class QueryUserPageListService { | |||
* @return | |||
*/ | |||
private JsonResult check(QueryUserPageListRequest request) { | |||
return JsonResult.success(); | |||
} | |||
private QueryWrapper<User> buildQueryWrapper(QueryUserPageListRequest request) { | |||
// 查询条件 | |||
QueryWrapper<User> queryWrapper = new QueryWrapper<>(); | |||
// 只显示非管理员用户 | |||
//queryWrapper.ne("is_admin", 1); | |||
// 租户ID | |||
queryWrapper.eq("tenant_id", CurrentUserUtil.getTenantId()); | |||
// 真实姓名 | |||
if (!StringUtils.isEmpty(request.getRealname())) { | |||
queryWrapper.like("realname", request.getRealname()); | |||
} | |||
// 用户账号 | |||
if (!StringUtils.isEmpty(request.getUsername())) { | |||
queryWrapper.eq("username", request.getUsername()); | |||
/** | |||
* 1)、查找问题类型字段 | |||
* 2)、拼接缩略图路径 | |||
* | |||
* @param userList | |||
* @return | |||
*/ | |||
private List<UserPageListVo> buildUserPageListVoList(List<User> userList) { | |||
Map<String, Dept> deptMap = this.getDeptMap(userList); | |||
Map<Integer, Role> roleMap = this.getRoletMap(userList); | |||
List<UserPageListVo> userPageListVoList = UserConverMapper.INSTANCE.fromUserListToUserPageVoList(userList); | |||
Dept dept; | |||
Role role; | |||
for (UserPageListVo userPageListVo : userPageListVoList) { | |||
if (ObjectUtil.isNotNull(deptMap)) { | |||
dept = deptMap.get(userPageListVo.getDeptId()); | |||
if (null != dept) { | |||
userPageListVo.setDeptName(dept.getName()); | |||
} | |||
} | |||
if (ObjectUtil.isNotNull(roleMap)) { | |||
role = roleMap.get(userPageListVo.getRoleId()); | |||
if (null != role) { | |||
userPageListVo.setRoleName(role.getRoleName()); | |||
} | |||
} | |||
} | |||
return userPageListVoList; | |||
} | |||
//根据角色id查询 | |||
if (StringUtils.isNotNull((request.getRoleId()))) { | |||
queryWrapper.eq("role_id", request.getRoleId()); | |||
/** | |||
* | |||
* 获取部门列表,放到map,减少循环次数 | |||
* | |||
* @param userList | |||
* @return | |||
*/ | |||
private Map<String, Dept> getDeptMap(List<User> userList) { | |||
if (CollectionUtil.isEmpty(userList)) { | |||
return null; | |||
} | |||
// 状态筛选 | |||
if (StringUtils.isNotNull(request.getStatus())) { | |||
queryWrapper.eq("status", request.getStatus()); | |||
List<String> deptIdList = userList.stream().map(o -> o.getDeptId()).collect(Collectors.toList()); | |||
List<Dept> deptList = deptMapper.selectList(new LambdaQueryWrapper<Dept>() | |||
.in(Dept::getId, deptIdList) | |||
.eq(Dept::getMark, 1)); | |||
if (CollectionUtil.isEmpty(deptList)) { | |||
return null; | |||
} | |||
queryWrapper.eq("mark", 1); | |||
queryWrapper.orderByDesc("create_time"); | |||
Map<String, Dept> deptMap = deptList.stream().collect(Collectors.toMap(Dept::getId, Function.identity())); | |||
return deptMap; | |||
} | |||
return queryWrapper; | |||
/** | |||
* | |||
* 获取角色列表,放到map,减少循环次数 | |||
* | |||
* @param userList | |||
* @return | |||
*/ | |||
private Map<Integer, Role> getRoletMap(List<User> userList) { | |||
if (CollectionUtil.isEmpty(userList)) { | |||
return null; | |||
} | |||
List<String> roleIdList = userList.stream().map(o -> o.getDeptId()).collect(Collectors.toList()); | |||
List<Role> roleList = roleMapper.selectList(new LambdaQueryWrapper<Role>() | |||
.in(Role::getId, roleIdList) | |||
.eq(Role::getMark, 1)); | |||
if (CollectionUtil.isEmpty(roleList)) { | |||
return null; | |||
} | |||
Map<Integer, Role> roleMap = roleList.stream().collect(Collectors.toMap(Role::getId, Function.identity())); | |||
return roleMap; | |||
} | |||
} |
@@ -0,0 +1,210 @@ | |||
package com.tuoheng.admin.vo; | |||
import com.baomidou.mybatisplus.annotation.IdType; | |||
import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import lombok.Data; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
import java.util.Date; | |||
/** | |||
* 返回用户分页列表视图Vo | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2022-12-20 | |||
*/ | |||
@Data | |||
public class UserPageListVo { | |||
/** | |||
* 用户ID | |||
*/ | |||
private String id; | |||
/** | |||
* 用户编号 | |||
*/ | |||
private String code; | |||
/** | |||
* 真实姓名 | |||
*/ | |||
private String realname; | |||
/** | |||
* 昵称 | |||
*/ | |||
private String nickname; | |||
/** | |||
* 性别:1男 2女 3保密 | |||
*/ | |||
private Integer gender; | |||
/** | |||
* 头像 | |||
*/ | |||
private String avatar; | |||
/** | |||
* 手机号码 | |||
*/ | |||
private String mobile; | |||
/** | |||
* 邮箱地址 | |||
*/ | |||
private String email; | |||
/** | |||
* 出生日期 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd") | |||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") | |||
private Date birthday; | |||
/** | |||
* 部门ID | |||
*/ | |||
private String deptId; | |||
/** | |||
* 部门名称 | |||
*/ | |||
private String deptName; | |||
/** | |||
* 省份编码 | |||
*/ | |||
private String provinceCode; | |||
/** | |||
* 城市编码 | |||
*/ | |||
private String cityCode; | |||
/** | |||
* 区县编码 | |||
*/ | |||
private String districtCode; | |||
/** | |||
* 街道编码 | |||
*/ | |||
private String streetCode; | |||
/** | |||
* 详细地址 | |||
*/ | |||
private String address; | |||
/** | |||
* 所属城市 | |||
*/ | |||
private String cityName; | |||
/** | |||
* 登录用户名 | |||
*/ | |||
private String username; | |||
/** | |||
* 用户类型:1管理员 | |||
*/ | |||
private Integer type; | |||
/** | |||
* 驾照类型:1飞行执照 2飞行许可证 | |||
*/ | |||
private Integer driverType; | |||
/** | |||
* 驾照编号 | |||
*/ | |||
private String driverCode; | |||
/** | |||
* 个人简介 | |||
*/ | |||
private String intro; | |||
/** | |||
* 状态:1正常 2禁用 | |||
*/ | |||
private Integer status; | |||
/** | |||
* 备注 | |||
*/ | |||
private String note; | |||
/** | |||
* 显示顺序 | |||
*/ | |||
private Integer sort; | |||
/** | |||
* 登录次数 | |||
*/ | |||
private Integer loginNum; | |||
/** | |||
* 最近登录IP | |||
*/ | |||
private String loginIp; | |||
/** | |||
* 最近登录时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date loginTime; | |||
/** | |||
* 添加人 | |||
*/ | |||
private String createUser; | |||
/** | |||
* 创建时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date createTime; | |||
/** | |||
* 更新人 | |||
*/ | |||
private String updateUser; | |||
/** | |||
* 更新时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date updateTime; | |||
/** | |||
* 有效标识 | |||
*/ | |||
private Integer mark; | |||
/** | |||
* 角色id | |||
*/ | |||
private Integer roleId; | |||
/** | |||
* 角色名称 | |||
*/ | |||
private String roleName; | |||
/** | |||
* 标识id 小程序,pc | |||
*/ | |||
private String clientId; | |||
} |
@@ -44,7 +44,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
<result property="clientId" column="client_id" /> | |||
</resultMap> | |||
<sql id="selectThUserVo"> | |||
<sql id="selectUserVo"> | |||
id, tenant_id, code, realname, nickname, gender, avatar, mobile, email, birthday, dept_id, province_code, city_code, district_code, street_code, address, city_name, username, password, type, driver_type, driver_code, salt, intro, status, note, sort, login_num, login_ip, login_time, create_user, create_time, update_user, update_time, role_id, client_id, mark | |||
</sql> | |||
@@ -65,4 +65,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
</where> | |||
</update> | |||
<select id="selectPageList" parameterType="com.tuoheng.admin.request.user.QueryUserPageListRequest" resultMap="UserResult"> | |||
select <include refid="selectUserVo"/> | |||
from th_oauth_user | |||
<where> | |||
<if test="1 == 1"> and mark = 1 </if> | |||
<if test="request.tenantId != null and request.tenantId != ''"> and tenant_id = #{request.tenantId} </if> | |||
<if test="request.username != null and request.username != ''"> and username like concat('%', #{request.username}, '%') </if> | |||
<if test="request.realname != null and request.realname != ''"> and realname like concat('%', #{request.realname}, '%') </if> | |||
<if test="request.roleId != null and request.roleId != 0"> and role_id = #{request.roleId} </if> | |||
</where> | |||
order by create_time desc | |||
</select> | |||
</mapper> |