|
|
@@ -1,32 +1,31 @@
|
|
|
package com.lc.ibps.platform.plan.job;
|
|
|
|
|
|
import com.lc.ibps.base.core.util.AppUtil;
|
|
|
+import com.lc.ibps.base.core.util.Collections;
|
|
|
+import com.lc.ibps.base.core.util.JacksonUtil;
|
|
|
+import com.lc.ibps.base.core.util.json.JsonUtil;
|
|
|
import com.lc.ibps.org.auth.persistence.entity.ResourcesPo;
|
|
|
import com.lc.ibps.org.auth.repository.RoleResourceRepository;
|
|
|
import com.lc.ibps.org.party.persistence.entity.PartyRolePo;
|
|
|
import com.lc.ibps.org.party.repository.PartyRoleRepository;
|
|
|
+import net.sf.json.JSONArray;
|
|
|
+import net.sf.json.JSONObject;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.quartz.JobExecutionContext;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
public class ResourceRuleJob extends AbstractJob {
|
|
|
|
|
|
- @Resource
|
|
|
- private RoleResourceRepository roleResourceRepository;
|
|
|
- @Resource
|
|
|
- private PartyRoleRepository partyRoleRepository ;
|
|
|
+ private RoleResourceRepository roleResourceRepository = AppUtil.getBean(RoleResourceRepository.class);
|
|
|
+ private PartyRoleRepository partyRoleRepository = AppUtil.getBean(PartyRoleRepository.class);;
|
|
|
@Override
|
|
|
public void executeJob(JobExecutionContext context) throws Exception {
|
|
|
+ //STEP 1. get menu - role.
|
|
|
List<MenuVO> allMenuList = null;
|
|
|
- partyRoleRepository = AppUtil.getBean(PartyRoleRepository.class);
|
|
|
- roleResourceRepository = AppUtil.getBean(RoleResourceRepository.class);
|
|
|
List<PartyRolePo> partyRolePos = partyRoleRepository.queryWithSys();
|
|
|
for (PartyRolePo rolePo : partyRolePos) {
|
|
|
List<ResourcesPo> roleResTreeChecked = roleResourceRepository.getRoleResTreeChecked(rolePo.getId(), rolePo.getSubSystemId());
|
|
|
@@ -42,7 +41,7 @@ public class ResourceRuleJob extends AbstractJob {
|
|
|
}else{
|
|
|
for (MenuVO menu : allMenuList) {
|
|
|
Optional<ResourcesPo> optional = roleResTreeChecked.stream().parallel().filter(x -> x.getId().equals(menu.id)).findAny();
|
|
|
- if(optional.isPresent()) menu.roles.add(optional.get().getChecked().equalsIgnoreCase("true")?"√":" ");
|
|
|
+ if(optional.isPresent()) menu.roles.add(optional.get().getChecked().equalsIgnoreCase("true")?"√":"");
|
|
|
else menu.roles.add("");
|
|
|
}
|
|
|
}
|
|
|
@@ -55,8 +54,71 @@ public class ResourceRuleJob extends AbstractJob {
|
|
|
System.out.println(s + "|" + s1);
|
|
|
}
|
|
|
}
|
|
|
+ System.out.println("------------------------------------------------------");
|
|
|
|
|
|
+ //Step 2. get button - role
|
|
|
|
|
|
+ System.out.println("" +"|"+partyRolePos.stream().map(x->x.getName()).collect(Collectors.joining("|")));
|
|
|
+
|
|
|
+ List<String> roleList = partyRolePos.stream().map(x -> x.getName()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<Map<String, Object>> list = fetchRecords("button_role_1");
|
|
|
+ if (list != null) {
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ String filterValue = (String) map.get("function_buttons_");
|
|
|
+ String id = (String) map.get("id_");
|
|
|
+ for (MenuVO menu : allMenuList) {
|
|
|
+ if(menu.id.equalsIgnoreCase(id)){
|
|
|
+ menu.buttons = fetchButtonRoles(filterValue);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (MenuVO menu : allMenuList) {
|
|
|
+ if(menu.buttons.size()>0){
|
|
|
+ String s = StringUtils.trim(menu.parentCode + "/" + menu.menuCode);
|
|
|
+ List<String> ss = new ArrayList<>();
|
|
|
+ ss.add(s);
|
|
|
+ for (String role : roleList) {
|
|
|
+ ss.add(menu.buttons.containsKey(role)?StringUtils.join(menu.buttons.get(role), ","):"");
|
|
|
+ }
|
|
|
+ System.out.println(StringUtils.join(ss, "|"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String,List<String>> fetchButtonRoles(String filterValue){
|
|
|
+ Map<String,List<String>> map = new HashMap<>();
|
|
|
+ JSONObject buttonsJson = JSONObject.fromObject(JacksonUtil.toMap(filterValue));
|
|
|
+ String jsonStr = JsonUtil.getString(buttonsJson, "function_buttons");
|
|
|
+ JSONArray jsonArray = JSONArray.fromObject(JacksonUtil.getDTOList(jsonStr, Map.class));
|
|
|
+ for (Object obj : jsonArray) {
|
|
|
+ JSONObject jsonObject = (JSONObject) obj;
|
|
|
+ JSONArray rights = JsonUtil.getJSONArray(jsonObject, "rights");
|
|
|
+ if (JsonUtil.isNotEmpty(rights)) {
|
|
|
+ String label = jsonObject.getString("label");
|
|
|
+ for (Object obj2 : rights) {
|
|
|
+ JSONObject jsonObject2 = (JSONObject) obj2;
|
|
|
+ String type = JsonUtil.getString(jsonObject2,"type","All");
|
|
|
+ if("role".equalsIgnoreCase(type)){
|
|
|
+ String[] rightsNames = jsonObject2.getString("rightsName").split(",");
|
|
|
+ for (String r : rightsNames) {
|
|
|
+ if(map.containsKey(r)){
|
|
|
+ map.get(r).add(label);
|
|
|
+ }else{
|
|
|
+ List<String> l = new ArrayList<>();
|
|
|
+ l.add(label);
|
|
|
+ map.put(r,l);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
}
|
|
|
|
|
|
public List<MenuVO> getFlatMenuList(String parentCode,List<MenuVO> allMenuList){
|
|
|
@@ -100,13 +162,14 @@ public class ResourceRuleJob extends AbstractJob {
|
|
|
|
|
|
String id;
|
|
|
String parentId;
|
|
|
+ Map<String,List<String>> buttons = new HashMap<>();
|
|
|
|
|
|
public MenuVO(int sn, String menuCode, String id, String parentId, String checked) {
|
|
|
this.sn = sn;
|
|
|
this.menuCode = menuCode;
|
|
|
this.id = id;
|
|
|
this.parentId = parentId;
|
|
|
- this.roles.add(checked.equalsIgnoreCase("true")?"√":" ");
|
|
|
+ this.roles.add(checked.equalsIgnoreCase("true")?"√":"");
|
|
|
}
|
|
|
|
|
|
public List<String> getRoles() {
|