Files
jsowell-charger-web/jsowell-admin/src/main/java/com/jsowell/api/uniapp/AuthCardController.java

125 lines
4.6 KiB
Java
Raw Normal View History

package com.jsowell.api.uniapp;
import com.alibaba.fastjson2.JSONObject;
import com.jsowell.common.annotation.Anonymous;
import com.jsowell.common.core.controller.BaseController;
2023-05-24 09:58:01 +08:00
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
2023-05-24 09:58:01 +08:00
import com.jsowell.pile.dto.MemberRegisterAndLoginDTO;
import com.jsowell.pile.dto.PileAuthCardDTO;
import com.jsowell.pile.service.IPileAuthCardService;
import com.jsowell.pile.vo.uniapp.AuthCardVO;
2023-05-24 09:58:01 +08:00
import com.jsowell.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* 鉴权卡相关
*
* @author JS-ZZA
* @date 2023/5/23 9:32
*/
@Anonymous
@RestController
@RequestMapping("/uniapp/authCard")
public class AuthCardController extends BaseController {
@Autowired
private IPileAuthCardService pileAuthCardService;
2023-05-24 09:58:01 +08:00
@Autowired
private MemberService memberService;
/**
* 查询鉴权卡列表
2023-05-24 09:58:01 +08:00
* http://localhost:8080/uniapp/authCard/getAuthCardList
* @param request
* @return
*/
@GetMapping("/getAuthCardList")
public RestApiResponse<?> getAuthCardList(HttpServletRequest request) {
RestApiResponse<?> response = null;
try {
String memberId = getMemberIdByAuthorization(request);
logger.info("查询用户鉴权卡列表 param memberId:{}", memberId);
List<AuthCardVO> list = pileAuthCardService.getAuthCardListByMemberId(memberId);
response = new RestApiResponse<>(list);
} catch (Exception e) {
logger.error("查询鉴权卡列表 error", e);
response = new RestApiResponse<>(e);
}
logger.info("查询用户鉴权卡列表 result : {}", response);
return response;
}
/**
* 用户绑定鉴权卡
2023-05-24 09:58:01 +08:00
* http://localhost:8080/uniapp/authCard/bindAuthCard
* @param dto
* @return
*/
@PostMapping("/bindAuthCard")
public RestApiResponse<?> bindAuthCard(HttpServletRequest request, @RequestBody PileAuthCardDTO dto) {
logger.info("用户绑定鉴权卡 params: {}", JSONObject.toJSONString(dto));
2023-05-24 09:58:01 +08:00
RestApiResponse<?> response = null;
try {
String memberId = getMemberIdByAuthorization(request);
2023-05-24 09:58:01 +08:00
if (memberId == null) {
throw new BusinessException(ReturnCodeEnum.CODE_AUTHENTICATION_ERROR);
}
2023-05-24 09:58:01 +08:00
dto.setMemberId(memberId);
// 校验短信验证码
MemberRegisterAndLoginDTO registerAndLoginDTO = MemberRegisterAndLoginDTO.builder()
.mobileNumber(dto.getPhoneNumber())
.verificationCode(dto.getVerificationCode())
.build();
memberService.checkVerificationCode(registerAndLoginDTO);
int i = pileAuthCardService.bindAuthCard(dto);
response = new RestApiResponse<>(i);
}catch (BusinessException e){
logger.warn("用户绑定鉴权卡 warn:", e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
} catch (Exception e) {
2023-05-24 09:58:01 +08:00
logger.error("用户绑定鉴权卡 error", e);
response = new RestApiResponse<>(e);
}
2023-05-24 09:58:01 +08:00
logger.info("用户绑定鉴权卡 result:{}", response);
return response;
}
2023-05-24 10:55:55 +08:00
/**
* 用户解绑鉴权卡
* http://localhost:8080/uniapp/authCard/unbindAuthCard
* @param dto
* @return
*/
@PostMapping("/unbindAuthCard")
public RestApiResponse<?> unbindAuthCard(HttpServletRequest request, @RequestBody PileAuthCardDTO dto) {
logger.info("用户解绑鉴权卡 params:{}", JSONObject.toJSONString(dto));
RestApiResponse<?> response = null;
try {
String memberId = getMemberIdByAuthorization(request);
if (memberId == null) {
throw new BusinessException(ReturnCodeEnum.CODE_AUTHENTICATION_ERROR);
}
dto.setMemberId(memberId);
pileAuthCardService.unbindAuthCard(dto);
response = new RestApiResponse<>();
} catch (BusinessException e) {
logger.warn("用户解绑鉴权卡 warn ", e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
}catch (Exception e) {
logger.warn("用户解绑鉴权卡 error ", e);
response = new RestApiResponse<>(e);
}
logger.info("用户解绑鉴权卡 result :{}", response);
return response;
}
}