|
|
@@ -2,6 +2,7 @@ package com.kym.service.miniapp.impl;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
+import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
@@ -12,18 +13,22 @@ import com.kym.common.enums.WxApi;
|
|
|
import com.kym.common.exception.BusinessException;
|
|
|
import com.kym.common.utils.CommUtil;
|
|
|
import com.kym.common.utils.HttpUtil;
|
|
|
+import com.kym.entity.admin.EquipmentInfo;
|
|
|
import com.kym.entity.admin.queryParams.CommonQueryParam;
|
|
|
import com.kym.entity.admin.vo.CustomUserVo;
|
|
|
import com.kym.entity.common.PageBean;
|
|
|
import com.kym.entity.miniapp.Account;
|
|
|
import com.kym.entity.miniapp.Cars;
|
|
|
import com.kym.entity.miniapp.User;
|
|
|
+import com.kym.entity.miniapp.UserRechargeRights;
|
|
|
import com.kym.entity.miniapp.params.WxLoginParams;
|
|
|
import com.kym.entity.miniapp.vo.UserVo;
|
|
|
import com.kym.entity.wechat.WxPhoneNum;
|
|
|
import com.kym.mapper.miniapp.UserMapper;
|
|
|
+import com.kym.service.admin.RechargeRightsService;
|
|
|
import com.kym.service.miniapp.AccountService;
|
|
|
import com.kym.service.miniapp.CarsService;
|
|
|
+import com.kym.service.miniapp.UserRechargeRightsService;
|
|
|
import com.kym.service.miniapp.UserService;
|
|
|
import lombok.SneakyThrows;
|
|
|
import org.slf4j.Logger;
|
|
|
@@ -50,23 +55,26 @@ import static java.util.Map.of;
|
|
|
@DS("db-miniapp")
|
|
|
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(UserServiceImpl.class);
|
|
|
- final
|
|
|
- WxConfig wxConfig;
|
|
|
+ private final WxConfig wxConfig;
|
|
|
private final AccountService accountService;
|
|
|
-
|
|
|
private final CarsService carsService;
|
|
|
+ private final UserRechargeRightsService userRechargeRightsService;
|
|
|
+ private final RechargeRightsService rechargeRightsService;
|
|
|
|
|
|
- public UserServiceImpl(WxConfig wxConfig, AccountService accountService, CarsService carsService) {
|
|
|
+ public UserServiceImpl(WxConfig wxConfig, AccountService accountService, CarsService carsService, UserRechargeRightsService userRechargeRightsService, RechargeRightsService rechargeRightsService) {
|
|
|
this.wxConfig = wxConfig;
|
|
|
this.accountService = accountService;
|
|
|
this.carsService = carsService;
|
|
|
+ this.userRechargeRightsService = userRechargeRightsService;
|
|
|
+
|
|
|
+ this.rechargeRightsService = rechargeRightsService;
|
|
|
}
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@SneakyThrows
|
|
|
@Override
|
|
|
- public R wxLogin(WxLoginParams params) {
|
|
|
+ public R<?> wxLogin(WxLoginParams params) {
|
|
|
// 微信登录
|
|
|
var json = HttpUtil.getJson(WxApi.WX_MP_LOGIN.getApi(), Map.of(
|
|
|
"appid", wxConfig.getAppid(),
|
|
|
@@ -131,7 +139,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
userVo.setDefaultPlateNo(car.getPlateNo());
|
|
|
userVo.setVin(car.getVin());
|
|
|
}
|
|
|
- return userVo;
|
|
|
+ // 当前用户有效的充电权益/优惠券
|
|
|
+ var userRechargeRight = userRechargeRightsService.lambdaQuery()
|
|
|
+ .eq(UserRechargeRights::getUserId, userId).eq(UserRechargeRights::getStatus, UserRechargeRights.STATUS_有效)
|
|
|
+ .orderByAsc(UserRechargeRights::getEndTime).list();
|
|
|
+
|
|
|
+ // 可以参加的活动-充值权益
|
|
|
+ // 手动切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push("db-admin");
|
|
|
+ var rechargeRight = rechargeRightsService.list();
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ return userVo.setRechargeRightsList(rechargeRight).setUserRechargeRightsList(userRechargeRight);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -141,7 +159,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
* @param user
|
|
|
* @return
|
|
|
*/
|
|
|
- private R handleLogin(User user) {
|
|
|
+ private R<?> handleLogin(User user) {
|
|
|
StpUtil.login(user.getId());
|
|
|
// 用户名存入session,统一日志读取使用
|
|
|
StpUtil.getSession().set("openid", user.getOpenid());
|