Преглед изворни кода

解决协议调度-永城数据错误导致的报错,增强代码的健壮性

lipf пре 4 месеци
родитељ
комит
c5c6c77125

+ 11 - 9
tenant/organization/src/main/java/com/jzg/organization/service/impl/PtlAgreementDispatchServiceImpl.java

@@ -202,20 +202,22 @@ public class PtlAgreementDispatchServiceImpl extends ServiceImpl<PtlAgreementDis
                                 }
                             }
                         }else if("change_bs_account".equals(action.getActionCode())){
-                            String accountId = action.getActionJson().get("accountId").toString();
-                            if(Objects.nonNull(accountId)){
-                                HttpResult<PtlAgreementAttribution> agreementAttribution = platformClient.getAgreementAttribution2(accountId);
-                                //HttpResult<PtlAgreementAttribution> agreementAttribution = esmInsCompanyClient.getAgreementAttribution(accountId);
-                                if (agreementAttribution.getCode() == 200) {
-                                    PtlAgreementAttribution data = agreementAttribution.getData();
-                                    action.getActionJson().put("userName", data.getUsername());
-                                    action.getActionJson().put("companyName", data.getInsCompanyName());
+                            if (action.getActionJson() != null && !action.getActionJson().isEmpty()) {
+                                // 修改这里:直接使用 getString,即使值为 null 也不会报错
+                                String accountId = action.getActionJson().getString("accountId");
+                                // 你的 Objects.nonNull 判断依然有效且非常规范
+                                if (Objects.nonNull(accountId)) {
+                                    HttpResult<PtlAgreementAttribution> agreementAttribution = platformClient.getAgreementAttribution2(accountId);
+                                    if (agreementAttribution.getCode() == 200) {
+                                        PtlAgreementAttribution data = agreementAttribution.getData();
+                                        action.getActionJson().put("userName", data.getUsername());
+                                        action.getActionJson().put("companyName", data.getInsCompanyName());
+                                    }
                                 }
                             }
                         }
                     }
                 }
-
                 PtlAgreementDispatchVo.DispatchVo vo = new PtlAgreementDispatchVo.DispatchVo(dispatch,attrLinks,actions);
                 dispatchVos.getDispatchVos().add(vo);
             }