浏览代码

根据多块牌子调整人员权限

songwb 11 月之前
父节点
当前提交
10584401cc

+ 47 - 27
ims-service/ims-eval/src/main/java/com/ims/eval/cache/CacheContext.java

@@ -10,7 +10,6 @@ import org.springframework.stereotype.Component;
 import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 /**
  * 初始化缓存类
@@ -37,15 +36,17 @@ public class CacheContext implements CommandLineRunner {
 	@Autowired
 	private IMultipleBrandService multipleBrandService;
 
-	//按公司
-	//public static Map<String, OrganizationStructure> brandMap = new HashMap<>();
-
-	//按单位营业收入配置
+	/**
+	 * 单位营业收入配置列表
+	 */
 	public static Map<String, MultipleBrand> brandMap = new HashMap<>();
 
-//	public static final ThreadLocal<List<String>> childCompany = new ThreadLocal<>();
-	public static final Map<String, String> childCompanyId = new LinkedHashMap<>();
+	/**
+	 * brandMap列表根据考评周期和具体年月分组
+	 */
+	public static Map<String, Map<String, MultipleBrand>> groupBrandMap = new HashMap<>();
 
+	public static final Map<String, String> childCompanyId = new LinkedHashMap<>();
 
 
 	//初始化字典表
@@ -85,6 +86,7 @@ public class CacheContext implements CommandLineRunner {
 		initBinSection();
 		initOrganizationEvaluationRule();
 		initTree();
+		initTree2();
 	}
 
 
@@ -95,41 +97,59 @@ public class CacheContext implements CommandLineRunner {
 
 		for (MultipleBrand record : records) {
 			brandMap.put(record.getOrganizationId(), record);
-			if (record.getChildren()==null) continue;
+			if (record.getChildren() == null) continue;
 			for (MultipleBrand child : record.getChildren()) {
 				brandMap.put(child.getOrganizationId(), child);
 			}
 		}
+	}
 
-		/*
-		//按照公司
-		List<OrganizationStructure> loss = organizationStructureService.getList2(null, null, null);
-		brandMap = loss.stream().collect(Collectors.toMap(OrganizationStructure::getId, Function.identity()));*/
+
+	private void initTree2() {
+		//按照单位营业收入配置
+		IPage<MultipleBrand> tree = multipleBrandService.getMultipleBranTree(1, 1000, null, null, "", "", "", null);
+		List<MultipleBrand> records = tree.getRecords();
+		Map<String, List<MultipleBrand>> collect = records.stream().peek(mb -> {
+			if ("NDKP".equals(mb.getCheckCycle())) {
+				mb.setCheckCycle(mb.getCheckCycle() + "_" + mb.getYear() + "_" + mb.getMonth());
+			} else {
+				mb.setCheckCycle(mb.getCheckCycle() + "_" + mb.getYear() + "_" + mb.getMonth());
+			}
+		}).collect(Collectors.groupingBy(MultipleBrand::getCheckCycle));
+
+		for (Map.Entry<String, List<MultipleBrand>> entry : collect.entrySet()) {
+			Map<String, MultipleBrand> aaa = new HashMap<>();
+			for (MultipleBrand record : entry.getValue()) {
+				aaa.put(record.getOrganizationId(), record);
+				if (record.getChildren() == null) {
+					continue;
+				}
+				for (MultipleBrand child : record.getChildren()) {
+					aaa.put(child.getOrganizationId(), child);
+				}
+			}
+			groupBrandMap.put(entry.getKey(), aaa);
+		}
 	}
 
