admin
2025-02-19 48c7ffb6e7137b4b62bfdc63be8aa72d085ba40e
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
package com.jcdm.main.da.testDeviceInterface.controller;
 
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import javax.servlet.http.HttpServletResponse;
 
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonObject;
import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
import com.jcdm.main.da.testDeviceInterface.domain.PrintData;
import com.jcdm.main.restful.qingYan.doman.ChildVO;
import com.jcdm.main.restful.qingYan.doman.ParentVO;
import com.jcdm.main.webservice.ItemList;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jcdm.common.annotation.Log;
import com.jcdm.common.core.controller.BaseController;
import com.jcdm.common.core.domain.AjaxResult;
import com.jcdm.common.enums.BusinessType;
import com.jcdm.main.da.testDeviceInterface.domain.DaTestDeviceInterface;
import com.jcdm.main.da.testDeviceInterface.service.IDaTestDeviceInterfaceService;
import com.jcdm.common.utils.poi.ExcelUtil;
import com.jcdm.common.core.page.TableDataInfo;
 
/**
 * 测试设备接口数据Controller
 * 
 * @author hdy
 * @date 2024-05-13
 */
@RestController
@RequestMapping("/da/testDeviceInterface")
public class DaTestDeviceInterfaceController extends BaseController
{
    @Autowired
    private IDaTestDeviceInterfaceService daTestDeviceInterfaceService;
 
    @Autowired
    private IDaParamCollectionService daParamCollectionService;
 
