package com.huatek.busi.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.huatek.busi.dao.BusiSemiAutomaticEvaluateDataDao;
import com.huatek.busi.dto.BusiSemiAutomaticEvaluateDataDto;
import com.huatek.busi.entity.BusiSemiAutomaticEvaluateData;
import com.huatek.busi.mapper.BusiSemiAutomaticEvaluateDataMapper;
import com.huatek.busi.service.BusiSemiAutomaticEvaluateDataService;
import com.huatek.busi.vo.BusiSemiAutomaticEvaluateDataVo;
import com.huatek.torch.sql.beans.LocalUser;
import com.huatek.torch.util.tools.UserUtil;
import com.huatek.torch.util.uuid.Uuid;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Component
@Service(interfaceClass = BusiSemiAutomaticEvaluateDataService.class)
@Transactional(rollbackFor = Exception.class)
public class BusiSemiAutomaticEvaluateDataServiceImpl implements BusiSemiAutomaticEvaluateDataService {

    @Autowired
    private BusiSemiAutomaticEvaluateDataDao busiSemiAutomaticEvaluateDataDao;

    @Autowired
    private BusiSemiAutomaticEvaluateDataMapper busiSemiAutomaticEvaluateDataMapper;

    @Override
    public boolean add(String token,BusiSemiAutomaticEvaluateDataDto dto) {
        LocalUser user = UserUtil.getLocalUser(token);
        BusiSemiAutomaticEvaluateData data = new BusiSemiAutomaticEvaluateData();
        BeanUtils.copyProperties(dto, data);
        data.setId(Uuid.getUUID());
        data.setCreateUser(user.getUid());
        data.setCreateTime(LocalDateTime.now());
        int add = busiSemiAutomaticEvaluateDataDao.add(data);
        return add > 0;
    }

    @Override
    public BusiSemiAutomaticEvaluateDataVo getLatest(String equipmentType,String mainEquipmentId,String siteId) {
        return busiSemiAutomaticEvaluateDataMapper.getLatestByEquipmentType(equipmentType,mainEquipmentId,siteId);
    }

    @Override
    public List<BusiSemiAutomaticEvaluateDataVo> getAll(String equipmentType, String mainEquipmentId, String siteId) {
        return busiSemiAutomaticEvaluateDataMapper.getAllByEquipmentID(equipmentType,mainEquipmentId,siteId);
    }
}
