123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 'use strict';
- const Controller = require('egg').Controller;
- class DeviceController extends Controller {
-
- //获取服务器状态
- async getServerState() {
- await this.train("/train/device/state", "get");
- }
- async shutdownServer() {
- await this.train("/train/device/shutdownServer");
- }
- async startServer() {
- let {ctx } = this;
- await this.train("/train/device/startServer");
- }
- async restartServer() {
- let {ctx } = this;
- await this.train("/train/device/restartServer");
- }
- async mysql() {
- let {ctx } = this;
- let ret = await this.app.mysql.query("select id from admin_user where id=4");
- ctx.adminOK(ret,"ok");
- }
- async train( uri, get ) {
- let {ctx , app} = this;
- let cfg = app.config.serverhosts;
- let url = cfg.train + uri;
- try {
- console.log("====>", url);
- let ret = await ctx.curl(url, {headers:{
- "Content-Type":"application/json"
- },
- method:get?get:'post',
- dataType:"json"
- });
- console.log( ret.data );
- if( ret.data && ret.data.code == 200 ) {
- ctx.adminOK( ret.data.result, ret.data.message );
- return;
- }
- ctx.adminFail(ret.data.message);
- } catch (error) {
- console.log("curl train server error")
- ctx.adminFail("未启动");
- }
- }
- }
- module.exports = DeviceController;
|