1. 修复回滚父子角色功能时错误的代码逻辑,补全单元测试用例
2. 新增支持切换后业务菜单查询需限定只查询该公司业务数据能力
This commit is contained in:
@@ -99,6 +99,10 @@
|
||||
<groupId>com.fhs-opensource</groupId>
|
||||
<artifactId>easy-trans-mybatis-plus-extend</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.cloud</groupId>
|
||||
<artifactId>yudao-spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package cn.iocoder.yudao.framework.mybatis.core.dataobject;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
/**
|
||||
* @author chenbowen
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class BusinessBaseDO extends BaseDO {
|
||||
|
||||
/** 公司编号 */
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long companyId;
|
||||
/** 公司名称 */
|
||||
@TableField(fill = FieldFill.INSERT, jdbcType = JdbcType.VARCHAR)
|
||||
private String companyName;
|
||||
/** 部门编号 */
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long deptId;
|
||||
/** 部门名称 */
|
||||
@TableField(fill = FieldFill.INSERT, jdbcType = JdbcType.VARCHAR)
|
||||
private String deptName;
|
||||
/** 岗位编号 */
|
||||
@TableField(fill = FieldFill.INSERT, jdbcType = JdbcType.VARCHAR)
|
||||
private Long postId;
|
||||
/**
|
||||
* 多租户编号
|
||||
*/
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* 清除 creator、createTime、updateTime、updater 等字段,避免前端直接传递这些字段,导致被更新
|
||||
*/
|
||||
@Override
|
||||
public void clean() {
|
||||
super.clean();
|
||||
this.companyId = null;
|
||||
this.companyName = null;
|
||||
this.deptId = null;
|
||||
this.deptName = null;
|
||||
this.postId = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,27 @@
|
||||
package cn.iocoder.yudao.framework.mybatis.core.handler;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BusinessBaseDO;
|
||||
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
||||
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.USER_NOT_SET_DEPT;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
|
||||
|
||||
/**
|
||||
* 通用参数填充实现类
|
||||
*
|
||||
* 如果没有显式的对通用参数进行赋值,这里会对通用参数进行填充、赋值
|
||||
*
|
||||
* @author hexiaowu
|
||||
@@ -41,6 +52,30 @@ public class DefaultDBFieldHandler implements MetaObjectHandler {
|
||||
baseDO.setUpdater(userId.toString());
|
||||
}
|
||||
}
|
||||
if (Objects.nonNull(metaObject) && metaObject.getOriginalObject() instanceof BusinessBaseDO businessBaseDO) {
|
||||
// 公司编号、公司名称、部门编号、部门名称、岗位编号等字段,默认不填充
|
||||
// 需要在业务层手动设置
|
||||
LoginUser loginUser = getLoginUser();
|
||||
Long visitCompanyId = loginUser.getVisitCompanyId();
|
||||
Long visitDeptId = loginUser.getVisitDeptId();
|
||||
loginUser.getInfo().getOrDefault(LoginUser.INFO_KEY_POST_IDS,"[]");
|
||||
// 更加合理的写法
|
||||
Set<Long> postIds = new HashSet<>(JSONUtil.parseArray(
|
||||
loginUser.getInfo().getOrDefault(LoginUser.INFO_KEY_POST_IDS, "[]")
|
||||
).toList(Long.class));
|
||||
// 如果 visitCompanyId 不存在,不能进行业务办理
|
||||
if (Objects.isNull(visitCompanyId) || Objects.isNull(visitDeptId)) {
|
||||
throw exception(USER_NOT_SET_DEPT);
|
||||
}
|
||||
businessBaseDO.setCompanyId(visitCompanyId);
|
||||
businessBaseDO.setCompanyName(loginUser.getVisitCompanyName());
|
||||
businessBaseDO.setDeptId(visitDeptId);
|
||||
businessBaseDO.setDeptName(loginUser.getVisitDeptName());
|
||||
// 暂时没有具体业务要求,岗位默认当前用户第一个 todo chenbowen
|
||||
businessBaseDO.setPostId(postIds.isEmpty() ? 0L : postIds.iterator().next());
|
||||
// 多租户编号,默认不填充
|
||||
businessBaseDO.setTenantId(loginUser.getTenantId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user