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