diff --git a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/CarVinController.java b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/CarVinController.java new file mode 100644 index 000000000..696e40761 --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/CarVinController.java @@ -0,0 +1,89 @@ +package com.jsowell.api.uniapp; + +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.annotation.Anonymous; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.response.RestApiResponse; +import com.jsowell.pile.dto.CarVinDTO; +import com.jsowell.pile.dto.MemberRegisterAndLoginDTO; +import com.jsowell.pile.service.ICarVinInfoService; +import com.jsowell.pile.vo.CarVinInfoVO; +import com.jsowell.pile.vo.uniapp.AuthCardVO; +import com.jsowell.service.MemberService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +/** + * TODO + * + * @author JS-ZZA + * @date 2023/6/8 13:56 + */ +@Anonymous +@RestController +@RequestMapping("/uniapp/carVin") +public class CarVinController extends BaseController { + + @Autowired + private ICarVinInfoService carVinInfoService; + + @Autowired + private MemberService memberService; + + /** + * 用户查询绑定的vin列表 + * @param request + * @return + */ + @PostMapping("/getCarVinList") + public RestApiResponse getCarVinList(HttpServletRequest request){ + RestApiResponse response = null; + try { + String memberId = getMemberIdByAuthorization(request); + logger.info("查询用户Vin列表 param memberId:{}", memberId); + List list = carVinInfoService.getCarVinListByMemberId(memberId); + response = new RestApiResponse<>(list); + } catch (Exception e) { + logger.error("查询用户Vin列表 error", e); + response = new RestApiResponse<>(e); + } + logger.info("查询用户Vin列表 result : {}", response); + return response; + } + + @PostMapping("/bindCarVin") + public RestApiResponse bindCarVin(HttpServletRequest request, CarVinDTO dto) { + logger.info("用户绑定Vin 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); + // 校验短信验证码 + MemberRegisterAndLoginDTO registerAndLoginDTO = MemberRegisterAndLoginDTO.builder() + .mobileNumber(dto.getPhoneNumber()) + .verificationCode(dto.getVerificationCode()) + .build(); + memberService.checkVerificationCode(registerAndLoginDTO); + int i = carVinInfoService.bindAuthCard(dto); + response = new RestApiResponse<>(i); + }catch (BusinessException e){ + logger.warn("用户绑定Vin warn:", e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + } catch (Exception e) { + logger.error("用户绑定Vin error", e); + response = new RestApiResponse<>(e); + } + logger.info("用户绑定Vin result:{}", response); + return response; + } +} diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/ReturnCodeEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/ReturnCodeEnum.java index 2406cd186..16667e7f6 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/ReturnCodeEnum.java +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/ReturnCodeEnum.java @@ -146,6 +146,7 @@ public enum ReturnCodeEnum { CODE_THIS_CARD_BIND_INFO_ERROR("00600006", "卡绑定信息有误!"), + CODE_SELECT_INFO_IS_NULL("00700001", "查询信息为空!"), ; private String value; diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/CarVinDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/CarVinDTO.java new file mode 100644 index 000000000..aa16ecb92 --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/CarVinDTO.java @@ -0,0 +1,20 @@ +package com.jsowell.pile.dto; + +import lombok.Data; + +/** + * 车辆vinDTO + * + * @author JS-ZZA + * @date 2023/6/8 15:02 + */ +@Data +public class CarVinDTO { + private String vinCode; + + private String memberId; + + private String phoneNumber; + + private String verificationCode; +} diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/CarVinInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/CarVinInfoMapper.java index 6b1723949..4ea336aaa 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/CarVinInfoMapper.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/CarVinInfoMapper.java @@ -75,4 +75,11 @@ public interface CarVinInfoMapper { * @return */ CarVinInfoVO getMemberInfoByVinCode(String vinCode); + + /** + * 通过memberId查询绑定的车辆vin列表 + * @param memberId + * @return + */ + List getCarVinListByMemberId(String memberId); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/ICarVinInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/ICarVinInfoService.java index 7a40bc992..5b1c55849 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/ICarVinInfoService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/ICarVinInfoService.java @@ -3,7 +3,9 @@ package com.jsowell.pile.service; import java.util.List; import com.jsowell.pile.domain.CarVinInfo; +import com.jsowell.pile.dto.CarVinDTO; import com.jsowell.pile.vo.CarVinInfoVO; +import com.jsowell.pile.vo.uniapp.AuthCardVO; /** * 车辆vin码Service接口 @@ -74,4 +76,17 @@ public interface ICarVinInfoService { */ CarVinInfoVO getMemberInfoByVinCode(String vinCode); + /** + * 通过memberId查询绑定的车辆vin列表 + * @param memberId + * @return + */ + List getCarVinListByMemberId(String memberId); + + /** + * 用户绑定车辆vin + * @param dto + * @return + */ + int bindAuthCard(CarVinDTO dto); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/CarVinInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/CarVinInfoServiceImpl.java index ff062aa1c..289900743 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/CarVinInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/CarVinInfoServiceImpl.java @@ -3,7 +3,13 @@ package com.jsowell.pile.service.impl; import java.math.BigDecimal; import java.util.List; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.StringUtils; +import com.jsowell.pile.domain.MemberBasicInfo; +import com.jsowell.pile.dto.CarVinDTO; +import com.jsowell.pile.service.IMemberBasicInfoService; import com.jsowell.pile.vo.CarVinInfoVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -22,6 +28,9 @@ public class CarVinInfoServiceImpl implements ICarVinInfoService { @Autowired private CarVinInfoMapper carVinInfoMapper; + @Autowired + private IMemberBasicInfoService memberBasicInfoService; + /** * 查询车辆vin码 * @@ -114,4 +123,44 @@ public class CarVinInfoServiceImpl implements ICarVinInfoService { memberInfo.setAccountBalance(memberInfo.getPrincipalBalance().add(memberInfo.getGiftBalance()).setScale(2, BigDecimal.ROUND_HALF_UP)); return memberInfo; } + + /** + * 通过memberId查询绑定的车辆vin列表 + * @param memberId + * @return + */ + @Override + public List getCarVinListByMemberId(String memberId) { + return carVinInfoMapper.getCarVinListByMemberId(memberId); + } + + /** + * 用户绑定车辆vin + * @param dto + * @return + */ + @Override + public int bindAuthCard(CarVinDTO dto) { + String phoneNumber = dto.getPhoneNumber(); + // 判断此用户是否已注册小程序账号 + MemberBasicInfo memberBasicInfo = memberBasicInfoService.selectInfoByMobileNumber(phoneNumber); + if (memberBasicInfo == null) { + throw new BusinessException(ReturnCodeEnum.CODE_USER_IS_NOT_REGISTER); + } + // 判断此vin号码是否已被绑定 + CarVinInfo carVinInfo = carVinInfoMapper.selectVinInfoByVin(dto.getVinCode()); + if (carVinInfo == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + if (!StringUtils.equals("1", carVinInfo.getStatus())) { + throw new BusinessException("", ""); + } + // 绑定操作 + carVinInfo.setVinCode(dto.getVinCode()); + carVinInfo.setStatus("1"); + carVinInfo.setMemberId(dto.getMemberId()); + carVinInfo.setCreateBy(dto.getMemberId()); + + return carVinInfoMapper.insertCarVinInfo(carVinInfo); + } } diff --git a/jsowell-pile/src/main/resources/mapper/pile/CarVinInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/CarVinInfoMapper.xml index a591c3ae8..b87a8c70c 100644 --- a/jsowell-pile/src/main/resources/mapper/pile/CarVinInfoMapper.xml +++ b/jsowell-pile/src/main/resources/mapper/pile/CarVinInfoMapper.xml @@ -110,4 +110,11 @@ join member_wallet_info t3 on t2.member_id = t3.member_id and t2.status = '1' where t1.vin_code = #{vinCode,jdbcType=VARCHAR} + + \ No newline at end of file