package cn.com.lzt.common.util; import java.lang.annotation.Annotation; import java.util.HashMap; import java.util.List; import javax.persistence.Table; import org.apache.commons.lang3.StringUtils; import org.jeecgframework.core.util.ApplicationContextUtil; import cn.com.lzt.extattribute.entity.ExtAttribulteBaseEntity; import cn.com.lzt.extattribute.page.ExtAttributePage; import cn.com.lzt.extattribute.service.ExtAttributeServiceI; import cn.com.lzt.extattributedefset.entity.ExtAttributeDefsetEntity; public class ExtAttributeUtil { private static HashMap> extAttriSetMap = new HashMap>(); /* * 获取扩展属性设置值 * @return 未找到,返回null * */ public static Object getExtAttritueValue(ExtAttribulteBaseEntity entity, String extcode) { Object extValue = null; Annotation[] anno = entity.getClass().getAnnotations(); String tableName = ""; for (int i = 0; i < anno.length; i++) { if (anno[i] instanceof Table) { Table table = (Table) anno[i]; System.out.println(table.name()); tableName = table.name(); } } boolean contain = false; if (!extAttriSetMap.containsKey(tableName) || !extAttriSetMap.get(tableName).containsKey(extcode)) { ExtAttributeServiceI extService = ApplicationContextUtil.getContext().getBean(ExtAttributeServiceI.class); List extSetList = extService.getExtSetting(tableName); if(extSetList.size() == 0) return null; HashMap defMap ; if(extAttriSetMap.containsKey(tableName)) { defMap = extAttriSetMap.get(tableName); }else { defMap = new HashMap(); } for (ExtAttributeDefsetEntity attri : extSetList) { if(!defMap.containsKey(attri.getExtcode())){ defMap.put(attri.getExtcode(), attri); } if(attri.getExtcode().equals(extcode)) contain = true; } } if(contain) { String tableField = extAttriSetMap.get(tableName).get(extcode).getTablefieldname(); extValue = BeanRefUtil.getFieldValueMap(entity).get(tableField); } return extValue; } /** * 刷新指定单据(档案)的扩展属性设置缓存 * */ public static void refreshExtAttributeSetting(ExtAttributePage extMain) { HashMap defMap = new HashMap(); for(ExtAttributeDefsetEntity attri: extMain.getExtAttributeDefsetList()) { if(StringUtils.isNotEmpty(attri.getExtcode())) defMap.put(attri.getExtcode(), attri); } extAttriSetMap.put(extMain.getTablename(), defMap); } }