loadMap
@loadMap($src, $field, $strTableName, $key, $target, $other, $systemId)
#function loadMap($src, $field, $strTableName, $key, $target, $other, $systemId)
#set($where = $vs.util.newMap())
#if ($vs.util.isMap($other))
$where.putAll($other)
#end
#set($fields = @collectSet($src, $field))
$where.put($key, $fields)
#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, null))
@listPut($src, $map, $field, $target)
#foreach ($row in $src)
#if (!$vs.util.isMap($row.get($target)))
$row.put($target, $vs.util.newMap())
#end
#end
return $src
#end
#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
#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
#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
#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
#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