李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
package com.chinaztt.mes.quality.service.impl;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.chinaztt.ifs.api.feign.IfsFeignClient;
import com.chinaztt.inspect.api.feign.InspectFeignClient;
import com.chinaztt.mes.common.numgen.NumberGenerator;
import com.chinaztt.mes.quality.dto.ReportSampleDTO;
import com.chinaztt.mes.quality.dto.ReportSampleItemDTO;
import com.chinaztt.mes.quality.dto.ValidateIsCheckItemDTO;
import com.chinaztt.mes.quality.entity.*;
import com.chinaztt.mes.quality.mapper.*;
import com.chinaztt.mes.quality.service.ReportSampleItemService;
import com.chinaztt.mes.quality.service.ReportSampleService;
import com.chinaztt.mes.quality.state.result.constant.ResultStateStringValues;
import com.chinaztt.mes.quality.utils.AutoJudgmentUtils;
import com.chinaztt.mes.quality.utils.ReportUtils;
import com.chinaztt.mes.quality.utils.SelfJudgmentUtils;
import com.chinaztt.mes.warehouse.dto.ValidateWeighPackagingDTO;
import com.chinaztt.ztt.common.core.util.R;
import com.chinaztt.ztt.common.oss.OssProperties;
import com.chinaztt.ztt.common.oss.service.OssTemplate;
import com.chinaztt.ztt.common.security.util.SecurityUtils;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 检测汇报样品表
 *
 * @author cxf
 * @date 2021-04-06 14:29:44
 */
@Slf4j
@Service
@AllArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class ReportSampleServiceImpl extends ServiceImpl<ReportSampleMapper, ReportSample> implements ReportSampleService {
    private final OssProperties ossProperties;
    private final OssTemplate minioTemplate;
    private NumberGenerator<ReportSample> reportSampleNumberGenerator;
    private ReportSampleItemMapper reportSampleItemMapper;
    private ReportMapper reportMapper;
    private ReportUtils reportUtils;
    private SelfJudgmentUtils selfJudgmentUtils;
    private ApplyPartMapper applyPartMapper;
    private ReportSampleAttachmentMapper reportSampleAttachmentMapper;
    private TestStandardMapper testStandardMapper;
 
    private ReportSampleItemService reportSampleItemService;
 
    private InspectFeignClient inspectFeignClient;
 
 
    @Override
    public boolean saveBatchList(List<ReportSample> reportSampleList) {
        for (ReportSample reportSample : reportSampleList) {
            reportSample.setSampleNo(reportSampleNumberGenerator.generateNumberWithPrefix(ReportSample.DIGIT, ReportSample.PREFIX, ReportSample::getSampleNo));
            //这里增加一个检测标准id字段值的自动校正补充功能
            if(true || reportSample.getTestStandardId() == null){//改成直接矫正,applyPart表中的检测标准不准
                //根据产出系统编号、检测汇报id获取检测制造订单检测标准id
                Long moTestStandardId = baseMapper.getMoTestStandardId(reportSample.getReportId(),reportSample.getSystemNo());
                String moTestStandardNo = baseMapper.getMoTestStandardNoById(moTestStandardId);
                reportSample.setTestStandardId(moTestStandardId);
                reportSample.setTestStandardNo(moTestStandardNo);
            }
            baseMapper.insert(reportSample);
            if (StringUtils.isNotBlank(reportSample.getTestStandardNo())) {
                // 这边查的是制造订单的检测标准
                reportSampleItemMapper.insertMoSampleItemsById(reportSample);
                // 获取配置继承检测参数的检测汇报项
                List<ReportSampleItem> extendsItemList =
                        reportSampleItemMapper.selectList(Wrappers.<ReportSampleItem>lambdaQuery().eq(ReportSampleItem::getReportSampleId, reportSample.getId())
                                .isNotNull(ReportSampleItem::getExtendsTestStandardParamId));
                if (CollectionUtil.isEmpty(extendsItemList)) {
                    return true;
                }
                List<Long> technologyDocumentStandardParamIdList =
                        extendsItemList.stream().map(ReportSampleItem::getExtendsTestStandardParamId).collect(Collectors.toList());
                Set<String> systemNoSet = new HashSet<>();
                // 将自己系统编号加进来,有可能继承检测项是同一道工序下,因此根据投入找不到检测项
                systemNoSet.add(reportSample.getSystemNo());
                getInputSystemNoByOutReportSampleSystemNo(systemNoSet, Collections.singletonList(reportSample.getSystemNo()));
                // 获取继承检验参数项检测结果
                List<ReportSampleItem> parentItemList =
                        reportSampleItemMapper.getParentItemList(technologyDocumentStandardParamIdList, systemNoSet);
                Map<Long, List<ReportSampleItem>> extendsItemMap =
                        extendsItemList.stream().collect(Collectors.groupingBy(ReportSampleItem::getExtendsTestStandardParamId));
                Map<Long, ReportSampleItem> parentItemMap =
                        parentItemList.stream().collect(Collectors.toMap(ReportSampleItem::getTechnologyDocumentStandardParamId, item -> item, (k1, k2) -> k1));
                // 将继承的参数项结果值,复制到当前检测结果中
                for (Map.Entry<Long, List<ReportSampleItem>> entry : extendsItemMap.entrySet()) {
                    if (!parentItemMap.containsKey(entry.getKey())) {
                        entry.getValue().forEach(v->v.setExtendsResultFlag(Boolean.FALSE));
                    }else{
                        entry.getValue().forEach(v->{
                            v.setItemValue(parentItemMap.get(entry.getKey()).getItemValue());
                            v.setExtendsResultFlag(Boolean.TRUE);
                        });
                    }
                }
                reportSampleItemService.updateBatchById(extendsItemList);
            }
        }
        return true;
    }
 
    /**
     * 递归获取当前产出的投入
     * @param systemNo
     * @return
     */
    private void getInputSystemNoByOutReportSampleSystemNo(Set<String>systemNoSet, List<String> systemNos) {
        // 获取当前系统号产出的投入系统号
        List<String> inputSystemNos =
                reportSampleItemMapper.getInputSystemNoByOutReportSampleSystemNo(systemNos);
        if (CollectionUtil.isNotEmpty(inputSystemNos)) {
            getInputSystemNoByOutReportSampleSystemNo(systemNoSet, inputSystemNos);
            systemNoSet.addAll(inputSystemNos);
        }
    }
 
 
    @Override
    public List<ReportSampleDTO> getReportSampleList(QueryWrapper<ReportSampleDTO> gen) {
        return baseMapper.getReportSampleList(gen);
    }
 
    @Override
    public ReportSample updateSampleById(ReportSample reportSample) {
        // 如果检测标准编号被修改了,需要替换样品检测项目
        ReportSample oldReportSample = baseMapper.selectById(reportSample.getId());
        String oldTestStandardNo = oldReportSample.getTestStandardNo();
        String testStandardNo = reportSample.getTestStandardNo();
        if (StringUtils.isNotBlank(oldTestStandardNo) && StringUtils.isNotBlank(testStandardNo) && oldTestStandardNo.trim().equals(testStandardNo.trim())) {
        } else {
            // 先去查询检测标准编号对应的检测标准
            TestStandard newTestStandard = testStandardMapper.selectOne(Wrappers.<TestStandard>lambdaQuery().eq(TestStandard::getActive, true)
                    .eq(TestStandard::getStandardNo, testStandardNo));
            if (newTestStandard == null) {
                throw new RuntimeException("质量-检测标准中不存在输入的检测标准编号,请确认");
            }
            // 样品的检测标准编号被修改,就认为是质量-检测标准
            reportSample.setIsMoTestStandard(false);
            reportSample.setTestStandardId(newTestStandard.getId());
            reportSampleItemMapper.delete(Wrappers.<ReportSampleItem>query().lambda().eq(ReportSampleItem::getReportSampleId, reportSample.getId()));
            // 这边查的是检测标准
            reportSampleItemMapper.insertSampleItemsById(reportSample);
        }
        baseMapper.updateById(reportSample);
        return reportSample;
    }
 
    @Override
    public ReportSample updateSampleByIdV2(ReportSample reportSample) {
        // 如果检测标准编号被修改了,需要替换样品检测项目
        ReportSample oldReportSample = baseMapper.selectById(reportSample.getId());
        String oldTestStandardNo = oldReportSample.getTestStandardNo();
        String testStandardNo = reportSample.getTestStandardNo();
        if (StringUtils.isNotBlank(oldTestStandardNo) && StringUtils.isNotBlank(testStandardNo) && oldTestStandardNo.trim().equals(testStandardNo.trim())) {
        } else {
            // 判断是否是车间订单的检测标准
            if (reportSample.getIsMoTestStandard()) {
                reportSampleItemMapper.delete(Wrappers.<ReportSampleItem>query().lambda().eq(ReportSampleItem::getReportSampleId, reportSample.getId()));
                reportSampleItemMapper.insertMoSampleItemsById(reportSample);
            } else {
                // 先去查询检测标准编号对应的检测标准
                TestStandard newTestStandard = testStandardMapper.selectOne(Wrappers.<TestStandard>lambdaQuery().eq(TestStandard::getActive, true)
                        .eq(TestStandard::getStandardNo, testStandardNo));
                if (newTestStandard == null) {
                    throw new RuntimeException("质量-检测标准中不存在输入的检测标准编号,请确认");
                }
                // 样品的检测标准编号被修改,就认为是质量-检测标准
                reportSample.setTestStandardId(newTestStandard.getId());
                reportSampleItemMapper.delete(Wrappers.<ReportSampleItem>query().lambda().eq(ReportSampleItem::getReportSampleId, reportSample.getId()));
                // 这边查的是检测标准
                reportSampleItemMapper.insertSampleItemsById(reportSample);
            }
        }
        baseMapper.updateById(reportSample);
        return reportSample;
    }
 
 
    @Override
    public boolean deleteById(Long id) {
        // 删除检测标准数据
        reportSampleItemMapper.delete(Wrappers.<ReportSampleItem>query().lambda().eq(ReportSampleItem::getReportSampleId, id));
        reportSampleAttachmentMapper.delete(Wrappers.<ReportSampleAttachment>lambdaQuery().eq(ReportSampleAttachment::getSampleId, id));
        return SqlHelper.retBool(baseMapper.deleteById(id));
    }
 
    @Override
    public List<ReportSampleItemDTO> getSampleItemsById(ReportSampleDTO reportSampleDTO) {
        return reportSampleItemMapper.getSampleItemsById(reportSampleDTO);
    }
 
    @Override
    public List<ReportSampleItemDTO> getSampleSysItemsById(ReportSampleDTO reportSampleDTO) {
        return reportSampleItemMapper.getSampleSysItemsById(reportSampleDTO);
    }
 
    @Override
    public R uploadFile(MultipartFile file, Long sampleId) {
        String fileName = IdUtil.simpleUUID() + StrUtil.DOT + FileUtil.extName(file.getOriginalFilename());
        String url = String.format("/mes/reportSample/%s/%s", ossProperties.getBucketName(), fileName);
        try {
            minioTemplate.putObject(ossProperties.getBucketName(), fileName, file.getInputStream());
 
            ReportSampleAttachment attachment = new ReportSampleAttachment();
            attachment.setOriginal(file.getOriginalFilename());
            attachment.setPath(url);
            attachment.setFileName(fileName);
            attachment.setSampleId(sampleId);
            reportSampleAttachmentMapper.insert(attachment);
 
        } catch (Exception e) {
            log.error("上传失败", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return R.failed(e.getLocalizedMessage());
        }
        return R.ok();
    }
 
    @Override
    @SneakyThrows
    public R<Boolean> deleteFile(String fileName) {
        ReportSampleAttachment attachment = reportSampleAttachmentMapper.selectOne(Wrappers.<ReportSampleAttachment>lambdaQuery().eq(ReportSampleAttachment::getFileName, fileName));
        minioTemplate.removeObject(ossProperties.getBucketName(), attachment.getFileName());
        reportSampleAttachmentMapper.deleteById(attachment.getId());
        return R.ok();
    }
 
    @Override
    public List<ReportSampleAttachment> getReportSampleAttachment(Long id) {
        return reportSampleAttachmentMapper.selectList(Wrappers.<ReportSampleAttachment>lambdaQuery().eq(ReportSampleAttachment::getSampleId, id));
    }
 
    @Override
    public void getFile(String bucket, String fileName, HttpServletResponse response) {
        try (InputStream inputStream = minioTemplate.getObject(bucket, fileName)) {
            response.setContentType("application/octet-stream; charset=UTF-8");
            IoUtil.copy(inputStream, response.getOutputStream());
        } catch (Exception e) {
            log.error("文件读取异常: {}", e.getLocalizedMessage());
        }
    }
 
    @Override
    public ReportSampleDTO saveSelfSampleItem(ReportSampleDTO reportSampleDTO) {
        // 1.同步创建检测汇报
        Report report = new Report();
        report.setRemark(reportSampleDTO.getOutBatchNo());
        report.setReportType("04self");
        report.setReportPerson(SecurityUtils.getUser().getUsername());
        reportUtils.checkReportNo(report);
        reportMapper.insert(report);
        // 2.同步创建检测汇报零件
        ApplyPart applyPart = new ApplyPart();
        applyPart.setReportId(report.getId());
        applyPart.setLotBatchNo(reportSampleDTO.getOutBatchNo());
        applyPart.setSystemNo(reportSampleDTO.getSystemNo());
        applyPart.setPartId(reportSampleDTO.getPartId());
        applyPart.setPartNo(reportSampleDTO.getPartNo());
        applyPart.setPartDesc(reportSampleDTO.getPartName());
        applyPart.setIsErp(false);
        applyPart.setQtyArrived(reportSampleDTO.getQtyArrived().stripTrailingZeros().toPlainString());
        applyPart.setUnqualifiedArrived("0");
        applyPart.setMoTestStandardId(reportSampleDTO.getTestStandardId());
        applyPart.setTestStandardNo(reportSampleDTO.getTestStandardNo());
        applyPartMapper.insert(applyPart);
        // 修改检测结果状态为检测中
        reportSampleDTO.setCheckStatus(ResultStateStringValues.TESTING);
        reportSampleDTO.setIsUsed(false);
        // 3.同步创建样品
        reportSampleDTO.setReportId(report.getId());
        reportSampleDTO.setSampleNo(reportSampleNumberGenerator.generateNumberWithPrefix(ReportSample.DIGIT, ReportSample.PREFIX, ReportSample::getSampleNo));
        baseMapper.insert(reportSampleDTO);
        // 4.同步创建样品检测项
        List<ReportSampleItemDTO> reportSampleItemList = reportSampleDTO.getReportSampleItemList();
        if (CollectionUtil.isNotEmpty(reportSampleItemList)) {
            reportSampleItemList.stream().forEach(item -> {
                item.setReportSampleId(reportSampleDTO.getId());
                reportSampleItemMapper.insert(item);
            });
        }
        return reportSampleDTO;
    }
 
    @Override
    public ReportSampleDTO getReportSampleForSelf(ReportSampleDTO reportSampleDTO) {
        reportSampleDTO = baseMapper.getReportSampleForSelf(reportSampleDTO);
        if (reportSampleDTO != null) {
            reportSampleDTO.setReportSampleItemList(reportSampleItemMapper.getSampleItemsById(reportSampleDTO));
        }
        return reportSampleDTO;
    }
 
    @Override
    public ReportSampleDTO autoMoveStock(ReportSampleDTO reportSampleDTO) {
        reportSampleDTO.setReportSampleItemList(reportSampleItemMapper.getSampleItemsById(reportSampleDTO));
        reportSampleDTO.setIsSelfQualified(reportSampleDTO.getIsQualified());
        reportSampleDTO.setCheckStatus(ResultStateStringValues.TESTED);
        reportSampleDTO.setIsUsed(reportSampleDTO.getIsQualified());
        selfJudgmentUtils.autoMoveStock(reportSampleDTO);
        return reportSampleDTO;
    }
 
 
    @Override
    public R judgmentSampleCheck(ReportSampleDTO reportSampleDTO) {
        // 1.判断各个检测项是否合格
        List<ReportSampleItemDTO> reportSampleItemList = reportSampleItemMapper.getSampleItemsById(reportSampleDTO);
        List<ReportSampleItemDTO> isCheckSampleItemList = reportSampleItemList.stream().filter(ReportSampleItem::getIsCheck).filter(a->StringUtils.isBlank(a.getItemValue())).collect(Collectors.toList());
        if(CollectionUtils.isNotEmpty(isCheckSampleItemList)){
            List<String> isCheckItemNameList = isCheckSampleItemList.stream().map(ReportSampleItem::getItemName).collect(Collectors.toList());
            return R.ok(ValidateIsCheckItemDTO.builder().success(Boolean.FALSE).message("以下抽检项未填,是否继续"+isCheckItemNameList.toString()).build());
        }else{
            return R.ok(ValidateIsCheckItemDTO.builder().success(Boolean.TRUE).build());
        }
    }
 
    @Override
    public ReportSampleDTO autoJudgmentSample(ReportSampleDTO reportSampleDTO) {
        // 1.判断各个检测项是否合格
        List<ReportSampleItemDTO> reportSampleItemList = reportSampleItemMapper.getSampleItemsById(reportSampleDTO);
        List<ReportSampleItemDTO> isCheckSampleItemList = reportSampleItemList.stream().filter(ReportSampleItem::getIsCheck).filter(a->StringUtils.isBlank(a.getItemValue())).collect(Collectors.toList());
        if(CollectionUtils.isNotEmpty(isCheckSampleItemList)){
            reportSampleItemList.removeAll(isCheckSampleItemList);
        }
        if (CollectionUtil.isNotEmpty(reportSampleItemList)) {
            // 1.1判断值公式
            reportSampleItemList.stream().forEach(reportSampleItem -> {
                // 检测项值和值公式都为空,才去帮忙计算
                if (StringUtils.isNotBlank(reportSampleItem.getValueFormula())) {
                    String expression = AutoJudgmentUtils.replace(reportSampleItem.getValueFormula(), reportSampleItemList);
                    try {
                        reportSampleItem.setItemValue(AutoJudgmentUtils.computeResult(expression));
                    } catch (Exception e) {
                        throw new RuntimeException("明细行检测项编号 = 【" + reportSampleItem.getItemCode() + "】 -> 表达式 = 【" + expression + "】异常");
                        //throw new RuntimeException("检测项编号为" + reportSampleItem.getItemCode() + "公式不正确,请检查后重试");
                    }
                    if (StringUtils.isNotBlank(reportSampleItem.getParameterFormat())) {
                        if (NumberUtils.isCreatable(reportSampleItem.getItemValue())) {
 
                            DecimalFormat decimalFormat = new DecimalFormat(reportSampleItem.getParameterFormat().replace("#", "#0"));
                            reportSampleItem.setItemValue(decimalFormat.format(new BigDecimal(reportSampleItem.getItemValue())));
                        }
                    }
                }
            });
            // 1.2判断合格公式
            reportSampleItemList.stream().forEach(reportSampleItem -> {
                if (StringUtils.isNotBlank(reportSampleItem.getJudgeFormula())) {
                    // 根据编号替换值
                    String expression = AutoJudgmentUtils.replace(reportSampleItem.getJudgeFormula(), reportSampleItemList);
                    // 再判断
                    reportSampleItem.setIsQualified(AutoJudgmentUtils.computeExpression(expression,"->检测项编号=" + reportSampleItem.getItemCode()));
                }
                reportSampleItemMapper.updateById(reportSampleItem);
            });
 
        }
        // 2.判断整体是否合格
        String sampleExpression = baseMapper.selectSampleExpressionById(reportSampleDTO.getId());
        if (StringUtils.isNotBlank(sampleExpression)) {
            sampleExpression = AutoJudgmentUtils.replace(sampleExpression, reportSampleItemList);
            reportSampleDTO.setIsQualified(AutoJudgmentUtils.computeExpression(sampleExpression,"->业务类别=" + "判断整体是否合格"));
            baseMapper.updateById(reportSampleDTO);
        }
        return reportSampleDTO;
    }
 
    @Override
    public ReportSampleItemDTO autoJudgmentSampleSingle(ReportSampleItemDTO reportSampleItemDTO){
        if(StringUtils.isNotBlank(reportSampleItemDTO.getItemValue()) && StringUtils.isNotBlank(reportSampleItemDTO.getJudgeFormula()) && StringUtils.isBlank(reportSampleItemDTO.getValueFormula())){
            //如果检测值及判断公式存在,且值计算公式不存在,则继续执行(如果检测值本身就是自动计算出来的,则不在本次功能范围内)
            List<ReportSampleItemDTO> reportSampleItemList = new ArrayList<>();
            reportSampleItemList.add(reportSampleItemDTO);
            // 根据编号替换值
            String expression = AutoJudgmentUtils.replace(reportSampleItemDTO.getJudgeFormula(), reportSampleItemList);
            // 再判断
            try{
                reportSampleItemDTO.setIsQualified(AutoJudgmentUtils.computeExpression(expression,"->检测项编号=" + reportSampleItemDTO.getItemCode()));
                //reportSampleItemMapper.updateById(reportSampleItemDTO);//不用保存结果
            }catch(Exception e){
                //单条实时自动判定中屏蔽异常
            }
        }
        if(StringUtils.isNotBlank(reportSampleItemDTO.getItemValue()) && StringUtils.isBlank(reportSampleItemDTO.getJudgeFormula())){
            reportSampleItemDTO.setIsQualified(true);//如果实测值不为空,且计算公式为空,则默认结果为合格
        }
        return reportSampleItemDTO;
    }
 
 
    @Override
    public List<ReportSampleItemDTO> dataAcquisition(Long id,String sn) {
        List<ReportSampleItem> reportSampleItemList = reportSampleItemMapper.selectList(Wrappers.<ReportSampleItem>lambdaQuery()
                .eq(ReportSampleItem::getReportSampleId,id)
                .eq(ReportSampleItem::getParamType,"采集项"));
        Map<String,String> map = new HashMap<>();
        //map.put("pdf_name","18012606007");
        map.put("pdf_name",sn);
/*        map.put("1","20℃导体电阻—红色主线芯1#");
        map.put("2","20℃导体电阻—白色主线芯1#");
        map.put("pdf_name",sn);*/
        for(ReportSampleItem reportSampleItem:reportSampleItemList){
            map.put(reportSampleItem.getSort()+"",reportSampleItem.getItemName().replace("-","—"));
        }
        R res = inspectFeignClient.getInfo(map);
        if(res==null || res.getCode()==1){
            throw new RuntimeException("请求inspect失败");
        }
        HashMap<String, String> hashMap = JSONObject.parseObject(JSONObject.toJSONString(res.getData()), HashMap.class);
        Set<String> keySet = hashMap.keySet();
        List<ReportSampleItemDTO> reportSampleItemInputList = null;
        if(CollectionUtil.isNotEmpty(keySet)) {
            List<Long> keyList = keySet.stream().map(Long::valueOf).collect(Collectors.toList());
            reportSampleItemInputList = reportSampleItemMapper.getSampleSysItemsBySortAndId(id, keyList);
        }
 
        List<ReportSampleItemDTO> returnList = new ArrayList<>();
        Iterator <Map.Entry< String, String >> iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry< String, String > entry = iterator.next();
            Long key = Long.valueOf(entry.getKey());
 
            for (ReportSampleItemDTO reportSampleItemDTO:reportSampleItemInputList) {
                if(key.equals(reportSampleItemDTO.getSort())){
                    reportSampleItemDTO.setItemValue(entry.getValue());
                    //判断是否合格
                    if(StringUtils.isNotBlank(reportSampleItemDTO.getItemValue()) && StringUtils.isNotBlank(reportSampleItemDTO.getJudgeFormula()) && StringUtils.isBlank(reportSampleItemDTO.getValueFormula())){
                        //如果检测值及判断公式存在,且值计算公式不存在,则继续执行(如果检测值本身就是自动计算出来的,则不在本次功能范围内)
                        List<ReportSampleItemDTO> reportSampleItemDTOList = new ArrayList<>();
                        reportSampleItemDTOList.add(reportSampleItemDTO);
                        // 根据编号替换值
                        String expression = AutoJudgmentUtils.replace(reportSampleItemDTO.getJudgeFormula(), reportSampleItemDTOList);
                        // 再判断
                        try{
                            reportSampleItemDTO.setIsQualified(AutoJudgmentUtils.computeExpression(expression,"->检测项编号=" + reportSampleItemDTO.getItemCode()));
                            //reportSampleItemMapper.updateById(reportSampleItemDTO);//不用保存结果
                        }catch(Exception e){
                            //单条实时自动判定中屏蔽异常
                        }
                    }
                    if(StringUtils.isNotBlank(reportSampleItemDTO.getItemValue()) && StringUtils.isBlank(reportSampleItemDTO.getJudgeFormula())){
                        reportSampleItemDTO.setIsQualified(true);//如果实测值不为空,且计算公式为空,则默认结果为合格
                    }
                    returnList.add(reportSampleItemDTO);
                }
            }
        }
        return returnList;
    }
 
    @Override
    public boolean insert(ReportSample reportSample) {
        reportSample.setSampleNo(reportSampleNumberGenerator.generateNumberWithPrefix(ReportSample.DIGIT, ReportSample.PREFIX, ReportSample::getSampleNo));
        return this.save(reportSample);
    }
 
    @Override
    public List<String> getTestStandardNoBySnOrPartId(String partBatchNo, Long partId, String testType) {
        return this.baseMapper.getTestStandardNoBySnOrPartId(partBatchNo, partId, testType);
    }
 
 
}