From 3bb4f33182b073be63695a633bbf39212519a4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E5=A4=A7=E5=8F=94?= <494979559@qq.com> Date: Wed, 9 Oct 2024 11:27:47 +0800 Subject: [PATCH] =?UTF-8?q?1.=E8=AE=BE=E5=A4=87=E5=88=86=E6=88=90=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E4=BF=AE=E6=94=B9=EF=BC=8C=E5=BE=85=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=EF=BC=9B=202.=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95=E6=97=A0?= =?UTF-8?q?=E9=9C=80=E6=89=8B=E6=9C=BA=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/service/SysLoginService.java | 42 ++++++++----------- .../web/service/UserDetailsServiceImpl.java | 2 +- .../service/impl/BonusConverterImpl.java | 3 +- .../ruoyi/ss/device/domain/vo/DeviceVO.java | 3 ++ .../ruoyi/ss/device/mapper/DeviceMapper.xml | 3 +- .../service/impl/DeviceValidatorImpl.java | 8 ++++ 6 files changed, 33 insertions(+), 28 deletions(-) diff --git a/smart-switch-ruoyi/smart-switch-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/smart-switch-ruoyi/smart-switch-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index 3f2fa8f3..8cc4f7a7 100644 --- a/smart-switch-ruoyi/smart-switch-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/smart-switch-ruoyi/smart-switch-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -259,28 +259,21 @@ public class SysLoginService // 通过登录授权码获取到用户信息 WxMaJscode2SessionResult wxMaJscode2SessionResult = wxAuthService.wxJsCode2Session(body.getLoginCode()); + ServiceUtil.assertion(wxMaJscode2SessionResult == null, "获取微信openId失败"); // 通过openId查询用户,判断是否微信用户 - SmUser user = smUserService.selectSmUserByWxOpenId(wxMaJscode2SessionResult.getOpenid()); + String openId = wxMaJscode2SessionResult.getOpenid(); + SmUser user = smUserService.selectSmUserByWxOpenId(openId); - // 不是微信老用户,则将微信与手机号绑定 + // 不是微信用户,则使用openId进行注册 if (user == null || Objects.equals(user.getDelFlag(), UserStatus.DELETED.getCode())) { - ServiceUtil.assertion(body.getMobileCode() == null, "请提供微信手机号授权码", 10003); - - // 通过授权码获取微信手机号 - String phoneNumber = getWxPhoneNumber(body.getMobileCode()); - ServiceUtil.assertion(StringUtils.isBlank(phoneNumber), "获取授权手机号失败"); - - // 判断用户是否注册,未注册的自动注册 - user = smUserService.selectUserByPhone(phoneNumber); - if(ObjectUtils.isEmpty(user)){ - user = registerWx(phoneNumber, wxMaJscode2SessionResult); - } + user = registerWx(openId); } + ServiceUtil.assertion(user == null, "用户不存在"); Authentication authentication = null; try { - UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(user.getPhonenumber(), Constants.CUSTOM_LOGIN_WX); + UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(openId, Constants.CUSTOM_LOGIN_WX); // 用户名和密码等信息保存在一个上下文中,只要是同一线程等会就能拿到用户名和密码,也就是能在loadUserByUsername(String username)方法中进行密码验证等 AuthenticationContextHolder.setContext(authenticationToken); // 把用户登录类型放在上下文中的details属性中,在UserDetailsServiceImpl.loadUserByUsername中获取 @@ -303,20 +296,19 @@ public class SysLoginService /** * 注册微信用户 - * @param phoneNumber 手机号 - * @param wxMaJscode2SessionResult 微信用户信息 - * @return + * @param openId 微信OpenId */ - private SmUser registerWx(String phoneNumber, WxMaJscode2SessionResult wxMaJscode2SessionResult) { + private SmUser registerWx(String openId) { + if (StringUtils.isBlank(openId)) { + return null; + } + + String name = "微信用户" + openId.substring(openId.length() - 4); + // 添加用户 SmUser newUser = new SmUser(); - newUser.setUserName(phoneNumber); - newUser.setPhonenumber(phoneNumber); - newUser.setNickName("微信用户" + phoneNumber.substring(phoneNumber.length() - 4)); - newUser.setLoginIp(IpUtils.getIpAddr()); - newUser.setLoginDate(DateUtils.getNowDate()); - newUser.setCreateTime(DateUtils.getNowDate()); - newUser.setWxOpenId(wxMaJscode2SessionResult.getOpenid()); + newUser.setUserName(name); + newUser.setWxOpenId(openId); smUserService.insertSmUser(newUser); // 添加微信账户 diff --git a/smart-switch-ruoyi/smart-switch-framework/src/main/java/com/ruoyi/framework/web/service/UserDetailsServiceImpl.java b/smart-switch-ruoyi/smart-switch-framework/src/main/java/com/ruoyi/framework/web/service/UserDetailsServiceImpl.java index cdecd276..8bd467c6 100644 --- a/smart-switch-ruoyi/smart-switch-framework/src/main/java/com/ruoyi/framework/web/service/UserDetailsServiceImpl.java +++ b/smart-switch-ruoyi/smart-switch-framework/src/main/java/com/ruoyi/framework/web/service/UserDetailsServiceImpl.java @@ -60,7 +60,7 @@ public class UserDetailsServiceImpl implements UserDetailsService return createLoginUser(user); } else if(Constants.USER_TYPE_WX.equals(userType)) { // app 用户微信登录 - SmUser user = smUserService.selectUserByPhone(username); + SmUser user = smUserService.selectSmUserByWxOpenId(username); this.checkUser(user, username); return createLoginUser(user); } else if(Constants.USER_TYPE_APP.equals(userType)) { diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/service/impl/BonusConverterImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/service/impl/BonusConverterImpl.java index f5203fa4..490ce0b5 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/service/impl/BonusConverterImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/service/impl/BonusConverterImpl.java @@ -123,6 +123,7 @@ public class BonusConverterImpl implements BonusConverter { // 代理模式 else if (DeviceServiceMode.AGENT.getMode().equals(device.getServiceMode())) { // 平台收取服务费 + ServiceUtil.assertion(agent == null, "代理商不存在,请联系管理员处理"); ServiceUtil.assertion(agent.getAgentServiceRate() == null, "代理商服务费未配置"); ServiceUtil.assertion(device.getAgentServiceRate() == null, "代理商设备服务费未配置"); @@ -130,7 +131,7 @@ public class BonusConverterImpl implements BonusConverter { point = point.subtract(agent.getAgentServiceRate()); // 代理商收取服务费 - result.add(this.toPo(agent, device.getAgentServiceRate(), agent.getUserId().toString())); + result.add(this.toPo(agent, device.getAgentServiceRate().subtract(agent.getAgentServiceRate()), agent.getUserId().toString())); point = point.subtract(device.getAgentServiceRate()); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/vo/DeviceVO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/vo/DeviceVO.java index 5dea50c4..b12d3193 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/vo/DeviceVO.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/vo/DeviceVO.java @@ -81,6 +81,9 @@ public class DeviceVO extends Device implements IotDevice { @ApiModelProperty("最终生效的服务费率") private BigDecimal realServiceRate; + @ApiModelProperty("代理商本人服务费") + private BigDecimal agentUserServiceRate; + @ApiModelProperty("代理名称") private String agentName; diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml index a4f9b87d..c84a9eb8 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml @@ -163,7 +163,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" su.user_name as user_name, su.service_rate as user_service_rate, sua.user_name as agent_name, - sua.phonenumber as agent_mobile + sua.phonenumber as agent_mobile, + sua.agent_service_rate as agent_user_service_rate from sm_device sd left join sm_model sm on sm.model_id = sd.model_id left join sm_store ss on ss.store_id = sd.store_id diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceValidatorImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceValidatorImpl.java index a846c0aa..d3b166c5 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceValidatorImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceValidatorImpl.java @@ -8,6 +8,7 @@ import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.collection.CollectionUtils; import com.ruoyi.ss.device.domain.DeviceBO; import com.ruoyi.ss.device.domain.DeviceQuery; +import com.ruoyi.ss.device.domain.enums.DeviceServiceMode; import com.ruoyi.ss.device.domain.vo.DeviceVO; import com.ruoyi.ss.device.service.DeviceService; import com.ruoyi.ss.device.service.DeviceValidator; @@ -176,6 +177,13 @@ public class DeviceValidatorImpl extends BaseValidator implements DeviceValidato ServiceUtil.assertion(this.isRepeatMac(vo.getDeviceId(), vo.getMac2()), "MAC-2重复:" + vo.getMac2()); ServiceUtil.assertion(this.isRepeatSn(vo.getDeviceId(), vo.getDeviceNo()), "SN重复"); + // 若是代理模式,则代理商服务费不允许 小于 代理商本人的服务费 + if (DeviceServiceMode.AGENT.getMode().equals(vo.getServiceMode())) { + ServiceUtil.assertion(vo.getAgentId() == null, "代理商不允许为空"); + ServiceUtil.assertion(vo.getAgentServiceRate() == null || vo.getAgentUserServiceRate() == null, "设备代理商服务费或平台代理商服务费不允许为空"); + ServiceUtil.assertion(vo.getAgentServiceRate().compareTo(vo.getAgentUserServiceRate()) < 0, "设备服务费不允许小于平台收取代理商的服务费:" + vo.getAgentUserServiceRate() + "%"); + } + } @Override