liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
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
/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.common.utils.excel.fieldtype;
 
import java.util.List;
 
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.Collections3;
import com.jeeplus.common.utils.SpringContextHolder;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.sys.entity.Role;
import com.jeeplus.modules.sys.service.SystemService;
 
/**
 * 字段类型转换
 * @author jeeplus
 * @version 2013-5-29
 */
public class RoleListType {
 
    private static SystemService systemService = SpringContextHolder.getBean(SystemService.class);
    
    /**
     * 获取对象值(导入)
     */
    public static Object getValue(String val) {
        List<Role> roleList = Lists.newArrayList();
        List<Role> allRoleList = systemService.findAllRole();
        for (String s : StringUtils.split(val, ",")){
            for (Role e : allRoleList){
                if (StringUtils.trimToEmpty(s).equals(e.getName())){
                    roleList.add(e);
                }
            }
        }
        return roleList.size()>0?roleList:null;
    }
 
    /**
     * 设置对象值(导出)
     */
    public static String setValue(Object val) {
        if (val != null){
            @SuppressWarnings("unchecked")
            List<Role> roleList = (List<Role>)val;
            return Collections3.extractToString(roleList, "name", ", ");
        }
        return "";
    }
    
}