diff --git a/src/main/java/com/yutou/tools/utils/NasDepotManager.java b/src/main/java/com/yutou/tools/utils/NasDepotManager.java new file mode 100644 index 0000000..0a55823 --- /dev/null +++ b/src/main/java/com/yutou/tools/utils/NasDepotManager.java @@ -0,0 +1,49 @@ +package com.yutou.tools.utils; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + + +@Controller +@RequestMapping("/nas/depot/") +public class NasDepotManager { + private static final String DEPOT_NAME = "nas_depot"; + + @ResponseBody + @RequestMapping("/add.do") + public JSONObject addNasPath(String path) { + JSONObject json=new JSONObject(); + long size=RedisTools.list_add(DEPOT_NAME, path); + if(size==0){ + json.put("code",0); + json.put("msg","添加失败"); + }else{ + json.put("code",1); + json.put("msg","添加成功"); + } + json.put("data", JSONArray.toJSON(RedisTools.list_get(DEPOT_NAME))); + return json; + + } + @ResponseBody + @RequestMapping("/list.do") + public JSONObject getNasList() { + JSONObject json=new JSONObject(); + json.put("code",1); + json.put("msg","ok"); + json.put("data", JSONArray.toJSON(RedisTools.list_get(DEPOT_NAME))); + return json; + } + @ResponseBody + @RequestMapping("/remove.do") + public JSONObject removeNas(String path) { + JSONObject json=new JSONObject(); + json.put("code",1); + json.put("msg","ok"); + json.put("data", RedisTools.list_remove(DEPOT_NAME, path)); + return json; + } +} diff --git a/src/main/java/com/yutou/tools/utils/RedisTools.java b/src/main/java/com/yutou/tools/utils/RedisTools.java index 2fbaa32..c77dc33 100644 --- a/src/main/java/com/yutou/tools/utils/RedisTools.java +++ b/src/main/java/com/yutou/tools/utils/RedisTools.java @@ -4,6 +4,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.util.HashSet; import java.util.Properties; import java.util.Set; @@ -146,6 +147,33 @@ public class RedisTools { } } + public static long list_add(String listName, String... value) { + Jedis jedis=getRedis(); + long index=jedis.sadd(listName,value); + jedis.close(); + return index; + } + public static Set list_get(String listName){ + Jedis jedis=getRedis(); + Set set=jedis.smembers(listName); + jedis.close(); + if(set==null){ + set=new HashSet<>(); + } + return set; + } + public static boolean list_remove(String listName,String... value){ + Jedis jedis=getRedis(); + long index=jedis.srem(listName,value); + jedis.close(); + return index != 0; + } + public static boolean list_isExist(String listName,String value){ + Jedis jedis=getRedis(); + boolean flag=jedis.sismember(listName,value); + jedis.close(); + return flag; + } private static class PropertyUtil { // 加载property文件到io流里面