Home > Back-end >  Two layers of the for loop, how to optimize
Two layers of the for loop, how to optimize

Time:12-24

How the two layers of loop optimization, preserved the 500 data, with 40 seconds, bosses help
 
Public String saveRoleGwType () {
RoleId=StringUtils. NVL (roleId);
GwType=StringUtils. NVL (gwType);
Data=https://bbs.csdn.net/topics/StringUtils.nvl (data);
Map Maps=(Map) JSON. Parse (data);
NkSysUsers user=super. GetCurrentUser ();
Date date=new Date();
List RoleGwTypePowerList=new ArrayList (a);
The Date time2=new Date ();
System. The out. Println (" to start the cycle time: "+ time2);

For (String gwType: Arrays. AsList (gwType. The split () ", ")) {
RoleGwTypePowerService. DeletePowerByRoleIdAndGwTypeAndSearchType (roleId, gwType);
For (Map. Entry M: maps. EntrySet ()) {
If (m.g etKey (.) the equals (" TextFileES ") | | m.g etKey (.) the equals (" TextFileSQL ") | |
TextNotFileES m.g etKey (.) the equals (" ") | | m.g etKey (.) the equals (" TextNotFileSQL ")) {
continue;
}
RoleGwTypePower RGTP=new RoleGwTypePower ();
RGTP. SetRoleId (roleId);
RGTP. SetGwType (gwType);
RGTP. SetSearchType (m.g etKey ());
RGTP. SetSearchRightLevel (String. The valueOf (m.g etValue ()));
RGTP. SetCustomRight (String. The valueOf (maps) get (" Text "+ m.g etKey ())));
RGTP. SetCreateUId (user. GetId ());
RGTP. SetCreateUName (user. GetUserName ());
RGTP. SetCreateTime (date);
RGTP. SetStatus (" 1 ");
RoleGwTypePowerList. Add (RGTP);
}
}

The Date time3=new Date ();
System. The out. Println (" the end of the cycle time: "+ time3);
Try {
RoleGwTypePowerService. UpdateDataRoleGwTypePowerList (roleGwTypePowerList);
The Date time4=new Date ();
System. The out. Println (" return to the front of time: "+ time4);
Return the outPut (" ok ");
} the catch (Exception e) {
Return the outPut (" error ");
}

}

  • Related