package com.boman.web.core.domain;

import com.alibaba.fastjson.JSONObject;
import com.boman.gen.domain.GenTable;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zc
 * @date 2019/02/19
 */
@Slf4j
public class RowRecord {

    private GenTable genTable;

    private Long id;

    //提交过来的数据
    private JSONObject postData = new JSONObject();

    //原数据
    private JSONObject originalData = new JSONObject();

    //新数据
    private JSONObject newData;

    //将要提交到数据库中的数据
    private JSONObject commitData = new JSONObject();

    public RowRecord(Long id, GenTable genTable, JSONObject fixedData) {
        this.id = id;
        this.genTable = genTable;

        if (fixedData == null) {
            fixedData = new JSONObject();
        }

        fixedData.forEach((fieldName, fieldValue)->{
            postData.put(fieldName.toUpperCase(), fieldValue);
        });

        for (String key : postData.keySet()) {
            commitData.put(key, postData.get(key));
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("baseData", originalData);
        jsonObject.put("data", commitData);
        newData = new JSONObject(jsonObject);
    }

    public GenTable getGenTable() {
        return genTable;
    }

    public void setGenTable(GenTable genTable) {
        this.genTable = genTable;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public JSONObject getPostData() {
        return postData;
    }

    public void setPostData(JSONObject postData) {
        this.postData = postData;
    }

    public JSONObject getOriginalData() {
        return originalData;
    }

    public void setOriginalData(JSONObject originalData) {
        this.originalData = originalData;
    }

    public JSONObject getNewData() {
        return newData;
    }

    public void setNewData(JSONObject newData) {
        this.newData = newData;
    }

    public JSONObject getCommitData() {
        return commitData;
    }

    public void setCommitData(JSONObject commitData) {
        this.commitData = commitData;
    }
}
