feat(qywx): 添加根据appid和corpid查询企业授权信息接口
添加selectByAppidAndCorpid方法用于精确查询企业授权信息 优化getBalance接口逻辑,直接使用传入的corpid参数 修复AssetApplicationService中monthlyPurchaseLimit的判断条件
This commit is contained in:
parent
cf5e5fa673
commit
7f45b1cf79
|
@ -245,43 +245,23 @@ public class PaymentController {
|
|||
* 3. 返回余额最大的用户信息
|
||||
*/
|
||||
@GetMapping("/getBalance")
|
||||
public ResponseDTO<GetBalanceResponse> getBalance(@RequestParam String openid) {
|
||||
public ResponseDTO<GetBalanceResponse> getBalance(@RequestParam String corpid, @RequestParam String openid) {
|
||||
String appid = "QWTONG_YS_WXSHOP";
|
||||
List<QyAuthCorpInfoEntity> qyAuthCorpInfoEntityList = authCorpInfoApplicationService.getByAppid(appid);
|
||||
List<QyUserEntity> qyUserEntityList = new ArrayList<>();
|
||||
for (QyAuthCorpInfoEntity qyAuthCorpInfoEntity : qyAuthCorpInfoEntityList) {
|
||||
String corpid = qyAuthCorpInfoEntity.getCorpid();
|
||||
if (!corpid.equals(WeixinConstants.corpid)) {
|
||||
continue;
|
||||
}
|
||||
QyAccessTokenEntity accessToken = accessTokenApplicationService.getByAppid(appid, corpid);
|
||||
UserIdResponse userIdResponse = QywxApiUtil.convertToUserid(accessToken.getAccessToken(), openid);
|
||||
QyUserEntity qyUser = qyUserApplicationService.getUserByUserIdAndCorpid(userIdResponse.getUserid(), corpid);
|
||||
if (qyUser == null) {
|
||||
continue;
|
||||
}
|
||||
qyUserEntityList.add(qyUser);
|
||||
}
|
||||
if (qyUserEntityList.isEmpty()) {
|
||||
return ResponseDTO.fail(new ApiException(ErrorCode.Client.COMMON_REQUEST_PARAMETERS_INVALID, "无效的openid参数"));
|
||||
}
|
||||
// 找出余额最大的用户
|
||||
QyUserEntity maxBalanceUser = qyUserEntityList.stream()
|
||||
.filter(user -> user.getBalance() != null)
|
||||
.max(Comparator.comparing(QyUserEntity::getBalance))
|
||||
.orElse(null);
|
||||
|
||||
if (maxBalanceUser == null) {
|
||||
return ResponseDTO.fail(new ApiException(ErrorCode.Client.COMMON_REQUEST_PARAMETERS_INVALID, "未找到有效余额信息"));
|
||||
QyAccessTokenEntity accessToken = accessTokenApplicationService.getByAppid(appid, corpid);
|
||||
UserIdResponse userIdResponse = QywxApiUtil.convertToUserid(accessToken.getAccessToken(), openid);
|
||||
QyUserEntity qyUser = qyUserApplicationService.getUserByUserIdAndCorpid(userIdResponse.getUserid(), corpid);
|
||||
if (qyUser == null) {
|
||||
return ResponseDTO.fail(new ApiException(ErrorCode.Client.COMMON_REQUEST_PARAMETERS_INVALID, "无效的openid参数"));
|
||||
}
|
||||
|
||||
// 创建响应对象(假设GetBalanceResponse包含balance字段)
|
||||
GetBalanceResponse response = new GetBalanceResponse(
|
||||
maxBalanceUser.getUserid(),
|
||||
maxBalanceUser.getCorpid(),
|
||||
BigDecimal.ZERO,
|
||||
BigDecimal.ZERO,
|
||||
BigDecimal.ZERO);
|
||||
qyUser.getUserid(),
|
||||
qyUser.getCorpid(),
|
||||
qyUser.getBalance(),
|
||||
qyUser.getUseBalance(),
|
||||
qyUser.getBalanceLimit());
|
||||
return ResponseDTO.ok(response);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.agileboot.domain.asset;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.agileboot.common.constant.WeixinConstants;
|
||||
import com.agileboot.domain.asset.command.PostAssetApprovalCommand;
|
||||
import com.agileboot.domain.asset.command.PostAssetGoodsCommand;
|
||||
|
@ -45,6 +46,7 @@ public class AssetApplicationService {
|
|||
private final CabinetCellService cabinetCellService;
|
||||
|
||||
public void pushExternalGoods(PostAssetGoodsCommand postAssetGoodsCommand) {
|
||||
log.info("postAssetGoodsCommand: {}", JSONUtil.toJsonStr(postAssetGoodsCommand));
|
||||
if (postAssetGoodsCommand == null || postAssetGoodsCommand.getGoodsInfoList() == null || postAssetGoodsCommand.getGoodsInfoList().isEmpty()) {
|
||||
throw new IllegalArgumentException("GoodsInfoList cannot be null or empty");
|
||||
}
|
||||
|
@ -67,7 +69,7 @@ public class AssetApplicationService {
|
|||
if (command.getStock() != null) {
|
||||
shopGoodsEntity.setStock(command.getStock());
|
||||
}
|
||||
if (command.getStock() != null) {
|
||||
if (command.getMonthlyPurchaseLimit() != null) {
|
||||
shopGoodsEntity.setMonthlyPurchaseLimit(command.getMonthlyPurchaseLimit());
|
||||
}
|
||||
if (command.getAutoApproval() != null) {
|
||||
|
@ -98,6 +100,7 @@ public class AssetApplicationService {
|
|||
goodsModel.setGoodsDetail(command.getGoodsDetail());
|
||||
goodsModel.setUsageInstruction(command.getUsageInstruction());
|
||||
goodsModel.setBelongType(command.getBelongType());
|
||||
goodsModel.setMonthlyPurchaseLimit(command.getMonthlyPurchaseLimit());
|
||||
goodsModel.initBaseEntity();
|
||||
goodsModel.setCategoryId(0L);
|
||||
goodsModel.setStatus(1);
|
||||
|
|
|
@ -54,4 +54,8 @@ public class AuthCorpInfoApplicationService {
|
|||
public List<QyAuthCorpInfoEntity> getByAppid(String appid) {
|
||||
return authCorpInfoService.getByAppid(appid);
|
||||
}
|
||||
|
||||
public QyAuthCorpInfoEntity selectByAppidAndCorpid(String appid, String corpid) {
|
||||
return authCorpInfoService.selectByAppidAndCorpid(appid, corpid);
|
||||
}
|
||||
}
|
|
@ -34,4 +34,8 @@ public interface QyAuthCorpInfoMapper extends BaseMapper<QyAuthCorpInfoEntity> {
|
|||
|
||||
@Select("SELECT * FROM qy_auth_corp_info WHERE appid = #{appid}")
|
||||
List<QyAuthCorpInfoEntity> selectByAppid(@Param("appid")String appid);
|
||||
|
||||
|
||||
@Select("SELECT * FROM qy_auth_corp_info WHERE appid = #{appid} AND corpid = #{corpid} LIMIT 1")
|
||||
QyAuthCorpInfoEntity selectByAppidAndCorpid(@Param("appid")String appid, @Param("corpid")String corpid);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.agileboot.domain.qywx.authCorpInfo.db;
|
|||
import com.agileboot.common.core.page.AbstractPageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -20,4 +22,6 @@ public interface QyAuthCorpInfoService extends IService<QyAuthCorpInfoEntity> {
|
|||
List<QyAuthCorpInfoEntity> selectAll();
|
||||
|
||||
List<QyAuthCorpInfoEntity> getByAppid(String appid);
|
||||
|
||||
QyAuthCorpInfoEntity selectByAppidAndCorpid(String appid, String corpid);
|
||||
}
|
||||
|
|
|
@ -33,4 +33,9 @@ public class QyAuthCorpInfoServiceImpl extends ServiceImpl<QyAuthCorpInfoMapper,
|
|||
public List<QyAuthCorpInfoEntity> getByAppid(String appid) {
|
||||
return baseMapper.selectByAppid(appid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QyAuthCorpInfoEntity selectByAppidAndCorpid(String appid, String corpid) {
|
||||
return baseMapper.selectByAppidAndCorpid(appid, corpid);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue