王佳豪
2021-06-26 718f604deb342b0bee6c588bb44e22ced3371fb8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.slcf.service.impl;
 
import java.util.List;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.slcf.dao.LoginDao;
import com.slcf.pojo.MenuBean;
import com.slcf.pojo.UserBean;
import com.slcf.service.LoginService;
@Service
public class LoginServiceImpl implements LoginService {
 
    @Autowired
    LoginDao loginDao;
    
    /**
     * 根据用户id查找此用户所用户的菜单
     */
    public List<MenuBean> getMenuByUserId(int id) {
        List<MenuBean>plist=loginDao.getParenMenuByUserId(id);
        for(MenuBean m:plist){
            List<MenuBean>clist=loginDao.getChildMenuByPid(id,m.getMenu_id());
            if(clist!=null){
                m.setChildren(clist);
            }
        }
        return plist;
    }
 
    /**
     * 根据用户登陆账号查询用户信息
     */
    public UserBean getUserInfoByAccount(String name,String pass) {
        UserBean user=loginDao.getInfoByAccount(name);
        return user;
    }
    
    /**
     * 根据用户id,查询角色list
     * @param id
     * @return
     */
    public String getRolesByUserId(int id) {
        String result = "";
        try {
            List<String> list = loginDao.getRolesByUserId(id);
            if(list!=null && list.size()>0) {
                for(String str : list) {
                    result += str + ",";
                }
                if(result.length()>0) {
                    result = result.substring(0, result.length()-1);
                }
            }
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
}