package com.sunxung.factoring.start.impl;

import com.sunxung.factoring.component.util.ConstantConversionUtil;
import com.sunxung.factoring.component.util.ConstantUtil;
import com.sunxung.factoring.component.util.SpringUtil;
import com.sunxung.factoring.entity.sys.Role;
import com.sunxung.factoring.service.sys.RoleService;

/**
 * 角色初始化
 */
public class RoleInit {

    public void run() {
        // 默认角色组
        Role group = new Role();
        group.setName("默认");
        group.setUserCreate("admin");
        group.setAdmin(true);
        Role groupRole = getRoleService().add(group);
        /** 超级管理员 **/
        Role role = new Role();
        role.setName(ConstantConversionUtil.ADMINISTORIES_DISPLAYNAME);
        role.setParent(groupRole);
        role.setAdmin(true);
        role.setUserCreate("admin");
        getRoleService().add(role);
        /** 子管理员 **/
        Role role2 = new Role();
        role2.setName(ConstantConversionUtil.CHILD_ADMINISTORIES_DISPLAYNAME);
        role2.setParent(groupRole);
        role2.setUserCreate("admin");
        role2.setAdmin(true);
        getRoleService().add(role2);
        /** 业务超级管理员 **/
        Role businessAdmin = new Role();
        businessAdmin.setName(ConstantConversionUtil.BUSINESS_ADMINISTORIES_DISPLAYNAME);
        businessAdmin.setParent(groupRole);
        businessAdmin.setUserCreate("admin");
        getRoleService().add(businessAdmin);
        /** 风险经理角色 **/
        Role riskManager = new Role();
        riskManager.setName(ConstantUtil.RISK_CONTROL_MANAGER);
        riskManager.setParent(groupRole);
        riskManager.setUserCreate("admin");
        getRoleService().add(riskManager);
        /** 风险负责人角色 **/
        Role riskOwner = new Role();
        riskOwner.setName(ConstantUtil.RISK_CONTROL_OWNER);
        riskOwner.setParent(groupRole);
        riskOwner.setUserCreate("admin");
        getRoleService().add(riskOwner);
        /** 风险助理角色 **/
        Role riskAssistant = new Role();
        riskAssistant.setName(ConstantUtil.RISK_CONTROL_ASSISTANT);
        riskAssistant.setParent(groupRole);
        riskAssistant.setUserCreate("admin");
        getRoleService().add(riskAssistant);
        /** 评审委员 **/
        Role reviewComittee = new Role();
        reviewComittee.setName(ConstantUtil.REVIEW_COMMITTEE);
        reviewComittee.setParent(groupRole);
        reviewComittee.setUserCreate("admin");
        getRoleService().add(reviewComittee);
        /** 专业人员 **/
        Role professional = new Role();
        professional.setName(ConstantUtil.PROFESSIONAL);
        professional.setParent(groupRole);
        professional.setUserCreate("admin");
        getRoleService().add(professional);
        /** 法务专员 **/
        Role legalSpecialist = new Role();
        legalSpecialist.setName(ConstantUtil.LEGAL_SPECIALIST);
        legalSpecialist.setParent(groupRole);
        legalSpecialist.setUserCreate("admin");
        getRoleService().add(legalSpecialist);
        /** 出纳 **/
        Role cashier = new Role();
        cashier.setName(ConstantUtil.CASHIER);
        cashier.setParent(groupRole);
        cashier.setUserCreate("admin");
        getRoleService().add(cashier);
        /** 会计 **/
        Role accountant = new Role();
        accountant.setName(ConstantUtil.ACCOUNTANT);
        accountant.setParent(groupRole);
        accountant.setUserCreate("admin");
        getRoleService().add(accountant);
        /** 财务负责人 **/
        Role financialOwner = new Role();
        financialOwner.setName(ConstantUtil.FINANCIAL_OWNER);
        financialOwner.setParent(groupRole);
        financialOwner.setUserCreate("admin");
        getRoleService().add(financialOwner);
        /** 运营专员 **/
        Role operationSpecialist = new Role();
        operationSpecialist.setName(ConstantUtil.OPERATION_SPECIALIST);
        operationSpecialist.setParent(groupRole);
        operationSpecialist.setUserCreate("admin");
        getRoleService().add(operationSpecialist);
        /** 运营负责人 **/
        Role operationOwner = new Role();
        operationOwner.setName(ConstantUtil.OPERATION_OWNER);
        operationOwner.setParent(groupRole);
        operationOwner.setUserCreate("admin");
        getRoleService().add(operationOwner);
        /** 项目经理 **/
        Role projectManager = new Role();
        projectManager.setName("项目经理");
        projectManager.setParent(groupRole);
        projectManager.setUserCreate("admin");
        getRoleService().add(projectManager);
        /** 业务负责人 **/
        Role businessOwner = new Role();
        businessOwner.setName("业务负责人");
        businessOwner.setParent(groupRole);
        businessOwner.setUserCreate("admin");
        getRoleService().add(businessOwner);
        /** 法务负责人 **/
        Role legalAffairsOwner = new Role();
        legalAffairsOwner.setName("法务负责人");
        legalAffairsOwner.setParent(groupRole);
        legalAffairsOwner.setUserCreate("admin");
        getRoleService().add(legalAffairsOwner);
        /** 财务主管 **/
        Role financialOfficer = new Role();
        financialOfficer.setName("财务主管");
        financialOfficer.setParent(groupRole);
        financialOfficer.setUserCreate("admin");
        getRoleService().add(financialOfficer);
        /** 催收专员 **/
        Role commissionerCollection = new Role();
        commissionerCollection.setName("催收专员");
        commissionerCollection.setParent(groupRole);
        commissionerCollection.setUserCreate("admin");
        getRoleService().add(commissionerCollection);
        /** 信保管理者 **/
        Role creditInsuranceManager = new Role();
        creditInsuranceManager.setName("信保管理者");
        creditInsuranceManager.setParent(groupRole);
        creditInsuranceManager.setUserCreate("admin");
        getRoleService().add(creditInsuranceManager);
    }

    private static RoleService roleService;

    private static RoleService getRoleService() {
        if (roleService == null) {
            roleService = SpringUtil.getBeanByType(RoleService.class);
        }
        return roleService;
    }
}
