| | |
| | | * 根据用户编号获取用户信息 |
| | | * @param userId 用户编号 |
| | | * @return 用户信息列表 |
| | | * 2024-01-09 废弃 |
| | | */ |
| | | List<VoUserInfo> getUserInfos(@Param("userId") Long userId); |
| | | |
| | | /** |
| | | * 根据用户编号获取用户信息 |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | Map getUserInfoById(@Param("userId") Long userId); |
| | | } |
| | |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Mapper |
| | | public interface BaUserRoleMapper extends BaseMapper<BaUserRole> { |
| | | |
| | |
| | | * @return deleteCount |
| | | */ |
| | | int deleteByRoleId(@Param("roleId") Long roleId); |
| | | |
| | | /** |
| | | * 根据用户编号获取权限列表 |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | List<Map<String, Object>> getPermissionsByUserId(@Param("userId") Long userId); |
| | | } |
| | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2023/12/20 10:19 |
| | |
| | | @Schema(title = "用户姓名") |
| | | private String userName; |
| | | |
| | | @Schema(title = "角色ID") |
| | | private Long roleId; |
| | | @Schema(title = "角色编号列表") |
| | | private List<Map<String, Object>> roleIds; |
| | | |
| | | @Schema(title = "角色名称") |
| | | private String roleName; |
| | | @Schema(title = "角色名称列表") |
| | | private List<Map<String, Object>> roleNames; |
| | | |
| | | @Schema(title = "授权列表") |
| | | private String permissions; |
| | | } |
| | | @Schema(title = "权限列表") |
| | | private List<Map<String, Object>> permissions; |
| | | |
| | | } |
| | |
| | | phone = '#{phone,jdbcType=VARCHAR}' and |
| | | </if> |
| | | <if test="area != null"> |
| | | area = #{area,jdbcType=INTEGER} and |
| | | area = ${area} and |
| | | </if> |
| | | </trim> |
| | | </select> |
| | |
| | | phone = '#{phone,jdbcType=VARCHAR}' and |
| | | </if> |
| | | <if test="area != null"> |
| | | area = #{area,jdbcType=INTEGER} and |
| | | area = ${area} and |
| | | </if> |
| | | </trim> |
| | | order by id DESC |
| | |
| | | color = #{color,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="remark != null"> |
| | | color = #{remark,jdbcType=VARCHAR}, |
| | | remark = #{remark,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="deleted != null"> |
| | | color = #{deleted,typeHandler=com.dy.common.mybatis.envm.EnumCodeTypeHandler, jdbcType=TINYINT}, |
| | | deleted = #{deleted,typeHandler=com.dy.common.mybatis.envm.EnumCodeTypeHandler, jdbcType=TINYINT}, |
| | | </if> |
| | | </set> |
| | | where id = #{id,jdbcType=BIGINT} |
| | |
| | | </sql> |
| | | |
| | | <sql id="part_Column_List"> |
| | | id, name |
| | | id, name, deleted |
| | | </sql> |
| | | |
| | | <select id="selectAll" resultMap="BaseResultMap"> |
| | |
| | | </delete> |
| | | |
| | | <!--根据用户编号获取用户信息--> |
| | | <!--2024-01-09 废弃--> |
| | | <select id="getUserInfos" resultType="com.dy.pipIrrGlobal.voBa.VoUserInfo"> |
| | | SELECT |
| | | user.id AS userId, |
| | |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | <!--根据用户编号获取用户信息--> |
| | | <select id="getUserInfoById" resultType="java.util.Map"> |
| | | SELECT |
| | | id AS userId, |
| | | name AS userName |
| | | FROM ba_user |
| | | <where> |
| | | AND disabled = 0 |
| | | AND deleted = 0 |
| | | <if test = "userId != null and userId > 0"> |
| | | AND ba_user.id = ${userId} |
| | | </if> |
| | | </where> |
| | | </select> |
| | | </mapper> |
| | |
| | | where userId = #{roleId,jdbcType=BIGINT} |
| | | </delete> |
| | | |
| | | <!--根据用户编号获取权限列表--> |
| | | <select id="getPermissionsByUserId" resultType="java.util.Map"> |
| | | SELECT |
| | | rol.id AS roleId, |
| | | rol.`name` AS roleName, |
| | | per.permissions |
| | | FROM ba_user_role use_rol |
| | | INNER JOIN ba_role rol ON rol.id = use_rol.roleId |
| | | INNER JOIN ba_role_permissions per ON per.roleId = rol.id |
| | | WHERE use_rol.userId = ${userId} |
| | | |
| | | </select> |
| | | |
| | | </mapper> |
| | |
| | | schema = @Schema(implementation = BaBlock.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | //@GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | @GetMapping(path = "one") |
| | | @SsoAop() |
| | | public BaseResponse<BaBlock> one(Long id){ |
| | | return BaseResponseUtils.buildSuccess(this.sv.selectById(id)); |
| | |
| | | schema = @Schema(implementation = Boolean.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | //@GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | @GetMapping(path = "delete") |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> delete(Long id){ |
| | | if(id == null){ |
| | |
| | | schema = @Schema(implementation = BaRole.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | //@GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | @GetMapping(path = "one") |
| | | @SsoAop() |
| | | public BaseResponse<BaRole> one(Long id){ |
| | | return BaseResponseUtils.buildSuccess(this.sv.selectById(id)); |
| | |
| | | schema = @Schema(implementation = Boolean.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "setPrivs", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | //@GetMapping(path = "setPrivs", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @PostMapping(path = "setPrivs", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> setPrivileges(Long id, Long[] privIds){ |
| | | Long[] privIds_lg = null ; |
| | |
| | | schema = @Schema(implementation = Boolean.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | //@GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | @GetMapping(path = "delete") |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> delete(Long id){ |
| | | if(id == null){ |
| | |
| | | schema = @Schema(implementation = BaUser.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | //@GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | @GetMapping(path = "one") |
| | | @SsoAop() |
| | | public BaseResponse<BaUser> one(String id) { |
| | | return BaseResponseUtils.buildSuccess(this.sv.selectById(Long.parseLong(id))); |
| | |
| | | schema = @Schema(implementation = Boolean.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "changePassword", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | //@GetMapping(path = "changePassword", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | @GetMapping(path = "changePassword") |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> changePassword(String id, String oldPassword, String newPassword) throws Exception { |
| | | if (id == null) { |
| | |
| | | schema = @Schema(implementation = Boolean.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | //@GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | @GetMapping(path = "delete") |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> delete(String id) { |
| | | if (id == null) { |
| | |
| | | }) |
| | | @GetMapping("/getUserInfos/{userId}") |
| | | @SsoAop() |
| | | public BaseResponse<QueryResultVo<List<VoUserInfo>>> getUserInfos(@PathVariable("userId") Long userId) { |
| | | public BaseResponse<QueryResultVo<VoUserInfo>> getUserInfos(@PathVariable("userId") Long userId) { |
| | | try { |
| | | List<VoUserInfo> res = this.sv.getUserInfos(userId); |
| | | VoUserInfo res = this.sv.getUserInfos(userId); |
| | | System.out.println(" :" + res); |
| | | return BaseResponseUtils.buildSuccess(res); |
| | | } catch (Exception e) { |
| | |
| | | package com.dy.pipIrrBase.user; |
| | | |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.dy.common.webUtil.QueryResultVo; |
| | | import com.dy.pipIrrGlobal.daoBa.BaUserMapper; |
| | | import com.dy.pipIrrGlobal.daoBa.BaUserRoleMapper; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Random; |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | | @Service |
| | |
| | | * @param userId 用户编号 |
| | | * @return 用户信息列表 |
| | | */ |
| | | public List<VoUserInfo> getUserInfos(Long userId) { |
| | | return dao.getUserInfos(userId); |
| | | public VoUserInfo getUserInfos(Long userId) { |
| | | VoUserInfo voUserInfo = new VoUserInfo(); |
| | | String permission = ""; |
| | | Map map = Optional.ofNullable(dao.getUserInfoById(userId)).orElse(new HashMap()); |
| | | if(map.size() > 0) { |
| | | voUserInfo.setUserId(userId); |
| | | voUserInfo.setUserName(map.get("userName").toString()); |
| | | } |
| | | |
| | | List list_roleIds = new ArrayList(); |
| | | List list_roleNames = new ArrayList(); |
| | | List list_permissions = new ArrayList(); |
| | | |
| | | List<Map<String, Object>> list = Optional.ofNullable(urDao.getPermissionsByUserId(userId)).orElse(new ArrayList<>()); |
| | | if(list.size() > 0) { |
| | | JSONArray array= JSONArray.parseArray(JSON.toJSONString(list)); |
| | | for (int i = 0; i < array.size(); i++) { |
| | | JSONObject job = array.getJSONObject(i); |
| | | list_roleIds.add(job.getLong("roleId")); |
| | | list_roleNames.add(job.getString("roleName")); |
| | | |
| | | String permissions = Optional.ofNullable(job.getString("permissions")).orElse(""); |
| | | if(permissions.length() > 0) { |
| | | permissions = permissions.substring(1, permissions.length() - 1); |
| | | permissions= permissions.replace(String.valueOf(" "), ""); |
| | | permission = permission + permissions + ","; |
| | | } |
| | | } |
| | | voUserInfo.setRoleIds(list_roleIds); |
| | | voUserInfo.setRoleNames(list_roleNames); |
| | | permission = permission.substring(0, permission.length()-1); |
| | | list_permissions.add(permission); |
| | | voUserInfo.setPermissions(list_permissions); |
| | | } |
| | | return voUserInfo; |
| | | } |
| | | } |