package com.persagy.adm.server.custom.entity.db;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;

/**
 * 数据实体基类
 */
@Data
abstract public class BaseAdmDataEntity extends BaseAdmEntity {

	protected String buildingId;

	protected String floorId;

	protected String creator;

	protected String creationTime;

	protected String modifier;

	protected String modifiedTime;

	protected Integer valid;

	@JsonSerialize(using = DateToLongSerializer.class)
	protected Timestamp ts;

	/** APP端上传的数据状态，可以判断是否为新增数据 */
	@TableField(exist = false)
	protected Integer state;

}

class DateToLongSerializer extends JsonSerializer<Date> {

	@Override
	public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
		jsonGenerator.writeNumber(date.getTime());
	}

}