content: package com.zyh432.server.modules.user.controller;
  
  import com.zyh432.core.response.Data;
  import com.zyh432.core.utils.IdUtil;
  import com.zyh432.server.common.annotation.LoginIgnore;
  import com.zyh432.server.common.utils.UserIdUtil;
  import com.zyh432.server.modules.user.context.*;
  import com.zyh432.server.modules.user.converter.UserConverter;
  import com.zyh432.server.modules.user.po.*;
  import com.zyh432.server.modules.user.service.IUserService;
  import com.zyh432.server.modules.user.vo.UserInfoVO;
  import io.swagger.annotations.Api;
  import io.swagger.annotations.ApiOperation;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.MediaType;
  import org.springframework.validation.annotation.Validated;
  import org.springframework.web.bind.annotation.*;
  
  /**
   * 该类是用户模块的控制器实体
   */
  @RestController
  @RequestMapping("user")
  @Api(tags = "用户模块")
  public class UserController {
      @Autowired
      private IUserService iUserService;
      @Autowired
      private UserConverter userConverter;
  
      @ApiOperation(
              value = "用户注册接口",
              notes = "该接口提供了用户注册的功能，实现了冥等性注册的逻辑，可以放心多并发调用",
              consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
              produces = MediaType.APPLICATION_JSON_UTF8_VALUE
      )
      @LoginIgnore
      @PostMapping("/register")
      public Data register(@Validated @RequestBody UserRegisterPO userRegisterPO){
          UserRegisterContext userRegisterContext= userConverter.userRegisterPO2UserRegisterContext(userRegisterPO);
          Long userId= iUserService.register(userRegisterContext);
          return Data.data(IdUtil.encrypt(userId));
      }
  
      @ApiOperation(
              value = "用户登录接口",
              notes = "该接口提供了用户登录的功能，成功登陆之后，会返回有时效性的accessToken供后续服务使用",
              consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
              produces = MediaType.APPLICATION_JSON_UTF8_VALUE
      )
      @LoginIgnore
      @PostMapping("/login")
      public Data login(@Validated @RequestBody UserLoginPO userLoginPO){
          UserLoginContext userLoginContext = userConverter.userLoginPO2UserLoginContext(userLoginPO);
          String accessToken= iUserService.login(userLoginContext);
          return Data.data(accessToken);
      }
  
      @ApiOperation(
              value = "用户登出接口",
              notes = "该接口提供了用户登出的功能",
              consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
              produces = MediaType.APPLICATION_JSON_UTF8_VALUE
      )
      @PostMapping("/exit")
      public Data exit(){
          iUserService.exit(UserIdUtil.get());
          return Data.success();
      }
  
      @ApiOperation(
              value = "用户忘记密码-校验用户名",
              notes = "该接口提供了用户忘记密码-校验用户名的功能",
              consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
              produces = MediaType.APPLICATION_JSON_UTF8_VALUE
      )
      @LoginIgnore
      @PostMapping("/username/check")
      public Data checkUsername(@Validated @RequestBody CheckUsernamePO checkUsernamePO){
          CheckUsernameContext checkUsernameContext = userConverter.checkUsernamePO2CheckUsernameContext(checkUsernamePO);
          String question= iUserService.checkUsername(checkUsernameContext);
          return Data.data(question);
      }
  
      @ApiOperation(
              value = "用户忘记密码-校验密保答案",
              notes = "该接口提供了用户忘记密码-校验密保答案的功能",
              consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
              produces = MediaType.APPLICATION_JSON_UTF8_VALUE
      )
      @LoginIgnore
      @PostMapping("answer/check")
      public Data checkAnswer(@Validated @RequestBody CheckAnswerPO checkAnswerPO) {
          CheckAnswerContext checkAnswerContext = userConverter.checkAnswerPO2CheckAnswerContext(checkAnswerPO);
          String token = iUserService.checkAnswer(checkAnswerContext);
          return Data.data(token);
      }
  
      @ApiOperation(
              value = "用户忘记密码-重置新密码",
              notes = "该接口提供了用户忘记密码-重置新密码的功能",
              consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
              produces = MediaType.APPLICATION_JSON_UTF8_VALUE
      )
      @PostMapping("password/reset")
      @LoginIgnore
      public Data resetPassword(@Validated @RequestBody ResetPasswordPO resetPasswordPO){
          ResetPasswordContext resetPasswordContext = userConverter.resetPasswordPO2ResetPasswordContext(resetPasswordPO);
          iUserService.resetPassword(resetPasswordContext);
          return Data.success();
      }
  
      @ApiOperation(
              value = "用户在线修改密码",
              notes = "该接口提供了用户在线修改密码的功能",
              consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
              produces = MediaType.APPLICATION_JSON_UTF8_VALUE
      )
      @PostMapping("password/change")
      public Data changePassword(@Validated @RequestBody ChangePasswordPO changePasswordPO){
          ChangePasswordContext changePasswordContext = userConverter.changePasswordPO2ChangePasswordContext(changePasswordPO);
          changePasswordContext.setUserId(UserIdUtil.get());
          iUserService.changePassword(changePasswordContext);
          return Data.success();
  
      }
  
      @ApiOperation(
              value = "查询登录用户的基本信息",
              notes = "该接口提供了查询登录用户的基本信息的功能",
              consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
              produces = MediaType.APPLICATION_JSON_UTF8_VALUE
      )
      @GetMapping("/")
      public Data<UserInfoVO> info(){
          UserInfoVO userInfoVO= iUserService.info(UserIdUtil.get());
          return Data.data(userInfoVO);
      }
  }
  