package com.pactera.nc.utils;
import java.rmi.RemoteException;
import java.util.Date;
import org.apache.commons.lang.StringUtils;
import com.pactera.common.General;
import com.pactera.model.sign.TranContract;
import com.pactera.model.transaction.TranSubscribingExample;
import com.pactera.model.transaction.TranSubscribingExample.Criteria;
import com.pactera.utils.PasswdUtil;
import nc.sd.ht.itf.IPosHTTInfo.IPosHTTInfoPortTypeProxy;
import nc.vo.pub.BusinessException.BusinessException;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
* 调用NC系统
* @author admin
*
*/
public class NCDataSharedUtils {
/**
* 数据同步分享到NC系统
* @param contractid
* @throws Exception
*/
public static void dataShared(TranContract tranContract) throws Exception{
String enpoint = General.getConfigurationInformation("config.properties", "NC.service.wsdl");
String appkey = General.getConfigurationInformation("config.properties", "NC.service.appkey");
long time = new Date().getTime();
String str = "QM" + appkey + time;
String token = PasswdUtil.getMD5(str);
JSONObject jsonParams = new JSONObject();
jsonParams.put("appid", "QM");
jsonParams.put("time", time);
jsonParams.put("token", token);
JSONObject jsondata = new JSONObject();
//jsonArr.add(new JSONObject().put("pk_org", ""));//财务组织
jsondata.put("custname", tranContract.getCustomername());//客户名称
//jsonArr.add(new JSONObject().put("contname", ""));//合同名称
jsondata.put("contcode", tranContract.getContractcode());
jsondata.put("contguid", tranContract.getContractid());
//jsonArr.add(new JSONObject().put("contvid", ""));//销售系统的合同版本ID
//jsonArr.add(new JSONObject().put("conttype", ""));//合同类型编码
jsondata.put("roomname", tranContract.getRoomname());
jsondata.put("roomid", tranContract.getRoomid());
jsondata.put("rootunit", tranContract.getRoomstructure());//房间结构
//jsonArr.add(new JSONObject().put("areastate", ""));//面积状态
jsondata.put("areabuild", tranContract.getBuiltarea());
jsondata.put("insidearea", tranContract.getSetinarea());
jsondata.put("buildprice", tranContract.getBuiltprice());
jsondata.put("insideprice", tranContract.getSetinprice());
jsondata.put("standtolpre", tranContract.getStandardtotalprice());
jsondata.put("fpricemodeflag", tranContract.getPricingmode());
jsondata.put("paytype", tranContract.getPaymentmethodname());
jsondata.put("pk_currtype", tranContract.getCurrency());
jsondata.put("discount", tranContract.getDiscount());
jsondata.put("buildconpic", tranContract.getBuilttranprice());
jsondata.put("insideconpr", tranContract.getSetintranprice());
jsondata.put("discounote", tranContract.getDiscountdetail());
jsondata.put("totalpriroot", tranContract.getRoomtotalprice());
jsondata.put("priexcludtax", tranContract.getAmountwithouttax());
jsondata.put("taxye", tranContract.getTaxamount());
jsondata.put("rate", tranContract.getTaxrate());
jsondata.put("dbilldate", tranContract.getContractdate());
jsondata.put("qmcreator", tranContract.getCreateuserid());//销售系统的创建人
jsondata.put("creationtime", tranContract.getCreatetime());//创建时间
jsondata.put("modifiedtime", tranContract.getUpdatetime());
jsondata.put("syssrc", "QM");
jsondata.put("syssrcid", tranContract.getContractguid());
//jsonArr.add(new JSONObject().put("syssrcbillcode", ""));
//作废原因-----合同同步接口不传,作废时作废接口传入
//jsonArr.add(new JSONObject().put("cancelreason", ""));
JSONArray decchoiceJsonArr = new JSONArray();
//sd_decchoice
JSONArray childDecchoiceJsonArr = new JSONArray();
childDecchoiceJsonArr.add(new JSONObject().put("decorstad", tranContract.getDecorationtype()));
childDecchoiceJsonArr.add(new JSONObject().put("decorpric", tranContract.getDecorationprice()));
childDecchoiceJsonArr.add(new JSONObject().put("decorzpric", tranContract.getDecorationamount()));
decchoiceJsonArr.add(childDecchoiceJsonArr);
jsondata.put("sd_decchoice", decchoiceJsonArr);
//sd_abstract
JSONArray abstractJsonArr = new JSONArray();
JSONArray childAbstractJsonArr = new JSONArray();
childAbstractJsonArr.add(new JSONObject().put("contractno", tranContract.getContractcode()));
childAbstractJsonArr.add(new JSONObject().put("contprice", tranContract.getContractamount()));
childAbstractJsonArr.add(new JSONObject().put("ctrsigndate", tranContract.getContractdate()));
childAbstractJsonArr.add(new JSONObject().put("businwdate", tranContract.getBusinessdate()));
childAbstractJsonArr.add(new JSONObject().put("proconsu", tranContract.getSalesmanname()));
abstractJsonArr.add(childAbstractJsonArr);
jsondata.put("sd_abstract", decchoiceJsonArr);
jsonParams.put("data", jsondata);
//调用NC接口
IPosHTTInfoPortTypeProxy iposhttinfoporttypeproxy =
new IPosHTTInfoPortTypeProxy(enpoint);
String returnParam = iposhttinfoporttypeproxy.postQMHT(jsonParams.toString());
//处理接口返回信息
JSONObject jsnResult = JSONObject.fromObject(returnParam);
String status = (String) jsnResult.get("status");
if(StringUtils.equals("0", status)) {
System.out.println((String) jsnResult.get("message"));
throw new Exception();
}
}
/**
* 调用NC合同作废接口
* @param contractid
* @throws Exception
*/
public static void contractInvalid(Integer contractid) throws Exception {
String enpoint = General.getConfigurationInformation("config.properties", "NC.service.wsdl");
String appkey = General.getConfigurationInformation("config.properties", "NC.service.appkey");
long time = new Date().getTime();
String str = "QM" + appkey + time;
String token = PasswdUtil.getMD5(str);
JSONObject jsonParams = new JSONObject();
jsonParams.put("appid", "QM");
jsonParams.put("time", time);
jsonParams.put("token", token);
JSONObject jsondata = new JSONObject();
jsonParams.put("data", jsondata);
jsondata.put("contguid", contractid);
//调用NC接口
IPosHTTInfoPortTypeProxy iposhttinfoporttypeproxy =
new IPosHTTInfoPortTypeProxy(enpoint);
String returnParam = iposhttinfoporttypeproxy.postQMHTCancel(jsonParams.toString());
//处理接口返回信息
JSONObject jsnResult = JSONObject.fromObject(returnParam);
String status = (String) jsnResult.get("status");
if(StringUtils.equals("0", status)) {
throw new Exception();
}
}
public static void main(String[] args) throws BusinessException, RemoteException {
String enpoint = "http://10.3.99.35:80/uapws/service/IPosHTTInfo";
IPosHTTInfoPortTypeProxy iposhttinfoporttypeproxy =
new IPosHTTInfoPortTypeProxy(enpoint);
JSONObject jsondata = new JSONObject();
jsondata.put("jsondata", "asfafaffa");
String A = iposhttinfoporttypeproxy.postQMHT(jsondata.toString());
}
}