king
2024-06-28 c8804ceb1fe2dea76f9949c5ea04423876ee2c81
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
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 FuncUtils from './utils.js'
import Api from '@/api'
// import './index.scss'
 
class CreateFunc extends Component {
  static propTypes = {
    getMsg: PropTypes.func
  }
 
  state = {
    loading: false
  }
 
  trigger = () => {
    this.props.getMsg().then(config => {
      let newLText = ''
      let func = ''
 
      if (config.$type === 'table') {
        func = config.func
        newLText = FuncUtils.getTableFunc(config)
      } else if (config.$type === 'excelIn') {
        func = config.func
        newLText = FuncUtils.getexcelInfunc(config)
      } else if (config.$type === 'btn') {
        func = config.func
        newLText = FuncUtils.getfunc(config)
      }
      
      if (!newLText || !func) return
 
      this.createExec(func, newLText)
    })
  }
 
  createExec = (func, newLText) => {
    let dropfunc = `IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID('${func}') AND type in (N'P', N'PC'))  mdrpk PROCEDURE ${func}`
    // 删除存储过程
    let droparam = {
      func: 'sPC_TableData_InUpDe',
      LText: Utils.formatOptions(dropfunc, window.GLOB.execType || 'y'),
      exec_type: window.GLOB.execType || 'y',
      TypeCharOne: 'proc' // 删除或创建存储过程标志
    }
 
    droparam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    droparam.secretkey = Utils.encrypt('', droparam.timestamp)
    droparam.open_key = Utils.encryptOpenKey(droparam.secretkey, droparam.timestamp)
 
    // 新建存储过程
    let _param = {
      func: 'sPC_TableData_InUpDe',
      LText: Utils.formatOptions(newLText, window.GLOB.execType || 'y'),
      exec_type: window.GLOB.execType || 'y',
      TypeCharOne: 'proc'
    }
    _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    _param.secretkey = Utils.encrypt('', _param.timestamp)
    _param.open_key = Utils.encryptOpenKey(_param.secretkey, _param.timestamp)
 
    let saveParam = {
      func: 's_proc_save',
      sql_script: window.btoa(window.encodeURIComponent(newLText)),
      proc_name: func,
      save_type: 'auto'
    }
 
    this.setState({
      loading: true
    })
 
    Api.genericInterface(droparam).then(res => {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        this.setState({
          loading: false
        })
        return
      }
      Api.genericInterface(_param).then(result => {
        if (!result.status) {
          notification.warning({
            top: 92,
            message: result.message,
            duration: 5
          })
          this.setState({
            loading: false
          })
          return
        }
 
        Api.genericInterface(saveParam).then(response => {
          this.setState({loading: false})
          if (!response.status) {
            notification.warning({
              top: 92,
              message: response.message,
              duration: 5
            })
          } else {
            notification.success({
              top: 92,
              message: '创建成功。',
              duration: 5
            })
          }
        })
      })
    })
  }
 
  render() {
    return (
      <Button
        className="mk-btn mk-purple"
        onClick={this.trigger}
        loading={this.state.loading}
      >
        创建存储过程
      </Button>
    )
  }
}
 
export default CreateFunc