package com.boman.system.common;

import com.alibaba.fastjson.JSONObject;
import com.boman.common.core.utils.SpringUtils;
import com.boman.gen.domain.GenTable;
import com.boman.system.mapper.StandardlyMapper;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zc
 * @date 2019/02/19
 */
@Data
@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);
    }

}
