package ink.wgink.module.menu.init;

import ink.wgink.interfaces.app.IAppSignBaseService;
import ink.wgink.interfaces.article.IArticleCheckService;
import ink.wgink.interfaces.config.ISystemConfigCheckService;
import ink.wgink.interfaces.department.IDepartmentCheckService;
import ink.wgink.interfaces.dictionary.IDictionaryCheckService;
import ink.wgink.interfaces.group.IGroupCheckService;
import ink.wgink.interfaces.init.IInitBaseMenu;
import ink.wgink.interfaces.menu.IMenuBaseService;
import ink.wgink.interfaces.permission.IPermissionCheckService;
import ink.wgink.interfaces.position.IPositionCheckService;
import ink.wgink.interfaces.role.IRoleCheckService;
import ink.wgink.interfaces.user.IUserCheckService;
import ink.wgink.interfaces.user.IUserDetailCheckService;
import ink.wgink.module.menu.dao.IMenuDao;
import ink.wgink.pojo.dtos.menu.MenuDTO;
import ink.wgink.util.UUIDUtil;
import ink.wgink.util.date.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: InitMenu
 * @Description: 初始化菜单
 * @Author: wanggeng
 * @Date: 2021/6/15 4:20 下午
 * @Version: 1.0
 */
@Component
public class InitMenu implements IInitBaseMenu {

    private static final Logger LOG = LoggerFactory.getLogger(InitMenu.class);
    @Autowired
    private IMenuDao menuDao;
    @Autowired(required = false)
    private IDictionaryCheckService dictionaryCheckService;
    @Autowired(required = false)
    private ISystemConfigCheckService systemConfigCheckService;
    @Autowired(required = false)
    private IUserCheckService userCheckService;
    @Autowired(required = false)
    private IDepartmentCheckService departmentCheckService;
    @Autowired(required = false)
    private IGroupCheckService groupCheckService;
    @Autowired(required = false)
    private IPositionCheckService positionCheckService;
    @Autowired(required = false)
    private IPermissionCheckService permissionCheckService;
    @Autowired(required = false)
    private IRoleCheckService roleCheckService;
    @Autowired(required = false)
    private IUserDetailCheckService userDetailCheckService;
    @Autowired(required = false)
    private IAppSignBaseService appSignBaseService;
    @Autowired(required = false)
    private IArticleCheckService articleCheckService;

    @Override
    public void init() {
        Map<String, Object> params = new HashMap<>(20);
        String gmt = DateUtil.getTime();
        params.put("gmtCreate", gmt);
        params.put("gmtModified", gmt);
        params.put("creator", "1");
        params.put("modifier", "1");
        params.put("isDelete", 0);

        params.put("menuCode", "0001");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId = IMenuBaseService.MENU_UNIFIED_USER;
        if (menuDTO == null) {
            params.put("menuId", menuId);
            params.put("menuParentId", "0");
            params.put("menuName", "统一用户系统");
            params.put("menuSummary", "统一用户系统");
            params.put("menuUrl", "javascript:void(0);");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-cogs");
            params.put("menuOrder", "1");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
        initSystemManage(params, menuId);
        initUserPermissionManage(params, menuId);
        initPermissionManage(params, menuId);
        initLogManage(params, menuId);
        initArticleManage(params, menuId);
    }

    private void initSystemManage(Map<String, Object> params, String menuParentId) {
        LOG.debug("初始化菜单：系统管理");
        params.remove("menuId");
        params.put("menuCode", "00010001");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId;
        if (menuDTO == null) {
            menuId = UUIDUtil.getUUID();
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "系统管理");
            params.put("menuSummary", "系统管理");
            params.put("menuUrl", "javascript:void(0);");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-cogs");
            params.put("menuOrder", "1");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        } else {
            menuId = menuDTO.getMenuId();
        }
        initMenuManage(params, menuId);
        initDataManager(params, menuId);
        initAreaManager(params, menuId);
        initConfigManager(params, menuId);
        initAppVersionMenu(params, menuId);
    }

