阅读 58

groovy parttion and sql example

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)
}

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