谷神后端$vs.proc.invoke.stock.loadValue

loadValue
// 调用
@loadValue($src, $paramField, $strTableName, $key, $field, $target, $other, $systemId)



/**
 * loadValue
 * 加载value。
 *
 * @param $src:list:列表。
 * @param $paramField:string:参数域。
 * @param $strTableName:string:表名。
 * @param $key:string:键。
 * @param $field:string:值域。
 * @param $target:string:落地属性。
 * @param $other:map:其它条件。
 * @param $systemId:string:系统id。
 *
 * @return list:加载数据后的列表。
 *
 */
#function loadValue($src, $paramField, $strTableName, $key, $field, $target, $other, $systemId)
	// 参数处理
	#set($where = $vs.util.newMap())
	#if ($vs.util.isMap($other))
		$where.putAll($other)
	#end

	// 数据收集
	#set($paramFields = @collectSet($src, $paramField))
	// 查询条件
	$where.put($key, $paramFields)

	// 列表数据
	#set($list = $vs.util.newList())
	#if ($vs.util.isString($systemId))
		#set($list = @remoteList($systemId, $strTableName, '*', $where))
	#else
		#set($list = $vs.dbTools.select($strTableName, $where))
	#end

	// 列表分组
	#set($map = @list2map($list, $key, $field))
	// 数据组装
	@listPut($src, $map, $paramField, $target)

	// 返回
	return $src
#end



/**
 * collectSet
 * 集合数据收集list实现:判空、去重。
 *
 * @param $list:list:列表。
 * @param $field:string:字段。
 *
 * @return list
 *
 */
#function collectSet($list, $field)
	#if ($vs.util.isList($list))
		#set($result = $vs.util.newList())
		#set($set = $vs.util.newList())
		#foreach($row in $list)
			#set($value = $row)
			#if ($vs.util.isNotNull($field))
				#set($value = $row.get($field))
			#end
			#if ($vs.util.isNotNull($value) and !$set.contains($value))
				$result.add($value)
				$set.add($value)
			#end
		#end
		return $result
	#end
	return null
#end

/**
 * remoteList
 * 远程列表。
 *
 * @param $systemId:string:系统id。
 * @param $strTableName:string:表。
 * @param $strColumns:string:字段。
 * @param $where:map:条件。
 *
 * @return list:列表。
 *
 */
#function remoteList($systemId, $strTableName, $strColumns, $where)
	#if ($vs.util.isBlankOne($strTableName, $systemId))
		return null
	#end
	#if ($vs.util.isNull($strColumns))
		#set($strColumns = ' * ')
	#end
	#set($strSql = `
		select
			${$strColumns}
		from
			${strTableName}
		where 1 = 1
	`)
	#set($strSql = $strSql + @andWhere($where))
	return $vs.dbTools.remoteList($systemId, $strSql ,$where)
#end

/**
 * andWhere
 * 条件。
 * 
 * @param $where:map:条件
 *
 * @return string:sql。
 *
 */
#function andWhere($where)
	#set($sql = '')
	#if ($vs.util.isMap($where))
		#foreach ($key in $vs.util.getMapKeys($where))
			#set($value = $where.get($key))
			#if ($vs.util.isList($value))
				#set($sql = $sql + " and " + $vs.sqlHelper.listIn($value, $key))
			#else
				#set($sql = $sql + $vs.sqlHelper.and($where, $key))
			#end
		#end
	#end
	return $sql
#end

/**
 * list2map
 * list转map:支持全量映射、单字段映射。
 * 
 * @param $list:list:列表。
 * @param $key:string:键字段域。
 * @param $field:string:值字段域。
 *
 * @return map
 *
 */ 
#function list2map($list, $key, $field)
	#if ($vs.util.isList($list))
		#set($map = $vs.util.newMap())
		#foreach($row in $list)
			#set($value = $row)
			#if (!$vs.util.isNull($field))
				#set($value = $row.get($field))
			#end
			$map.put($row.get($key), $value)
		#end
		return $map
	#end
	return null
#end

/**
 * listPut
 * 数据组装。
 *
 * @param $list:list:列表。
 * @param $map:map:映射。
 * @param $key:string:键。
 * @param $field:string:域。
 *
 * @return null
 *
 */ 
#function listPut($list, $map, $key, $field)
	#if ($vs.util.isList($list) and $vs.util.isMap($map) and $vs.util.isString($key))
		#if ($vs.util.isNull($field))
			#set($field = 'data')
		#end
		#foreach($item in $list)
			#set($itemKey = $item.get($key))
			#set($data = $map.get($itemKey))
			$item.put($field, $data)
		#end
	#end
	return null
#end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值