Browse Source

代码优化

wangchangsheng 1 năm trước cách đây
mục cha
commit
9eb44a3b89

+ 66 - 10
ims-service/ims-eval/src/main/java/com/ims/eval/config/permission/PermissionAspect.java

@@ -1,14 +1,16 @@
 package com.ims.eval.config.permission;
 
 import cn.hutool.core.util.ClassUtil;
-import com.alibaba.fastjson.JSON;
 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.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.custom.PostUserService;
 import lombok.extern.slf4j.Slf4j;
 import net.sf.jsqlparser.JSQLParserException;
 import net.sf.jsqlparser.expression.Expression;
@@ -30,10 +32,10 @@ import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Before;
 import org.aspectj.lang.annotation.Pointcut;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Component;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
-import springfox.documentation.annotations.Cacheable;
 
 import javax.servlet.http.HttpServletRequest;
 import java.lang.reflect.Method;
@@ -53,6 +55,12 @@ public class PermissionAspect implements Interceptor {
 	@Autowired
 	private RemoteServiceBuilder serviceBuilder;
 
+
+	@Autowired
+	private HttpServletRequest request;
+	@Autowired
+	private PostUserService postUserService;
+
 	//扫描的包路径,需要权限的加在mapper类及方法上
 	private String packagePath = "com.ims.eval.dao";
 	private final static String DEPT_ID = "dept_id";
@@ -93,9 +101,36 @@ public class PermissionAspect implements Interceptor {
 
 	@Override
 	public Object intercept(Invocation invocation) throws Throwable {
+		//部门权限
 		MyuserResDTO user = getSysUser(code);
 		DataDictionary dept = getSysDept(user);
-		if (user == null || dept == null) {
+
+		//岗位权限
+		DataDictionary post = null;
+		// 比较Scope字段并取最大值
+		Integer scope = 2;//1:全部;2部门;3个人
+		if(null !=user){
+			if(null != dept){
+				scope = dept.getScope();
+			}
+
+			List<PostUser> postUserList = getUserPostList(user.getId());
+			post = getSysPost(postUserList);
+			// 比较Scope字段并取最大值
+			if(null != post){
+				scope = Integer.min(scope, post.getScope());
+			}
+		}
+
+
+		//权限最大值不需要后续处理
+		if (scope.equals(DATA_SCOPE_ALL)){
+			return invocation.proceed();
+		}
+
+
+		//人员和部门数据为空
+		if (user == null || dept == null ) {
 			try {
 				//反射扫包会比较慢,这里做了个懒加载
 				if (classNames == null) {
@@ -139,7 +174,7 @@ public class PermissionAspect implements Interceptor {
 
 				//是否开启数据权限
 				boolean isPermission = true;
-				isPermission = methodNames.get(newId + "-" + newName);
+				isPermission = null != methodNames.get(newId + "-" + newName) ?methodNames.get(newId + "-" + newName) :false;
 				if (isPermission) {
 					// 获取到原始sql语句
 					String sql = statementHandler.getBoundSql().getSql();
@@ -158,10 +193,6 @@ public class PermissionAspect implements Interceptor {
 			return invocation.proceed();
 		}
 
-		Integer scope = dept.getScope();
-		if (scope.equals(DATA_SCOPE_ALL)){
-			return invocation.proceed();
-		}
 		if (scope.equals(DATA_SCOPE_DEPT)) {
 			String deptId = dept.getDataKey();
 			try {
@@ -273,7 +304,7 @@ public class PermissionAspect implements Interceptor {
 	}
 
 	@Cacheable(value = "user_code")
-	private MyuserResDTO getSysUser(String code) {
+	public MyuserResDTO getSysUser(String code) {
 		if (StringUtils.isBlank(code) || code.toLowerCase().equals("null")){
 			return null;
 		}
@@ -282,11 +313,36 @@ public class PermissionAspect implements Interceptor {
 		return user;
 	}
 
-	private DataDictionary getSysDept(MyuserResDTO user){
+	@Cacheable(cacheNames = "user_id",key= "#userId")
+	public List<PostUser> getUserPostList(String userId) {
+		JSONObject postuserjson  = (JSONObject)postUserService.getUserPostList(null,null,userId,request);
+		if(null !=postuserjson){
+			PagResult pagResult =	JSONObject.parseObject(postuserjson.toJSONString(), PagResult.class);
+			List<PostUser> list = pagResult.getRecords().toJavaList(PostUser.class);
+			return list;
+		}
+		return null;
+	}
+
+	@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();
 			return any.isPresent() ?  any.get() : null;
 		}
 		return null;
 	}
+
+
+	@Cacheable(value = "user_id_post")
+	public DataDictionary getSysPost(List<PostUser> postUsers){
+		if (postUsers != null  && postUsers.size()>0 && CacheContext.ddSuperKeyMap.containsKey(POS_MARK)){
+			List<DataDictionary> list  = CacheContext.ddSuperKeyMap.get(POS_MARK).stream()
+				.filter(data -> postUsers.stream().anyMatch(user -> user.getPosCode().equals(data.getDataKey()))).collect(Collectors.toList());
+				DataDictionary maxScopeData =  list.stream().min(Comparator.comparing(DataDictionary::getScope))
+				.orElse(null);
+			return maxScopeData;
+		}
+		return null;
+	}
 }

+ 40 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/controller/OrganizationStructureController.java

@@ -95,6 +95,13 @@ public class OrganizationStructureController {
 	}
 
 
+	/**
+	 * 根据组织获取岗位
+	 * @param current
+	 * @param size
+	 * @param orgId
+	 * @return
+	 */
 	@GetMapping(value = "getPostList")
 	public R getPostList(
 		@RequestParam(value = "current", required = false) Integer current,
@@ -114,6 +121,13 @@ public class OrganizationStructureController {
 	}
 
 
+	/**
+	 * 根据岗位获取人员
+	 * @param current
+	 * @param size
+	 * @param posId
+	 * @return
+	 */
 	@GetMapping(value = "getPostUserList")
 	public R getPostUserList(
 		@RequestParam(value = "current", required = false) Integer current,
@@ -134,5 +148,31 @@ public class OrganizationStructureController {
 	}
 
 
+	/**
+	 * 更具人员获取岗位
+	 * @param current
+	 * @param size
+	 * @param userId
+	 * @return
+	 */
+	@GetMapping(value = "getUserPostList")
+	public R getUserPostList(
+		@RequestParam(value = "current", required = false) Integer current,
+		@RequestParam(value = "size", required = false) Integer size,
+		@RequestParam(value = "userId", required = false) String userId) {
+
+		try {
+			Object list = postUserService.getUserPostList(current,size,userId, request);
+			if(null !=list){
+				return R.ok().data(list);
+			}
+			return R.customError("失败");
+		} catch (Exception e) {
+			return R.customError("失败");
+		}
+
+	}
+
+
 
 }

+ 13 - 7
ims-service/ims-eval/src/main/java/com/ims/eval/dao/EvaluateRuleMapper.java

@@ -19,14 +19,20 @@ import java.util.List;
  */
 public interface EvaluateRuleMapper extends BaseMapper<EvaluateRule> {
 
-	IPage<EvaluateRule>  selectListPage(Page page, @Param("id") String id,
-										@Param("des") String des,
-										@Param("binSection") String binSection,
-										@Param("binStage") String binStage,
-										@Param("checkCycle") String checkCycle,
-										@Param("year")String year);
+	IPage<EvaluateRule> selectListPage(Page page, @Param("id") String id,
+									   @Param("des") String des,
+									   @Param("binSection") String binSection,
+									   @Param("binStage") String binStage,
+									   @Param("checkCycle") String checkCycle,
+									   @Param("year") String year);
 
 
-	List <EvaluateRuleInfoResDTO> selectListInIdsInfos(List<String> ids, String binSection, String binStage);
+	List<EvaluateRuleInfoResDTO> selectListInIdsInfos(List<String> ids, String binSection, String binStage);
+
+
+	List<EvaluateRule> selectEvaluateRuleList(@Param("binSection") String binSection,
+											  @Param("binStage") String binStage,
+											  @Param("checkCycle") String checkCycle,
+											  @Param("year") String year);
 
 }

+ 16 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/entity/dto/result/PagResult.java

@@ -0,0 +1,16 @@
+package com.ims.eval.entity.dto.result;
+
+import com.alibaba.fastjson.JSONArray;
+import lombok.Data;
+
+
+@Data
+public class PagResult {
+
+	private Integer total;
+	private Integer current;
+	private Boolean hitCount;
+	private Integer pages;
+	private Integer size;
+	private JSONArray records;
+}

+ 2 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/service/IEvaluateRuleService.java

@@ -30,6 +30,8 @@ public interface IEvaluateRuleService extends IService<EvaluateRule> {
 
 	List<EvaluateRule> getEvaluateRuleByYear( String binSection, String binStage,String checkCycle,String year);
 
+	List<EvaluateRule> getEvaluateRuleList(String binSection, String binStage, String checkCycle, String year);
+
 
 
 }

+ 3 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/service/custom/PostService.java

@@ -47,4 +47,7 @@ public class PostService {
 		return null;
 	}
 
+
+
+
 }

+ 19 - 1
ims-service/ims-eval/src/main/java/com/ims/eval/service/custom/PostUserService.java

@@ -29,7 +29,7 @@ public class PostUserService {
 		HttpHeaders headers = new HttpHeaders();
 		headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
 		headers.add("Blade-Auth", "bearer "+request.getHeader("Blade-Auth"));
-		HttpEntity<Map> param = new HttpEntity<>(null, headers);									//ims-idms/pgposuser/page?
+		HttpEntity<Map> param = new HttpEntity<>(null, headers);
 		ResponseEntity<String> responseEntity2 = restTemplate.exchange(imaConfig.getGatewayUrl() + "/ims-idms/pgposuser/page?current={1}&size={2}&posId={3}", HttpMethod.GET, param, String.class, current,size,posId);
 		log.info("\n code:{}\n header:{}\n body:{}\n", responseEntity2.getStatusCodeValue(), responseEntity2.getHeaders(), responseEntity2.getBody());
 		if (200 == responseEntity2.getStatusCodeValue()) {
@@ -43,6 +43,24 @@ public class PostUserService {
 	}
 
 
+	public Object getUserPostList(Integer current, Integer size, String userId, HttpServletRequest request) {
+		HttpHeaders headers = new HttpHeaders();
+		headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
+		headers.add("Blade-Auth", "bearer "+request.getHeader("Blade-Auth"));
+		HttpEntity<Map> param = new HttpEntity<>(null, headers);
+		ResponseEntity<String> responseEntity2 = restTemplate.exchange(imaConfig.getGatewayUrl() + "/ims-idms/pgposuser/page?current={1}&size={2}&userId={3}", HttpMethod.GET, param, String.class, current,size,userId);
+		log.info("\n code:{}\n header:{}\n body:{}\n", responseEntity2.getStatusCodeValue(), responseEntity2.getHeaders(), responseEntity2.getBody());
+		if (200 == responseEntity2.getStatusCodeValue()) {
+			ResultInfo resultInfo = JSON.parseObject(responseEntity2.getBody(), ResultInfo.class);
+			if(200 == resultInfo.getCode()){
+				return resultInfo.getData();
+			}
+			return null;
+		}
+		return null;
+	}
+
+
 
 
 }

+ 6 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/EvaluateRuleServiceImpl.java

@@ -191,4 +191,10 @@ public class EvaluateRuleServiceImpl extends ServiceImpl<EvaluateRuleMapper, Eva
 		return super.saveOrUpdate(entity);
 
 	}
+
+	@Override
+	public List<EvaluateRule> getEvaluateRuleList(String binSection, String binStage, String checkCycle, String year) {
+		List<EvaluateRule> list = baseMapper.selectEvaluateRuleList(binSection, binStage, checkCycle, year);
+		return list;
+	}
 }

+ 24 - 18
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/OrganizationEvaluationRuleServiceImpl.java

@@ -8,7 +8,6 @@ import com.ims.eval.cache.CacheContext;
 import com.ims.eval.config.CustomException;
 import com.ims.eval.entity.*;
 import com.ims.eval.dao.OrganizationEvaluationRuleMapper;
-import com.ims.eval.entity.dto.request.OrganizationEvaluationRuleDTO;
 import com.ims.eval.service.IDeptResponsibilityService;
 import com.ims.eval.service.IEvaluateRuleService;
 import com.ims.eval.service.IOrganizationEvaluationRuleService;
@@ -105,27 +104,34 @@ public class OrganizationEvaluationRuleServiceImpl extends ServiceImpl<Organizat
 
 		List<OrganizationEvaluationRule> list = baseMapper.selectListAll(id, organizationName, organizationId, organizationType, binSection, binStage, evaluationCycle,year);
 
-		list().stream().forEach(l->{
-			l.setBinSectionName(null == CacheContext.ddNameMap.get(l.getBinSection()) ? "" :CacheContext.ddNameMap.get(l.getBinSection()));
-
-			StringBuilder binStageName =  new StringBuilder();
-			for (String stage : l.getBinStage().split(",")){
-				binStageName.append(null == CacheContext.ddNameMap.get(stage) ? "" :CacheContext.ddNameMap.get(stage)).append(",");
-			}
+		List<EvaluateRule> dtoList = evaluateRuleService.getEvaluateRuleList("","","",year);
+		Map<String, EvaluateRule> dtoMap = dtoList.stream().collect(Collectors.toMap(EvaluateRule::getId, dto -> dto));
 
-			l.setBinStageName(binStageName.toString().length()>0?binStageName.toString().substring(0,binStageName.toString().length()-1):"");
+		try {
+			list().stream().forEach(l->{
+				l.setBinSectionName(null == CacheContext.ddNameMap.get(l.getBinSection()) ? "" :CacheContext.ddNameMap.get(l.getBinSection()));
 
-			StringBuilder ruleName = new StringBuilder();
-			for (String ruleId :l.getEvaluateRuleId().split(",")){
-				EvaluateRule rulebyid = evaluateRuleService.getById(ruleId);
-				if(null != rulebyid){
-					ruleName.append(rulebyid.getRuleName()).append(",");
+				StringBuilder binStageName =  new StringBuilder();
+				for (String stage : l.getBinStage().split(",")){
+					binStageName.append(null == CacheContext.ddNameMap.get(stage) ? "" :CacheContext.ddNameMap.get(stage)).append(",");
 				}
 
-			}
-			l.setEvaluateRuleName(ruleName.toString().length()>0?ruleName.toString().substring(0,ruleName.toString().length()-1):"");
+				l.setBinStageName(binStageName.toString().length()>0?binStageName.toString().substring(0,binStageName.toString().length()-1):"");
 
-		});
+				StringBuilder ruleName = new StringBuilder();
+
+				for (String ruleId :l.getEvaluateRuleId().split(",")){
+					EvaluateRule rulebyid = dtoMap.get(ruleId);
+					if(null != rulebyid){
+						ruleName.append(rulebyid.getRuleName()).append(",");
+					}
+				}
+				l.setEvaluateRuleName(ruleName.toString().length()>0?ruleName.toString().substring(0,ruleName.toString().length()-1):"");
+
+			});
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
 
 		return list;
 	}
@@ -269,7 +275,7 @@ public class OrganizationEvaluationRuleServiceImpl extends ServiceImpl<Organizat
 		if (StringUtils.isNotEmpty(organizationId)) {
 			qw.lambda().eq(OrganizationEvaluationRule::getOrganizationId, organizationId);
 		}
-		
+
 		//没有删除标记,并且是需要考核的单位
 		qw.lambda().eq(OrganizationEvaluationRule::getDelFlag, false);
 		qw.lambda().eq(OrganizationEvaluationRule::getIsCheck, true);

+ 31 - 0
ims-service/ims-eval/src/main/resources/mappers/EvaluateRuleMapper.xml

@@ -90,5 +90,36 @@
         </where>
 
     </select>
+    <select id="selectEvaluateRuleList" resultType="com.ims.eval.entity.EvaluateRule">
+
+        SELECT
+        r.*,
+        b.stage_name binStageName,
+        bs.section_name binSectionName
+        FROM
+        evaluate_rule r
+        LEFT JOIN bin_stage b  ON r.bin_stage = b.id
+        LEFT JOIN bin_section bs  ON r.bin_section = bs.id
+        <where>
+
+            r.enable = true
+            <if test="binSection !=null and binSection !=''">
+                AND r.bin_section = #{binSection}
+            </if>
+
+            <if test="binStage !=null and binStage !=''">
+                AND r.bin_stage = #{binStage}
+            </if>
+            <if test="checkCycle !=null and checkCycle !=''">
+                AND r.check_cycle = #{checkCycle}
+            </if>
+            <if test="year !=null and year !=''">
+                AND r.year = #{year}
+            </if>
+
+            order by  r.create_time desc
+        </where>
+
+    </select>
 
 </mapper>