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.annotations.UserAuth; import com.xcong.excoin.common.response.Result; import com.xcong.excoin.modules.member.entity.MemberEntity; 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.*; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.validation.annotation.Validated; 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 @Validated TestUserDto testUserDto, @UserAuth MemberEntity memberEntity) { log.info("--->{}",SecurityContextHolder.getContext().getAuthentication()); log.info("----->{}", memberEntity); Page page = new Page<>(pageNum, pageSize); IPage list = testUserService.page(page); IPage aa = TestUserEntityMapper.INSTANCE.pageEntityToPageVO(list); return Result.ok(MessageSourceUtils.getString("111"), aa); } @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 = "修改测试用户", notes = "该接口用户修改测试用户") @PostMapping(value = "/modify") public Result modify(@RequestBody @Validated TestUserDto testUserDto) { TestUserEntity testUserEntity = TestUserEntityMapper.INSTANCE.dtoToEntity(testUserDto); log.info("#-------->{}#", testUserEntity); boolean flag = testUserService.updateById(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(@ApiParam(name = "id", value = "用户ID", required = true, example = "1") @PathVariable(value = "id") Long id) { TestUserEntity testUserEntity = testUserService.getById(id); TestUserVo testUserVo = TestUserEntityMapper.INSTANCE.entityToVo(testUserEntity); return Result.ok("success", testUserVo); } @ApiOperation(value = "根据Id查询用户信息", notes = "根据Id查询用户信息") @GetMapping(value = "/findByIdAndName/{id}/{name}") public Result findByIdAndName(@ApiParam(name = "id", value="用户ID", required = true, example = "1") @PathVariable(value = "id") Long id, @ApiParam(name = "name", value="用户姓名", required = true, example = "wzy") @PathVariable(value = "name") String name) { log.info("---->{}", id); log.info("----<{}", name); return Result.ok("success"); } }