NC集成旺店通使用JSONObject获取数据

NC使用JSONObject获取数据
小例子测试,非正式环境系统

  1. 需要引入com.alibaba.fastjson.JSONObject.jarnet.sf.json.JSONObject.jar
  2. net.sf.json.JSONObject转换JSON方式JSONObject json=JSONObject.fromObject(request.getParameter("data"));
  3. com.alibaba.fastjson.JSONObject 方式 JSONObject.parseObject(response1);
public class Demo {
	
	public static void main(String[] args) {
	/*增加、删除、修改 */
	IVOPersistence ivop = NCLocator.getInstance().lookup(IVOPersistence.class);
	//单表方式
   	//获取整个json(data)
	JSONObject json=JSONObject.fromObject(request.getParameter("data"));
	 Map<String, Object> map=json;
	  String token= map.get("token").toString();
		 String abledate= map.get("abledate").toString();
		 Integer base_doc_type= (Integer) map.get("base_doc_type");
		......
		 //封装VO
		UserVO userVO = new  UserVO();
		userVO.setAbledate(new UFDate(abledate));
		userVO.setBase_doc_type(base_doc_type);
		userVO.setContentlang(contentlang);
		....

	try {
			ivop.insertVO(userVO);
		} catch (BusinessException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}

	/*多表方式*/
	//获取整个json(data)
	SONObject json=JSONObject.fromObject(request.getParameter("data"));
	//获取表头数据
	JSONObject head = json.getJSONObject("head");
	Map<JSONObject, JSONObject> map=head;
		
	JSONArray bodyjson =json.getJSONArray("body");

	OrderVO orderVO = new OrderVO();//主子表
	OrderHeaderVO headerVO = new OrderHeaderVO();
	OrderItemVO itemVO = new OrderItemVO();
	ArrayList<OrderItemVO> list = new ArrayList<OrderItemVO>();

		/**
		 * 获取表头页面数据
		 */
		// 审批人
//		String user_code_q = map.get("user_code_q");
		String user_code_q= map.get("user_code_q").toString();
		// 已协同生成销售订单
		String bcooptoso = map.get("bcooptoso").toString();
		// 直运采购
		String bdirect = map.get("bdirect").toString();
		.....

		/**
		 * 获取子表页面数据
		 * 循环遍历json,获取数据
		 * 表体可能会有多条数据成为数组,转换时需要使用JSONArray
		 * 
		 */
		
		Map<JSONObject,JSONObject> body = null;
		for (int i = 0; i < bodyjson.size(); i++) {
			body = bodyjson.getJSONObject(i);
		}
		
		// 到货关闭
		String barriveclose = body.get(" barriveclose").toString();
		// 借入转采购
		String bborrowpur = body.get("bborrowpur").toString();
		....
		//利用主子表的VO类把主表/子表VO进行set 插入数据
		list.add(itemVO);
		orderVO.setParent(headerVO);
		orderVO.setChildrenVO(list.toArray(new OrderItemVO[list.size()]));
		//执行持久化操作
		PFBusiAction PFBusiAction = new PFBusiAction();
		try {
			PFBusiAction.processAction("WRITE", "4R", null, orderVO, null, null);
		} catch (Exception e) {
			e.printStackTrace();
		}

	//通过api返回获取数据,
	//例子以旺店通为例
	WdtClient client = new WdtClient(sid,appkey,appsecret,baseUrl);
	//查询数据部需要传入时间
	Map<String, String> params = new HashMap<String, String>();
	//获取时间
	Calendar cal=Calendar.getInstance();
	cal.add(Calendar.DATE,-1);
	Date d=cal.getTime();
	SimpleDateFormat sp=new SimpleDateFormat("yyyy-MM-dd");
	String ZUOTIAN=sp.format(d);//获取前一天日期
	params.put("consign_date","2020-10-25");
	// client.execute("api", 传入的参数);
	String response1 = client.execute("vip_stat_sales_by_spec_shop_warehouse_query.php", params);
	//转换成JSON
	JSONObject json = JSONObject.parseObject(response1);
	根据返回数据格式获取数据
	JSONObject json2 = json.getJSONObject("content");
	
	JSONArray listjosn = json2.getJSONArray("spec_list");
	for (int i = 0; i < listjosn.size(); i++) {
		saleVo = new SaleOrderVO ();
		saleHVo = new SaleOrderHVO();
		saleBVo = new SaleOrderBVO ();
		list = new ArrayList<SaleOrderBVO>();
		//根据下标获取
		Map<String, Object> map = listjosn.getJSONObject(i);
		//行标识
		String rec_id = map.get("rec_id").toString();
		//发货日期
		String consign_date = map.get("consign_date").toString();
		//销售日期
		String sales_date = map.get("sales_date").toString();
		//销售类型
		String order_type = map.get("order_type").toString();		
		//持久化
		try {
			PFBusiAction.processAction("WRITE", "30", w, saleVo, null, null);
					Logger.info("销售订单汇总数据保存成功"+spec_no);
				} catch (Exception e) {
					e.printStackTrace();
					Logger.info("销售订单汇总数据保存失败异常               "+e);
			}


		}
	}

}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值