All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.frameworkset.platform.dictionary.DictDataProvide Maven / Gradle / Ivy

There is a newer version: 5.6.4
Show newest version
package com.frameworkset.platform.dictionary;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.frameworkset.event.Event;
import org.frameworkset.event.EventType;
import org.frameworkset.event.Listener;
import org.frameworkset.event.NotifiableFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.frameworkset.common.poolman.DBUtil;
import com.frameworkset.dictionary.Data;
import com.frameworkset.dictionary.DataManager;
import com.frameworkset.dictionary.Item;
import com.frameworkset.dictionary.ProfessionDataManagerException;
import com.frameworkset.platform.sysmgrcore.exception.ManagerException;

/**
 * 项目:SysMgrCore 
* 描述:为 sysui 中的数据字典组件提供数据的数据提供实现类
* 日期:Apr 20, 2006
* * @author * @author chunqiu.zhao 2007.11.2,biaoping.yin 2008.05.22 */ public class DictDataProvide implements DataManager,Listener { private static Logger logger = LoggerFactory.getLogger(DictDataProvide.class); private Map datas = new ConcurrentHashMap(); private Map datasbyid = new ConcurrentHashMap(); /** * Map>存放机构的列表,这些机构符合编码权限过滤条件 */ private Map taxcodeOrgs = new ConcurrentHashMap(); /** * Map>存放机构的列表,这些机构符合编码权限过滤条件 不包括自己采集的 */ private Map expSelf_taxcodeOrgs = new ConcurrentHashMap(); private static final List NULL_TAXCODEORGS = new ArrayList(0); public DictDataProvide(){} /** * 获取机构-编码关系对象 包括有权限的和自己采集的 * 对象保存的名称是 * @param userId * @param dicttypeId * @param dictdataValue * @return * DictDataProvide.java * @author: ge.tao */ public List getDictDataOpcodeOrgs(String dicttypeId, String dictdataValue,String opcode){ String key = dicttypeId+":"+dictdataValue+":"+opcode; List dictDataUserOrgs = (List)this.taxcodeOrgs.get(key); if(dictDataUserOrgs!=null){ return dictDataUserOrgs; } try { DictManager dictMgr = new DictManagerImpl(); dictDataUserOrgs = dictMgr.getDictDataOpcodeOrgs(dicttypeId, dictdataValue,opcode); if(dictDataUserOrgs != null&& dictDataUserOrgs.size() > 0) { taxcodeOrgs.put(key,dictDataUserOrgs); } else { taxcodeOrgs.put(key,NULL_TAXCODEORGS); } } catch (Exception e1) { logger.error("",e1); } return dictDataUserOrgs; } /** * 获取机构-编码关系对象 包括有权限的 不包括自己采集的 * 对象保存的名称是 * @param userId * @param dicttypeId * @param dictdataValue * @return * DictDataProvide.java * @author: ge.tao */ public List getExpSelfDictDataOpcodeOrgs(String dicttypeId, String dictdataValue,String opcode){ String key = dicttypeId+":"+dictdataValue+":"+opcode; List dictDataUserOrgs = (List)this.expSelf_taxcodeOrgs.get(key); if(dictDataUserOrgs!=null){ return dictDataUserOrgs; } try { DictManager dictMgr = new DictManagerImpl(); dictDataUserOrgs = dictMgr.getExpSelfDictDataOpcodeOrgs(dicttypeId, dictdataValue,opcode); if(dictDataUserOrgs != null&& dictDataUserOrgs.size() > 0) { expSelf_taxcodeOrgs.put(key,dictDataUserOrgs); } else { expSelf_taxcodeOrgs.put(key,NULL_TAXCODEORGS); } } catch (Exception e1) { logger.error("",e1); } return dictDataUserOrgs; } /** * 根据字典类型名称,获取字典类型对象 */ public Data getData(String dictionaryName) throws ProfessionDataManagerException { Data data = (Data)this.datas.get(dictionaryName); if(data != null) { return data; } try { DictManagerImpl dictMgr = new DictManagerImpl(); data = dictMgr.getDicttypeByName(dictionaryName); if(data != null) { //字典类型的顶级数据项对象(Item) List items = dictMgr.getDictdataList(data.getDataId()); // if(data.isTree()) // { // // List newItems = new ArrayList(); // setCacheValue( data, items,newItems); // data.setItems(items); // data.setAllitems(newItems); // // } // else // { // data.setItems(items); // data.setAllitems(items); // } // // datas.put(data.getName(),data); // datasbyid.put(data.getDataId(),data); loadData(data, items); } return data; } catch (ManagerException e1) { logger.error("",e1); } catch (Exception e) { logger.error("",e); } return null; } public Data refreshDataByID(String dictionaryID) { try { removeDictFromCacheByID(dictionaryID); return getDataByID( dictionaryID); } catch (Exception e) { logger.error("",e); } return null; } private static Object lock = new Object(); /** * 根据字典类型ID,获取字典类型对象 */ public Data getDataByID(String dictionaryID) throws ProfessionDataManagerException { DictManagerImpl dictMgr = new DictManagerImpl(); try { Data data = (Data)this.datasbyid.get(dictionaryID); if(data != null) { return data; } synchronized(lock) { data = (Data)this.datasbyid.get(dictionaryID); if(data != null) { return data; } data = dictMgr.getDicttypeById(dictionaryID); if(data != null) { //字典类型的顶级数据项对象(Item) List items = dictMgr.getDictdataList(data.getDataId()); loadData(data, items); } } return data; } catch (ManagerException e1) { logger.error("",e1); } catch (Exception e) { logger.error("",e); } return null; } /** * @param data * @param items */ private void loadData(Data data, List items) { if(data.isTree()) { List newItems = new ArrayList(); setCacheValue( data, items,newItems); data.setItems(items); data.setAllitems(newItems); datas.put(data.getName(),data); datasbyid.put(data.getDataId(),data); } else { data.setItems(items); data.setAllitems(items); if(data.isCachable()) { datas.put(data.getName(),data); datasbyid.put(data.getDataId(),data); } } } public boolean removeDictFromCacheByID(String dictionaryID) throws ProfessionDataManagerException { boolean state = false; try { if(datasbyid != null && datas != null){ Data data = (Data)this.datasbyid.get(dictionaryID); if(data != null && data.isCachable()) { datasbyid.remove(data.getDataId()); datas.remove(data.getName()); state = true; } } } catch (Exception e) { logger.error("",e); } return state; } /** * 递归设置数据到缓冲 * @param dictMgr * @param data * @param items * @param newItems * DictDataProvide.java * @author: ge.tao */ private void setCacheValue(Data data,List items,List newItems){ try{ DictManagerImpl dictMgr = new DictManagerImpl(); for(int i=0;i0){ //System.out.println("-----------递归---------------"); item.setSubItems(subItems); data.setIndexItem(item); newItems.add(item); //放开 就加载全部数据 setCacheValue( data, subItems,newItems); }else{ //System.out.println("-----------不递归---------------"); item.setSubItems(new ArrayList()); data.setIndexItem(item); newItems.add(item); } } }catch(Exception e){ e.printStackTrace(); } //return newItems; } /** * * @param ids 根据字典类型ID:数据项的ID:数据项名称, 如123:45:aa 根节点 123:root:root * @return List * @throws ManagerException * DictDataProvide.java * @author: ge.tao */ public List getChildDictdataList(String ids) throws ManagerException { return null; } /** * 根据字典类型名称,获取字典的数据项列表 */ public List getDataItems(String dictionaryName) throws ProfessionDataManagerException { return getData(dictionaryName).getItems(); } /** * 根据字典类型ID和数据项名称,获取数据项的真实值 */ public String getItemValue(String dictionaryName, String itemName) throws ProfessionDataManagerException { // TODO Auto-generated method stub return getData(dictionaryName).getItemValue(itemName); } /** * 根据字典类型ID和数据项真实值,获取数据项的名称 */ public String getItemName(String dictionaryName, String value) throws ProfessionDataManagerException { // TODO Auto-generated method stub return getData(dictionaryName).getItemName(value); } public void init() throws ProfessionDataManagerException { List eventType = new ArrayList(); eventType.add(DictionaryChangeEvent.DICTIONARY_ADD); eventType.add(DictionaryChangeEvent.DICTIONARY_DATA_ADD); eventType.add(DictionaryChangeEvent.DICTIONARY_DATA_DELETE); eventType.add(DictionaryChangeEvent.DICTIONARY_INFO_UPDATE); eventType.add(DictionaryChangeEvent.DICTIONARY_DATA_ORDERCHANGE); eventType.add(DictionaryChangeEvent.DICTIONARY_DELETE); eventType.add(DictionaryChangeEvent.DICTIONARY_TREE_DATA_ORDERCHANGE); eventType.add(DictionaryChangeEvent.DICTIONARY_DATA_INFO_UPDATE); eventType.add(DictionaryChangeEvent.DICTIONARY_DATA_VALIDATE_UPDATE); eventType.add(DictionaryChangeEvent.DICTIONARY_USERORG_CHANGE_READ); eventType.add( DictionaryChangeEvent.DICTIONARY_USERORG_CHANGE_USUAL); NotifiableFactory.getNotifiable().addListener(this,eventType); } public void reinit() { reset(); } private void reset() { datas.clear(); this.datasbyid.clear(); // description = null; // version = null; // datas = null; } public void handle(Event e) { Object source = e.getSource(); EventType type = e.getType(); Object obj = datasbyid; if(source instanceof Item){ Item dictdata = (Item)source; obj = datasbyid.get(dictdata.getDataId()); }else if(source instanceof Data){ Data dicttype = (Data)source; obj = datasbyid.get(dicttype.getDataId()); } if(obj == null){ return; } //datasbyid synchronized(obj) { //处理事件 if(type .equals( DictionaryChangeEvent.DICTIONARY_ADD)){//新增字典类型 // if(source instanceof Data){ // Data dicttype = (Data)source; // try { // this.getData(dicttype.getName()); // } catch (ProfessionDataManagerException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } // } }else if(type .equals( DictionaryChangeEvent.DICTIONARY_DATA_ADD)){//新增字典数据 if(source instanceof Item){ Item dictdata = (Item)source; try { Data dicttype = this.getDataByID(dictdata.getDataId()); if(dicttype==null) return; if(!dicttype.isCachable()) return; //放置到item列表中 if(dictdata.getParentId()==null || dictdata.getParentId().trim().length()==0 || "null".equalsIgnoreCase(dictdata.getParentId())){ //树形结构,但是 是顶级数据项的 //平铺结构的,直接放到type的item列表中 dicttype.addItem(dictdata); }else{//树形机构,不是顶级数据项,放到子item的item列表中 //======.equals(============================================================================= Map itemsMap = dicttype.getItemsIdxByValue(); if(itemsMap!=null){ //找到父item //为什么找不到根据Value索引的item对象呢??? 重新实例化了ItemsIdxByValueMap Item parentItem = (Item)itemsMap.get(String.valueOf(dictdata.getParentId())); //添加到数据项下 作为数据项的子数据项列表 if(parentItem!=null){ parentItem.addSubItem(dictdata); } } } //放到dicttype的索引 dicttype.setIndexItem(dictdata); } catch (ProfessionDataManagerException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }else if(type .equals( DictionaryChangeEvent.DICTIONARY_DATA_DELETE)){//删除字典数据 if(source instanceof Item){ Item dictdata = (Item)source; try { Data dicttype = this.getDataByID(dictdata.getDataId()); if(dicttype==null) return; if(!dicttype.isCachable()) return; if(dicttype.getIsTree()==DictManager.DICTDATA_IS_TREE){//树形的 Map itemsMap = dicttype.getItemsIdxByValue(); //缓存现有item Item old_item = (Item)itemsMap.get(String.valueOf(dictdata.getValue())); String parentId = old_item.getParentId(); //缓存的父item Item parentItem = (Item)itemsMap.get(String.valueOf(parentId)); List subItems = new ArrayList(); if(parentItem == null){//字典类型的一级数据项. subItems = dicttype.getItems(); }else{//子数据项 subItems = parentItem.getSubItems(); } for(int i=0;i0){ subItem.setDataValidate(flag); updateValidate(subItem.getSubItems(), flag); }else{ subItem.setDataValidate(flag); } } } private void copy(Item old,Item newitem) { newitem.setAttachFields(old.getAttachFields()); newitem.setSubItems(old.getSubItems()); // newitem.set } /* (non-Javadoc) * @see com.frameworkset.dictionary.DataManager#getTaxCodesByUserId(java.lang.String) * @retrun List * 根据用户ID,获取用户所在机构的指定税种的编码,如果dicttypeName=="" 取出所有的税种编码 */ public List getTaxCodesByUserId(String userId,String dicttypeName) { // TODO Auto-generated method stub try { DictManager dictManager = new DictManagerImpl(); return dictManager.getTaxCodesByUserIdAndTypeName(userId,dicttypeName); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } /* (non-Javadoc) * @see com.frameworkset.dictionary.DataManager#getTaxCodesByOrgId(java.lang.String) * @retrun List * 根据机构ID,获取机构的指定税种的编码,如果dicttypeName=="" 取出所有的税种编码 */ public List getTaxCodesByOrgId(String orgId,String dicttypeName) { // TODO Auto-generated method stub try { DictManager dictManager = new DictManagerImpl(); return dictManager.getTaxCodesByOrgIdAndTypeName(orgId,dicttypeName); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } /* (non-Javadoc) * @see com.frameworkset.dictionary.DataManager#hasOrgTaxcodeRelation(java.lang.String, java.lang.String, java.lang.String, java.lang.String) * 判断机构是否设置了 此类型ID,数据项值,操作编码的权限 */ public boolean hasOrgTaxcodeRelation(String orgid, String dictypeid, String dictdatavalue, String opcode) { List orgs = this.getDictDataOpcodeOrgs(dictypeid,dictdatavalue,opcode); if(orgs == null) return false; for(int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy