範例一:
架構
/**
* 遞歸啓動任務觸發相關事件
* @describe:TODO
* @param oriGroupList
* @param groupId
* @param level
* @return
* @throws ZdnstException
* @author:yongqin.zhong
* @time:Sep 29, 20148:10:21 PM
*/
private void recurrenceStartTask(String taskId,ActionItemTask selItemTaskDto) throws ZdnstException {
try{
Map<String,Object> map=new HashMap<String,Object>();
List<String> relStatusList=new ArrayList<String>();
relStatusList.add(ConstantAction.SYS_ITEM_TASK_STATUS_SS);//開始-開始
relStatusList.add(ConstantAction.SYS_ITEM_TASK_STATUS_SF);//開始-完成
map.put("relStatusList", relStatusList);
map.put("oriTaskId", taskId);
List<Map> relationTaskList=atItemTaskDao.selectTaskRelByOriIdAndStatus(map);
if(relationTaskList!=null&&relationTaskList.size()>0){
for(Map dbItemTaskMap:relationTaskList){
ActionItemTask itemTaskDto=(ActionItemTask)JBeanUtils.convertMap(ActionItemTask.class, dbItemTaskMap);
String relactionStatus=itemTaskDto.getRelactionStatus();
if(ConstantAction.SYS_ITEM_TASK_STATUS_SS.equals(relactionStatus)){
recurrenceStartTask(itemTaskDto.getItemTaskId(),itemTaskDto);
}else if(ConstantAction.SYS_ITEM_TASK_STATUS_SF.equals(relactionStatus)){
recurrenceEndTask(itemTaskDto.getItemTaskId());
}
}
}
} catch (ZdnstException e) {
throw new ZdnstException(e.getCode());
} catch (Exception e) {
logger.error("Service method throws exception:", e);
throw new ZdnstException(BaseCode.ERROR_CODE110, e);
}
}
/**
* 遞歸結束任務觸發相關事件
* @describe:TODO
* @param taskId
* @throws ZdnstException
* @author:yongqin.zhong
* @time:Dec 25, 20145:30:15 PM
*/
private void recurrenceEndTask(String taskId) throws ZdnstException {
try{
Map<String,Object> map=new HashMap<String,Object>();
List<String> relStatusList=new ArrayList<String>();
relStatusList.add(ConstantAction.SYS_ITEM_TASK_STATUS_FS);//完成-開始
relStatusList.add(ConstantAction.SYS_ITEM_TASK_STATUS_FF);//完成-完成
map.put("relStatusList", relStatusList);
map.put("oriTaskId", taskId);
List<Map> relationTaskList=atItemTaskDao.selectTaskRelByOriIdAndStatus(map);
if(relationTaskList!=null&&relationTaskList.size()>0){
for(Map dbItemTaskMap:relationTaskList){
ActionItemTask itemTaskDto=(ActionItemTask)JBeanUtils.convertMap(ActionItemTask.class, dbItemTaskMap);
String relactionStatus=itemTaskDto.getRelactionStatus();
if(ConstantAction.SYS_ITEM_TASK_STATUS_FS.equals(relactionStatus)){
recurrenceStartTask(itemTaskDto.getItemTaskId(),itemTaskDto);
}else if(ConstantAction.SYS_ITEM_TASK_STATUS_FF.equals(relactionStatus)){
recurrenceEndTask(itemTaskDto.getItemTaskId());
}
}
}
} catch (ZdnstException e) {
throw new ZdnstException(e.getCode());
} catch (Exception e) {
logger.error("Service method throws exception:", e);
throw new ZdnstException(BaseCode.ERROR_CODE110, e);
}
}.net
範例二:對象
/**
* 遞歸獲取企業架構樹形結構
* @describe:TODO
* @param oriGroupList
* @param groupId
* @param level
* @return
* @throws ZdnstException
* @author:yongqin.zhong
* @time:Sep 29, 20148:10:21 PM
*/
private ArrayList<Group> getEnterpriseOrganization(List<Group> oriGroupList,String groupId,
int level) throws ZdnstException {
// 首先根據企業圈子ID獲得改圈子的實際對象
ArrayList<Group> clientGroups=new ArrayList<Group>();
for (Group gpGroup : oriGroupList) {
if(gpGroup.getParentId()!=null&&gpGroup.getParentId().equals(groupId)){
clientGroups.add(gpGroup);
//oriGroupList.remove(gpGroup);
}
}
long seqNo=1L;
for (Group gpGroup : clientGroups) {
gpGroup.setGroupLevel(level+"");
gpGroup.setSeqNo(seqNo+"");
seqNo++;
gpGroup.setGroupList(getEnterpriseOrganization(oriGroupList,
gpGroup.getGroupId(), level + 1));
}
return clientGroups;
}
遞歸