import com.sdtool.business.dao.SystemDao
import com.sdtool.common.api.NoSqlKeysService
import com.sdtool.common.datas.RedisKeys
import com.sdtool.common.entity.system.Menu
import com.dySweetFishPlugin.redis.RedisService
import com.sweetfish.convert.json.JsonConvert
import org.rex.RMap

//def task = { RedisService redisService, NoSqlKeysService keysService, SystemDao systemDao, JsonConvert jsonConvert, String dataSourceId, long supplierCode ->
//    RMap params = new RMap<>()
//
//    redisService.del(keysService.getRedisKey(RedisKeys.KEY_SYSMENUS, supplierCode))
//
//    List<Menu> menuList = systemDao.queryAllMenus(params, dataSourceId, supplierCode)
//    //直接写入到redis，取出交给服务需要进行子集处理
//    Map<String, String> menuMap = menuList.collectEntries { [String.valueOf(it.getId()), jsonConvert.convertTo(it)] }
//    if (!menuMap.isEmpty()) {
//        redisService.hmset(keysService.getRedisKey(RedisKeys.KEY_SYSMENUS, supplierCode), menuMap)
//    }
//} as Runnable
//
//return task(redisService)

//使用上面的写法报错，只能用下面的写法，ide有警告不纠结了，还有一种写法，写一个实现Runnable的class，不如现在看着舒服
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_SYSMENUS, supplierCode))

        List<Menu> menuList = systemDao.queryAllMenus(params, dataSourceId, supplierCode)
        //直接写入到redis，取出交给服务需要进行子集处理
        Map<String, String> menuMap = menuList.collectEntries { [String.valueOf(it.getId()), jsonConvert.convertTo(it)] }
        if (!menuMap.isEmpty()) {
            redisService.hmset(keysService.getRedisKey(RedisKeys.KEY_SYSMENUS, supplierCode), menuMap)
        }
    } as Runnable
}

//groovy最后一个表达式的值为返回，下面的警告用这种写法去不掉，因为参数是java传递过来的
createRunnable(redisService, keysService, systemDao, jsonConvert, dataSourceId, supplierCode)
