资讯动态

peopleSoft 带生效日期结构缓存工具类

发布时间:2026/10/30 4:03:08 来源:尧图企业网站定制
此工具类可以将PS生效日期结构数据全部加载后按照日期快速从内存中读取避免单条查询占用数据库及系统资源。/* 说明: 带生效日期结构缓存工具类父类 ---------------------------------------------------------- */ class EffdtCacheSuper method EffdtCacheSuper(); property integer len get; property integer keyLen get; /* 获取key下所有生效日期行数据 */ method getRowAllEffdtDataByKey(key As string) Returns array of any; protected property JavaObject mapData; property integer _len; property integer _keyLen; /* 添加一行数据 */ method addRowData(key As string, effdt As date, effStatus As string, rowData As any); /* 根据key获取date日最新有效数据行的第index位,并转为字符串仅当addRowData方法添加的rowData为数组时有效否则会报错如果想要无效数据在addRowData时effStatus固定传入A即可实际生效状态可以放在rowData中 */ method getStrByDate(key As string, date As date, index As integer) Returns string; /* 根据key获取date日最新有效数据行如果想要无效数据在addRowData时effStatus固定传入A即可实际生效状态可以放在rowData中 */ method getRowByDate(key As string, date As date) Returns any; /* 是否包含key对应date日的数据 */ method containsCodeByDate(key As string, date As date) Returns boolean; /* 获取所有key */ method getAllKey() Returns array of string; method loading(); method clean(); private method getRowByDateFromRowSet(rowSet As array of array of any, date As date) Returns array of any; instance string lastKey; instance array of array of any lastRowSet; instance array of string rowNull; instance array of string allKey; end-class; method EffdtCacheSuper %This.rowNull CreateArrayRept(, 0); %This.allKey CreateArrayRept(, 0); end-method; get len / Returns Integer / Return %This._len; end-get; get keyLen / Returns Integer / Return %This._keyLen; end-get; method addRowData / key as String, / / effdt as Date, / / effStatus as String, / / rowData as Any / Local array of any dataCP rowData.Clone(); %This.mapData.put(key | effdt, dataCP); Local string lk %This.lastKey; If None(lk) Or lk key Then %This.lastKey key; Local array of array of any rowSet %This.mapData.get(key); If rowSet Null Then rowSet CreateArrayRept(dataCP, 0); %This.allKey.Push(key); %This.mapData.put(key, rowSet); %This._keyLen %This._keyLen 1; End-If; %This.lastRowSet rowSet; End-If; %This.lastRowSet.Push(CreateArrayAny(0, 0)); %This.lastRowSet [%This.lastRowSet.Len][1] effdt; %This.lastRowSet [%This.lastRowSet.Len][2] effStatus; %This.lastRowSet [%This.lastRowSet.Len][3] dataCP; If %This.lastRowSet [1].Len 4 Then %This.lastRowSet [1][4] CreateArrayRept(dataCP, 0); End-If; %This.lastRowSet [1][4].push(dataCP); %This._len %This._len 1; end-method; method getStrByDate / key as String, / / date as Date, / / index as Integer / / Returns String / Local array of any value %This.getRowByDate(key, date); If value Null Then Return ; Else Return String(value [index]); End-If; end-method; method getRowByDate / key as String, / / date as Date / / Returns Any / If %This.mapData Null Then %This.loading(); End-If; Local any value %This.mapData.get(key | date); If value Null Then /* 带日期的缓存中没有按日期查找 */ Local array of array of any rowSet; rowSet %This.mapData.get(key); If rowSet Null Then /* 没有此key */ %This.mapData.put(key | date, %This.rowNull); Else value %This.getRowByDateFromRowSet(rowSet, date); If value Null Then /* 无此key对应日期的数据 */ %This.mapData.put(key | date, %This.rowNull); End-If; End-If; Else If value.len 0 Then /* 带日期缓存标记为空行 */ value Null; End-If; End-If; Return value; end-method; method containsCodeByDate / key as String, / / date as Date / / Returns Boolean / Local array of any value %This.getRowByDate(key, date); Return (value Null); end-method; method getAllKey / Returns Array of String / Return %This.allKey; end-method; method getRowAllEffdtDataByKey / key as String / / Returns Array of Any / Local array of array of any rowSet %This.mapData.get(key); If rowSet Null Then Return Null; Else Return rowSet [1][4]; End-If; end-method; method getRowByDateFromRowSet / rowSet as Array2 of Any, / / date as Date / / Returns Array of Any / Local integer i; For i 1 To rowSet.Len If date rowSet [i][1] Then If rowSet [i][2] A Then Return rowSet [i][3]; Else Return Null; End-If; End-If; End-For; Return Null; end-method; method loading end-method; method clean %This.mapData Null; end-method;部门数据应用代码/* 说明: 部门缓存工具类 ---------------------------------------------------------- */ import COMMON:cacheUtil:EffdtCacheSuper; import COMMON:UTIL:TreeDataManager; import COMMON:UTIL:entity:TreeDataEntity; class DeptCache extends COMMON:cacheUtil:EffdtCacheSuper method DeptCache(loading As boolean); method getDescr(setId As string, deptId As string) Returns string; method getDescrShort(setId As string, deptId As string) Returns string; method getDescrByDate(setId As string, deptId As string, date As date) Returns string; method getCompanyCodeByDate(setId As string, deptId As string, date As date) Returns string; method getDeptAttrCodeByDate(setId As string, deptId As string, date As date) Returns string; method getIsCompanyByDate(setId As string, deptId As string, date As date) Returns boolean; method getIsVirtualCompanyByDate(setId As string, deptId As string, date As date) Returns boolean; method getIsShellCompanyByDate(setId As string, deptId As string, date As date) Returns boolean; method getIsVirtualDeptByDate(setId As string, deptId As string, date As date) Returns boolean; /* 获取部门全称全部门路径描述实时数据 */ method getRealTimePathDescrByDate(setId As string, deptId As string, date As date) Returns string; method getRealTimePathDescrShortByDate(setId As string, deptId As string, date As date) Returns string; /* 获取全部门路径代码实时数据 */ method getRealTimePathCodeByDate(setId As string, deptId As string, date As date) Returns string; /* 获取部门排序字符串从顶级节点向下拼接的结果 */ method getSortStrByDate(setId As string, deptId As string, date As date) Returns string; method containsCode(setId As string, deptId As string) Returns boolean; method containsCodeByDate(setId As string, deptId As string, date As date) Returns boolean; /* 获取对应日期的树管理器树内节点ID为setId|deptId父节点ID同理 */ method getTreeDataManagerByDate(date As date) Returns COMMON:UTIL:TreeDataManager; method getDescrByTreeDataEntity(tde As COMMON:UTIL:entity:TreeDataEntity) Returns string; method getCompanyCodeByTreeDataEntity(tde As COMMON:UTIL:entity:TreeDataEntity) Returns string; method getDeptAttrCodeByTreeDataEntity(tde As COMMON:UTIL:entity:TreeDataEntity) Returns string; method getIsCompanyByTreeDataEntity(tde As COMMON:UTIL:entity:TreeDataEntity) Returns boolean; method getIsVirtualCompanyByTreeDataEntity(tde As COMMON:UTIL:entity:TreeDataEntity) Returns boolean; method getIsShellCompanyByTreeDataEntity(tde As COMMON:UTIL:entity:TreeDataEntity) Returns boolean; method getIsVirtualDeptByTreeDataEntity(tde As COMMON:UTIL:entity:TreeDataEntity) Returns boolean; method clean(); private method loading(); method loadingSortStr(); instance JavaObject sortData; instance JavaObject tempMap; instance array of any treeDataManagerArray; end-class; method DeptCache / loading as Boolean / %Super create COMMON:cacheUtil:EffdtCacheSuper(); %This.treeDataManagerArray CreateArrayAny(); If loading Then %This.loading(); End-If; end-method; method getDescr / setId as String, / / deptId as String / / Returns String / Return %Super.getStrByDate(setId | deptId, %Date, 5); end-method; method getDescrShort / setId as String, / / deptId as String / / Returns String / Return %Super.getStrByDate(setId | deptId, %Date, 6); end-method; method getDescrByDate / setId as String, / / deptId as String, / / date as Date / / Returns String / Return %Super.getStrByDate(setId | deptId, date, 5); end-method; method getCompanyCodeByDate / setId as String, / / deptId as String, / / date as Date / / Returns String / Return %Super.getStrByDate(setId | deptId, date, 8); end-method; method getDeptAttrCodeByDate / setId as String, / / deptId as String, / / date as Date / / Returns String / Return %Super.getStrByDate(setId | deptId, date, 13); end-method; method getIsCompanyByDate / setId as String, / / deptId as String, / / date as Date / / Returns Boolean / Return (%Super.getStrByDate(setId | deptId, date, 9) Y); end-method; method getIsVirtualCompanyByDate / setId as String, / / deptId as String, / / date as Date / / Returns Boolean / Return (%Super.getStrByDate(setId | deptId, date, 11) Y); end-method; method getIsShellCompanyByDate / setId as String, / / deptId as String, / / date as Date / / Returns Boolean / Return (%Super.getStrByDate(setId | deptId, date, 12) Y); end-method; method getIsVirtualDeptByDate / setId as String, / / deptId as String, / / date as Date / / Returns Boolean / Return (%Super.getStrByDate(setId | deptId, date, 10) Y); end-method; method containsCode / setId as String, / / deptId as String / / Returns Boolean / Return %This.containsCodeByDate(setId, deptId, %Date); end-method; method containsCodeByDate / setId as String, / / deptId as String, / / date as Date / / Returns Boolean / Return %Super.containsCodeByDate(setId | deptId, %Date); end-method; method getRealTimePathDescrByDate / setId as String, / / deptId as String, / / date as Date / / Returns String / /* getRowByDate */ If %Super.mapData Null Then %This.loading(); End-If; Local array of any pd %Super.mapData.get(setId | deptId | date | PATH); If pd Null Or pd [1] Then If pd Null Then pd CreateArrayAny( False, 0, True, 0, True, 0); %Super.mapData.put(setId | deptId | date | PATH, pd); Else pd [1] False; End-If; Local string path, superId; If %This.tempMap Null Then %This.tempMap CreateJavaObject(java.util.HashMap); Else If %This.tempMap.containsKey(deptId) Then /* 防止树结构死循环 */ %This.tempMap Null; Return ; End-If; End-If; path %Super.getStrByDate(setId | deptId, %Date, 5); superId %Super.getStrByDate(setId | deptId, %Date, 7); If None(superId) Then pd [2] path; %This.tempMap Null; Else pd [2] %This.getRealTimePathDescrByDate(setId, superId, date) | / | path; End-If; End-If; Return pd [2]; end-method; method getRealTimePathDescrShortByDate / setId as String, / / deptId as String, / / date as Date / / Returns String / /* getRowByDate */ If %Super.mapData Null Then %This.loading(); End-If; Local array of any pd %Super.mapData.get(setId | deptId | date | PATH); If pd Null Or pd [3] Then If pd Null Then pd CreateArrayAny( True, 0, False, 0, True, 0); %Super.mapData.put(setId | deptId | date | PATH, pd); Else pd [3] False; End-If; Local string path, superId; If %This.tempMap Null Then %This.tempMap CreateJavaObject(java.util.HashMap); Else If %This.tempMap.containsKey(deptId) Then /* 防止树结构死循环 */ %This.tempMap Null; Return ; End-If; End-If; path %Super.getStrByDate(setId | deptId, %Date, 6); superId %Super.getStrByDate(setId | deptId, %Date, 7); If None(superId) Then pd [4] path; %This.tempMap Null; Else pd [4] %This.getRealTimePathDescrShortByDate(setId, superId, date) | / | path; End-If; End-If; Return pd [4]; end-method; method getRealTimePathCodeByDate / setId as String, / / deptId as String, / / date as Date / / Returns String / If %Super.mapData Null Then %This.loading(); End-If; Local array of any pd %Super.mapData.get(setId | deptId | date | PATH); If pd Null Or pd [5] Then If pd Null Then pd CreateArrayAny( True, 0, True, 0, False, 0); %Super.mapData.put(setId | deptId | date | PATH, pd); Else pd [5] False; End-If; Local string superId; If %This.tempMap Null Then %This.tempMap CreateJavaObject(java.util.HashMap); Else If %This.tempMap.containsKey(deptId) Then /* 防止树结构死循环 */ %This.tempMap Null; Return ; End-If; End-If; superId %Super.getStrByDate(setId | deptId, %Date, 7); If None(superId) Then pd [6] deptId; %This.tempMap Null; Else pd [6] %This.getRealTimePathCodeByDate(setId, superId, date) | / | deptId; End-If; End-If; Return pd [6]; end-method; method getSortStrByDate / setId as String, / / deptId as String, / / date as Date / / Returns String / If %This.sortData Null Then %This.loadingSortStr(); End-If; Local JavaObject ss %This.sortData.get(setId | deptId | R); If ss Null Then Local string sort, superId; /* Local integer i; Local array of array of string pathSortArray CreateArrayRept(CreateArrayRept(, 0), 0);*/ If %This.tempMap Null Then %This.tempMap CreateJavaObject(java.util.HashMap); Else If %This.tempMap.containsKey(deptId) Then /* 防止树结构死循环 */ %This.tempMap Null; Return ; End-If; End-If; ss %This.sortData.get(setId | deptId); If ss Null Then sort 00000 | setId | 99999 | deptId; Else sort ss.toString(); ss Null; End-If; superId %Super.getStrByDate(setId | deptId, %Date, 7); If None(superId) Then %This.tempMap Null; Else sort %This.getSortStrByDate(setId, superId, date) | sort; End-If; %This.sortData.put(setId | deptId | R, sort); Return sort; Else Return ss.toString(); End-If; end-method; method getTreeDataManagerByDate / date as Date / / Returns COMMON:UTIL:TreeDataManager / Local COMMON:UTIL:TreeDataManager tdm %Super.mapData.get(date | TREE); If tdm Null Then tdm create COMMON:UTIL:TreeDataManager(); %Super.mapData.put(date | TREE, tdm); %This.treeDataManagerArray.Push(tdm); Local array of string allKey %Super.getAllKey(); Local integer i; Local string superId; Local any row; Local COMMON:UTIL:entity:TreeDataEntity tde; For i 1 To allKey.Len row %Super.getRowByDate(allKey [i], date); If row Null Then If None(row [7]) Then superId ; Else superId row [1] | row [7]; End-If; tde create COMMON:UTIL:entity:TreeDataEntity(allKey [i], superId); tde.anyProperty row; tdm.disorderAddTreeNode(tde); End-If; End-For; End-If; Return tdm; end-method; method getDescrByTreeDataEntity / tde as COMMON:UTIL:entity:TreeDataEntity / / Returns String / Return String(tde.anyProperty [5]); end-method; method getCompanyCodeByTreeDataEntity / tde as COMMON:UTIL:entity:TreeDataEntity / / Returns String / Return String(tde.anyProperty [8]); end-method; method getDeptAttrCodeByTreeDataEntity / tde as COMMON:UTIL:entity:TreeDataEntity / / Returns String / Return String(tde.anyProperty [13]); end-method; method getIsCompanyByTreeDataEntity / tde as COMMON:UTIL:entity:TreeDataEntity / / Returns Boolean / Return (String(tde.anyProperty [9]) Y); end-method; method getIsVirtualCompanyByTreeDataEntity / tde as COMMON:UTIL:entity:TreeDataEntity / / Returns Boolean / Return (String(tde.anyProperty [11]) Y); end-method; method getIsShellCompanyByTreeDataEntity / tde as COMMON:UTIL:entity:TreeDataEntity / / Returns Boolean / Return (String(tde.anyProperty [12]) Y); end-method; method getIsVirtualDeptByTreeDataEntity / tde as COMMON:UTIL:entity:TreeDataEntity / / Returns Boolean / Return (String(tde.anyProperty [10]) Y); end-method; method clean %This.sortData Null; %Super.clean(); Local integer i; For i 1 To %This.treeDataManagerArray.Len %This.treeDataManagerArray [i].clean(); End-For; end-method; method loading %Super.mapData CreateJavaObject(java.util.HashMap); Local string sqlStr SELECT DT.SETID, DT.DEPTID, DT.EFFDT, DT.EFF_STATUS, DT.DESCR9, DT.DESCRSHORT; sqlStr sqlStr | , DT.PARENT_BUSINESS, DT.COMPANY, DT.IS_COMPANY, DT.IS_VIRTUAL_DPT; sqlStr sqlStr | , DT.IS_VIRTUAL_COMP, DT.IS_SHELL, DT.DEPT_ATTR ; sqlStr sqlStr | FROM PS_DEPT_TBL DT ; sqlStr sqlStr | ORDER BY DT.SETID, DT.DEPTID, DT.EFFDT DESC; Local array of any data CreateArrayAny(); Local SQL sql CreateSQL(sqlStr); While sql.Fetch(data) %Super.addRowData(data [1] | data [2], data [3], data [4], data.Clone()); End-While; end-method; method loadingSortStr %This.sortData CreateJavaObject(java.util.HashMap); Local string sqlStr SELECT HD.SETID, HD.DEPTID, LPAD(BU.SORT_NBER, 5, 0) || HD.SETID || LPAD( DECODE(HD.DEPT_ORDER,0,99999,HD.DEPT_ORDER) , 5, 0) || HD.DEPTID FROM ; sqlStr sqlStr | PS_DEPT_SORT_HD HD LEFT JOIN PS_BUS_UNIT_TBL_HR BU ON HD.SETID BU.BUSINESS_UNIT; Local array of any data CreateArrayAny(); Local SQL sql CreateSQL(sqlStr); While sql.Fetch(data) %This.sortData.put(data [1] | data [2], data [3]); End-While; end-method;纯Util版/* 说明: 带生效日期结构缓存工具类 ---------------------------------------------------------- 修复点BUG1 拆分两套缓存主map只存原始行集合独立queryCacheMap存放keydate查询缓存 */ class EffdtCacheUtil method EffdtCacheUtil(); property integer len get; property integer keyLen get; /* 添加一行数据同key数据需按生效日期倒序添加否则将触发自动排序降低添加效率 */ method addRowData(key As string, effdt As date, effStatus As string, rowData As any); /* 获取key的date日最新数据 */ method getRowDataByDate(key As string, date As date) Returns any; /* 获取key的date日最新数据状态 */ method getRowStatusByDate(key As string, date As date) Returns string; /* 获取key的date日最新有效数据 */ method getActiveRowDataByDate(key As string, date As date) Returns any; /* 是否包含key对应date日的数据 */ method containsCodeByDate(key As string, date As date) Returns boolean; /* 获取所有key */ method getAllKey() Returns array of string; protected property JavaObject mapData; property JavaObject queryCacheMap; /* 新增独立存放 keydate 查询结果缓存 */ property integer _len; property integer _keyLen; /* 获取key的date日最新数据行 */ method getRowByDate(key As string, date As date) Returns array of any; method clean(); private method getRowByDateFromRowSet(rowSet As array of array of any, date As date) Returns array of any; instance string lastKey; instance array of array of any lastRowSet; instance array of string allKey; end-class; method EffdtCacheUtil %This.mapData CreateJavaObject(java.util.HashMap); %This.queryCacheMap CreateJavaObject(java.util.HashMap); /* 初始化独立查询缓存 */ %This.allKey CreateArrayRept(, 0); end-method; get len / Returns Integer / Return %This._len; end-get; get keyLen / Returns Integer / Return %This._keyLen; end-get; method addRowData / key as String, / / effdt as Date, / / effStatus as String, / / rowData as Any / %This.queryCacheMap.put(key | | effdt, rowData); Local string lk %This.lastKey; If None(lk) Or lk key Then %This.lastKey key; Local array of array of any rowSet %This.mapData.get(key); If rowSet Null Then rowSet CreateArrayRept(CreateArray(), 0); %This.allKey.Push(key); %This.mapData.put(key, rowSet); %This._keyLen %This._keyLen 1; End-If; %This.lastRowSet rowSet; End-If; %This.lastRowSet.Push(CreateArray()); %This.lastRowSet [%This.lastRowSet.Len][1] effdt; %This.lastRowSet [%This.lastRowSet.Len][2] effStatus; %This.lastRowSet [%This.lastRowSet.Len][3] rowData; If rowSet.Len 1 And %This.lastRowSet [%This.lastRowSet.Len - 1][1] effdt Then %This.lastRowSet.Sort(D); End-If; %This._len %This._len 1; end-method; method getRowByDate / key as String, / / date as Date / / Returns Array of Any / Local string mKey key | | date; Local array of any rowData Null; If Not %This.queryCacheMap.containsKey(mKey) Then /* 从独立查询缓存判断 */ Local array of array of any rowSet; rowSet %This.mapData.get(key); If rowSet Null Then /* 没有此key */ %This.queryCacheMap.put(mKey, Null); Else rowData %This.getRowByDateFromRowSet(rowSet, date); %This.queryCacheMap.put(mKey, rowData); End-If; Else rowData %This.queryCacheMap.get(mKey); End-If; Return rowData; end-method; method getRowDataByDate / key as String, / / date as Date / / Returns Any / Local array of any rowData %This.getRowByDate(key, date); If rowData Null Then Return Null; Else Return rowData [3]; End-If; end-method; method getRowStatusByDate / key as String, / / date as Date / / Returns String / Local array of any rowData %This.getRowByDate(key, date); If rowData Null Then Return ; Else Return rowData [2]; End-If; end-method; method getActiveRowDataByDate / key as String, / / date as Date / / Returns Any / Local array of any rowData %This.getRowByDate(key, date); If rowData Null Then Return Null; Else If rowData [2] A Then Return rowData [3]; Else Return Null; End-If; End-If; end-method; method containsCodeByDate / key as String, / / date as Date / / Returns Boolean / Local array of any value %This.getRowByDate(key, date); Return (value Null); end-method; method getAllKey / Returns Array of String / Return %This.allKey; end-method; method getRowByDateFromRowSet / rowSet as Array2 of Any, / / date as Date / / Returns Array of Any / Local integer i; For i 1 To rowSet.Len If date rowSet [i][1] Then Return rowSet [i]; End-If; End-For; Return Null; end-method; method clean %This.mapData Null; %This.queryCacheMap Null; end-method;

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价 →
↑