-	public static List<String> getChildList(String id) {
-		MultipleBrand brand = brandMap.get(id);
-		List<String> zgs = new ArrayList<>();
-		if (brand==null){
+	public static Set<String> getChildList(String id, String orgCode) {
+		Set<String> zgs = new HashSet<>();
+		zgs.add(id);
+		Map<String, MultipleBrand> stringMultipleBrandMap = groupBrandMap.get(orgCode);
+		if (stringMultipleBrandMap == null) return zgs;
+
+		MultipleBrand brand = stringMultipleBrandMap.get(id);
+		if (brand == null) {
 			return zgs;
 		}
-		zgs.add(brand.getOrganizationId());
 		Map<String, MultipleBrand> coll = brandMap.values().stream().filter(bm -> bm.getChildren() != null).collect(Collectors.toMap(MultipleBrand::getOrganizationId, Function.identity()));
 		List<String> parentId = coll.values().stream().filter(bm -> id.equals(bm.getChildren().get(0).getOrganizationId())).map(MultipleBrand::getOrganizationId).collect(Collectors.toList());
 		zgs.addAll(parentId);
-		if(brand.getChildren() == null) return zgs;
+		if (brand.getChildren() == null) return zgs;
 		for (MultipleBrand child : brand.getChildren()) {
-			List<String> childList = getChildList(child.getOrganizationId());
-			zgs.addAll(childList);
+			zgs.add(child.getOrganizationId());
 		}
 		return zgs;
-		/*
-		//按公司
-		List<String> ids = new ArrayList<>();
-		ids.add(id);
-		List<String> collects = brandMap.values().stream().filter(i -> id.equals(i.getParentId())).map(OrganizationStructure::getId).collect(Collectors.toList());
-		ids.addAll(collects);
-		return ids;*/
 	}
 
 

+ 16 - 25
ims-service/ims-eval/src/main/java/com/ims/eval/config/permission/PermissionAspect.java

@@ -5,14 +5,11 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.ims.eval.cache.CacheContext;
-import com.ims.eval.entity.DataDictionary;
-import com.ims.eval.entity.OrganizationEvaluationRule;
-import com.ims.eval.entity.OrganizationStructure;
+import com.ims.eval.entity.*;
 import com.ims.eval.entity.custom.PostUser;
 import com.ims.eval.entity.dto.response.MyuserResDTO;
 import com.ims.eval.entity.dto.result.PagResult;
 import com.ims.eval.feign.RemoteServiceBuilder;
-import com.ims.eval.service.IOrganizationStructureService;
 import com.ims.eval.service.custom.PostUserService;
 import lombok.extern.slf4j.Slf4j;
 import net.sf.jsqlparser.JSQLParserException;
@@ -40,7 +37,6 @@ import org.springframework.stereotype.Component;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
-import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.lang.reflect.Method;
 import java.sql.Connection;
@@ -62,11 +58,6 @@ public class PermissionAspect implements Interceptor {
 	private HttpServletRequest request;
 	@Autowired
 	private PostUserService postUserService;
-//	@Resource
-//	private IOrganizationStructureService organizationStructureService;
-
-////	@Resource
-//	private IUserService userService;
 
 
 	//扫描的包路径,需要权限的加在mapper类及方法上
@@ -126,7 +117,6 @@ public class PermissionAspect implements Interceptor {
 		MyuserResDTO user = getSysUser(code, bladeAuth);
 		DataDictionary dept = getSysDept(user);
 
-
 		//岗位权限
 		DataDictionary post = null;
 		// 比较Scope字段并取最大值
@@ -135,9 +125,12 @@ public class PermissionAspect implements Interceptor {
 		if (null != user) {
 			organizationId = user.getUnitId();
 			if (null != dept) {
-				scope = dept.getScope();
+				if ("LSBM".equals(dept.getDataKey())) {
+					scope = 3;
+				} else {
+					scope = dept.getScope();
+				}
 			}
-
 			List<PostUser> postUserList = getUserPostList(user.getId());
 			post = getSysPost(postUserList);
 
@@ -169,16 +162,12 @@ public class PermissionAspect implements Interceptor {
 			return invocation.proceed();
 //			throw new CustomException("暂无权限");
 		}
-
 		if (scope.equals(DATA_SCOPE_DEPT)) {
-			List<String> childList = CacheContext.getChildList(user.getUnitId());
-			CacheContext.childCompanyId.put(user.getId(),user.getUnitId());
 
 			String deptId = "";
 			if (null != dept) {
 				deptId = dept.getDataKey();
 			}
-
 			try {
 				//反射扫包会比较慢,这里做了个懒加载
 				if (classNames == null) {
@@ -191,12 +180,10 @@ public class PermissionAspect implements Interceptor {
 						classNames = classSet.stream().map(Class::getName).collect(Collectors.toList());
 					}
 				}
-
 				// 拿到mybatis的一些对象
 				StatementHandler statementHandler = PluginUtils.realTarget(invocation.getTarget());
 				MetaObject metaObject = SystemMetaObject.forObject(statementHandler);
 				MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement");
-
 				// mappedStatement.getId()为执行的mapper方法的全路径名,newId为执行的mapper方法的类全名
 				String newId = mappedStatement.getId().substring(0, mappedStatement.getId().lastIndexOf("."));
 				// 如果不是指定的方法,直接结束拦截
@@ -227,7 +214,6 @@ public class PermissionAspect implements Interceptor {
 						}
 					}
 				}
-
 				//是否开启数据权限
 				boolean isPermission = true;
 				isPermission = null != methodNames.get(newId + "-" + newName) ? methodNames.get(newId + "-" + newName) : false;
@@ -237,7 +223,6 @@ public class PermissionAspect implements Interceptor {
 					// 解析并返回新的SQL语句,只处理查询sql
 					if (mappedStatement.getSqlCommandType().toString().equals("SELECT")) {
 
-
 //						boolean jbtype = null != methodNames.get(newId + "-" + newName+"jbtype") ?methodNames.get(newId + "-" + newName+"jbtype") :false;
 						boolean type = null != methodNames.get(newId + "-" + newName + "type") ? methodNames.get(newId + "-" + newName + "type") : false;
 						boolean zbtype = null != methodNames.get(newId + "-" + newName + "zbtype") ? methodNames.get(newId + "-" + newName + "zbtype") : false;
@@ -245,8 +230,6 @@ public class PermissionAspect implements Interceptor {
 
 
 						System.out.println("==========type=" + type + ";zbtype" + zbtype + ";bktype" + bktype);
-
-
 						if (null != post && post.getKeyValue().equals("JCDW")) {
 							System.out.println("==========post.getKeyValue()=" + post.getKeyValue());
 							if (type) {
@@ -293,8 +276,14 @@ public class PermissionAspect implements Interceptor {
 				}
 			} catch (Exception e) {
 				log.error("数据权限隔离异常:", e);
+				e.printStackTrace();
 			}
 		}
+
+		if (scope.equals(DATA_SCOPE_CUSTOM)) {
+			CacheContext.childCompanyId.put(user.getId(), user.getUnitId());
+			return invocation.proceed();
+		}
 		return invocation.proceed();
 	}
 
@@ -397,8 +386,10 @@ public class PermissionAspect implements Interceptor {
 	@Cacheable(cacheNames = "user_code_dept", key = "#user.id")
 	public DataDictionary getSysDept(MyuserResDTO user) {
 		if (user != null && CacheContext.ddSuperKeyMap.containsKey(DEPT_MARK)) {
-//			Optional<DataDictionary> any = CacheContext.ddSuperKeyMap.get(DEPT_MARK).stream().filter(t -> t.getKeyName().equals(user.getDeptName())).findAny();
-			Optional<DataDictionary> any = CacheContext.ddSuperKeyMap.get(DEPT_MARK).stream().filter(t -> user.getDeptName().contains(t.getKeyName())).findAny();
+			if (!user.getUnitName().contains("本部")) {
+				return CacheContext.ddMap.get("LSBM");
+			}
+			Optional<DataDictionary> any = CacheContext.ddSuperKeyMap.get(DEPT_MARK).stream().filter(t -> t.getKeyName().equals(user.getDeptName())).findAny();
 			return any.isPresent() ? any.get() : CacheContext.ddMap.get("LSBM");//如果没有匹配上部门,赋予零时部门权限
 		}
 		return null;

+ 35 - 26
ims-service/ims-eval/src/main/java/com/ims/eval/controller/OrganizationEvaluationInfoController.java

@@ -2,16 +2,16 @@ package com.ims.eval.controller;
 
 
 import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.ims.eval.cache.CacheContext;
-import com.ims.eval.entity.MultipleBrand;
+import com.ims.eval.entity.OrganizationEvaluation;
 import com.ims.eval.entity.OrganizationEvaluationInfo;
 import com.ims.eval.entity.dto.request.AddEvaluationInfoDTO;
 import com.ims.eval.entity.dto.response.MyuserResDTO;
 import com.ims.eval.entity.dto.response.OrganizationEvaluationInfoResDTO;
 import com.ims.eval.entity.dto.result.R;
-import com.ims.eval.service.IMultipleBrandService;
 import com.ims.eval.service.IOrganizationEvaluationInfoService;
+import com.ims.eval.service.IOrganizationEvaluationService;
 import com.ims.eval.service.custom.PostUserService;
 import com.ims.eval.util.ExcelUtil;
 import io.swagger.annotations.ApiOperation;
@@ -28,14 +28,13 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.servlet.http.HttpServletRequest;
 import java.io.InputStream;
 import java.util.*;
-import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
  * <p>
  * 考评指标明细
-
- 前端控制器
+ * <p>
+ * 前端控制器
  * </p>
  *
  * @author wang
@@ -56,6 +55,8 @@ public class OrganizationEvaluationInfoController {
 	@Autowired
 	private PostUserService postUserService;
 
+	@Autowired
+	private IOrganizationEvaluationService organizationEvaluationService;
 
 
 	/**
@@ -84,7 +85,7 @@ public class OrganizationEvaluationInfoController {
 		@RequestParam(value = "organizationEvaluationId", required = false) String organizationEvaluationId,
 		@RequestParam(value = "binSection", required = false) String binSection,
 		@RequestParam(value = "binStage", required = false) String binStage) {
-		List<Map> list = organizationEvaluationInfoService.getEvaluationIndicatorList(organizationEvaluationId, binSection,binStage, request);
+		List<Map> list = organizationEvaluationInfoService.getEvaluationIndicatorList(organizationEvaluationId, binSection, binStage, request);
 		return R.ok().data(list);
 	}
 
@@ -103,27 +104,35 @@ public class OrganizationEvaluationInfoController {
 		@RequestParam(value = "indicatorId", required = false) String indicatorId,
 		@RequestParam(value = "binSection", required = false) String binSection,
 		@RequestParam(value = "binStage", required = false) String binStage) {
+		LambdaQueryWrapper<OrganizationEvaluation> qw = new LambdaQueryWrapper<>();
+		qw.eq(OrganizationEvaluation::getId, organizationEvaluationId);
+		List<OrganizationEvaluation> orgEva = organizationEvaluationService.list(qw);
+		StringBuilder sb = new StringBuilder();
+		if (orgEva != null) {
+			sb.append(orgEva.get(0).getCheckCycle()).append("_").append(orgEva.get(0).getYear());
+			if (orgEva.get(0).getMonth() != null) {
+				sb.append("_").append(orgEva.get(0).getMonth());
+			}
+		}
+
 		ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
 		HttpServletRequest request = Objects.requireNonNull(attributes).getRequest();
 		JSONObject json = postUserService.getSysUser(request.getHeader("code"), request.getHeader("Blade-Auth"), request);
 		MyuserResDTO user = JSONObject.parseObject(json.getJSONObject("data").toJSONString(), MyuserResDTO.class);
 
-		Map list = organizationEvaluationInfoService.getEvaluationInfoList(organizationEvaluationId,organizationShortName, indicatorId,binSection,binStage, request);
-		List<Map> value2 = (List<Map>)list.get("value");
+		Map list = organizationEvaluationInfoService.getEvaluationInfoList(organizationEvaluationId, organizationShortName, indicatorId, binSection, binStage, request);
+		List<Map> value2 = (List<Map>) list.get("value");
 		String s = CacheContext.childCompanyId.get(user.getId());
-		if (s!=null){
-			List<String> childList = CacheContext.getChildList(s);
+		if (s != null) {
+			Set<String> childList = CacheContext.getChildList(s, sb.toString());
 			List<Map> value1 = value2.stream().filter(a -> childList.contains(a.get("organizationId"))).collect(Collectors.toList());
-			list.put("value",value1);
+			list.put("value", value1);
 		}
 
 		return R.ok().data(list);
 	}
 
 
-
-
-
 	@GetMapping("/download-excel")
 	public ResponseEntity<byte[]> downloadExcel(
 		@RequestParam(value = "organizationEvaluationId", required = false) String organizationEvaluationId,
@@ -132,7 +141,7 @@ public class OrganizationEvaluationInfoController {
 		@RequestParam(value = "binStage", required = false) String binStage) throws Exception {
 
 
-		byte[] excelBytes = organizationEvaluationInfoService.downloadExcel(organizationEvaluationId, indicatorId,binSection,binStage, request);
+		byte[] excelBytes = organizationEvaluationInfoService.downloadExcel(organizationEvaluationId, indicatorId, binSection, binStage, request);
 		HttpHeaders headers = new HttpHeaders();
 		headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
 		headers.setContentDispositionFormData("attachment", "example.xlsx");
@@ -143,9 +152,9 @@ public class OrganizationEvaluationInfoController {
 
 
 	@PostMapping("/import-excel")
-	public R importExcel(@RequestParam("file") MultipartFile file,HttpServletRequest request) throws Exception {
+	public R importExcel(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws Exception {
 
-		boolean b = organizationEvaluationInfoService.importExcel(file,request);
+		boolean b = organizationEvaluationInfoService.importExcel(file, request);
 
 		if (b) {
 			return R.ok().data(b);
@@ -217,7 +226,7 @@ public class OrganizationEvaluationInfoController {
 		@RequestParam(value = "indicatorName", required = false) String indicatorName,
 		@RequestParam(value = "binSection", required = false) String binSection,
 		@RequestParam(value = "isQuantified", required = false) String isQuantified) {
-		List<OrganizationEvaluationInfoResDTO> list = organizationEvaluationInfoService.finishValueList(organizationEvaluationId, dept, organizationShortName,indicatorName,binSection,isQuantified,request);
+		List<OrganizationEvaluationInfoResDTO> list = organizationEvaluationInfoService.finishValueList(organizationEvaluationId, dept, organizationShortName, indicatorName, binSection, isQuantified, request);
 		return R.ok().data(list);
 	}
 
@@ -250,7 +259,7 @@ public class OrganizationEvaluationInfoController {
 
 	@PostMapping(value = "/import")
 	@ResponseBody
-	public R importAlertrule(@RequestParam("file") MultipartFile file,HttpServletRequest request) {
+	public R importAlertrule(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
 
 		if (!file.isEmpty()) {
 			try {
@@ -274,7 +283,7 @@ public class OrganizationEvaluationInfoController {
 				}
 				boolean b = organizationEvaluationInfoService.saveOrUpdateBatch(bindingList);
 				if (b) {
-					organizationEvaluationInfoService.calculationByEvaluationId("","",bindingList.get(0).getOrganizationEvaluationId(),"");
+					organizationEvaluationInfoService.calculationByEvaluationId("", "", bindingList.get(0).getOrganizationEvaluationId(), "");
 					return R.ok().data(b);
 				} else {
 					return R.error().data("保存失败!");
@@ -292,13 +301,13 @@ public class OrganizationEvaluationInfoController {
 
 	@PostMapping(value = "/calculation")
 	@ApiOperation(value = "计算得分", notes = "计算得分")
-	public R calculation(@RequestParam(value = "id", required = false)String id,
-						  @RequestParam(value = "indicatorId", required = false) String indicatorId ,
-						  @RequestParam(value = "organizationEvaluationId", required = false) String organizationEvaluationId,
-						  @RequestParam(value = "optionCode", required = false) String optionCode) {
+	public R calculation(@RequestParam(value = "id", required = false) String id,
+						 @RequestParam(value = "indicatorId", required = false) String indicatorId,
+						 @RequestParam(value = "organizationEvaluationId", required = false) String organizationEvaluationId,
+						 @RequestParam(value = "optionCode", required = false) String optionCode) {
 
 		try {
-			boolean b = organizationEvaluationInfoService.calculationByEvaluationId(id,indicatorId,organizationEvaluationId,optionCode);
+			boolean b = organizationEvaluationInfoService.calculationByEvaluationId(id, indicatorId, organizationEvaluationId, optionCode);
 			if (b) {
 				return R.ok().data(b);
 			} else {

+ 37 - 5
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/MultipleBrandServiceImpl.java

@@ -27,10 +27,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.function.Function;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -52,12 +49,18 @@ public class MultipleBrandServiceImpl extends ServiceImpl<MultipleBrandMapper, M
 
 	@Override
 	public void  initData(){
+		initTree();
+		initTree2();
+	}
+
+	private void initTree() {
 		//按照单位营业收入配置
 		IPage<MultipleBrand> tree = getMultipleBranTree(1, 1000, null, null, "", "", "", null);
 		List<MultipleBrand> records = tree.getRecords();
+
 		for (MultipleBrand record : records) {
 			CacheContext.brandMap.put(record.getOrganizationId(), record);
-			if (record.getChildren()==null) continue;
+			if (record.getChildren() == null) continue;
 			for (MultipleBrand child : record.getChildren()) {
 				CacheContext.brandMap.put(child.getOrganizationId(), child);
 			}
@@ -65,6 +68,35 @@ public class MultipleBrandServiceImpl extends ServiceImpl<MultipleBrandMapper, M
 	}
 
 
+	private void initTree2() {
+		//按照单位营业收入配置
+		IPage<MultipleBrand> tree = getMultipleBranTree(1, 1000, null, null, "", "", "", null);
+		List<MultipleBrand> records = tree.getRecords();
+		Map<String, List<MultipleBrand>> collect = records.stream().peek(mb -> {
+			if ("NDKP".equals(mb.getCheckCycle())) {
+				mb.setCheckCycle(mb.getCheckCycle() + "_" + mb.getYear() + "_" + mb.getMonth());
+			} else {
+				mb.setCheckCycle(mb.getCheckCycle() + "_" + mb.getYear() + "_" + mb.getMonth());
+			}
+		}).collect(Collectors.groupingBy(MultipleBrand::getCheckCycle));
+
+		for (Map.Entry<String, List<MultipleBrand>> entry : collect.entrySet()) {
+			Map<String, MultipleBrand> aaa = new HashMap<>();
+			for (MultipleBrand record : entry.getValue()) {
+				aaa.put(record.getOrganizationId(), record);
+				if (record.getChildren() == null) {
+					continue;
+				}
+				for (MultipleBrand child : record.getChildren()) {
+					aaa.put(child.getOrganizationId(), child);
+				}
+			}
+			CacheContext.groupBrandMap.put(entry.getKey(), aaa);
+		}
+	}
+
+
+
 	@Override
 	public IPage<MultipleBrand> getMultipleBranTree(Integer pageNum, Integer pageSize, String id, String parentId, String binSection, String checkCycle, String year, String month) {
 		Page<Indicator> page = new Page<>(pageNum, pageSize);