|
@@ -0,0 +1,84 @@
|
|
|
+package com.ozs.system.service;
|
|
|
+
|
|
|
+import com.ozs.common.core.domain.entity.SysDept;
|
|
|
+import com.ozs.common.core.domain.entity.SysUser;
|
|
|
+import com.ozs.common.exception.base.BaseException;
|
|
|
+import com.ozs.common.vo.DataScore;
|
|
|
+import com.ozs.system.mapper.SysDeptMapper;
|
|
|
+import com.ozs.system.mapper.SysUserMapper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class DataScoreUtil {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysDeptMapper sysDeptMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysUserMapper sysUserMapper;
|
|
|
+
|
|
|
+ public DataScore setDataScore(String dsUserId, DataScore ds) {
|
|
|
+ if (StringUtils.isBlank(dsUserId)) {
|
|
|
+ throw new BaseException("dsUserId null");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isEmpty(ds)) {
|
|
|
+ throw new BaseException("DataScore null");
|
|
|
+ }
|
|
|
+ SysUser user = sysUserMapper.selectUserByUserId(dsUserId);
|
|
|
+ if (ObjectUtils.isEmpty(user)) {
|
|
|
+ throw new BaseException("dsUserId error");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isEmpty(user.getDataPermission())) {
|
|
|
+ throw new BaseException("dsUserId dataPermission null");
|
|
|
+ }
|
|
|
+ if (!Arrays.asList(1, 2, 3, 4, 5, 6).contains(user.getDataPermission())) {
|
|
|
+ throw new BaseException("dsUserId dataPermission error");
|
|
|
+ }
|
|
|
+ List<SysDept> sysDepts = sysDeptMapper.selectChildrenDeptById(user.getDeptId());
|
|
|
+ List<Long> deptIds = new ArrayList<>();
|
|
|
+ if (!ObjectUtils.isEmpty(sysDepts)) {
|
|
|
+ deptIds = sysDepts.stream().map(SysDept::getDeptId).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ // 数据权限 1:本人;2:本部门;3:本部门及下级部门;4:本人及本级部门;5:本人及本部门及下级部门;6:全部
|
|
|
+ switch (user.getDataPermission().intValue()) {
|
|
|
+ case 6:
|
|
|
+ ds.setDsFlay(true);
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ ds.setDsUserId(dsUserId);
|
|
|
+ ds.setDsDeptId(user.getDeptId());
|
|
|
+ if (!ObjectUtils.isEmpty(deptIds)) {
|
|
|
+ ds.setDsDeptIds(deptIds);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ ds.setDsUserId(dsUserId);
|
|
|
+ ds.setDsDeptId(user.getDeptId());
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ ds.setDsDeptId(user.getDeptId());
|
|
|
+ if (!ObjectUtils.isEmpty(deptIds)) {
|
|
|
+ ds.setDsDeptIds(deptIds);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ ds.setDsDeptId(user.getDeptId());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ ds.setDsUserId(dsUserId);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ds;
|
|
|
+ }
|
|
|
+}
|