@RequestMapping("/login") @ResponseBody public Response login(@RequestBody Map<String, Object> map) { Response res = new Response(); List<User> users = userService.login(map); if (users == null || users.size() == 0) { return res.failure("登陆失败"); } ShardedJedis shardedJedis = shardedJedisPool.getResource(); try { String skey = "session:" + users.get(0).getId(); String token = UUID.randomUUID().toString(); if (shardedJedis.exists(skey)) { String oldtoken = shardedJedis.get(skey); shardedJedis.del(skey); shardedJedis.del("token:" + oldtoken); } if (shardedJedis.setnx(skey, token) == 1) { shardedJedis.expire(skey, 3600 * 24); shardedJedis.hset("token:" + token, "name", users.get(0).getName()); shardedJedis.expire("token:" + token, 3600 * 24); } else { token = shardedJedis.get(skey); } Map<String, Object> data = new HashMap<>(); data.put("token", token); return new Response().success(data); } finally { shardedJedis.close(); } }
@RequestMapping("/queryUser") @ResponseBody public Response queryUser(@RequestBody Map<String, Object> map) { Response res = new Response(); List<User> users = userService.queryUser(map); if (map.containsKey("count")) { res.setCount((Integer) map.get("count")); } res.success(users); return res; }
@RequestMapping("/deleteUser") @ResponseBody public Response deleteUser(@RequestBody ArrayList<Integer> ids) { userService.deleteUser(ids); return new Response().success("删除用户成功"); }
@RequestMapping("/updateUser") @ResponseBody public Response updateUser(@RequestBody @Valid User user) { userService.updateUser(user); return new Response().success("修改用户成功"); }
@RequestMapping("/insertUser") @ResponseBody public Response insertUser(@RequestBody @Valid User user) { userService.insertUser(user); return new Response().success("新增用户成功"); }
@RequestMapping("/queryUserById") @ResponseBody public Response queryUserById(int id) { User user = userService.queryUserById(id); return new Response().success(user); }