收款单修改
This commit is contained in:
		
							parent
							
								
									ad8c2fa6d6
								
							
						
					
					
						commit
						f76fc42505
					
				|  | @ -0,0 +1,261 @@ | |||
| package nc.bs.arap.busireg; | ||||
| 
 | ||||
| import com.alibaba.fastjson.JSONObject; | ||||
| import com.google.gson.Gson; | ||||
| import com.yonyou.cloud.utils.StringUtils; | ||||
| import nc.bs.businessevent.BdUpdateEvent; | ||||
| import nc.bs.businessevent.BusinessEvent; | ||||
| import nc.bs.businessevent.IBusinessEvent; | ||||
| import nc.bs.businessevent.IBusinessListener; | ||||
| import nc.bs.dao.BaseDAO; | ||||
| import nc.bs.trade.business.HYSuperDMO; | ||||
| import nc.bs.uapbd.util.IgnoreSslUtil; | ||||
| import nc.jdbc.framework.processor.ColumnProcessor; | ||||
| import nc.jdbc.framework.processor.MapProcessor; | ||||
| import nc.vo.arap.basebill.BaseAggVO; | ||||
| import nc.vo.arap.utils.ArrayUtil; | ||||
| import nc.vo.pub.AggregatedValueObject; | ||||
| import nc.vo.pub.BusinessException; | ||||
| import nc.vo.pub.CircularlyAccessibleValueObject; | ||||
| import nc.vo.pub.lang.UFDouble; | ||||
| import nc.vo.so.m30.entity.SaleOrderHVO; | ||||
| import nccloud.bs.arap.sagas.util.SagasUtils; | ||||
| import nccloud.commons.lang.ArrayUtils; | ||||
| 
 | ||||
| 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.util.Base64; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| import java.util.TreeMap; | ||||
| 
 | ||||
