diff --git a/class/db.js b/class/db.js index 5be7e64..c7fc1dc 100644 --- a/class/db.js +++ b/class/db.js @@ -1,7 +1,8 @@ //这个是应用初始化sequelize的文件 const AZL = require('../../azeroth'); +const default_config = require('../default_config'); const { Sequelize } = AZL.sequelize; -class ParameterDB { +class SQL { constructor() { const db_conf = default_config.mysql_config; this.sequelize = new Sequelize(db_conf.database, db_conf.user, db_conf.password, { @@ -11,10 +12,10 @@ class ParameterDB { }); } static get_instance() { - if (!ParameterDB.instance) { - ParameterDB.instance = new ParameterDB(); + if (!SQL.instance) { + SQL.instance = new SQL(); } - return ParameterDB.instance; + return SQL.instance; } } -module.exports = ParameterDB; \ No newline at end of file +module.exports = SQL.get_instance(); diff --git a/default_config.js b/default_config.js index cc1e631..14618fa 100644 --- a/default_config.js +++ b/default_config.js @@ -6,11 +6,11 @@ module.exports = { public_path, upload_path, port: 8117, - // "mysql_config": { - // "host": "127.0.0.1", - // "user": "root", - // "password": "root", //Leaper@123 - // "database": "parameter" - // }, + "mysql_config": { + "host": "192.168.0.108",// "127.0.0.1", + "user": "root", + "password": "Leaper@123", + "database": "lipo_duoji" + }, } diff --git a/job/styles.js b/job/antv_styles.js similarity index 100% rename from job/styles.js rename to job/antv_styles.js diff --git a/job/stock.js b/job/stock.js new file mode 100644 index 0000000..0b607d0 --- /dev/null +++ b/job/stock.js @@ -0,0 +1,43 @@ +const Stock = require('../model/stock'); +exports.getStockRowColumn = async (req, res, next)=>{ + const { + leftShelveId, + rightShelveId + } = req.query; + let left = await Stock.getStockRowColumn(leftShelveId); + let right; + if(leftShelveId === rightShelveId) { + right = left; + } else { + right = await Stock.getStockRowColumn(rightShelveId); + } + res.send({ + code: 200, + data: { + left, + right + } + }); + res.end(); +} + +// 如果是人工复合错误,那么就需要取stock_log里的关联的最新的信息。 +exports.getStockRowColumnNesInfo = async (req, res, next) => { + const { shelveId, row, column } = req.query; + const data = await Stock.getStockRowColumnNesInfo(shelveId, row, column); + if(!data) { + res.send({ + code: 200, + message: '暂无数据', + data: {} + }); + }else { + res.send({ + code: 200, + data: data + }); + } + res.end(); +} + + diff --git a/model/stock.js b/model/stock.js new file mode 100644 index 0000000..3114fd1 --- /dev/null +++ b/model/stock.js @@ -0,0 +1,32 @@ +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; diff --git a/public/default_css.json b/public/default_css.json index 84502b3..e78aa9a 100644 --- a/public/default_css.json +++ b/public/default_css.json @@ -1 +1 @@ -{"theme":{"primary-color":"rgba(184, 68, 13, 1)"},"title":{"text":"ROBO垛机视觉系统","style":{"color":"rgba(255, 255, 255, 1)","background-color":"rgba(163, 60, 12, 1)","font-size":"24px"}},"menu":{"default":{"color":"rgba(230, 224, 224, 1)","background-color":"rgba(163, 60, 12, 1)"},"select":{"color":"rgba(255, 255, 255, 1)","background-color":"rgba(184, 68, 13, 1)"}}} \ No newline at end of file +{"theme":{"primary-color":"rgba(184, 68, 13, 1)"},"title":{"text":"ROBO垛机视觉系统","style":{"color":"rgba(255, 255, 255, 1)","background-color":"rgba(163, 60, 12, 1)","font-size":"24px"}},"menu":{"default":{"color":"rgba(230, 224, 224, 1)","background-color":"rgba(163, 60, 12, 1)"},"select":{"color":"rgba(255, 255, 255, 1)","background-color":"rgba(184, 68, 13, 1)"}}} diff --git a/routes/styles.js b/routes/antv_styles.js similarity index 77% rename from routes/styles.js rename to routes/antv_styles.js index 76aa7b0..0f3e742 100644 --- a/routes/styles.js +++ b/routes/antv_styles.js @@ -1,6 +1,6 @@ const express = require('express'); const router = express.Router(); -const stylesAPI = require('../job/styles'); +const stylesAPI = require('../job/antv_styles'); console.log(stylesAPI); // 更新css router.post('/update', stylesAPI.update); diff --git a/routes/index.js b/routes/index.js index f3eb2ad..6eab496 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,10 +1,12 @@ const express = require('express'); const router = express.Router(); -const styleRouter = require('./styles'); +const styleRouter = require('./antv_styles'); +const stockRouter = require('./stock'); /* GET home page. */ router.get('/', function(req, res, next) { res.render('index', { title: 'logistics-node' }); }); -router.use('/styles', styleRouter); +router.use('/antv-styles', styleRouter); +router.use('/stock', stockRouter); module.exports = router; diff --git a/routes/stock.js b/routes/stock.js new file mode 100644 index 0000000..324f3e3 --- /dev/null +++ b/routes/stock.js @@ -0,0 +1,6 @@ +const express = require('express'); +const router = express.Router(); +const stockAPI = require('../job/stock'); +router.get('/getStockRowColumn', stockAPI.getStockRowColumn); +router.get('/getStockRowColumnNesInfo', stockAPI.getStockRowColumnNesInfo); +module.exports = router; diff --git a/test/insert.js b/test/insert.js new file mode 100644 index 0000000..47cf2dc --- /dev/null +++ b/test/insert.js @@ -0,0 +1,38 @@ + +const { DataTypes, Model, Op } = require('../../azeroth').sequelize; +const sequelize = require("../class/db").sequelize; +const Table = {}; +Table.insert = async (shelveId, row, column) => { + let data = await sequelize.query( + "INSERT INTO stock_log(user_id, `username`, shelve_id, `row`, `column`, `order_num`, `content`, `preoperation_pic`, `overoperation_pic`, `create_time`) VALUES ( 1, 'wong', '"+ shelveId +"', "+ row +", "+column+", 'SRM015_60246', '{\"old_status\":0,\"new_status\":2,\"new_category\":\"dianshi\",\"new_count\":22}', '2021/03/19/15/3ff16124-be04-4e1a-bbd8-37c9e4cf0878.jpg', '2021/03/19/15/e0fcca5b-66df-4b11-b165-803998125e27.jpg', '2021-03-19 21:39:28');"); +} + +Table.insertSocket = async (shelveId, row, column, status) => { + let data = await sequelize.query(`INSERT INTO \`lipo_duoji\`.\`stock\`(\`order_num\`, \`category\`, \`count\`, \`shelve_id\`, \`row\`, \`column\`, \`status\`, \`preoperation_pic\`, \`overoperation_pic\`, \`export_time\`) VALUES ('SRM015_60246', '女装-上装-外套', 500, '${shelveId}', ${row}, ${column}, '${status}', '2021/03/19/15/3ff16124-be04-4e1a-bbd8-37c9e4cf0878.jpg', '2021/03/19/15/e0fcca5b-66df-4b11-b165-803998125e27.jpg', '2021-10-18 11:27:32'); +`) +} +// Table.insert(1,1,1) + +// for(let shelveId = 1; shelveId <=10; shelveId++) { +// if([8].indexOf(shelveId) > -1) { +// for(let row = 70; row <=100; row++) { +// for(let column = 1; column <=100; column++) { +// Table.insert(shelveId, row, column) +// } +// } +// } +// } + +// Table.insertSocket(1, 1, 15, 1) +for(let shelveId = 1; shelveId <=10; shelveId++) { + if([1,2,4,6,7,8].indexOf(shelveId) > -1) { + for(let i=0; i<100;i++) { + let row = parseInt(Math.random() * 100); + let column = parseInt(Math.random() * 100); + let status = Math.random() > 0.2 ? 2 : 1; + Table.insertSocket(shelveId, row, column, status) + } + } +} + +