diff --git a/src/main/java/cn/com/tenlion/operator/controller/route/systemuser/SystemUserRouteController.java b/src/main/java/cn/com/tenlion/operator/controller/route/systemuser/SystemUserRouteController.java index 61c7b0f..a12ff7d 100644 --- a/src/main/java/cn/com/tenlion/operator/controller/route/systemuser/SystemUserRouteController.java +++ b/src/main/java/cn/com/tenlion/operator/controller/route/systemuser/SystemUserRouteController.java @@ -17,6 +17,7 @@ import ink.wgink.pojo.dtos.role.RoleSimpleDTO; import ink.wgink.pojo.dtos.user.UserDTO; import ink.wgink.properties.ServerProperties; import io.swagger.annotations.Api; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -59,21 +60,19 @@ public class SystemUserRouteController extends DefaultBaseController { UserInfoBO userInfoBO = this.securityComponent.getCurrentUser(); List roleSimpleDTOList = userInfoBO.getRoles(); String url = systemProperties.getUrl(); - if(userInfoBO == null) { - return new ModelAndView("systemuser/login"); - } - if(userInfoBO.getUserId().equals("1")) { + if (userInfoBO.getUserId().equals("1")) { return new ModelAndView("forward:/default-main"); } - if (roleSimpleDTOList == null || roleSimpleDTOList.size() < 1) { + if (roleSimpleDTOList == null || roleSimpleDTOList.isEmpty()) { throw new SaveException("角色不存在"); } - if(roleSimpleDTOList.get(0).getRoleName().contains("普通用户")) { - return new ModelAndView(new RedirectView(ProjectConfigUtil.getText("AiServerUrl"))); - }else if(roleSimpleDTOList.get(0).getRoleName().contains("代理商")) { - return new ModelAndView(new RedirectView(ProjectConfigUtil.getText("AgentServerUrl"))); - }else if(roleSimpleDTOList.get(0).getRoleName().contains("运营平台") || userInfoBO.getUserId().equals("1")){ + boolean isAdmin = roleSimpleDTOList.stream().anyMatch(roleSimpleDTO -> StringUtils.equals("运营平台", roleSimpleDTO.getRoleName()) || + StringUtils.equals("项目运营", roleSimpleDTO.getRoleName()) || + StringUtils.equals("开发人员", roleSimpleDTO.getRoleName())); + if (isAdmin || userInfoBO.getUserId().equals("1")) { return new ModelAndView("forward:/default-main"); + } else if (roleSimpleDTOList.stream().anyMatch(roleSimpleDTO -> StringUtils.equals("普通用户", roleSimpleDTO.getRoleName()))) { + return new ModelAndView(new RedirectView(ProjectConfigUtil.getText("AiServerUrl"))); } return new ModelAndView("systemuser/login?error=无权限访问"); } diff --git a/src/main/java/cn/com/tenlion/operator/pojo/dtos/user/expand/UserExpandDTO.java b/src/main/java/cn/com/tenlion/operator/pojo/dtos/user/expand/UserExpandDTO.java index b604b1d..bdc0a01 100644 --- a/src/main/java/cn/com/tenlion/operator/pojo/dtos/user/expand/UserExpandDTO.java +++ b/src/main/java/cn/com/tenlion/operator/pojo/dtos/user/expand/UserExpandDTO.java @@ -44,6 +44,8 @@ public class UserExpandDTO extends UserDTO { * 子账号关联的主账号ID */ private String mainUserId; + private String wxMiniappOpenId; + private String wxOfficialAccountOpenId; public String getSubUserIds() { return subUserIds == null ? "" : subUserIds.trim(); @@ -244,4 +246,20 @@ public class UserExpandDTO extends UserDTO { public void setRelationIcUserId(String relationIcUserId) { this.relationIcUserId = relationIcUserId; } + + public String getWxMiniappOpenId() { + return wxMiniappOpenId == null ? "" : wxMiniappOpenId.trim(); + } + + public void setWxMiniappOpenId(String wxMiniappOpenId) { + this.wxMiniappOpenId = wxMiniappOpenId; + } + + public String getWxOfficialAccountOpenId() { + return wxOfficialAccountOpenId == null ? "" : wxOfficialAccountOpenId.trim(); + } + + public void setWxOfficialAccountOpenId(String wxOfficialAccountOpenId) { + this.wxOfficialAccountOpenId = wxOfficialAccountOpenId; + } } diff --git a/src/main/java/cn/com/tenlion/operator/service/user/wx/UserWxMiniappService.java b/src/main/java/cn/com/tenlion/operator/service/user/wx/UserWxMiniappService.java index f0a2d59..7e92b24 100644 --- a/src/main/java/cn/com/tenlion/operator/service/user/wx/UserWxMiniappService.java +++ b/src/main/java/cn/com/tenlion/operator/service/user/wx/UserWxMiniappService.java @@ -15,12 +15,15 @@ import ink.wgink.register.base.pojo.vos.RegisterPhoneVO; import ink.wgink.register.base.service.IRegisterService; import ink.wgink.service.user.pojo.pos.UserPO; import ink.wgink.service.user.service.IUserService; +import ink.wgink.util.date.DateUtil; import org.apache.commons.lang3.StringUtils; +import org.joda.time.LocalDateTime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -56,13 +59,11 @@ public class UserWxMiniappService { */ public void refreshAccessToken() { long currentTimeMillis = System.currentTimeMillis(); - if (miniappAccessToken != null) { - long lastTime = miniappAccessToken.getWxAccessToken().getExpires_in() / 4 * 3; - if (currentTimeMillis - miniappAccessToken.getUpdateTime() < lastTime) { - LOG.debug("小程序 access_token 不需要刷新, 剩余时间: {}", lastTime); - } + if (miniappAccessToken != null && (currentTimeMillis - miniappAccessToken.getUpdateTime() < 5400000)) { + LOG.debug("小程序 access_token 不需要刷新, 刷新时间: {}", LocalDateTime.fromDateFields(new Date(miniappAccessToken.getUpdateTime() + 5400000))); return; } + LOG.debug("小程序 access_token 刷新"); WxAccessToken wxAccessToken = wxMiniappRemoteService.getAccessToken(WX_API_BASE_URL, new HashMap() {{ put("grant_type", "client_credential"); put("appid", wxMiniappProperties.getAppid()); @@ -95,7 +96,7 @@ public class UserWxMiniappService { appLoginPhoneVO.setUsername(userPO.getUserUsername()); String token = appSignService.phoneSign(appLoginPhoneVO); // 如果有账号返回accessToken - return new UserWxLoginDTO(wxLoginResult.getOpenid(), token, 0); + return new UserWxLoginDTO(wxLoginResult.getOpenid(), token, 0, userPO.getUserUsername()); } catch (Exception e) { LOG.error(e.getMessage(), e); throw new SystemException("登录异常"); @@ -129,7 +130,7 @@ public class UserWxMiniappService { appLoginPhoneVO.setUsername(poByUsername.getUserUsername()); String token = appSignService.phoneSign(appLoginPhoneVO); accessTokenService.set2Redis(poByUsername.getUserId(), token); - return new UserWxLoginDTO(openid, token, 0); + return new UserWxLoginDTO(openid, token, 0, poByUsername.getUserUsername()); } // 执行注册 RegisterPhoneVO registerPhoneVO = new RegisterPhoneVO(); @@ -146,7 +147,7 @@ public class UserWxMiniappService { appLoginPhoneVO.setUsername(poByUsername.getUserUsername()); String token = appSignService.phoneSign(appLoginPhoneVO); accessTokenService.set2Redis(poByUsername.getUserId(), token); - return new UserWxLoginDTO(openid, token, 0, phone); + return new UserWxLoginDTO(openid, token, 1, phone); } catch (Exception e) { LOG.error(e.getMessage(), e); throw new SystemException("注册异常");