瀏覽代碼

续期标签展示新增权限控制

drbjm 3 月之前
父節點
當前提交
98b66e3fdd
共有 1 個文件被更改,包括 187 次插入174 次删除
  1. 187 174
      dgtis-modules/dgtis-modules-data/src/main/java/com/dgtis/data/api/CustomerApiController.java

+ 187 - 174
dgtis-modules/dgtis-modules-data/src/main/java/com/dgtis/data/api/CustomerApiController.java

@@ -11,6 +11,7 @@ import com.dgtis.common.security.utils.SecurityUtils;
 import com.dgtis.data.domain.Customer;
 import com.dgtis.data.service.ISysUserService;
 import com.dgtis.data.util.AddressResolutionUtil;
+import com.dgtis.system.api.domain.SysRole;
 import com.dgtis.system.api.domain.SysUser;
 import com.google.common.collect.Lists;
 import org.apache.commons.lang3.mutable.Mutable;
@@ -328,187 +329,199 @@ public class CustomerApiController {
            map.put("partytimeline",partytimeline);
           logger.info(scriptRequest.getEndpoint());
 
-          //202508 新增续期标签信息和保单信息
-          JSONObject renewalNode = (JSONObject) map.computeIfAbsent("renewalNode", k -> new JSONObject(true));
-
-          //1.标签信息
-          List<String> labelDescs = (List<String>) renewalNode.computeIfAbsent("labelDescs", k -> Lists.newArrayList());
-
-          Stream.of(mpInfo.get("label130"), mpInfo.get("label131"), mpInfo.get("label132"))
-                  .filter(Objects::nonNull)
-                  .map(Object::toString)
-                  .forEach(labelDescs::add);
-
-          Request esRequest = new Request(HttpMethod.GET.name(), "/shanglifeecif.customerno_insurance_policies_info/_search");
-          esRequest.addParameter("pretty", "true");
-          esRequest.setJsonEntity(String.format("{\"query\": {\"bool\": {\"filter\": [{\"term\": {\"customer_no\": \"%s\"}}]}}, \"from\": 0, \"size\": 1000}", scustid));
-          Response esResponse = restClient.performRequest(esRequest);
-          String responseStr = EntityUtils.toString(esResponse.getEntity());
-
-          Optional<List<JSONObject>> optional = Optional.ofNullable(responseStr)
-                  .map(JSON::parseObject)
-                  .map(j -> j.getJSONObject("hits"))
-                  .map(j -> j.getJSONArray("hits"))
-                  .map(hits -> hits.stream()
-                          .filter(o -> o instanceof JSONObject)
-                          .map(o -> (JSONObject) o)
-                          .map(j -> j.getJSONObject("_source"))
-                          .filter(Objects::nonNull)
-                          .collect(Collectors.toList()));
-
-          if (optional.isPresent()) {
-              List<JSONObject> _sources = optional.get();
-
-              LinkedList<Triple<Pair<String, String>, MutableInt, Mutable<String>>> triples = Lists.newLinkedList();
-              //a.交费时间
-              triples.add(new ImmutableTriple<>(new ImmutablePair<>("a", "30天内交费"), new MutableInt(), new MutableObject<>()));
-              triples.add(new ImmutableTriple<>(new ImmutablePair<>("b", "31-50天交费"), new MutableInt(), new MutableObject<>()));
-              triples.add(new ImmutableTriple<>(new ImmutablePair<>("c", "50-60天交费"), new MutableInt(), new MutableObject<>()));
-              triples.add(new ImmutableTriple<>(new ImmutablePair<>("d", "逾期交费"), new MutableInt(), new MutableObject<>()));
-
-              BiConsumer<Triple<Pair<String, String>, MutableInt, Mutable<String>>, JSONObject> consumer = (triple, jsonObj) -> {
-                  String type = triple.getLeft().getKey();
-                  MutableInt num = triple.getMiddle();
-                  Mutable<String> date = triple.getRight();
-                  Optional.of("pay_period_num_".concat(type))
-                          .map(jsonObj::getInteger)
-                          .ifPresent(num::add);
-                  Optional.of("pay_period_date_".concat(type))
-                          .map(jsonObj::getString)
-                          .filter(StringUtils::isNotEmpty)
-                          .map(d -> Optional.ofNullable(date.getValue())
-                                  .filter(_d -> _d.compareTo(d) > 0)
-                                  .orElse(d))
-                          .ifPresent(date::setValue);
-              };
-
-              //b.是否存在暂停扣费
-              MutableInt stopFeeNum = new MutableInt();
-
-              //c.是否存在收费退费
-              MutableInt refundFeeNum = new MutableInt();
-
-              //d.多次联系不上
-              MutableBoolean failedContacted = new MutableBoolean();
-
-              //e.是否存在多张保单
-              MutableInt withinPayPeriodNum = new MutableInt();
-
-              //f_1.是否存在保单挂起_保全挂起中
-              MutableInt bqHangupNum = new MutableInt();
-
-              //f_2是否存在保单挂起_理赔挂起中
-              MutableInt lpHangupNum = new MutableInt();
-
-              _sources.forEach(_source -> {
-                  triples.forEach(triple -> consumer.accept(triple, _source));
-
-                  Optional.ofNullable(_source.getString("policy_label_2"))
-                          .filter(StringUtils::isNotEmpty)
-                          .ifPresent(s -> stopFeeNum.increment());
-
-                  Optional.ofNullable(_source.getString("policy_label_3"))
-                          .filter(StringUtils::isNotEmpty)
-                          .ifPresent(s -> refundFeeNum.increment());
-
-                  Optional.ofNullable(_source.getString("policy_label_4"))
-                          .filter(StringUtils::isNotEmpty)
-                          .ifPresent(s -> failedContacted.setTrue());
-
-                  Optional.ofNullable(_source.getString("is_within_pay_period"))
-                          .filter("Y"::equals)
-                          .ifPresent(s -> withinPayPeriodNum.increment());
-
-                  Optional.ofNullable(_source.getString("policy_label_5"))
-                          .filter(StringUtils::isNotEmpty)
-                          .ifPresent(s -> bqHangupNum.increment());
-
-                  Optional.ofNullable(_source.getString("policy_label_6"))
-                          .filter(StringUtils::isNotEmpty)
-                          .ifPresent(s -> lpHangupNum.increment());
-              });
-
-              triples.stream()
-                      .max((t1, t2) -> {
-                          int cmp = t1.getMiddle().compareTo(t2.getMiddle());
-                          if (cmp != 0) {
-                              return cmp;
-                          }
-                          String date1 = t1.getRight().getValue();
-                          String date2 = t2.getRight().getValue();
-                          if (date1 == null && date2 == null) {
-                              return 0;
-                          } else if (date1 == null) {
-                              return -1;
-                          } else if (date2 == null) {
-                              return 1;
-                          }
-                          return date1.compareTo(date2);
-                      })
-                      .ifPresent(triple -> {
-                          Pair<String, String> pair = triple.getLeft();
-                          String type = pair.getKey();
-                          String desc = pair.getValue();
-                          Integer num = triple.getMiddle().getValue();
-                          if (num > 0) {
-                              if ("d".equals(type)) {
-                                  labelDescs.add(desc.concat("(").concat(num.toString()).concat("次)"));
-                              } else {
-                                  labelDescs.add(desc);
-                                  triple = triples.getLast();
-                                  desc = triple.getLeft().getValue();
-                                  num = triple.getMiddle().getValue();
-                                  if (num > 0) {
+          //权限控制 超级管理员或拥有续期角色才能查看续期标签数据
+          Boolean renewalGranted = Optional.ofNullable(sysUser.getRoles())
+                  .map(roles -> roles.stream()
+                          .map(SysRole::getRoleKey)
+                          .anyMatch(roleKey -> StringUtils.equalsAny(roleKey, "admin", "renewal")))
+                  .orElse(false);
+          if (!renewalGranted) {
+              mpInfo.remove("label130");
+              mpInfo.remove("label131");
+              mpInfo.remove("label132");
+          } else {
+              //202508 新增续期标签信息和保单信息
+              JSONObject renewalNode = (JSONObject) map.computeIfAbsent("renewalNode", k -> new JSONObject(true));
+
+              //1.标签信息
+              List<String> labelDescs = (List<String>) renewalNode.computeIfAbsent("labelDescs", k -> Lists.newArrayList());
+
+              Stream.of(mpInfo.get("label130"), mpInfo.get("label131"), mpInfo.get("label132"))
+                      .filter(Objects::nonNull)
+                      .map(Object::toString)
+                      .forEach(labelDescs::add);
+
+              Request esRequest = new Request(HttpMethod.GET.name(), "/shanglifeecif.customerno_insurance_policies_info/_search");
+              esRequest.addParameter("pretty", "true");
+              esRequest.setJsonEntity(String.format("{\"query\": {\"bool\": {\"filter\": [{\"term\": {\"customer_no\": \"%s\"}}]}}, \"from\": 0, \"size\": 1000}", scustid));
+              Response esResponse = restClient.performRequest(esRequest);
+              String responseStr = EntityUtils.toString(esResponse.getEntity());
+
+              Optional<List<JSONObject>> optional = Optional.ofNullable(responseStr)
+                      .map(JSON::parseObject)
+                      .map(j -> j.getJSONObject("hits"))
+                      .map(j -> j.getJSONArray("hits"))
+                      .map(hits -> hits.stream()
+                              .filter(o -> o instanceof JSONObject)
+                              .map(o -> (JSONObject) o)
+                              .map(j -> j.getJSONObject("_source"))
+                              .filter(Objects::nonNull)
+                              .collect(Collectors.toList()));
+
+              if (optional.isPresent()) {
+                  List<JSONObject> _sources = optional.get();
+
+                  LinkedList<Triple<Pair<String, String>, MutableInt, Mutable<String>>> triples = Lists.newLinkedList();
+                  //a.交费时间
+                  triples.add(new ImmutableTriple<>(new ImmutablePair<>("a", "30天内交费"), new MutableInt(), new MutableObject<>()));
+                  triples.add(new ImmutableTriple<>(new ImmutablePair<>("b", "31-50天交费"), new MutableInt(), new MutableObject<>()));
+                  triples.add(new ImmutableTriple<>(new ImmutablePair<>("c", "50-60天交费"), new MutableInt(), new MutableObject<>()));
+                  triples.add(new ImmutableTriple<>(new ImmutablePair<>("d", "逾期交费"), new MutableInt(), new MutableObject<>()));
+
+                  BiConsumer<Triple<Pair<String, String>, MutableInt, Mutable<String>>, JSONObject> consumer = (triple, jsonObj) -> {
+                      String type = triple.getLeft().getKey();
+                      MutableInt num = triple.getMiddle();
+                      Mutable<String> date = triple.getRight();
+                      Optional.of("pay_period_num_".concat(type))
+                              .map(jsonObj::getInteger)
+                              .ifPresent(num::add);
+                      Optional.of("pay_period_date_".concat(type))
+                              .map(jsonObj::getString)
+                              .filter(StringUtils::isNotEmpty)
+                              .map(d -> Optional.ofNullable(date.getValue())
+                                      .filter(_d -> _d.compareTo(d) > 0)
+                                      .orElse(d))
+                              .ifPresent(date::setValue);
+                  };
+
+                  //b.是否存在暂停扣费
+                  MutableInt stopFeeNum = new MutableInt();
+
+                  //c.是否存在收费退费
+                  MutableInt refundFeeNum = new MutableInt();
+
+                  //d.多次联系不上
+                  MutableBoolean failedContacted = new MutableBoolean();
+
+                  //e.是否存在多张保单
+                  MutableInt withinPayPeriodNum = new MutableInt();
+
+                  //f_1.是否存在保单挂起_保全挂起中
+                  MutableInt bqHangupNum = new MutableInt();
+
+                  //f_2是否存在保单挂起_理赔挂起中
+                  MutableInt lpHangupNum = new MutableInt();
+
+                  _sources.forEach(_source -> {
+                      triples.forEach(triple -> consumer.accept(triple, _source));
+
+                      Optional.ofNullable(_source.getString("policy_label_2"))
+                              .filter(StringUtils::isNotEmpty)
+                              .ifPresent(s -> stopFeeNum.increment());
+
+                      Optional.ofNullable(_source.getString("policy_label_3"))
+                              .filter(StringUtils::isNotEmpty)
+                              .ifPresent(s -> refundFeeNum.increment());
+
+                      Optional.ofNullable(_source.getString("policy_label_4"))
+                              .filter(StringUtils::isNotEmpty)
+                              .ifPresent(s -> failedContacted.setTrue());
+
+                      Optional.ofNullable(_source.getString("is_within_pay_period"))
+                              .filter("Y"::equals)
+                              .ifPresent(s -> withinPayPeriodNum.increment());
+
+                      Optional.ofNullable(_source.getString("policy_label_5"))
+                              .filter(StringUtils::isNotEmpty)
+                              .ifPresent(s -> bqHangupNum.increment());
+
+                      Optional.ofNullable(_source.getString("policy_label_6"))
+                              .filter(StringUtils::isNotEmpty)
+                              .ifPresent(s -> lpHangupNum.increment());
+                  });
+
+                  triples.stream()
+                          .max((t1, t2) -> {
+                              int cmp = t1.getMiddle().compareTo(t2.getMiddle());
+                              if (cmp != 0) {
+                                  return cmp;
+                              }
+                              String date1 = t1.getRight().getValue();
+                              String date2 = t2.getRight().getValue();
+                              if (date1 == null && date2 == null) {
+                                  return 0;
+                              } else if (date1 == null) {
+                                  return -1;
+                              } else if (date2 == null) {
+                                  return 1;
+                              }
+                              return date1.compareTo(date2);
+                          })
+                          .ifPresent(triple -> {
+                              Pair<String, String> pair = triple.getLeft();
+                              String type = pair.getKey();
+                              String desc = pair.getValue();
+                              Integer num = triple.getMiddle().getValue();
+                              if (num > 0) {
+                                  if ("d".equals(type)) {
                                       labelDescs.add(desc.concat("(").concat(num.toString()).concat("次)"));
+                                  } else {
+                                      labelDescs.add(desc);
+                                      triple = triples.getLast();
+                                      desc = triple.getLeft().getValue();
+                                      num = triple.getMiddle().getValue();
+                                      if (num > 0) {
+                                          labelDescs.add(desc.concat("(").concat(num.toString()).concat("次)"));
+                                      }
                                   }
                               }
-                          }
-                      });
-
-              Optional.of(stopFeeNum)
-                      .map(MutableInt::getValue)
-                      .filter(num -> num > 0)
-                      .ifPresent(num -> labelDescs.add("有暂停扣费".concat("(").concat(num.toString()).concat("单)")));
-
-              Optional.of(refundFeeNum)
-                      .map(MutableInt::getValue)
-                      .filter(num -> num > 0)
-                      .ifPresent(num -> labelDescs.add("有续期收费回退".concat("(").concat(num.toString()).concat("单)")));
-
-              if (failedContacted.isTrue()) {
-                  labelDescs.add("多次联系不上");
+                          });
+
+                  Optional.of(stopFeeNum)
+                          .map(MutableInt::getValue)
+                          .filter(num -> num > 0)
+                          .ifPresent(num -> labelDescs.add("有暂停扣费".concat("(").concat(num.toString()).concat("单)")));
+
+                  Optional.of(refundFeeNum)
+                          .map(MutableInt::getValue)
+                          .filter(num -> num > 0)
+                          .ifPresent(num -> labelDescs.add("有续期收费回退".concat("(").concat(num.toString()).concat("单)")));
+
+                  if (failedContacted.isTrue()) {
+                      labelDescs.add("多次联系不上");
+                  }
+
+                  Optional.of(withinPayPeriodNum)
+                          .map(MutableInt::getValue)
+                          .filter(num -> num >= 2)
+                          .ifPresent(num -> labelDescs.add("多单交费".concat("(").concat(num.toString()).concat("单)")));
+
+                  Optional.of(bqHangupNum)
+                          .map(MutableInt::getValue)
+                          .filter(num -> num > 0)
+                          .ifPresent(num -> labelDescs.add("保全挂起中".concat("(").concat(num.toString()).concat("单)")));
+
+                  Optional.of(lpHangupNum)
+                          .map(MutableInt::getValue)
+                          .filter(num -> num > 0)
+                          .ifPresent(num -> labelDescs.add("理赔挂起中".concat("(").concat(num.toString()).concat("单)")));
               }
 
-              Optional.of(withinPayPeriodNum)
-                      .map(MutableInt::getValue)
-                      .filter(num -> num >= 2)
-                      .ifPresent(num -> labelDescs.add("多单交费".concat("(").concat(num.toString()).concat("单)")));
-
-              Optional.of(bqHangupNum)
-                      .map(MutableInt::getValue)
-                      .filter(num -> num > 0)
-                      .ifPresent(num -> labelDescs.add("保全挂起中".concat("(").concat(num.toString()).concat("单)")));
-
-              Optional.of(lpHangupNum)
-                      .map(MutableInt::getValue)
-                      .filter(num -> num > 0)
-                      .ifPresent(num -> labelDescs.add("理赔挂起中".concat("(").concat(num.toString()).concat("单)")));
+              //2.保单信息 过滤只展示投保人数据
+              List<Object> policyInfos = (List<Object>) renewalNode.computeIfAbsent("policyInfos",
+                      k -> Lists.newArrayListWithCapacity(insurancearrangement.size()));
+
+              ((List<Object>) insurancearrangement).stream()
+                      .filter(o -> {
+                          Map mp = (Map) o;
+                          String applicantscustid = Optional.ofNullable(mp.get("applicantscustid"))
+                                  .map(Object::toString)
+                                  .orElse(null);
+                          return StringUtils.equals(applicantscustid, scustid);
+                      })
+                      .forEach(policyInfos::add);
           }
 
-          //2.保单信息 过滤只展示投保人数据
-          List<Object> policyInfos = (List<Object>) renewalNode.computeIfAbsent("policyInfos",
-                  k -> Lists.newArrayListWithCapacity(insurancearrangement.size()));
-
-          ((List<Object>) insurancearrangement).stream()
-                  .filter(o -> {
-                      Map mp = (Map) o;
-                      String applicantscustid = Optional.ofNullable(mp.get("applicantscustid"))
-                              .map(Object::toString)
-                              .orElse(null);
-                      return StringUtils.equals(applicantscustid, scustid);
-                  })
-                  .forEach(policyInfos::add);
-
           logger.info("出客户详情时间:"+DateUtils.getTime());
             return AjaxResult.success(map);
         } catch (Exception e) {