Helius
2020-05-13 d0de0bf06f69c8584330e857ec1ecce34b244c9f
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.xcong.excoin.modules.test.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.test.dto.TestUserDto;
import com.xcong.excoin.modules.test.entity.TestUserEntity;
import com.xcong.excoin.modules.test.mapper.TestUserEntityMapper;
import com.xcong.excoin.modules.test.service.TestUserService;
import com.xcong.excoin.modules.test.vo.TestUserVo;
import com.xcong.excoin.utils.MessageSourceUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.validation.Valid;
 
/**
 * @author wzy
 * @date 2020-04-24 15:25
 **/
@RestController
@RequestMapping(value = "/test")
@Slf4j
@Api(value = "这是测试用类", tags = "这是测试用类")
public class TestUserController {
 
    @Resource
    private TestUserService testUserService;
 
    @ApiOperation(value = "测试用户分页请求", notes = "说明")
    @ApiResponses({@ApiResponse(code = 0, message = "ok", response = TestUserVo.class)})
    @PostMapping(value = "/findUserInPage")
    public Result findUserInPage(@RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                                 @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                 @RequestBody @Valid TestUserDto testUserDto) {
        log.info("--->{}",SecurityContextHolder.getContext().getAuthentication());
        Page<TestUserEntity> page = new Page<>(pageNum, pageSize);
        log.info(testUserDto.getName());
        IPage<TestUserEntity> list = testUserService.page(page);
        return Result.ok(MessageSourceUtils.getString("111"), list);
    }
 
 
    @ApiOperation(value = "添加测试用户", notes = "该接口用于添加测试用户")
    @PostMapping(value = "/add")
    public Result add(@RequestBody @Valid TestUserDto testUserDto) {
        TestUserEntity testUserEntity = TestUserEntityMapper.INSTANCE.dtoToEntity(testUserDto);
        boolean flag = testUserService.save(testUserEntity);
        if (flag) {
            return Result.ok("success");
        }
        return Result.fail("fail");
    }
 
    @ApiOperation(value = "根据ID删除用户", notes = "根据ID删除用户")
    @GetMapping(value = "/del/{id}")
    public Result del(@PathVariable(value = "id") Long id) {
        boolean flag = testUserService.removeById(id);
        if (flag) {
            return Result.ok("success");
        }
        return Result.fail("fail");
    }
 
    @ApiOperation(value = "根据Id查询用户信息", notes = "根据Id查询用户信息")
    @GetMapping(value = "/findById/{id}")
    public Result findById(@PathVariable(value = "id") Long id) {
        TestUserEntity testUserEntity = testUserService.getById(id);
        TestUserVo testUserVo = TestUserEntityMapper.INSTANCE.entityToVo(testUserEntity);
        return Result.ok("success", testUserVo);
    }
}