Bladeren bron

代码优化

wangchangsheng 1 jaar geleden
bovenliggende
commit
e2b3232d87

+ 64 - 2
ims-service/ims-eval/src/main/java/com/ims/eval/config/permission/PermissionAspect.java

@@ -56,7 +56,8 @@ public class PermissionAspect implements Interceptor {
 	//扫描的包路径,需要权限的加在mapper类及方法上
 	private String packagePath = "com.ims.eval.dao";
 	private final static String DEPT_ID = "dept_id";
-	private final static String DEPT_MARK = "BM0001";
+	private final static String DEPT_MARK = "BM0001";//部门
+	private final static String POS_MARK = "GW0001";//岗位
 
 	/**  start  以下定义的数据需要和部门表一致       **/
 	//全部数据权限
@@ -95,6 +96,65 @@ public class PermissionAspect implements Interceptor {
 		MyuserResDTO user = getSysUser(code);
 		DataDictionary dept = getSysDept(user);
 		if (user == null || dept == null) {
+			try {
+				//反射扫包会比较慢,这里做了个懒加载
+				if (classNames == null) {
+					//扫描指定包路径下所有包含指定注解的类
+					Set<Class<?>> classSet = ClassUtil.scanPackageByAnnotation(packagePath, DataPermission.class);
+					if (classSet == null && classSet.size() == 0) {
+						classNames = new ArrayList<>();
+					} else {
+						//取得类全名
+						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("."));
+				// 如果不是指定的方法,直接结束拦截
+				if (!classNames.contains(newId)) {
+					return invocation.proceed();
+				}
+				String newName = mappedStatement.getId().substring(mappedStatement.getId().lastIndexOf(".") + 1, mappedStatement.getId().length());
+				Class<?> clazz = Class.forName(newId);
+
+				if (!methodNames.containsKey(newId + "-" + newName)){
+					for (Method method : clazz.getDeclaredMethods()) {
+						//方法是否含有DataPermission注解,如果含有注解则将数据结果过滤
+						if (method.isAnnotationPresent(DataPermission.class)) {
+							DataPermission dataPermission = method.getAnnotation(DataPermission.class);
+							if (dataPermission != null) {
+								methodNames.put(newId + "-" + method.getName(), dataPermission.isPermission());
+							}
+						} else {
+							methodNames.put(newId + "-" + method.getName(), true);
+						}
+					}
+				}
+
+				//是否开启数据权限
+				boolean isPermission = true;
+				isPermission = methodNames.get(newId + "-" + newName);
+				if (isPermission) {
+					// 获取到原始sql语句
+					String sql = statementHandler.getBoundSql().getSql();
+					// 解析并返回新的SQL语句,只处理查询sql
+					if (mappedStatement.getSqlCommandType().toString().equals("SELECT")) {
+						sql = getSql(sql, "");
+					}
+					// 修改sql
+					metaObject.setValue("delegate.boundSql.sql", sql);
+				}
+			} catch (Exception e) {
+				log.error("数据权限隔离异常:", e);
+			}
+
+
 			return invocation.proceed();
 		}
 
@@ -147,7 +207,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();
@@ -181,6 +241,8 @@ public class PermissionAspect implements Interceptor {
 			Table table = (Table)plainSelect.getFromItem();
 			if (table.getAlias() != null){
 				condition = table.getAlias().getName() + "." + DEPT_ID + "='" + deptId + "'";;
+			}else {
+				condition = table.getAlias().getName() + "." + DEPT_ID + "=''";;
 			}
 
 			//取得原SQL的where条件

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

@@ -3,9 +3,13 @@ package com.ims.eval.controller;
 
 
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.ims.eval.entity.OrganizationStructure;
 import com.ims.eval.entity.dto.result.R;
 import com.ims.eval.service.IOrganizationStructureService;
+import com.ims.eval.service.custom.PostService;
+import com.ims.eval.service.custom.PostUserService;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -31,6 +35,13 @@ public class OrganizationStructureController {
 
 	@Autowired
 	private IOrganizationStructureService organizationStructureService;
+
+
+	@Autowired
+	private PostService postService;
+
+	@Autowired
+	private PostUserService postUserService;
 	/**
 	 * 添加
 	 *
@@ -84,5 +95,44 @@ public class OrganizationStructureController {
 	}
 
 
+	@GetMapping(value = "getPostList")
+	public R getPostList(
+		@RequestParam(value = "current", required = false) Integer current,
+		@RequestParam(value = "size", required = false) Integer size,
+		@RequestParam(value = "orgId", required = false) String orgId) {
+
+		try {
+			Object list = postService.getPostList(current,size,orgId, request);
+			if(null !=list){
+				return R.ok().data(list);
+			}
+			return R.customError("失败");
+		} catch (Exception e) {
+			return R.customError("失败");
+		}
+
+	}
+
+
+	@GetMapping(value = "getPostUserList")
+	public R getPostUserList(
+		@RequestParam(value = "current", required = false) Integer current,
+		@RequestParam(value = "size", required = false) Integer size,
+		@RequestParam(value = "posId", required = false) String posId) {
+
+		try {
+			Object list = postUserService.getPostUserList(current,size,posId, request);
+			if(null !=list){
+				return R.ok().data(list);
+			}
+			return R.customError("失败");
+		} catch (Exception e) {
+			e.printStackTrace();
+			return R.customError("失败");
+		}
+
+	}
+
+
 
 }

+ 1 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/dao/OrganizationEvaluationInfoMapper.java

@@ -58,6 +58,7 @@ public interface OrganizationEvaluationInfoMapper extends BaseMapper<Organizatio
 											@Param("binStage") String binStage);
 
 
+	@DataPermission(isPermission = false)
 	List<OrganizationEvaluationInfoResDTO> selectEvaluationInfoList(@Param("organizationEvaluationId") String organizationEvaluationId,
 											@Param("organizationShortName") String organizationShortName,
 											@Param("indicatorId") String indicatorId,

+ 39 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/entity/custom/Post.java

@@ -0,0 +1,39 @@
+package com.ims.eval.entity.custom;
+
+
+import lombok.Data;
+
+/**
+ * 岗位
+ */
+@Data
+public class Post {
+	private static final long serialVersionUID = 1L;
+
+
+	private String id;
+	private String name;
+	private String seqNo;
+	private String code;
+	private String orgId;
+	private String orgName;
+	private String specId;
+	private String specName;
+	private String createBy;
+	private String createDate;
+	private String updateBy;
+	private String updateDate;
+	private String remarks;
+	private String delFlag;
+	private String companyId;
+	private String deptId;
+	private String posType;
+	private String posClass;
+	private String outId;
+	private String status;
+	private String sysOrgName;
+	private String companyName;
+	private String deptName;
+
+
+}

+ 35 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/entity/custom/PostUser.java

@@ -0,0 +1,35 @@
+package com.ims.eval.entity.custom;
+
+import lombok.Data;
+
+/**
+ * 岗位user
+ */
+@Data
+public class PostUser {
+	private static final long serialVersionUID = 1L;
+
+	private String id;// "ddeee6a31db24e41a4d5af8382c4bb03",
+	private String posId;// "50174897",
+	private String posName;// "高级主管",
+	private String userId;// "515f2adecc4f0c7cd2725e56b78581fd",
+	private String userName;// "王熠楠",
+	private String mainPos;// "1",
+	private String createBy;// "",
+	private String createDate;// "",
+	private String updateBy;// "",
+	private String updateDate;// "",
+	private String sort;// -1,
+	private String outId;// "",
+	private String orgId;// "50174730",
+	private String orgName;// "合规管理处",
+	private String companyName;// "国电电力发展股份有限公司本部",
+	private String deptName;// "企业管理与法律事务部",
+	private String loginName;// "wangyinan",
+	private String no;// "16010126",
+	private String mobile;// "",
+	private String uunitName;// "国电电力发展股份有限公司本部",
+	private String udeptName;// "",
+	private String posCode;// "29851"
+
+}

+ 1 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/entity/dto/response/EvaluationScoreInfoResDTO.java

@@ -24,6 +24,7 @@ public class EvaluationScoreInfoResDTO {
 	private String indicatorName;
 	private String evaluateRuleId;
 	private String  evaluateRuleInfoId;
+	private Boolean isQuantified;
 
 
 

+ 1 - 4
ims-service/ims-eval/src/main/java/com/ims/eval/entity/dto/response/IndicatorResDTO.java

@@ -68,10 +68,7 @@ public class IndicatorResDTO {
 	private String deptName;
 
 
-	/**
-	 * 能否量化2
-	 */
-	private Boolean isQuantified2;
+
 
 
 

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

@@ -0,0 +1,50 @@
+package com.ims.eval.service.custom;
+
+
+
+import com.alibaba.fastjson.JSON;
+import com.ims.eval.config.ImaConfig;
+import com.ims.eval.entity.dto.result.ResultInfo;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.*;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+
+
+@Service
+@Slf4j
+public class PostService {
+
+
+
+	@Autowired
+	private RestTemplate restTemplate;
+
+
+	@Autowired
+	private ImaConfig imaConfig;
+
+
+	public Object getPostList(Integer current, Integer size, String orgId, 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/pgpos/page?current={1}&size={2}&orgId={3}", HttpMethod.GET, param, String.class, current,size,orgId);
+		log.info("\n code:{}\n header:{}\n body:{}\n", responseEntity2.getStatusCodeValue(), responseEntity2.getHeaders(), responseEntity2.getBody());
+		if (200 == responseEntity2.getStatusCodeValue()) {
+//			return JSON.parseArray(responseEntity2.getBody());
+			ResultInfo resultInfo = JSON.parseObject(responseEntity2.getBody(), ResultInfo.class);
+			if(200 == resultInfo.getCode()){
+				return resultInfo.getData();
+			}
+			return null;
+		}
+		return null;
+	}
+
+}

+ 48 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/service/custom/PostUserService.java

@@ -0,0 +1,48 @@
+package com.ims.eval.service.custom;
+
+
+import com.alibaba.fastjson.JSON;
+import com.ims.eval.config.ImaConfig;
+import com.ims.eval.entity.dto.result.ResultInfo;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.*;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+
+@Service
+@Slf4j
+public class PostUserService {
+
+	@Autowired
+	private RestTemplate restTemplate;
+
+
+	@Autowired
+	private ImaConfig imaConfig;
+
+
+	public Object getPostUserList(Integer current, Integer size, String posId, 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);									//ims-idms/pgposuser/page?
+		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()) {
+			ResultInfo resultInfo = JSON.parseObject(responseEntity2.getBody(), ResultInfo.class);
+			if(200 == resultInfo.getCode()){
+				return resultInfo.getData();
+			}
+			return null;
+		}
+		return null;
+	}
+
+
+
+
+}

+ 10 - 5
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/OrganizationEvaluationInfoServiceImpl.java

@@ -494,7 +494,7 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
 					titleArray.add(titlemap);
 
 				}
-				title.put(childCodeEntry.getKey().split(",")[1], titleArray);
+				title.put(childCodeEntry.getKey().split(",")[1]+"-对标", titleArray);
 			}
 			Map deptstateMap = new LinkedHashMap();
 			List<Map> titlestateArray = new ArrayList<>();
@@ -997,20 +997,25 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
 					info.setIndicatorId(addEvaluationInfoDTO.getIndicatorId());
 					info.setIndicatorDictionaryId(d.getId());
 					info.setOptionCode(d.getOptionCode());
-					info.setIsQuantified(d.getIsQuantified2());
+					info.setIsQuantified(d.getIsQuantified());
 					if (null != optionMap.get(d.getChildCode() + "_" + d.getOptionCode())) {
 						Object value = optionMap.get(d.getChildCode() + "_" +d.getOptionCode());
 						if (null != value) {
 							info.setNonQuantifiedValue(String.valueOf(value));
-							if (d.getIsQuantified2()) {
-								info.setQuantifiedValue(Double.valueOf(value.toString()));
+							if (d.getIsQuantified()) {
+
+								if (MathCalculatorUtil.isNumber(value.toString())) {
+									info.setQuantifiedValue(Double.valueOf(value.toString()));
+								} else {
+									info.setQuantifiedValue(0);
+								}
 							}
 						}
 					}
 					info.setChildCode(d.getChildCode());
 					info.setDeptId(d.getDeptId());
 					info.setCreateTime(new Date());
-					this.saveOrUpdate(info);
+					saveOrUpdate(info);
 				}
 			}
 		}

+ 7 - 1
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/OrganizationEvaluationServiceImpl.java

@@ -747,7 +747,13 @@ public class OrganizationEvaluationServiceImpl extends ServiceImpl<OrganizationE
 							}
 						}else  {
 							//获取每个单元格的数据
-							opmap.put(dto.getChildCode()+"_"+dto.getOptionCode(),dto.getNonQuantifiedValue());
+							if(dto.getIsQuantified()){
+
+								opmap.put(dto.getChildCode()+"_"+dto.getOptionCode(),dto.getQuantifiedValue());
+							}else {
+								opmap.put(dto.getChildCode()+"_"+dto.getOptionCode(),dto.getNonQuantifiedValue());
+							}
+
 						}
 
 						//综合得分

+ 2 - 3
ims-service/ims-eval/src/main/resources/mappers/IndicatorMapper.xml

@@ -96,12 +96,11 @@
         i.id indicatorId,
         i.dept_id,
         i.bin_section,
-        i.is_quantified isQuantified,
+        d.is_quantified isQuantified,
         d.option_code optionCode,
         d.option_name optionName,
         d.child_code,
-        d.child_name,
-        d.is_quantified isQuantified2
+        d.child_name
         FROM
         INDICATOR i
         LEFT JOIN indicator_dictionary d ON i.ID = d.indicator_id

+ 1 - 0
ims-service/ims-eval/src/main/resources/mappers/OrganizationEvaluationMapper.xml

@@ -98,6 +98,7 @@
         d.child_code,
         oi.option_code,
         d.option_name,
+        d.is_quantified,
         oi.quantified_value,
         oi.non_quantified_value,
         ei.evaluate_rule_id,