定时回写BIP的销售订单-增加回写字段-累计出库主数量

This commit is contained in:
mzr 2025-03-24 16:50:32 +08:00
parent f7a6fca8f9
commit bd4f714e3a
1 changed files with 388 additions and 393 deletions

View File

@ -40,17 +40,16 @@ import java.util.*;
import java.util.zip.GZIPInputStream;
public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlugin {
private HYSuperDMO superDMO = null;
private String baseUrl="https://www.tkkfbip.com";
private String baseUrl = "https://www.tkkfbip.com";
public HYSuperDMO getSuperDMO() {
if(superDMO == null) {
if (superDMO == null) {
superDMO = new HYSuperDMO();
}
@ -59,17 +58,18 @@ public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlug
/**
* 检查bip参数是否完整
*
* @return
*/
private Map<String,String> checkBipParam(){
private Map<String, String> checkBipParam() {
Map<String,String> map = new HashMap<String, String>();
Map<String, String> map = new HashMap<String, String>();
String strWhere=" pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='BIP-sq' and dr=0 ) and dr=0";
String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='BIP-sq' and dr=0 ) and dr=0";
try {
DefdocVO[] defdocVOs=(DefdocVO[]) getSuperDMO().queryByWhereClause(DefdocVO.class, strWhere);
if(defdocVOs!=null&&defdocVOs.length>0) {
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());
@ -93,24 +93,24 @@ public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlug
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateTime = dateFormat.format(date);
Map<String,String> bipParamMap= checkBipParam();
if(bipParamMap.isEmpty()) {
Map<String, String> bipParamMap = checkBipParam();
if (bipParamMap.isEmpty()) {
return null;
}
baseUrl=bipParamMap.get("baseUrl");
Map<String,Object> userMap=arg0.getKeyMap();
String usercustcode="";
baseUrl = bipParamMap.get("baseUrl");
Map<String, Object> userMap = arg0.getKeyMap();
String usercustcode = "";
if(!userMap.isEmpty()) {
if(userMap.get("code")!=null) {
usercustcode=userMap.get("code").toString();
if (!userMap.isEmpty()) {
if (userMap.get("code") != null) {
usercustcode = userMap.get("code").toString();
}
}
String invoiceReceiveUrl = bipParamMap.get("contractSaleOrder");//开票申请单回传
if(StringUtils.isEmpty(invoiceReceiveUrl)) {
String invoiceReceiveUrl = bipParamMap.get("contractSaleOrder");// 开票申请单回传
if (StringUtils.isEmpty(invoiceReceiveUrl)) {
return null;
}
@ -118,11 +118,11 @@ public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlug
Gson gson = new Gson();
//获取未推送合同销售订单更新的销售发票信息
String sql=" select so_saleinvoice_b.cfirstbid,csaleinvoicebid from so_saleinvoice,so_saleinvoice_b where so_saleinvoice.csaleinvoiceid=so_saleinvoice_b.csaleinvoiceid and so_saleinvoice.fstatusflag=2 and nvl(so_saleinvoice_b.vbdef10,'N') in ('~','N') and nvl(so_saleinvoice.vdef13,'~') not in ('~') ";
// 获取未推送合同销售订单更新的销售发票信息
String sql = " select so_saleinvoice_b.cfirstbid,csaleinvoicebid from so_saleinvoice,so_saleinvoice_b where so_saleinvoice.csaleinvoiceid=so_saleinvoice_b.csaleinvoiceid and so_saleinvoice.fstatusflag=2 and nvl(so_saleinvoice_b.vbdef10,'N') in ('~','N') and nvl(so_saleinvoice.vdef13,'~') not in ('~') ";
List<Map<String,String>> l_pk = (List<Map<String, String>>)new BaseDAO().executeQuery(sql.toString(),new MapListProcessor());
if(l_pk.isEmpty()) {
List<Map<String, String>> l_pk = (List<Map<String, String>>) new BaseDAO().executeQuery(sql.toString(), new MapListProcessor());
if (l_pk.isEmpty()) {
return null;
}
@ -130,7 +130,7 @@ public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlug
StringBuffer sb = new StringBuffer();
sb.append(" select so_saleinvoice_b.csaleinvoicebid,so_saleorder.vdef9,so_saleorder_b.vbdef11,so_saleorder_exe.ntotalarmny as totalaccrued ,so_saleorder_exe.ntotalinvoicenum as billqty ");
sb.append(" select so_saleinvoice_b.csaleinvoicebid,so_saleorder.vdef9,so_saleorder_b.vbdef11,so_saleorder_exe.ntotalarmny as totalaccrued ,so_saleorder_exe.ntotalinvoicenum as billqty, NVL(so_saleorder_exe.ntotaloutnum, 0) as totaloutqty ");
sb.append(" from so_saleorder_exe,so_saleinvoice_b,so_saleinvoice,so_saleorder_b,so_saleorder ");
sb.append(" where so_saleorder_exe.csaleorderbid=so_saleinvoice_b.csrcbid ");
sb.append(" and so_saleinvoice.csaleinvoiceid=so_saleinvoice_b.csaleinvoiceid and so_saleinvoice.fstatusflag=2 ");
@ -139,32 +139,33 @@ public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlug
sb.append(" and so_saleorder_exe.dr=0 and so_saleorder.dr=0 and so_saleorder_b.dr=0 ");
sb.append(" and nvl(so_saleorder.vdef9,'~') not in ('~') ");
sb.append(" and so_saleorder_exe.csaleorderbid='").append(map.get("cfirstbid")).append("'");
List<Map<String,String>> ll_saleorder = (List<Map<String, String>>)new BaseDAO().executeQuery(sb.toString(),new MapListProcessor());
List<Map<String, String>> ll_saleorder = (List<Map<String, String>>) new BaseDAO().executeQuery(sb.toString(), new MapListProcessor());
if(ll_saleorder.isEmpty()) {
if (ll_saleorder.isEmpty()) {
continue;
}
try {
String accessToken=getAccessToken(baseUrl,bipParamMap);
Map<String,String> tokenParam = new HashMap<>();
String accessToken = getAccessToken(baseUrl, bipParamMap);
Map<String, String> tokenParam = new HashMap<>();
tokenParam.put("access_token", accessToken);
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
String custUpdateUrl=baseUrl+invoiceReceiveUrl;
if(accessToken!="") {
JSONObject js_apct_detail =new JSONObject();
JSONObject js_apct =new JSONObject();
String hid=ll_saleorder.get(0).get("vdef9");//BIP合同销售订单更新 主表id
List<Map<String,Object>> l_map_f = new ArrayList<Map<String,Object>>();
String custUpdateUrl = baseUrl + invoiceReceiveUrl;
if (accessToken != "") {
JSONObject js_apct_detail = new JSONObject();
JSONObject js_apct = new JSONObject();
String hid = ll_saleorder.get(0).get("vdef9");// BIP合同销售订单更新 主表id
List<Map<String, Object>> l_map_f = new ArrayList<Map<String, Object>>();
for (Map<String, String> custpkmap : ll_saleorder) {
Map<String, Object> b_map = new HashMap<String, Object>();
b_map.put("id", custpkmap.get("vbdef11"));//BIP合同销售订单更新 子表id
b_map.put("billQty", custpkmap.get("billqty"));//累计开票主数量
b_map.put("totalAccrued", custpkmap.get("totalaccrued"));//累计确认应收金额
b_map.put("id", custpkmap.get("vbdef11"));// BIP合同销售订单更新 子表id
b_map.put("billQty", custpkmap.get("billqty"));// 累计开票主数量
b_map.put("totalAccrued", custpkmap.get("totalaccrued"));// 累计确认应收金额
b_map.put("totalOutQty", custpkmap.get("totaloutqty"));// 累计出库主数量
l_map_f.add(b_map);
@ -173,13 +174,13 @@ public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlug
js_apct_detail.put("HTXSDD", js_apct);
String resultString=doSendHttp(custUpdateUrl,"POST",tokenParam,"",headers, js_apct_detail.toJSONString());
String resultString = doSendHttp(custUpdateUrl, "POST", tokenParam, "", headers, js_apct_detail.toJSONString());
Map updateMap = gson.fromJson(resultString, Map.class);
String updateSql="";
if (StringUtils.equals("200", updateMap.get("code").toString())) {//保存更新成功后需要更新日志表
updateSql="update so_saleinvoice_b set vbdef10='Y' where csaleinvoiceid='"+map.get("csaleinvoicebid")+"'";
}else {
updateSql="update so_saleinvoice_b set vbdef10='N' where csaleinvoiceid='"+map.get("csaleinvoicebid")+"'";
String updateSql = "";
if (StringUtils.equals("200", updateMap.get("code").toString())) {// 保存更新成功后需要更新日志表
updateSql = "update so_saleinvoice_b set vbdef10='Y' where csaleinvoiceid='" + map.get("csaleinvoicebid") + "'";
} else {
updateSql = "update so_saleinvoice_b set vbdef10='N' where csaleinvoiceid='" + map.get("csaleinvoicebid") + "'";
}
getSuperDMO().executeUpdateSQL(updateSql);
@ -195,15 +196,13 @@ public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlug
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//获取BIP的token
}// 获取BIP的token
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@ -211,39 +210,39 @@ public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlug
}
/**
* 查询bip 中开户行及银行类型id
*
* @param map
* @param bipUrl
* @return
*/
private static Map<String,String> getBIPBankID(HashMap<String, String> map,String bipUrl,String accessToken,String bankdocname) {
private static Map<String, String> getBIPBankID(HashMap<String, String> map, String bipUrl, String accessToken, String bankdocname) {
Gson gson = new Gson();
Map<String,String> tokenParam = new HashMap<>();
Map<String, String> tokenParam = new HashMap<>();
tokenParam.put("access_token", accessToken);
String jsonData= JSON.toJSONString(map);
String resultString=doSendHttp(bipUrl,"POST",tokenParam,"",new HashMap<>(), jsonData);
String jsonData = JSON.toJSONString(map);
String resultString = doSendHttp(bipUrl, "POST", tokenParam, "", new HashMap<>(), jsonData);
// Map custDetailresult = gson.fromJson(resultString, Map.class);
JSONObject custDetailresult= JSON.parseObject(resultString);
if (StringUtils.equals("200", custDetailresult.get("code").toString())) {//数据存在
Map<String, Object> dataInfo = (Map<String, Object>)custDetailresult.get("data");
if(!MMValueCheck.isEmpty(dataInfo.get("recordList"))){
List<Map<String,String>> l_record=(List<Map<String, String>>) dataInfo.get("recordList");
JSONObject custDetailresult = JSON.parseObject(resultString);
if (StringUtils.equals("200", custDetailresult.get("code").toString())) {// 数据存在
Map<String, Object> dataInfo = (Map<String, Object>) custDetailresult.get("data");
if (!MMValueCheck.isEmpty(dataInfo.get("recordList"))) {
List<Map<String, String>> l_record = (List<Map<String, String>>) dataInfo.get("recordList");
return l_record.get(0);
}else {
} else {
map.remove("linenumber");
map.put("name", bankdocname);
jsonData= JSON.toJSONString(map);
resultString=doSendHttp(bipUrl,"POST",tokenParam,"",new HashMap<>(), jsonData);
jsonData = JSON.toJSONString(map);
resultString = doSendHttp(bipUrl, "POST", tokenParam, "", new HashMap<>(), jsonData);
// custDetailresult = gson.fromJson(resultString, Map.class);
custDetailresult= JSON.parseObject(resultString);
if (StringUtils.equals("200", custDetailresult.get("code").toString())) {//数据存在
dataInfo = (Map<String, Object>)custDetailresult.get("data");
if(!MMValueCheck.isEmpty(dataInfo.get("recordList"))){
List<Map<String,String>> l_record=(List<Map<String, String>>) dataInfo.get("recordList");
custDetailresult = JSON.parseObject(resultString);
if (StringUtils.equals("200", custDetailresult.get("code").toString())) {// 数据存在
dataInfo = (Map<String, Object>) custDetailresult.get("data");
if (!MMValueCheck.isEmpty(dataInfo.get("recordList"))) {
List<Map<String, String>> l_record = (List<Map<String, String>>) dataInfo.get("recordList");
return l_record.get(0);
}
}
@ -253,7 +252,7 @@ public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlug
}
public static String doSendHttp(String baseUrl, String method, Map<String, String> paramMap, String mediaType, Map<String, String> headers, String json){
public static String doSendHttp(String baseUrl, String method, Map<String, String> paramMap, String mediaType, Map<String, String> headers, String json) {
HttpURLConnection urlConnection = null;
InputStream in = null;
OutputStream out = null;
@ -262,13 +261,13 @@ public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlug
try {
StringBuffer sb = new StringBuffer();
sb.append(baseUrl);
if(paramMap != null){
if (paramMap != null) {
sb.append("?");
for (Map.Entry<String, String> entry : paramMap.entrySet()){
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
sb.append(key + "="+ value).append("&");
baseUrl = sb.toString().substring(0,sb.toString().length()- 1);
sb.append(key + "=" + value).append("&");
baseUrl = sb.toString().substring(0, sb.toString().length() - 1);
}
}
// log.error("uRL:" + baseUrl);
@ -276,10 +275,10 @@ public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlug
// log.error("Request URL: " + baseUrl);
// log.error("Request Method: " + method);
URL urlobj = new URL(baseUrl);
if("https".equalsIgnoreCase(urlobj.getProtocol())) {//判定网址是否信任不信任则调用忽略信任工具类SslUtil
if ("https".equalsIgnoreCase(urlobj.getProtocol())) {// 判定网址是否信任不信任则调用忽略信任工具类SslUtil
IgnoreSslUtil.ignoreSsl();
}
urlConnection = (HttpURLConnection)urlobj.openConnection();
urlConnection = (HttpURLConnection) urlobj.openConnection();
urlConnection.setConnectTimeout(50000);
urlConnection.setRequestMethod(method);
urlConnection.setDoInput(true);
@ -291,62 +290,62 @@ public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlug
// log.error("Request Header: " + entry.getKey() + ": " + entry.getValue());
}
}
if(json !=null&&json.length()>0){
if (json != null && json.length() > 0) {
// log.error("Request Body: " + json);
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
out=urlConnection.getOutputStream();
out = urlConnection.getOutputStream();
out.write(json.getBytes("utf-8"));
out.flush();
}
int resCode=urlConnection.getResponseCode();
String ecod=urlConnection.getContentEncoding();
if(resCode==HttpURLConnection.HTTP_OK||resCode== HttpURLConnection.HTTP_CREATED
||resCode==HttpURLConnection.HTTP_ACCEPTED){
if(StringUtils.isNotEmpty(ecod)&&ecod.equals("gzip")) {
in=new GZIPInputStream(urlConnection.getInputStream());
}else{
in=urlConnection.getInputStream();
int resCode = urlConnection.getResponseCode();
String ecod = urlConnection.getContentEncoding();
if (resCode == HttpURLConnection.HTTP_OK || resCode == HttpURLConnection.HTTP_CREATED
|| resCode == HttpURLConnection.HTTP_ACCEPTED) {
if (StringUtils.isNotEmpty(ecod) && ecod.equals("gzip")) {
in = new GZIPInputStream(urlConnection.getInputStream());
} else {
in = urlConnection.getInputStream();
}
}else {
in=urlConnection.getErrorStream();
} else {
in = urlConnection.getErrorStream();
}
bufferedReader =new BufferedReader(new InputStreamReader(in,"utf-8"));
StringBuffer temp=new StringBuffer();
String line=bufferedReader.readLine();
while (line!=null){
bufferedReader = new BufferedReader(new InputStreamReader(in, "utf-8"));
StringBuffer temp = new StringBuffer();
String line = bufferedReader.readLine();
while (line != null) {
temp.append(line).append("\r\n");
line=bufferedReader.readLine();
line = bufferedReader.readLine();
}
if(ecod==null||ecod.equals("gzip")){
ecod= Charset.forName("utf-8").name();
if (ecod == null || ecod.equals("gzip")) {
ecod = Charset.forName("utf-8").name();
}
result=new String(temp.toString().getBytes("utf-8"),ecod);
}catch(Exception e) {
JSONObject js=new JSONObject();
js.put("",-1);
js.put("message","调用外系统接口失败:"+e.getMessage());
result=js.toString();
result = new String(temp.toString().getBytes("utf-8"), ecod);
} catch (Exception e) {
JSONObject js = new JSONObject();
js.put("", -1);
js.put("message", "调用外系统接口失败:" + e.getMessage());
result = js.toString();
e.printStackTrace();
}finally {
if(null!=bufferedReader) {
try{
} finally {
if (null != bufferedReader) {
try {
bufferedReader.close();
}catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
}
if(null!=out) {
try{
if (null != out) {
try {
out.close();
}catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
}
if(null!=in) {
try{
if (null != in) {
try {
in.close();
}catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
}
@ -400,14 +399,14 @@ public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlug
// }
private String getAccessToken(String baseUrl,Map<String,String> bipParamMap) throws NoSuchAlgorithmException, InvalidKeyException, IOException {
String tokenUrl=baseUrl+"/iuap-api-auth/open-auth/selfAppAuth/getAccessToken";
private String getAccessToken(String baseUrl, Map<String, String> bipParamMap) throws NoSuchAlgorithmException, InvalidKeyException, IOException {
String tokenUrl = baseUrl + "/iuap-api-auth/open-auth/selfAppAuth/getAccessToken";
// String appKey = "f10c4bf17b1d4e1fb08eb82bf8540eab";
String appKey = bipParamMap.get("appKey");
// String appSecret = "71dc2a58ca378c1a1143231a62e73e75a60e9236";
String appSecret = bipParamMap.get("appSecret");
String accessToken="";
String accessToken = "";
Map<String, String> params = new HashMap<>();
@ -448,8 +447,7 @@ public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlug
}
private String doPost(String requestUrl,JSONObject jsonObject) throws IOException {
private String doPost(String requestUrl, JSONObject jsonObject) throws IOException {
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(500);
cm.setDefaultMaxPerRoute(50);
@ -512,21 +510,21 @@ public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlug
path += '?' + paramStr;
}
}
//创建远程url连接对象
// 创建远程url连接对象
URL url = new URL(path);
if("https".equalsIgnoreCase(url.getProtocol())){//判定网址是否信任不信任则调用忽略信任工具类SslUtil
if ("https".equalsIgnoreCase(url.getProtocol())) {// 判定网址是否信任不信任则调用忽略信任工具类SslUtil
IgnoreSslUtil.ignoreSsl();
}
//通过远程url连接对象打开一个连接强转成HTTPURLConnection类
// 通过远程url连接对象打开一个连接强转成HTTPURLConnection类
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
//设置连接超时时间和读取超时时间
// 设置连接超时时间和读取超时时间
conn.setConnectTimeout(120000);
conn.setReadTimeout(120000);
conn.setRequestProperty("Accept", "application/json");
//发送请求
// 发送请求
conn.connect();
//通过conn取得输入流并使用Reader读取
// 通过conn取得输入流并使用Reader读取
if (200 == conn.getResponseCode()) {
is = conn.getInputStream();
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
@ -562,9 +560,6 @@ public class ErpSaleOrderToBIPBackgroupWorkPlugin implements IBackgroundWorkPlug
}
// private String doGet(String requestUrl, Map<String, String> paramMap) throws IOException {
// PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
// cm.setMaxTotal(500);