if( interalOrgSet.contains( role.getType() ) )
toRole = role;
}
if( fromRole != null && toRole != null ){
PartyRelationship pr = new PartyRelationship(
RelationshipType.ORG_ROLLUP,fromRole,toRole );
partyRelationshipManager.save( pr );
}
}else{ //修改数据
RoleType type = types[0];
for( RoleType item:types ){
if( !RoleType.PARENT_ORG.equals(item))
type = item;
}
PartyRole newFromRole = null;
List<PartyRole> savedPartyRoles = partyRoleManager.list(
party, RoleType.internalOrg() );
if( savedPartyRoles != null && !savedPartyRoles.isEmpty()){
//savedPartyRoles.size()>1 数据有问题
newFromRole = savedPartyRoles.get(0);
savedPartyRoles.get(0).setType( type );
}else{
//用于数据容错,正常情况不会执行
newFromRole = new PartyRole(party,type);
savedPartyRoles.add( newFromRole );
}
partyRoleManager.save(savedPartyRoles);
if( party.getParent() != null ){
PartyRole newToRole = null;
RoleType[] allowedSelectTypes = RoleType.internalOrg();
RoleType[] paramRoleTypes = new RoleType[allowedSelectTypes.length+1];
paramRoleTypes[allowedSelectTypes.length] = RoleType.PARENT_ORG;
System.arraycopy( allowedSelectTypes,0, paramRoleTypes, 0,allowedSelectTypes.length);
List<PartyRole> newToRoles = partyRoleManager.list(
party.getParent(), paramRoleTypes );
if( newToRoles != null && !newToRoles.isEmpty() ){
newToRole = newToRoles.get(0);
for( PartyRole role:newToRoles )
if( RoleType.PARENT_ORG.equals(role.getType()) )
newToRole = role;
}else{
throw new ApplicationException("("+ party.getParent().getName()+")缺失["
+RoleType.internalOrg()+"]中的一种角色!");
}
PartyRelationship pr = partyRelationshipManager.getRollupByFromParty( party );
if( pr != null ){
pr.setTo( newToRole );
//pr.setFrom(newFromRole);
}else{
pr = new PartyRelationship(RelationshipType.ORG_ROLLUP
,newFromRole,newToRole );
}
partyRelationshipManager.save( pr );
}
}