zoukankan      html  css  js  c++  java
  • 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+"
    ");
    		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+"
    ");
    		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+"
    ");
    		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+"
    ");
    		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+"
    ");
    		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+"
    ");
    		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;
    		
    	}
    
    
    }
    

      

  • 相关阅读:
    sniffer 和 debug flow
    如何认识TOS----DSCP 对照表
    NAT alg 和 ASPF
    使用refind引导多系统
    Backdooring a OS VM
    exit(0)与exit(1),return三者区别(详解)
    Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)
    2017年中国大学生程序设计竞赛-中南地区赛暨第八届湘潭市大学生计算机程序设计大赛题解&源码(A.高斯消元,D,模拟,E,前缀和,F,LCS,H,Prim算法,I,胡搞,J,树状数组)
    高斯消元法(Gauss Elimination)【超详解&模板】
    2015 计蒜之道 初赛(4)爱奇艺的自制节目(枚举 贪心)
  • 原文地址:https://www.cnblogs.com/JAYIT/p/10522300.html
Copyright © 2011-2022 走看看