eis/eqpm/eqpm_alg.h

109 lines
2.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
/**
* @file eqpm_alg.h
* @brief 设备点检计划时间计算
* @author your name (you@domain.com)
* @version 0.1
* @date 2023-12-22
*
* Copyright: Baosight Co. Ltd.
* DO NOT COPY/USE WITHOUT PERMISSION
*
*/
#include <eqpm/EqpmRecord.h>
#include <eqpm/utility.h>
#include <log4cplus/LOG.h>
#include <chrono>
#include <map>
// #include <mutex>///<弃用
#include <string>
using std::map;
using std::string;
/**
* @brief 设备点检 数据
*/
struct EqpRule {
int rule_type =
0; ///< 设备保养规则类型0-无1-重量(吨)2-长度(千米)3-时间(天)
double data = 0;
TimePoint repair_date; ///<上次检修时间
TimePoint repair_plan; ///<计划检修时间
};
class EqpmAlg {
public:
EqpmAlg();
~EqpmAlg();
private:
std::unique_ptr<LOG> logger_; ///< 本地logger
map<string, EqpRule> map_rules_; ///<设备-保养规则
double weight_slope_; ///<日产重量
double length_slope_; ///<日产长度
EqpRule rule_; ///<计算时更新的数据
TimePoint EqpmShm_stime_; ///<累计的开始时间从shm获取初始化后不变
TimePoint stime_; ///<更新shm累计数据的开始时间
TimePoint etime_; ///<更新shm累计数据的结束时间
EqpmShm::EqpmRecord eqpm_record_; ///<最新查询的日重量,日长度
TimePoint init_time_;
private:
// std::mutex local_mutext{}; ///<共享锁 弃用
public:
int init();
bool update_data();
bool select_eqpm_data(TimePoint stime);
/**
* @brief 检测所有设备管理规则
*
* @return true
* @return false
*/
void update_repair();
/**
* @brief 将时间转换为shm累计数据的map下标
* @param time My Param doc
* @return int
*/
int get_index(TimePoint time);
/**
* @brief 结束mq的json更新对应设备的检修计划时间
* @param mq mq消息的json
* @return int
*/
int update_repair(std::string mq);
/**
* @brief 更新计算的规则数据
* @param eqpid My Param doc
* @param rule_type My Param doc
* @param repair_date My Param doc
* @param interval My Param doc
* @return int
*/
int update_rule_data(std::string eqpid, int rule_type, TimePoint repair_date,
double interval);
/**
* @brief 更新 db2 T_EQP_REPAIR 表
* @param eqpid My Param doc
* @return int
*/
int update_db2(std::string eqpid);
/**
* @brief 获取最新的斜率(日生产长度,日生产重量)
* @param date My Param doc
*/
void update_slope(TimePoint date);
/**
* @brief 查询所有设备的点检规则
* @return int
*/
int select_repair();
/**
* @brief 查询指定设备的点检规则参数
* @param eqpid My Param doc
* @return int
*/
int select_eqp_data(std::string eqpid);
};