菜单


数据库

/*
 Navicat Premium Data Transfer

 Source Server         : 开发环境10.20.131.115-deployop 
 Source Server Type    : MySQL
 Source Server Version : 50622
 Source Host           : 10.20.131.115:5089
 Source Schema         : smt

 Target Server Type    : MySQL
 Target Server Version : 50622
 File Encoding         : 65001

 Date: 16/05/2018 19:49:52
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for smt_module_menu
-- ----------------------------
DROP TABLE IF EXISTS `smt_module_menu`;
CREATE TABLE `smt_module_menu`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `p_id` bigint(20) NOT NULL,
  `name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Compact;

-- ----------------------------
-- Records of smt_module_menu
-- ----------------------------
INSERT INTO `smt_module_menu` VALUES (1, 0, '我的深圳');
INSERT INTO `smt_module_menu` VALUES (2, 0, '我的南通');
INSERT INTO `smt_module_menu` VALUES (3, 0, '宝安通');
INSERT INTO `smt_module_menu` VALUES (4, 1, '首页');
INSERT INTO `smt_module_menu` VALUES (5, 2, '首页');
INSERT INTO `smt_module_menu` VALUES (6, 3, '首页');
INSERT INTO `smt_module_menu` VALUES (7, 4, '常用服务');
INSERT INTO `smt_module_menu` VALUES (8, 7, '公积金');
INSERT INTO `smt_module_menu` VALUES (9, 7, '社保');
INSERT INTO `smt_module_menu` VALUES (10, 7, '住房服务');

SET FOREIGN_KEY_CHECKS = 1;
SmtModuleMenuDTO.java
package com.paic.smt.app.pcapi.configSystem.dto;

import java.util.List;

/**
 * Created by HUANGLIAO322 on 2018/5/16.
 */
public class SmtModuleMenuDTO {

    private long id;
    private long parentId;
    private String name;
    private List<SmtModuleMenuDTO> childMenus;

    public List<SmtModuleMenuDTO> getChildMenus() {
        return childMenus;
    }

    public void setChildMenus(List<SmtModuleMenuDTO> childMenus) {
        this.childMenus = childMenus;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getParentId() {
        return parentId;
    }

    public void setParentId(long parentId) {
        this.parentId = parentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}


package com.paic.smt.app.pcapi.configSystem.biz.service.impl;

import com.alibaba.fastjson.JSON;
import com.paic.smt.app.pcapi.configSystem.biz.dao.ConfigMenuPcDAO;
import com.paic.smt.app.pcapi.configSystem.biz.service.ConfigMenuPcService;
import com.paic.smt.app.pcapi.configSystem.dto.SmtModuleMenuDTO;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by HUANGLIAO322 on 2018/5/16.
 */
@Service
public class ConfigMenuPcServiceImpl implements ConfigMenuPcService {

    private static Logger logger  = Logger.getLogger(ConfigMenuPcServiceImpl.class);

    @Autowired
    private ConfigMenuPcDAO configMenuPcDAO;

    @Override
    public  List<SmtModuleMenuDTO> getMenu(final long rootId ) {



        List<SmtModuleMenuDTO> allList = this.configMenuPcDAO.findList(null); //查询全部数据

        List<SmtModuleMenuDTO> menuList = new ArrayList<SmtModuleMenuDTO>();

        for(SmtModuleMenuDTO smtModuleMenuDTO: allList){
            if(rootId == smtModuleMenuDTO.getParentId()) {
                menuList.add(smtModuleMenuDTO);
            }
        }

        logger.info(JSON.toJSONString(menuList));


        for (SmtModuleMenuDTO smtModuleMenuDTO : menuList){
            smtModuleMenuDTO.setChildMenus(this.getChild(smtModuleMenuDTO.getId(),allList));
        }



        logger.info(JSON.toJSONString(menuList));

        return menuList;
    }


    private List<SmtModuleMenuDTO> getChild(long id, List<SmtModuleMenuDTO> allList) {

        List<SmtModuleMenuDTO> childList = new ArrayList<SmtModuleMenuDTO>();

        for (SmtModuleMenuDTO menu : allList) {
            if (menu.getParentId()==id) {
                childList.add(menu);
            }
        }

        if (childList.size() == 0) {
            return null;
        }

        for (SmtModuleMenuDTO menu : childList) {
            menu.setChildMenus(this.getChild(menu.getId(), allList));
        }

        return childList;
    }



}










  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值