liulingling.177216
2024-08-26 349f1cfc5fa77fbc636d542df0d8050fddec48c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.dingzhuo.energy.project.plannedOutput.service.impl;
 
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import com.dingzhuo.energy.common.utils.DateUtils;
import com.dingzhuo.energy.common.utils.time.TimeManager;
import com.dingzhuo.energy.common.utils.time.TimeType;
import com.dingzhuo.energy.project.plannedOutput.domain.PlanEnergy;
import com.dingzhuo.energy.project.plannedOutput.domain.PlannedOutput;
import com.dingzhuo.energy.project.plannedOutput.mapper.PlanEnergyMapper;
import com.dingzhuo.energy.project.plannedOutput.service.IPlanEnergyService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author sys
 * @date 2020-12-17
 */
@Service
public class PlanEnergyServiceImpl implements IPlanEnergyService
{
    private Logger logger = LogManager.getLogger(PlanEnergyServiceImpl.class);
    @Autowired
    private PlanEnergyMapper planEnergyMapper;
 
    /**
     * 查询列表
     */
    @Override
    public List<PlanEnergy> selectPlanEnergyList(List<Integer> indexIds,TimeType timeType, Date dataTime)
    {
        if (indexIds.size() !=0) {
            String timeCode = TimeManager.getTimeCode(dataTime, timeType);
            return planEnergyMapper.selectPlanEnergyList(indexIds,timeCode);
        }
        return Collections.emptyList();
    }
 
    public List<PlanEnergy> PlanEnergyList(List<Integer> indexIds, TimeType timeType, Date dataTime,String type)
    {
        if (indexIds.size() !=0) {
            String timeCode = TimeManager.getTimeCode(dataTime, timeType);
            return planEnergyMapper.PlanEnergyList(indexIds, timeCode,type);
        }
        return Collections.emptyList();
    }
 
 
    /**
     * 新增修改
     */
    @Override
    public void insertPlanEnergy(List<PlanEnergy> datas) {
        List<List<PlanEnergy>> splitDatas = splitList(datas, 100);
        if (splitDatas != null) {
            splitDatas.parallelStream().forEach(dataPart -> {
                /*try {
                    plannedOutputMapper.saveDataList(dataPart);
                } catch (Exception ex) {
                    logger.error("批量保存数据失败", ex);*/
                dataPart.parallelStream().forEach(dataItem -> {
                    try {
                        planEnergyMapper.save(dataItem);
                    } catch (Exception singleEx) {
                        logger.error("单个指标数据保存失败!【" + dataItem + "】", singleEx);
                    }
                });
                /* }*/
            });
        }
    }
    public static <E> List<List<E>> splitList(List<E> targetList, Integer splitSize) {
        if (targetList == null) {
            return Collections.emptyList();
        }
 
        int size = targetList.size();
        List<List<E>> resultList = new ArrayList<>();
        if (size <= splitSize) {
            resultList.add(targetList);
        } else {
            for (int i = 0; i < size; i += splitSize) {
                //用于限制最后一部分size小于splitSize的list
                int limit = i + splitSize;
                if (limit > size) {
                    limit = size;
                }
                resultList.add(targetList.subList(i, limit));
            }
        }
        return resultList;
    }
}