wangrong
2022-07-08 7e9badac4f3df3650e72bd419f9cdaa485b054d6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { Inject, Provide } from '@midwayjs/decorator';
import { BaseService, ICoolCache, } from '@cool-midway/core';
import * as _ from 'lodash';
import { MysqlUtil } from '../../utils/mysqlutil';
import { DateUtil } from '../../utils/dateutil';
import { AxiosUtil } from '../../utils/axiosutil';
 
// 引入读写核心模块
 
 
/**
 * 系统用户
 */
@Provide()
export class RpcService extends BaseService {
 
    @Inject('cool:cache')
    coolCache: ICoolCache;
 
    @Inject()
    mysqlUtil: MysqlUtil;
 
    rpc_url: "http://192.168.1.4:5000/api";
 
    @Inject()
    dateUtil: DateUtil;
 
    @Inject()
    axios: AxiosUtil;
 
    /**
   * 远程调用设备,启动任务执行
   * @param query
   */
    async remoteCall(url, query) {
        if (url == null) {
            url = this.rpc_url;
        }
        let stattime = this.dateUtil.getCurretTimeStr()
        console.log('---------------------------------------------send msg  to device-----------------------------------------')
        console.log(query)
        // let res = await this.axios.httpPostBuffer(url, query)
        console.log('---------------------------------------receive the reply msg from device-----------------------------------')
        this.axios.httpPostBuffer(url, query).then(res => {
            console.log(res)
            const bidsql = `insert into t_config_interface_record (interface_direct,start_time,end_time,request_type,createTime,remark,status,params,result) 
                values ('${url}','${stattime}','${this.dateUtil.getCurretTimeStr()}','post',now(),'ok',200,'${JSON.stringify(query)}','${res}') `;
            this.nativeQuery(bidsql);
            return res
        }).catch((error) => {
            console.log(error)
            return error
        })
 
    }
 
 
    /**
     * 分页查询
     * @param query
     */
    async getData(query) {
        // const { keyWord, status, departmentIds = [] } = query;
        // const permsDepartmentArr = await this.baseSysPermsService.departmentIds(
        //   this.ctx.admin.userId
        // ); // 部门权限
        const bidsql = `select * from t_sys_business_config where id_='${query.bid}' limit 0,1`;
        const bid_obj_ = await this.nativeQuery(bidsql);
        console.log(bid_obj_)
        let sqlObj = this.mysqlUtil.create_sql(bid_obj_[0], query?.pageindex || null, query?.pagesize || null, query);
        if (sqlObj?.status == 0) {
            return sqlObj?.msg;
        }
        return this.nativeQuery(sqlObj?.sql, query);
    }
 
 
    /**
     * 分页查询
     * @param query
     */
    async getDataByNative(query) {
        // const { keyWord, status, departmentIds = [] } = query;
        // const permsDepartmentArr = await this.baseSysPermsService.departmentIds(
        //   this.ctx.admin.userId
        // ); // 部门权限
        const bidsql = `select * from t_sys_business_config where id_='${query.bid}' limit 0,1`;
        const bid_obj_ = await this.nativeQuery(bidsql);
        console.log(bid_obj_)
        let sqlObj = this.mysqlUtil.create_sql(bid_obj_[0], query?.pageindex || null, query?.pagesize || null, query);
        if (sqlObj?.status == 0) {
            return sqlObj?.msg;
        }
        return this.nativeQuery(sqlObj?.sql)
    }
 
    /**
     * 分页查询
     * @param query
     */
    async updateData(query) {
        // const { keyWord, status, departmentIds = [] } = query;
        // const permsDepartmentArr = await this.baseSysPermsService.departmentIds(
        //   this.ctx.admin.userId
        // ); // 部门权限
        const bidsql = `select * from t_sys_business_config where id_='${query.bid}' limit 0,1`;
        const bid_obj_ = await this.nativeQuery(bidsql);
        let sqlObj = this.mysqlUtil.create_sql(bid_obj_[0], query?.pageindex || null, query?.pagesize || null, query);
        if (sqlObj?.status == 0) {
            return sqlObj?.msg;
        }
        return this.sqlRenderPage(sqlObj?.sql, query);
    }
 
}