| | |
| | | */ |
| | | static getguid () { |
| | | // 产生一个新的GUID值 |
| | | let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { |
| | | let r = Math.random() * 16 | 0 |
| | | // eslint-disable-next-line |
| | | let v = (c === 'x') ? r : (r & 0x3 | 0x8) |
| | | return v.toString(16) |
| | | }) |
| | | return uuid |
| | | let uuid = [] |
| | | let d = new Date() |
| | | let options = '0123456789abcdefghigklmnopqrstuv' |
| | | for (let i = 0; i < 19; i++) { |
| | | uuid.push(options.substr(Math.floor(Math.random() * 0x20), 1)) |
| | | } |
| | | uuid = moment().format('YYYYMMDDHHmmss') + d.getMilliseconds() + uuid.join('') |
| | | return uuid.toUpperCase() |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | static encrypt (str, timestamp) { |
| | | let salt = 'mingke' // 盐值 |
| | | return md5(str + salt + timestamp) |
| | | let _str = str + salt + timestamp |
| | | if (_str.length > 8000) { |
| | | _str = _str.slice(_str.length - 8000) |
| | | } |
| | | return md5(_str) |
| | | } |
| | | |
| | | /** |
| | |
| | | value = value.replace(/%/ig, 'mpercent') |
| | | value = value.replace(/(^\s|\s$)/ig, '') |
| | | |
| | | // value = value.replace(/>/ig, 'greateror') |
| | | // .replace(/</ig, 'lessor') |
| | | // .replace(/!=/ig, 'noequal') |
| | | // .replace(/=/ig, 'equal') |
| | | // .replace(/,/ig, 'comma') |
| | | // .replace(/>=/ig, 'greaterorequal') |
| | | // .replace(/<=/ig, 'lessorequal') |
| | | // .replace(/@/ig, 'matk') |
| | | // .replace(/\(/ig, 'mlbrktsk') |
| | | // .replace(/\)/ig, 'mrbrktsk') |
| | | // .replace(/\*/ig, 'mastrsk') |
| | | // .replace(/'/ig, 'mqotek') |
| | | // .replace(/\s/ig, 'mspace') |
| | | |
| | | // 1、encode编码(中文字符超出base64加密范围),2、base64加密 |
| | | value = window.btoa(window.encodeURIComponent(value)) |
| | | |
| | | // 随机插入字符 |
| | | let index = Math.floor(Math.random() * value.length) |
| | | // 插入字符 |
| | | let index = Math.floor(value.length / 2) |
| | | value = value.slice(0, index) + salt + value.slice(index) |
| | | |
| | | // base64加密 |
| | |
| | | } |
| | | |
| | | /** |
| | | * @description 拼接搜索条件 |
| | | * @description 初始化搜索条件 |
| | | * @param {Array} searches 搜索条件 |
| | | * @return {String} searches 格式化后结果 |
| | | */ |
| | | static initMainSearch (searches) { |
| | | if (!searches || searches.length === 0) return [] |
| | | |
| | | let newsearches = [] |
| | | searches.forEach(search => { |
| | | let item = { |
| | | key: search.field, |
| | | match: search.match, |
| | | type: search.type, |
| | | value: search.initval |
| | | } |
| | | if (item.type === 'date') { |
| | | item.value = item.value ? moment().subtract(item.value, 'days').format('YYYY-MM-DD') : '' |
| | | } else if (item.type === 'datemonth') { |
| | | item.value = item.value ? moment().subtract(item.value, 'month').format('YYYY-MM') : '' |
| | | } else if (item.type === 'dateweek') { |
| | | item.value = item.value ? [moment().subtract(item.value * 7, 'days').startOf('week').format('YYYY-MM-DD'), |
| | | moment().subtract(item.value * 7, 'days').endOf('week').format('YYYY-MM-DD')] : '' |
| | | } else if (item.type === 'daterange') { |
| | | let _val = item.value |
| | | if (_val) { |
| | | try { |
| | | _val = JSON.parse(_val) |
| | | } catch { |
| | | _val = '' |
| | | } |
| | | } |
| | | item.value = _val ? [moment().subtract(_val[0], 'days').format('YYYY-MM-DD'), |
| | | moment().subtract(_val[1], 'days').format('YYYY-MM-DD')] : '' |
| | | } else if (item.type === 'multiselect') { |
| | | item.value = item.value ? item.value.split(',').filter(Boolean) : [] |
| | | } |
| | | newsearches.push(item) |
| | | }) |
| | | |
| | | return newsearches |
| | | } |
| | | |
| | | /** |
| | | * @description 初始化搜索条件 |
| | | * @param {Array} searches 搜索条件 |
| | | * @return {String} searches 格式化后结果 |
| | | */ |
| | | static formatCustomMainSearch (searches) { |
| | | if (!searches || searches.length === 0) return {} |
| | | |
| | | let newsearches = {} |
| | | searches.forEach(item => { |
| | | if (item.type === 'date') { |
| | | let timetail = '' |
| | | let _val = item.value |
| | | |
| | | if (item.match === '<' || item.match === '<=') { |
| | | timetail = ' 00:00:00.000' |
| | | if (_val) { |
| | | _val = moment(_val, 'YYYY-MM-DD').add(1, 'days').format('YYYY-MM-DD') |
| | | } |
| | | } else if (item.match === '>' || item.match === '>=') { |
| | | timetail = ' 00:00:00.000' |
| | | } |
| | | |
| | | if (newsearches[item.key]) { |
| | | newsearches[item.key + '1'] = _val ? _val + timetail : null |
| | | } else { |
| | | newsearches[item.key] = _val ? _val + timetail : null |
| | | } |
| | | } else if (item.type === 'datemonth') { |
| | | // 月-过滤条件,从月开始至结束 |
| | | let _startval = null |
| | | let _endval = null |
| | | |
| | | if (item.value) { |
| | | _startval = moment(item.value, 'YYYY-MM').startOf('month').format('YYYY-MM-DD') + ' 00:00:00.000' |
| | | _endval = moment(item.value, 'YYYY-MM').endOf('month').add(1, 'days').format('YYYY-MM-DD') + ' 00:00:00.000' |
| | | } |
| | | |
| | | newsearches[item.key] = _startval |
| | | newsearches[item.key + '1'] = _endval |
| | | } else if (item.type === 'dateweek') { |
| | | let _endval = '' |
| | | if (item.value) { |
| | | _endval = moment(item.value[1], 'YYYY-MM-DD').add(1, 'days').format('YYYY-MM-DD') |
| | | } |
| | | |
| | | newsearches[item.key] = item.value ? item.value[0] + ' 00:00:00.000' : null |
| | | newsearches[item.key + '1'] = item.value ? _endval + ' 00:00:00.000' : null |
| | | } else if (item.type === 'daterange') { |
| | | let _endval = '' |
| | | if (item.value) { |
| | | _endval = moment(item.value[1], 'YYYY-MM-DD').add(1, 'days').format('YYYY-MM-DD') |
| | | } |
| | | |
| | | newsearches[item.key] = item.value ? item.value[0] + ' 00:00:00.000' : null |
| | | newsearches[item.key + '1'] = item.value ? _endval + ' 00:00:00.000' : null |
| | | } else if (item.type === 'text') { |
| | | item.key.split(',').forEach(field => { // 综合搜索,所字段拼接 |
| | | newsearches[field] = item.value |
| | | }) |
| | | } else if (item.type === 'multiselect') { |
| | | newsearches[item.key] = item.value.join(',') |
| | | } else { |
| | | newsearches[item.key] = item.value |
| | | } |
| | | }) |
| | | |
| | | return newsearches |
| | | } |
| | | |
| | | /** |
| | | * @description 拼接搜索条件main |
| | | * @param {Array} searches 搜索条件 |
| | | * @return {String} searchText 拼接结果 |
| | | */ |
| | | static mainjointsearchkey (searches) { |
| | | static joinMainSearchkey (searches) { |
| | | if (!searches || searches.length === 0) return '' |
| | | |
| | | if (searches[0].hasOwnProperty('initval')) { |
| | | let newsearches = [] |
| | | searches.forEach(search => { |
| | | let item = { |
| | | key: search.field, |
| | | match: search.match, |
| | | type: search.type, |
| | | value: search.initval |
| | | } |
| | | if (item.type === 'date') { |
| | | item.value = item.value ? moment().subtract(item.value, 'days').format('YYYY-MM-DD') : '' |
| | | } else if (item.type === 'datemonth') { |
| | | item.value = item.value ? moment().subtract(item.value, 'month').format('YYYY-MM') : '' |
| | | } else if (item.type === 'dateweek') { |
| | | item.value = item.value ? [moment().subtract(item.value * 7, 'days').startOf('week').format('YYYY-MM-DD'), |
| | | moment().subtract(item.value * 7, 'days').endOf('week').format('YYYY-MM-DD')] : '' |
| | | } else if (item.type === 'daterange') { |
| | | item.value = item.value ? [moment().subtract(item.value, 'days').format('YYYY-MM-DD'), |
| | | moment().subtract(item.value === 1 ? 1 : 0, 'days').format('YYYY-MM-DD')] : '' |
| | | } |
| | | newsearches.push(item) |
| | | }) |
| | | searches = newsearches |
| | | } |
| | | |
| | | let searchText = '' |
| | | searches.forEach(item => { |
| | | if (!item.value) return |
| | | // eslint-disable-next-line |
| | | searchText += (searchText !== '' ? ' ' + 'AND' + ' ' : '') |
| | | if (item.type === 'text' || item.type === 'select') { |
| | | // eslint-disable-next-line |
| | | if (!item.value || (item.type === 'multiselect' && item.value.length === 0)) return |
| | | |
| | | searchText += (searchText !== '' ? ' AND ' : '') |
| | | if (item.type === 'text') { |
| | | let str = item.match === '=' ? '' : '%' |
| | | // eslint-disable-next-line |
| | | searchText += item.key + ' ' + item.match + ' ' + '\'' + str + item.value + str + '\'' |
| | | } else if (item.type === 'date' || item.type === 'datemonth') { |
| | | // eslint-disable-next-line |
| | | searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + '\')' |
| | | } else if (item.type === 'dateweek') { |
| | | // eslint-disable-next-line |
| | | searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + '\' AND \'' + item.value[1] + '\')' |
| | | let fields = item.key.split(',').map(field => { // 综合搜索,所字段拼接 |
| | | return field + ' ' + item.match + ' \'' + str + item.value + str + '\'' |
| | | }) |
| | | |
| | | searchText += '(' + fields.join(' OR ') + ')' |
| | | } else if (item.type === 'select') { |
| | | let str = item.match === '=' ? '' : '%' |
| | | |
| | | searchText += item.key + ' ' + item.match + ' \'' + str + item.value + str + '\'' |
| | | } else if (item.type === 'multiselect') { |
| | | let str = item.match === '=' ? '' : '%' |
| | | let options = item.value.map(val => { |
| | | return item.key + ' ' + item.match + ' \'' + str + val + str + '\'' |
| | | }) |
| | | |
| | | searchText += '(' + options.join(' OR ') + ')' |
| | | } else if (item.type === 'date') { |
| | | let _val = item.value |
| | | let timetail = ' 00:00:00.000' |
| | | let _match = item.match |
| | | |
| | | if (item.match === '<' || item.match === '<=') { // 时间为<=时,匹配后一天的0点,匹配方式为< |
| | | _match = '<' |
| | | _val = moment(_val, 'YYYY-MM-DD').add(1, 'days').format('YYYY-MM-DD') |
| | | } else if (item.match === '=') { |
| | | timetail = '' |
| | | } |
| | | |
| | | searchText += '(' + item.key + ' ' + _match + ' \'' + _val + timetail + '\')' |
| | | } else if (item.type === 'datemonth') { // 月-过滤条件,从月开始至结束,结束时间为月末加一天的0点,方式为< |
| | | let _startval = moment(item.value, 'YYYY-MM').startOf('month').format('YYYY-MM-DD') + ' 00:00:00.000' |
| | | let _endval = moment(item.value, 'YYYY-MM').endOf('month').add(1, 'days').format('YYYY-MM-DD') + ' 00:00:00.000' |
| | | |
| | | searchText += '(' + item.key + ' >= \'' + _startval + '\' AND ' + item.key + ' < \'' + _endval + '\')' |
| | | } else if (item.type === 'dateweek') { // 周-过滤条件 |
| | | let _startval = item.value[0] + ' 00:00:00.000' |
| | | let _endval = moment(item.value[1], 'YYYY-MM-DD').add(1, 'days').format('YYYY-MM-DD') + ' 00:00:00.000' |
| | | |
| | | searchText += '(' + item.key + ' >= \'' + _startval + '\' AND ' + item.key + ' < \'' + _endval + '\')' |
| | | } else if (item.type === 'daterange') { |
| | | // eslint-disable-next-line |
| | | searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + '\' AND \'' + item.value[1] + '\')' |
| | | let _startval = item.value[0] + ' 00:00:00.000' |
| | | let _endval = moment(item.value[1], 'YYYY-MM-DD').add(1, 'days').format('YYYY-MM-DD') + ' 00:00:00.000' |
| | | |
| | | searchText += '(' + item.key + ' >= \'' + _startval + '\' AND ' + item.key + ' < \'' + _endval + '\')' |
| | | } else { |
| | | // eslint-disable-next-line |
| | | searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + '\')' |
| | | searchText += '(' + item.key + ' ' + item.match + ' \'' + item.value + '\')' |
| | | } |
| | | }) |
| | | return searchText |
| | | } |
| | | |
| | | /** |
| | | * @description 拼接搜索条件 |
| | | * @description 拼接搜索条件datamanage |
| | | * @param {Array} searches 搜索条件 |
| | | * @return {String} searchText 拼接结果 |
| | | */ |
| | |
| | | let searchText = '' |
| | | searches.forEach(item => { |
| | | if (!item.value) return |
| | | // eslint-disable-next-line |
| | | searchText += (searchText !== '' ? ' ' + 'AND' + ' ' : '') |
| | | searchText += (searchText !== '' ? ' AND ' : '') |
| | | if (item.type === 'text') { |
| | | let options = item.key.split(',').map(op => { |
| | | // equal时不添加% |
| | | // eslint-disable-next-line |
| | | let str = item.op === 'equal' ? '' : '%' |
| | | // eslint-disable-next-line |
| | | return op + ' ' + item.op + ' ' + '"' + str + item.value + str + '"' |
| | | return op + ' ' + item.op + ' \'' + str + item.value + str + '\'' |
| | | }) |
| | | // eslint-disable-next-line |
| | | searchText += '(' + options.join(' ' + 'OR' + ' ') + ')' |
| | | searchText += '(' + options.join(' OR ') + ')' |
| | | } else if (item.type === 'date') { |
| | | // eslint-disable-next-line |
| | | searchText += '(' + item.key + ' ' + item.op + ' ' + '"' + item.value + '")' |
| | | searchText += '(' + item.key + ' ' + item.op + ' \'' + item.value + '\')' |
| | | } else { |
| | | // eslint-disable-next-line |
| | | searchText += '(' + item.key + ' ' + item.op + ' ' + '"' + item.value + '")' |
| | | searchText += '(' + item.key + ' ' + item.op + ' \'' + item.value + '\')' |
| | | } |
| | | }) |
| | | return searchText |
| | |
| | | } else { |
| | | baseurl = 'http://qingqiumarket.cn/' + service |
| | | } |
| | | // if (!/Content\/images\/upload\//.test(url)) { |
| | | // baseurl = baseurl + 'Content/images/upload/' |
| | | // } |
| | | let realurl = url.match(/^http/) || url.match(/^\/\//) ? url : baseurl + url |
| | | return realurl |
| | | } |
| | | |
| | | /** |
| | | * @description 获取下拉搜索查询条件 |
| | | * @return {String} item 搜索条件信息 |
| | | */ |
| | | static getSelectQueryOptions (item) { |
| | | let arrfield = [item.valueField, item.valueText] |
| | | |
| | | if (item.type === 'link') { |
| | | arrfield.push(item.linkField) |
| | | } else if (item.type === 'select' && item.linkSubField && item.linkSubField.length > 0) { |
| | | arrfield.push(...item.linkSubField) |
| | | } |
| | | |
| | | arrfield = Array.from(new Set(arrfield)) |
| | | |
| | | let _datasource = item.dataSource |
| | | let sql = '' |
| | | |
| | | if (/\s/.test(_datasource)) { // 拼接别名 |
| | | _datasource = '(' + _datasource + ') tb' |
| | | } |
| | | |
| | | arrfield = arrfield.join(',') |
| | | |
| | | if (item.orderBy) { |
| | | sql = 'select distinct ' + arrfield + ',' + item.orderBy + ' as orderfield from ' + _datasource + ' order by orderfield ' + item.orderType |
| | | } else { |
| | | sql = 'select distinct ' + arrfield + ' from ' + _datasource |
| | | } |
| | | |
| | | return { |
| | | sql: sql, |
| | | field: arrfield |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 使用系统函数时(sPC_TableData_InUpDe ),生成sql语句 |
| | | * @return {String} type 执行类型 |
| | | * @return {String} table 表名 |
| | | */ |
| | | static getSysDefaultSql (btn, setting, formdata, param, data) { |
| | | let primaryId = param.ID |
| | | let BID = param.BID |
| | | let verify = btn.verify |
| | | let _formFieldValue = {} |
| | | |
| | | if (formdata) { // 获取字段键值对 |
| | | formdata.forEach(form => { |
| | | _formFieldValue[form.key] = form.value |
| | | }) |
| | | } |
| | | |
| | | let primaryKey = setting.primaryKey || 'id' // 主键字段 |
| | | // 系统变量声明与设置初始值 |
| | | let _sql = `Declare @tbid nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50) |
| | | ` |
| | | if (verify && verify.scripts && verify.scripts.length > 0 && formdata) { |
| | | let _formfields = formdata.filter(form => !['tbid', 'ErrorCode', 'retmsg', 'BillCode', 'BVoucher', 'FIBVoucherDate', 'FiYear'].includes(form.key)) |
| | | _formfields = _formfields.map(form => `@${form.key} nvarchar(50)`) |
| | | _formfields = _formfields.join(',') |
| | | _sql += `${_formfields} |
| | | ` |
| | | } |
| | | |
| | | _sql += `Select @BVoucher='',@FIBVoucherDate='',@FiYear='' |
| | | ` |
| | | |
| | | if (verify && verify.accountdate === 'true') { // 启用账期验证 |
| | | _sql += `exec s_FIBVoucherDateCheck @ErrorCode=@ErrorCode OUTPUT,@retmsg=@retmsg OUTPUT |
| | | if @ErrorCode!='' |
| | | GOTO aaa |
| | | ` |
| | | } |
| | | if (btn.sqlType !== 'insert' && verify && verify.invalid === 'true' && setting.dataresource) { // 失效验证,添加数据时不用 |
| | | let datasource = setting.dataresource |
| | | if (/\s/.test(datasource)) { // 拼接别名 |
| | | datasource = '(' + datasource + ') tb' |
| | | } |
| | | |
| | | _sql += `Select @tbid='', @ErrorCode='',@retmsg='' |
| | | Select @tbid=${primaryKey} from ${datasource} where ${primaryKey} ='${primaryId}' |
| | | If @tbid='' |
| | | Begin |
| | | select @ErrorCode='E',@retmsg='数据已失效' |
| | | goto aaa |
| | | end |
| | | ` |
| | | } |
| | | if (formdata && verify && verify.uniques.length > 0) { // 唯一性验证,必须存在表单(表单存在时,主键均为单值),必须填写数据源 |
| | | let _primaryId = primaryId |
| | | if (btn.sqlType === 'insert') { |
| | | _primaryId = '' |
| | | } |
| | | |
| | | verify.uniques.forEach(item => { |
| | | let _fieldValue = [] // 表单键值对field=value |
| | | let _value = [] // 表单值,用于错误提示 |
| | | let _labels = item.fieldlabel.split(',') |
| | | |
| | | item.field.split(',').forEach((_field, index) => { |
| | | _fieldValue.push(`${_field}='${_formFieldValue[_field]}'`) |
| | | _value.push(`${_labels[index] || ''}:${_formFieldValue[_field] || ''}`) |
| | | }) |
| | | |
| | | _sql += `Select @tbid='', @ErrorCode='',@retmsg='' |
| | | Select @tbid='X' from ${btn.sql} where ${_fieldValue.join(' and ')} and ${primaryKey} !='${_primaryId}' |
| | | If @tbid!='' |
| | | Begin |
| | | select @ErrorCode='${item.errorCode}',@retmsg='${_value.join(', ')} 已存在' |
| | | goto aaa |
| | | end |
| | | ` |
| | | }) |
| | | } |
| | | |
| | | if (verify && verify.customverifys.length > 0) { // 自定义验证 |
| | | let _primaryId = primaryId |
| | | if (btn.sqlType === 'insert') { |
| | | _primaryId = '' |
| | | } |
| | | |
| | | verify.customverifys.forEach(item => { |
| | | let _cuSql = item.sql |
| | | if (data) { |
| | | _formFieldValue = {...data, ..._formFieldValue} |
| | | } |
| | | let keys = Object.keys(_formFieldValue) |
| | | keys = keys.sort((a, b) => { |
| | | return b.length - a.length |
| | | }) |
| | | |
| | | keys.forEach(key => { |
| | | let reg = new RegExp('@' + key, 'ig') |
| | | _cuSql = _cuSql.replace(reg, `'${_formFieldValue[key]}'`) |
| | | }) |
| | | let idreg = new RegExp('@ID', 'ig') |
| | | _cuSql = _cuSql.replace(idreg, `'${_primaryId}'`) |
| | | |
| | | let bidreg = new RegExp('@BID', 'ig') |
| | | _cuSql = _cuSql.replace(bidreg, `'${BID}'`) |
| | | |
| | | _sql += `Select @tbid='', @ErrorCode='',@retmsg='' |
| | | Select top 1 @tbid='X' from (${_cuSql}) a |
| | | If @tbid ${item.result === 'true' ? '!=' : '='}'' |
| | | Begin |
| | | select @ErrorCode='${item.errorCode}',@retmsg='${item.errmsg}' |
| | | goto aaa |
| | | end |
| | | ` |
| | | }) |
| | | } |
| | | |
| | | if (verify && verify.billcodes.length > 0) { // 单号生成 |
| | | verify.billcodes.forEach(item => { |
| | | let _ModularDetailCode = '' |
| | | if (item.TypeCharOne === 'Lp' || item.TypeCharOne === 'BN') { |
| | | let _val = '' |
| | | if (item.linkField === 'BID' && BID) { // 替换bid |
| | | _val = BID |
| | | } else if (data && data.hasOwnProperty(item.linkField)) { |
| | | _val = data[item.linkField] |
| | | } |
| | | _ModularDetailCode = item.TypeCharOne + _val |
| | | } else { |
| | | _ModularDetailCode = item.ModularDetailCode |
| | | } |
| | | |
| | | _sql += `Declare @${item.field} nvarchar(50) |
| | | select @BillCode='', @${item.field}='' |
| | | exec s_get_BillCode |
| | | @ModularDetailCode='${_ModularDetailCode}', |
| | | @Type=${item.Type}, |
| | | @TypeCharOne='${item.TypeCharOne}', |
| | | @TypeCharTwo ='${item.TypeCharTwo}', |
| | | @BillCode =@BillCode output, |
| | | @ErrorCode =@ErrorCode output, |
| | | @retmsg=@retmsg output |
| | | if @ErrorCode!='' |
| | | goto aaa |
| | | set @${item.field}=@BillCode |
| | | ` |
| | | }) |
| | | } |
| | | |
| | | let _updateconfig = '' |
| | | |
| | | if (verify && verify.voucher && verify.voucher.enabled && data) { // 凭证-显示列中选取,必须选行 |
| | | let _voucher = verify.voucher |
| | | |
| | | _updateconfig = ',BVoucher=@BVoucher,FIBVoucherDate=@FIBVoucherDate,FiYear=@FiYear' |
| | | |
| | | _sql += `exec s_BVoucher_Create |
| | | @Bill ='${data[_voucher.linkField]}', |
| | | @BVoucherType ='${_voucher.BVoucherType}', |
| | | @VoucherTypeOne ='${_voucher.VoucherTypeOne}', |
| | | @VoucherTypeTwo ='${_voucher.VoucherTypeTwo}', |
| | | @Type =${_voucher.Type}, |
| | | @BVoucher =@BVoucher OUTPUT , |
| | | @FIBVoucherDate =@FIBVoucherDate OUTPUT , |
| | | @FiYear =@FiYear OUTPUT , |
| | | @ErrorCode =@ErrorCode OUTPUT, |
| | | @retmsg=@retmsg OUTPUT |
| | | if @ErrorCode!='' |
| | | GOTO aaa |
| | | ` |
| | | } |
| | | |
| | | if (btn.OpenType === 'pop' && btn.sqlType === 'insert') { |
| | | let keys = [] |
| | | let values = [] |
| | | formdata.forEach(item => { |
| | | if (item.type === 'funcvar') { |
| | | keys.push(item.key) |
| | | values.push('@' + item.key) |
| | | } else if (item.type === 'number') { |
| | | keys.push(item.key) |
| | | values.push(item.value) |
| | | } else { |
| | | keys.push(item.key) |
| | | values.push('\'' + item.value + '\'') |
| | | } |
| | | }) |
| | | |
| | | keys = keys.join(',') |
| | | values = values.join(',') |
| | | _sql += `declare @UserName nvarchar(50),@FullName nvarchar(50) |
| | | select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID |
| | | ` |
| | | _sql += `insert into ${btn.sql} (${keys},createuserid,CreateUser,CreateStaff,BID) select ${values},@userid,@username,@fullname,@BID` |
| | | } else if (btn.OpenType === 'pop' && btn.sqlType === 'update') { |
| | | let _form = [] |
| | | formdata.forEach(item => { |
| | | if (item.type === 'funcvar') { |
| | | _form.push(item.key + '=@' + item.key) |
| | | } else if (item.type === 'number') { |
| | | _form.push(item.key + '=' + item.value) |
| | | } else { |
| | | _form.push(item.key + '=\'' + item.value + '\'') |
| | | } |
| | | }) |
| | | _form = _form.join(',') |
| | | _sql += `update ${btn.sql} set ${_form},modifydate=getdate(),modifyuserid=@userid${_updateconfig} where ${primaryKey}=@${primaryKey}` |
| | | } else if ((btn.OpenType === 'prompt' || btn.OpenType === 'exec') && btn.sqlType === 'LogicDelete') { // 逻辑删除 |
| | | _sql += `update ${btn.sql} set deleted=1,modifydate=getdate(),modifyuserid=@userid where ${primaryKey}=@${primaryKey}` |
| | | } else if ((btn.OpenType === 'prompt' || btn.OpenType === 'exec') && btn.sqlType === 'delete') { // 物理删除 |
| | | _sql += `insert into snote (remark,createuserid) select '删除表:${btn.sql} 数据: ${primaryKey}='+@${primaryKey},@userid delete ${btn.sql} where ${primaryKey}=@${primaryKey}` |
| | | } |
| | | |
| | | if (verify && verify.scripts && verify.scripts.length > 0) { |
| | | let _scripts = '' |
| | | verify.scripts.forEach(item => { |
| | | _scripts += `${item.sql} |
| | | ` |
| | | }) |
| | | _sql += ` |
| | | ${_scripts}` |
| | | } |
| | | |
| | | _sql += `aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg |
| | | ` |
| | | console.log(_sql) |
| | | return _sql |
| | | } |
| | | |
| | | /** |
| | | * @description 删除存储过程sql |
| | | * @return {String} name 存储过程名称 |
| | | */ |
| | | static dropfunc (name) { |
| | | return `IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID('${name}') AND type in (N'P', N'PC')) mdrpk PROCEDURE ${name}` |
| | | } |
| | | |
| | | /** |
| | | * @description 创建页面存储过程 |
| | | * @return {String} |
| | | */ |
| | | static getTableFunc (param, menu, config) { |
| | | let form = '' |
| | | let formParam = '' |
| | | let _columns = [] |
| | | let primaryKey = config.setting.primaryKey || 'ID' |
| | | |
| | | if (config.search && config.search.length > 0) { |
| | | let _fields = new Map() |
| | | config.search.forEach(item => { |
| | | if (item.field) { |
| | | let type = '' |
| | | let _f = item.field |
| | | |
| | | if (item.type.match(/date/ig)) { |
| | | type = 'datetime=null' |
| | | } else { |
| | | type = 'nvarchar(50)=\'\'' |
| | | } |
| | | |
| | | if (_fields.has(item.field)) { |
| | | _f = _f + '1' |
| | | } |
| | | |
| | | _fields.set(item.field, true) |
| | | formParam = formParam + `mchr13k@${_f} ${type},` |
| | | } |
| | | }) |
| | | } |
| | | |
| | | if (config.columns && config.columns.length > 0) { |
| | | config.columns.forEach(item => { |
| | | if (item.field) { |
| | | _columns.push(`${item.field} as ${item.label}`) |
| | | } |
| | | }) |
| | | |
| | | form = ` |
| | | declare @dc table (${_columns.join(',')}) |
| | | |
| | | @tableid ='${menu.MenuID}' |
| | | ` |
| | | } |
| | | |
| | | let Ltext = `create proc ${param.innerFunc} |
| | | ( /*${menu.MenuName}*/ |
| | | @BID nvarchar(50)='', |
| | | @${primaryKey} nvarchar(50)='',${formParam} |
| | | @PageIndex nvarchar(50)='', |
| | | @PageSize nvarchar(50)='', |
| | | @OrderCol nvarchar(50)='', |
| | | @OrderType nvarchar(50)='', |
| | | @exceltype nvarchar(50)='', |
| | | @sEPTMenuNo nvarchar(50)='${menu.MenuNo}', |
| | | @lang nvarchar(50)='', |
| | | @debug nvarchar(50)='', |
| | | @LoginUID nvarchar(50)='', |
| | | @SessionUid nvarchar(50)='', |
| | | @UserID nvarchar(50), |
| | | @ErrorCode nvarchar(50) out, |
| | | @retmsg nvarchar(4000) out |
| | | ) |
| | | as |
| | | begin |
| | | declare @BegindateTest datetime,@EnddateTest datetime |
| | | select @BegindateTest=getdate() |
| | | set @ErrorCode='' |
| | | set @retmsg='' |
| | | BEGIN TRY |
| | | /*事务操作*/ |
| | | BEGIN TRAN |
| | | /*具体业务操作*/ |
| | | |
| | | /* |
| | | select top 10 * from sProcExcep order by id desc |
| | | |
| | | declare @UserName nvarchar(50),@FullName nvarchar(50) |
| | | |
| | | select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID |
| | | ${form} |
| | | if 1=2 |
| | | begin |
| | | set @ErrorCode='E' |
| | | set @retmsg='在此写报错' |
| | | goto GOTO_RETURN |
| | | end |
| | | |
| | | insert into sNote (remark,createuserid,CreateUser,CreateStaff) |
| | | select '在此写日志',@UserID,@UserName,@FullName |
| | | */ |
| | | |
| | | COMMIT TRAN |
| | | SET NOCOUNT ON |
| | | RETURN |
| | | END TRY |
| | | BEGIN CATCH |
| | | /*错误处理*/ |
| | | ROLLBACK TRAN |
| | | DECLARE @ErrorMessage NVARCHAR(4000); |
| | | DECLARE @ErrorSeverity INT; |
| | | DECLARE @ErrorState INT; |
| | | |
| | | /*把自定义的友好的错误信息提示加上*/ |
| | | set @ErrorCode=cast(ERROR_NUMBER() as nvarchar(50)) |
| | | SET @retmsg=ERROR_MESSAGE(); |
| | | SELECT @ErrorMessage=ERROR_MESSAGE(), |
| | | @ErrorSeverity=ERROR_SEVERITY(), |
| | | @ErrorState=ERROR_STATE(); |
| | | |
| | | RAISERROR(@ErrorMessage, /*-- Message text.*/ |
| | | @ErrorSeverity, /*-- Severity.*/ |
| | | @ErrorState /*-- State.*/ |
| | | ); |
| | | END CATCH |
| | | |
| | | GOTO_RETURN: |
| | | ROLLBACK TRAN |
| | | |
| | | END` |
| | | |
| | | Ltext = Ltext.replace(/\n\s{4}/ig, 'mchr13k') |
| | | |
| | | return Ltext |
| | | } |
| | | |
| | | /** |
| | | * @description 创建存储过程 |
| | | * @return {String} |
| | | */ |
| | | static getfunc (param, btn, menu, config) { |
| | | let form = '' |
| | | let formParam = '' |
| | | let columns = config.columns |
| | | let primaryKey = config.setting.primaryKey || 'ID' |
| | | |
| | | if (param.fields && param.fields.length > 0) { |
| | | let _fields = [] |
| | | param.fields.forEach(item => { |
| | | if (item.field) { |
| | | let type = '' |
| | | if (item.type.match(/date/ig)) { |
| | | type = 'datetime=null' |
| | | } else if (item.type === 'number') { |
| | | type = `decimal(18,${item.decimal})=0` |
| | | } else { |
| | | type = 'nvarchar(50)=\'\'' |
| | | } |
| | | formParam = formParam + `mchr13k@${item.field} ${type},` |
| | | |
| | | _fields.push(item.field) |
| | | } |
| | | }) |
| | | |
| | | let field1 = _fields.join(',') |
| | | let field2 = _fields.join(',@') |
| | | let field3 = _fields.map(cell => { |
| | | return cell + '=@' + cell |
| | | }) |
| | | |
| | | field2 = field2 ? '@' + field2 : '' |
| | | field3 = field3.join(',') |
| | | |
| | | form = ` |
| | | insert into ${param.name} (${field1},createuserid) select ${field2},@UserID |
| | | |
| | | update ${param.name} set ${field3},modifydate=getdate(),modifyuserid=@UserID |
| | | ` |
| | | } |
| | | |
| | | if (columns) { |
| | | let _col = [] |
| | | let _field = [] |
| | | columns.forEach(col => { |
| | | if (col.field) { |
| | | if (col.type === 'number') { |
| | | _col.push(col.field + ' decimal(18,2)') |
| | | } else { |
| | | _col.push(col.field + ' nvarchar(50)') |
| | | } |
| | | _field.push(col.field) |
| | | } |
| | | }) |
| | | _col = _col.join(',') |
| | | _field = _field.join(',') |
| | | |
| | | form = form + ` |
| | | declare @dc table (${_col}) |
| | | |
| | | insert into @dc (${_field}) |
| | | |
| | | @tableid ='${menu.MenuID}' |
| | | ` |
| | | } |
| | | |
| | | let Ltext = `create proc ${param.funcName} |
| | | ( /*${menu.MenuName} ${btn.label}*/ |
| | | @BID nvarchar(50)='', |
| | | @${primaryKey} nvarchar(50)='',${formParam} |
| | | @sEPTMenuNo nvarchar(50)='${param.menuNo}', |
| | | @lang nvarchar(50)='', |
| | | @debug nvarchar(50)='', |
| | | @LoginUID nvarchar(50)='', |
| | | @SessionUid nvarchar(50)='', |
| | | @UserID nvarchar(50), |
| | | @ErrorCode nvarchar(50) out, |
| | | @retmsg nvarchar(4000) out |
| | | ) |
| | | as |
| | | begin |
| | | declare @BegindateTest datetime,@EnddateTest datetime |
| | | select @BegindateTest=getdate() |
| | | set @ErrorCode='' |
| | | set @retmsg='' |
| | | BEGIN TRY |
| | | /*事务操作*/ |
| | | BEGIN TRAN |
| | | /*具体业务操作*/ |
| | | |
| | | /* |
| | | select top 10 * from sProcExcep order by id desc |
| | | |
| | | declare @UserName nvarchar(50),@FullName nvarchar(50) |
| | | |
| | | select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID |
| | | ${form} |
| | | if 1=2 |
| | | begin |
| | | set @ErrorCode='E' |
| | | set @retmsg='在此写报错' |
| | | goto GOTO_RETURN |
| | | end |
| | | |
| | | insert into sNote (remark,createuserid,CreateUser,CreateStaff) |
| | | select '在此写日志',@UserID,@UserName,@FullName |
| | | */ |
| | | |
| | | COMMIT TRAN |
| | | SET NOCOUNT ON |
| | | RETURN |
| | | END TRY |
| | | BEGIN CATCH |
| | | /*错误处理*/ |
| | | ROLLBACK TRAN |
| | | DECLARE @ErrorMessage NVARCHAR(4000); |
| | | DECLARE @ErrorSeverity INT; |
| | | DECLARE @ErrorState INT; |
| | | |
| | | /*把自定义的友好的错误信息提示加上*/ |
| | | set @ErrorCode=cast(ERROR_NUMBER() as nvarchar(50)) |
| | | SET @retmsg=ERROR_MESSAGE(); |
| | | SELECT @ErrorMessage=ERROR_MESSAGE(), |
| | | @ErrorSeverity=ERROR_SEVERITY(), |
| | | @ErrorState=ERROR_STATE(); |
| | | |
| | | RAISERROR(@ErrorMessage, /*-- Message text.*/ |
| | | @ErrorSeverity, /*-- Severity.*/ |
| | | @ErrorState /*-- State.*/ |
| | | ); |
| | | END CATCH |
| | | |
| | | GOTO_RETURN: |
| | | ROLLBACK TRAN |
| | | |
| | | END` |
| | | |
| | | Ltext = Ltext.replace(/\n\s{4}/ig, 'mchr13k') |
| | | |
| | | return Ltext |
| | | } |
| | | } |