/**
   * 将查询结果转换sop对象
   *
   * @param sendSop
   * @param startNum
   * @param result
   * @param corporateQueryItemList
   * @param queryNumber
   */
  private void setNormalMessageForSop(
      SopIntf sendSop, PybjyEO record, List<Item0781> list, C0781RowkeyItem item) {
    sendSop.put(null, "JIAOYM", this.getExCode());
    long currentT = System.currentTimeMillis();
    sendSop.put(null, "JIOYRQ", DateTimeFormatUtils.formatDate(currentT, "yyyymmdd"));
    sendSop.put(
        null, "JIOYSJ", Integer.valueOf(DateTimeFormatUtils.formatDate(currentT, "HHmmss")));
    sendSop.put(null, "GUIYLS", record.getGuiyls());
    Short FDCWJYXH = 0;
    sendSop.put(null, "CWJYXH", FDCWJYXH);
    sendSop.put(null, SopIntf.TPU_RETCODE, SopIntf.SOP_SUCC);

    sendSop.put(getFileSent(), "KEHHAO", item.getKehhao());
    sendSop.put(getFileSent(), "KEHUZH", record.getKehuzh());
    sendSop.put(getFileSent(), "GERZWM", item.getGerzwm());
    sendSop.put(getFileSent(), "BISHUU", item.getBishuu() + "");
    Map<String, List<String>> map = convertResultToMap(list);
    sendSop.put(getFileSent(), getFileTable(), "ZHANGH", getStrArrayFromList(map.get("0")));
    sendSop.put(getFileSent(), getFileTable(), "JIOYRQ", getStrArrayFromList(map.get("1")));
    sendSop.put(getFileSent(), getFileTable(), "JIOYSJ", getStrArrayFromList(map.get("2")));
    sendSop.put(getFileSent(), getFileTable(), "HUOBDH", getStrArrayFromList(map.get("3")));
    sendSop.put(getFileSent(), getFileTable(), "CHUIBZ", getStrArrayFromList(map.get("4")));
    sendSop.put(getFileSent(), getFileTable(), "JIO1JE", getStrArrayFromList(map.get("5")));
    sendSop.put(getFileSent(), getFileTable(), "ZHHUYE", getStrArrayFromList(map.get("6")));
    sendSop.put(getFileSent(), getFileTable(), "JIAOYM", getStrArrayFromList(map.get("7")));
    sendSop.put(getFileSent(), getFileTable(), "JIEDBZ", getStrArrayFromList(map.get("8")));
    sendSop.put(getFileSent(), getFileTable(), "JIO1GY", getStrArrayFromList(map.get("9")));
    sendSop.put(getFileSent(), getFileTable(), "SHOQGY", getStrArrayFromList(map.get("10")));
    sendSop.put(getFileSent(), getFileTable(), "CHBUBZ", getStrArrayFromList(map.get("11")));
    sendSop.put(getFileSent(), getFileTable(), "GUIYLS", getStrArrayFromList(map.get("12")));
    sendSop.put(getFileSent(), getFileTable(), "ZHYODM", getStrArrayFromList(map.get("13")));
    sendSop.put(getFileSent(), getFileTable(), "YNGYJG", getStrArrayFromList(map.get("14")));
    sendSop.put(getFileSent(), getFileTable(), "KHZHLX", getStrArrayFromList(map.get("15")));
    sendSop.put(getFileSent(), getFileTable(), "PNGZHH", getStrArrayFromList(map.get("16")));
    sendSop.put(getFileSent(), getFileTable(), "DUIFZH", getStrArrayFromList(map.get("17")));
    sendSop.put(getFileSent(), getFileTable(), "DUIFMC", getStrArrayFromList(map.get("18")));
    sendSop.put(getFileSent(), getFileTable(), "DANWMC", getStrArrayFromList(map.get("19")));
    sendSop.put(getFileSent(), getFileTable(), "ZHUJRQ", getStrArrayFromList(map.get("20")));
    if (!record.getShfobz().equals(HdqsConstants.SHFOBZ_NONE)) {
      String filePath = getFilePathForSyn(record, item);
      setPrintFilePath(sendSop, filePath != null ? filePath : "");
      // setFileDownLoadDir(sendSop);
    }
  }
  public Reply service(TPServiceInformation tpServiceInfor) throws Exception {
    SopIntf recvSop = getSopFromWTC(tpServiceInfor);
    SopIntf sendSop = new SopIntf();
    setSystemHeadForSop(recvSop, sendSop);
    printRecvHeaderPkt(recvSop);

    PybjyEO record = buildAsyQueryRecord(recvSop);
    record.setChaxzl(HdqsConstants.CHAXZL_KEHUZH);
    Handle0781Form form = buildForm(record);
    printRecvFormPkt(form, record);
    try {
      validateField(record);
    } catch (HdqsWtcException e) {
      getLogger().info(getExCode() + " sop invalid: " + e.getMessage());
      if (isFrontAuthorize(record)) {
        return getAuthorizeBuffer(tpServiceInfor, sendSop, Authorize.NO_AUTH_MSG);
      }
      return getExceptionBuffer(tpServiceInfor, sendSop, e.getMessage());
    }
    getLogger().info("Start query:" + getExCode());
    TimerUtils timer = new TimerUtils();
    timer.start();
    PjyjlEO sRecord = saveExchangeRecord(record, form);
    record.setJioyrq(sRecord.getJioyrq());
    String key = buildKey(record);
    isZonghangAuthorize(record);
    try {
      Handle0781Cache cache = Handle0781Cache.getInstance();
      Authorize authorize = new Authorize();
      C0781RowkeyItem rowkeyItem = new C0781RowkeyItem();
      if (!cache.containsKey(key)) {
        Handle0781Query queryAction = new Handle0781Query();
        Query0781Result queryResult = queryAction.load(record);
        Map<Integer, List<RowkeyAndTblContext>> qMap = queryResult.getPageCache();
        // 无论记录明细是否存在,都需要进行授权
        if (queryResult != null && queryResult.getAuthorize() != null) {
          authorize = isNeedAuthorize(record, queryResult.getAuthorize());
          rowkeyItem.setAuthorize(authorize);
        }
        if (qMap != null && qMap.size() > 0) {
          rowkeyItem.setBishuu(queryResult.getBishuu());
          rowkeyItem.setKehuzh(record.getKehuzh());
          rowkeyItem.setKehhao(queryResult.getKehhao());
          rowkeyItem.setGerzwm(queryResult.getGerzwm());
          rowkeyItem.getCache().putAll(qMap);
          getLogger().info("total size: " + rowkeyItem.getBishuu());
        }
        // 无论记录明细是否存在,都缓存
        rowkeyItem.setLastModifiedT(System.currentTimeMillis());
        cache.put(key, rowkeyItem);
      }
      List<Item0781> result = null;
      if (cache.containsKey(key)) {
        rowkeyItem = cache.get(key);
        if (rowkeyItem.getAuthorize() != null) {
          authorize = isNeedCacheAuthorize(rowkeyItem.getAuthorize(), record);
        }
        if (isFrontAuthorize(record) || authorize.isNeedAuth()) {
          getLogger().info(authorize.getPrintMsg());
          return getAuthorizeBuffer(tpServiceInfor, sendSop, authorize.getPrintMsg());
        }

        Map<Integer, List<RowkeyAndTblContext>> itemCache = rowkeyItem.getCache();
        if (itemCache.containsKey(record.getStartNum())) {
          List<RowkeyAndTblContext> pageInfo = itemCache.get(record.getStartNum());
          Adgmx0781Scanner itemQuery = new Adgmx0781Scanner();
          result = itemQuery.query(record, pageInfo);
          getLogger().info("current query size: " + result.size());
        }

        rowkeyItem.setLastModifiedT(System.currentTimeMillis());
        cache.put(key, rowkeyItem);
      }
      if (isFrontAuthorize(record) || authorize.isNeedAuth()) {
        getLogger().info(authorize.getPrintMsg());
        updateExchangeEndTime(sRecord);
        return getAuthorizeBuffer(tpServiceInfor, sendSop, authorize.getPrintMsg());
      }
      if (!cache.containsKey(key) || result == null || result.isEmpty()) {
        timer.stop();
        getLogger().info("存在[0]条记录, Cost time(ms)=" + timer.getExecutionTime());
        updateExchangeEndTime(sRecord);
        return getExceptionBuffer(tpServiceInfor, sendSop, "存在[0]条记录");
      }
      getTPServiceInfoAsResult(tpServiceInfor, record, sendSop, result, rowkeyItem);
    } catch (ConditionNotExistException e) {
      timer.stop();
      getLogger().info(e.getMessage());
      updateExchangeRunErrStatus(sRecord);
      if (isFrontAuthorize(record)) {
        return getAuthorizeBuffer(tpServiceInfor, sendSop, Authorize.NO_AUTH_MSG);
      }
      return getExceptionBuffer(tpServiceInfor, sendSop, e.getMessage());
    } catch (UnCorporationCardException e) {
      timer.stop();
      getLogger().info(e.getMessage());
      updateExchangeRunErrStatus(sRecord);
      if (isFrontAuthorize(record)) {
        return getAuthorizeBuffer(tpServiceInfor, sendSop, Authorize.NO_AUTH_MSG);
      }
      return getExceptionBuffer(tpServiceInfor, sendSop, e.getMessage());
    } catch (BalanceBrokedException e) {
      timer.stop();
      getLogger().info(e.getMessage());
      updateExchangeRunErrStatus(sRecord);
      if (isFrontAuthorize(record)) {
        return getAuthorizeBuffer(tpServiceInfor, sendSop, Authorize.NO_AUTH_MSG);
      }
      return getExceptionBuffer(tpServiceInfor, sendSop, e.getMessage());
    } catch (AsynQueryException e) {
      timer.stop();
      getLogger().info("进入异步查询");
      updateExchangeEndTime(sRecord);
      Authorize asyAuth = isAsyAuthorize(record);
      if (asyAuth.isNeedAuth()) {
        return getAuthorizeBuffer(tpServiceInfor, sendSop, asyAuth.getPrintMsg());
      }
      if (isFrontAuthorize(record)) {
        return getAuthorizeBuffer(tpServiceInfor, sendSop, Authorize.NO_AUTH_MSG);
      }
      this.getYbjyService().add(record);
      return handleAsynchronized(tpServiceInfor, sendSop, record);
    } catch (Exception e) {
      timer.stop();
      getLogger().error(e.getMessage(), e);
      updateExchangeRunErrStatus(sRecord);
      if (isFrontAuthorize(record)) {
        return getAuthorizeBuffer(tpServiceInfor, sendSop, Authorize.NO_AUTH_MSG);
      }
      return getExceptionBuffer(tpServiceInfor, sendSop, "后台查询异常");
    }
    timer.stop();
    getLogger().info(getExCode() + " query complete, Cost time(ms)=" + timer.getExecutionTime());
    updateExchangeEndTime(sRecord);
    return tpServiceInfor;
  }