package org.example.background.condition;

import org.apache.ibatis.jdbc.SQL;
import org.example.background.entity.ElectricityData;
import org.example.socket.utils.FieldUtils;
import org.springframework.cglib.beans.BeanMap;

public class ElectricityDataCondition {

    public String insert(ElectricityData data){
        SQL sql = new SQL();
        sql.INSERT_INTO("electricity_data");
        BeanMap beanMap = BeanMap.create(data);
        for (Object key : beanMap.keySet()) {
            Object val = beanMap.get(key);
            if (val != null) {
                sql.VALUES(FieldUtils.camelToLines(key + ""), "#{" + key + "}");
            }
        }
        return sql.toString();
    }

    public String updateByPrimaryKey(ElectricityData data) {
        SQL sql = new SQL();
        sql.UPDATE("electricity_data");
        BeanMap beanMap = BeanMap.create(data);
        for (Object key : beanMap.keySet()) {
            Object val = beanMap.get(key);
            if (val != null) {
                sql.SET(FieldUtils.camelToLines(key + "") + "=#{" + key + "}");
            }
        }
        sql.WHERE("electricity_id= #{electricityId}");
        return sql.toString();
    }
}
