浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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

posted on 2012-08-03 16:58  lexus  阅读(323)  评论(0编辑  收藏  举报