1、设置id拦截器修改,处理实体没有setId方法的情况
2、用户管理中增加设置用户角色的方法
3个文件已修改
74 ■■■■■ 已修改文件
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java
@@ -43,8 +43,17 @@
            if (entity instanceof BaseEntity) {
                //Class<? extends Object> entityClass = entity.getClass();
                Class<?> entityClass = entity.getClass();
                Method setMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME, Long.class) ;
                setMt.invoke(entity, new IDLongGenerator().generate());
                Method setMt = null ;
                try{
                    //有一些实体没有id,例如中间表
                    setMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME, Long.class) ;
                }catch (Exception e){
                    //当entityClass没有setId方法时,会抛出异常
                }
                if(setMt != null){
                    setMt.invoke(entity, new IDLongGenerator().generate());
                }
                invocation.getArgs()[PARAMETER_INDEX] = entity;
            }
        }
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java
@@ -235,6 +235,42 @@
    /**
     * 设置用户角色
     * @param id 用户ID
     * @return 是否成功
     */
    @Operation(summary = "设置用户角色", description = "提交用户ID,及所选择的角色ID集合(数组)")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "操作结果:true:成功,false:失败(BaseResponse.content)",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = Boolean.class))}
            )
    })
    @GetMapping(path = "setRoles", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @SsoAop("-1")//@SsoAop(power = "-1")
    public BaseResponse<Boolean> setRoles(@Parameter(description = "实体id", required = true) String id,
                                          @Parameter(description = "角色id数组集合") String[] roleIds){
        Long[] roleId_lg = null ;
        if(roleIds != null && roleIds.length > 0){
            roleId_lg = new Long[roleIds.length] ;
            int index = 0 ;
            for(String roleId : roleIds){
                roleId_lg[index++] = Long.parseLong(roleId) ;
            }
        }
        try {
            this.sv.setRoles(Long.parseLong(id), roleId_lg);
        } catch (Exception e) {
            log.error("保存用户异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
        return BaseResponseUtils.buildSuccess(true) ;
    }
    /**
     * 删除用户
     * @param id 用户ID
     * @return 是否成功
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java
@@ -3,7 +3,9 @@
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pipIrrGlobal.daoBa.BaUserMapper;
import com.dy.pipIrrGlobal.daoBa.BaUserRoleMapper;
import com.dy.pipIrrGlobal.pojoBa.BaUser;
import com.dy.pipIrrGlobal.pojoBa.BaUserRole;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -19,10 +21,16 @@
public class UserSv {
    private BaUserMapper dao;
    private BaUserRoleMapper urDao;
    @Autowired
    private void setDao(BaUserMapper dao){
        this.dao = dao;
    }
    @Autowired
    private void setDao(BaUserRoleMapper dao){
        this.urDao = dao;
    }
    /**
@@ -84,6 +92,23 @@
    }
    /**
     * 设置用户角色
     * @param userId 用户id
     * @param roleIds 选择的角色id集合
     * @return 插入用户与角色关联记录数量
     */
    public int setRoles(Long userId, Long[] roleIds){
        this.urDao.deleteByUserId(userId) ;
        int count = 0 ;
        if(roleIds != null && roleIds.length > 0){
            for(Long roleId : roleIds){
                count += this.urDao.insertSelective(new BaUserRole(userId,roleId)) ;
            }
        }
        return count ;
    }
    /**
     * 保存修改实体
     * @param id 实体ID
     * @return 影响记录数量