1 /**
2 * Copyright © 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
3 */
4 package com.newtouch.common.utils.excel.fieldtype;
5
6 import java.util.List;
7
8 import com.google.common.collect.Lists;
9 import com.newtouch.common.utils.Collections3;
10 import com.newtouch.common.utils.SpringContextHolder;
11 import com.newtouch.common.utils.StringUtils;
12 import com.newtouch.modules.sys.entity.Role;
13 import com.newtouch.modules.sys.service.SystemService;
14
15 /**
16 * 字段类型转换
17 * @author ThinkGem
18 * @version 2013-5-29
19 */
20 public class RoleListType {
21
22 private static SystemService systemService = SpringContextHolder.getBean(SystemService.class);
23
24 /**
25 * 获取对象值(导入)
26 */
27 public static Object getValue(String val) {
28 List<Role> roleList = Lists.newArrayList();
29 List<Role> allRoleList = systemService.findAllRole();
30 for (String s : StringUtils.split(val, ",")){
31 for (Role e : allRoleList){
32 if (StringUtils.trimToEmpty(s).equals(e.getName())){
33 roleList.add(e);
34 }
35 }
36 }
37 return roleList.size()>0?roleList:null;
38 }
39
40 /**
41 * 设置对象值(导出)
42 */
43 public static String setValue(Object val) {
44 if (val != null){
45 @SuppressWarnings("unchecked")
46 List<Role> roleList = (List<Role>)val;
47 return Collections3.extractToString(roleList, "name", ", ");
48 }
49 return "";
50 }
51
52 }