其他分享
首页 > 其他分享> > http后台json解析实例

http后台json解析实例

作者:互联网

localhost:8080/hbinterface/orderInterface/sIReverseAccept.do?bizType=4&&bnetAccount=ESBTEST20150522OP&&bnetId=GD101140264&&customerType={accNbr:"13316268440","bnetId":"D101140264","bnetAccount":"ESBTEST20150522OP","contactTelephone":"13316268440","contactPersonName":"13316268440","identitySerialNumber":"13316268440",identityType:1,"nodeId":"100000",
servNbr:"GZ200000008536710189","offeringType":{"offeringSpecId":"GD9900405","servNbr":"GZ200000008536710189","productType":[{"productSpecId":"GD9900404","productAttributeList":[{"attributeId":"1","attributeValue":"1","productSpecId":"GD9900405"},{"attributeId":"1","attributeValue":"1","productSpecId":"GD9900108"}]},{"productSpecId":"GD9900406","productAttributeList":[{"attributeId":"1","attributeValue":"1","productSpecId":"GD9900415"}]}]}}

  

 

后台解析:

package com.eshore.ismp.hbinterface.webapi.controller.b;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.eshore.ismp.common.entity.ResultInfo;
import com.eshore.ismp.common.hb.esb.b.CustomerType;
import com.eshore.ismp.common.hb.esb.b.OfferingType;
import com.eshore.ismp.common.hb.esb.b.OnlineAcceptType;
import com.eshore.ismp.common.hb.esb.b.ProductAttributeType;
import com.eshore.ismp.common.hb.esb.b.ProductType;
import com.eshore.ismp.common.util.ConstVal;
import com.eshore.ismp.hbinterface.entity.webapi.ReverseOrderEntity;
import com.eshore.ismp.hbinterface.esb.b.BizAcceptService;
import com.eshore.ismp.hbinterface.respository.webapi.ReverseOrderRepository;

/**
 * @author mercy
 *反向订购接口
 */
@RestController
@RequestMapping("/orderInterface")
public class ReverseAcceptHttpProcess {
	private static final Log log = LogFactory.getLog(ReverseAcceptHttpProcess.class);
	@Autowired
	private BizAcceptService service;
	@Autowired
	private ReverseOrderRepository dao;

