king
2022-10-17 e8edfdadb561cd83bf6e1c3e00d55b8cc2aee6d5
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Button, notification } from 'antd'
import moment from 'moment'
 
import Utils from '@/utils/utils.js'
import Api from '@/api'
// import './index.scss'
 
class CreateFunc extends Component {
  static propTypes = {
    trigger: PropTypes.func
  }
 
  state = {
    loading: false,
  }
 
  exec = (innerFunc, newLText, DelText) => {
    this.setState({
      loading: true
    })
 
    this.createExec(innerFunc, newLText, DelText)
  }
  
  createExec = (innerFunc, newLText, DelText) => {
    let isExist = false // 存储过程是否存在
    let cloudText = ''  // 云端存储结果
    let localfunc = ''  // 本地存储过程
 
    new Promise(resolve => {
      // 获取云端存储过程信息
      Api.getSystemConfig({
        func: 'sPC_Get_TVP',
        TVPName: innerFunc
      }).then(result => {
        if (!result.status) {
          notification.warning({
            top: 92,
            message: result.message,
            duration: 5
          })
          resolve(false)
        } else {
          cloudText = result.TVPText
          resolve(true)
        }
      })
    }).then(res => {
      if (!res) return res
      // 获取本地存储过程信息
 
      let _param = {
        func: 's_get_userproc',
        LText: innerFunc
      }
      _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)
      
      return Api.genericInterface(_param)
    }).then(res => {
      if (!res) return res
 
      // 处理本地结果
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        return false
      } else {
        isExist = true
        localfunc = Utils.formatOptions(res.Ltext)
        return true
      }
    }).then(res => {
      if (!res) return res
 
      // 根据本地及远端结果判断执行动作
      if ((newLText === localfunc) && (newLText === cloudText)) {
        return 'drop'
      } else if (!localfunc || (cloudText === localfunc)) {
        // 本地存储过程不存在,或云端和本地存储过程一致时,将新的存储过程更新至云端
        return Api.getSystemConfig({
          func: 'sPC_TVP_InUp',
          TVPName: innerFunc,
          TVPText: newLText,
          TypeName: 'P'
        })
      } else {
        return new Promise(resolve => {
          Api.getSystemConfig({ // 添加现有的本地存储过程至云端
            func: 'sPC_TVP_InUp',
            TVPName: innerFunc,
            TVPText: localfunc,
            TypeName: 'P'
          }).then(result => {
            if (result.status) {
              Api.getSystemConfig({
                func: 'sPC_TVP_InUp', // 添加最新的存储过程至云端
                TVPName: innerFunc,
                TVPText: newLText,
                TypeName: 'P'
              }).then(response => {
                resolve(response)
              })
            } else {
              resolve(result)
            }
          })
        })
      }
    }).then(res => {
      if (!res || res === 'drop') return res
 
      // 处理云端更新结果
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        return false
      } else if (isExist) {
        return 'drop'
      } else {
        return 'create'
      }
    }).then(res => {
      if (!res || res === 'create') return res
 
      // 删除存储过程
      let _param = {
        func: 'sPC_TableData_InUpDe',
        LText: DelText,
        TypeCharOne: 'proc' // 删除或创建存储过程标志
      }
 
      _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)
      _param.open_key = Utils.encryptOpenKey(_param.secretkey, _param.timestamp)
 
      return Api.genericInterface(_param)
    }).then(res => {
      if (!res || res === 'create') return res
      
      // 删除结果处理
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        return false
      } else {
        return true
      }
    }).then(res => {
      if (!res) return res
      
      // 新建存储过程
      let _param = {
        func: 'sPC_TableData_InUpDe',
        LText: newLText,
        TypeCharOne: 'proc'
      }
      _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)
      _param.open_key = Utils.encryptOpenKey(_param.secretkey, _param.timestamp)
 
      return Api.genericInterface(_param)
    }).then(res => {
      this.setState({
        loading: false
      })
 
      if (!res) return res
      
      // 处理新建结果
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
      } else {
        notification.success({
          top: 92,
          message: '创建成功',
          duration: 2
        })
      }
    })
  }
 
  render() {
 
    return (
      <Button
        className="mk-btn mk-purple"
        onClick={this.props.trigger}
        loading={this.state.loading}
      >
        创建存储过程
      </Button>
    )
  }
}
 
export default CreateFunc