fix (farm): 微信端切换租户

- 添加默认展示字段
This commit is contained in:
达富斌
2025-11-06 20:28:18 +08:00
parent c0c271333a
commit 4aec3151a7
10 changed files with 88 additions and 18 deletions

View File

@@ -108,7 +108,7 @@ public class ProductionPlanResp2VO {
@Schema(description = "基地负责人")
private String baseManager;
@Schema(description = "地块使用剩余网箱数")
@Schema(description = "地块使用网箱数")
private Integer predictedGridNumber;
@Schema(description = "养殖网箱信息")
private ProductionPlanGridRespVO planGridInfo;

View File

@@ -88,6 +88,10 @@ public class ProductionPlanRespVO {
private Double remainingArea;
@Schema(description = "占地面积(百分比)")
private Double usagePercentage;
@Schema(description = "地块总网箱数")
private Integer plotGridNumber;
@Schema(description = "地块使用剩余网箱数")
private Integer predictedGridNumber;
@Schema(description = "备注")
private String remark;

View File

@@ -95,8 +95,8 @@ public class PersonnelManagementServiceImpl implements PersonnelManagementServic
PersonnelManagementDO updateObj = BeanUtils.toBean(updateReqVO, PersonnelManagementDO.class);
SystemUserDO userDO = userMapper.selectByPhone(managementDO.getPhone());
if (updateReqVO.getPhone() != null) userDO.setUsername(updateReqVO.getPhone());
if (updateReqVO.getName() != null) userDO.setNickname(updateReqVO.getName());
if (updateReqVO.getPhone() != null) userDO.setMobile(updateReqVO.getPhone());
if (updateReqVO.getName() != null) userDO.setNickname(updateReqVO.getName());
if (updateReqVO.getPicture() != null) userDO.setAvatar(updateReqVO.getPicture());
// 处理图片集合转换
handleImageConversion(updateObj, updateReqVO);

View File

@@ -25,5 +25,7 @@ public class TenantTokenRespVO {
private String accessToken;
@Schema(description = "刷新令牌")
private String refreshToken;
@Schema(description = "默认展示租户 (1:当前; 0: 非当前)")
private Integer defaultStatus;
}

View File

@@ -5,7 +5,10 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Collection;
import java.util.List;
@@ -48,4 +51,7 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
return selectList(AdminUserDO::getDeptId, deptIds);
}
@InterceptorIgnore(tenantLine = "true")
@Select("SELECT * FROM system_users WHERE deleted = 0 AND mobile = #{mobile}")
List<AdminUserDO> selectListByMobile(@Param("mobile") String mobile);
}

View File

@@ -47,15 +47,14 @@ import jakarta.validation.Validator;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
@@ -507,30 +506,63 @@ public class AdminAuthServiceImpl implements AdminAuthService {
try {
OAuth2AccessTokenDO currentOAuth = oauth2TokenService.getAccessToken(accessToken);
currentOAuth.getTenantId();
TenantDO tenant = tenantService.getTenant(currentOAuth.getTenantId());
Long tenantId = currentOAuth.getTenantId();
TenantDO tenant = tenantService.getTenant(tenantId);
res.add(this.getCurrentTenant(currentOAuth,tenant.getName()));
res.addAll(this.getTenantList(phoneNumber,tenantId));
res.addAll(this.getRemoteTenant(phoneNumber));
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
/**
* 获取当前登录租户列表
* @return
*/
private List<TenantTokenRespVO> getTenantList(String phoneNumber,Long tenantId) {
List<TenantRespVO> tList = tenantService.getTenantListByMobile(phoneNumber);
tList = tList.stream()
.filter(tenant -> ObjectUtils.notEqual(tenantId, tenant.getTenantId()))
.collect(Collectors.toList());
return tList.stream().map(e ->
new TenantTokenRespVO(String.valueOf(e.getTenantId()), e.getTenantName(), "1", "", "", 0)
).toList();
}
/**
* 获取当前登录信息
* @return
*/
private TenantTokenRespVO getCurrentTenant(OAuth2AccessTokenDO currentOAuth,String tenantName) {
TenantTokenRespVO currentTenantObj = new TenantTokenRespVO();
currentTenantObj.setTenantId(currentOAuth.getTenantId().toString());
currentTenantObj.setTenantName(tenant.getName());
currentTenantObj.setTenantName(tenantName);
currentTenantObj.setAccessToken(currentOAuth.getAccessToken());
currentTenantObj.setRefreshToken(currentOAuth.getRefreshToken());
currentTenantObj.setType("1");
res.add(currentTenantObj);
} catch (Exception e) {
e.printStackTrace();
currentTenantObj.setDefaultStatus(0);
return currentTenantObj;
}
/**
* 获取wms系统登录信息
* @param phoneNumber
* @return
*/
private List<TenantTokenRespVO> getRemoteTenant(String phoneNumber) {
try {
TenantResp tenantResp = httpClientUtil.postRequest(wmsHosts, url_1, new TenantReq(phoneNumber));
if (tenantResp.getCode() == 200) {
res.addAll(tenantResp.getData());
return tenantResp.getData();
}
} catch (Exception e) {
e.printStackTrace();
}
return res;
return Collections.EMPTY_LIST;
}
@Override

View File

@@ -145,4 +145,6 @@ public interface TenantService {
void validTenant(Long id);
List<TenantRespVO> loginForTenantList(LoginForTenantReqVO reqVO);
List<TenantRespVO> getTenantListByMobile(String mobileNumber);
}

View File

@@ -118,6 +118,23 @@ public class TenantServiceImpl implements TenantService {
}
@Override
public List<TenantRespVO> getTenantListByMobile(String mobileNumber) {
List<TenantPackageDO> pList = tenantPackageService.getTenantPackageListByStatus(0);
Map<Long, String> pMap = pList.stream().collect(Collectors.toMap(TenantPackageDO::getId, TenantPackageDO::getName, (v1, v2) -> v1));
List<AdminUserDO> uList = userService.getUserByMobileToList2(mobileNumber);
List<Long> ids = uList.stream().map(AdminUserDO::getTenantId).toList();
List<TenantDO> tList = tenantMapper.selectList(TenantDO::getId,ids);
return tList.stream().map(t ->
new TenantRespVO(
t.getId(),
t.getName(),
t.getPackageId(),
pMap.getOrDefault(t.getPackageId(), ""))).toList();
}
@Override
@DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换
@DataPermission(enable = false) // 参见 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/1154 说明

View File

@@ -120,6 +120,8 @@ public interface AdminUserService {
*/
AdminUserDO getUserByMobile(String mobile);
List<AdminUserDO> getUserByMobileToList(String mobile);
List<AdminUserDO> getUserByMobileToList2(String mobileNumber);
/**
* 获得用户分页列表

View File

@@ -337,6 +337,11 @@ public class AdminUserServiceImpl implements AdminUserService {
return userMapper.selectList(AdminUserDO::getMobile,mobile);
}
@Override
public List<AdminUserDO> getUserByMobileToList2(String mobileNumber) {
return userMapper.selectListByMobile(mobileNumber);
}
@Override
public PageResult<AdminUserDO> getUserPage(UserPageReqVO reqVO) {
// 如果有角色编号,查询角色对应的用户编号