sfd
2025-05-20 a18b8e051947411bab76769efc20b4814d7e0674
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package com.aps.core.service.impl;
 
import cn.hutool.core.util.IdUtil;
import com.aps.common.core.utils.DateUtils;
import com.aps.common.security.utils.SecurityUtils;
import com.aps.core.domain.ApsGasPipelinePrediction;
import com.aps.core.mapper.ApsGasPipelinePredictionMapper;
import com.aps.core.service.IApsGasPipelinePredictionService;
import io.micrometer.common.util.StringUtils;
import lombok.SneakyThrows;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
 
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * 管路手工气体预测数据Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-19
 */
@Service
public class ApsGasPipelinePredictionServiceImpl implements IApsGasPipelinePredictionService
{
    @Autowired
    private ApsGasPipelinePredictionMapper apsGasPipelinePredictionMapper;
 
    /**
     * 查询管路手工气体预测数据
     * 
     * @param id 管路手工气体预测数据主键
     * @return 管路手工气体预测数据
     */
    @Override
    public ApsGasPipelinePrediction selectApsGasPipelinePredictionById(Long id)
    {
        return apsGasPipelinePredictionMapper.selectApsGasPipelinePredictionById(id);
    }
 
    /**
     * 查询管路手工气体预测数据列表
     * 
     * @param apsGasPipelinePrediction 管路手工气体预测数据
     * @return 管路手工气体预测数据
     */
    @Override
    public List<ApsGasPipelinePrediction> selectApsGasPipelinePredictionList(ApsGasPipelinePrediction apsGasPipelinePrediction)
    {
        return apsGasPipelinePredictionMapper.selectApsGasPipelinePredictionList(apsGasPipelinePrediction);
    }
 
    /**
     * 新增管路手工气体预测数据
     * 
     * @param apsGasPipelinePrediction 管路手工气体预测数据
     * @return 结果
     */
    @Override
    public int insertApsGasPipelinePrediction(ApsGasPipelinePrediction apsGasPipelinePrediction)
    {
        apsGasPipelinePrediction.setCreateTime(DateUtils.getNowDate());
        return apsGasPipelinePredictionMapper.insertApsGasPipelinePrediction(apsGasPipelinePrediction);
    }
 
    /**
     * 修改管路手工气体预测数据
     * 
     * @param apsGasPipelinePrediction 管路手工气体预测数据
     * @return 结果
     */
    @Override
    public int updateApsGasPipelinePrediction(ApsGasPipelinePrediction apsGasPipelinePrediction)
    {
        apsGasPipelinePrediction.setUpdateTime(DateUtils.getNowDate());
        return apsGasPipelinePredictionMapper.updateApsGasPipelinePrediction(apsGasPipelinePrediction);
    }
 
    /**
     * 批量删除管路手工气体预测数据
     * 
     * @param ids 需要删除的管路手工气体预测数据主键
     * @return 结果
     */
    @Override
    public int deleteApsGasPipelinePredictionByIds(Long[] ids)
    {
        return apsGasPipelinePredictionMapper.deleteApsGasPipelinePredictionByIds(ids);
    }
 
    /**
     * 删除管路手工气体预测数据信息
     * 
     * @param id 管路手工气体预测数据主键
     * @return 结果
     */
    @Override
    public int deleteApsGasPipelinePredictionById(Long id)
    {
        return apsGasPipelinePredictionMapper.deleteApsGasPipelinePredictionById(id);
    }
 
    @SneakyThrows
    @Override
    public int batchInsertApsGasPipelinePrediction(MultipartFile file) {
        Workbook workbook = WorkbookFactory.create(file.getInputStream());
 
        Sheet sheet = workbook.getSheetAt(0);
        int rows = sheet.getLastRowNum();
        if (rows > 0) {
            List<ApsGasPipelinePrediction> list = new ArrayList<>();
 
            /*数据列从1开始*/
            for (int i = 1; i <= rows; i++) {
                Row row = sheet.getRow(i);
                if (row.getCell(0) == null){
                    continue;
                }
 
                String materialCode = row.getCell(0).getStringCellValue();
                if (StringUtils.isEmpty(materialCode)){
                    continue;
                }
                String factory = row.getCell(1).getStringCellValue();
                double quantity = row.getCell(2).getNumericCellValue();
                Date date = row.getCell(3).getDateCellValue();
                if (StringUtils.isNotBlank(factory) &&
                    date != null) {
                    ApsGasPipelinePrediction item = new ApsGasPipelinePrediction();
                    item.setId(IdUtil.getSnowflakeNextId());
                    item.setFactory(factory);
                    item.setMaterialCode(materialCode);
                    item.setCreateBy(SecurityUtils.getUsername());
                    item.setCreateTime(DateUtils.getNowDate());
                    item.setPredictQuantity(new BigDecimal(quantity));
                    item.setPredictDate(new Timestamp(date.getTime()));
                    list.add(item);
                }
            }
            if (!list.isEmpty()) {
                apsGasPipelinePredictionMapper.deleteAll();
                apsGasPipelinePredictionMapper.insert(list);
            }
            return list.size();
        }
        return 0;
    }
}