package cache; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.commons.lang.StringUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.springframework.ui.Model; import com.xt.jygl.common.SearchCondition; import com.xt.jygl.gkjygl.gkjyr.jyrjbxx.entity.GkjyrEntity; public class CacheSearchCondition { public static String CACHE_SEARCHCONDITION="cache.SearchCondition"; public static Map cacheSCmap (HttpServletRequest request,String attrname){ HttpSession session = request.getSession(true); StringBuffer key=new StringBuffer(CACHE_SEARCHCONDITION); if(StringUtils.isNotBlank(attrname)){ key.append(".").append(attrname); } Map cacheSCmap = (Map)session.getAttribute(key.toString()); if(null==cacheSCmap){ session.setAttribute(key.toString(), new HashMap()); } return cacheSCmap; } public static Map putCacheSCmap (Map beanMap ,Map cacheSCmap){ if(null!=cacheSCmap){ try { if(null!=beanMap&&!beanMap.isEmpty()){ cacheSCmap.clear(); for(Map.Entry et:beanMap.entrySet()){ if(et.getValue() instanceof String[]){ String[] vs=(String[])et.getValue(); if(vs.length==1){ cacheSCmap.put((String)et.getKey(), vs[0]); }else if(vs.length>1){ cacheSCmap.put((String)et.getKey(), vs); } }else{ cacheSCmap.put((String)et.getKey(), et.getValue()); } } //System.out.println(":"+financeBean); } } catch (Exception e) { e.printStackTrace(); } } return cacheSCmap; } public static Map modeladdAttribute ( Model model ,Map cacheSCmap,String key1,String key2){ if(null!=model && null!=cacheSCmap && !cacheSCmap.isEmpty() &&StringUtils.isNotBlank(key1)){ if(StringUtils.isBlank(key2)){ key2=key1; } model.addAttribute(key1, CacheSearchCondition.cacheSCmapVal(cacheSCmap, key2)); } return cacheSCmap; } public static Map modeladdAttribute ( Model model ,Map cacheSCmap,String key1){ return modeladdAttribute(model,cacheSCmap,key1,null); } public static Map modeladdAttribute ( Model model ,Map cacheSCmap,JSONArray json){ if(null!=json&&json.length()>0){ try { for(int i=0;i map,String key){ if(null!=map&&!map.isEmpty()&&StringUtils.isNotBlank(key)){ Object obj=map.get(key); if(null!=obj){ return obj; } } return ""; } public static List predicateList(List list,Map cacheSCmap,Root root,CriteriaBuilder cb,String k1,String key1,String key2){ if(null!=list &&null!=cacheSCmap&&!cacheSCmap.isEmpty()){ if(StringUtils.isBlank(key2)){ key2=key1; } Object val=cacheSCmapVal(cacheSCmap, key2); //System.out.println(val); if(StringUtils.isNotBlank((String)val)){ if(StringUtils.isNotBlank(k1)){ list.add(cb.like(root.get(key1).get(k1).as(String.class), "%" + val + "%")); }else{ list.add(cb.like(root.get(key1).as(String.class), "%" + val + "%")); } } } return list; } public static List predicateList(List list,Map cacheSCmap,Root root,CriteriaBuilder cb,String k1,String key1){ return predicateList(list,cacheSCmap,root,cb,k1,key1,null); } }