/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.glaf.core.domain.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.glaf.core.domain.SysLog;
import com.glaf.core.util.DateUtils;

public class SysLogJsonFactory {

	public static java.util.List<SysLog> arrayToList(JSONArray array) {
		java.util.List<SysLog> list = new java.util.ArrayList<SysLog>();
		for (int i = 0, len = array.size(); i < len; i++) {
			JSONObject jsonObject = array.getJSONObject(i);
			SysLog model = jsonToObject(jsonObject);
			list.add(model);
		}
		return list;
	}

	public static SysLog jsonToObject(JSONObject jsonObject) {
		SysLog model = new SysLog();
		if (jsonObject.containsKey("id")) {
			model.setId(jsonObject.getLong("id"));
		}
		if (jsonObject.containsKey("account")) {
			model.setAccount(jsonObject.getString("account"));
		}
		if (jsonObject.containsKey("ip")) {
			model.setIp(jsonObject.getString("ip"));
		}
		if (jsonObject.containsKey("createTime")) {
			model.setCreateTime(jsonObject.getDate("createTime"));
		}
		if (jsonObject.containsKey("operate")) {
			model.setOperate(jsonObject.getString("operate"));
		}
		if (jsonObject.containsKey("flag")) {
			model.setFlag(jsonObject.getInteger("flag"));
		}

		return model;
	}

	public static JSONArray listToArray(java.util.List<SysLog> list) {
		JSONArray array = new JSONArray();
		if (list != null && !list.isEmpty()) {
			for (SysLog model : list) {
				JSONObject jsonObject = model.toJsonObject();
				array.add(jsonObject);
			}
		}
		return array;
	}

	public static JSONObject toJsonObject(SysLog model) {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("id", model.getId());
		jsonObject.put("_id_", model.getId());
		jsonObject.put("_oid_", model.getId());
		if (model.getAccount() != null) {
			jsonObject.put("account", model.getAccount());
		}
		if (model.getIp() != null) {
			jsonObject.put("ip", model.getIp());
		}
		if (model.getCreateTime() != null) {
			jsonObject.put("createTime",
					DateUtils.getDate(model.getCreateTime()));
			jsonObject.put("createTime_date",
					DateUtils.getDate(model.getCreateTime()));
			jsonObject.put("createTime_datetime",
					DateUtils.getDateTime(model.getCreateTime()));
		}
		if (model.getOperate() != null) {
			jsonObject.put("operate", model.getOperate());
		}
		jsonObject.put("flag", model.getFlag());
		return jsonObject;
	}

	public static ObjectNode toObjectNode(SysLog model) {
		ObjectNode jsonObject = new ObjectMapper().createObjectNode();
		jsonObject.put("id", model.getId());
		jsonObject.put("_id_", model.getId());
		jsonObject.put("_oid_", model.getId());
		if (model.getAccount() != null) {
			jsonObject.put("account", model.getAccount());
		}
		if (model.getIp() != null) {
			jsonObject.put("ip", model.getIp());
		}
		if (model.getCreateTime() != null) {
			jsonObject.put("createTime",
					DateUtils.getDate(model.getCreateTime()));
			jsonObject.put("createTime_date",
					DateUtils.getDate(model.getCreateTime()));
			jsonObject.put("createTime_datetime",
					DateUtils.getDateTime(model.getCreateTime()));
		}
		if (model.getOperate() != null) {
			jsonObject.put("operate", model.getOperate());
		}
		jsonObject.put("flag", model.getFlag());
		return jsonObject;
	}

	private SysLogJsonFactory() {

	}

}

@@ -2121,16 +2121,115 @@
 %22));%0A%09%09%7D
+%0A%09%09if (jsonObject.containsKey(%22timeMS%22)) %7B%0A%09%09%09model.setTimeMS(jsonObject.getInteger(%22timeMS%22));%0A%09%09%7D
 %0A%0A%09%09retu
@@ -3337,32 +3337,79 @@
 del.getFlag());%0A
+%09%09jsonObject.put(%22timeMS%22, model.getTimeMS());%0A
 %09%09return jsonObj
@@ -4254,24 +4254,71 @@
 getFlag());%0A
+%09%09jsonObject.put(%22timeMS%22, model.getTimeMS());%0A
 %09%09return jso

update sys log