|
|
@@ -26,6 +26,7 @@ import org.springblade.system.user.feign.IUserClient;
|
|
|
import org.springblade.u9cloud.entity.ZcrmU9cWebapiSo;
|
|
|
import org.springblade.u9cloud.entity.ZcrmU9cWebapiSoApprove;
|
|
|
import org.springblade.u9cloud.entity.ZcrmU9cWebapiSoSubmit;
|
|
|
+import org.springblade.u9cloud.entity.ZcrmViewCustomerSel;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -71,6 +72,10 @@ public class SalesOrderController {
|
|
|
private final PjpfStockDescService stockService;
|
|
|
|
|
|
private final PjpfBrandDescService brandService;
|
|
|
+ @Autowired
|
|
|
+ private ZcrmViewItemSelService zcrmViewItemSelService;
|
|
|
+ @Autowired
|
|
|
+ private ZcrmViewWhqohSelService zcrmViewWhqohSelService;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -748,82 +753,165 @@ public class SalesOrderController {
|
|
|
|
|
|
|
|
|
// TODO 修改这个接口---考虑关联关系和映射方式
|
|
|
- // 用户关联品牌和商品业务接口
|
|
|
+// // 用户关联品牌和商品业务接口
|
|
|
+// @GetMapping("/getUserLinkGoods")
|
|
|
+// @ApiOperation(value = "用户关联品牌和商品业务接口", notes = "获取当前用户关联的品牌和商品信息")
|
|
|
+// public R<?> getUserLinkGoods() {
|
|
|
+// // 获取当前登录用户ID
|
|
|
+// Long userId = AuthUtil.getUserId();
|
|
|
+// System.err.println();
|
|
|
+// if (userId == null) {
|
|
|
+// return R.fail("未获取到登录用户信息,请先登录");
|
|
|
+// }
|
|
|
+//
|
|
|
+// //修改---重要修复 userID需要修改成CUSTOMER_ID传参
|
|
|
+// R<User> user = userClient.userInfoById(userId);
|
|
|
+// Long customer_id = new Long("0");
|
|
|
+// if (user.getData() == null && user.getData().getCustomerId() == null) {
|
|
|
+// return R.fail("用户不存在");
|
|
|
+// } else {
|
|
|
+// customer_id = user.getData().getCustomerId();
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 构建查询条件
|
|
|
+// QueryWrapper<PcBladeUserLinkGoods> queryWrapper = new QueryWrapper<>();
|
|
|
+// queryWrapper.eq("CUSTOMER_ID", customer_id)
|
|
|
+// .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) {
|
|
|
+// System.err.println(linkGoods);
|
|
|
+// 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, "获取成功");
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户关联品牌和商品业务接口
|
|
|
+ */
|
|
|
@GetMapping("/getUserLinkGoods")
|
|
|
@ApiOperation(value = "用户关联品牌和商品业务接口", notes = "获取当前用户关联的品牌和商品信息")
|
|
|
public R<?> getUserLinkGoods() {
|
|
|
// 获取当前登录用户ID
|
|
|
- Long userId = AuthUtil.getUserId();
|
|
|
- System.err.println();
|
|
|
- if (userId == null) {
|
|
|
+ String userAccount = AuthUtil.getUserAccount();
|
|
|
+ if (userAccount == null) {
|
|
|
return R.fail("未获取到登录用户信息,请先登录");
|
|
|
}
|
|
|
|
|
|
- //修改---重要修复 userID需要修改成CUSTOMER_ID传参
|
|
|
- R<User> user = userClient.userInfoById(userId);
|
|
|
- Long customer_id = new Long("0");
|
|
|
- if (user.getData() == null && user.getData().getCustomerId() == null) {
|
|
|
- return R.fail("用户不存在");
|
|
|
- } else {
|
|
|
- customer_id = user.getData().getCustomerId();
|
|
|
- }
|
|
|
-
|
|
|
- // 构建查询条件
|
|
|
- QueryWrapper<PcBladeUserLinkGoods> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("CUSTOMER_ID", customer_id)
|
|
|
- .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) {
|
|
|
- System.err.println(linkGoods);
|
|
|
- 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);
|
|
|
+ QueryWrapper<ViewCustomerSel> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("Customer_CODE", userAccount);
|
|
|
+ ViewCustomerSel viewCustomerSel = zcrmViewCustomerSelService.getOne(queryWrapper);
|
|
|
+ if (viewCustomerSel == null) {
|
|
|
+ return R.fail("未查询到用户关联信息");
|
|
|
+ }
|
|
|
+ System.err.println(viewCustomerSel);
|
|
|
+ String pubDescSeg4Name = viewCustomerSel.getPubDescSeg4Name();
|
|
|
+ System.err.println(pubDescSeg4Name);
|
|
|
+ // 按逗号分割成数组(处理null或空字符串)
|
|
|
+ String[] codeArray = pubDescSeg4Name != null && !pubDescSeg4Name.isEmpty()
|
|
|
+ ? pubDescSeg4Name.split(",")
|
|
|
+ : new String[0];
|
|
|
+
|
|
|
+ // 查询料品档案并映射为品牌列表
|
|
|
+ QueryWrapper<ViewItemSel> itemQuery = new QueryWrapper<>();
|
|
|
+ itemQuery.in(codeArray.length > 0, "Item_Name", codeArray);
|
|
|
+ List<ViewItemSel> viewItemSelList = zcrmViewItemSelService.list(itemQuery);
|
|
|
+ System.err.println("料品档案查询结果数量:" + viewItemSelList.size());
|
|
|
+ if (viewItemSelList.isEmpty()) {
|
|
|
+ System.err.println("料品档案无匹配数据,查询条件:" + Arrays.toString(codeArray));
|
|
|
+ }
|
|
|
+ List<PjpfBrandDesc> brandList = viewItemSelList.stream().map(item -> {
|
|
|
+ PjpfBrandDesc brand = new PjpfBrandDesc();
|
|
|
+ brand.setId(item.getItemId());
|
|
|
+ brand.setTenantId(String.valueOf(item.getOrgId()));
|
|
|
+ brand.setCname(item.getItemName());
|
|
|
+ brand.setSalesCompanyId(item.getOrgId());
|
|
|
+ brand.setSalesCompanyName(item.getOrgName());
|
|
|
+ brand.setType(item.getMainItemCategoryCode());
|
|
|
+ // 可根据实际业务补充其他字段(如启用状态默认0启用)
|
|
|
+ brand.setEnableOrNot(0);
|
|
|
+ return brand;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 查询库存视图并映射为库存列表
|
|
|
+ QueryWrapper<ViewWhqohSel> stockQuery = new QueryWrapper<>();
|
|
|
+ stockQuery.in(codeArray.length > 0, "Item_Name", codeArray);
|
|
|
+ List<ViewWhqohSel> viewWhqohSelList = zcrmViewWhqohSelService.list(stockQuery);
|
|
|
+ System.err.println("库存视图查询结果数量:" + viewWhqohSelList.size());
|
|
|
+ if (viewWhqohSelList.isEmpty()) {
|
|
|
+ System.err.println("库存视图无匹配数据,查询条件:" + Arrays.toString(codeArray));
|
|
|
+ }
|
|
|
+ List<PjpfStockDesc> stockList = viewWhqohSelList.stream().map(whqoh -> {
|
|
|
+ PjpfStockDesc stock = new PjpfStockDesc();
|
|
|
+ stock.setId(whqoh.getItemId());
|
|
|
+ stock.setTenantId(String.valueOf(whqoh.getOrgId()));
|
|
|
+ stock.setStorageId(whqoh.getWarehouseId());
|
|
|
+ stock.setStorageName(whqoh.getWarehouseName());
|
|
|
+ stock.setGoodsId(whqoh.getItemId());
|
|
|
+ stock.setCode(whqoh.getItemCode());
|
|
|
+ stock.setCname(whqoh.getItemName());
|
|
|
+ stock.setTypeNo(whqoh.getItemPecs());
|
|
|
+ stock.setProductDescription(whqoh.getItemDescription());
|
|
|
+ stock.setSalesCompanyId(whqoh.getOrgId());
|
|
|
+ stock.setSalesCompanyName(whqoh.getOrgName());
|
|
|
+ stock.setBalanceQuantity(whqoh.getStoreQty());
|
|
|
+ stock.setStoreInventory(whqoh.getStoreQty());
|
|
|
+ return stock;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
|
// 组装返回结果
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
resultMap.put("pjpfStockDescList", stockList);
|
|
|
resultMap.put("pjpfBrandDescList", brandList);
|
|
|
-// resultMap.put("debug", debugInfo); // 包含调试信息
|
|
|
|
|
|
return R.data(resultMap, "获取成功");
|
|
|
}
|
|
|
@@ -831,8 +919,4 @@ public class SalesOrderController {
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|