| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- 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<String,HashMap<String,ExtAttributeDefsetEntity>> extAttriSetMap = new HashMap<String, HashMap<String,ExtAttributeDefsetEntity>>();
- /*
- * 获取扩展属性设置值
- * @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<ExtAttributeDefsetEntity> extSetList = extService.getExtSetting(tableName);
- if(extSetList.size() == 0)
- return null;
- HashMap<String,ExtAttributeDefsetEntity> defMap ;
- if(extAttriSetMap.containsKey(tableName)) {
- defMap = extAttriSetMap.get(tableName);
- }else {
- defMap = new HashMap<String, ExtAttributeDefsetEntity>();
- }
-
- 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<String, ExtAttributeDefsetEntity> defMap = new HashMap<String, ExtAttributeDefsetEntity>();
- for(ExtAttributeDefsetEntity attri: extMain.getExtAttributeDefsetList()) {
- if(StringUtils.isNotEmpty(attri.getExtcode()))
- defMap.put(attri.getExtcode(), attri);
- }
- extAttriSetMap.put(extMain.getTablename(), defMap);
- }
- }
|