package cn.ibizlab.core.extensions.service;

import cn.ibizlab.core.lite.service.impl.MetaEntityServiceImpl;
import lombok.extern.slf4j.Slf4j;
import cn.ibizlab.core.lite.domain.MetaEntity;
import cn.ibizlab.core.lite.extensions.service.LiteModelService;
import cn.ibizlab.core.lite.extensions.util.LiteStorage;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
import java.util.*;

/**
 * 实体[实体] 自定义服务对象
 */
@Slf4j
@Primary
@Service("MetaEntityExService")
public class MetaEntityExService extends MetaEntityServiceImpl {

    @Override
    protected Class currentModelClass() {
        return com.baomidou.mybatisplus.core.toolkit.ReflectionKit.getSuperClassGenericType(this.getClass().getSuperclass(), 1);
    }

    /**
     * [GetDefaultModel:GetDefaultModel] 行为扩展
     * @param et
     * @return
     */
    @Override
    @Transactional
    public MetaEntity getDefaultModel(MetaEntity et) {
        return super.getDefaultModel(et);
    }

    @Autowired
    @Lazy
    private LiteModelService liteModelService;

    @Override
    public boolean update(MetaEntity et)
    {
        if(!super.update(et))
            return false;
        liteModelService.resetEntityModel(et.getSystemId(), et.getEntityName());
        return true;
    }
}

