Browse Source

增加用户关联品牌和商品-新增业务接口

bai 3 weeks ago
parent
commit
091ea744e7

+ 85 - 7
blade-service/blade-factory/src/main/java/org/springblade/factory/api/controller/SalesOrderController.java

@@ -2,6 +2,7 @@ package org.springblade.factory.api.controller;
 
 
 import com.alibaba.cloud.commons.lang.StringUtils;
+import com.alibaba.excel.util.CollectionUtils;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.gubersail.dealer.admin.api.fegin.IBrandClient;
@@ -30,9 +31,8 @@ import org.springblade.core.secure.utils.AuthUtil;
 import springfox.documentation.annotations.ApiIgnore;
 
 import javax.validation.Valid;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
+import java.util.stream.Collectors;
 
 
 //	System.out.println(AuthUtil.getTenantId());
@@ -62,6 +62,12 @@ public class SalesOrderController {
 
 	private final ZcrmViewCustomerSelService zcrmViewCustomerSelService;
 
+	private final PcBladeUserLinkGoodsService pcBladeUserLinkGoodsService;
+
+	private final PjpfStockDescService stockService;
+
+	private final PjpfBrandDescService brandService;
+
 	/**
 	 * 获取用户的U9相关数据
 	 * @return
@@ -586,10 +592,6 @@ public class SalesOrderController {
 	}
 
 
-
-
-
-
 	/**
 	 * 批量创建销售订单
 	 */
@@ -640,5 +642,81 @@ public class SalesOrderController {
 
 
 
+	// 用户关联品牌和商品业务接口
+	@GetMapping("/getUserLinkGoods")
+	@ApiOperation(value = "用户关联品牌和商品业务接口", notes = "获取当前用户关联的品牌和商品信息")
+	public R<Map<String, Object>> getUserLinkGoods() {
+		// 获取当前登录用户ID
+		Long userId = AuthUtil.getUserId();
+		System.err.println();
+		if (userId == null) {
+			return R.fail("未获取到登录用户信息,请先登录");
+		}
+
+		// 构建查询条件
+		QueryWrapper<PcBladeUserLinkGoods> queryWrapper = new QueryWrapper<>();
+		queryWrapper.eq("CUSTOMER_ID", userId)
+			.eq("is_deleted", 0);  // 先只过滤已删除状态
+
+		// 增加调试信息:显示当前用户ID和查询条件
+		Map<String, Object> debugInfo = new HashMap<>();
+		debugInfo.put("currentUserId", userId);
+		debugInfo.put("queryCondition", queryWrapper.getEntity());
+
+		// 查询所有状态的关联记录(用于调试)
+		List<PcBladeUserLinkGoods> allStatusList = pcBladeUserLinkGoodsService.list(queryWrapper);
+		debugInfo.put("totalRecords", allStatusList.size());
+		debugInfo.put("statusDistribution", allStatusList.stream()
+			.collect(Collectors.groupingBy(PcBladeUserLinkGoods::getStatus, Collectors.counting())));
+
+		// 应用状态过滤
+		queryWrapper.eq("status", 1);  // 只查询状态为1的记录
+		List<PcBladeUserLinkGoods> userLinkGoodsList = pcBladeUserLinkGoodsService.list(queryWrapper);
+
+		if (CollectionUtils.isEmpty(userLinkGoodsList)) {
+			// 返回调试信息帮助排查问题
+			Map<String, Object> result = new HashMap<>();
+			result.put("debug", debugInfo);
+			return R.data(result, "未查询到关联的品牌和商品数据");
+		}
+
+		// 收集需要查询的ID,使用Set去重
+		Set<Long> stockIds = new HashSet<>();
+		Set<Long> brandIds = new HashSet<>();
+
+		for (PcBladeUserLinkGoods linkGoods : userLinkGoodsList) {
+			if (linkGoods.getStockDescId() != null) {
+				stockIds.add(linkGoods.getStockDescId());
+			}
+			if (linkGoods.getBrandId() != null) {
+				brandIds.add(linkGoods.getBrandId());
+			}
+		}
+
+		// 批量查询库存信息
+		List<PjpfStockDesc> stockList = stockIds.isEmpty() ?
+			Collections.emptyList() :
+			stockService.listByIds(stockIds);
+
+		// 批量查询品牌信息
+		List<PjpfBrandDesc> brandList = brandIds.isEmpty() ?
+			Collections.emptyList() :
+			brandService.listByIds(brandIds);
+
+		// 组装返回结果
+		Map<String, Object> resultMap = new HashMap<>();
+		resultMap.put("pjpfStockDescList", stockList);
+		resultMap.put("pjpfBrandDescList", brandList);
+//		resultMap.put("debug", debugInfo);  // 包含调试信息
+
+		return R.data(resultMap, "获取成功");
+	}
+
+
+
+
+
+
+
 
 }