import Ignore_ExecPageFlipper as ExecPageFlipper
import com.sdtool.business.dao.SystemDao
import com.sdtool.common.api.NoSqlKeysService
import com.sdtool.common.datas.RedisKeys
import com.sdtool.common.entity.system.UserNoticeMessage
import com.dySweetFishPlugin.redis.RedisService
import com.sweetfish.source.PageFlipper
import org.rex.RMap

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

        redisService.del(keysService.getRedisKey(RedisKeys.KEY_ERP_USERNOTICEMESSAGE, supplierCode));
        ExecPageFlipper.execute(500, { PageFlipper p ->
            List<UserNoticeMessage> personList = systemDao.selectUserNoticeMessage(params, p, dataSourceId, supplierCode);

            if (!personList.isEmpty()) {
                Map<String, String> redisMap = personList.collectEntries { [it.messageCode + "-" + it.getIdUser() + "-0", "1"] }
                redisService.hmset(keysService.getRedisKey(RedisKeys.KEY_ERP_USERNOTICEMESSAGE, supplierCode), redisMap);
            }
        })
    } as Runnable
}

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




