删除销售发票后同步修改BIP的开票申请存的NCC信息-init
This commit is contained in:
		
							parent
							
								
									a3c4533095
								
							
						
					
					
						commit
						1e0eb5a2e8
					
				|  | @ -0,0 +1,65 @@ | ||||||
|  | // | ||||||
|  | // Source code recreated from a .class file by IntelliJ IDEA | ||||||
|  | // (powered by FernFlower decompiler) | ||||||
|  | // | ||||||
|  | 
 | ||||||
|  | package nc.bs.so.m32.maintain; | ||||||
|  | 
 | ||||||
|  | import nc.bs.scmpub.rule.VOSagaFrozenValidateRule; | ||||||
|  | import nc.bs.scmpub.ssc.rule.BaseBillDeleteSyncImage; | ||||||
|  | import nc.bs.scmpub.ssc.rule.SyncRPBillRuleForDelete; | ||||||
|  | import nc.bs.so.m32.maintain.rule.delete.*; | ||||||
|  | import nc.bs.so.m32.plugin.BP32PlugInPoint; | ||||||
|  | import nc.impl.pubapp.pattern.data.bill.BillDelete; | ||||||
|  | import nc.impl.pubapp.pattern.rule.IRule; | ||||||
|  | import nc.impl.pubapp.pattern.rule.processer.AroundProcesser; | ||||||
|  | import nc.vo.ml.NCLangRes4VoTransl; | ||||||
|  | import nc.vo.pubapp.pattern.log.TimeLog; | ||||||
|  | import nc.vo.scmpub.res.billtype.SOBillType; | ||||||
|  | import nc.vo.so.m32.entity.SaleInvoiceVO; | ||||||
|  | 
 | ||||||
