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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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.time.TimeManager;
import com.dingzhuo.energy.common.utils.time.TimeType;
import com.dingzhuo.energy.dataservice.domain.DataItem;
import com.dingzhuo.energy.dataservice.service.impl.PeriodDataServiceImpl;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dingzhuo.energy.project.plannedOutput.mapper.PlannedOutputMapper;
import com.dingzhuo.energy.project.plannedOutput.domain.PlannedOutput;
import com.dingzhuo.energy.project.plannedOutput.service.IPlannedOutputService;
 
/**
 * plannedOutputService业务层处理
 * 
 * @author sys
 * @date 2020-12-16
 */
@Service
public class PlannedOutputServiceImpl implements IPlannedOutputService 
{
    private Logger logger = LogManager.getLogger(PlannedOutputServiceImpl.class);
    @Autowired
    private PlannedOutputMapper plannedOutputMapper;
 
    /**
     * 查询plannedOutput列表
     * 
     * @param
     * @return plannedOutput
     */
    @Override
    public List<PlannedOutput> selectPlannedOutputList(List<Integer> indexIds, TimeType timeType,Date dataTime,String palnType)
    {
        if (indexIds.size() !=0) {
            String timeCode = TimeManager.getTimeCode(dataTime, timeType);
            return plannedOutputMapper.selectPlannedOutputList(indexIds, timeCode,palnType);
        }
        return Collections.emptyList();
    }
    public List<PlannedOutput> selectPlanList(List<Integer> indexIds){
        if (indexIds.size() !=0) {
            return plannedOutputMapper.selectPlanList(indexIds);
        }
        return Collections.emptyList();
    }
    /**
     * 新增plannedOutput
     *
     * @return 结果
     */
    /*@Override
    public int insertPlannedOutput(PlannedOutput plannedOutput)
    {
        return plannedOutputMapper.insertPlannedOutput(plannedOutput);
    }*/
    @Override
    public void insertPlannedOutput(List<PlannedOutput> datas) {
        List<List<PlannedOutput>> 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 {
                            plannedOutputMapper.save(dataItem);
                        } catch (Exception singleEx) {
                            logger.error("单个指标数据保存失败!【" + dataItem + "】", singleEx);
                        }
                    });
               /* }*/
            });
        }
    }
    /**
     * 修改plannedOutput
     * 
     * @param plannedOutput plannedOutput
     * @return 结果
     */
    @Override
    public int updatePlannedOutput(PlannedOutput plannedOutput)
    {
        return plannedOutputMapper.updatePlannedOutput(plannedOutput);
    }
    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;
    }
}