king
2021-10-14 44fa8b4f4b4c4ae93570b14b9835b2d61552cb95
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
import React, {Component} from 'react'
import { is, fromJS } from 'immutable'
import { Modal, notification, Timeline, Icon, Button, Typography } from 'antd'
import moment from 'moment'
 
import Api from '@/api'
import options from '@/store/options.js'
import Utils from '@/utils/utils.js'
import './index.scss'
 
const { Paragraph } = Typography
 
class DataSource extends Component {
  state = {
    visible: false,
    versions: null,
    version: null,
    error: false
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
  
  verup = () => {
    let _param = {
      func: 's_get_sversions_sys',
    }
 
    Api.getSystemConfig(_param).then(result => {
      if (!result.status) {
        notification.warning({
          top: 92,
          message: result.message,
          duration: 5
        })
        return
      }
 
      let edition_int = ''
      if (options.sysType === 'SSO') {
        edition_int = result.edition_int_sso
      } else if (options.sysType === 'local' && window.GLOB.systemType !== 'production') {
        edition_int = result.edition_int_local
      } else {
        if (result.edition_int_sso < result.edition_int_local) {
          edition_int = result.edition_int_sso
        } else {
          edition_int = result.edition_int_local
        }
      }
      if (edition_int === '') {
        notification.warning({
          top: 92,
          message: '未查询到更新版本信息!',
          duration: 5
        })
        return
      }
 
      let sysType = options.sysType.toLowerCase()
 
      if (window.GLOB.systemType === 'production' || sysType !== 'local') {
        sysType = ''
      }
 
      let param = {
        func: 's_get_sversions_sys_epc',
        edition_int: edition_int,
        sys_type: sysType
      }
  
      Api.getCloudConfig(param).then(res => {
        if (!res.status) {
          notification.warning({
            top: 92,
            message: res.message,
            duration: 5
          })
          return
        } else if (!res.data || res.data.length === 0) {
          notification.success({
            top: 92,
            message: '已经是最新的版本了。',
            duration: 2
          })
          return
        }
 
        res.data = res.data.map((item, i) => {
          item.status = i === 0 ? 'loading' : 'waiting'
          item.index = i
          return item
        })
        this.setState({versions: res.data, version: res.data[0], visible: true}, () => {
          this.queryScript()
        })
      })
    })
  }
 
  queryScript = () => {
    const { version } = this.state
 
    let _param = {
      func: 's_get_sVersiondetail_Up',
      VersionName: version.id,
      BID: ''
    }
 
    Api.getCloudConfig(_param).then(res => {
      delete res.message
      delete res.status
 
      res.func = 's_sVersion_Local_add'
      res.VersionName = version.id
 
      Api.getLocalConfig(res).then(result => {
        if (!result.status) {
          notification.warning({
            top: 92,
            message: result.message,
            duration: 5
          })
          this.execError()
          return
        } else if (!result.vid) {
          notification.warning({
            top: 92,
            message: '当前应用需要升级系统接口,请联系管理员!',
            duration: 5
          })
          this.execError()
          return
        }
 
        this.setState({version: {...version, BID: result.vid}})
 
        let sql = `select ID,KeyWords,Remark,TypeName,Sort,SrcID from (select * from sVersionDetail_Local where BID='${result.vid}' and deleted=0 and status=0 ) tmptable order by Sort`
 
        let param = {
          func: 'sPC_Get_TableData',
          obj_name: 'data',
          arr_field: 'ID,KeyWords,Remark,TypeName,Sort,SrcID',
          BID: '',
        }
 
        param.LText = Utils.formatOptions(sql)
        param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
        param.secretkey = Utils.encrypt(param.LText, param.timestamp)
        param.DateCount = ''
 
        Api.getLocalConfig(param).then(response => {
          if (!response.status) {
            notification.warning({
              top: 92,
              message: response.message,
              duration: 5
            })
            this.execError()
            return
          } else if (!response.data || response.data.length === 0) {
            this.next()
          } else {
            this.loopRequest(response.data)
          }
        }, () => { this.execError() })
      }, () => { this.execError() })
    }, () => { this.execError() })
  }
 
  loopRequest = (scripts) => {
    const { version } = this.state
 
    if (!version) return
 
    let script = scripts.shift()
    let param = {
      func: 's_get_sVersionDetail_Ltext',
      SrcID: script.SrcID,
      ID: script.ID,
      BID: version.BID
    }
 
    let ssoParam = {
      func: 's_sDataDictb_TBBack',
      SrcID: script.SrcID,
      ID: script.ID,
      BID: version.BID
    }
 
    let localParam = {
      func: 's_sDataDictb_TBBack',
      SrcID: script.SrcID,
      ID: script.ID,
      BID: version.BID
    }
 
    Api.getCloudConfig(param).then(res => {
      delete res.message
      delete res.status
 
      localParam = {...localParam, ...res}
 
      if (res.LTextOut) {
        localParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
        localParam.secretkey = Utils.encrypt(localParam.LTextOut, localParam.timestamp)
        localParam.open_key = Utils.encryptOpenKey(localParam.secretkey, localParam.timestamp)
      }
 
      if (res.UpType === 'SSO' && window.GLOB.mainSystemApi) {
        ssoParam = {...ssoParam, ...res}
        delete ssoParam.UpType
 
        ssoParam.rduri = window.GLOB.mainSystemApi
 
        if (res.LTextOut) {
          ssoParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
          ssoParam.secretkey = Utils.encrypt(ssoParam.LTextOut, ssoParam.timestamp)
          ssoParam.open_key = Utils.encryptOpenKey(ssoParam.secretkey, ssoParam.timestamp)
        }
      } else {
        delete localParam.UpType
        ssoParam = null
      }
 
      this.execLocal(localParam, ssoParam, scripts)
    }, () => {
      this.execError()
    })
  }
 
  execSso = (ssoParam, scripts) => {
    Api.getLocalConfig(ssoParam).then(res => {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        this.execWarning()
        this.setState({}, () => {
          if (scripts.length === 0) {
            this.next()
          } else {
            this.loopRequest(scripts)
          }
        })
      } else {
        if (scripts.length === 0) {
          this.next()
        } else {
          this.loopRequest(scripts)
        }
      }
    }, () => {
      this.execError()
    })
  }
 
