package com.huatek.busi.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.huatek.busi.entity.TransformerEpaOfflineData;
import com.huatek.busi.mapper.TransformerEpaOfflineDataMapper;
import com.huatek.busi.service.ITransformerEpaOfflineDataService;
import com.huatek.busi.vo.epa.EpaEvaluateDataVo;
import com.huatek.torch.sql.beans.LocalUser;
import com.huatek.torch.sql.dao.impl.BaseDao;
import com.huatek.torch.util.tools.UserUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Slf4j
@Component
@Service(interfaceClass = ITransformerEpaOfflineDataService.class)
@Transactional(rollbackFor = Exception.class)
public class TransformerEpaOfflineDataServiceImpl extends BaseDao<TransformerEpaOfflineData, String> implements ITransformerEpaOfflineDataService {

    @Resource
    private TransformerEpaOfflineDataMapper transformerEpaOfflineDataMapper;

    @Override
    public int save(String token, TransformerEpaOfflineData transformerEpaOfflineData) {
        LocalUser user = UserUtil.getLocalUser(token);
        if(user != null){
            transformerEpaOfflineData.setCreateUser(user.getUid());
            transformerEpaOfflineData.setCreateTime(LocalDateTime.now());
        }
        return this.addLocal(transformerEpaOfflineData);
    }

    @Override
    public EpaEvaluateDataVo findByMainEquipmentId(String mainEquipmentId){
        return transformerEpaOfflineDataMapper.findByMainEquipmentId(mainEquipmentId);
    }

    @Override
    public int delete(String mainEquipmentId){
        return transformerEpaOfflineDataMapper.delete(mainEquipmentId);
    }
}