    /**
     * 菜单管理
     *
     * @param params
     * @param menuParentId
     */
    private void initMenuManage(Map<String, Object> params, String menuParentId) {
        LOG.debug("初始化菜单：系统菜单");
        params.remove("menuId");
        params.put("menuCode", "000100010001");
        MenuDTO menuDTO = menuDao.getSimple(params);
        if (menuDTO == null) {
            params.put("menuId", UUIDUtil.getUUID());
            params.put("menuParentId", menuParentId);
            params.put("menuName", "系统菜单");
            params.put("menuSummary", "系统菜单");
            params.put("menuUrl", "/route/menu/list-tree");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-list");
            params.put("menuOrder", "1");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 初始化数据字典
     *
     * @param params
     * @param menuParentId
     */
    public void initDataManager(Map<String, Object> params, String menuParentId) {
        if (dictionaryCheckService == null) {
            return;
        }
        LOG.debug("初始化菜单：数据字典");
        params.remove("menuId");
        params.put("menuCode", "000100010002");
        MenuDTO menuDTO = menuDao.getSimple(params);
        if (menuDTO == null) {
            params.put("menuId", UUIDUtil.getUUID());
            params.put("menuParentId", menuParentId);
            params.put("menuName", "数据字典");
            params.put("menuSummary", "数据字典");
            params.put("menuUrl", "/route/data/list-tree");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-address-book");
            params.put("menuOrder", "2");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 初始化地区字典
     *
     * @param params
     * @param menuParentId
     */
    public void initAreaManager(Map<String, Object> params, String menuParentId) {
        if (dictionaryCheckService == null) {
            return;
        }
        LOG.debug("初始化菜单：地区字典");
        params.remove("menuId");
        params.put("menuCode", "000100010003");
        MenuDTO menuDTO = menuDao.getSimple(params);
        if (menuDTO == null) {
            params.put("menuId", UUIDUtil.getUUID());
            params.put("menuParentId", menuParentId);
            params.put("menuName", "区域字典");
            params.put("menuSummary", "区域字典");
            params.put("menuUrl", "/route/area/list-tree");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-map-o");
            params.put("menuOrder", "3");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 初始化配置
     *
     * @param params
     * @param menuParentId
     */
    public void initConfigManager(Map<String, Object> params, String menuParentId) {
        if (systemConfigCheckService == null) {
            return;
        }
        LOG.debug("初始化菜单：系统配置");
        params.remove("menuId");
        params.put("menuCode", "000100010004");
        MenuDTO menuDTO = menuDao.getSimple(params);
        if (menuDTO == null) {
            params.put("menuId", UUIDUtil.getUUID());
            params.put("menuParentId", menuParentId);
            params.put("menuName", "系统配置");
            params.put("menuSummary", "系统配置");
            params.put("menuUrl", "/route/config/update");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-dashboard");
            params.put("menuOrder", "4");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 初始化APP版本管理
     *
     * @param params
     * @param menuParentId
     */
    public void initAppVersionMenu(Map<String, Object> params, String menuParentId) {
        if (appSignBaseService == null) {
            return;
        }
        LOG.debug("初始化菜单：APP版本管理");
        params.remove("menuId");
        params.put("menuCode", "000100010005");
        MenuDTO menuDTO = menuDao.getSimple(params);
        if (menuDTO == null) {
            params.put("menuId", UUIDUtil.getUUID());
            params.put("menuParentId", menuParentId);
            params.put("menuName", "APP版本管理");
            params.put("menuSummary", "APP版本管理");
            params.put("menuUrl", "/route/appversion/list");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-tv");
            params.put("menuOrder", "5");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 用户权限管理
     *
     * @param params
     * @param menuParentId
     */
    private void initUserPermissionManage(Map<String, Object> params, String menuParentId) {
        LOG.debug("初始化菜单：用户管理");
        params.remove("menuId");
        params.put("menuCode", "00010002");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId;
        if (menuDTO == null) {
            menuId = UUIDUtil.getUUID();
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "用户管理");
            params.put("menuSummary", "用户管理");
            params.put("menuUrl", "javascript:void(0);");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-users");
            params.put("menuOrder", "2");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        } else {
            menuId = menuDTO.getMenuId();
        }
        initUserManage(params, menuId);
        initDepartmentManage(params, menuId);
        initGroupManage(params, menuId);
        initPositionManage(params, menuId);
    }

    /**
     * 用户管理
     *
     * @param params
     * @param menuParentId
     */
    private void initUserManage(Map<String, Object> params, String menuParentId) {
        if (userCheckService == null) {
            return;
        }
        LOG.debug("初始化菜单：用户管理");

        params.remove("menuId");
        params.put("menuCode", "000100020001");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId = UUIDUtil.getUUID();
        if (menuDTO == null) {
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "用户账号");
            params.put("menuSummary", "用户账号管理");
            params.put("menuUrl", "/route/user/list");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-address-book");
            params.put("menuOrder", "1");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 组织机构管理
     *
     * @param params
     * @param menuParentId
     */
    private void initDepartmentManage(Map<String, Object> params, String menuParentId) {
        if (departmentCheckService == null) {
            return;
        }
        LOG.debug("初始化菜单：组织机构管理");

        params.remove("menuId");
        params.put("menuCode", "000100020002");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId = UUIDUtil.getUUID();
        if (menuDTO == null) {
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "组织机构");
            params.put("menuSummary", "组织机构管理");
            params.put("menuUrl", "/route/department/list-tree");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-bank");
            params.put("menuOrder", "2");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 用户组管理
     *
     * @param params
     * @param menuParentId
     */
    private void initGroupManage(Map<String, Object> params, String menuParentId) {
        if (groupCheckService == null) {
            return;
        }
        LOG.debug("初始化菜单：用户组管理");

        params.remove("menuId");
        params.put("menuCode", "000100020003");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId = UUIDUtil.getUUID();
        if (menuDTO == null) {
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "用户组管理");
            params.put("menuSummary", "用户组管理");
            params.put("menuUrl", "/route/group/list-tree");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-users");
            params.put("menuOrder", "3");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 职位管理
     *
     * @param params
     * @param menuParentId
     */
    private void initPositionManage(Map<String, Object> params, String menuParentId) {
        if (positionCheckService == null) {
            return;
        }
        LOG.debug("初始化菜单：职位管理");
        params.remove("menuId");
        params.put("menuCode", "000100020004");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId = UUIDUtil.getUUID();
        if (menuDTO == null) {
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "职位管理");
            params.put("menuSummary", "职位管理");
            params.put("menuUrl", "/route/position/list-tree");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-users");
            params.put("menuOrder", "4");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 初始化权限管理
     *
     * @param params
     * @param menuParentId
     */
    private void initPermissionManage(Map<String, Object> params, String menuParentId) {
        if (permissionCheckService == null && roleCheckService == null) {
            return;
        }
        LOG.debug("初始化菜单：权限与角色");
        params.remove("menuId");
        params.put("menuCode", "00010003");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId;
        if (menuDTO == null) {
            menuId = UUIDUtil.getUUID();
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "权限与角色");
            params.put("menuSummary", "权限与角色管理");
            params.put("menuUrl", "javascript:void(0);");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-users");
            params.put("menuOrder", "3");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        } else {
            menuId = menuDTO.getMenuId();
        }

        if (permissionCheckService != null) {
            initSavePermissionManage(params, menuId);
            initDeletePermissionManage(params, menuId);
            initUpdatePermissionManage(params, menuId);
            initQueryPermissionManage(params, menuId);
        }

        if (roleCheckService != null) {
            initRoleManage(params, menuId);
        }
    }

    /**
     * 新增权限
     *
     * @param params
     * @param menuParentId
     */
    private void initSavePermissionManage(Map<String, Object> params, String menuParentId) {
        LOG.debug("初始化菜单：新增权限");
        params.remove("menuId");
        params.put("menuCode", "000100030001");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId;
        if (menuDTO == null) {
            menuId = UUIDUtil.getUUID();
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "新增权限");
            params.put("menuSummary", "新增权限");
            params.put("menuUrl", "/route/permission/list?permissionType=permissionInsert");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-users");
            params.put("menuOrder", "1");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 修改权限
     *
     * @param params
     * @param menuParentId
     */
    private void initDeletePermissionManage(Map<String, Object> params, String menuParentId) {
        LOG.debug("初始化菜单：删除权限");
        params.remove("menuId");
        params.put("menuCode", "000100030002");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId;
        if (menuDTO == null) {
            menuId = UUIDUtil.getUUID();
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "删除权限");
            params.put("menuSummary", "删除权限");
            params.put("menuUrl", "/route/permission/list?permissionType=permissionDelete");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-users");
            params.put("menuOrder", "2");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 修改权限
     *
     * @param params
     * @param menuParentId
     */
    private void initUpdatePermissionManage(Map<String, Object> params, String menuParentId) {
        LOG.debug("初始化菜单：修改权限");
        params.remove("menuId");
        params.put("menuCode", "000100030003");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId;
        if (menuDTO == null) {
            menuId = UUIDUtil.getUUID();
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "修改权限");
            params.put("menuSummary", "修改权限");
            params.put("menuUrl", "/route/permission/list?permissionType=permissionUpdate");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-users");
            params.put("menuOrder", "3");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 查询权限
     *
     * @param params
     * @param menuParentId
     */
    private void initQueryPermissionManage(Map<String, Object> params, String menuParentId) {
        LOG.debug("初始化菜单：查询权限");
        params.remove("menuId");
        params.put("menuCode", "000100030004");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId;
        if (menuDTO == null) {
            menuId = UUIDUtil.getUUID();
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "查询权限");
            params.put("menuSummary", "查询权限");
            params.put("menuUrl", "/route/permission/list?permissionType=permissionQuery");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-users");
            params.put("menuOrder", "4");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 角色管理
     *
     * @param params
     * @param menuParentId
     */
    private void initRoleManage(Map<String, Object> params, String menuParentId) {
        LOG.debug("初始化菜单：角色管理");
        params.remove("menuId");
        params.put("menuCode", "000100030005");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId;
        if (menuDTO == null) {
            menuId = UUIDUtil.getUUID();
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "角色管理");
            params.put("menuSummary", "角色管理");
            params.put("menuUrl", "/route/role/list-tree?permissionType=permissionQuery");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-users");
            params.put("menuOrder", "5");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 日志管理
     *
     * @param params
     * @param menuParentId
     */
    private void initLogManage(Map<String, Object> params, String menuParentId) {
        if (userDetailCheckService == null) {
            return;
        }
        LOG.debug("初始化菜单：日志管理");
        params.remove("menuId");
        params.put("menuCode", "00010004");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId;
        if (menuDTO == null) {
            menuId = UUIDUtil.getUUID();
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "日志管理");
            params.put("menuSummary", "日志管理");
            params.put("menuUrl", "javascript:void(0);");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-history");
            params.put("menuOrder", "4");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        } else {
            menuId = menuDTO.getMenuId();
        }

        initLoginLogManage(params, menuId);
        initUserAdjustmentManage(params, menuId);
        initDepartmentAdjustmentManage(params, menuId);
        initDepartmentUserAdjustmentManage(params, menuId);
    }

    /**
     * 登录日志
     *
     * @param params
     * @param menuParentId
     */
    private void initLoginLogManage(Map<String, Object> params, String menuParentId) {
        LOG.debug("初始化菜单：登录日志");
        params.remove("menuId");
        params.put("menuCode", "000100040001");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId;
        if (menuDTO == null) {
            menuId = UUIDUtil.getUUID();
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "登录日志");
            params.put("menuSummary", "登录日志");
            params.put("menuUrl", "/route/log/list-login-log");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-history");
            params.put("menuOrder", "1");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 用户调整
     *
     * @param params
     * @param menuParentId
     */
    private void initUserAdjustmentManage(Map<String, Object> params, String menuParentId) {
        LOG.debug("初始化菜单：用户调整");
        params.remove("menuId");
        params.put("menuCode", "000100040002");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId;
        if (menuDTO == null) {
            menuId = UUIDUtil.getUUID();
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "用户调整");
            params.put("menuSummary", "用户调整");
            params.put("menuUrl", "/route/log/list-user-adjustment");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-history");
            params.put("menuOrder", "2");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 部门调整
     *
     * @param params
     * @param menuParentId
     */
    private void initDepartmentAdjustmentManage(Map<String, Object> params, String menuParentId) {
        LOG.debug("初始化菜单：部门调整");
        params.remove("menuId");
        params.put("menuCode", "000100040003");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId;
        if (menuDTO == null) {
            menuId = UUIDUtil.getUUID();
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "部门调整");
            params.put("menuSummary", "部门调整");
            params.put("menuUrl", "/route/log/list-department-adjustment");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-history");
            params.put("menuOrder", "3");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 部门用户调整
     *
     * @param params
     * @param menuParentId
     */
    private void initDepartmentUserAdjustmentManage(Map<String, Object> params, String menuParentId) {
        LOG.debug("初始化菜单：部门用户调整");
        params.remove("menuId");
        params.put("menuCode", "000100040004");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId;
        if (menuDTO == null) {
            menuId = UUIDUtil.getUUID();
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "部门用户调整");
            params.put("menuSummary", "部门用户调整");
            params.put("menuUrl", "/route/log/list-department-user-adjustment");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-history");
            params.put("menuOrder", "4");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 文章管理
     *
     * @param params
     * @param menuParentId
     */
    private void initArticleManage(Map<String, Object> params, String menuParentId) {
        if (articleCheckService == null) {
            return;
        }
        LOG.debug("初始化菜单：文章管理");
        params.remove("menuId");
        params.put("menuCode", "00010100");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId;
        if (menuDTO == null) {
            menuId = UUIDUtil.getUUID();
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "文章管理");
            params.put("menuSummary", "文章管理");
            params.put("menuUrl", "javascript:void(0);");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-newspaper-o");
            params.put("menuOrder", "100");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        } else {
            menuId = menuDTO.getMenuId();
        }

        initCategoryManage(params, menuId);
        initContentManage(params, menuId);
    }

    /**
     * 部门用户调整
     *
     * @param params
     * @param menuParentId
     */
    private void initCategoryManage(Map<String, Object> params, String menuParentId) {
        LOG.debug("初始化菜单：目录管理");
        params.remove("menuId");
        params.put("menuCode", "000101000001");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId;
        if (menuDTO == null) {
            menuId = UUIDUtil.getUUID();
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "目录管理");
            params.put("menuSummary", "目录管理");
            params.put("menuUrl", "/route/category/list");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-newspaper-o");
            params.put("menuOrder", "1");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

    /**
     * 部门用户调整
     *
     * @param params
     * @param menuParentId
     */
    private void initContentManage(Map<String, Object> params, String menuParentId) {
        LOG.debug("初始化菜单：内容管理");
        params.remove("menuId");
        params.put("menuCode", "000101000002");
        MenuDTO menuDTO = menuDao.getSimple(params);
        String menuId;
        if (menuDTO == null) {
            menuId = UUIDUtil.getUUID();
            params.put("menuId", menuId);
            params.put("menuParentId", menuParentId);
            params.put("menuName", "内容管理");
            params.put("menuSummary", "内容管理");
            params.put("menuUrl", "/route/content/list");
            params.put("menuType", "1");
            params.put("menuIcon", "fa-icon-color-white fa fa-newspaper-o");
            params.put("menuOrder", "2");
            params.put("menuStatus", "0");
            params.put("openType", "1");
            menuDao.save(params);
        }
    }

}
