import com.sdtool.business.dao.SystemDao
import com.sdtool.common.api.NoSqlKeysService
import com.sdtool.common.datas.RedisKeys
import com.sdtool.common.entity.system.Dept
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_DEPT, supplierCode))
        List<Dept> deptList = systemDao.queryAllDepts(params, dataSourceId, supplierCode)

        if (!deptList.isEmpty()) {
            Map<String, String> redisMap = deptList.collectEntries { [String.valueOf(it.getId()), jsonConvert.convertTo(it)] }
            redisService.hmset(keysService.getRedisKey(RedisKeys.KEY_DEPT, supplierCode), redisMap)
        }
    } as Runnable
}

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