| public class BusiregForSyncSaleorderAndToBIP implements IBusinessListener{ | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void doAction(IBusinessEvent event) throws BusinessException { | ||||
| 		// TODO Auto-generated method stub | ||||
| 		BaseAggVO[] bills = getBills(event); | ||||
| 		if (ArrayUtils.isEmpty(bills) || SagasUtils.isCompensateStage()) { | ||||
| 			return; | ||||
| 		} | ||||
| 		// 更新 销售订单 | ||||
| 		try { | ||||
| 			BaseDAO dao = new BaseDAO(); | ||||
| 			for(BaseAggVO aggvo : bills) { | ||||
| 				CircularlyAccessibleValueObject headvo = aggvo.getParentVO(); | ||||
| 				// 本次收款金额 | ||||
| 				Object money = headvo.getAttributeValue("money"); | ||||
| 				// 收款单主键 | ||||
| 				Object pk_busibill = headvo.getAttributeValue("pk_gatherbill"); | ||||
| 				// 销售订单主键 | ||||
| 				Object csaleorderid = headvo.getAttributeValue("def3"); | ||||
| 				// 根据销售订单主键,查询比较字段 | ||||
| 				String sql = "select vdef17, vdef15, vdef14, vdef11, vdef9 from so_saleorder where csaleorderid = '" + csaleorderid + "' and dr = 0 "; | ||||
| 				HashMap hm = (HashMap)dao.executeQuery(sql, new MapProcessor()); | ||||
| 				Object vdef17 = hm.get("vdef17"); | ||||
| 				Object vdef15 = hm.get("vdef15"); | ||||
| 				Object vdef14 = hm.get("vdef14"); | ||||
| 				Object vdef11 = hm.get("vdef11"); | ||||
| 				Object  vdef9 = hm.get("vdef9"); | ||||
| 				// 合同号 | ||||
| 				Object ctpk = aggvo.getChildrenVO()[0].getAttributeValue("def6"); | ||||
| 				// 查询合同号下 | ||||
| 				String sql1 = " select sum(ar_gatheritem.money_cr) sk_effect_money " +  | ||||
| 							 " from ar_gatheritem " +  | ||||
| 							 " left join ar_gatherbill on ar_gatherbill.pk_gatherbill = ar_gatheritem.pk_gatherbill " +  | ||||
| 							 " where ar_gatherbill.dr = 0 and ar_gatheritem.dr = 0 and ar_gatherbill.EFFECTSTATUS = 10 " +  | ||||
| 							 " and ar_gatheritem.def6 = '" + ctpk + "'"; | ||||
| 				Object obj = dao.executeQuery(sql1, new ColumnProcessor()); | ||||
| 				// 收款单累计金额 | ||||
| 				UFDouble sk_effect_money = UFDouble.ZERO_DBL; | ||||
| 				if(obj != null) { | ||||
| 					sk_effect_money = new UFDouble(obj.toString()); | ||||
| 				} | ||||
| 				// 表头合同金额 | ||||
| 				UFDouble ctmoney = UFDouble.ZERO_DBL; | ||||
| 				if(vdef17 != null) { | ||||
| 					ctmoney = new UFDouble(vdef17.toString()); | ||||
| 				} | ||||
| 				// 预收比例 | ||||
| 				UFDouble preratio = UFDouble.ZERO_DBL; | ||||
| 				if(vdef15 != null) { | ||||
| 					preratio = new UFDouble(vdef15.toString()); | ||||
| 				} | ||||
| 				// 收款大于预收 | ||||
| 				if (sk_effect_money.compareTo(UFDouble.ZERO_DBL) > 0 && sk_effect_money.sub(ctmoney.multiply(preratio)).compareTo(UFDouble.ZERO_DBL) >= 0) { | ||||
| 					String updateSQL = "update so_saleorder set vdef11 = (select pk_defdoc from bd_defdoc where code = 'fhk01') where csaleorderid = '" + csaleorderid + "'"; | ||||
| 					dao.executeUpdate(updateSQL); | ||||
| 				} else if (sk_effect_money.compareTo(UFDouble.ZERO_DBL) > 0 && sk_effect_money.sub(ctmoney.multiply(preratio)).compareTo(UFDouble.ZERO_DBL) < 0) { | ||||
| 					String updateSQL = "update so_saleorder set vdef11 = (select pk_defdoc from bd_defdoc where code = 'fhk02') where csaleorderid = '" + csaleorderid + "'"; | ||||
| 					dao.executeUpdate(updateSQL); | ||||
| 				} | ||||
| 				JSONObject HTXSDD = new JSONObject(); | ||||
| 				HTXSDD.put("id", vdef9); | ||||
| 				HYSuperDMO dmo= new HYSuperDMO(); | ||||
| 				SaleOrderHVO[] hvo = (SaleOrderHVO[])dmo.queryByWhereClause(SaleOrderHVO.class, "csaleorderid='"+csaleorderid+"'"); | ||||
| 				 | ||||
| 				 | ||||
| 				// 实际预收款 npreceivemny | ||||
| 				UFDouble npreceivemny = hvo[0].getNpreceivemny(); | ||||
| 				JSONObject p = new JSONObject(); | ||||
| 				HTXSDD.put("actPreRecvAmt", npreceivemny.getDouble()); | ||||
| 				// 实际收款金额 nreceivedmny | ||||
| 				UFDouble nreceivedmny = hvo[0].getNreceivedmny(); | ||||
| 				HTXSDD.put("actRecvAmt", nreceivedmny.getDouble()); | ||||
| 				// 是否收到预收款 | ||||
| 				Object vdef14Code = dao.executeQuery("select code from bd_defdoc where pk_defdoc = '" + vdef14 + "'", new ColumnProcessor()); | ||||
| 				HTXSDD.put("isPreRecv", vdef14Code); | ||||
| 				// 是否收到发货款 | ||||
| 				Object vdef11Code = dao.executeQuery("select code from bd_defdoc where pk_defdoc = '" + vdef11 + "'", new ColumnProcessor()); | ||||
| 				HTXSDD.put("isShipRecdAmt", vdef11Code); | ||||
| 				p.put("HTXSDD", HTXSDD); | ||||
| 				System.out.println(p.toJSONString()); | ||||
| 				// 获取旗舰版的token | ||||
| 				Map<String, String> params = new HashMap<>(); | ||||
| 	 			String appKey = "a3c57e0d871240e9b9bf56b35001a324"; | ||||
| 	 			String appSecret = "a959f7786db8dbb9a2c0493b5855a46bea68ad75"; | ||||
| 	 			String tokenUrl="https://www.tkkfbip.com/iuap-api-auth/open-auth/selfAppAuth/getAccessToken"; | ||||
| 	 			String toBipUrl="https://www.tkkfbip.com/iuap-api-gateway/oxp4h3x6/current_yonbip_default_sys/KKAPI/contractSaleOrder/update?access_token="; | ||||
| 	 			// 除签名外的其他参数 | ||||
| 				params.put("appKey", appKey); | ||||
| 				String timestamp = String.valueOf(System.currentTimeMillis()); | ||||
| 				params.put("timestamp", timestamp); | ||||
| 				// 计算签名 | ||||
| 				Map<String, String> treeMap; | ||||
| 				if (params instanceof TreeMap) { | ||||
| 					treeMap = params; | ||||
| 				} else { | ||||
| 					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); | ||||
|     			if (StringUtils.equals("00000", result.get("code").toString())) { | ||||
|     				Map<String, Object> tokenInfo = (Map<String, Object>) result.get("data"); | ||||
|     				String access_token = (String) tokenInfo.get("access_token"); | ||||
|     				doPost(toBipUrl+ access_token, p); | ||||
|     			} | ||||
| 			} | ||||
| 		} catch (Exception e) { | ||||
| 			e.printStackTrace(); | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	private BaseAggVO[] getBills(IBusinessEvent event) { | ||||
| 		Object value = null; | ||||
| 		if (event instanceof BusinessEvent) { | ||||
| 			value = ((BusinessEvent)event).getObject(); | ||||
| 		} else if (event instanceof BdUpdateEvent) { | ||||
| 			value = ((BdUpdateEvent)event).getNewObject(); | ||||
| 		}      | ||||
| 		BaseAggVO[] bills = null; | ||||
| 		if (null != value) { | ||||
| 			if (value.getClass().isArray()) { | ||||
| 				Object[] objs = (Object[])value; | ||||
| 				bills = (objs instanceof BaseAggVO[]) ? (BaseAggVO[])objs : (BaseAggVO[])ArrayUtil.convertSupers2Subs((AggregatedValueObject[])objs, BaseAggVO.class); | ||||
| 			} else { | ||||
| 				bills = new BaseAggVO[1]; | ||||
| 				bills[0] = (BaseAggVO)value; | ||||
| 			}  | ||||
| 		} | ||||
| 		return bills; | ||||
| 	} | ||||
| 	 | ||||
| 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) { | ||||
| 				e.printStackTrace(); | ||||
| 			} | ||||
| 		 | ||||
| 		 | ||||
| 		 | ||||
| 		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) { | ||||
| 			e.printStackTrace(); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Loading…
	
		Reference in New Issue