1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.moral.api.controller;
 
import com.moral.api.pojo.dto.LoginDTO;
import com.moral.api.service.ManageAccountService;
import com.moral.constant.Constants;
import com.moral.constant.ResultMessage;
import com.moral.util.ObjectUtils;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
 
@Slf4j
@Api(tags = {"后台账户管理"})
@RestController
@RequestMapping("/account")
public class AccountController {
    @Resource
    ManageAccountService accountService;
    @Autowired
    @Qualifier("tokenRedisTemplate")
    RedisTemplate redisTemplate;
 
 
    @PostMapping("login")
    public ResultMessage login(@RequestBody Map<String, Object> parameters) {
        if (!ObjectUtils.isNotAllEmpty(parameters, "account", "password"))
            return ResultMessage.fail(Constants.CODE_PARAMETER_IS_MISSING,Constants.MSG_PARAMETER_IS_MISSING);
        String AESAccount = (String) parameters.get("account");
        String AESPassword = (String) parameters.get("password");
 
        LoginDTO loginDTO = accountService.login(AESAccount,AESPassword);
 
        if(loginDTO.getCode().equals(LoginDTO.SUCCESS))
            return ResultMessage.ok(loginDTO);
        return ResultMessage.fail(loginDTO);
    }
 
 
    @PostMapping("logout")
    public ResultMessage logout(@RequestBody Map<String, Object> parameters, HttpServletRequest request) {
        if(!ObjectUtils.isNotAllEmpty(parameters,"accountId"))
            return ResultMessage.fail(Constants.CODE_PARAMETER_IS_MISSING,Constants.MSG_PARAMETER_IS_MISSING);
        String token = request.getHeader("token");
 
        if(accountService.logout(String.valueOf(parameters.get("accountId")),token))
            return ResultMessage.ok("注销成功");
        return ResultMessage.fail("注销异常");
 
    }
 
 
}