#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
|