谷神后端代码模块化:更新

更新
// selectOneById
#set($old = @selectOneById($strTableName, $data, $idKey, $lockKey, $tipMsg))
#set($where = $old.where)
#set($one = $old.one)

// TODO 操作

// updateAndRefresh
@updateAndRefresh($strTableName, $data, $optimisticLockKey, $optimisticLockValue, $where, $strMsg)



/**
 * selectOneById
 * 查询唯一:ID。
 *
 * @param $strTableName:string:表名。
 * @param $data:map:数据。
 * @param $idKey:string:ID。
 * @param $lockKey:string:乐观锁键。
 * @param $tipMsg:string:消息。
 *
 * @return map
 *
 */
#function selectOneById($strTableName, $data, $idKey, $lockKey, $tipMsg)
	#if ($vs.util.isString($strTableName) and $vs.util.isMap($data) and $vs.util.isString($idKey))
		#if ($vs.util.isNull($tipMsg))
			#set($tipMsg = '数据已变更,请刷新重试!')
		#end
		#set($result = $vs.util.newMap())
		#set($where = $vs.util.newMap())
		#set($result.where = $where)
		#set($idValue = $data.get($idKey))
		$vs.util.checkInput($idValue, 'ID不能为空!')
		$where.put($idKey, $idValue)
		#if ($vs.util.isString($lockKey))
			#set($lockValue = $data.get($lockKey))
			$vs.util.checkInput($lockValue, '乐观锁不能为空!')
			$where.put($lockKey, $lockValue)
		#end
		#set($one = $vs.dbTools.selectOne($strTableName, $where))
		$vs.util.checkInput($one, $tipMsg)
		#set($result.one = $one)
		return $result
	#end
	return null
#end

/**
 * updateAndRefresh
 * 更新:异常、乐观锁。
 *
 * @param $strTableName:string:表名。
 * @param $data:map:数据。
 * @param $optimisticLockKey:string:乐观锁键。
 * @param $optimisticLockValue:string:乐观锁值。
 * @param $where:map:条件。
 * @param $strMsg:string:消息。
 *
 * @return number:更新数量。
 *
 */
#function updateAndRefresh($strTableName, $data, $optimisticLockKey, $optimisticLockValue, $where, $strMsg)
	#if ($vs.util.isString($optimisticLockKey))
		$data.put($optimisticLockKey, $optimisticLockValue)
	#end
	#set($i = $vs.dbTools.update($strTableName, $data, $where))
	#if ($i != 1)
		#if ($vs.util.isNull($strMsg))
			#set($strMsg = '数据已变更,请刷新重试!')
		#end
		$vs.exception.throwException($strMsg)
	#end
	return $i
#end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值