package com.xintong.visualinspection.util; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.slf4j.LoggerFactory; import com.xintong.visualinspection.bean.Constant; import com.xintong.visualinspection.bean.Job; import com.xintong.visualinspection.bean.Organ; import com.xintong.visualinspection.bean.User; import com.xintong.visualinspection.service.ConstantService; import com.xintong.visualinspection.service.DepartmentService; import com.xintong.visualinspection.service.JobService; import com.xintong.visualinspection.service.UserService; public class CacheUtil { public static Map commonDataMap = new HashMap(); public static Map userMap = new HashMap(); public static Map deptMap = new HashMap(); public static Map codeMap = new HashMap(); public static Map> codeFlagMap = new HashMap>(); public static Map jobMap = new HashMap(); private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CacheUtil.class); public static void refreshCodeMap(ConstantService constantService){ //加载用户信息 List constantList = constantService.getAll(); for(Constant c:constantList){ CacheUtil.codeMap.put(c.getCode_flag()+"_"+c.getCode_value(), c); List list = CacheUtil.codeFlagMap.get(c.getCode_flag()); if(list==null) list = new ArrayList(); list.add(c); CacheUtil.codeFlagMap.put(c.getCode_flag(),list); } logger.info("加载用户信息成功,数据数:"+CacheUtil.userMap.size()); } public static void refreshUserMap(UserService userService){ //加载用户信息 List userList = userService.getAll(); for(User user:userList){ CacheUtil.userMap.put(new Long(user.getId()), user); } logger.info("加载用户信息成功,数据数:"+CacheUtil.userMap.size()); } public static void refreshDeptMap(DepartmentService deptService){ //加载部门信息 List deptList = deptService.getAll(); for(Organ organ:deptList){ CacheUtil.deptMap.put(new Long(organ.getId()), organ); } logger.info("加载部门信息成功,数据数:"+CacheUtil.deptMap.size()); } public static void refreshJobMap(JobService jobService){ //加载用户信息 Job j = new Job(); j.setDept_id(1L); List jobList = jobService.getJobList(j); for(Job job:jobList){ CacheUtil.jobMap.put(new Long(job.getId()), job); } logger.info("加载用户信息成功,数据数:"+CacheUtil.userMap.size()); } public static User getUserFromMap(Long key){ if(key == null) return null; return CacheUtil.userMap.get(key); } public static String getUserTurenameFromMap(Long key){ if(getUserFromMap(key)!=null && key!=null){ return getUserFromMap(key).getTruename(); } return null; } public static Organ getOrganFromMap(Long key){ if(key == null) return null; return CacheUtil.deptMap.get(key); } public static String getOrgannameFromMap(Long key){ if(getOrganFromMap(key)!=null){ return getOrganFromMap(key).getOrganname(); } return null; } public static Job getJobFromMap(Long key){ if(key == null) return null; return CacheUtil.jobMap.get(key); } public static String getJobnameFromMap(Long key){ if(getJobFromMap(key)!=null){ return getJobFromMap(key).getName(); } return null; } }