package com.ho.filecenter.service.impl;

import com.ho.business.entity.DeviceTypeCol;
import com.ho.common.tools.entity.SimpleUser;
import com.ho.filecenter.entity.PvEleAnalysis;
import com.ho.filecenter.mapper.PvEleAnalysisMapper;
import com.ho.filecenter.service.PvEleAnalysisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author xueweizhi
 * @description 针对表【pv_ele_analysis】的数据库操作Service实现
 * @createDate 2023-04-10
 */
@Service
@Slf4j
public class PvEleAnalysisServiceImpl implements PvEleAnalysisService {

    @Autowired
    PvEleAnalysisMapper pvEleAnalysisMapper;

    @Override
    public List<PvEleAnalysis> getPvEleAnalysisList(PvEleAnalysis pvEleAnalysis) {
        List<PvEleAnalysis> pvEleAnalyses = pvEleAnalysisMapper.selectByParam(pvEleAnalysis);
        return pvEleAnalyses;
    }

    @Override
    public int savePvEleAnalysisList(List<PvEleAnalysis> pvEleAnalysisList, SimpleUser user) {
        List<PvEleAnalysis> insertList = new ArrayList<>();
        List<PvEleAnalysis> updateList = new ArrayList<>();
        for (PvEleAnalysis pv : pvEleAnalysisList) {
            if (null != pv.getId()) {
                updateList.add(pv);
            } else {
                pv.setGroupId(user.getGroupId());
                pv.setCreator(user.getUserId());
                pv.setCreateTime(new Date());
                insertList.add(pv);
            }
        }
        if(insertList.size()>0){
            log.info("savePvEleAnalysisList 新增{}条",insertList.size());
            pvEleAnalysisMapper.insertList(insertList);
        }
        if (updateList.size()>0){
            log.info("savePvEleAnalysisList 更新{}条",updateList.size());
            pvEleAnalysisMapper.updateList(updateList);
        }
        return 0;
    }
}