  execLocal = (localParam, ssoParam, scripts) => {
    Api.getLocalConfig(localParam).then(res => {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        this.execWarning()
        this.setState({}, () => {
          if (scripts.length === 0) {
            this.next()
          } else {
            this.loopRequest(scripts)
          }
        })
      } else if (ssoParam) {
        this.execSso(ssoParam, scripts)
      } else {
        if (scripts.length === 0) {
          this.next()
        } else {
          this.loopRequest(scripts)
        }
      }
    }, () => {
      this.execError()
    })
  }
 
  execWarning = () => {
    const { version } = this.state
 
    if (!version) return
 
    this.setState({version: {...version, warning: true}})
  }
 
  execError = () => {
    const { version } = this.state
 
    if (!version) return
 
    this.setState({error: true, versions: this.state.versions.map(item => {
      if (version.id === item.id) {
        item.status = 'error'
      }
      return item
    })})
  }
 
  next = () => {
    const { version, versions } = this.state
 
    if (!version || !versions) return
 
    let sql = `declare @Vid nvarchar(50) set @Vid='' select top 1 @Vid=id from sVersionDetail_Local where BID='${version.BID}' and Status =10 if @Vid='' begin delete sVersion_Local where id ='${version.BID}'  delete sVersionDetail_Local where bid ='${version.BID}' end else begin  update sVersion_Local set deleted=1,Modifydate=getdate(),ModifyUserID=@UserID@ where id ='${version.BID}' end`
 
    let param = {
      func: 'sPC_TableData_InUpDe',
      exec_type: 'y',
      ID: version.BID
    }
 
    param.LText = Utils.formatOptions(sql)
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt('', param.timestamp)
 
    Api.getLocalConfig(param).then(response => {
      if (!response.status) {
        notification.warning({
          top: 92,
          message: response.message,
          duration: 5
        })
        return
      }
    })
 
    let nextver = versions[version.index + 1]
    let _versions = versions.map(item => {
      if (version.id === item.id) {
        item.status = 'done'
        item.warning = version.warning === true
      }
      return item
    })
 
    if (nextver) {
      this.setState({
        version: nextver,
        versions: _versions
      }, () => {
        this.queryScript()
      })
    } else {
      this.setState({
        version: null,
        versions: _versions
      })
      notification.success({
        top: 92,
        message: '升级已完成。',
        duration: 3
      })
    }
  }
 
  stop = () => {
    this.setState({
      version: null,
      versions: null,
      visible: false,
      error: false
    })
  }
 
  skip = () => {
    const { version, versions } = this.state
 
    let nextver = versions[version.index + 1]
 
    this.setState({
      version: nextver,
      error: false
    }, () => {
      this.queryScript()
    })
  }
 
  reset = () => {
    const { version } = this.state
 
    this.setState({versions: this.state.versions.map(item => {
      if (version.id === item.id) {
        item.status = 'loading'
      }
      return item
    }), error: false}, () => {
      this.queryScript()
    })
  }
 
  render () {
    const { visible, versions, error, version } = this.state
 
    return (
      <>
        <div style={{padding: '5px 25px'}} onClick={this.verup}>应用升级</div>
        <Modal
          wrapClassName="version-up-modal"
          title="应用升级"
          visible={visible}
          width={800}
          closable={false}
          maskClosable={false}
          footer={[
            error && version && versions && versions.length > (version.index + 1) ? <Button key="skip" className="mk-orange" onClick={this.skip}>跳过</Button> : null,
            error && version ? <Button key="reset" type="primary" onClick={this.reset}>重新执行</Button> : null,
            <Button key="close" onClick={this.stop}>关闭</Button>,
          ]}
          destroyOnClose
        >
          <Timeline>
            {versions && versions.map(item => {
              let icon = <Icon type="clock-circle-o" style={{ fontSize: '16px' }} />
              if (item.status === 'loading') {
                icon = <Icon type="sync" spin style={{ fontSize: '16px' }} />
              } else if (item.status === 'done') {
                if (item.warning) {
                  icon = <Icon type="warning" style={{ fontSize: '16px', color: 'orange' }}/>
                } else {
                  icon = <Icon type="check-circle" style={{ fontSize: '16px', color: '#52c41a' }} />
                }
              }
              return (
                <Timeline.Item key={item.id} dot={icon}>{item.ProgramName}(<Paragraph style={{display: 'inline-block', marginBottom: '0px'}} copyable>{item.id}</Paragraph>)</Timeline.Item>
              )
            })}
          </Timeline>
        </Modal>
      </>
    )
  }
}
 
export default DataSource