@PostMapping("/takeUserOrder")
public String takeUserOrder(String useOrder,String orderNo){
String json = orderService.getUserOrder(useOrder);
//根据订单号获取List的Map集合
/**
* <select id="getItemMap" resultType="java.util.Map">
* select catalog_no,cas_no,remarks,quantity,size,amount from user_order_item where order_no=#{order_no}
* </select>
*/
List<Map<String, String>> itemMap = orderService.getItemMap(orderNo);
//将Json转为Map对象 JSONObject 方法类 put set 等等
JSONObject jsonObject =JSONObject.parseObject(json);
//实例化集合
List<Map<String,Object>> list = new ArrayList<>();
//put对象
jsonObject.put("applySaleNo",orderNo);
//遍历
itemMap.forEach(p->{
Map<String,Object> map = new HashMap<>();
map.put("catalogNo",p.get("catalog_no"));
map.put("cas",p.get("cas_no"));
map.put("remarks",p.get("remarks"));
map.put("saleCount",p.get("quantity"));
map.put("saleUnit","瓶");
map.put("spec",p.get("size"));
map.put("moneyWithTax",0);
map.put("unitPrice",p.get("amount"));
map.put("productRemarks","");
list.add(map);
});
//继续塞入
jsonObject.put("details",list);
//返回json字符串
return jsonObject.toString();
}
示例Json:
{
"applySaleNo": "xxx",
"applySourceName": "xxx",
"ccompanyName": "xxx",
"creceiverName": "xxx",
"creceiverPhone": "xxx",
"creceiverAddr": "xxx",
"creceiverEmail": "xxx",
"cbuyerName": "xxx",
"cbuyerPhone": "xxx",
"cbuyerEmail": "xxx",
"cticketPersonName": "xxx",
"cticketAddr": "xxx",
"cticketEmail": "xxx",
"cticketPhone": "xxx",
"remarks": "xxx",
"otherInfo": "xxx",
"sumPrice": xxx,
"details": [{
"catalogNo": "xxx",
"cas": "1703-46-4",
"remarks": "",
"saleCount": 1,
"saleUnit": "瓶",
"spec": "5g",
"moneyWithTax": 0,
"unitPrice": 1120.00,
"productRemarks": ""
}],
"websitePerSonID": 7713,
"websiteGroupID": 0,
"websiteCustomerName": "xxx",
"paymentMethod": "支付"
}