唯一性校验:数据库
#function checkUnique($strTableName, $data, $field, $idKey, $strMsg)
#if ($vs.util.isBlankOne($strTableName, $data, $field, $idKey))
return null
#end
#set($strSql = `
select count(0) from ${$strTableName} where ${$field} = #{${$field}}
`)
#set($where = $vs.util.newMap())
$where.put($field, $data.get($field))
#set($id = $data.get($idKey))
#if ($vs.util.isNotNull($id))
$where.put($idKey, $id)
#set($strSql = $strSql + `
and ${$idKey} != #{${$idKey}}
`)
#end
#set($count = $vs.dbTools.countSQL($strSql,$where))
#if ($vs.util.isNotNull($strMsg) and $count > 0)
$vs.exception.throwException($strMsg)
#end
return $count
#end