groovy parttion and sql example

groovy parttion and sql example,第1张

def partition(array, size) {
    def partitions = []
    int partitionCount = array.size() / size

    partitionCount.times { partitionNumber ->
        def start = partitionNumber * size
        def end = start + size - 1
        partitions << array[start..end]   
    }

    if (array.size() % size) partitions << array[partitionCount * size..-1]
    return partitions   
}

import groovy.sql.Sql
def dataSource=__ac.getBean("dataSource")
def popDataSource=__ac.getBean('popDataSource')

def mysql=new Sql(dataSource)
def mysql2=new Sql(popDataSource)

println mysql.firstRow("select count(*) as cnt from target_url where website_id=1 and status=0 or status=-2").cnt
def skus=[]
mysql.eachRow("select sku from target_url where website_id=1 and status=0 or status=-2")
{
skus <<it.sku
}
println skus.size()

partition(skus,1000).each{k->
//println k
def s= k.join(",")
def update_sql= "update opponent_product set available=0 where sku in ('${s}')"
//println update_sql
println mysql2.execute(update_sql)
}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/2083816.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-07-22
下一篇 2022-07-22

发表评论

登录后才能评论

评论列表(0条)

保存