chenluhua1980
2026-01-08 3e91a18f75a75fbe8f646d73e4e68ba107b6750b
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
#ifndef PRODUCTION_LOG_MANAGER_H
#define PRODUCTION_LOG_MANAGER_H
 
#include <string>
#include <vector>
#include <mutex>
#include <unordered_map>
#include "Database.h"
 
// µ¥ÌõÉú²úÂÄÀú¼Ç¼
struct ProductionStep {
    int nStepId;                         // ²½ÖèID£¨Ö÷¼ü£©
    std::string strProductId;            // ²úÆ·ID
    std::string strBatchNo;              // Åú´ÎºÅ
    int nDeviceId;                       // µ±Ç°É豸ID
    std::string strDeviceName;           // µ±Ç°É豸Ãû³Æ
    int nPrevDeviceId;                   // ÉÏÒ»¸öÉ豸ID
    std::string strPrevDeviceName;       // ÉÏÒ»¸öÉ豸Ãû³Æ
    int nNextDeviceId;                   // ÏÂÒ»¸öÉ豸ID
    std::string strNextDeviceName;       // ÏÂÒ»¸öÉ豸Ãû³Æ
    std::string strOperator;             // ²Ù×÷Ô±
    std::string strStartTime;            // ¹¤Ðò¿ªÊ¼Ê±¼ä
    std::string strEndTime;              // ¹¤Ðò½áÊøÊ±¼ä
    int nYield;                          // ×ܲúÁ¿
    int nGoodCount;                      // Á¼Æ·Êý
    int nBadCount;                       // ²»Á¼Æ·Êý
    std::string strStatus;               // ×´Ì¬£¨Íê³É¡¢ÔÝÍ£¡¢Òì³£µÈ£©
    std::string strNote;                 // ±¸×¢ÐÅÏ¢
};
 
using ProductionStepMap = std::unordered_map<int, ProductionStep>;
 
class ProductionLogManager {
public:
    // »ñÈ¡µ¥ÀýʵÀý
    static ProductionLogManager& getInstance();
 
    // ³õʼ»¯Éú²úÂÄÀú±í
    bool initProductionTable();
 
    // ¹Ø±ÕÊý¾Ý¿âÁ¬½Ó
    void termProductionTable();
 
    // É¾³ýÉú²úÂÄÀú±í
    bool destroyProductionTable();
 
    // ²åÈëÄ£ÄâÊý¾Ý
    void insertMockData();
 
    // Ìí¼ÓÉú²úÂÄÀú¼Ç¼
    bool addProductionStep(int stepId, const ProductionStep& stepData);
 
    // ²éѯËùÓÐÉú²úÂÄÀú
    std::vector<ProductionStep> getAllSteps();
 
    // ¸ù¾Ý²úÆ·ID²éѯ
    std::vector<ProductionStep> getStepsByProductId(const std::string& productId);
 
    // ¸ù¾ÝÅú´ÎºÅ²éѯ
    std::vector<ProductionStep> getStepsByBatchNo(const std::string& batchNo);
 
    // ¸ù¾ÝÉ豸ID²éѯ
    std::vector<ProductionStep> getStepsByDeviceId(int nDeviceId);
 
    // ¸ù¾Ýʱ¼ä·¶Î§²éѯ
    std::vector<ProductionStep> getStepsByTimeRange(const std::string& startTime, const std::string& endTime);
 
    // ·ÖÒ³²éѯ + ¶àÌõ¼þ¹ýÂË
    std::vector<ProductionStep> getFilteredSteps(
        const std::string& productId,
        const std::string& batchNo,
        const std::string& deviceId,
        const std::string& operatorName,
        const std::string& status,
        const std::string& startTime,
        const std::string& endTime,
        int pageNumber,
        int pageSize);
 
    // »ñÈ¡Âú×ãÌõ¼þµÄ×ÜÊý
    int getTotalStepCount(
        const std::string& productId,
        const std::string& batchNo,
        const std::string& deviceId,
        const std::string& operatorName,
        const std::string& status,
        const std::string& startTime,
        const std::string& endTime);
 
    // ¸üÐÂijһÂÄÀúµÄ½áÊøÊ±¼ä
    bool updateStepEndTime(int nStepId, const std::string& newEndTime);
 
    // ±£´æµ½CSVÎļþ
    bool saveProductionFile(const std::string& filename);
 
    // ´ÓCSVÎļþµ¼Èë
    bool readProductionFile(const std::string& filename);
 
private:
    ProductionLogManager();
    ~ProductionLogManager();
 
    // ½ûÓÿ½±´¹¹ÔìºÍ¸³Öµ
    ProductionLogManager(const ProductionLogManager&) = delete;
    ProductionLogManager& operator=(const ProductionLogManager&) = delete;
 
private:
    BL::Database* m_pDB;
    ProductionStepMap m_mapStepCache;
    static std::mutex m_mutex;
};
 
#endif // PRODUCTION_LOG_MANAGER_H