package com.example.xiaoshiweixinback.controller; import com.example.xiaoshiweixinback.business.common.Constants; import com.example.xiaoshiweixinback.business.common.Response; import com.example.xiaoshiweixinback.entity.dto.person.*; import com.example.xiaoshiweixinback.entity.vo.person.LoginByWxVO; import com.example.xiaoshiweixinback.entity.vo.person.LoginVO; import com.example.xiaoshiweixinback.entity.vo.person.PersonVO; import com.example.xiaoshiweixinback.service.LoginService; import io.swagger.v3.oas.annotations.Operation; import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.HashMap; import java.util.Map; /** * 登录相关接口 * * @author: 高昌奎 */ @RequestMapping(Constants.XIAOSHI_WEIXINBACK + "/account") @RestController public class LoginController { @Autowired private LoginService loginService; @Operation(summary = "手机号/账号登录") @PostMapping(value = "/loginByPhone") public Response loginByPhone(@Valid @RequestBody LoginDTO vo) { LoginVO loginVO = null; try { loginVO = loginService.loginByPhone(vo); } catch (Exception e) { return Response.error(e.getMessage()); } return Response.success(loginVO); } @Operation(summary = "微信小程序登录") @PostMapping(value = "/loginByWeChat") public Response loginByWeChat(@Valid @RequestBody LoginByWxDTO wxDTO) throws Exception { LoginByWxVO loginByWxVO = null; try { loginByWxVO = loginService.loginByWeChat(wxDTO); } catch (Exception e) { return Response.error(e.getMessage()); } return Response.success(loginByWxVO); } @Operation(summary = "发送验证码") @PostMapping("/sendCode") public Response sendCode(@RequestBody @Valid SendCodeDTO vo) { boolean b = false; try { b = loginService.sendCode(vo); } catch (Exception e) { return Response.error(e.getMessage()); } return Response.success(b); } @PostMapping("/verifyCode") @Operation(summary = "生成校验码") public Response verifyCode(@RequestBody @Valid PersonPhoneDTO vo) throws Exception { Map map = new HashMap<>(); try { map = loginService.verifyCode(vo); } catch (Exception e) { return Response.error(e.getMessage()); } return Response.success(map); } @PostMapping("/selectPerson") @Operation(summary = "查询个人信息") public Response selectPerson(@RequestBody PersonIdDTO vo) throws Exception { PersonVO personVO = null; try { personVO = loginService.selectPerson(vo); } catch (Exception e) { return Response.unLogin(e.getMessage()); } return Response.success(personVO); } @PostMapping("/editPerson") @Operation(summary = "修改个人信息") public Response editPerson(@RequestBody EditPersonDTO vo) throws Exception { boolean b = true; try { b = loginService.editPerson(vo); } catch (Exception e) { return Response.error(e.getMessage()); } return Response.success(b); } @PostMapping("/logout") @Operation(summary = "退出登录") public Response logout(PersonIdDTO dto) { return Response.success(loginService.logout(dto)); } }