	/**
	 * @return
	 * 集团反向订购
	 * 只做校验
	 */
	@RequestMapping("/groupReverseAccept")
	public String groupReverseAccept(HttpServletRequest request){
		ResultInfo resultInfo = new ResultInfo(ConstVal.RESULT_CODE_SUCCESS, ConstVal.RESULT_DETAIL_SUCCESS, "");
		OnlineAcceptType oaType=new OnlineAcceptType();
		CustomerType cType=new CustomerType();
		OfferingType oType=new OfferingType();
		List<ProductType> pTypeList=new ArrayList<ProductType>();
		List<ProductAttributeType> lpTypeList=new ArrayList<ProductAttributeType>();
		long bizType=Long.parseLong(request.getParameter("bizType"));
		String bnetId=request.getParameter("bnetId");
		String bnetAccount=request.getParameter("bnetAccount");
		log.info("bizType:"+bizType+",bnetId:"+bnetId+",bnetAccount"+bnetAccount+"\n");
		oaType.setBizType(bizType);
		oaType.setBnetId(bnetId);
		//oaType.setBnetAccount(bnetAccount);
		String customerType=request.getParameter("customerType");
		ReverseOrderEntity entity=new ReverseOrderEntity();
		String msg="bizType="+bizType+"&&bnetId="+bnetId+"&&bnetAccount="+bnetAccount+"&&customerType="+customerType;
		entity.setMsg(msg);
		entity.setType(1);
		dao.save(entity);
		if(isEmpty(customerType)){
			resultInfo.setResult_code(-1);
			resultInfo.setResult_detail("参数customerType不能为空");
			return JSONObject.toJSONString(resultInfo);
		}
		JSONObject cuType=(JSONObject) JSONObject.parse(customerType);
		String accNbr=cuType.getString("accNbr");
		String cbnetId=cuType.getString("bnetId");
		String cbnetAccount=cuType.getString("bnetAccount");
		String contactTelephone=cuType.getString("contactTelephone");
		String contactPersonName=cuType.getString("contactPersonName");
		//经办人证件号码
		String identitySerialNumber=cuType.getString("identitySerialNumber");
		//经办人证件类型 
		long identityType=cuType.getLongValue("identityType");
		String identityAddress=cuType.getString("identityAddress");
		String nodeId=cuType.getString("nodeId");
		String servNbr=cuType.getString("servNbr");
		if(isEmpty(cbnetId)){
			resultInfo.setResult_code(-1);
			resultInfo.setResult_detail("参数bnetId不能为空");
			return JSONObject.toJSONString(resultInfo);
		}
		if(isEmpty(cbnetAccount)){
			resultInfo.setResult_code(-1);
			resultInfo.setResult_detail("参数bnetAccount不能为空");
			return JSONObject.toJSONString(resultInfo);
		}
		if(isEmpty(nodeId)){
			resultInfo.setResult_code(-1);
			resultInfo.setResult_detail("参数nodeId不能为空");
			return JSONObject.toJSONString(resultInfo);
		}
		if(isEmpty(servNbr)){
			resultInfo.setResult_code(-1);
			resultInfo.setResult_detail("参数servNbr不能为空");
			return JSONObject.toJSONString(resultInfo);
		}
		if(isEmpty(identityType)){
			resultInfo.setResult_code(-1);
			resultInfo.setResult_detail("参数identityType不能为空");
			return JSONObject.toJSONString(resultInfo);
		}
		if(isEmpty(identitySerialNumber)){
			resultInfo.setResult_code(-1);
			resultInfo.setResult_detail("参数identitySerialNumber不能为空");
			return JSONObject.toJSONString(resultInfo);
		}
		if(isEmpty(identityAddress)){
			resultInfo.setResult_code(-1);
			resultInfo.setResult_detail("参数identityAddress不能为空");
			return JSONObject.toJSONString(resultInfo);
		}
		//long state=cuType.getLongValue("state");
		log.info("accNbr:"+accNbr+",bnetAccount:"+cbnetAccount+",bnetId"+cbnetId+",contactTelephone:"+contactTelephone
				+",contactPersonName:"+contactPersonName+",identitySerialNumber:"+identitySerialNumber+",identityType:"+identityType
				+",identityAddress:"+identityAddress+",nodeId:"+nodeId+",servNbr:"+servNbr+"\n");
		cType.setAccNbr(accNbr);
		//cType.setBnetId(cbnetId);
		cType.setBnetAccount(cbnetAccount);
		cType.setContactTelephone(contactTelephone);
		cType.setCompanyName(contactPersonName);
		cType.setIdentitySerialNumber(identitySerialNumber);
		cType.setIdentityType(identityType);
		cType.setIdentityAddress(identityAddress);
		cType.setNodeId(nodeId);
		cType.setServNbr(servNbr);
		//cType.setState(state);
		String offeringType=cuType.getString("offeringType");
		log.info("====offeringType:"+offeringType+"\n");
		JSONObject ofType=(JSONObject) JSONObject.parse(offeringType);
		//String oaccNbr=ofType.getString("accNbr");
		//String obnetId=ofType.getString("bnetId");
		//String onodeId=ofType.getString("nodeId");
		String oofferingSpecId=ofType.getString("offeringSpecId");
		String oservNbr=ofType.getString("servNbr");
		//oType.setAccNbr(oaccNbr);
		//oType.setBnetId(obnetId);
		//oType.setNodeId(onodeId);
		log.info("offeringSpecId:"+oofferingSpecId+",servNbr:"+oservNbr);
		oType.setOfferingSpecId(oofferingSpecId);
		oType.setServNbr(oservNbr);
		String productTypeList=ofType.getString("productType");
		log.info("===productTypeList:"+productTypeList);
		List<ProductType>  pTypeList1=JSONArray.parseArray(productTypeList,ProductType.class);
		for(ProductType pt:pTypeList1){
			ProductType pType=new ProductType();
			//String pbnetId=pt.getBnetId();
			//String pnodeId=pt.getNodeId();
			String productSpecId=pt.getProductSpecId();
			//pType.setBnetId(pbnetId);
			//pType.setNodeId(pnodeId);
			pType.setProductSpecId(productSpecId);
			log.info("===list productSpecId:"+productSpecId);
			List<ProductAttributeType> lpTypeList1=pt.getProductAttributeList();
			for(ProductAttributeType ls:lpTypeList1){
				ProductAttributeType paType=new ProductAttributeType();
				String attributeId=ls.getAttributeId();
				String attributeValue=ls.getAttributeValue();
				String lproductSpecId=ls.getProductSpecId();
				log.info("===AttributeList attributeId:"+attributeId+",attributeValue:"+attributeValue+",productSpecId:"+lproductSpecId);
				paType.setAttributeId(attributeId);
				paType.setAttributeValue(attributeValue);
				paType.setProductSpecId(lproductSpecId);
				lpTypeList.add(paType);
			}
			pType.setProductAttributeList(lpTypeList);
			pTypeList.add(pType);
		}
		oType.setProductList(pTypeList);
		oaType.setOfferingType(oType);
		oaType.setCustomerType(cType);
		log.info("oaTypeToString:"+JSONObject.toJSONString(oaType));
		String result=JSONObject.toJSONString(service.newGroupProd(oaType));
		return result;
	}
	/**
	 * @return
	 * SI反向订购改号
	 * 只做校验
	 */
	@RequestMapping("/sIReverseAccept")
	public String sIReverseAccept(HttpServletRequest request){
		ResultInfo resultInfo = new ResultInfo(ConstVal.RESULT_CODE_SUCCESS, ConstVal.RESULT_DETAIL_SUCCESS, "");
		OnlineAcceptType oaType=new OnlineAcceptType();
		CustomerType cType=new CustomerType();
		OfferingType oType=new OfferingType();
		List<ProductType> pTypeList=new ArrayList<ProductType>();
		List<ProductAttributeType> lpTypeList=new ArrayList<ProductAttributeType>();
		long bizType=Long.parseLong(request.getParameter("bizType"));
		String bnetId=request.getParameter("bnetId");
		String bnetAccount=request.getParameter("bnetAccount");
		log.info("bizType:"+bizType+",bnetId:"+bnetId+",bnetAccount"+bnetAccount+"\n");
		oaType.setBizType(bizType);
		oaType.setBnetId(bnetId);
		//oaType.setBnetAccount(bnetAccount);
		String customerType=request.getParameter("customerType");
		ReverseOrderEntity entity=new ReverseOrderEntity();
		String msg="bizType="+bizType+"&&bnetId="+bnetId+"&&bnetAccount="+bnetAccount+"&&customerType="+customerType;
		entity.setMsg(msg);
		entity.setType(2);
		dao.save(entity);
		if(isEmpty(customerType)){
			resultInfo.setResult_code(-1);
			resultInfo.setResult_detail("参数customerType不能为空");
			return JSONObject.toJSONString(resultInfo);
		}
		JSONObject cuType=(JSONObject) JSONObject.parse(customerType);
		String accNbr=cuType.getString("accNbr");
		String cbnetId=cuType.getString("bnetId");
		String cbnetAccount=cuType.getString("bnetAccount");
		String contactTelephone=cuType.getString("contactTelephone");
		String contactPersonName=cuType.getString("contactPersonName");
		//经办人证件号码
		String identitySerialNumber=cuType.getString("identitySerialNumber");
		//经办人证件类型 
		long identityType=cuType.getLongValue("identityType");
		String identityAddress=cuType.getString("identityAddress");
		String nodeId=cuType.getString("nodeId");
		String servNbr=cuType.getString("servNbr");
		if(isEmpty(cbnetId)){
			resultInfo.setResult_code(-1);
			resultInfo.setResult_detail("参数bnetId不能为空");
			return JSONObject.toJSONString(resultInfo);
		}
		if(isEmpty(cbnetAccount)){
			resultInfo.setResult_code(-1);
			resultInfo.setResult_detail("参数bnetAccount不能为空");
			return JSONObject.toJSONString(resultInfo);
		}
		if(isEmpty(nodeId)){
			resultInfo.setResult_code(-1);
			resultInfo.setResult_detail("参数nodeId不能为空");
			return JSONObject.toJSONString(resultInfo);
		}
		if(isEmpty(servNbr)){
			resultInfo.setResult_code(-1);
			resultInfo.setResult_detail("参数servNbr不能为空");
			return JSONObject.toJSONString(resultInfo);
		}
		if(isEmpty(identityType)){
			resultInfo.setResult_code(-1);
			resultInfo.setResult_detail("参数identityType不能为空");
			return JSONObject.toJSONString(resultInfo);
		}
		if(isEmpty(identitySerialNumber)){
			resultInfo.setResult_code(-1);
			resultInfo.setResult_detail("参数identitySerialNumber不能为空");
			return JSONObject.toJSONString(resultInfo);
		}
		if(isEmpty(identityAddress)){
			resultInfo.setResult_code(-1);
			resultInfo.setResult_detail("参数identityAddress不能为空");
			return JSONObject.toJSONString(resultInfo);
		}
		//long state=cuType.getLongValue("state");
		log.info("accNbr:"+accNbr+",bnetAccount:"+cbnetAccount+",bnetId"+cbnetId+",contactTelephone:"+contactTelephone
				+",contactPersonName:"+contactPersonName+",identitySerialNumber:"+identitySerialNumber+",identityType:"+identityType
				+",identityAddress:"+identityAddress+",nodeId:"+nodeId+",servNbr:"+servNbr+"\n");
		cType.setAccNbr(accNbr);
		//cType.setBnetId(cbnetId);
		cType.setBnetAccount(cbnetAccount);
		cType.setContactTelephone(contactTelephone);
		cType.setCompanyName(contactPersonName);
		cType.setIdentitySerialNumber(identitySerialNumber);
		cType.setIdentityType(identityType);
		cType.setIdentityAddress(identityAddress);
		cType.setNodeId(nodeId);
		cType.setServNbr(servNbr);
		//cType.setState(state);
		String offeringType=cuType.getString("offeringType");
		log.info("====offeringType:"+offeringType+"\n");
		JSONObject ofType=(JSONObject) JSONObject.parse(offeringType);
		//String oaccNbr=ofType.getString("accNbr");
		//String obnetId=ofType.getString("bnetId");
		//String onodeId=ofType.getString("nodeId");
		String oofferingSpecId=ofType.getString("offeringSpecId");
		String oservNbr=ofType.getString("servNbr");
		//oType.setAccNbr(oaccNbr);
		//oType.setBnetId(obnetId);
		//oType.setNodeId(onodeId);
		log.info("offeringSpecId:"+oofferingSpecId+",servNbr:"+oservNbr);
		oType.setOfferingSpecId(oofferingSpecId);
		oType.setServNbr(oservNbr);
		String productTypeList=ofType.getString("productType");
		log.info("===productTypeList:"+productTypeList);
		List<ProductType>  pTypeList1=JSONArray.parseArray(productTypeList,ProductType.class);
		for(ProductType pt:pTypeList1){
			ProductType pType=new ProductType();
			//String pbnetId=pt.getBnetId();
			//String pnodeId=pt.getNodeId();
			String productSpecId=pt.getProductSpecId();
			//pType.setBnetId(pbnetId);
			//pType.setNodeId(pnodeId);
			pType.setProductSpecId(productSpecId);
			log.info("===list productSpecId:"+productSpecId);
			List<ProductAttributeType> lpTypeList1=pt.getProductAttributeList();
			for(ProductAttributeType ls:lpTypeList1){
				ProductAttributeType paType=new ProductAttributeType();
				String attributeId=ls.getAttributeId();
				String attributeValue=ls.getAttributeValue();
				String lproductSpecId=ls.getProductSpecId();
				log.info("===AttributeList attributeId:"+attributeId+",attributeValue:"+attributeValue+",productSpecId:"+lproductSpecId);
				paType.setAttributeId(attributeId);
				paType.setAttributeValue(attributeValue);
				paType.setProductSpecId(lproductSpecId);
				lpTypeList.add(paType);
			}
			pType.setProductAttributeList(lpTypeList);
			pTypeList.add(pType);
		}
		oType.setProductList(pTypeList);
		oaType.setOfferingType(oType);
		oaType.setCustomerType(cType);
		log.info("oaTypeToString:"+JSONObject.toJSONString(oaType));
		String result=JSONObject.toJSONString(service.modifyGroupProd(oaType));
		return result;
	}
	public boolean isEmpty(Object obj){
		if(null==obj||obj.equals("")){
			return true;
		}
		return false;
		
	}


}

  

标签:http,String,getString,JSONObject,cType,resultInfo,json,实例,setResult
来源: https://www.cnblogs.com/JAYIT/p/10522300.html