| | |
| | | |
| | | import com.ruoyi.common.annotation.AddOrgId; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.core.service.IConfigService; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import org.aspectj.lang.JoinPoint; |
| | | import org.aspectj.lang.annotation.Aspect; |
| | | import org.aspectj.lang.annotation.Before; |
| | | import org.aspectj.lang.reflect.MethodSignature; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.lang.reflect.Field; |
| | |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(SetOrgIdAspect.class); |
| | | |
| | | @Autowired |
| | | private IConfigService sysConfigService; |
| | | |
| | | @Before("@annotation(setOrgId)") |
| | | public void setOrgId(JoinPoint joinPoint, AddOrgId setOrgId) throws Throwable |
| | | { |
| | |
| | | { |
| | | String orgid = loginUser.getUser().getOrgid(); |
| | | String campusid = loginUser.getUser().getCampusid(); |
| | | boolean allCampusUser = false; |
| | | //显示所有院区权限 |
| | | String allCampus = sysConfigService.selectConfigByKey("sys.authority.campus.all"); |
| | | if (StringUtils.isNotEmpty(allCampus)) { |
| | | String userName = loginUser.getUser().getUserName(); |
| | | if (StringUtils.isNotEmpty(userName)) { |
| | | for (String item : allCampus.split("[,,;;\\s]+")) { |
| | | if (userName.equals(item.trim())) { |
| | | campusid = null; |
| | | allCampusUser = true; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 获取方法参数 |
| | | Object[] args = joinPoint.getArgs(); |
| | |
| | | } |
| | | |
| | | // 如果需要同时设置campusid |
| | | if (setOrgId.withCampusId() && campusid != null) |
| | | if (setOrgId.withCampusId()) |
| | | { |
| | | String campusFieldName = setOrgId.campusField(); |
| | | |
| | | // 检查字段是否已经有值,如果有且skipIfPresent为true,则跳过设置 |
| | | Object currentValueCampus = getFieldValue(param, campusFieldName); |
| | | if (setOrgId.skipIfPresent() && currentValueCampus != null && !currentValueCampus.toString().isEmpty()) { |
| | | // 如果字段已经有值且skipIfPresent为true,则跳过设置 |
| | | log.debug("字段 {} 已有值: {},跳过设置", campusFieldName, currentValueCampus); |
| | | } else { |
| | | setFieldValue(param, campusFieldName, campusid); |
| | | if (allCampusUser) { |
| | | // 全院区权限必须覆盖请求里可能带进来的 campusid, |
| | | // 否则前端传 campusid=8 会重新把院区条件加回去。 |
| | | setFieldValue(param, campusFieldName, null); |
| | | } else if (campusid != null) { |
| | | // 检查字段是否已经有值,如果有且skipIfPresent为true,则跳过设置 |
| | | Object currentValueCampus = getFieldValue(param, campusFieldName); |
| | | if (setOrgId.skipIfPresent() && currentValueCampus != null && !currentValueCampus.toString().isEmpty()) { |
| | | // 如果字段已经有值且skipIfPresent为true,则跳过设置 |
| | | log.debug("字段 {} 已有值: {},跳过设置", campusFieldName, currentValueCampus); |
| | | } else { |
| | | setFieldValue(param, campusFieldName, campusid); |
| | | } |
| | | } |
| | | } |
| | | } |