基本完成前后端代码
This commit is contained in:
131
EdgeManager.php
131
EdgeManager.php
@@ -24,56 +24,74 @@ $worker -> onWorkerStart = function(Worker $worker) {
|
|||||||
$worker -> onMessage = function(TcpConnection $connection, Request $request) {
|
$worker -> onMessage = function(TcpConnection $connection, Request $request) {
|
||||||
global $options, $dbconn;
|
global $options, $dbconn;
|
||||||
|
|
||||||
$post = $request -> post();
|
// 仅供Axios使用
|
||||||
if (isset($post['action']) and str_contains($post['action'], 'node')) {
|
if ($request->header('content-type') === 'application/json') {
|
||||||
$action = $post['action'];
|
$post = $request -> post();
|
||||||
unset($post['action']);
|
if (isset($post['action']) and str_contains($post['action'], 'node')) {
|
||||||
$enode_configure = new ENodeConfigure($dbconn, $post = $post);
|
$action = $post['action'];
|
||||||
$res = $enode_configure -> $action();
|
unset($post['action']);
|
||||||
if ($res === true)
|
$enode_configure = new ENodeConfigure($dbconn, post: $post);
|
||||||
$connection -> send(json_encode(array(
|
$res = $enode_configure -> $action();
|
||||||
'code' => 0,
|
if ($res === true)
|
||||||
'msg' => 'Success'
|
$connection -> send(json_encode(array(
|
||||||
)));
|
'code' => 0,
|
||||||
else if ($res === "REPLICATED")
|
'msg' => 'Success'
|
||||||
$connection -> send(json_encode(array(
|
)));
|
||||||
'code' => 1,
|
else if ($res === "REPLICATED")
|
||||||
'msg' => '节点编码不可重复!'
|
$connection -> send(json_encode(array(
|
||||||
)));
|
'code' => 1,
|
||||||
else if ($res === false) {
|
'msg' => '节点编码不可重复!'
|
||||||
$connection -> send(json_encode(array(
|
)));
|
||||||
'code' => 1,
|
else if ($res === false) {
|
||||||
'msg' => '服务器内部逻辑错误,请联系开发者!'
|
$connection -> send(json_encode(array(
|
||||||
)));
|
'code' => 1,
|
||||||
|
'msg' => '服务器内部逻辑错误,请联系开发者!'
|
||||||
|
)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (isset($post['action']) and str_contains($post['action'], 'data')) {
|
} else {
|
||||||
$action = $post['action'];
|
$post = json_decode($request -> rawBody());
|
||||||
unset($post['action']);
|
if (json_last_error() !== JSON_ERROR_NONE)
|
||||||
$data_capture = new EDataCapture($dbconn, $post = $post);
|
dump('fuck');
|
||||||
$res = $data_capture -> $action();
|
|
||||||
if ($res === true) {
|
|
||||||
$connection -> send(json_encode(array(
|
$connection -> send(json_encode(array(
|
||||||
'action' => 'result_set_data',
|
'action' => '错得太离谱以至于我也不知道这是什么动作',
|
||||||
'errcode' => 0,
|
'errcode' => 4001,
|
||||||
'errmsg' => ''
|
'errmsg' => 'POST的内容不是JSON,也并非可按照JSON解析的字符串!'
|
||||||
)));
|
)));
|
||||||
|
dump($post);
|
||||||
|
if ($post -> action === 'set_node_data') {
|
||||||
|
$data_capture = new EDataCapture($dbconn, post: $post);
|
||||||
|
$res = $data_capture -> set_node_data();
|
||||||
|
if ($res === true) {
|
||||||
|
$connection -> send(json_encode(array(
|
||||||
|
'action' => 'result_set_data',
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => ''
|
||||||
|
)));
|
||||||
|
} else {
|
||||||
|
$connection -> send(json_encode(array(
|
||||||
|
'action' => 'result_set_data',
|
||||||
|
'errcode' => 4002,
|
||||||
|
'errmsg' => 'ROLLBACKed: Bad data received (structure and/or values)'
|
||||||
|
)));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$connection -> send(json_encode(array(
|
$connection -> send(json_encode(array(
|
||||||
'action' => 'result_set_data',
|
'action' => $post -> action,
|
||||||
'errcode' => 4002,
|
'errcode' => 4002,
|
||||||
'errmsg' => 'ROLLBACKed: Bad data received (structure and/or values)'
|
'errmsg' => '请检查传入的字段值!'
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$get = $request -> get();
|
$get = $request -> get();
|
||||||
if (isset($get['query']) and $get['query'] == 'nodes') {
|
if (isset($get['query']) and $get['query'] == 'nodes') {
|
||||||
$enode_configure = new ENodeConfigure($dbconn, $get = $get);
|
$enode_configure = new ENodeConfigure($dbconn, get: $get);
|
||||||
$nodes = $enode_configure -> get_nodes();
|
$nodes = $enode_configure -> get_nodes();
|
||||||
if (is_null($nodes))
|
if (is_null($nodes))
|
||||||
$connection -> send(json_encode(array(
|
$connection -> send(json_encode(array(
|
||||||
'code' => 1,
|
'code' => 1,
|
||||||
'msg' => 'no node data'
|
'msg' => 'no node data yet'
|
||||||
)));
|
)));
|
||||||
else
|
else
|
||||||
$connection -> send(json_encode(array(
|
$connection -> send(json_encode(array(
|
||||||
@@ -81,6 +99,51 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
|
|||||||
'data' => $nodes
|
'data' => $nodes
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($get['query']) and $get['query'] == 'working_subclasses') {
|
||||||
|
$enode_configure = new ENodeConfigure($dbconn, get: $get);
|
||||||
|
$working_subclasses = $enode_configure -> get_working_subclasses();
|
||||||
|
if (is_null($working_subclasses))
|
||||||
|
$connection -> send(json_encode(array(
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '还没有工序单元!'
|
||||||
|
)));
|
||||||
|
else
|
||||||
|
$connection -> send(json_encode(array(
|
||||||
|
'code' => 0,
|
||||||
|
'data' => $working_subclasses
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($get['query']) and $get['query'] == 'codes') {
|
||||||
|
$enode_configure = new ENodeConfigure($dbconn, get: $get);
|
||||||
|
$codes = $enode_configure -> get_codes_by_working_subclasses();
|
||||||
|
if (is_null($codes))
|
||||||
|
$connection -> send(json_encode(array(
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '服务器内部逻辑错误,请联系开发者!'
|
||||||
|
)));
|
||||||
|
else
|
||||||
|
$connection -> send(json_encode(array(
|
||||||
|
'code' => 0,
|
||||||
|
'data' => $codes
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($get['query']) and $get['query'] == 'node_data') {
|
||||||
|
$data_capture = new EDataCapture($dbconn, get: $get);
|
||||||
|
$data = $data_capture -> get_node_data();
|
||||||
|
if (is_null($data))
|
||||||
|
$connection -> send(json_encode(array(
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => '服务器内部逻辑错误,请联系开发者!'
|
||||||
|
)));
|
||||||
|
else
|
||||||
|
$connection -> send(json_encode(array(
|
||||||
|
'code' => 0,
|
||||||
|
'data' => $data
|
||||||
|
)));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Worker::runAll();
|
Worker::runAll();
|
||||||
|
|||||||
@@ -10,23 +10,50 @@ class EDataCapture {
|
|||||||
protected $get = NULL
|
protected $get = NULL
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
private function set_data() {
|
function set_node_data() {
|
||||||
foreach (array_chunk($this -> post -> param, 6507524, true) as $chunk) {
|
foreach (array_chunk($this -> post -> param -> data, 6507524, true) as $chunk) {
|
||||||
$sql_cmd[] = [sprintf(
|
$sql_head = sprintf(
|
||||||
"INSERT INTO hf_mes_scada_data_capture_node_data_%s",
|
"INSERT INTO hf_mes_scada_data_capture_node_data_%s (code, v_%s, device_code, batch)
|
||||||
$chunk[0] -> working_subclass
|
VALUES",
|
||||||
)];
|
$this -> post -> param -> working_subclass,
|
||||||
|
$this -> post -> param -> type
|
||||||
|
);
|
||||||
foreach ($chunk as $row) {
|
foreach ($chunk as $row) {
|
||||||
$sql_cmd[] = sprintf(
|
$sql_values[] = sprintf(
|
||||||
"(code, v_%s, device_code, batch) VALUES('%s', %s, %s, %s)",
|
"('%s', %s, %s, %s)",
|
||||||
$row -> type,
|
|
||||||
$row -> code,
|
$row -> code,
|
||||||
$row -> value,
|
$row -> value,
|
||||||
$row -> device_code ?? NULL,
|
$row -> device_code ?? 'DEFAULT',
|
||||||
$row -> batch ?? NULL
|
$row -> batch ?? 'DEFAULT'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return pg_query($this -> dbconn, implode(' ', $sql_cmd));
|
return pg_query($this -> dbconn, $sql_head . implode(',', $sql_values));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_node_data() {
|
||||||
|
$name_type = pg_fetch_assoc(pg_query($this -> dbconn, sprintf(
|
||||||
|
"SELECT name, type
|
||||||
|
FROM hf_mes_scada_data_capture_node_configure
|
||||||
|
WHERE working_subclass = '%s'
|
||||||
|
AND code = '%s'",
|
||||||
|
$this -> get['working_subclass'],
|
||||||
|
$this -> get['code']
|
||||||
|
)));
|
||||||
|
|
||||||
|
$res = pg_fetch_all(pg_query($this -> dbconn, sprintf(
|
||||||
|
"SELECT id, v_%s AS value, device_code, batch, capture_time
|
||||||
|
FROM hf_mes_scada_data_capture_node_data_%s
|
||||||
|
WHERE code = '%s'",
|
||||||
|
$name_type['type'],
|
||||||
|
$this -> get['working_subclass'],
|
||||||
|
$this -> get['code']
|
||||||
|
)));
|
||||||
|
|
||||||
|
array_walk($res, function(&$v, $k) use ($name_type) {
|
||||||
|
$v['name'] = $name_type['name'];
|
||||||
|
});
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,4 +105,19 @@ class ENodeConfigure {
|
|||||||
$res = pg_query($this -> dbconn, "SELECT * FROM hf_mes_scada_data_capture_node_configure");
|
$res = pg_query($this -> dbconn, "SELECT * FROM hf_mes_scada_data_capture_node_configure");
|
||||||
return pg_fetch_all($res);
|
return pg_fetch_all($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_working_subclasses() {
|
||||||
|
$res = pg_query($this -> dbconn, "SELECT DISTINCT ON (working_subclass) working_subclass FROM hf_mes_scada_data_capture_node_configure");
|
||||||
|
return pg_fetch_all_columns($res, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_codes_by_working_subclasses() {
|
||||||
|
$res = pg_query($this -> dbconn, sprintf(
|
||||||
|
"SELECT code
|
||||||
|
FROM hf_mes_scada_data_capture_node_configure
|
||||||
|
WHERE working_subclass = '%s'",
|
||||||
|
$this -> get['working_subclass']
|
||||||
|
));
|
||||||
|
return pg_fetch_all_columns($res, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,5 +16,17 @@ export default ({ service, request, serviceForMock, requestForMock, mock, faker,
|
|||||||
|
|
||||||
QUERY_NODE () {
|
QUERY_NODE () {
|
||||||
return request({ url: '?query=nodes' })
|
return request({ url: '?query=nodes' })
|
||||||
|
},
|
||||||
|
|
||||||
|
QUERY_WORKING_SUBCLASSES () {
|
||||||
|
return request({ url: '?query=working_subclasses' })
|
||||||
|
},
|
||||||
|
|
||||||
|
QUERY_CODES (workingSubclass) {
|
||||||
|
return request({ url: '?query=codes&working_subclass=' + workingSubclass })
|
||||||
|
},
|
||||||
|
|
||||||
|
QUERY_NODE_DATA (workingSubclass, code) {
|
||||||
|
return request({ url: '?query=node_data&working_subclass=' + workingSubclass + '&code=' + code })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import store from '@/store/index'
|
|||||||
import ElementUI from 'element-ui'
|
import ElementUI from 'element-ui'
|
||||||
import 'element-ui/lib/theme-chalk/index.css'
|
import 'element-ui/lib/theme-chalk/index.css'
|
||||||
import D2Crud from '@d2-projects/d2-crud'
|
import D2Crud from '@d2-projects/d2-crud'
|
||||||
|
// Cheetah-Grid
|
||||||
|
import vueCheetahGrid from 'vue-cheetah-grid'
|
||||||
|
|
||||||
// 菜单和路由设置
|
// 菜单和路由设置
|
||||||
import router from './router'
|
import router from './router'
|
||||||
@@ -20,6 +22,7 @@ import { frameInRoutes } from '@/router/routes'
|
|||||||
Vue.use(d2Admin)
|
Vue.use(d2Admin)
|
||||||
Vue.use(ElementUI)
|
Vue.use(ElementUI)
|
||||||
Vue.use(D2Crud)
|
Vue.use(D2Crud)
|
||||||
|
Vue.use(vueCheetahGrid)
|
||||||
|
|
||||||
new Vue({
|
new Vue({
|
||||||
router,
|
router,
|
||||||
|
|||||||
@@ -105,20 +105,20 @@ export default {
|
|||||||
name: 'el-select',
|
name: 'el-select',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
value: 'text',
|
value: 'string',
|
||||||
label: '字符串'
|
label: 'string (字符串)'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'int',
|
value: 'int',
|
||||||
label: '整数'
|
label: 'int (整数)'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'float8',
|
value: 'float',
|
||||||
label: '浮点数'
|
label: 'float (浮点数)'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'bool',
|
value: 'bool',
|
||||||
label: '逻辑值'
|
label: 'bool (逻辑值)'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
span: 12
|
span: 12
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
<template>
|
||||||
|
<d2-container>
|
||||||
|
<el-form :inline="true" :model="formInline" class="demo-form-inline">
|
||||||
|
<el-form-item label="工序单元">
|
||||||
|
<el-select
|
||||||
|
v-model="formInline.workingSubclass"
|
||||||
|
filterable
|
||||||
|
clearable
|
||||||
|
placeholder="工序单元"
|
||||||
|
@change="getCodesByWorkingSubclass(formInline.workingSubclass)">
|
||||||
|
<el-option
|
||||||
|
v-for="workingSubclass in workingSubclasses"
|
||||||
|
:key="workingSubclass"
|
||||||
|
:value="workingSubclass">
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="节点编码">
|
||||||
|
<el-select
|
||||||
|
v-model="formInline.code"
|
||||||
|
filterable
|
||||||
|
clearable
|
||||||
|
placeholder="节点编码">
|
||||||
|
<el-option
|
||||||
|
v-for="code in codes"
|
||||||
|
:key="code"
|
||||||
|
:value="code">
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" @click="getData">查询</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<c-grid
|
||||||
|
:data="data">
|
||||||
|
<c-grid-column
|
||||||
|
field="id"
|
||||||
|
width="5%">
|
||||||
|
序号
|
||||||
|
</c-grid-column>
|
||||||
|
<c-grid-column
|
||||||
|
field="name"
|
||||||
|
width="16.25%">
|
||||||
|
节点名称
|
||||||
|
</c-grid-column>
|
||||||
|
<c-grid-column
|
||||||
|
field="value"
|
||||||
|
width="16.25%"
|
||||||
|
sort="true">
|
||||||
|
值
|
||||||
|
</c-grid-column>
|
||||||
|
<c-grid-column
|
||||||
|
field="device_code"
|
||||||
|
width="16.25%"
|
||||||
|
sort="true">
|
||||||
|
设备
|
||||||
|
</c-grid-column>
|
||||||
|
<c-grid-column
|
||||||
|
field="batch"
|
||||||
|
width="16.25%"
|
||||||
|
sort="true">
|
||||||
|
批次
|
||||||
|
</c-grid-column>
|
||||||
|
<c-grid-column
|
||||||
|
field="capture_time"
|
||||||
|
width="30%"
|
||||||
|
sort="true">
|
||||||
|
采集时间
|
||||||
|
</c-grid-column>
|
||||||
|
</c-grid>
|
||||||
|
</d2-container>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
formInline: {
|
||||||
|
workingSubclass: '',
|
||||||
|
code: ''
|
||||||
|
},
|
||||||
|
workingSubclasses: [],
|
||||||
|
codes: [],
|
||||||
|
data: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async getworkingSubclasses () {
|
||||||
|
try {
|
||||||
|
this.workingSubclasses = await this.$api.QUERY_WORKING_SUBCLASSES()
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async getCodesByWorkingSubclass (workingSubclass) {
|
||||||
|
try {
|
||||||
|
this.codes = await this.$api.QUERY_CODES(workingSubclass)
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async getData () {
|
||||||
|
try {
|
||||||
|
this.data = await this.$api.QUERY_NODE_DATA(this.formInline.workingSubclass, this.formInline.code)
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted () {
|
||||||
|
this.getworkingSubclasses()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user