package com.engine.htsc.payment.util;

import cn.hutool.core.lang.Assert;
import weaver.conn.RecordSet;
import weaver.general.Util;

import java.util.HashMap;
import java.util.Map;

public final class PayCommonUtil {

  /**
   * 从总部出纳建模表 uf_zbfk 中获取requestId对应的建模id
   *
   * @param reqId 总部流程的requestId
   * @return ufId
   */
  public static String trans2Id(String reqId) throws Exception {
    RecordSet rs = new RecordSet();
    rs.executeQuery("SELECT ID FROM UF_ZBFK uz WHERE uz.REQUTID = ?", reqId);
    if (rs.next()) {
      return Util.null2String(rs.getString("ID"));
    } else {
      throw new Exception("requestid:" + reqId + ",没有对应的流程ID");
    }
  }

  /**
   * getUnNumberByRequestId
   *
   * @param requestMark requestMark
   * @return unNumber
   */
  public static Map<String, String> getUnNumberByRequestId(String requestMark) throws Exception {
    Assert.notBlank(requestMark, "requestMark不能为空");
    RecordSet rs = new RecordSet();
    Map<String,String> resp = new HashMap<>();
    rs.executeQuery("SELECT wb.UNNUMBER,wr.REQUESTID FROM WORKFLOW_BASE wb\n" +
            "LEFT JOIN WORKFLOW_REQUESTBASE wr \n" +
            "ON wb.ID = wr.WORKFLOWID \n" +
            "WHERE wr.REQUESTMARK = ?", requestMark);
    if (rs.next()) {
      resp.put("UNNUMBER", Util.null2String(rs.getString("UNNUMBER")));
      resp.put("REQUESTID", Util.null2String(rs.getString("REQUESTID")));
      return resp;
    } else {
      throw new IllegalArgumentException("requestMark:" + requestMark + " ,没有对应的流程唯一标识");
    }
  }
}
