package com.mirs.biz.service.impl;

import java.util.List;

import com.mirs.biz.domain.EmiMeasurement;
import com.mirs.common.exception.ServiceException;
import com.mirs.common.utils.DateUtils;
import com.mirs.common.utils.StringUtils;
import com.mirs.common.utils.bean.BeanValidators;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mirs.biz.mapper.IntegratedDataMapper;
import com.mirs.biz.domain.IntegratedData;
import com.mirs.biz.service.IIntegratedDataService;

import javax.validation.Validator;

/**
 * 积分数据Service业务层处理
 * 
 * @author kk
 * @date 2025-04-24
 */
@Service
public class IntegratedDataServiceImpl implements IIntegratedDataService 
{
    private static final Logger log = LoggerFactory.getLogger(BrdfDataServiceImpl.class);
    @Autowired
    private IntegratedDataMapper integratedDataMapper;

    @Autowired
    protected Validator validator;

    /**
     * 查询积分数据
     * 
     * @param id 积分数据主键
     * @return 积分数据
     */
    @Override
    public IntegratedData selectIntegratedDataById(Long id)
    {
        return integratedDataMapper.selectIntegratedDataById(id);
    }

    /**
     * 查询积分数据列表
     * 
     * @param integratedData 积分数据
     * @return 积分数据
     */
    @Override
    public List<IntegratedData> selectIntegratedDataList(IntegratedData integratedData)
    {
        return integratedDataMapper.selectIntegratedDataList(integratedData);
    }

    /**
     * 新增积分数据
     * 
     * @param integratedData 积分数据
     * @return 结果
     */
    @Override
    public int insertIntegratedData(IntegratedData integratedData)
    {
        integratedData.setCreateTime(DateUtils.getNowDate());
        return integratedDataMapper.insertIntegratedData(integratedData);
    }

    /**
     * 修改积分数据
     * 
     * @param integratedData 积分数据
     * @return 结果
     */
    @Override
    public int updateIntegratedData(IntegratedData integratedData)
    {
        integratedData.setUpdateTime(DateUtils.getNowDate());
        return integratedDataMapper.updateIntegratedData(integratedData);
    }

    /**
     * 批量删除积分数据
     * 
     * @param ids 需要删除的积分数据主键
     * @return 结果
     */
    @Override
    public int deleteIntegratedDataByIds(Long[] ids)
    {
        return integratedDataMapper.deleteIntegratedDataByIds(ids);
    }

    /**
     * 删除积分数据信息
     * 
     * @param id 积分数据主键
     * @return 结果
     */
    @Override
    public int deleteIntegratedDataById(Long id)
    {
        return integratedDataMapper.deleteIntegratedDataById(id);
    }

    @Override
    public String importIntegratedData(List<IntegratedData> integratedDataList, boolean updateSupport, String operName) {
        if (StringUtils.isNull(integratedDataList) || integratedDataList.isEmpty())
        {
            throw new ServiceException("导入用户数据不能为空！");
        }
        int batchSize = 1000; // 每批插入 1000 条
        for (int i =  0; i < integratedDataList.size(); i += batchSize) {
            int end = Math.min(i + batchSize, integratedDataList.size());
            List<IntegratedData> subList = integratedDataList.subList(i, end);
            integratedDataMapper.batchInsertIntegratedData(subList); // 调用 MyBatis 批量插入
        }
        return "导入成功";
    }
}
