如何prevent参数被再次使用?参数、prevent

2023-09-04 06:00:58 作者:豁达

这个答案后:

Why这些是哈希codeS等于?

我意识到,GetHash code打算是不提供的唯一标识符的对象。

I realized that GetHashCode intend is not to provide a unique identifier for an object.

本次测试的目的是,我有一个业务功能与6个参数:

The purpose of this test was that I have a business function with 6 parameters :

客户ID 服务ID 的startDate 结束日期 cmsThematicId customerId serviceId startDate EndDate cmsThematicId

我不希望能够调用不止一次此功能的详细使用相同的值

And I don't want to be able to call this function more than once with the same values

这些参数被插入到数据库中,我可以(客户ID = @CustomerID 服务ID = @serviceId ...),但我需要有效率与很多组合,所以这不是一个解决办法。

These parameters are inserted in the database, I could query with (customerId = @customerId and serviceId = @serviceId ...), but I need to be efficient with a lot of combination so this is not a solution.

编辑:

例如:

让我们说我有一个超级用户,他需要注册客户。登记的,由5个参数:客户ID,服务ID,的startDate,结束日期,cmsThematicId。登记的过程是这样的:

Let's say I have a super user he need to register customers. A registration is made of 5 parameters : customerId, serviceId, startDate, EndDate, cmsThematicId. The process of registering is like this :

您选择的服务(比如秀喜用大红色按钮) 您选择的客户(谁买了服务) 您选择cmsThematicId(网页,如果你想) 您选择起始日期(在下拉列表) 您选择结束日期(在下拉列表)

我的状态不能显示一组已使用的参数。

My form can't show a set of parameters that was already used.

例如一旦客户1被注册为服务页面假期在纽约的一月份的大红色按钮,超级用户将不会看到这些集的形式参数。

For instance once the customer 1 is registered for the service "big red button" on the page "holidays in new york" for the month of january, the super user won't be see these set of parameters in the form.

所以,我的方法做: - 创建所有的可能性, - 计算出每个可能的哈希值code在列表 - 让每个已经使用可能性的散列code(从DB) - 除去已经使用的可能性,从列表 - 显示表单

So my process did this : - create all the possibility - compute each possibility's hashcode in a List - get the hashcode of each already used possibility (from the db) - remove the already used possibility from the list - display the form

问题是:哈希code是不是唯一的,所以我可能会删除,即使不使用项目

problem is : hashcode are not unique , so I might remove a item even if it was not used.

是更清楚?

推荐答案

在每次通话后,在历史记录表中存储的6个值与综合指数。 在您的业务功能我想补充一个code,以验证这些值都在历史记录表中已经并立即退出,如果我发现这些值。

After each call, store your 6 values in a history table with a composed index. In your business function I would add a code to verify if those values are already in your history table and immediately exit if I found those values.

在以后编辑: 这是你应该怎么查询历史记录表:

LATER This is how you should query the History table:

IF EXISTS
  (SELECT customerId FROM HIstory WITH (NOLOCK) WHERE customerId='<value>' AND serviceId='<value>' AND <add all your fields here>)
    SELECT 1
ELSE
    SELECT 0

这样,如果已经有一个记录(这意味着你的业务功能已被调用正在测试的PARAMS),上面的查询返回1,否则为0。

This way, if there is already a record (meaning your business function has been already called with the params you are testing), the above query returns 1, otherwise 0.

所以,如果1,你需要停下来。

So if 1, you need to stop.

如果为0,则需要将值添加到历史表并执行业务逻辑。 OR:执行业务逻辑,那么该值添加到历史记录表

If 0, you need to add the values to history table and execute the business logic. OR: execute the business logic THEN add the values to history table.

EDIT2: 首先,你的历史记录表是空的。每次调用你的函数的意志:

Initially, your History table is empty. Each call to your function will:

查询Hitory表匹配作为参数传递的价值观,为你的函数现有值

Query the Hitory table for existing values that match the values passed as parameters to your function

如果需要填充的历史记录表。

Populate the History table if needed.

也就是说,你的函数所做的第一件事就是查询历史记录表(如果需要的话)来插入一组新值在该表中。 基本上,查询将获得每次打电话给你实现,因为该查询该函数中完成的功能执行。

That is, first thing your function does is to query the History table and (if needed) to insert a new set of values in that table. Basically the query will get executed each time you call the function you implemented because the query is done inside that function.

 
精彩推荐
图片推荐