请购单同步旗舰版SRM-更新采购需求数量-V1

This commit is contained in:
mzr 2025-11-15 21:28:05 +08:00
parent 0a79ead6a6
commit 2adb10e87a
1 changed files with 126 additions and 0 deletions

View File

@ -0,0 +1,126 @@
package nc.bs.mmpac.pmo.pac0002.bp.rule.util;
import com.alibaba.fastjson.JSONObject;
import nc.bs.dao.DAOException;
import nc.bs.logging.Logger;
import nc.bs.trade.business.HYSuperDMO;
import nc.vo.bd.defdoc.DefdocVO;
import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
/**
* 请购单同步旗舰版SRM-更新采购需求数量
*
* @author mzr
* @date 2025/11/14
*/
public class SyncSrmPrayBillUtil {
private HYSuperDMO superDMO = null;
private String appKey = "";
private String appSecret = "";
private String baseUrl = "";
private String tokenUrl = "/iuap-api-auth/open-auth/selfAppAuth/getAccessToken";
private String toBipUrl = "";
public HYSuperDMO getSuperDMO() {
if (superDMO == null) {
superDMO = new HYSuperDMO();
}
return superDMO;
}
public void reqBIPBill(JSONObject reqData) {
// 从自定义档案中获取
try {
Map<String, String> bipParamMap = checkBipParam("BIP-sq");
if (bipParamMap.isEmpty()) {
Logger.error("SyncSrmPrayBillUtil-bipParamMap is empty");
return;
}
baseUrl = bipParamMap.get("baseUrl");
appKey = bipParamMap.get("srmappkey");
appSecret = bipParamMap.get("appSecret");
toBipUrl = bipParamMap.get("ipuPuReqQuery");
Logger.error("SyncSrmPrayBillUtil-param = " + reqData.toJSONString());
String url = baseUrl + toBipUrl + "?appKey=" + appKey;
String resultString = doPost(url, reqData);
Logger.error("SyncSrmPrayBillUtil-res = " + resultString);
} catch (Exception e) {
Logger.error("SyncSrmPrayBillUtil-error:" + e.getMessage(), e);
}
}
/**
* 检查bip参数是否完整
*
* @return
*/
private Map<String, String> checkBipParam(String code) {
Map<String, String> map = new HashMap<String, String>();
String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='" + code + "' and dr=0 ) and dr=0";
try {
DefdocVO[] defdocVOs = (DefdocVO[]) getSuperDMO().queryByWhereClause(DefdocVO.class, strWhere);
if (defdocVOs != null && defdocVOs.length > 0) {
for (DefdocVO defdocVO : defdocVOs) {
map.put(defdocVO.getCode().trim(), defdocVO.getName());
}
}
} catch (DAOException e) {
e.printStackTrace();
}
return map;
}
private String doPost(String requestUrl, JSONObject json) throws IOException {
URL u = new URL(requestUrl);
try {
if ("https".equalsIgnoreCase(u.getProtocol())) {// 判定网址是否信任不信任则调用忽略信任工具类SslUtil
nc.vo.so.m30.util.IgnoreSslUtil.ignoreSsl();
}
HttpsURLConnection connection = (HttpsURLConnection) u.openConnection();
// 设置请求方法
connection.setRequestMethod("POST");
// 设置请求属性
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
// 发送POST请求必须设置如下两行
connection.setDoOutput(true);
connection.setDoInput(true);
byte[] outputInBytes = json.toJSONString().getBytes(StandardCharsets.UTF_8);
// 写入数据到请求体
OutputStream os = connection.getOutputStream();
os.write(outputInBytes);
// 获取响应码
int responseCode = connection.getResponseCode();
// System.out.println("Response Code: " + responseCode);
// 读取响应
String response = "";
try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
br.readLine();
// System.out.println("Response: " + response);
}
// 关闭连接
connection.disconnect();
return response;
} catch (Exception e) {
Logger.error("SyncSrmPrayBillUtil-doPost:" + e.getMessage(), e);
}
return null;
}
}