import com.sdtool.business.dao.SystemDao
import com.sdtool.common.api.NoSqlKeysService
import com.sdtool.common.datas.RedisKeys
import com.sdtool.common.entity.system.NoticeMessage
import com.dySweetFishPlugin.redis.RedisService
import com.sweetfish.convert.json.JsonConvert
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_ERP_NOTICEMESSAGE, supplierCode))
        List<NoticeMessage> dataList = systemDao.selectAllNoticeMessage(params, dataSourceId, supplierCode)
        if (!dataList.isEmpty()) {
            Map<String, String> redisMap = dataList.collectEntries { [String.valueOf(it.getId()), jsonConvert.convertTo(it)] }
            redisService.hmset(keysService.getRedisKey(RedisKeys.KEY_ERP_NOTICEMESSAGE, supplierCode), redisMap)
        }
    } as Runnable
}

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



