package com.boman.report.service.impl;

import com.boman.common.core.utils.SecurityUtils;
import com.boman.domain.entity.StatisticReportPersonnel;
import com.boman.report.mapper.StatisticReportPersonnelMapper;
import com.boman.report.service.StatisticReportPersonnelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.List;

import static com.boman.common.core.utils.obj.ObjectUtils.*;

/**
 * @author shiqian
 * @date 2021年08月24日 11:11
 **/
@Service
public class StatisticReportPersonnelImpl implements StatisticReportPersonnelService {

    private static final Logger LOGGER = LoggerFactory.getLogger(StatisticReportPersonnelImpl.class);

    @Autowired
    private StatisticReportPersonnelMapper personnelMapper;

    @Override
    @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
    public int deleteByStatisticIds(Long[] ids) {
        return personnelMapper.deleteByStatisticIds(ids);
    }

    @Override
    @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
    public int insert(List<StatisticReportPersonnel> personnels) {
        if(isEmpty(personnels)) {
            return 0;
        }

        for(StatisticReportPersonnel personnel : personnels) {
            Timestamp timestamp = new Timestamp(System.currentTimeMillis());
            personnel.setCreateTime(timestamp);
            personnel.setUpdateTime(timestamp);
            personnelMapper.insert(personnel);
        }
        return personnels.size();
    }

    @Override
    @Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
    public int updateStatus(StatisticReportPersonnel personnel) {
        return personnelMapper.updateStatus(personnel);
    }

    @Override
    public List<StatisticReportPersonnel> selectList(StatisticReportPersonnel personnel) {
        personnel.setUserName(SecurityUtils.getUsername());
        return personnelMapper.selectList(personnel);
    }


}
