package gameDesign; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import db.SqlHelper; import entity.JConfig; import entity.UserInfo; import java.util.Iterator; import java.util.Map; public class ItemConstructor extends ElementConstructor { public ItemConstructor(SqlHelper helper, int botId) { super(); this.helper = helper; this.botId = botId; } public void construct(JSONObject jsonObject, UserInfo userinfo) { String category, name, description, attrName, attrValue; JSONArray goods = jsonObject.getJSONArray("goods"); Map attribute = null; Iterator attrIter = null; String conditionName1 = "nums"; String keywords1 = ""; for (JSONObject good : goods.toJavaList(JSONObject.class)) { category = (String) good.get("category"); JSONArray items = good.getJSONArray("items"); for (JSONObject item : items.toJavaList(JSONObject.class)) { name = (String) item.get("name"); description = (String) item.get("intro"); attribute = JSONObject.toJavaObject(item.getJSONObject("attr"), Map.class); attrIter = attribute.keySet().iterator(); while (attrIter.hasNext()) { attrName = attrIter.next(); attrValue = attribute.get(attrName); varInitialMap.put(category + "_" + name + "_" + attrName, attrValue); keywords1 += "+" + name + ":" + attrName ; } } jConfig = new JConfig( conditionName1 + "::match-Keyword=" + keywords1, " ", "match,return-0", "{items_reply-2}", " ", "items_reply:queryAttrByGoodsName:" + conditionName1 ); jConfigList.add(jConfig); } } }