发票接收回写BIP接口
This commit is contained in:
		
							parent
							
								
									842da0669f
								
							
						
					
					
						commit
						004ab7f574
					
				| 
						 | 
					@ -0,0 +1,6 @@
 | 
				
			||||||
 | 
					<?xml version="1.0" encoding='gb2312'?>
 | 
				
			||||||
 | 
					<module>
 | 
				
			||||||
 | 
						<rest>
 | 
				
			||||||
 | 
							<resource classname="nc.api.arap.resource.GatheringbillRestResource" exinfo="澗운데" />		
 | 
				
			||||||
 | 
						</rest>
 | 
				
			||||||
 | 
					</module>
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,314 @@
 | 
				
			||||||
 | 
					package nc.api.arap.resource;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.google.gson.Gson;
 | 
				
			||||||
 | 
					import java.lang.reflect.Type;
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.HashMap;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					import nc.api.arap.util.ArapAPIUtil;
 | 
				
			||||||
 | 
					import nc.bs.framework.common.NCLocator;
 | 
				
			||||||
 | 
					import nc.itf.arap.pub.IArapBillService;
 | 
				
			||||||
 | 
					import nc.vo.arap.basebill.BaseAggVO;
 | 
				
			||||||
 | 
					import nc.vo.arap.openapi.ArapBillOpenApiVO;
 | 
				
			||||||
 | 
					import nc.vo.arap.openapi.ArapF0EstiOpenApiVO;
 | 
				
			||||||
 | 
					import nc.vo.arap.openapi.ArapF1EstiOpenApiVO;
 | 
				
			||||||
 | 
					import nc.vo.arap.verify.ArapVerifyVO;
 | 
				
			||||||
 | 
					import nc.vo.ml.NCLangRes4VoTransl;
 | 
				
			||||||
 | 
					import nc.vo.pub.BusinessException;
 | 
				
			||||||
 | 
					import nc.vo.pub.lang.UFBoolean;
 | 
				
			||||||
 | 
					import nccloud.api.rest.utils.NCCRestUtils;
 | 
				
			||||||
 | 
					import nccloud.api.rest.utils.ResultMessageUtil;
 | 
				
			||||||
 | 
					import nccloud.impl.platform.common.util.StringUtils;
 | 
				
			||||||
 | 
					import nccloud.pubitf.arap.openapi.IARAPOpenAPIService;
 | 
				
			||||||
 | 
					import nccloud.pubitf.arap.openapi.IBillOpenService;
 | 
				
			||||||
 | 
					import nccloud.ws.rest.resource.AbstractNCCRestResource;
 | 
				
			||||||
 | 
					import org.apache.commons.collections4.CollectionUtils;
 | 
				
			||||||
 | 
					import org.apache.commons.lang3.ArrayUtils;
 | 
				
			||||||
 | 
					import org.json.JSONString;
 | 
				
			||||||
 | 
					import java.lang.reflect.Method;
 | 
				
			||||||
 | 
					import nc.bs.logging.Logger;
 | 
				
			||||||
 | 
					import nc.itf.arap.fieldmap.IBillFieldGet;
 | 
				
			||||||
 | 
					import nc.vo.pub.BusinessRuntimeException;
 | 
				
			||||||
 | 
					import nc.vo.pub.lang.UFDate;
 | 
				
			||||||
 | 
					import nc.vo.pub.lang.UFDouble;
 | 
				
			||||||
 | 
					import com.google.gson.internal.LinkedTreeMap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class ArapBaseRestResource extends AbstractNCCRestResource {
 | 
				
			||||||
 | 
						public String getModule() {
 | 
				
			||||||
 | 
							return "arap";
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						protected <T> T fromJson(String json, Type clazz) {
 | 
				
			||||||
 | 
							return (T) (new Gson()).fromJson(json, clazz);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public BaseAggVO fromJsonToAggVO(String json, String billtype) {
 | 
				
			||||||
 | 
							ArapBillOpenApiVO apivo = (ArapBillOpenApiVO) fromJson(json, ArapBillOpenApiVO.class);
 | 
				
			||||||
 | 
							return apivo.toAggVO(billtype);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public ArapF1EstiOpenApiVO fromJsonToAggVOForSP(String json, String billtype) {
 | 
				
			||||||
 | 
							return (ArapF1EstiOpenApiVO) fromJson(json, ArapF1EstiOpenApiVO.class);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public ArapF0EstiOpenApiVO fromJsonToF0AggVOForSP(String json, String billtype) {
 | 
				
			||||||
 | 
							return (ArapF0EstiOpenApiVO) fromJson(json, ArapF0EstiOpenApiVO.class);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public ArapVerifyVO fromJsonToArapVerifyVO(String json) {
 | 
				
			||||||
 | 
							return (ArapVerifyVO) fromJson(json, ArapVerifyVO.class);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public JSONString unCommitAndDelBill(JSONString str, String keyItem, String pk_billtype) throws BusinessException {
 | 
				
			||||||
 | 
							NCCRestUtils.initInvocationInfo();
 | 
				
			||||||
 | 
							String json = str.toJSONString();
 | 
				
			||||||
 | 
							Map<String, String> billMap = (Map) fromJson(json, Map.class);
 | 
				
			||||||
 | 
							String[] pk_bills = null;
 | 
				
			||||||
 | 
							IBillOpenService service = (IBillOpenService) NCLocator.getInstance()
 | 
				
			||||||
 | 
									.lookup(ArapAPIUtil.getClassName(pk_billtype));
 | 
				
			||||||
 | 
							if (StringUtils.isEmpty((String) billMap.get(keyItem))) {
 | 
				
			||||||
 | 
								try {
 | 
				
			||||||
 | 
									List<String> returnMap = service.getPkBySrc(billMap);
 | 
				
			||||||
 | 
									if (returnMap == null) {
 | 
				
			||||||
 | 
										return ResultMessageUtil.exceptionToJSON(
 | 
				
			||||||
 | 
												NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0970"), "filed");
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									pk_bills = (String[]) returnMap.toArray(new String[returnMap.size()]);
 | 
				
			||||||
 | 
								} catch (Exception e) {
 | 
				
			||||||
 | 
									return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								String pk_bill = (String) billMap.get(keyItem);
 | 
				
			||||||
 | 
								pk_bills = pk_bill.split(",");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								UFBoolean[] checkHasFlowBills = new UFBoolean[0];
 | 
				
			||||||
 | 
								IArapBillService sservice = (IArapBillService) NCLocator.getInstance().lookup(IArapBillService.class);
 | 
				
			||||||
 | 
								checkHasFlowBills = sservice.checkHasFlowBills(pk_bills, pk_billtype);
 | 
				
			||||||
 | 
								if (!ArrayUtils.isEmpty(checkHasFlowBills) && checkHasFlowBills[0].booleanValue()) {
 | 
				
			||||||
 | 
									String mess = NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-1680");
 | 
				
			||||||
 | 
									throw new BusinessException(mess);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Map<String, Object> returnMap = service.unCommitAndDelBill(pk_bills);
 | 
				
			||||||
 | 
								if (returnMap == null) {
 | 
				
			||||||
 | 
									return ResultMessageUtil.exceptionToJSON(
 | 
				
			||||||
 | 
											NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0970"), "filed");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return ResultMessageUtil.toJSON(returnMap);
 | 
				
			||||||
 | 
							} catch (Exception e) {
 | 
				
			||||||
 | 
								throw new BusinessException(e);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						protected JSONString queryBill(JSONString str, String pk_billtype) {
 | 
				
			||||||
 | 
							NCCRestUtils.initInvocationInfo();
 | 
				
			||||||
 | 
							String json = str.toJSONString();
 | 
				
			||||||
 | 
							Map<String, String> conditionMap = (Map) fromJson(json, Map.class);
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								IBillOpenService service = (IBillOpenService) NCLocator.getInstance()
 | 
				
			||||||
 | 
										.lookup(ArapAPIUtil.getClassName(pk_billtype));
 | 
				
			||||||
 | 
								List<Map<String, Object>> bills = service.queryBill(conditionMap);
 | 
				
			||||||
 | 
								if (CollectionUtils.isEmpty(bills)) {
 | 
				
			||||||
 | 
									bills = new ArrayList<Map<String, Object>>();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return ResultMessageUtil.toJSON(bills);
 | 
				
			||||||
 | 
							} catch (Exception e) {
 | 
				
			||||||
 | 
								return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						protected JSONString updateBill(JSONString str, String pk_billtype) {
 | 
				
			||||||
 | 
							NCCRestUtils.initInvocationInfo();
 | 
				
			||||||
 | 
							String json = str.toJSONString();
 | 
				
			||||||
 | 
							Map<String, Object> billMap = (Map) fromJson(json, Map.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								IBillOpenService service = (IBillOpenService) NCLocator.getInstance()
 | 
				
			||||||
 | 
										.lookup(ArapAPIUtil.getClassName(pk_billtype));
 | 
				
			||||||
 | 
								Map<String, String> returnMap = service.updateBill(billMap);
 | 
				
			||||||
 | 
								return ResultMessageUtil.toJSON(returnMap);
 | 
				
			||||||
 | 
							} catch (Exception e) {
 | 
				
			||||||
 | 
								return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public JSONString deleteBill(JSONString str, String keyItem, String pk_billtype) throws BusinessException {
 | 
				
			||||||
 | 
							NCCRestUtils.initInvocationInfo();
 | 
				
			||||||
 | 
							String json = str.toJSONString();
 | 
				
			||||||
 | 
							Map<String, String> billMap = (Map) fromJson(json, Map.class);
 | 
				
			||||||
 | 
							String[] pk_bills = null;
 | 
				
			||||||
 | 
							if (StringUtils.isEmpty((String) billMap.get(keyItem))) {
 | 
				
			||||||
 | 
								try {
 | 
				
			||||||
 | 
									IBillOpenService service = (IBillOpenService) NCLocator.getInstance()
 | 
				
			||||||
 | 
											.lookup(ArapAPIUtil.getClassName(pk_billtype));
 | 
				
			||||||
 | 
									List<String> returnMap = service.getPkBySrc(billMap);
 | 
				
			||||||
 | 
									if (returnMap == null) {
 | 
				
			||||||
 | 
										return ResultMessageUtil.exceptionToJSON(
 | 
				
			||||||
 | 
												NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0970"), "filed");
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									pk_bills = (String[]) returnMap.toArray(new String[returnMap.size()]);
 | 
				
			||||||
 | 
								} catch (Exception e) {
 | 
				
			||||||
 | 
									return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								String pk_recbill = (String) billMap.get(keyItem);
 | 
				
			||||||
 | 
								pk_bills = pk_recbill.split(",");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								IArapBillService service = (IArapBillService) NCLocator.getInstance().lookup(IArapBillService.class);
 | 
				
			||||||
 | 
								BaseAggVO[] bills = service.queryArapBillByPKs(pk_bills, pk_billtype);
 | 
				
			||||||
 | 
								if (ArrayUtils.isEmpty(bills)) {
 | 
				
			||||||
 | 
									return ResultMessageUtil.exceptionToJSON(
 | 
				
			||||||
 | 
											NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0970"), "filed");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								for (BaseAggVO aggVo : bills) {
 | 
				
			||||||
 | 
									aggVo.getParentVO().setAttributeValue("operate", "API");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								((IARAPOpenAPIService) NCLocator.getInstance().lookup(IARAPOpenAPIService.class)).executeBatchPM("DELETE",
 | 
				
			||||||
 | 
										bills);
 | 
				
			||||||
 | 
								Map<String, String> returnMap = new HashMap<String, String>();
 | 
				
			||||||
 | 
								returnMap.put("successful", "Y");
 | 
				
			||||||
 | 
								return ResultMessageUtil.toJSON(returnMap);
 | 
				
			||||||
 | 
							} catch (Exception e) {
 | 
				
			||||||
 | 
								return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						protected JSONString isclose(Map<String, String> conditionMap, String moduleID) {
 | 
				
			||||||
 | 
							if (conditionMap == null || conditionMap.size() == 0) {
 | 
				
			||||||
 | 
								return null;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							NCCRestUtils.initInvocationInfo();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								Map<String, String> res = ((IARAPOpenAPIService) NCLocator.getInstance().lookup(IARAPOpenAPIService.class))
 | 
				
			||||||
 | 
										.queryIscloseOrIsendaccStatus(conditionMap, moduleID);
 | 
				
			||||||
 | 
								return ResultMessageUtil.toJSON(res);
 | 
				
			||||||
 | 
							} catch (Exception e) {
 | 
				
			||||||
 | 
								return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						protected JSONString commitBill(JSONString str, String keyItem, String pk_billtype) throws BusinessException {
 | 
				
			||||||
 | 
							return commitUnCommitBill(str, keyItem, pk_billtype, "COMMIT");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						protected JSONString unCommitBill(JSONString str, String keyItem, String pk_billtype) throws BusinessException {
 | 
				
			||||||
 | 
							return commitUnCommitBill(str, keyItem, pk_billtype, "UNCOMMIT");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private JSONString commitUnCommitBill(JSONString str, String keyItem, String pk_billtype, String actioncode) {
 | 
				
			||||||
 | 
							NCCRestUtils.initInvocationInfo();
 | 
				
			||||||
 | 
							String json = str.toJSONString();
 | 
				
			||||||
 | 
							Map<String, String> billMap = (Map) fromJson(json, Map.class);
 | 
				
			||||||
 | 
							String[] pk_bills = null;
 | 
				
			||||||
 | 
							if (StringUtils.isEmpty((String) billMap.get(keyItem))) {
 | 
				
			||||||
 | 
								try {
 | 
				
			||||||
 | 
									List<String> returnMap = ((IBillOpenService) NCLocator.getInstance().lookup(IBillOpenService.class))
 | 
				
			||||||
 | 
											.getPkBySrc(billMap);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (returnMap == null) {
 | 
				
			||||||
 | 
										return ResultMessageUtil.exceptionToJSON(
 | 
				
			||||||
 | 
												NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0970"), "filed");
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									pk_bills = (String[]) returnMap.toArray(new String[returnMap.size()]);
 | 
				
			||||||
 | 
								} catch (Exception e) {
 | 
				
			||||||
 | 
									return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								String pk_bill = (String) billMap.get(keyItem);
 | 
				
			||||||
 | 
								pk_bills = pk_bill.split(",");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								Map<String, Object> returnMap = ((IARAPOpenAPIService) NCLocator.getInstance()
 | 
				
			||||||
 | 
										.lookup(IARAPOpenAPIService.class)).doBatchCommit(pk_bills, pk_billtype, actioncode);
 | 
				
			||||||
 | 
								if (Integer.parseInt(returnMap.get("failNum").toString()) == 0) {
 | 
				
			||||||
 | 
									return ResultMessageUtil.toJSON(returnMap.get("message"));
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if (Integer.parseInt(returnMap.get("successNum").toString()) == 0) {
 | 
				
			||||||
 | 
									return ResultMessageUtil.exceptionToJSON((String) returnMap.get("message"), "false");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return ResultMessageUtil.toJSON(returnMap.get("message"));
 | 
				
			||||||
 | 
							} catch (Exception e) {
 | 
				
			||||||
 | 
								return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * 转换Map为VO
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static Object fromJsonToVO(Map<?, ?> map, Type t) {
 | 
				
			||||||
 | 
							Object obj = null;
 | 
				
			||||||
 | 
							Class<?> clazz = (Class<?>) t;
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								obj = clazz.newInstance();
 | 
				
			||||||
 | 
								Method[] methods = clazz.getMethods();
 | 
				
			||||||
 | 
								if (methods != null) {
 | 
				
			||||||
 | 
									for (Method method : methods) {
 | 
				
			||||||
 | 
										if (method.getName().startsWith("set")) {// set方法
 | 
				
			||||||
 | 
											String key = (method.getName().replace("set", "")).toLowerCase();
 | 
				
			||||||
 | 
											Object value = map.get(key);
 | 
				
			||||||
 | 
											// 说明文档里。收款银行账户,付款银行账户字段拼接了ap或ar,导致此处可能获取不到值
 | 
				
			||||||
 | 
											if (value == null && (IBillFieldGet.PAYACCOUNT.equals(key)
 | 
				
			||||||
 | 
													|| IBillFieldGet.RECACCOUNT.equals(key) || IBillFieldGet.PK_PAYTERM.equals(key))) {
 | 
				
			||||||
 | 
												List<LinkedTreeMap<String, Object>> link = (List<LinkedTreeMap<String, Object>>) map
 | 
				
			||||||
 | 
														.get("items");
 | 
				
			||||||
 | 
												if (CollectionUtils.isEmpty(link)) {
 | 
				
			||||||
 | 
													String oldkey = key;
 | 
				
			||||||
 | 
													key = "ap_" + key;
 | 
				
			||||||
 | 
													if (map.get(key) == null) {
 | 
				
			||||||
 | 
														key = "ar_" + oldkey;
 | 
				
			||||||
 | 
													}
 | 
				
			||||||
 | 
													value = map.get(key);
 | 
				
			||||||
 | 
												} else {
 | 
				
			||||||
 | 
													LinkedTreeMap<String, Object> linkedMap = link.get(0);
 | 
				
			||||||
 | 
													String oldkey = key;
 | 
				
			||||||
 | 
													key = "ap_" + key;
 | 
				
			||||||
 | 
													if (linkedMap.get(key) == null) {
 | 
				
			||||||
 | 
														key = "ar_" + oldkey;
 | 
				
			||||||
 | 
													}
 | 
				
			||||||
 | 
													value = linkedMap.get(key);
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											if (value == null || StringUtils.isEmpty(value.toString()))
 | 
				
			||||||
 | 
												continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
											Class<?>[] parameterTypes = method.getParameterTypes();
 | 
				
			||||||
 | 
											if (IBillFieldGet.PREPAY.equals(key)) {
 | 
				
			||||||
 | 
												method.invoke(obj,
 | 
				
			||||||
 | 
														(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("2006pub_0", "02006pub-0997")
 | 
				
			||||||
 | 
																/* @res "预付款" */.equals(value)
 | 
				
			||||||
 | 
																|| nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
 | 
				
			||||||
 | 
																		.getStrByID("2006pub_0", "02006pub-0388")
 | 
				
			||||||
 | 
																		/* @res "预收款" */.equals(value)) ? 1 : 0);
 | 
				
			||||||
 | 
											} else if (parameterTypes[0] == UFBoolean.class) {
 | 
				
			||||||
 | 
												method.invoke(obj, UFBoolean.valueOf(value.toString()));
 | 
				
			||||||
 | 
											} else if (parameterTypes[0] == UFDouble.class) {
 | 
				
			||||||
 | 
												method.invoke(obj, new UFDouble(value.toString()));
 | 
				
			||||||
 | 
											} else if (parameterTypes[0] == Integer.class) {
 | 
				
			||||||
 | 
												method.invoke(obj, new Integer(value.toString()));
 | 
				
			||||||
 | 
											} else if (parameterTypes[0] == UFDate.class) {
 | 
				
			||||||
 | 
												method.invoke(obj, new UFDate(value.toString()));
 | 
				
			||||||
 | 
											} else {
 | 
				
			||||||
 | 
												method.invoke(obj, value);
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} catch (Exception e) {
 | 
				
			||||||
 | 
								Logger.error(e.getMessage(), e);
 | 
				
			||||||
 | 
								throw new BusinessRuntimeException(e.getMessage());
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return obj;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,757 @@
 | 
				
			||||||
 | 
					package nc.api.arap.resource;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					import javax.ws.rs.Consumes;
 | 
				
			||||||
 | 
					import javax.ws.rs.POST;
 | 
				
			||||||
 | 
					import javax.ws.rs.Path;
 | 
				
			||||||
 | 
					import javax.ws.rs.Produces;
 | 
				
			||||||
 | 
					import nc.bs.framework.common.NCLocator;
 | 
				
			||||||
 | 
					import nc.bs.trade.business.HYSuperDMO;
 | 
				
			||||||
 | 
					import nc.vo.arap.basebill.BaseAggVO;
 | 
				
			||||||
 | 
					import nc.vo.pub.BusinessException;
 | 
				
			||||||
 | 
					import nccloud.api.rest.utils.NCCRestUtils;
 | 
				
			||||||
 | 
					import nccloud.api.rest.utils.ResultMessageUtil;
 | 
				
			||||||
 | 
					import nccloud.pubitf.arap.openapi.IGatheringbillOpenService;
 | 
				
			||||||
 | 
					import org.json.JSONString;
 | 
				
			||||||
 | 
					import com.google.gson.Gson;
 | 
				
			||||||
 | 
					import java.io.BufferedReader;
 | 
				
			||||||
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					import java.io.InputStream;
 | 
				
			||||||
 | 
					import java.io.InputStreamReader;
 | 
				
			||||||
 | 
					import java.io.OutputStream;
 | 
				
			||||||
 | 
					import java.net.HttpURLConnection;
 | 
				
			||||||
 | 
					import java.net.MalformedURLException;
 | 
				
			||||||
 | 
					import java.net.URL;
 | 
				
			||||||
 | 
					import java.net.URLEncoder;
 | 
				
			||||||
 | 
					import java.nio.charset.Charset;
 | 
				
			||||||
 | 
					import java.nio.charset.StandardCharsets;
 | 
				
			||||||
 | 
					import java.security.InvalidKeyException;
 | 
				
			||||||
 | 
					import java.security.NoSuchAlgorithmException;
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.Base64;
 | 
				
			||||||
 | 
					import java.util.HashMap;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.TreeMap;
 | 
				
			||||||
 | 
					import java.util.zip.GZIPInputStream;
 | 
				
			||||||
 | 
					import javax.crypto.Mac;
 | 
				
			||||||
 | 
					import javax.crypto.spec.SecretKeySpec;
 | 
				
			||||||
 | 
					import nc.bs.dao.BaseDAO;
 | 
				
			||||||
 | 
					import nc.bs.dao.DAOException;
 | 
				
			||||||
 | 
					import nc.bs.framework.common.InvocationInfoProxy;
 | 
				
			||||||
 | 
					import nc.bs.trade.business.HYPubBO;
 | 
				
			||||||
 | 
					import nc.jdbc.framework.processor.ColumnProcessor;
 | 
				
			||||||
 | 
					import nc.jdbc.framework.processor.MapProcessor;
 | 
				
			||||||
 | 
					import nc.vo.arap.gathering.AggGatheringBillVO;
 | 
				
			||||||
 | 
					import nc.vo.arap.gathering.GatheringBillItemVO;
 | 
				
			||||||
 | 
					import nc.vo.arap.gathering.GatheringBillVO;
 | 
				
			||||||
 | 
					import nc.vo.bd.defdoc.DefdocVO;
 | 
				
			||||||
 | 
					import nc.vo.pub.CircularlyAccessibleValueObject;
 | 
				
			||||||
 | 
					import nc.vo.pub.lang.UFBoolean;
 | 
				
			||||||
 | 
					import nc.vo.pub.lang.UFDouble;
 | 
				
			||||||
 | 
					import nc.vo.pubapp.pattern.pub.MathTool;
 | 
				
			||||||
 | 
					import nc.vo.so.m30.entity.SaleOrderBVO;
 | 
				
			||||||
 | 
					import nc.vo.so.m30.entity.SaleOrderHVO;
 | 
				
			||||||
 | 
					import nccloud.commons.lang.StringUtils;
 | 
				
			||||||
 | 
					import com.alibaba.fastjson.JSON;
 | 
				
			||||||
 | 
					import com.alibaba.fastjson.JSONObject;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Path("arap/gatheringbill")
 | 
				
			||||||
 | 
					public class GatheringbillRestResource extends ArapBaseRestResource {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						HYSuperDMO dmo = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public HYSuperDMO getSuperDMO() {
 | 
				
			||||||
 | 
							if (dmo == null) {
 | 
				
			||||||
 | 
								dmo = new HYSuperDMO();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return dmo;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * 该收款单保存为BIP专业保存方法。请谨慎修改;
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param str
 | 
				
			||||||
 | 
						 * @return
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@POST
 | 
				
			||||||
 | 
						@Path("/bipinsert")
 | 
				
			||||||
 | 
						@Consumes({ "application/json" })
 | 
				
			||||||
 | 
						@Produces({ "application/json" })
 | 
				
			||||||
 | 
						public JSONString bipInsertPaybill(JSONString str) {
 | 
				
			||||||
 | 
							InvocationInfoProxy.getInstance().setGroupId("0001A110000000000677");
 | 
				
			||||||
 | 
							NCCRestUtils.initInvocationInfo();
 | 
				
			||||||
 | 
							String json = str.toJSONString();
 | 
				
			||||||
 | 
							Map<String, Object> billMap = (Map) fromJson(json, Map.class);
 | 
				
			||||||
 | 
							billMap.put("recaccount", billMap.get("ar_recaccount"));
 | 
				
			||||||
 | 
							GatheringBillVO headvo = (GatheringBillVO) fromJsonToVO(billMap, GatheringBillVO.class);
 | 
				
			||||||
 | 
							headvo.setDef28(headvo.getBilldate().toStdString());// 交易日期
 | 
				
			||||||
 | 
							// 汇率为空时,默认为1
 | 
				
			||||||
 | 
							if (headvo.getRate() == null) {
 | 
				
			||||||
 | 
								headvo.setRate(UFDouble.ONE_DBL);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							// 结算方式名称
 | 
				
			||||||
 | 
							Object balatypeName = "";
 | 
				
			||||||
 | 
							// 金额
 | 
				
			||||||
 | 
							UFDouble money = new UFDouble(0);
 | 
				
			||||||
 | 
							// 税率
 | 
				
			||||||
 | 
							UFDouble ntaxrate = new UFDouble(0);
 | 
				
			||||||
 | 
							// 税码
 | 
				
			||||||
 | 
							String ctaxcode = "";
 | 
				
			||||||
 | 
							BaseDAO dao = new BaseDAO();
 | 
				
			||||||
 | 
							// 销售订单号
 | 
				
			||||||
 | 
							String csaleorderid = "";
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								HYPubBO hybo = new HYPubBO();
 | 
				
			||||||
 | 
								headvo.setIsinit(new UFBoolean(false));
 | 
				
			||||||
 | 
								// 默认 收款类型 默认合同收款单
 | 
				
			||||||
 | 
								Object pk_billtypecode = hybo.findColValue("bd_billtype", "PK_BILLTYPECODE", "billtypename = '合同收款单' ");
 | 
				
			||||||
 | 
								headvo.setPk_tradetype(pk_billtypecode.toString());
 | 
				
			||||||
 | 
								// 业务流程 默认【收款结算】
 | 
				
			||||||
 | 
								Object pk_busitype = hybo.findColValue("bd_busitype", "busicode", "businame = '收款结算' ");
 | 
				
			||||||
 | 
								headvo.setPk_busitype(pk_busitype.toString());
 | 
				
			||||||
 | 
								// 往来对象0-客户 2-部门 3-业务员 默认客户
 | 
				
			||||||
 | 
								headvo.setObjtype(0);
 | 
				
			||||||
 | 
								// 销售订单号
 | 
				
			||||||
 | 
								csaleorderid = headvo.getDef3();
 | 
				
			||||||
 | 
								// 客户
 | 
				
			||||||
 | 
								Object customerid = hybo.findColValue("so_saleorder", "ccustomerid",
 | 
				
			||||||
 | 
										"csaleorderid = '" + csaleorderid + "' ");
 | 
				
			||||||
 | 
								Object customerCode = hybo.findColValue("bd_customer", "code", "pk_customer = '" + customerid + "' ");
 | 
				
			||||||
 | 
								headvo.setCustomer(customerCode.toString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Object tr = dao.executeQuery(
 | 
				
			||||||
 | 
										"select ntaxrate from  so_saleorder_b where csaleorderid = '" + csaleorderid + "'",
 | 
				
			||||||
 | 
										new ColumnProcessor());
 | 
				
			||||||
 | 
								ntaxrate = new UFDouble(tr.toString());
 | 
				
			||||||
 | 
								// 税码
 | 
				
			||||||
 | 
								Object ctaxcodeid = hybo.findColValue("so_saleorder_b", "ctaxcodeid",
 | 
				
			||||||
 | 
										"csaleorderid = '" + csaleorderid + "' ");
 | 
				
			||||||
 | 
								Object tc = hybo.findColValue("bd_taxcode", "code", "pk_taxcode = '" + ctaxcodeid + "' ");
 | 
				
			||||||
 | 
								ctaxcode = tc.toString();
 | 
				
			||||||
 | 
								// 业务员
 | 
				
			||||||
 | 
								Object cemployeeid = hybo.findColValue("so_saleorder", "cemployeeid",
 | 
				
			||||||
 | 
										"csaleorderid = '" + csaleorderid + "' ");
 | 
				
			||||||
 | 
								if (cemployeeid != null) {// 能够获取到值,但是该值可能在销售订单生成的时候,没有翻译,依然存的是人员编码,如果存的是人员编码,则说明该人员在erp系统中不存在
 | 
				
			||||||
 | 
									Object cemployeeCode = hybo.findColValue("bd_psndoc", "code", "pk_psndoc = '" + cemployeeid + "' ");
 | 
				
			||||||
 | 
									if (cemployeeCode != null) {
 | 
				
			||||||
 | 
										headvo.setPk_psndoc(cemployeeCode.toString());
 | 
				
			||||||
 | 
										// 部门
 | 
				
			||||||
 | 
										Object deptCode = hybo.findColValue("org_orgs", "code",
 | 
				
			||||||
 | 
												" pk_org in( select pk_dept from bd_psnjob where pk_psndoc = '" + cemployeeid + "')");
 | 
				
			||||||
 | 
										if (deptCode != null) {
 | 
				
			||||||
 | 
											headvo.setPk_deptid(deptCode.toString());
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								// pk_currtype 币种编码 默认人民币
 | 
				
			||||||
 | 
								headvo.setPk_currtype("CNY");
 | 
				
			||||||
 | 
								// accessorynum 附件张数 默认2
 | 
				
			||||||
 | 
								headvo.setAccessorynum(2);
 | 
				
			||||||
 | 
								// 制单人 默认BIP
 | 
				
			||||||
 | 
								headvo.setBillmaker("BIP");
 | 
				
			||||||
 | 
								// 结算方式名称
 | 
				
			||||||
 | 
								String balatypeCode = headvo.getPk_balatype();
 | 
				
			||||||
 | 
								if (!StringUtils.isEmpty(balatypeCode)) {
 | 
				
			||||||
 | 
									Object pk_balatype = hybo.findColValue("bd_balatype", "pk_balatype", " code = '" + balatypeCode + "' ");
 | 
				
			||||||
 | 
					//			          headvo.setPk_balatype(pk_balatype.toString());
 | 
				
			||||||
 | 
									if (pk_balatype != null) {
 | 
				
			||||||
 | 
										balatypeName = hybo.findColValue("bd_balatype", "name", " code = '" + balatypeCode + "' ");
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// 银行收款账号
 | 
				
			||||||
 | 
								// 原币金额
 | 
				
			||||||
 | 
								// 单据状态
 | 
				
			||||||
 | 
								headvo.setBillstatus(-1);
 | 
				
			||||||
 | 
								// 单据来源系统编码
 | 
				
			||||||
 | 
								headvo.setSrc_syscode(17);
 | 
				
			||||||
 | 
								// 合同金额
 | 
				
			||||||
 | 
								// 结算组织
 | 
				
			||||||
 | 
								headvo.setSett_org(headvo.getPk_org());
 | 
				
			||||||
 | 
							} catch (Exception e) {
 | 
				
			||||||
 | 
								return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							List<Map<String, Object>> itemMaps = (List) billMap.get("items");
 | 
				
			||||||
 | 
							List<GatheringBillItemVO> itemvos = new ArrayList<GatheringBillItemVO>();
 | 
				
			||||||
 | 
							if (itemMaps != null && itemMaps.size() > 0) {
 | 
				
			||||||
 | 
								for (Map<String, Object> item : itemMaps) {
 | 
				
			||||||
 | 
									GatheringBillItemVO itemvo = (GatheringBillItemVO) fromJsonToVO(item, GatheringBillItemVO.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									try {
 | 
				
			||||||
 | 
										HYPubBO hybo = new HYPubBO();
 | 
				
			||||||
 | 
										itemvo.setRecaccount(headvo.getRecaccount());
 | 
				
			||||||
 | 
										// pk_balatype 结算方式 表头带出
 | 
				
			||||||
 | 
										itemvo.setPk_balatype(headvo.getPk_balatype());
 | 
				
			||||||
 | 
										// 票据类型 checktype 结算方式:银行承兑汇票-电子、银行承兑汇票-纸质=银行承兑汇票;商业承兑汇票-电子、商业承兑汇票-纸质=商业承兑汇票
 | 
				
			||||||
 | 
										String checktypeName = "";
 | 
				
			||||||
 | 
										if ("银行承兑汇票-电子".equals(balatypeName)) {
 | 
				
			||||||
 | 
											checktypeName = "电子银行承兑汇票";
 | 
				
			||||||
 | 
										} else if ("商业承兑汇票-电子".equals(balatypeName)) {
 | 
				
			||||||
 | 
											checktypeName = "电子商业承兑汇票";
 | 
				
			||||||
 | 
										} else if ("商业承兑汇票-纸质".equals(balatypeName)) {
 | 
				
			||||||
 | 
											checktypeName = "商业承兑汇票";
 | 
				
			||||||
 | 
										} else if ("银行承兑汇票-纸质".equals(balatypeName)) {
 | 
				
			||||||
 | 
											checktypeName = "银行承兑汇票";
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										if (checktypeName != "") {
 | 
				
			||||||
 | 
											Object checktypeCode = hybo.findColValue("bd_notetype", "code",
 | 
				
			||||||
 | 
													" name = '" + checktypeName + "' ");
 | 
				
			||||||
 | 
											itemvo.setChecktype(checktypeCode.toString());
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										// objtype 往来对象0-客户 2-部门 3-业务员 表头带出
 | 
				
			||||||
 | 
										itemvo.setObjtype(headvo.getObjtype());
 | 
				
			||||||
 | 
										// supplier 客户编码 表头带出
 | 
				
			||||||
 | 
										itemvo.setCustomer(headvo.getCustomer());
 | 
				
			||||||
 | 
										// pk_dept 部门编码 表头带出
 | 
				
			||||||
 | 
										itemvo.setPk_deptid(headvo.getPk_deptid());
 | 
				
			||||||
 | 
										// pk_psndoc 业务员编码 表头带出
 | 
				
			||||||
 | 
										itemvo.setPk_psndoc(headvo.getPk_psndoc());
 | 
				
			||||||
 | 
										// pk_currtype 币种编码 表头带出
 | 
				
			||||||
 | 
										itemvo.setPk_currtype(headvo.getPk_currtype());
 | 
				
			||||||
 | 
										// prepay 收款性质 默认应收款 0
 | 
				
			||||||
 | 
										itemvo.setPrepay(0);
 | 
				
			||||||
 | 
										//
 | 
				
			||||||
 | 
										UFDouble money_cr = itemvo.getMoney_cr();
 | 
				
			||||||
 | 
										UFDouble local_tax_cr = money_cr.multiply(ntaxrate).div(100);
 | 
				
			||||||
 | 
										itemvo.setLocal_tax_cr(local_tax_cr);
 | 
				
			||||||
 | 
										//
 | 
				
			||||||
 | 
										UFDouble notax_cr = money_cr.sub(local_tax_cr);
 | 
				
			||||||
 | 
										itemvo.setNotax_cr(notax_cr);
 | 
				
			||||||
 | 
										//
 | 
				
			||||||
 | 
										itemvo.setRate(UFDouble.ZERO_DBL);
 | 
				
			||||||
 | 
										//
 | 
				
			||||||
 | 
										itemvo.setTaxcodeid(ctaxcode);
 | 
				
			||||||
 | 
										//
 | 
				
			||||||
 | 
										itemvo.setTaxrate(ntaxrate);
 | 
				
			||||||
 | 
										// 收支项目
 | 
				
			||||||
 | 
										itemvo.setPk_subjcode("201");
 | 
				
			||||||
 | 
										money = money.add(itemvo.getMoney_cr());
 | 
				
			||||||
 | 
										itemvo.setLocal_money_cr(itemvo.getMoney_cr());
 | 
				
			||||||
 | 
										Object def2 = itemvo.getDef2();
 | 
				
			||||||
 | 
										if (def2 != null)
 | 
				
			||||||
 | 
											itemvo.setDef2(hybo.findColValue("bd_defdoc", "pk_defdoc", " code = '" + def2 + "' ") + "");
 | 
				
			||||||
 | 
										Object def3 = itemvo.getDef3();
 | 
				
			||||||
 | 
										if (def3 != null)
 | 
				
			||||||
 | 
											itemvo.setDef3(hybo.findColValue("bd_defdoc", "pk_defdoc", " code = '" + def3 + "' ") + "");
 | 
				
			||||||
 | 
										Object def6 = itemvo.getDef6();
 | 
				
			||||||
 | 
										if (def6 != null)
 | 
				
			||||||
 | 
											itemvo.setDef6(hybo.findColValue("bd_defdoc", "pk_defdoc", " code = '" + def6 + "' ") + "");
 | 
				
			||||||
 | 
										Object def36 = itemvo.getDef36();
 | 
				
			||||||
 | 
										if (def36 != null)
 | 
				
			||||||
 | 
											itemvo.setDef36(hybo.findColValue("bd_defdoc", "pk_defdoc", " code = '" + def36 + "' ") + "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										HYSuperDMO dmo = new HYSuperDMO();
 | 
				
			||||||
 | 
										SaleOrderHVO[] hvo = (SaleOrderHVO[]) dmo.queryByWhereClause(SaleOrderHVO.class,
 | 
				
			||||||
 | 
												"vbillcode='" + def2 + "'");
 | 
				
			||||||
 | 
										SaleOrderBVO[] bvos = (SaleOrderBVO[]) dmo.queryByWhereClause(SaleOrderBVO.class,
 | 
				
			||||||
 | 
												"csaleorderid='" + hvo[0].getPrimaryKey() + "'");
 | 
				
			||||||
 | 
										if (bvos != null) {
 | 
				
			||||||
 | 
											itemvo.setSrc_billid(bvos[0].getCsaleorderid());
 | 
				
			||||||
 | 
											itemvo.setSrc_itemid(bvos[0].getCsaleorderbid());
 | 
				
			||||||
 | 
											itemvo.setSrc_billtype("30");
 | 
				
			||||||
 | 
											itemvo.setSrc_tradetype(hvo[0].getVtrantypecode());
 | 
				
			||||||
 | 
											itemvo.setTop_billid(bvos[0].getCsaleorderid());
 | 
				
			||||||
 | 
											itemvo.setTop_itemid(bvos[0].getCsaleorderbid());
 | 
				
			||||||
 | 
											itemvo.setTop_billtype("30");
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									} catch (Exception e) {
 | 
				
			||||||
 | 
										return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									itemvos.add(itemvo);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							headvo.setMoney(money);
 | 
				
			||||||
 | 
							headvo.setGloballocal(money);
 | 
				
			||||||
 | 
							headvo.setRate(new UFDouble(1));
 | 
				
			||||||
 | 
							headvo.setLocal_money(money);
 | 
				
			||||||
 | 
							AggGatheringBillVO bill = new AggGatheringBillVO();
 | 
				
			||||||
 | 
							bill.setParentVO(headvo);
 | 
				
			||||||
 | 
							bill.setChildrenVO((CircularlyAccessibleValueObject[]) itemvos.toArray(new GatheringBillItemVO[0]));
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								Map<String, String> returnMap = ((IGatheringbillOpenService) NCLocator.getInstance()
 | 
				
			||||||
 | 
										.lookup(IGatheringbillOpenService.class)).saveBill(bill);
 | 
				
			||||||
 | 
								JSONString resultJson = ResultMessageUtil.toJSON(returnMap);
 | 
				
			||||||
 | 
								// 保存后动作
 | 
				
			||||||
 | 
								JSONObject js_result = JSON.parseObject(resultJson.toJSONString());
 | 
				
			||||||
 | 
								if (js_result.containsKey("success")) {
 | 
				
			||||||
 | 
									if (js_result.getString("success").equals("true")) {
 | 
				
			||||||
 | 
										if (js_result.containsKey("data")) {
 | 
				
			||||||
 | 
											JSONObject js_data = js_result.getJSONObject("data");
 | 
				
			||||||
 | 
											String pk_gatherid = js_data.getString("pk_bill");
 | 
				
			||||||
 | 
											String pk_org = js_data.getString("pk_org");
 | 
				
			||||||
 | 
											GatheringBillItemVO[] billItemVOs = (GatheringBillItemVO[]) bill.getChildrenVO();
 | 
				
			||||||
 | 
											for (GatheringBillItemVO gatheringBillItemVO : billItemVOs) {
 | 
				
			||||||
 | 
												afterChangeMny(gatheringBillItemVO.getSrc_billid(), pk_org, billItemVOs[0].getDef6(),
 | 
				
			||||||
 | 
														pk_gatherid);
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return resultJson;
 | 
				
			||||||
 | 
							} catch (BusinessException e) {
 | 
				
			||||||
 | 
								return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 实际收款金额 01无约定预付款 02有约定已收到预付款 03有约定未收到款
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param csaleorderid 销售订单id
 | 
				
			||||||
 | 
						 * @param pk_org       组织
 | 
				
			||||||
 | 
						 * @param ctid         合同id
 | 
				
			||||||
 | 
						 * @param pk_gatherid  收款单id
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						private void afterChangeMny(String csaleorderid, String pk_org, String ctid, String pk_gatherid) {
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								// 合同id
 | 
				
			||||||
 | 
								if (StringUtils.isEmpty(ctid)) {
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								// 获取销售订单表头
 | 
				
			||||||
 | 
								SaleOrderHVO hvo = (SaleOrderHVO) getSuperDMO().queryByPrimaryKey(SaleOrderHVO.class, csaleorderid);
 | 
				
			||||||
 | 
								if (hvo == null) {
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								String vdef9 = hvo.getVdef9();// BIP 合同销售订单id
 | 
				
			||||||
 | 
								if (StringUtils.isEmpty(vdef9)) {// 为空,不是从bip 生成的
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								// 合同金额vdef17
 | 
				
			||||||
 | 
								UFDouble ctmny = new UFDouble(hvo.getVdef17() == null ? "0" : hvo.getVdef17());
 | 
				
			||||||
 | 
								// 预收比例vdef15
 | 
				
			||||||
 | 
								UFDouble yfrate = new UFDouble(hvo.getVdef15() == null ? "0" : hvo.getVdef15());
 | 
				
			||||||
 | 
								UFDouble temp_yf_mny = ctmny.multiply(yfrate);
 | 
				
			||||||
 | 
								// 发货比例vdef16
 | 
				
			||||||
 | 
								UFDouble fhrate = new UFDouble(hvo.getVdef16() == null ? "0" : hvo.getVdef16());
 | 
				
			||||||
 | 
								UFDouble temp_fh_mny = ctmny.multiply(fhrate);
 | 
				
			||||||
 | 
								// vdef14 预付款标识
 | 
				
			||||||
 | 
								String vdef14 = "01";// 01无约定预付款
 | 
				
			||||||
 | 
								// vdef11 发货款标识
 | 
				
			||||||
 | 
								String vdef11 = "fhk03";// fhk03无约定发货款
 | 
				
			||||||
 | 
								UFDouble total_mny = UFDouble.ZERO_DBL;// 当前组织下本合同所有收款单金额累计
 | 
				
			||||||
 | 
								String sum_sql = "select sum(money_cr) as money_cr from ar_gatheritem where def6 not in ('~') and dr=0   and def6='"
 | 
				
			||||||
 | 
										+ ctid + "'";
 | 
				
			||||||
 | 
								Map map = (Map) new BaseDAO().executeQuery(sum_sql, new MapProcessor());
 | 
				
			||||||
 | 
								if (map != null) {
 | 
				
			||||||
 | 
									total_mny = new UFDouble(String.valueOf(map.get("money_cr")));
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if ((MathTool.compareTo(yfrate, UFDouble.ZERO_DBL) == 0)) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									if (MathTool.compareTo(total_mny, temp_yf_mny) >= 0) {// 累计收款金额≥合同金额*预收比例
 | 
				
			||||||
 | 
										vdef14 = "02"; // 02有约定已收到预付款
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										vdef14 = "03";// 03 有约定未收到款
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if ((MathTool.compareTo(fhrate, UFDouble.ZERO_DBL) == 0)) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									if (MathTool.compareTo(total_mny, temp_fh_mny) >= 0) {// 累计收款金额≥合同金额*发货比例
 | 
				
			||||||
 | 
										vdef11 = "fhk01";// fhk01有约定已收到发货款
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										vdef11 = "fhk02";// fhk02有约定未收到发货款
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								DefdocVO[] defdocVOs = (DefdocVO[]) getSuperDMO().queryByWhereClause(DefdocVO.class,
 | 
				
			||||||
 | 
										" pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='xsdd' ) and code='" + vdef14
 | 
				
			||||||
 | 
												+ "' and dr=0 ");
 | 
				
			||||||
 | 
								if (defdocVOs != null && defdocVOs.length > 0) {
 | 
				
			||||||
 | 
									hvo.setVdef14(defdocVOs[0].getPrimaryKey());
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								defdocVOs = (DefdocVO[]) getSuperDMO().queryByWhereClause(DefdocVO.class,
 | 
				
			||||||
 | 
										" pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='FHK' ) and code='" + vdef11
 | 
				
			||||||
 | 
												+ "' and dr=0 ");
 | 
				
			||||||
 | 
								if (defdocVOs != null && defdocVOs.length > 0) {
 | 
				
			||||||
 | 
									hvo.setVdef11(defdocVOs[0].getPrimaryKey());
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								pushBipCtOrderUpdate(hvo, vdef14, vdef11);
 | 
				
			||||||
 | 
							} catch (DAOException e) {
 | 
				
			||||||
 | 
								e.printStackTrace();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * BIP 合同销售订单更新
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param hvo
 | 
				
			||||||
 | 
						 * @param vdef14 预付款标识
 | 
				
			||||||
 | 
						 * @param vdef11 发货款标识
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						private void pushBipCtOrderUpdate(SaleOrderHVO hvo, String vdef14, String vdef11) {
 | 
				
			||||||
 | 
							String baseUrl = "";
 | 
				
			||||||
 | 
							Map<String, String> bipParamMap = checkBipParam();
 | 
				
			||||||
 | 
							if (bipParamMap.isEmpty()) {
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							baseUrl = bipParamMap.get("baseUrl");
 | 
				
			||||||
 | 
							String contractSaleOrderUrl = bipParamMap.get("contractSaleOrder");// 开票申请单回传
 | 
				
			||||||
 | 
							if (StringUtils.isEmpty(contractSaleOrderUrl)) {
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							Gson gson = new Gson();
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								String accessToken = getAccessToken(baseUrl, bipParamMap);
 | 
				
			||||||
 | 
								if (accessToken != "") {
 | 
				
			||||||
 | 
									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 + contractSaleOrderUrl;
 | 
				
			||||||
 | 
									JSONObject js_apct_detail = new JSONObject();
 | 
				
			||||||
 | 
									JSONObject js_apct = new JSONObject();
 | 
				
			||||||
 | 
									js_apct.put("id", hvo.getVdef9());
 | 
				
			||||||
 | 
									js_apct.put("isShipRecdAmt", vdef11);
 | 
				
			||||||
 | 
									js_apct.put("isPreRecv", vdef14);
 | 
				
			||||||
 | 
									js_apct.put("actRecvAmt", hvo.getNreceivedmny().floatValue());
 | 
				
			||||||
 | 
									js_apct.put("actPreRecvAmt", hvo.getNpreceivemny().floatValue());
 | 
				
			||||||
 | 
									js_apct_detail.put("HTXSDD", js_apct);
 | 
				
			||||||
 | 
									String resultString = doSendHttp(custUpdateUrl, "POST", tokenParam, "", headers,
 | 
				
			||||||
 | 
											js_apct_detail.toJSONString());
 | 
				
			||||||
 | 
									Map updateMap = gson.fromJson(resultString, Map.class);
 | 
				
			||||||
 | 
									if (StringUtils.equals("200", updateMap.get("code").toString())) {// 保存更新成功后需要更新日志表
 | 
				
			||||||
 | 
										getSuperDMO().update(hvo);
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} catch (InvalidKeyException e) {
 | 
				
			||||||
 | 
								e.printStackTrace();
 | 
				
			||||||
 | 
							} catch (NoSuchAlgorithmException e) {
 | 
				
			||||||
 | 
								e.printStackTrace();
 | 
				
			||||||
 | 
							} catch (IOException e) {
 | 
				
			||||||
 | 
								e.printStackTrace();
 | 
				
			||||||
 | 
							} catch (DAOException e) {
 | 
				
			||||||
 | 
								e.printStackTrace();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * 检查bip参数是否完整
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @return
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						private Map<String, String> checkBipParam() {
 | 
				
			||||||
 | 
							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";
 | 
				
			||||||
 | 
							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 static String doGet(String path, Map<String, String> params) throws IOException {
 | 
				
			||||||
 | 
							HttpURLConnection conn = null;
 | 
				
			||||||
 | 
							InputStream is = null;
 | 
				
			||||||
 | 
							BufferedReader br = null;
 | 
				
			||||||
 | 
							StringBuilder result = new StringBuilder();
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								if (params != null) {
 | 
				
			||||||
 | 
									String paramStr = "";
 | 
				
			||||||
 | 
									for (String key : params.keySet()) {
 | 
				
			||||||
 | 
										if (!paramStr.isEmpty()) {
 | 
				
			||||||
 | 
											paramStr += '&';
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										paramStr += key + '=' + params.get(key);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (path.indexOf('?') > 0) {
 | 
				
			||||||
 | 
										path += '&' + paramStr;
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										path += '?' + paramStr;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								// 创建远程url连接对象
 | 
				
			||||||
 | 
								URL url = new URL(path);
 | 
				
			||||||
 | 
								if ("https".equalsIgnoreCase(url.getProtocol())) {// 判定网址是否信任,不信任则调用忽略信任工具类SslUtil
 | 
				
			||||||
 | 
									IgnoreSslUtil.ignoreSsl();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								// 通过远程url连接对象打开一个连接,强转成HTTPURLConnection类
 | 
				
			||||||
 | 
								conn = (HttpURLConnection) url.openConnection();
 | 
				
			||||||
 | 
								conn.setRequestMethod("GET");
 | 
				
			||||||
 | 
								// 设置连接超时时间和读取超时时间
 | 
				
			||||||
 | 
								conn.setConnectTimeout(120000);
 | 
				
			||||||
 | 
								conn.setReadTimeout(120000);
 | 
				
			||||||
 | 
								conn.setRequestProperty("Accept", "application/json");
 | 
				
			||||||
 | 
								// 发送请求
 | 
				
			||||||
 | 
								conn.connect();
 | 
				
			||||||
 | 
								// 通过conn取得输入流,并使用Reader读取
 | 
				
			||||||
 | 
								if (200 == conn.getResponseCode()) {
 | 
				
			||||||
 | 
									is = conn.getInputStream();
 | 
				
			||||||
 | 
									br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
 | 
				
			||||||
 | 
									String line;
 | 
				
			||||||
 | 
									while ((line = br.readLine()) != null) {
 | 
				
			||||||
 | 
										result.append(line);
 | 
				
			||||||
 | 
										System.out.println(line);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									System.out.println("ResponseCode is an error code:" + conn.getResponseCode());
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} catch (MalformedURLException e) {
 | 
				
			||||||
 | 
								e.printStackTrace();
 | 
				
			||||||
 | 
							} catch (IOException e) {
 | 
				
			||||||
 | 
								e.printStackTrace();
 | 
				
			||||||
 | 
							} catch (Exception e) {
 | 
				
			||||||
 | 
								e.printStackTrace();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return result.toString();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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 = "";
 | 
				
			||||||
 | 
							Map<String, String> params = new HashMap<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							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");
 | 
				
			||||||
 | 
								accessToken = (String) tokenInfo.get("access_token");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return accessToken;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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;
 | 
				
			||||||
 | 
							BufferedReader bufferedReader = null;
 | 
				
			||||||
 | 
							String result = null;
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								StringBuffer sb = new StringBuffer();
 | 
				
			||||||
 | 
								sb.append(baseUrl);
 | 
				
			||||||
 | 
								if (paramMap != null) {
 | 
				
			||||||
 | 
									sb.append("?");
 | 
				
			||||||
 | 
									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);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								URL urlobj = new URL(baseUrl);
 | 
				
			||||||
 | 
								if ("https".equalsIgnoreCase(urlobj.getProtocol())) {// 判定网址是否信任,不信任则调用忽略信任工具类SslUtil
 | 
				
			||||||
 | 
									IgnoreSslUtil.ignoreSsl();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								urlConnection = (HttpURLConnection) urlobj.openConnection();
 | 
				
			||||||
 | 
								urlConnection.setConnectTimeout(50000);
 | 
				
			||||||
 | 
								urlConnection.setRequestMethod(method);
 | 
				
			||||||
 | 
								urlConnection.setDoInput(true);
 | 
				
			||||||
 | 
								urlConnection.setUseCaches(false);
 | 
				
			||||||
 | 
								// 如果设置了自定义头,则打印它们
 | 
				
			||||||
 | 
								if (headers != null && !headers.isEmpty()) {
 | 
				
			||||||
 | 
									for (Map.Entry<String, String> entry : headers.entrySet()) {
 | 
				
			||||||
 | 
										urlConnection.addRequestProperty(entry.getKey(), entry.getValue());
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if (json != null && json.length() > 0) {
 | 
				
			||||||
 | 
									urlConnection.setDoInput(true);
 | 
				
			||||||
 | 
									urlConnection.setDoOutput(true);
 | 
				
			||||||
 | 
									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();
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									in = urlConnection.getErrorStream();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								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();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								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();
 | 
				
			||||||
 | 
								e.printStackTrace();
 | 
				
			||||||
 | 
							} finally {
 | 
				
			||||||
 | 
								if (null != bufferedReader) {
 | 
				
			||||||
 | 
									try {
 | 
				
			||||||
 | 
										bufferedReader.close();
 | 
				
			||||||
 | 
									} catch (IOException e) {
 | 
				
			||||||
 | 
										e.printStackTrace();
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if (null != out) {
 | 
				
			||||||
 | 
									try {
 | 
				
			||||||
 | 
										out.close();
 | 
				
			||||||
 | 
									} catch (IOException e) {
 | 
				
			||||||
 | 
										e.printStackTrace();
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if (null != in) {
 | 
				
			||||||
 | 
									try {
 | 
				
			||||||
 | 
										in.close();
 | 
				
			||||||
 | 
									} catch (IOException e) {
 | 
				
			||||||
 | 
										e.printStackTrace();
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								urlConnection.disconnect();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return result;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@POST
 | 
				
			||||||
 | 
						@Path("/insert")
 | 
				
			||||||
 | 
						@Consumes({ "application/json" })
 | 
				
			||||||
 | 
						@Produces({ "application/json" })
 | 
				
			||||||
 | 
						public JSONString insertBill(JSONString str) {
 | 
				
			||||||
 | 
							return insertBill(str, false);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@POST
 | 
				
			||||||
 | 
						@Path("/insertandcommit")
 | 
				
			||||||
 | 
						@Consumes({ "application/json" })
 | 
				
			||||||
 | 
						@Produces({ "application/json" })
 | 
				
			||||||
 | 
						public JSONString insertAndCommitBill(JSONString str) {
 | 
				
			||||||
 | 
							return insertBill(str, true);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private JSONString insertBill(JSONString str, boolean isInsertAndCommit) {
 | 
				
			||||||
 | 
							NCCRestUtils.initInvocationInfo();
 | 
				
			||||||
 | 
							String json = str.toJSONString();
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								BaseAggVO bill = fromJsonToAggVO(json, "F2");
 | 
				
			||||||
 | 
								if (isInsertAndCommit) {
 | 
				
			||||||
 | 
									Map<String, Object> returnMap = ((IGatheringbillOpenService) NCLocator.getInstance()
 | 
				
			||||||
 | 
											.lookup(IGatheringbillOpenService.class)).saveAndCommitBill(bill);
 | 
				
			||||||
 | 
									return ResultMessageUtil.toJSON(returnMap);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								Map<String, String> returnMap = ((IGatheringbillOpenService) NCLocator.getInstance()
 | 
				
			||||||
 | 
										.lookup(IGatheringbillOpenService.class)).saveBill(bill);
 | 
				
			||||||
 | 
								return ResultMessageUtil.toJSON(returnMap);
 | 
				
			||||||
 | 
							} catch (Exception e) {
 | 
				
			||||||
 | 
								return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@POST
 | 
				
			||||||
 | 
						@Path("/uncommitanddelete")
 | 
				
			||||||
 | 
						@Consumes({ "application/json" })
 | 
				
			||||||
 | 
						@Produces({ "application/json" })
 | 
				
			||||||
 | 
						public JSONString unCommitAndDelBill(JSONString str) {
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								return unCommitAndDelBill(str, "pk_gatherbill", "F2");
 | 
				
			||||||
 | 
							} catch (BusinessException e) {
 | 
				
			||||||
 | 
								return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@POST
 | 
				
			||||||
 | 
						@Path("/query")
 | 
				
			||||||
 | 
						@Consumes({ "application/json" })
 | 
				
			||||||
 | 
						@Produces({ "application/json" })
 | 
				
			||||||
 | 
						public JSONString queryBill(JSONString str) {
 | 
				
			||||||
 | 
							return queryBill(str, "F2");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@POST
 | 
				
			||||||
 | 
						@Path("/update")
 | 
				
			||||||
 | 
						@Consumes({ "application/json" })
 | 
				
			||||||
 | 
						@Produces({ "application/json" })
 | 
				
			||||||
 | 
						public JSONString updateBill(JSONString str) {
 | 
				
			||||||
 | 
							return updateBill(str, "F2");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@POST
 | 
				
			||||||
 | 
						@Path("/delete")
 | 
				
			||||||
 | 
						@Consumes({ "application/json" })
 | 
				
			||||||
 | 
						@Produces({ "application/json" })
 | 
				
			||||||
 | 
						public JSONString deleteBill(JSONString str) {
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								return deleteBill(str, "pk_gatherbill", "F2");
 | 
				
			||||||
 | 
							} catch (BusinessException e) {
 | 
				
			||||||
 | 
								return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@POST
 | 
				
			||||||
 | 
						@Path("/commit")
 | 
				
			||||||
 | 
						@Consumes({ "application/json" })
 | 
				
			||||||
 | 
						@Produces({ "application/json" })
 | 
				
			||||||
 | 
						public JSONString commitBill(JSONString str) {
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								return commitBill(str, "pk_gatherbill", "F2");
 | 
				
			||||||
 | 
							} catch (BusinessException e) {
 | 
				
			||||||
 | 
								return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@POST
 | 
				
			||||||
 | 
						@Path("/uncommit")
 | 
				
			||||||
 | 
						@Consumes({ "application/json" })
 | 
				
			||||||
 | 
						@Produces({ "application/json" })
 | 
				
			||||||
 | 
						public JSONString unCommitBill(JSONString str) {
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								return unCommitBill(str, "pk_gatherbill", "F2");
 | 
				
			||||||
 | 
							} catch (BusinessException e) {
 | 
				
			||||||
 | 
								return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,60 @@
 | 
				
			||||||
 | 
					package nc.api.arap.resource;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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