&、&&的区别
1、最终结果一样。
2、&无论左边是false还是true,右边都执行。
3、&&具有短路效果,左边是false,右边不执行。
4、&&效率更高,项目中推荐使用。
|、||的区别
1、最终结果一样。
2、|无论左边是false还是true,右边都会执行。
3、||具有短路效果,左边是true,右边不执行。
4、||效果效率更高,项目中推荐使用。
实例:
if("Apply".equals(actionId)) {
//基础监控评估!=涉及//应用监控评估!=涉及//对账务类交易评估!=涉及//建单人所在部门!=运维室
if(!baseMonAssess(commitCxt) && !appMonassess(commitCxt) && !reconTranEval(commitCxt) && !changeManage(commitCxt)) {
//获取申请版块负责人
getChangePerson(commitCxt);
}
}
private boolean baseMonAssess(WorksheetCommitContext commitCxt) {
Map<String, String> fieldMap = commitCxt.getFieldMap();
if("涉及".equals(fieldMap.get("baseMonAssess"))) {
commitCxt.setAssignString(PropertiesUtils.getPropertyItsm("Change.baseMonAssess"));
return true;
}
return false;
}
private boolean appMonassess(WorksheetCommitContext commitCxt) {
Map<String, String> fieldMap = commitCxt.getFieldMap();
if("涉及".equals(fieldMap.get("appMonassess"))) {
commitCxt.setAssignString(PropertiesUtils.getPropertyItsm("Change.appMonassess"));
return true;
}
return false;
}
private boolean reconTranEval(WorksheetCommitContext commitCxt) {
Map<String, String> fieldMap = commitCxt.getFieldMap();
if("涉及".equals(fieldMap.get("reconTranEval"))) {
commitCxt.setAssignString(PropertiesUtils.getPropertyItsm("Change.reconTranEval"));
return true;
}
return false;
}
private boolean changeManage(WorksheetCommitContext commitCxt) {
Map<String, String> fieldMap = commitCxt.getFieldMap();
Map<String, String> attributeMap = commitCxt.getAttributeMap();
attributeMap.put("UBP_MSCC_CHANGE_DNAME", fieldMap.get("BASECREATORDEP"));
commitCxt.setAttributeMap(attributeMap);
if("运行维护室".equals(fieldMap.get("BASECREATORDEP"))) {
commitCxt.setAssignString(PropertiesUtils.getPropertyItsm("Resource.changeMan"));//
return true;
}
return false;
}
private boolean getChangePerson(WorksheetCommitContext commitCxt) {
Map<String, String> fieldMap = commitCxt.getFieldMap();
String baseCreatorDepId = fieldMap.get("BASECREATORDEPID");//建单人所在部门ID
if(!"运行维护室".equals(fieldMap.get("BASECREATORDEP"))) {//建单人所在部门!=运行维护室
String science = PropertiesUtils.getPropertyItsm("Change.science");
String nextLoginName = "";
DepManagerService depManagerService = (DepManagerService)ApplicationContextUtils.getBean("depManagerService");
List<UserInfo> userList = depManagerService.getUserByDepID(science, false);
if(userList!=null) {
for(UserInfo user:userList) {
if(baseCreatorDepId.equals(user.getDepid())) {
nextLoginName = user.getLoginname();
break;
}
}
if(StringUtils.isBlank(nextLoginName)) {
boolean flag = false;
for(UserInfo user:userList) {
if(flag) break;
List<String> depIdList = depManagerService.getDepIdByUser(user.getPid(), "2");
if(depIdList!=null) {
for(String depId:depIdList) {
if(baseCreatorDepId.equals(depId)) {
nextLoginName = user.getLoginname();
flag = true;
break;
}
}
}
}
}
}
if(StringUtils.isNotBlank(nextLoginName)) {
commitCxt.setAssignString("U#:"+nextLoginName+"#:NEXT#:2#:0#:0#:0#:#:#:#:#;");
return true;
}
}
return false;
}
private boolean getPerson(WorksheetCommitContext commitCxt) {
Map<String, String> fieldMap = commitCxt.getFieldMap();
String baseCreatorDepId = fieldMap.get("BASECREATORDEPID");//建单人所在部门ID
String president = PropertiesUtils.getPropertyItsm("Change.president");
String nextLoginName = "";
DepManagerService depManagerService = (DepManagerService)ApplicationContextUtils.getBean("depManagerService");
List<UserInfo> userList = depManagerService.getUserByDepID(president, false);
if(userList!=null) {
for(UserInfo user:userList) {
if(baseCreatorDepId.equals(user.getDepid())) {
nextLoginName = user.getLoginname();
break;
}
}
if(StringUtils.isBlank(nextLoginName)) {
boolean flag = false;
for(UserInfo user:userList) {
if(flag) break;
List<String> depIdList = depManagerService.getDepIdByUser(user.getPid(), "2");
if(depIdList!=null) {
for(String depId:depIdList) {
if(baseCreatorDepId.equals(depId)) {
nextLoginName = user.getLoginname();
flag = true;
break;
}
}
}
}
}
}
if(StringUtils.isNotBlank(nextLoginName)) {
commitCxt.setAssignString("U#:"+nextLoginName+"#:NEXT#:2#:0#:0#:0#:#:#:#:#;");
return true;
}
return false;
}