|  | public class DeleteSaleInvoiceBP { | ||||||
|  |     public DeleteSaleInvoiceBP() { | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void delete(SaleInvoiceVO[] bills) { | ||||||
|  |         AroundProcesser<SaleInvoiceVO> processer = new AroundProcesser(BP32PlugInPoint.DeleteAction); | ||||||
|  |         this.addBeforeRule(processer); | ||||||
|  |         this.addAfterRule(processer); | ||||||
|  |         TimeLog.logStart(); | ||||||
|  |         processer.before(bills); | ||||||
|  |         TimeLog.info(NCLangRes4VoTransl.getNCLangRes().getStrByID("4006008_0", "04006008-0020")); | ||||||
|  |         TimeLog.logStart(); | ||||||
|  |         BillDelete<SaleInvoiceVO> bo = new BillDelete(); | ||||||
|  |         bo.delete(bills); | ||||||
|  |         TimeLog.info(NCLangRes4VoTransl.getNCLangRes().getStrByID("4006008_0", "04006008-0021")); | ||||||
|  |         TimeLog.logStart(); | ||||||
|  |         processer.after(bills); | ||||||
|  |         TimeLog.info(NCLangRes4VoTransl.getNCLangRes().getStrByID("4006008_0", "04006008-0022")); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void addAfterRule(AroundProcesser<SaleInvoiceVO> processer) { | ||||||
|  |         IRule<SaleInvoiceVO> rule = new ReturnBillCodeRule(); | ||||||
|  |         processer.addAfterRule(rule); | ||||||
|  |         IRule<SaleInvoiceVO> updateOppDeleteRule = new UpdateOppDeleteRule(); | ||||||
|  |         processer.addAfterRule(updateOppDeleteRule); | ||||||
|  |         IRule<SaleInvoiceVO> rewriteARSubDeleteRule = new RewriteARSubDeleteRule(); | ||||||
|  |         processer.addAfterRule(rewriteARSubDeleteRule); | ||||||
|  |         IRule<SaleInvoiceVO> rewriteBillDeleteRule = new RewriteBillDeleteRule(); | ||||||
|  |         processer.addAfterRule(rewriteBillDeleteRule); | ||||||
|  |         IRule<SaleInvoiceVO> baseBillDeleteSyncImage = new BaseBillDeleteSyncImage(); | ||||||
|  |         processer.addAfterRule(baseBillDeleteSyncImage); | ||||||
|  |         IRule<SaleInvoiceVO> syncRPBillRuleForDelete = new SyncRPBillRuleForDelete(SOBillType.Invoice.getCode()); | ||||||
|  |         processer.addAfterRule(syncRPBillRuleForDelete); | ||||||
|  |         // 删除后同步修改BIP的开票申请存的NCC信息 | ||||||
|  |         IRule<SaleInvoiceVO> syncBipBillRuleForDelete = new SyncBipBillRuleForDelete(); | ||||||
|  |         processer.addAfterRule(syncBipBillRuleForDelete); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void addBeforeRule(AroundProcesser<SaleInvoiceVO> processer) { | ||||||
|  |         IRule<SaleInvoiceVO> rule = new VOSagaFrozenValidateRule(true); | ||||||
|  |         processer.addBeforeRule(rule); | ||||||
|  |         IRule<SaleInvoiceVO> checkEnableDeleteRule = new CheckEnableDeleteRule(); | ||||||
|  |         processer.addBeforeRule(checkEnableDeleteRule); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,202 @@ | ||||||
|  | package nc.bs.so.m32.maintain.rule.delete; | ||||||
|  | 
 | ||||||
|  | import com.alibaba.fastjson.JSONObject; | ||||||
|  | import com.google.gson.Gson; | ||||||
|  | import com.yonyou.cloud.utils.StringUtils; | ||||||
|  | import nc.bs.logging.Logger; | ||||||
|  | import nc.bs.uapbd.util.IgnoreSslUtil; | ||||||
|  | import nc.impl.pubapp.pattern.rule.IRule; | ||||||
|  | import nc.vo.pubapp.pattern.exception.ExceptionUtils; | ||||||
|  | import nc.vo.so.m32.entity.SaleInvoiceBVO; | ||||||
|  | import nc.vo.so.m32.entity.SaleInvoiceHVO; | ||||||
|  | import nc.vo.so.m32.entity.SaleInvoiceVO; | ||||||
|  | import nccloud.baseapp.core.log.NCCForUAPLogger; | ||||||
|  | 
 | ||||||
|  | import javax.crypto.Mac; | ||||||
|  | import javax.crypto.spec.SecretKeySpec; | ||||||
|  | import javax.net.ssl.HttpsURLConnection; | ||||||
|  | import java.io.*; | ||||||
|  | import java.net.URL; | ||||||
|  | import java.net.URLEncoder; | ||||||
|  | import java.nio.charset.StandardCharsets; | ||||||
|  | import java.security.InvalidKeyException; | ||||||
|  | import java.security.NoSuchAlgorithmException; | ||||||
|  | import java.util.*; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * 删除后同步修改BIP的开票申请存的NCC信息 | ||||||
|  |  * | ||||||
|  |  * @author mzr | ||||||
|  |  * @date 2025/3/20 | ||||||
|  |  */ | ||||||
|  | public class SyncBipBillRuleForDelete implements IRule<SaleInvoiceVO> { | ||||||
|  | 
 | ||||||
|  |     private static String appKey = "a3c57e0d871240e9b9bf56b35001a324"; | ||||||
|  |     private static String appSecret = "a959f7786db8dbb9a2c0493b5855a46bea68ad75"; | ||||||
|  |     private static String tokenUrl = "https://www.tkkfbip.com/iuap-api-auth/open-auth/selfAppAuth/getAccessToken"; | ||||||
|  |     private static String toBipUrl = "https://www.tkkfbip.com/iuap-api-gateway/oxp4h3x6/current_yonbip_default_sys/KKAPI/invoiceApplication/updateInvoice?access_token="; | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void process(SaleInvoiceVO[] vos) { | ||||||
|  |         try { | ||||||
|  |             boolean hasVdef38 = Arrays.stream(vos) | ||||||
|  |                     .map(SaleInvoiceVO::getParentVO) | ||||||
|  |                     .anyMatch(hvo -> StringUtils.isNotEmpty(hvo.getVdef38())); | ||||||
|  |             // 如果vos里边都没有存BIP合同的开票申请的主键,则不往下执行 | ||||||
|  |             if (!hasVdef38) { | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |             String access_token = getAccessToken(); | ||||||
|  |             for (SaleInvoiceVO invoiceVO : vos) { | ||||||
|  |                 SaleInvoiceHVO hvo = invoiceVO.getParentVO(); | ||||||
|  |                 SaleInvoiceBVO[] bvos = invoiceVO.getChildrenVO(); | ||||||
|  |                 if (access_token.isEmpty()) { | ||||||
|  |                     Logger.error("SyncBipBillRuleForDelete-token获取失败"); | ||||||
|  |                     ExceptionUtils.wrappBusinessException("token获取失败"); | ||||||
|  |                 } | ||||||
|  |                 // bip旗舰版发票主键 | ||||||
|  |                 String vdef38 = hvo.getVdef38(); | ||||||
|  |                 Logger.error("SyncBipBillRuleForDelete-vdef38 = " + vdef38); | ||||||
|  |                 if (StringUtils.isNotEmpty(vdef38)) { | ||||||
|  |                     List<JSONObject> childrenList = new ArrayList<>(); | ||||||
|  |                     for (SaleInvoiceBVO bvo : bvos) { | ||||||
|  |                         JSONObject jsonObject = new JSONObject(); | ||||||
|  |                         if (StringUtils.isNotEmpty(bvo.getVbdef14())) { | ||||||
|  |                             jsonObject.put("id", bvo.getVbdef14()); | ||||||
|  |                             jsonObject.put("saleInvoiceDetailId", ""); | ||||||
|  |                             childrenList.add(jsonObject); | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                     JSONObject updateJson = new JSONObject(); | ||||||
|  |                     updateJson.put("id", vdef38); | ||||||
|  |                     updateJson.put("saleInvoiceId", ""); | ||||||
|  |                     updateJson.put("contractInvoiceApplicationDetailList", childrenList); | ||||||
|  |                     String bipRes = doPost(toBipUrl + access_token, updateJson); | ||||||
|  |                     NCCForUAPLogger.debug("SyncBipBillRuleForDelete-bipRes = " + bipRes); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } catch (NoSuchAlgorithmException | InvalidKeyException | IOException e) { | ||||||
|  |             Logger.error("SyncBipBillRuleForDelete-exp:" + e.getMessage(), e); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 获取旗舰版的token | ||||||
|  |      * | ||||||
|  |      * @return token | ||||||
|  |      * @author mzr | ||||||
|  |      * @date 2025/3/20 | ||||||
|  |      */ | ||||||
|  |     private String getAccessToken() throws NoSuchAlgorithmException, InvalidKeyException, IOException { | ||||||
|  |         // 获取旗舰版的token | ||||||
|  |         Map<String, String> params = new HashMap<>(); | ||||||
|  |         // 除签名外的其他参数 | ||||||
|  |         params.put("appKey", appKey); | ||||||
|  |         String timestamp = String.valueOf(System.currentTimeMillis()); | ||||||
|  |         params.put("timestamp", timestamp); | ||||||
|  |         // 计算签名 | ||||||
|  |         Map<String, String> treeMap = new TreeMap<>(params); | ||||||
|  |         StringBuilder stringBuilder = new StringBuilder(); | ||||||
|  |         for (Map.Entry<String, String> entry : treeMap.entrySet()) { | ||||||
|  |             stringBuilder.append(entry.getKey()).append(entry.getValue()); | ||||||
|  |         } | ||||||
|  |         Mac mac = Mac.getInstance("HmacSHA256"); | ||||||
|  |         mac.init(new SecretKeySpec(appSecret.getBytes(StandardCharsets.UTF_8), "HmacSHA256")); | ||||||
|  |         byte[] signData = mac.doFinal(stringBuilder.toString().getBytes(StandardCharsets.UTF_8)); | ||||||
|  |         String base64String = Base64.getEncoder().encodeToString(signData); | ||||||
|  |         String signature = URLEncoder.encode(base64String, "UTF-8"); | ||||||
|  |         params.put("signature", signature); | ||||||
|  |         String responseString = doGet(tokenUrl, params); | ||||||
|  |         Gson gson = new Gson(); | ||||||
|  |         Map result = gson.fromJson(responseString, Map.class); | ||||||
|  |         String access_token = ""; | ||||||
|  |         if (StringUtils.equals("00000", result.get("code").toString())) { | ||||||
|  |             Map<String, Object> tokenInfo = (Map<String, Object>) result.get("data"); | ||||||
|  |             access_token = (String) tokenInfo.get("access_token"); | ||||||
|  |         } | ||||||
|  |         Logger.error("SyncBipBillRuleForDelete-getAccessToken = " + access_token); | ||||||
|  |         return access_token; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private String doGet(String requestUrl, Map<String, String> paramMap) throws IOException { | ||||||
|  | 
 | ||||||
|  |         StringBuilder param = new StringBuilder("?"); | ||||||
|  |         if (paramMap != null) { | ||||||
|  |             for (Map.Entry<String, String> entry : paramMap.entrySet()) { | ||||||
|  |                 param.append(entry.getKey()); | ||||||
|  |                 param.append("="); | ||||||
|  |                 param.append(entry.getValue()); | ||||||
|  |                 param.append("&"); | ||||||
|  |             } | ||||||
|  |             param.deleteCharAt(param.length() - 1); | ||||||
|  |         } | ||||||
|  |         String url = requestUrl + param; | ||||||
|  |         URL u = new URL(url); | ||||||
|  |         try { | ||||||
|  |             if ("https".equalsIgnoreCase(u.getProtocol())) {// 判定网址是否信任,不信任则调用忽略信任工具类SslUtil | ||||||
|  |                 IgnoreSslUtil.ignoreSsl(); | ||||||
|  |             } | ||||||
|  |             HttpsURLConnection connection = (HttpsURLConnection) u.openConnection(); | ||||||
|  |             connection.setRequestMethod("GET"); | ||||||
|  |             connection.setConnectTimeout(5000); | ||||||
|  |             connection.setReadTimeout(5000); | ||||||
|  |             connection.connect(); | ||||||
|  |             StringBuilder response = new StringBuilder(); | ||||||
|  |             int responsecode = connection.getResponseCode(); | ||||||
|  |             if (responsecode == HttpsURLConnection.HTTP_OK) { | ||||||
|  |                 InputStream inputstream = connection.getInputStream(); | ||||||
|  |                 BufferedReader reader = new BufferedReader(new InputStreamReader(inputstream)); | ||||||
|  |                 String line; | ||||||
|  | 
 | ||||||
|  |                 while ((line = reader.readLine()) != null) { | ||||||
|  |                     response.append(line); | ||||||
|  |                 } | ||||||
|  |                 reader.close(); | ||||||
|  |             } | ||||||
|  |             connection.disconnect(); | ||||||
|  |             return response.toString(); | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             Logger.error("SyncBipBillRuleForDelete-doGet:" + e.getMessage(), e); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private String doPost(String requestUrl, JSONObject json) throws IOException { | ||||||
|  |         URL u = new URL(requestUrl); | ||||||
|  |         try { | ||||||
|  |             if ("https".equalsIgnoreCase(u.getProtocol())) {// 判定网址是否信任,不信任则调用忽略信任工具类SslUtil | ||||||
|  |                 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("SyncBipBillRuleForDelete-doPost:" + e.getMessage(), e); | ||||||
|  |         } | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -0,0 +1,60 @@ | ||||||
|  | package nc.bs.uapbd.util; | ||||||
|  | import java.security.cert.CertificateException; | ||||||
|  | import java.security.cert.X509Certificate; | ||||||
|  |   | ||||||
|  | import javax.net.ssl.HostnameVerifier; | ||||||
|  | import javax.net.ssl.HttpsURLConnection; | ||||||
|  | import javax.net.ssl.SSLContext; | ||||||
|  | import javax.net.ssl.SSLSession; | ||||||
|  | import javax.net.ssl.TrustManager; | ||||||
|  | import javax.net.ssl.X509TrustManager; | ||||||
|  |   | ||||||
|  | public class IgnoreSslUtil { | ||||||
|  | 	private static void trustAllHttpsCertificates() throws Exception {   | ||||||
|  | 	    TrustManager[] trustAllCerts = new TrustManager[1];   | ||||||
|  | 	    TrustManager tm = new miTM();   | ||||||
|  | 	    trustAllCerts[0] = tm;   | ||||||
|  | 	    SSLContext sc = SSLContext.getInstance("SSL");   | ||||||
|  | 	    sc.init(null, trustAllCerts, null);   | ||||||
|  | 	    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());   | ||||||
|  | 	}   | ||||||
|  | 	   | ||||||
|  | 	static class miTM implements TrustManager,X509TrustManager {   | ||||||
|  | 	    public X509Certificate[] getAcceptedIssuers() {   | ||||||
|  | 	        return null;   | ||||||
|  | 	    }   | ||||||
|  | 	   | ||||||
|  | 	    public boolean isServerTrusted(X509Certificate[] certs) {   | ||||||
|  | 	        return true;   | ||||||
|  | 	    }   | ||||||
|  | 	   | ||||||
|  | 	    public boolean isClientTrusted(X509Certificate[] certs) {   | ||||||
|  | 	        return true;   | ||||||
|  | 	    }   | ||||||
|  | 	   | ||||||
|  | 	    public void checkServerTrusted(X509Certificate[] certs, String authType)   | ||||||
|  | 	            throws CertificateException {   | ||||||
|  | 	        return;   | ||||||
|  | 	    }   | ||||||
|  | 	   | ||||||
|  | 	    public void checkClientTrusted(X509Certificate[] certs, String authType)   | ||||||
|  | 	            throws CertificateException {   | ||||||
|  | 	        return;   | ||||||
|  | 	    }   | ||||||
|  | 	}   | ||||||
|  | 	    | ||||||
|  | 	/**  | ||||||
|  | 	 * 忽略HTTPS请求的SSL证书,必须在openConnection之前调用  | ||||||
|  | 	 * @throws Exception  | ||||||
|  | 	 */   | ||||||
|  | 	public static void ignoreSsl() throws Exception{   | ||||||
|  | 	    HostnameVerifier hv = new HostnameVerifier() {   | ||||||
|  | 	        public boolean verify(String urlHostName, SSLSession session) {   | ||||||
|  | 	            System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost());   | ||||||
|  | 	            return true;   | ||||||
|  | 	        }   | ||||||
|  | 	    };   | ||||||
|  | 	    trustAllHttpsCertificates();   | ||||||
|  | 	    HttpsURLConnection.setDefaultHostnameVerifier(hv);   | ||||||
|  | 	}   | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue