Lius
2025-04-15 6a5cb9b11c95fbde3e56a55ea5379b633651d2ad
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
package org.jeecg.modules.mdcJc.service.impl;
 
import org.jeecg.common.util.dynamic.db.DynamicDBUtil;
import org.jeecg.modules.mdcJc.dto.MesRcJobreport;
import org.jeecg.modules.mdcJc.service.MesRcJobreportService;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * @Author: Lius
 * @CreateTime: 2025-04-14
 * @Description:
 */
@Service
public class MesRcJobreportServiceImpl implements MesRcJobreportService {
 
 
    @Override
    public List<MesRcJobreport> findPartProcessInfo(String date, List<String> equipmentIdList) {
        List<MesRcJobreport> result = new ArrayList<>();
 
        // 空参数检查
        if (equipmentIdList == null || equipmentIdList.isEmpty()) {
            return result;
        }
 
        // 构建动态IN子句
        String inClause = String.join(",", Collections.nCopies(equipmentIdList.size(), "?"));
 
        // 构建安全SQL(注意WHERE子句的空格)
        String sql = "SELECT the_data AS thedate, " +
                "device_number AS deviceNumber, " +
                "okuqty, qty " +
                "FROM hegelv " +
                "WHERE the_data = ? " +  // 使用参数化查询
                "AND device_number IN (" + inClause + ")";
 
        // 准备参数(日期在前,设备ID在后)
        List<String> params = new ArrayList<>();
        params.add(date);
        params.addAll(equipmentIdList);
 
        System.out.println("SQL参数: date=" + date + ", equipmentIds=" + equipmentIdList);
 
        List<Map<String, Object>> mapList = DynamicDBUtil.findList("basicDB", sql, params.toArray());
 
        if (mapList == null || mapList.isEmpty()) {
            return result;
        }
 
        result = mapList.stream().map(map -> {
            MesRcJobreport mesRcJobreport = new MesRcJobreport();
            mesRcJobreport.setBillDate(map.get("thedate").toString());
            mesRcJobreport.setDeviceNumber(map.get("deviceNumber").toString());
            mesRcJobreport.setOkuqty(new BigDecimal(map.get("okuqty").toString()));
            mesRcJobreport.setQty(new BigDecimal(map.get("qty").toString()));
            return mesRcJobreport;
        }).collect(Collectors.toList());
 
        return result;
    }
}