|
一、实现效果
如果需求需要的树形结构数据,平台配置过滤满足不了的话,就要根据需求条件重写后台getTree方法和load方法
二、实现思路
三、具体操作
重写方法加入当前需求的过滤条件后,在平台配置的Action改为方法中的路径。(提交git代码注意先更新再提交)
四、相关代码(可选)
- package com.project.sidri.controller;
- import cn.hutool.core.util.StrUtil;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.google.common.collect.Lists;
- import com.je.core.base.AbstractPlatformController;
- import com.je.core.base.MethodArgument;
- import com.je.core.entity.extjs.JSONTreeNode;
- import com.je.core.exception.PlatformException;
- import com.je.core.exception.PlatformExceptionEnum;
- import com.je.core.mapper.query.Condition;
- import com.je.core.mapper.query.Query;
- import com.je.core.result.BaseRespResult;
- import com.je.core.service.PCDynaBeanTemplate;
- import com.je.core.service.PCDynaServiceTemplate;
- import com.je.core.service.PCServiceTemplate;
- import com.je.core.util.SecurityUserHolder;
- import com.je.core.util.bean.BeanUtils;
- import com.je.core.util.bean.DynaBean;
- import com.je.ibatis.extension.conditions.ConditionsWrapper;
- import com.je.ibatis.extension.plugins.pagination.Page;
- import com.je.wf.processVo.ProcessVoBuilder;
- import com.project.sidri.service.LoadTreeService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.ResponseBody;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Map;
- import static com.je.wf.processVo.ProcessVoBuilder.jsonAssist;
- /**
- * @ClassName TreeLodeDemoController
- * @Description
- * @Author Administrator
- * @Date 2021/7/15 0015 9:40
- * @Version V1.0
- */
- @Controller
- @RequestMapping(value = "/je/demoDynaTree")
- public class LoadTreeController extends AbstractPlatformController{
- @Autowired
- PCDynaBeanTemplate dynabeanTemplate;
- @Autowired
- PCDynaServiceTemplate serviceTemplate;
- @Autowired
- //@Qualifier("LoadTreeService")
- protected LoadTreeService loadTreeService;
- /**
- * 默认的列表读取
- *
- * @param param 请求参数封装对象
- */
- @RequestMapping(value = "/load", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
- @ResponseBody
- @Override
- public void load(MethodArgument param) {
- Page page = new Page<>(param.getPage(), param.getLimit());
- Query query = param.getQuery();
- List<Condition> tree = query.getTree();
- List<Condition> custom = query.getCustom();
- String userId = SecurityUserHolder.getCurrentUser().getUserId();
- String userCode = SecurityUserHolder.getCurrentUser().getUserCode();
- //获取登录人相关数据
- List<DynaBean> lists = metaService.select("RWGL_RWXX", ConditionsWrapper.builder().eq("RWXX_RWSFGD_CODE", 1)
- .like("RWXX_FZRID", userId)
- .or().like("RWXX_FZRID", userCode)
- .or().like("RWXX_ZPRID", userId)
- .or().like("RWXX_ZPRID", userCode)
- .or().like("RWXX_CSRID", userId)
- .or().like("RWXX_CSRID", userCode)
- .or().like("SY_CREATEUSERID",userId));
- //获取所有根节点主键
- HashSet<String> sites = new HashSet<>();
- for (int i = 0; i < lists.size(); i++) {
- String sy_path = lists.get(i).getStr("SY_PATH");
- String[] a = sy_path.split("/");
- if(a.length > 2){
- sites.add(a[2]);
- }
- }
- //拼接查询条件
- Condition condition = new Condition();
- condition.setType("and");
- List<Condition> valueCondition = new ArrayList<>();
- int i = 0;
- for (String str : sites){
- Condition con = new Condition();
- if(i != 0){
- con.setCn("or");
- }
- con.setValue(str);
- con.setType("like");
- con.setCode("SY_PATH");
- valueCondition.add(con);
- i++;
- }
- condition.setValue(valueCondition);
- tree.add(condition);
- query.setTree(tree);
- Condition customCon = new Condition();
- customCon.setValue("1");
- customCon.setCode("RWXX_RWSFGD_CODE");
- customCon.setType("=");
- custom.add(customCon);
- super.load(param);
- }
- /**
- * 默认平台
- *
- * @param param 请求参数封装对象
- */
- @RequestMapping(value = "/getTree", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
- @ResponseBody
- public void getTree(MethodArgument param) {
- try {
- Query query = new Query();
- //query.addCustom();
- manager.getTree(param);
- if (isSecurity(param)) {
- JSONTreeNode tree = loadTreeService.getTree(param);
- if (tree != null) {
- this.toWrite(ProcessVoBuilder.jsonAssist.buildModelJson(tree, param.getExcludes().split(",")), param);
- } else {
- this.toWrite("{}", param);
- }
- } else {
- this.dynaManager.getTree(param);
- }
- } catch (PlatformException var3) {
- throw var3;
- } catch (Exception var4) {
- throw new PlatformException("数据加载失败!", PlatformExceptionEnum.UNKOWN_ERROR, var4);
- }
- }
- }
复制代码- package com.project.sidri.service;
- import com.je.core.base.MethodArgument;
- import com.je.core.entity.extjs.JSONTreeNode;
- import com.je.ibatis.extension.plugins.pagination.Page;
- import java.util.List;
- import java.util.Map;
- public interface LoadTreeService {
- JSONTreeNode getTree(MethodArgument param);
- }
复制代码- package com.project.sidri.service;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.je.core.base.MethodArgument;
- import com.je.core.constants.ConstantVars;
- import com.je.core.entity.extjs.JSONTreeNode;
- import com.je.core.exception.PlatformException;
- import com.je.core.exception.PlatformExceptionEnum;
- import com.je.core.mapper.query.Query;
- import com.je.core.result.BaseRespResult;
- import com.je.core.service.*;
- import com.je.core.util.ArrayUtils;
- import com.je.core.util.SecurityUserHolder;
- import com.je.core.util.StringUtil;
- import com.je.core.util.bean.BeanUtils;
- import com.je.core.util.bean.DynaBean;
- import com.je.develop.vo.FuncInfo;
- import com.je.develop.vo.FuncPermVo;
- import com.je.develop.vo.FuncQueryStrategy;
- import com.je.ibatis.extension.conditions.ConditionsWrapper;
- import com.je.ibatis.extension.enums.Conditions;
- import com.je.ibatis.extension.plugins.pagination.Page;
- import com.je.rbac.model.EndUser;
- import com.sun.xml.bind.v2.model.core.ID;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang.StringUtils;
- import org.apache.derby.iapi.services.io.Limit;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Bean;
- import org.springframework.stereotype.Service;
- import javax.servlet.http.HttpServletRequest;
- import javax.xml.soap.Text;
- import java.util.*;
- import java.util.function.Consumer;
- import java.util.stream.Collectors;
- @Slf4j
- @Service("loadTreeService")
- public class LoadTreeServiceImpl implements LoadTreeService {
- private Logger logger = LoggerFactory.getLogger(this.getClass());
- @Autowired
- private PCDynaBeanTemplate dynaBeanTemplate;
- @Autowired
- private MetaService metaService;
- @Autowired
- private CommonService commonService;
- @Autowired
- private QueryBuilder queryBuilder;
- @Autowired
- private PlatformManager platformManager;
- @Override
- public JSONTreeNode getTree(MethodArgument param) {
- String node = param.getNode();
- if (StringUtils.isEmpty(node)) {
- node = "ROOT";
- }
- if (StringUtils.isNotEmpty(param.getRootId())) {
- node = param.getRootId();
- }
- //查询当前登录人拥有的数据
- //构建查询条件
- List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
- Map<String, Object> map1 = new HashMap<String, Object>();
- //获取当前登陆人
- String userCode = SecurityUserHolder.getCurrentUser().getUserCode();
- String userId = SecurityUserHolder.getCurrentUser().getUserId();
- //--------------获取当前登录人为负责人和抄送人的数据-----------
- List<DynaBean> lists = metaService.select("RWGL_RWXX", ConditionsWrapper.builder().eq("RWXX_RWSFGD_CODE", "1")
- .like("RWXX_FZRID", userId)
- .or().like("RWXX_FZRID", userCode)
- .or().like("RWXX_ZPRID", userId)
- .or().like("RWXX_ZPRID", userCode)
- .or().like("RWXX_CSRID", userId)
- .or().like("RWXX_CSRID", userCode)
- .or().like("SY_CREATEUSERID",userId));
- String whereSqlbyUserId = "";
- for (int i = 0; i < lists.size(); i++) {
- String sy_path = lists.get(i).getStr("SY_PATH");
- String sy_layer = lists.get(i).getStr("SY_LAYER");
- if (i == 0) {
- if (sy_layer == "1") {
- whereSqlbyUserId += " SY_PATH LIKE '%" + sy_path + "%'";
- } else {
- String[] a = sy_path.split("/");
- if(a.length>2){
- String new_path = "/" + a[1] + "/" + a[2];
- whereSqlbyUserId += " SY_PATH LIKE '%" + new_path + "%'";
- }else{
- whereSqlbyUserId += " OR SY_PATH LIKE '%" + sy_path + "%'";
- }
- }
- } else {
- if (sy_layer == "1") {
- whereSqlbyUserId += " OR SY_PATH LIKE '%" + sy_path + "%'";
- } else {
- String[] aa = sy_path.split("/");
- if(aa.length>2){
- String new_path = "/" + aa[1] + "/" + aa[2];
- whereSqlbyUserId += " OR SY_PATH LIKE '%" + new_path + "%'";
- }else {
- whereSqlbyUserId += " OR SY_PATH LIKE '%" + sy_path + "%'";
- }
- }
- }
- }
- if("".equals(whereSqlbyUserId)){
- return this.commonService.buildJSONNewTree(new ArrayList<>(), node);
- }else {
- whereSqlbyUserId = param.getWhereSql() + "and (" + whereSqlbyUserId + ")";
- }
- String querySql = "SELECT * FROM RWGL_RWXX WHERE 1=1 " + whereSqlbyUserId + " and RWXX_RWSFGD_CODE = '1' or SY_PATH = '/ROOT'";
- querySql = querySql+" ORDER BY SY_TREEORDERINDEX,SY_CREATETIME DESC";
- List<Map<String, Object>> maps = metaService.selectSql(querySql, param);
- List<JSONTreeNode> jsonTreeNodes = new ArrayList<JSONTreeNode>();
- if(maps.size()>0){
- for (Map<String, Object> map : maps){
- JSONTreeNode jsonTreeNode = new JSONTreeNode();
- jsonTreeNode.setId(map.get("RWGL_RWXX_ID").toString());
- jsonTreeNode.setText(map.get("RWXX_RWM").toString());
- jsonTreeNode.setEnField("");
- jsonTreeNode.setCode(map.get("RWXX_RWBM") == null ? "" : map.get("RWXX_RWBM").toString());
- //jsonTreeNode.setCode(map.get("RWXX_RWBM").toString());
- jsonTreeNode.setParent(map.get("SY_PARENT") == null ? "" :map.get("SY_PARENT").toString());
- jsonTreeNode.setIcon(null);
- jsonTreeNode.setIconCls(null);
- jsonTreeNode.setHref(null);
- jsonTreeNode.setHrefTarget("");
- jsonTreeNode.setNodeType(map.get("SY_NODETYPE").toString());
- jsonTreeNode.setLayer(map.get("SY_LAYER").toString());
- jsonTreeNode.setDescription("");
- jsonTreeNode.setExpandable(true);
- jsonTreeNode.setExpanded(false);
- jsonTreeNode.setChecked(false);
- jsonTreeNode.setAsync(false);
- jsonTreeNode.setNodeInfo(map.get("SY_NODETYPE").toString());
- jsonTreeNode.setNodeInfoType(map.get("SY_NODETYPE").toString());
- if ("LEAF".equalsIgnoreCase(map.get("SY_NODETYPE") + "")) {
- jsonTreeNode.setLeaf(true);
- } else {
- jsonTreeNode.setLeaf(false);
- }
- jsonTreeNode.setParentText(map.get("SY_PARENTPATH") == null ? "" :map.get("SY_PARENTPATH").toString());
- jsonTreeNode.setNodePath(map.get("SY_PATH").toString());
- jsonTreeNode.setParentPath(map.get("SY_PARENTPATH") == null ? "" :map.get("SY_PARENTPATH").toString());
- jsonTreeNode.setCode(map.get("SY_DISABLED") == null ? "" : map.get("SY_DISABLED").toString());
- //jsonTreeNode.setDisabled(map.get("SY_DISABLED").toString());
- //jsonTreeNode.setOrderIndex(map.get("SY_ORDERINDEX").toString());
- //jsonTreeNode.setParentPath(map.get("SY_ORDERINDEX") == null ? "" :map.get("SY_ORDERINDEX").toString());
- jsonTreeNode.setTreeOrderIndex(map.get("SY_TREEORDERINDEX").toString());
- jsonTreeNode.setFieldCodes(null);
- jsonTreeNode.setBean(map);
- jsonTreeNode.setChildren(new ArrayList<JSONTreeNode>());
- jsonTreeNodes.add(jsonTreeNode);
- }
- }
- return this.commonService.buildJSONNewTree(jsonTreeNodes, node);
- }
- }
复制代码
五、总结(可选)
当前代码只是根据自身特有的需求条件生成树形,可根据不同需求修改过滤条件
六、关键字
重写树形方法 getTree
|
|