fix (farm): 微服务API,微信端接口
- 微信端,获取多个服务token,用于切换服务
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.farm.controller.admin.baseinfo;
|
||||
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.baseinfo.vo.*;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.baseinfo.vo.wx.BaseInfoForWxRespVO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
@@ -108,4 +109,17 @@ public class BaseInfoController {
|
||||
BeanUtils.toBean(list, BaseInfoRespVO.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* === === 微信端 === ===
|
||||
*/
|
||||
// @GetMapping("/wx/base/list")
|
||||
// @Operation(summary = "微信端-常用地块集合")
|
||||
@GetMapping("/wx/base/list")
|
||||
@Operation(summary = "基地列表(微信端)")
|
||||
public CommonResult<List<BaseInfoForWxRespVO>> getBaseListForWx() {
|
||||
List<BaseInfoForWxRespVO> res = baseInfoService.getBaseListForWx();
|
||||
return success(res);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.iocoder.yudao.module.farm.controller.admin.baseinfo.vo.wx;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description: for微信端
|
||||
* @author: binda
|
||||
* @date: 2025/9/16 18:38
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class BaseInfoForWxRespVO {
|
||||
|
||||
private String baseId;
|
||||
private String baseName;
|
||||
private BigDecimal baseArea;
|
||||
private List<PLotInfo> pLotInfos;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public static class PLotInfo{
|
||||
@Schema(description = "地块ID")
|
||||
private String plotId;
|
||||
@Schema(description = "地块名称")
|
||||
private String plotName;
|
||||
@Schema(description = "地块面积")
|
||||
private BigDecimal plotArea;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.farm.controller.admin.api.vo.FarmBaseInfoRespVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.api.vo.FarmBaseOverviewReqVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.api.vo.FarmBaseOverviewRespVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.baseinfo.vo.*;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.baseinfo.vo.wx.BaseInfoForWxRespVO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.baseinfo.BaseInfoDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@@ -101,5 +102,9 @@ public interface BaseInfoService {
|
||||
|
||||
CommonResult<List<FarmBaseInfoRespVO>> getBaseInfoList(FarmBaseInfoReqVO req);
|
||||
|
||||
|
||||
/**
|
||||
* 基地列表 - 微信端
|
||||
* @return
|
||||
*/
|
||||
List<BaseInfoForWxRespVO> getBaseListForWx();
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.farm.controller.admin.api.vo.FarmBaseInfoRespVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.api.vo.FarmBaseOverviewReqVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.api.vo.FarmBaseOverviewRespVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.baseinfo.vo.*;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.baseinfo.vo.wx.BaseInfoForWxRespVO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.baseinfo.BaseInfoDO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.companyinfo.CompanyInfoDO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.gridinfo.GridInfoDO;
|
||||
@@ -377,4 +378,27 @@ public class BaseInfoServiceImpl implements BaseInfoService {
|
||||
|
||||
return CommonResult.success(vos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BaseInfoForWxRespVO> getBaseListForWx() {
|
||||
long tenantId = getLoginUser().getTenantId();
|
||||
LambdaQueryWrapperX<BaseInfoDO> wrapperX = new LambdaQueryWrapperX<>();
|
||||
wrapperX.eq(BaseInfoDO::getTenantId, tenantId);
|
||||
wrapperX.eq(BaseInfoDO::getDeleted, CommonConstants.NO_CODE);
|
||||
List<BaseInfoDO> list = baseInfoMapper.selectList(wrapperX);
|
||||
|
||||
return list.stream().map(e -> {
|
||||
String baseId = e.getId();
|
||||
List<PlotInfoDO> plotInfos = plotInfoService.getPlotInfos(baseId);
|
||||
List<BaseInfoForWxRespVO.PLotInfo> pLotInfos = plotInfos.stream().map(p -> new BaseInfoForWxRespVO.PLotInfo(p.getId(), p.getPlotName(), p.getPlotArea())).toList();
|
||||
|
||||
BaseInfoForWxRespVO b = new BaseInfoForWxRespVO();
|
||||
b.setBaseId(e.getId());
|
||||
b.setBaseName(e.getName());
|
||||
b.setBaseArea(e.getArea());
|
||||
b.setPLotInfos(pLotInfos);
|
||||
return b;
|
||||
}).toList();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -56,10 +56,15 @@
|
||||
AND production_start_date IS NOT NULL
|
||||
<if test="tenantId != null and tenantId != ''">AND tenant_id = #{tenantId}</if>
|
||||
<if test="baseId != null and baseId != ''">AND base_id = #{baseId}</if>
|
||||
<!-- 添加年份范围筛选 -->
|
||||
<if test="yieldDate != null and yieldDate.size() == 2">
|
||||
AND YEAR(production_start_date) BETWEEN #{yieldDate[0]} AND #{yieldDate[1]}
|
||||
</if>
|
||||
<!-- 年份范围筛选 -->
|
||||
<choose>
|
||||
<when test="yieldDate != null and yieldDate.size() == 2">
|
||||
AND YEAR(production_start_date) BETWEEN #{yieldDate[0]} AND #{yieldDate[1]}
|
||||
</when>
|
||||
<otherwise>
|
||||
AND YEAR(production_start_date) BETWEEN YEAR(DATE_SUB(CURDATE(), INTERVAL 4 YEAR)) AND YEAR(CURDATE())
|
||||
</otherwise>
|
||||
</choose>
|
||||
</where>
|
||||
GROUP BY YEAR(production_start_date)
|
||||
ORDER BY date
|
||||
|
||||
@@ -150,6 +150,14 @@ public class AuthController {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/get-tenant-token")
|
||||
@Operation(summary = "获取租户的令牌列表")
|
||||
public CommonResult<List<TenantTokenRespVO>> getTenantTokenList(@RequestHeader("authorization") String authorization,
|
||||
@RequestBody @Valid TenantTokenReqVO reqVO) {
|
||||
List<TenantTokenRespVO> res = authService.getTenantTokenList(reqVO.getPhoneNumber(), authorization);
|
||||
return success(res);
|
||||
}
|
||||
|
||||
// ========== 短信登录相关 ==========
|
||||
|
||||
@PostMapping("/sms-login")
|
||||
@@ -201,14 +209,12 @@ public class AuthController {
|
||||
|
||||
|
||||
@PostMapping("/api/user-add")
|
||||
@PermitAll
|
||||
@Operation(summary = "同步用户")
|
||||
public CommonResult<Boolean> synchronize(@RequestBody @Valid UserReqVO reqVO) {
|
||||
return success(authService.synchronize(reqVO));
|
||||
}
|
||||
|
||||
@PostMapping("/api/user-info")
|
||||
@PermitAll
|
||||
@Operation(summary = "手机号获取token")
|
||||
public CommonResult<AuthLoginRespVO> getUserInfo(@RequestBody @Valid UserReqVO reqVO) {
|
||||
return success(authService.getUserInfo(reqVO));
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -96,4 +97,11 @@ public interface AdminAuthService {
|
||||
Boolean synchronize(@Valid UserReqVO reqVO);
|
||||
|
||||
AuthLoginRespVO getUserInfo(@Valid UserReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获取住户令牌列表
|
||||
* @param phoneNumber
|
||||
* @return
|
||||
*/
|
||||
List<TenantTokenRespVO> getTenantTokenList(String phoneNumber,String accessToken);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import cn.iocoder.yudao.module.system.controller.admin.auth.vo.*;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.convert.auth.AuthConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum;
|
||||
@@ -30,7 +31,11 @@ import cn.iocoder.yudao.module.system.service.logger.LoginLogService;
|
||||
import cn.iocoder.yudao.module.system.service.member.MemberService;
|
||||
import cn.iocoder.yudao.module.system.service.oauth2.OAuth2TokenService;
|
||||
import cn.iocoder.yudao.module.system.service.social.SocialUserService;
|
||||
import cn.iocoder.yudao.module.system.service.tenant.TenantService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import cn.iocoder.yudao.module.system.util.httpClient.HttpClientUtil;
|
||||
import cn.iocoder.yudao.module.system.util.httpClient.vo.TenantReq;
|
||||
import cn.iocoder.yudao.module.system.util.httpClient.vo.TenantResp;
|
||||
import com.anji.captcha.model.common.ResponseModel;
|
||||
import com.anji.captcha.model.vo.CaptchaVO;
|
||||
import com.anji.captcha.service.CaptchaService;
|
||||
@@ -45,7 +50,9 @@ 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 static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
@@ -78,6 +85,8 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
@Resource
|
||||
private SmsCodeApi smsCodeApi;
|
||||
private final WxMaService wxMaService;
|
||||
private final HttpClientUtil httpClientUtil;
|
||||
private final TenantService tenantService;
|
||||
/**
|
||||
* 验证码的开关,默认为 true
|
||||
*/
|
||||
@@ -91,8 +100,18 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
@Value("${wx.miniapp.appid}")
|
||||
private String wxMiniAppId;
|
||||
|
||||
public AdminAuthServiceImpl(WxMaService wxMaService) {
|
||||
/**
|
||||
* wms系统
|
||||
*/
|
||||
@Value("${wms.hosts}")
|
||||
private String wmsHosts;
|
||||
@Value("${wms.url_1}")
|
||||
private String url_1;
|
||||
|
||||
public AdminAuthServiceImpl(WxMaService wxMaService, HttpClientUtil httpClientUtil, TenantService tenantService) {
|
||||
this.wxMaService = wxMaService;
|
||||
this.httpClientUtil = httpClientUtil;
|
||||
this.tenantService = tenantService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -480,6 +499,38 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
return createTokenAfterLoginSuccess(user.getId(), reqVO.getPhone(), LoginLogTypeEnum.LOGIN_MOBILE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TenantTokenRespVO> getTenantTokenList(String phoneNumber,String accessToken) {
|
||||
List<TenantTokenRespVO> res = new ArrayList<>();
|
||||
|
||||
try {
|
||||
OAuth2AccessTokenDO currentOAuth = oauth2TokenService.getAccessToken(accessToken);
|
||||
currentOAuth.getTenantId();
|
||||
TenantDO tenant = tenantService.getTenant(currentOAuth.getTenantId());
|
||||
|
||||
TenantTokenRespVO currentTenantObj = new TenantTokenRespVO();
|
||||
currentTenantObj.setTenantId(currentOAuth.getTenantId().toString());
|
||||
currentTenantObj.setTenantName(tenant.getName());
|
||||
currentTenantObj.setAccessToken(currentOAuth.getAccessToken());
|
||||
currentTenantObj.setRefreshToken(currentOAuth.getRefreshToken());
|
||||
currentTenantObj.setType("1");
|
||||
res.add(currentTenantObj);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
TenantResp tenantResp = httpClientUtil.postRequest(wmsHosts, url_1, new TenantReq(phoneNumber));
|
||||
if (tenantResp.getCode() == 200) {
|
||||
res.addAll(tenantResp.getData());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密微信小程序数据
|
||||
* 根据微信官方文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package cn.iocoder.yudao.module.system.util.httpClient;
|
||||
|
||||
import cn.iocoder.yudao.module.system.util.httpClient.vo.TenantResp;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.Duration;
|
||||
/**
|
||||
* @description: http client
|
||||
* @author: binda
|
||||
* @date: 2025/9/16 16:46
|
||||
*/
|
||||
@Component
|
||||
public class HttpClientUtil {
|
||||
|
||||
private final HttpClient httpClient;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public HttpClientUtil(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
this.httpClient = HttpClient.newBuilder()
|
||||
.connectTimeout(Duration.ofSeconds(10))
|
||||
.build();
|
||||
}
|
||||
|
||||
private String getBaseUrl(String wmsHosts) {
|
||||
return "http://" + wmsHosts ;
|
||||
}
|
||||
|
||||
public TenantResp postRequest(String hosts,String path, Object requestBody) throws Exception {
|
||||
String requestBodyJson = objectMapper.writeValueAsString(requestBody);
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(this.getBaseUrl(hosts) +"/"+ path))
|
||||
.header("Content-Type", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(requestBodyJson))
|
||||
.timeout(Duration.ofSeconds(10))
|
||||
.build();
|
||||
|
||||
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
if (response.statusCode() == 200) {
|
||||
return objectMapper.readValue(response.body(), TenantResp.class);
|
||||
} else {
|
||||
throw new RuntimeException("HTTP request failed with status: " + response.statusCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.iocoder.yudao.module.system.util.httpClient.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: binda
|
||||
* @date: 2025/9/16 17:21
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TenantReq {
|
||||
private String phoneNumber;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.iocoder.yudao.module.system.util.httpClient.vo;
|
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.TenantTokenRespVO;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: binda
|
||||
* @date: 2025/9/16 17:03
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TenantResp {
|
||||
|
||||
private String msg;
|
||||
private int code;
|
||||
private List<TenantTokenRespVO> data;
|
||||
|
||||
}
|
||||
@@ -339,4 +339,8 @@ spring:
|
||||
core-size: 16 # 默认核心线程数,可根据实际需求调整
|
||||
max-size: 32 # 最大线程数
|
||||
queue-capacity: 1000 # 队列容量
|
||||
keep-alive: 60s # 空闲线程存活时间
|
||||
keep-alive: 60s # 空闲线程存活时间
|
||||
# 万懋wms系统
|
||||
wms:
|
||||
hosts: 47.111.15.9:8074/prod-api
|
||||
url_1: getTenantByMobile
|
||||
Reference in New Issue
Block a user