Skip to content

Instantly share code, notes, and snippets.

@coderberry
Created March 29, 2011 17:05
Show Gist options
  • Select an option

  • Save coderberry/892766 to your computer and use it in GitHub Desktop.

Select an option

Save coderberry/892766 to your computer and use it in GitHub Desktop.
Blog Post 3
/**
* Count duplicate submissions within 45 days
* SELECT count(l.id)
* FROM lead AS l, submission AS s, buyerLog as bl
* WHERE l.id = s.leadId
* AND s.id = bl.submissionId
* AND bl.leadBuyer = $buyerName
* AND l.id != $lead.id
* AND l.dateCreated::date > $daysAgo
*/
protected def Boolean isDuplicateSubmission(Lead lead, ArrayList<String> buyerNames) {
def isDuplicate = false
def daysAgo = new Date() - 45
def cnt = Lead.withCriteria {
not {
idEq(lead.id)
}
and {
le('dateCreated', daysAgo)
submissions {
buyerLogs {
inList('leadBuyer', buyerNames)
}
}
}
projections {
rowCount()
}
}
return (cnt > 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment