ExtAttributeUtil.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package cn.com.lzt.common.util;
  2. import java.lang.annotation.Annotation;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import javax.persistence.Table;
  6. import org.apache.commons.lang3.StringUtils;
  7. import org.jeecgframework.core.util.ApplicationContextUtil;
  8. import cn.com.lzt.extattribute.entity.ExtAttribulteBaseEntity;
  9. import cn.com.lzt.extattribute.page.ExtAttributePage;
  10. import cn.com.lzt.extattribute.service.ExtAttributeServiceI;
  11. import cn.com.lzt.extattributedefset.entity.ExtAttributeDefsetEntity;
  12. public class ExtAttributeUtil {
  13. private static HashMap<String,HashMap<String,ExtAttributeDefsetEntity>> extAttriSetMap = new HashMap<String, HashMap<String,ExtAttributeDefsetEntity>>();
  14. /*
  15. * 获取扩展属性设置值
  16. * @return 未找到,返回null
  17. * */
  18. public static Object getExtAttritueValue(ExtAttribulteBaseEntity entity, String extcode) {
  19. Object extValue = null;
  20. Annotation[] anno = entity.getClass().getAnnotations();
  21. String tableName = "";
  22. for (int i = 0; i < anno.length; i++) {
  23. if (anno[i] instanceof Table) {
  24. Table table = (Table) anno[i];
  25. System.out.println(table.name());
  26. tableName = table.name();
  27. }
  28. }
  29. boolean contain = false;
  30. if (!extAttriSetMap.containsKey(tableName) || !extAttriSetMap.get(tableName).containsKey(extcode)) {
  31. ExtAttributeServiceI extService = ApplicationContextUtil.getContext().getBean(ExtAttributeServiceI.class);
  32. List<ExtAttributeDefsetEntity> extSetList = extService.getExtSetting(tableName);
  33. if(extSetList.size() == 0)
  34. return null;
  35. HashMap<String,ExtAttributeDefsetEntity> defMap ;
  36. if(extAttriSetMap.containsKey(tableName)) {
  37. defMap = extAttriSetMap.get(tableName);
  38. }else {
  39. defMap = new HashMap<String, ExtAttributeDefsetEntity>();
  40. }
  41. for (ExtAttributeDefsetEntity attri : extSetList) {
  42. if(!defMap.containsKey(attri.getExtcode())){
  43. defMap.put(attri.getExtcode(), attri);
  44. }
  45. if(attri.getExtcode().equals(extcode))
  46. contain = true;
  47. }
  48. }
  49. if(contain) {
  50. String tableField = extAttriSetMap.get(tableName).get(extcode).getTablefieldname();
  51. extValue = BeanRefUtil.getFieldValueMap(entity).get(tableField);
  52. }
  53. return extValue;
  54. }
  55. /**
  56. * 刷新指定单据(档案)的扩展属性设置缓存
  57. * */
  58. public static void refreshExtAttributeSetting(ExtAttributePage extMain) {
  59. HashMap<String, ExtAttributeDefsetEntity> defMap = new HashMap<String, ExtAttributeDefsetEntity>();
  60. for(ExtAttributeDefsetEntity attri: extMain.getExtAttributeDefsetList()) {
  61. if(StringUtils.isNotEmpty(attri.getExtcode()))
  62. defMap.put(attri.getExtcode(), attri);
  63. }
  64. extAttriSetMap.put(extMain.getTablename(), defMap);
  65. }
  66. }