sfd
2025-05-23 8c6327da1e57033a8d331d11e7f2e81496f1d6b5
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
157
158
159
160
161
162
package com.aps.core.controller.mainPlan;
 
import com.aps.common.core.utils.poi.ExcelUtil;
import com.aps.common.core.web.controller.BaseController;
import com.aps.common.core.web.domain.AjaxResult;
import com.aps.common.core.web.page.TableDataInfo;
import com.aps.common.log.annotation.Log;
import com.aps.common.log.enums.BusinessType;
import com.aps.common.security.annotation.RequiresPermissions;
import com.aps.common.security.utils.DictUtils;
import com.aps.core.domain.ApsGasPipelinePrediction;
import com.aps.core.service.IApsGasPipelinePredictionService;
import com.aps.system.api.domain.SysDictData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.SneakyThrows;
import org.apache.commons.io.IOUtils;
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.core.io.ByteArrayResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
 
/**
 * 管路手工气体预测数据Controller
 *
 * @author ruoyi
 * @date 2025-05-19
 */
 
@Tag(name = "管路手工气体预测数据", description = "管路手工气体预测数据接口")
@RestController
@RequestMapping("/gasPipelinePrediction")
public class ApsGasPipelinePredictionController extends BaseController {
    @Autowired
    private IApsGasPipelinePredictionService apsGasPipelinePredictionService;
 
    /**
     * 查询管路手工气体预测数据列表
     */
    @Operation(summary = "查询管路手工气体预测数据列表", description = "分页查询")
    @RequiresPermissions("gasPipeline:prediction:list")
    @GetMapping("/list")
    public TableDataInfo list(ApsGasPipelinePrediction apsGasPipelineMo) {
        startPage();
        List<ApsGasPipelinePrediction> list = apsGasPipelinePredictionService.selectApsGasPipelinePredictionList(apsGasPipelineMo);
        return getDataTable(list);
    }
 
 
    @Operation(summary = "导入手工气体预测数据", description = "批量导入")
    @Log(title = "导入手工气体预测数据", businessType = BusinessType.IMPORT)
//    @RequiresPermissions("gasPipeline:prediction:import")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
 
        apsGasPipelinePredictionService.batchInsertApsGasPipelinePrediction(file);
        return toAjax(true);
    }
 
    /**
     * 下载气体预测数据导入模板
     */
    @SneakyThrows
    @Operation(summary = "下载气体预测数据导入模板", description = "下载气体预测数据导入模板")
//    @RequiresPermissions("gasPipeline:prediction:template")
//    @Log(title = "下载气体预测数据导入模板", businessType = BusinessType.EXPORT)
    @GetMapping("/template")
    public ResponseEntity<ByteArrayResource> exportTemplate() {
        byte[] file = IOUtils.resourceToByteArray("/templates/气体预测数据模板v1.0.xlsx");
        Workbook workbook = WorkbookFactory.create(new ByteArrayInputStream(file));
        Sheet sheet = workbook.getSheet("字典-生产基地");
        List<SysDictData> sysDictDataList = DictUtils.getDictCache("aps_factory");
        if (sysDictDataList != null) {
            for (int i = 0; i < sysDictDataList.size(); i++) {
                Row row = sheet.createRow(i + 1);
                row.createCell(0).setCellValue(sysDictDataList.get(i).getDictValue());
                row.createCell(1).setCellValue(sysDictDataList.get(i).getDictLabel());
            }
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            workbook.write(baos);
            file = baos.toByteArray();
        }
        workbook.close();
        ByteArrayResource resource = new ByteArrayResource(file);
        return ResponseEntity.ok()
                .header("Access-Control-Expose-Headers", HttpHeaders.CONTENT_DISPOSITION)
                .header(HttpHeaders.CONTENT_DISPOSITION,
                        String.format("attachment;filename=%s", URLEncoder.encode("气体预测数据模板.xlsx", StandardCharsets.UTF_8)))
                .header(HttpHeaders.CONTENT_TYPE, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
                .contentLength(file.length)
                .body(resource);
    }
 
    /**
     * 导出管路手工气体预测数据列表
     */
    @Operation(summary = "导出管路手工气体预测数据列表", description = "导出")
    @RequiresPermissions("gasPipeline:prediction:export")
    @Log(title = "管路手工气体预测数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApsGasPipelinePrediction apsGasPipelinePrediction) {
        List<ApsGasPipelinePrediction> list = apsGasPipelinePredictionService.selectApsGasPipelinePredictionList(apsGasPipelinePrediction);
        ExcelUtil<ApsGasPipelinePrediction> util = new ExcelUtil<ApsGasPipelinePrediction>(ApsGasPipelinePrediction.class);
        util.exportExcel(response, list, "管路手工气体预测数据数据");
    }
 
    /**
     * 获取管路手工气体预测数据详细信息
     */
    @Operation(summary = "获取管路手工气体预测数据详细信息", description = "根据id获取")
    @RequiresPermissions("gasPipeline:prediction:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(apsGasPipelinePredictionService.selectApsGasPipelinePredictionById(id));
    }
 
    /**
     * 新增管路手工气体预测数据
     */
    @Operation(summary = "新增管路手工气体预测数据", description = "单个新增")
    @RequiresPermissions("gasPipeline:prediction:add")
    @Log(title = "管路手工气体预测数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApsGasPipelinePrediction apsGasPipelinePrediction) {
        return toAjax(apsGasPipelinePredictionService.insertApsGasPipelinePrediction(apsGasPipelinePrediction));
    }
 
    /**
     * 修改管路手工气体预测数据
     */
    @Operation(summary = "修改管路手工气体预测数据", description = "单个修改")
    @RequiresPermissions("gasPipeline:prediction:edit")
    @Log(title = "管路手工气体预测数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApsGasPipelinePrediction apsGasPipelinePrediction) {
        return toAjax(apsGasPipelinePredictionService.updateApsGasPipelinePrediction(apsGasPipelinePrediction));
    }
 
    /**
     * 删除管路手工气体预测数据
     */
    @Operation(summary = "删除管路手工气体预测数据", description = "批量删除")
    @RequiresPermissions("gasPipeline:prediction:remove")
    @Log(title = "管路手工气体预测数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(apsGasPipelinePredictionService.deleteApsGasPipelinePredictionByIds(ids));
    }
}