const { DataTypes, Model, Op } = require('../../azeroth').sequelize;
const sequelize = require("../class/db").sequelize;
const Table = {};
// 获取所有stock 得到节点状态
Table.getStockRowColumn = async (shelveId) => {
    let data = await sequelize.query(`SELECT * FROM stock  WHERE shelve_id = ${shelveId}`);
    data = data ? data[0] : [];
    let rowCol = {};
    data.forEach(item=>{
        rowCol[`${item.row}-${item.column}`] = item;
    })
    return rowCol;
}

Table.getStockRowColumnNesInfo = async (shelveId, row, column) => {
    let data = await sequelize.query(`SELECT * FROM stock_log WHERE shelve_id = ${shelveId} AND row = ${row} AND \`column\` = ${column} order by id DESC limit 0,1;`);
    try {
        console.log(data);
        data = data[0][0];
        data.content = data.content.replace(/'/g, '"');
        data = {
            ...data,
            ...JSON.parse(data.content)
        };
    }catch (e) {
        console.error(e);
        data = false;
    }
    return data;
}

module.exports = Table;
