import com.sdtool.business.dao.DesignDao
import com.sdtool.common.api.NoSqlKeysService
import com.sdtool.common.datas.RedisKeys
import com.sdtool.common.entity.design.DesignFont
import com.dySweetFishPlugin.redis.RedisService
import com.sweetfish.convert.json.JsonConvert
import com.sweetfish.source.PageFlipper
import org.apache.logging.log4j.Logger
import org.rex.RMap

/**
 * @Author: xl Created on 2024-05-11
 * @Content:
 */

static def createRunnable(RedisService redisService, NoSqlKeysService keysService,
                          DesignDao designDao, Logger logger, JsonConvert jsonConvert, String dataSourceId, long supplierCode) {
    RMap params = new RMap()
    return {
        redisService.del(keysService.getRedisKey(RedisKeys.KEY_DESIGNER_DESIGN_FONT, supplierCode))
        Ignore_ExecPageFlipper.execute(1000, { PageFlipper p ->
            List<DesignFont> designFontList = designDao.selectDesignFonts(params, dataSourceId, supplierCode, p)
            if (!designFontList.isEmpty()) {
                Map<String, String> redisMap = designFontList.collectEntries { [String.valueOf(it.getId()), jsonConvert.convertTo(it)] }
                redisService.hmset(keysService.getRedisKey(RedisKeys.KEY_DESIGNER_DESIGN_FONT, supplierCode), redisMap)
                logger.info("设计字体共" + designFontList.size() + "条记录")
            }
        })
    } as Runnable
}

createRunnable(redisService, keysService, designDao, logger, jsonConvert, dataSourceId, supplierCode)