package com.ho.user;

import com.ho.common.tools.entity.SysPermission;
import com.ho.user.api.entity.SysDept;
import com.ho.user.mapper.SysPermissionMapper;
import com.ho.user.service.DeptService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

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

/**
 * @Description TODO
 * Author yule
 * Date 2023/3/6 15:00
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class DeptTest {


    @Autowired
    DeptService deptService;


    @Test
    public void testDeptByPid(){
      List<SysDept> depts = deptService.selectByGroupId(1);
        Map<Integer,SysDept> map = new HashMap<>();
        for (SysDept dept : depts) {
            map.put(dept.getId(),dept);
        }
        for (SysDept dept : depts) {
            int hierarchy = deptService.getHierarchy(map, dept, 1);
            dept.setHierarchy(hierarchy);
        }
        System.out.println();
    }


    @Autowired
    SysPermissionMapper sysPermissionMapper;

    @Test
    public void testAddPermissionMapper(){
        SysPermission sysPermission = new SysPermission();
        sysPermission.setName("111");
        int i = sysPermissionMapper.insertSelective(sysPermission);
        System.out.println(i);
        System.out.println(sysPermission.getId());
    }
}
