Update Value Report.
This commit is contained in:
@@ -57,27 +57,27 @@ class HistoryValueController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getHistoryValueReportPivot(req, res) {
|
static async getHistoryValueReportPivot(req, res) {
|
||||||
try {
|
try {
|
||||||
const queryParams = req.query;
|
const queryParams = req.query;
|
||||||
|
|
||||||
const results = await HistoryValue.getHistoryValueReportPivot(queryParams);
|
const results = await HistoryValue.getHistoryValueReportPivot(queryParams);
|
||||||
const response = await setResponsePaging(queryParams, results, 'Data found');
|
const response = await setResponsePaging(queryParams, results, 'Data found');
|
||||||
|
|
||||||
if (results.column) {
|
if (results.column) {
|
||||||
response.columns = results.column;
|
response.columns = results.column;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.status(response.statusCode).json(response);
|
||||||
|
} catch (error) {
|
||||||
|
const statusCode = error.statusCode || 500;
|
||||||
|
res.status(statusCode).json({
|
||||||
|
success: false,
|
||||||
|
statusCode,
|
||||||
|
message: error.message || 'Internal server error'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(response.statusCode).json(response);
|
|
||||||
} catch (error) {
|
|
||||||
const statusCode = error.statusCode || 500;
|
|
||||||
res.status(statusCode).json({
|
|
||||||
success: false,
|
|
||||||
statusCode,
|
|
||||||
message: error.message || 'Internal server error'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static async getHistoryValueTrendingPivot(req, res) {
|
static async getHistoryValueTrendingPivot(req, res) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -385,10 +385,7 @@ const getHistoryValueReportPivotDb = async (tableName, searchParams = {}) => {
|
|||||||
OPTION (MAXRECURSION 0);
|
OPTION (MAXRECURSION 0);
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const request = pool.request();
|
const result = await pool.query(queryText, [from, to, interval]);
|
||||||
request.timeout = 60000; // 60 detik
|
|
||||||
|
|
||||||
const result = await request.query(queryText, [from, to, interval]);
|
|
||||||
|
|
||||||
if (result.recordsets && result.recordsets.length >= 2) {
|
if (result.recordsets && result.recordsets.length >= 2) {
|
||||||
console.log('Sample averaging data:');
|
console.log('Sample averaging data:');
|
||||||
@@ -551,7 +548,7 @@ const getHistoryValueTrendingPivotDb = async (tableName, searchParams = {}) => {
|
|||||||
const tagList = Object.keys(rows[0]).filter(k => k !== timeKey);
|
const tagList = Object.keys(rows[0]).filter(k => k !== timeKey);
|
||||||
|
|
||||||
const nivoData = tagList.map(tag => ({
|
const nivoData = tagList.map(tag => ({
|
||||||
name: tag,
|
id: tag,
|
||||||
data: rows.map(row => ({
|
data: rows.map(row => ({
|
||||||
x: row[timeKey],
|
x: row[timeKey],
|
||||||
y: row[tag] !== null ? Number(row[tag]) : null
|
y: row[tag] !== null ? Number(row[tag]) : null
|
||||||
|
|||||||
@@ -64,41 +64,41 @@ class HistoryValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async getHistoryValueReportPivot(param) {
|
static async getHistoryValueReportPivot(param) {
|
||||||
try {
|
try {
|
||||||
if (!param.plant_sub_section_id) {
|
if (!param.plant_sub_section_id) {
|
||||||
throw new ErrorHandler(400, 'plant_sub_section_id is required');
|
throw new ErrorHandler(400, 'plant_sub_section_id is required');
|
||||||
|
}
|
||||||
|
if (!param.from || !param.to) {
|
||||||
|
throw new ErrorHandler(400, 'from and to date parameters are required');
|
||||||
|
}
|
||||||
|
|
||||||
|
const plantSubSection = await getSubSectionByIdDb(param.plant_sub_section_id);
|
||||||
|
|
||||||
|
if (!plantSubSection || plantSubSection.length < 1) {
|
||||||
|
throw new ErrorHandler(404, 'Plant sub section not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
const tableNameValue = plantSubSection[0]?.table_name_value;
|
||||||
|
|
||||||
|
if (!tableNameValue) {
|
||||||
|
throw new ErrorHandler(404, 'Table name not configured for this sub section');
|
||||||
|
}
|
||||||
|
|
||||||
|
const tableExist = await checkTableNamedDb(tableNameValue);
|
||||||
|
|
||||||
|
if (!tableExist || tableExist.length < 1) {
|
||||||
|
throw new ErrorHandler(404, `Value table '${tableNameValue}' not found`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const results = await getHistoryValueReportPivotDb(tableExist[0].TABLE_NAME, param);
|
||||||
|
return results;
|
||||||
|
} catch (error) {
|
||||||
|
throw new ErrorHandler(
|
||||||
|
error.statusCode || 500,
|
||||||
|
error.message || 'Error fetching history value report pivot'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (!param.from || !param.to) {
|
|
||||||
throw new ErrorHandler(400, 'from and to date parameters are required');
|
|
||||||
}
|
|
||||||
|
|
||||||
const plantSubSection = await getSubSectionByIdDb(param.plant_sub_section_id);
|
|
||||||
|
|
||||||
if (!plantSubSection || plantSubSection.length < 1) {
|
|
||||||
throw new ErrorHandler(404, 'Plant sub section not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
const tableNameValue = plantSubSection[0]?.table_name_value;
|
|
||||||
|
|
||||||
if (!tableNameValue) {
|
|
||||||
throw new ErrorHandler(404, 'Table name not configured for this sub section');
|
|
||||||
}
|
|
||||||
|
|
||||||
const tableExist = await checkTableNamedDb(tableNameValue);
|
|
||||||
|
|
||||||
if (!tableExist || tableExist.length < 1) {
|
|
||||||
throw new ErrorHandler(404, `Value table '${tableNameValue}' not found`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const results = await getHistoryValueReportPivotDb(tableExist[0].TABLE_NAME, param);
|
|
||||||
return results;
|
|
||||||
} catch (error) {
|
|
||||||
throw new ErrorHandler(
|
|
||||||
error.statusCode || 500,
|
|
||||||
error.message || 'Error fetching history value report pivot'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static async getHistoryValueTrendingPivot(param) {
|
static async getHistoryValueTrendingPivot(param) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user