import com.sdtool.business.dao.SystemDao
import com.sdtool.common.api.NoSqlKeysService
import com.sdtool.common.datas.RedisKeys
import com.sdtool.common.entity.site.SiteContent
import com.dySweetFishPlugin.redis.RedisService
import com.sweetfish.convert.json.JsonConvert
import com.sweetfish.source.PageFlipper
import org.rex.RMap

static def createRunnable(RedisService redisService, NoSqlKeysService keysService, SystemDao systemDao, JsonConvert jsonConvert, String dataSourceId, long supplierCode) {
    return {
        RMap params = new RMap()

        redisService.del(keysService.getRedisKey(RedisKeys.KEY_SITE_CONTENT, supplierCode))

        Ignore_ExecPageFlipper.execute(500, { PageFlipper p ->

            List<SiteContent> siteContentList = systemDao.selectSiteContent(params, p, dataSourceId, supplierCode)

            Map<String, String> siteContentMap = siteContentList.collectEntries { [String.valueOf(it.getId()), jsonConvert.convertTo(it)] }

            if (!siteContentMap.isEmpty()) {
                redisService.hmset(keysService.getRedisKey(RedisKeys.KEY_SITE_CONTENT, supplierCode), siteContentMap)
            }
        })
    } as Runnable
}

//groovy最后一个表达式的值为返回
createRunnable(redisService, keysService, systemDao, jsonConvert, dataSourceId, supplierCode)