    /**
     * 查询测试设备接口数据列表
     */
    @PostMapping("/testPut")
    public AjaxResult list(@RequestBody ParentVO parentVO) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        List<ChildVO> li = parentVO.getCheckList();
        String s = mapper.writeValueAsString(li);
        DaTestDeviceInterface daTestDeviceInterface = new DaTestDeviceInterface();
        daTestDeviceInterface.setRecordId(parentVO.getRecordId());
        daTestDeviceInterface.setStationCode(parentVO.getStationCode());
        daTestDeviceInterface.setProductNum(parentVO.getProductNum());
        daTestDeviceInterface.setTotalResult(parentVO.getTotalResult());
        daTestDeviceInterface.setCheckList(s);
        daTestDeviceInterfaceService.save(daTestDeviceInterface);
        return AjaxResult.success("i");
    }
 
    /**
     * 查询测试设备接口数据列表
     */
    @PreAuthorize("@ss.hasPermi('da:testDeviceInterface:list')")
    @GetMapping("/list")
    public TableDataInfo list(DaTestDeviceInterface daTestDeviceInterface)
    {
        startPage();
        List<DaTestDeviceInterface> list = daTestDeviceInterfaceService.selectDaTestDeviceInterfaceList(daTestDeviceInterface);
        return getDataTable(list);
    }
 
    /**
     * 导出测试设备接口数据列表
     */
    @PreAuthorize("@ss.hasPermi('da:testDeviceInterface:export')")
    @Log(title = "测试设备接口数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DaTestDeviceInterface daTestDeviceInterface)
    {
        List<DaTestDeviceInterface> list = daTestDeviceInterfaceService.selectDaTestDeviceInterfaceList(daTestDeviceInterface);
        ExcelUtil<DaTestDeviceInterface> util = new ExcelUtil<DaTestDeviceInterface>(DaTestDeviceInterface.class);
        util.exportExcel(response, list, "测试设备接口数据数据");
    }
 
    /**
     * 获取测试设备接口数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('da:testDeviceInterface:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(daTestDeviceInterfaceService.selectDaTestDeviceInterfaceById(id));
    }
 
    /**
     * 新增测试设备接口数据
     */
    @PreAuthorize("@ss.hasPermi('da:testDeviceInterface:add')")
    @Log(title = "测试设备接口数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DaTestDeviceInterface daTestDeviceInterface)
    {
        return toAjax(daTestDeviceInterfaceService.insertDaTestDeviceInterface(daTestDeviceInterface));
    }
 
    /**
     * 修改测试设备接口数据
     */
    @PreAuthorize("@ss.hasPermi('da:testDeviceInterface:edit')")
    @Log(title = "测试设备接口数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DaTestDeviceInterface daTestDeviceInterface)
    {
        return toAjax(daTestDeviceInterfaceService.updateDaTestDeviceInterface(daTestDeviceInterface));
    }
 
    /**
     * 删除测试设备接口数据
     */
    @PreAuthorize("@ss.hasPermi('da:testDeviceInterface:remove')")
    @Log(title = "测试设备接口数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(daTestDeviceInterfaceService.deleteDaTestDeviceInterfaceByIds(ids));
    }
 
    /**
     * 查询设备产品过程参数采集列表
     */
    @GetMapping("/getPrintOfflineReportInfo")
    public AjaxResult getPrintOfflineReportInfo(DaTestDeviceInterface daTestDeviceInterface)
    {
        Map map = new HashMap<>();
        String[] split = daTestDeviceInterface.getProductNum().split(",");
        try{
            CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
                for (int i = 0; i < split.length; i++) {
                    PrintData printData = new PrintData();
                    printData.setParam1("1.1");
                    printData.setParam9("≥125Ah");
                    printData.setParam10("≤200mV");
                    printData.setParam11("≤250mV");
                    printData.setParam12("50");
                    printData.setParam13("15.73");
                    printData.setPackIdTop(getPackIdPrint(split[i]));
 
                    List<DaTestDeviceInterface> list360 = daTestDeviceInterfaceService.list(new LambdaQueryWrapper<DaTestDeviceInterface>()
                        .eq(DaTestDeviceInterface::getProductNum, split[0])
                        .like(DaTestDeviceInterface::getStationCode, "360")
                    );
 
                    if(!list360.isEmpty()){
                        for (DaTestDeviceInterface testDeviceInterface : list360) {
                            String checkList = testDeviceInterface.getCheckList();
                            List<ChildVO> childVOS = JSON.parseArray(checkList, ChildVO.class);
                            if(checkList.contains("PEOL_NZFNY")){
                                Optional<String> optionalParam2 = childVOS.stream().filter(item -> item.getItemCode().equals("PEOL_NZFNY")).map(ChildVO::getItemValue).findFirst();
                                printData.setParam2(optionalParam2.orElse("param2"));
                            }
 
                            if(checkList.contains("PEOL_NZFJY")){
                                Optional<String> optionalParam3 = childVOS.stream().filter(item -> item.getItemCode().equals("PEOL_NZFJY")).map(ChildVO::getItemValue).findFirst();
                                printData.setParam3(optionalParam3.orElse("param3"));
 
                            }
 
                            if(checkList.contains("PEOL_DDWZZ1")){
                                Optional<String> optionalParam4 = childVOS.stream().filter(item -> item.getItemCode().equals("PEOL_DDWZZ1")).map(ChildVO::getItemValue).findFirst();
                                printData.setParam4(optionalParam4.orElse("param4"));
 
                            }
 
                            if(checkList.contains("PEOL_JRDZ")){
                                Optional<String> optionalParam5 = childVOS.stream().filter(item -> item.getItemCode().equals("PEOL_JRDZ")).map(ChildVO::getItemValue).findFirst();
                                printData.setParam5(optionalParam5.orElse("param5"));
 
                            }
 
                            if(checkList.contains("PEOL_DITMAX")){
                                Optional<String> optionalParam6 = childVOS.stream().filter(item -> item.getItemCode().equals("PEOL_DITMAX")).map(ChildVO::getItemValue).findFirst();
                                printData.setParam6(optionalParam6.orElse("param6"));
                            }
 
                            if(checkList.contains("PEOL_DIVMAX")){
                                Optional<String> optionalParam7 = childVOS.stream().filter(item -> item.getItemCode().equals("PEOL_DIVMAX")).map(ChildVO::getItemValue).findFirst();
                                printData.setParam7(optionalParam7.orElse("param7"));
                            }
                        }
                    }
 
                    //370-工位
                    List<DaTestDeviceInterface> list370 = daTestDeviceInterfaceService.list(new LambdaQueryWrapper<DaTestDeviceInterface>()
                        .eq(DaTestDeviceInterface::getProductNum, split[i])
                        .like(DaTestDeviceInterface::getStationCode, "370")
                    );
 
                    if(!list370.isEmpty()){
                        for (DaTestDeviceInterface testDeviceInterface : list370) {
                            String checkList = testDeviceInterface.getCheckList();
                            if(checkList.contains("PDCR_FDDCR") && checkList.contains("PDCR_CDDCR")){
                                List<ChildVO> childVOS = JSON.parseArray(checkList, ChildVO.class);
                                //充电
                                Optional<String> optionalPEOL_NZFNY = childVOS.stream().filter(item -> item.getItemCode().equals("PDCR_FDDCR")).map(ChildVO::getItemValue).findFirst();
                                //放电
                                Optional<String> optionalPDCR_CDDCR = childVOS.stream().filter(item -> item.getItemCode().equals("PDCR_CDDCR")).map(ChildVO::getItemValue).findFirst();
                                String StringNZFNY = optionalPEOL_NZFNY.orElse("StringNZFNY");
                                String StringCDDCR = optionalPDCR_CDDCR.orElse("StringCDDCR");
                                printData.setParam8("放电:"+StringNZFNY+"充电:"+StringCDDCR);
                            }
                        }
                    }
 
                    //410-工位
                    List<DaTestDeviceInterface> list410 = daTestDeviceInterfaceService.list(new LambdaQueryWrapper<DaTestDeviceInterface>()
                        .eq(DaTestDeviceInterface::getProductNum, split[i])
                        .like(DaTestDeviceInterface::getStationCode, "410")
                    );
 
                    if(!list410.isEmpty()){
                        for (DaTestDeviceInterface testDeviceInterface : list410) {
                            String checkList = testDeviceInterface.getCheckList();
                            List<ChildVO> childVOS = JSON.parseArray(checkList, ChildVO.class);
                            if(checkList.contains("PAT_PATR")){
                                Optional<String> optionalParam13 = childVOS.stream().filter(item -> item.getItemCode().equals("PAT_PATR")).map(ChildVO::getItemValue).findFirst();
                                printData.setParam13(optionalParam13.orElse("param13"));
                            }
                        }
                    }
 
                    List<DaParamCollection> pwdPw = daParamCollectionService.list(new LambdaQueryWrapper<DaParamCollection>()
                            .eq(DaParamCollection::getSfcCode, split[i])
                            .eq(DaParamCollection::getParamCode, "PWD_PW")
                    );
 
                    if(!pwdPw.isEmpty()){
                        printData.setParam14(pwdPw.get(0).getParamValue());
                    }else {
                        printData.setParam14(getRandomValue());
                    }
 
                    map.put("data"+(i+1), printData);
                }
            });
            cp1.join();
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
 
        map.put("reviewerDate", getReviewerDate());
        return AjaxResult.success(map);
    }
 
    public static void main(String[] args) {
        System.out.println(getPackIdPrint("0RSPB0011A2E3BEAC0000022"));
    }
 
    public static String getReviewerDate(){
        // 获取当前日期
        LocalDate today = LocalDate.now();
        // 定义日期格式(年.月.日)
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd");
        // 格式化当前日期
        return today.format(formatter);
    }
 
    /**
     * 随机生成一个在313正负9之间的值,并保留一位小数。
     *
     * @return 生成的随机值
     */
    public static String getRandomValue() {
        // 创建随机数生成器
        Random random = new Random();
 
        // 计算随机值范围
        double min = 313 - 9;
        double max = 313 + 9;
 
        // 生成随机值
        double randomValue = min + (max - min) * random.nextDouble();
 
        // 使用DecimalFormat保留一位小数
        DecimalFormat decimalFormat = new DecimalFormat("#.0");
        String formattedValue = decimalFormat.format(randomValue);
 
        // 将格式化后的字符串转换为double
        return formattedValue;
    }
 
    public static String getPackIdPrint(String productNum) {
        String part1 = productNum.substring(14, 17);
        // 截取21-24位
        String part2 = productNum.substring(21, 24);
        // 拼接成新的字符串
        return part1 + part2;
    }
}