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

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.persagy.dmp.common.helper.SpringHelper;
import lombok.Data;

import java.io.IOException;

@Data
@TableName(value = "adm_job_space",autoResultMap = true)
public class AdmJobSpace extends BaseAdmDataEntity {

    private String workId;

    private String spaceId;

//    private String bimId; 业务空间没有bimId

    private String spaceType;

    private String parentSpaceId;

    private Integer archState;

    private Integer equipState;

    @JsonIgnore
    @TableField(
            typeHandler = JacksonTypeHandler.class
    )
    private ArrayNode outline;

    @TableField(
            exist = false
    )
    private String strOutline;

    @Override
    public void serializeJsonProp() {
        if(outline != null) {
            ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
            try {
                strOutline = objectMapper.writeValueAsString(outline);
            } catch (JsonProcessingException e) {

            }
            //outline = null;
        }
    }

    @Override
    public void deserializeJsonProp() {
        if(StrUtil.isNotBlank(strOutline)) {
            ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
            try {
                outline = objectMapper.readValue(strOutline, ArrayNode.class);
            } catch (IOException e) {

            }
            strOutline = null;
        }
    }

}