| | |
| | | */ |
| | | 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加密 |
| | |
| | | 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')] : '' |
| | | 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 |
| | |
| | | |
| | | 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 + '\'' |
| | | 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' |
| | | if (item.match === '<' || item.match === '<=') { |
| | | timetail = ' 23:59:59.999' |
| | | 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 = '' |
| | | } |
| | | // eslint-disable-next-line |
| | | searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value + timetail + '\')' |
| | | } else if (item.type === 'datemonth') { |
| | | // 月-过滤条件,从月开始至结束 |
| | | |
| | | 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').format('YYYY-MM-DD') + ' 23:59:59.999' |
| | | // eslint-disable-next-line |
| | | searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + _startval + '\' AND \'' + _endval + '\')' |
| | | } else if (item.type === 'dateweek') { |
| | | let stimetail = ' 00:00:00.000' |
| | | let etimetail = ' 23:59:59.999' |
| | | // eslint-disable-next-line |
| | | searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + stimetail + '\' AND \'' + item.value[1] + etimetail + '\')' |
| | | 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') { |
| | | let stimetail = ' 00:00:00.000' |
| | | let etimetail = ' 23:59:59.999' |
| | | // eslint-disable-next-line |
| | | searchText += '(' + item.key + ' ' + item.match + ' ' + '\'' + item.value[0] + stimetail + '\' AND \'' + item.value[1] + etimetail + '\')' |
| | | 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 |
| | |
| | | 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 |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return {String} type 执行类型 |
| | | * @return {String} table 表名 |
| | | */ |
| | | static getSysDefaultSql (btn, setting, formdata) { |
| | | let _sql = '' |
| | | if (btn.OpenType === 'pop' && btn.sqlType === 'insert') { |
| | | static getSysDefaultSql (btn, setting, formdata, param, data, logcolumns) { |
| | | let primaryId = param.ID |
| | | let BID = param.BID |
| | | let verify = btn.verify || {} |
| | | let _formFieldValue = {} |
| | | // 需要声明的变量集 |
| | | let _vars = ['tbid', 'ErrorCode', 'retmsg', 'BillCode', 'BVoucher', 'FIBVoucherDate', 'FiYear', 'UserName', 'FullName', 'ID', 'BID'] |
| | | |
| | | // 主键字段 |
| | | 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), @UserName nvarchar(50),@FullName nvarchar(50) |
| | | ` |
| | | |
| | | // 获取字段键值对 |
| | | if (formdata) { |
| | | formdata.forEach(form => { |
| | | _formFieldValue[form.key] = form.value |
| | | }) |
| | | } |
| | | |
| | | // 添加数据中字段,表单值优先 |
| | | if (data) { |
| | | _formFieldValue = {...data, ..._formFieldValue} |
| | | } |
| | | |
| | | // 添加时主键为空 |
| | | if (btn.sqlType === 'insert') { |
| | | primaryId = '' |
| | | } |
| | | |
| | | // 声明表单及列表数据字段,初始化赋值 |
| | | let keys = Object.keys(_formFieldValue) |
| | | let _initfields = [] |
| | | let _initvars = ['ID', 'BID'] |
| | | let _formfields = [] |
| | | keys.forEach(key => { |
| | | if (!_initvars.includes(key)) { |
| | | _initvars.push(key) |
| | | _initfields.push(`@${key}='${_formFieldValue[key]}'`) |
| | | } |
| | | |
| | | if (!_vars.includes(key)) { |
| | | _vars.push(key) |
| | | _formfields.push(`@${key} nvarchar(50)`) |
| | | } |
| | | }) |
| | | |
| | | _formfields = _formfields.join(',') |
| | | if (_formfields) { |
| | | _sql += `,${_formfields} |
| | | ` |
| | | } |
| | | |
| | | _initfields = _initfields.join(',') |
| | | if (_initfields) { |
| | | _sql += `select ${_initfields} |
| | | ` |
| | | } |
| | | |
| | | // 去除禁用的验证 |
| | | if (verify.contrasts) { |
| | | verify.contrasts = verify.contrasts.filter(item => item.status !== 'false') |
| | | } |
| | | if (verify.uniques) { |
| | | verify.uniques = verify.uniques.filter(item => item.status !== 'false') |
| | | } |
| | | if (verify.customverifys) { |
| | | verify.customverifys = verify.customverifys.filter(item => item.status !== 'false') |
| | | } |
| | | if (verify.billcodes) { |
| | | verify.billcodes = verify.billcodes.filter(item => item.status !== 'false') |
| | | } |
| | | if (verify.scripts) { |
| | | verify.scripts = verify.scripts.filter(item => item.status !== 'false') |
| | | } |
| | | |
| | | // 初始化凭证字段 |
| | | _sql += `select @BVoucher='',@FIBVoucherDate='',@FiYear='' |
| | | ` |
| | | |
| | | // 启用账期验证 |
| | | if (verify.accountdate === 'true') { |
| | | _sql += `exec s_FIBVoucherDateCheck @ErrorCode=@ErrorCode OUTPUT,@retmsg=@retmsg OUTPUT |
| | | if @ErrorCode!='' |
| | | GOTO aaa |
| | | ` |
| | | } |
| | | |
| | | // 失效验证,添加数据时不用 |
| | | if (btn.sqlType !== 'insert' && 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 (verify.contrasts && verify.contrasts.length > 0) { |
| | | verify.contrasts.forEach(item => { |
| | | _sql += `If ${item.frontfield} ${item.operator} ${item.backfield} |
| | | Begin |
| | | select @ErrorCode='${item.errorCode}',@retmsg='${item.errmsg}' |
| | | goto aaa |
| | | end |
| | | ` |
| | | }) |
| | | } |
| | | |
| | | // 唯一性验证,必须存在表单(表单存在时,主键均为单值),必须填写数据源 |
| | | if (formdata && verify.uniques && verify.uniques.length > 0) { |
| | | 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] || ''}`) |
| | | }) |
| | | |
| | | let _verifyType = '' |
| | | if (item.verifyType === 'logic') { |
| | | _verifyType = ' and deleted=0' |
| | | } |
| | | |
| | | _sql += `select @tbid='', @ErrorCode='',@retmsg='' |
| | | select @tbid='X' from ${btn.sql} where ${_fieldValue.join(' and ')} and ${primaryKey} !='${primaryId}'${_verifyType} |
| | | If @tbid!='' |
| | | Begin |
| | | select @ErrorCode='${item.errorCode}',@retmsg='${_value.join(', ')} 已存在' |
| | | goto aaa |
| | | end |
| | | ` |
| | | }) |
| | | } |
| | | |
| | | // 自定义验证 |
| | | if (verify.customverifys && verify.customverifys.length > 0) { |
| | | verify.customverifys.forEach(item => { |
| | | _sql += `select @tbid='', @ErrorCode='',@retmsg='' |
| | | select top 1 @tbid='X' from (${item.sql}) a |
| | | If @tbid ${item.result === 'true' ? '!=' : '='}'' |
| | | Begin |
| | | select @ErrorCode='${item.errorCode}',@retmsg='${item.errmsg}' |
| | | goto aaa |
| | | end |
| | | ` |
| | | }) |
| | | } |
| | | |
| | | // 单号生成,使用上级id(BID)或列表数据,声明变量(检验) |
| | | if (verify.billcodes && 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 |
| | | } |
| | | |
| | | let _declare = '' |
| | | if (!_vars.includes(item.field)) { |
| | | _declare = `Declare @${item.field} nvarchar(50)` |
| | | } |
| | | _vars.push(item.field) |
| | | |
| | | _sql += `${_declare} |
| | | 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.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 |
| | | ` |
| | | } |
| | | |
| | | // 用于取用户信息 |
| | | let _user = `select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID |
| | | ` |
| | | |
| | | // 添加、修改、逻辑删除、物理删除 |
| | | if (btn.OpenType === 'pop' && btn.sqlType === 'insert' && verify.default !== 'false') { |
| | | let keys = [] |
| | | let values = [] |
| | | formdata.forEach(item => { |
| | | if (!item.readonly && item.type === 'number') { |
| | | 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 if (!item.readonly) { |
| | | } else { |
| | | keys.push(item.key) |
| | | values.push('\'' + item.value + '\'') |
| | | } |
| | | }) |
| | | |
| | | keys = keys.join(',') |
| | | values = values.join(',') |
| | | |
| | | _sql = `insert into ${btn.sql} (${keys}, createuserid) select ${values},@userid` |
| | | } else if (btn.OpenType === 'pop' && btn.sqlType === 'update') { |
| | | _sql += _user |
| | | _sql += `insert into ${btn.sql} (${keys},createuserid,CreateUser,CreateStaff,BID) select ${values},@userid,@username,@fullname,@BID;` |
| | | } else if (btn.OpenType === 'pop' && btn.sqlType === 'update' && verify.default !== 'false') { |
| | | let _form = [] |
| | | formdata.forEach(item => { |
| | | if (!item.readonly && item.type === 'number') { |
| | | if (item.type === 'funcvar') { |
| | | _form.push(item.key + '=@' + item.key) |
| | | } else if (item.type === 'number') { |
| | | _form.push(item.key + '=' + item.value) |
| | | } else if (!item.readonly) { |
| | | } else { |
| | | _form.push(item.key + '=\'' + item.value + '\'') |
| | | } |
| | | }) |
| | | _form = _form.join(',') |
| | | _sql = `update ${btn.sql} set ${_form},modifydate=getdate(),modifyuserid=@userid where ${setting.primaryKey}=@id` |
| | | } else if ((btn.OpenType === 'prompt' || btn.OpenType === 'exec') && btn.sqlType === 'LogicDelete') { // 逻辑删除 |
| | | _sql = `update ${btn.sql} set deleted=1,modifydate=getdate(),modifyuserid=@userid where ${setting.primaryKey}=@id` |
| | | } else if ((btn.OpenType === 'prompt' || btn.OpenType === 'exec') && btn.sqlType === 'delete') { |
| | | _sql = `insert into snote (remark,createuserid) select '删除表:${btn.sql} 数据: id='+@id,@userid delete ${btn.sql} where ${setting.primaryKey}=@id` |
| | | _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' && verify.default !== 'false') { // 逻辑删除 |
| | | _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' && verify.default !== 'false') { // 物理删除 |
| | | let _msg = '' |
| | | if (data && logcolumns && logcolumns.length > 0) { |
| | | logcolumns.forEach(col => { |
| | | _msg += col.label + '=' + data[col.field] + ',' |
| | | }) |
| | | } |
| | | _sql += _user |
| | | _sql += `insert into snote (remark,createuserid,CreateUser,CreateStaff) select '删除表:${btn.sql} 数据: ${_msg}${primaryKey}='+@${primaryKey},@userid,@username,@fullname delete ${btn.sql} where ${primaryKey}=@${primaryKey};` |
| | | } |
| | | |
| | | // 拼接自定义脚本 |
| | | if (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 创建页面存储过程 |
| | | * @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, columns) { |
| | | static getfunc (param, btn, menu, config) { |
| | | let form = '' |
| | | let formParam = '' |
| | | console.log(menu) |
| | | console.log(columns) |
| | | let columns = config.columns |
| | | let primaryKey = config.setting.primaryKey || 'ID' |
| | | |
| | | if (param.fields && param.fields.length > 0) { |
| | | let _fields = [] |
| | | param.fields.forEach(item => { |
| | |
| | | let Ltext = `create proc ${param.funcName} |
| | | ( /*${menu.MenuName} ${btn.label}*/ |
| | | @BID nvarchar(50)='', |
| | | @ID nvarchar(50)='',${formParam} |
| | | @${primaryKey} nvarchar(50)='',${formParam} |
| | | @sEPTMenuNo nvarchar(50)='${param.menuNo}', |
| | | @lang nvarchar(50)='', |
| | | @debug nvarchar(50)='', |
| | |
| | | BEGIN TRAN |
| | | /*具体业务操作*/ |
| | | |
| | | /* |
| | | /* |
| | | select top 10 * from sProcExcep order by id desc |
| | | |
| | | declare @UserName nvarchar(50),@FullName nvarchar(50) |
| | |
| | | RAISERROR(@ErrorMessage, /*-- Message text.*/ |
| | | @ErrorSeverity, /*-- Severity.*/ |
| | | @ErrorState /*-- State.*/ |
| | | ); |
| | | ); |
| | | END CATCH |
| | | |
| | | GOTO_RETURN: |
| | | ROLLBACK TRAN |
| | | |
| | | END` |
| | | console.log(Ltext) |
| | | |
| | | Ltext = Ltext.replace(/\n\s{4}/ig, 'mchr13k') |
| | | |
| | | return Ltext |