Administrator
2024-01-09 d76ee745d82d0525f88d9eeebed23961130ccccd
2024-01-09 朱宝民 重构农户查询接口
11个文件已修改
147 ■■■■ 已修改文件
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaUserMapper.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaUserRoleMapper.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voBa/VoUserInfo.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaBlockMapper.xml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRoleMapper.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaUserMapper.xml 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaUserRoleMapper.xml 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/block/BlockCtrl.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java 44 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaUserMapper.java
@@ -91,6 +91,14 @@
     * 根据用户编号获取用户信息
     * @param userId 用户编号
     * @return 用户信息列表
     * 2024-01-09 废弃
     */
    List<VoUserInfo> getUserInfos(@Param("userId") Long userId);
    /**
     * 根据用户编号获取用户信息
     * @param userId
     * @return
     */
    Map getUserInfoById(@Param("userId") Long userId);
}
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaUserRoleMapper.java
@@ -5,6 +5,9 @@
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> {
@@ -43,4 +46,11 @@
     * @return deleteCount
     */
    int deleteByRoleId(@Param("roleId") Long roleId);
    /**
     * 根据用户编号获取权限列表
     * @param userId
     * @return
     */
    List<Map<String, Object>> getPermissionsByUserId(@Param("userId") Long userId);
}
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voBa/VoUserInfo.java
@@ -4,6 +4,9 @@
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
@@ -22,12 +25,13 @@
    @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;
}
pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaBlockMapper.xml
@@ -50,7 +50,7 @@
          phone = '#{phone,jdbcType=VARCHAR}' and
        </if>
        <if test="area != null">
          area = #{area,jdbcType=INTEGER} and
          area = ${area} and
        </if>
      </trim>
  </select>
@@ -70,7 +70,7 @@
        phone = '#{phone,jdbcType=VARCHAR}' and
      </if>
      <if test="area != null">
        area = #{area,jdbcType=INTEGER} and
        area = ${area} and
      </if>
    </trim>
    order by id DESC
@@ -169,10 +169,10 @@
        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}
pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRoleMapper.xml
@@ -22,7 +22,7 @@
  </sql>
  <sql id="part_Column_List">
    id, name
    id, name, deleted
  </sql>
  <select id="selectAll" resultMap="BaseResultMap">
pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaUserMapper.xml
@@ -223,6 +223,7 @@
    </delete>
    <!--根据用户编号获取用户信息-->
    <!--2024-01-09 废弃-->
    <select id="getUserInfos" resultType="com.dy.pipIrrGlobal.voBa.VoUserInfo">
        SELECT
            user.id AS userId,
@@ -240,4 +241,19 @@
            </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>
pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaUserRoleMapper.xml
@@ -60,4 +60,17 @@
    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>
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/block/BlockCtrl.java
@@ -99,7 +99,8 @@
                            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));
@@ -192,7 +193,8 @@
                            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){
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java
@@ -108,7 +108,8 @@
                            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));
@@ -204,7 +205,8 @@
                            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 ;
@@ -237,7 +239,8 @@
                            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){
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java
@@ -113,7 +113,8 @@
                            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)));
@@ -227,7 +228,8 @@
                            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) {
@@ -452,7 +454,8 @@
                            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) {
@@ -488,9 +491,9 @@
    })
    @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) {
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java
@@ -1,6 +1,9 @@
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;
@@ -13,9 +16,7 @@
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
@@ -168,7 +169,40 @@
     * @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;
    }
}