package com.mortals.xhx.modules.implementlist.service.impl;

import com.github.benmanes.caffeine.cache.Cache;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.modules.implementlist.dao.ImplementlistDao;
import com.mortals.xhx.modules.implementlist.model.ImplementlistEntity;
import com.mortals.xhx.modules.implementlist.service.ImplementlistService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* <p>Title: 实施清单主表</p>
* <p>Description: ImplementlistService service接口 </p>
* <p>Copyright: Copyright &reg;  </p>
* @version 1.0.0
*/
@Service("implementlistService")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ImplementlistServiceImpl extends AbstractCRUDServiceImpl<ImplementlistDao, ImplementlistEntity, Long> implements ImplementlistService {

    private final Cache<String, Object> caffeineCache;

    @Override
    public ImplementlistEntity getThImplement(String event_code) {
        caffeineCache.getIfPresent(event_code);
        ImplementlistEntity thImplementList = (ImplementlistEntity) caffeineCache.asMap().get(event_code);
        if (thImplementList != null) {
            return thImplementList;
        }
        ImplementlistEntity implementlistEntity = new ImplementlistEntity();
        implementlistEntity.setEventCode(event_code);
        List<ImplementlistEntity> implementlistEntities = this.find(implementlistEntity, null);
        if (implementlistEntities.size() > 0) {
            for (ImplementlistEntity entity : implementlistEntities) {
                thImplementList=entity;
                caffeineCache.put(event_code, entity);
            }
        }
        return thImplementList;
    }
}